ホーム › Graphics.Gdi › GetCharABCWidthsI
GetCharABCWidthsI
関数グリフインデックスごとのABC幅を取得する。
シグネチャ
// GDI32.dll
#include <windows.h>
BOOL GetCharABCWidthsI(
HDC hdc,
DWORD giFirst,
DWORD cgi,
WORD* pgi, // optional
ABC* pabc
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdc | HDC | in | デバイスコンテキストへのハンドル。 |
| giFirst | DWORD | in | 現在のフォントにおける連続するグリフインデックスのグループの最初のグリフインデックス。このパラメーターは、pgi パラメーターが NULL の場合にのみ使用されます。 |
| cgi | DWORD | in | グリフインデックスの数。 |
| pgi | WORD* | inoptional | グリフインデックスを含む配列へのポインター。このパラメーターが NULL の場合は、代わりに giFirst パラメーターが使用されます。cgi パラメーターは、この配列内のグリフインデックスの数を指定します。 |
| pabc | ABC* | out | 文字幅を論理単位で受け取る ABC 構造体の配列へのポインター。この配列には、cgi パラメーターで指定されたグリフインデックスの数以上の ABC 構造体が含まれている必要があります。 |
戻り値の型: BOOL
公式ドキュメント
GetCharABCWidthsI 関数は、現在の TrueType フォントから、指定された範囲の連続するグリフインデックスの幅を論理単位で取得します。この関数は TrueType フォントでのみ成功します。
戻り値
関数が成功した場合、戻り値は 0 以外の値です。
関数が失敗した場合、戻り値は 0 です。
解説(Remarks)
TrueType ラスタライザーは、特定のポイントサイズが選択された後に ABC 文字間隔を提供します。A 間隔は、グリフを配置する前に現在位置に加算される距離です。B 間隔は、グリフの黒い部分の幅です。C 間隔は、グリフの右側に空白を設けるために現在位置に加算される距離です。総送り幅は A+B+C で指定されます。
GetCharABCWidthsI 関数がある文字に対して負の A 幅または C 幅を取得した場合、その文字にはアンダーハングまたはオーバーハングが含まれています。
ABC 幅をフォントデザイン単位に変換するには、アプリケーションは OUTLINETEXTMETRIC 構造体の otmEMSquare メンバーに格納されている値を使用する必要があります。この値は、GetOutlineTextMetrics 関数を呼び出すことで取得できます。
既定の文字の ABC 幅は、現在選択されているフォントの範囲外の文字に使用されます。
TrueType 以外のフォントのグリフインデックスの幅を取得するには、アプリケーションは GetCharWidthI 関数を使用する必要があります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
BOOL GetCharABCWidthsI(
HDC hdc,
DWORD giFirst,
DWORD cgi,
WORD* pgi, // optional
ABC* pabc
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern bool GetCharABCWidthsI(
IntPtr hdc, // HDC
uint giFirst, // DWORD
uint cgi, // DWORD
IntPtr pgi, // WORD* optional
IntPtr pabc // ABC* out
);<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function GetCharABCWidthsI(
hdc As IntPtr, ' HDC
giFirst As UInteger, ' DWORD
cgi As UInteger, ' DWORD
pgi As IntPtr, ' WORD* optional
pabc As IntPtr ' ABC* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hdc : HDC
' giFirst : DWORD
' cgi : DWORD
' pgi : WORD* optional
' pabc : ABC* out
Declare PtrSafe Function GetCharABCWidthsI Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal giFirst As Long, _
ByVal cgi As Long, _
ByVal pgi As LongPtr, _
ByVal pabc As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetCharABCWidthsI = ctypes.windll.gdi32.GetCharABCWidthsI
GetCharABCWidthsI.restype = wintypes.BOOL
GetCharABCWidthsI.argtypes = [
wintypes.HANDLE, # hdc : HDC
wintypes.DWORD, # giFirst : DWORD
wintypes.DWORD, # cgi : DWORD
ctypes.POINTER(ctypes.c_ushort), # pgi : WORD* optional
ctypes.c_void_p, # pabc : ABC* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
GetCharABCWidthsI = Fiddle::Function.new(
lib['GetCharABCWidthsI'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
-Fiddle::TYPE_INT, # giFirst : DWORD
-Fiddle::TYPE_INT, # cgi : DWORD
Fiddle::TYPE_VOIDP, # pgi : WORD* optional
Fiddle::TYPE_VOIDP, # pabc : ABC* out
],
Fiddle::TYPE_INT)#[link(name = "gdi32")]
extern "system" {
fn GetCharABCWidthsI(
hdc: *mut core::ffi::c_void, // HDC
giFirst: u32, // DWORD
cgi: u32, // DWORD
pgi: *mut u16, // WORD* optional
pabc: *mut ABC // ABC* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll")]
public static extern bool GetCharABCWidthsI(IntPtr hdc, uint giFirst, uint cgi, IntPtr pgi, IntPtr pabc);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetCharABCWidthsI' -Namespace Win32 -PassThru
# $api::GetCharABCWidthsI(hdc, giFirst, cgi, pgi, pabc)#uselib "GDI32.dll"
#func global GetCharABCWidthsI "GetCharABCWidthsI" sptr, sptr, sptr, sptr, sptr
; GetCharABCWidthsI hdc, giFirst, cgi, varptr(pgi), varptr(pabc) ; 戻り値は stat
; hdc : HDC -> "sptr"
; giFirst : DWORD -> "sptr"
; cgi : DWORD -> "sptr"
; pgi : WORD* optional -> "sptr"
; pabc : ABC* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "GDI32.dll" #cfunc global GetCharABCWidthsI "GetCharABCWidthsI" sptr, int, int, var, var ; res = GetCharABCWidthsI(hdc, giFirst, cgi, pgi, pabc) ; hdc : HDC -> "sptr" ; giFirst : DWORD -> "int" ; cgi : DWORD -> "int" ; pgi : WORD* optional -> "var" ; pabc : ABC* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "GDI32.dll" #cfunc global GetCharABCWidthsI "GetCharABCWidthsI" sptr, int, int, sptr, sptr ; res = GetCharABCWidthsI(hdc, giFirst, cgi, varptr(pgi), varptr(pabc)) ; hdc : HDC -> "sptr" ; giFirst : DWORD -> "int" ; cgi : DWORD -> "int" ; pgi : WORD* optional -> "sptr" ; pabc : ABC* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetCharABCWidthsI(HDC hdc, DWORD giFirst, DWORD cgi, WORD* pgi, ABC* pabc) #uselib "GDI32.dll" #cfunc global GetCharABCWidthsI "GetCharABCWidthsI" intptr, int, int, var, var ; res = GetCharABCWidthsI(hdc, giFirst, cgi, pgi, pabc) ; hdc : HDC -> "intptr" ; giFirst : DWORD -> "int" ; cgi : DWORD -> "int" ; pgi : WORD* optional -> "var" ; pabc : ABC* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetCharABCWidthsI(HDC hdc, DWORD giFirst, DWORD cgi, WORD* pgi, ABC* pabc) #uselib "GDI32.dll" #cfunc global GetCharABCWidthsI "GetCharABCWidthsI" intptr, int, int, intptr, intptr ; res = GetCharABCWidthsI(hdc, giFirst, cgi, varptr(pgi), varptr(pabc)) ; hdc : HDC -> "intptr" ; giFirst : DWORD -> "int" ; cgi : DWORD -> "int" ; pgi : WORD* optional -> "intptr" ; pabc : ABC* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procGetCharABCWidthsI = gdi32.NewProc("GetCharABCWidthsI")
)
// hdc (HDC), giFirst (DWORD), cgi (DWORD), pgi (WORD* optional), pabc (ABC* out)
r1, _, err := procGetCharABCWidthsI.Call(
uintptr(hdc),
uintptr(giFirst),
uintptr(cgi),
uintptr(pgi),
uintptr(pabc),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetCharABCWidthsI(
hdc: THandle; // HDC
giFirst: DWORD; // DWORD
cgi: DWORD; // DWORD
pgi: Pointer; // WORD* optional
pabc: Pointer // ABC* out
): BOOL; stdcall;
external 'GDI32.dll' name 'GetCharABCWidthsI';result := DllCall("GDI32\GetCharABCWidthsI"
, "Ptr", hdc ; HDC
, "UInt", giFirst ; DWORD
, "UInt", cgi ; DWORD
, "Ptr", pgi ; WORD* optional
, "Ptr", pabc ; ABC* out
, "Int") ; return: BOOL●GetCharABCWidthsI(hdc, giFirst, cgi, pgi, pabc) = DLL("GDI32.dll", "bool GetCharABCWidthsI(void*, dword, dword, void*, void*)")
# 呼び出し: GetCharABCWidthsI(hdc, giFirst, cgi, pgi, pabc)
# hdc : HDC -> "void*"
# giFirst : DWORD -> "dword"
# cgi : DWORD -> "dword"
# pgi : WORD* optional -> "void*"
# pabc : ABC* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdi32" fn GetCharABCWidthsI(
hdc: ?*anyopaque, // HDC
giFirst: u32, // DWORD
cgi: u32, // DWORD
pgi: [*c]u16, // WORD* optional
pabc: [*c]ABC // ABC* out
) callconv(std.os.windows.WINAPI) i32;proc GetCharABCWidthsI(
hdc: pointer, # HDC
giFirst: uint32, # DWORD
cgi: uint32, # DWORD
pgi: ptr uint16, # WORD* optional
pabc: ptr ABC # ABC* out
): int32 {.importc: "GetCharABCWidthsI", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
int GetCharABCWidthsI(
void* hdc, // HDC
uint giFirst, // DWORD
uint cgi, // DWORD
ushort* pgi, // WORD* optional
ABC* pabc // ABC* out
);ccall((:GetCharABCWidthsI, "GDI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, UInt32, Ptr{UInt16}, Ptr{ABC}),
hdc, giFirst, cgi, pgi, pabc)
# hdc : HDC -> Ptr{Cvoid}
# giFirst : DWORD -> UInt32
# cgi : DWORD -> UInt32
# pgi : WORD* optional -> Ptr{UInt16}
# pabc : ABC* out -> Ptr{ABC}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetCharABCWidthsI(
void* hdc,
uint32_t giFirst,
uint32_t cgi,
uint16_t* pgi,
void* pabc);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.GetCharABCWidthsI(hdc, giFirst, cgi, pgi, pabc)
-- hdc : HDC
-- giFirst : DWORD
-- cgi : DWORD
-- pgi : WORD* optional
-- pabc : ABC* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const GetCharABCWidthsI = lib.func('__stdcall', 'GetCharABCWidthsI', 'int32_t', ['void *', 'uint32_t', 'uint32_t', 'uint16_t *', 'void *']);
// GetCharABCWidthsI(hdc, giFirst, cgi, pgi, pabc)
// hdc : HDC -> 'void *'
// giFirst : DWORD -> 'uint32_t'
// cgi : DWORD -> 'uint32_t'
// pgi : WORD* optional -> 'uint16_t *'
// pabc : ABC* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
GetCharABCWidthsI: { parameters: ["pointer", "u32", "u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.GetCharABCWidthsI(hdc, giFirst, cgi, pgi, pabc)
// hdc : HDC -> "pointer"
// giFirst : DWORD -> "u32"
// cgi : DWORD -> "u32"
// pgi : WORD* optional -> "pointer"
// pabc : ABC* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetCharABCWidthsI(
void* hdc,
uint32_t giFirst,
uint32_t cgi,
uint16_t* pgi,
void* pabc);
C, "GDI32.dll");
// $ffi->GetCharABCWidthsI(hdc, giFirst, cgi, pgi, pabc);
// hdc : HDC
// giFirst : DWORD
// cgi : DWORD
// pgi : WORD* optional
// pabc : ABC* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Gdi32 extends StdCallLibrary {
Gdi32 INSTANCE = Native.load("gdi32", Gdi32.class);
boolean GetCharABCWidthsI(
Pointer hdc, // HDC
int giFirst, // DWORD
int cgi, // DWORD
ShortByReference pgi, // WORD* optional
Pointer pabc // ABC* out
);
}@[Link("gdi32")]
lib LibGDI32
fun GetCharABCWidthsI = GetCharABCWidthsI(
hdc : Void*, # HDC
giFirst : UInt32, # DWORD
cgi : UInt32, # DWORD
pgi : UInt16*, # WORD* optional
pabc : ABC* # ABC* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetCharABCWidthsINative = Int32 Function(Pointer<Void>, Uint32, Uint32, Pointer<Uint16>, Pointer<Void>);
typedef GetCharABCWidthsIDart = int Function(Pointer<Void>, int, int, Pointer<Uint16>, Pointer<Void>);
final GetCharABCWidthsI = DynamicLibrary.open('GDI32.dll')
.lookupFunction<GetCharABCWidthsINative, GetCharABCWidthsIDart>('GetCharABCWidthsI');
// hdc : HDC -> Pointer<Void>
// giFirst : DWORD -> Uint32
// cgi : DWORD -> Uint32
// pgi : WORD* optional -> Pointer<Uint16>
// pabc : ABC* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetCharABCWidthsI(
hdc: THandle; // HDC
giFirst: DWORD; // DWORD
cgi: DWORD; // DWORD
pgi: Pointer; // WORD* optional
pabc: Pointer // ABC* out
): BOOL; stdcall;
external 'GDI32.dll' name 'GetCharABCWidthsI';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetCharABCWidthsI"
c_GetCharABCWidthsI :: Ptr () -> Word32 -> Word32 -> Ptr Word16 -> Ptr () -> IO CInt
-- hdc : HDC -> Ptr ()
-- giFirst : DWORD -> Word32
-- cgi : DWORD -> Word32
-- pgi : WORD* optional -> Ptr Word16
-- pabc : ABC* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getcharabcwidthsi =
foreign "GetCharABCWidthsI"
((ptr void) @-> uint32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr void) @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* giFirst : DWORD -> uint32_t *)
(* cgi : DWORD -> uint32_t *)
(* pgi : WORD* optional -> (ptr uint16_t) *)
(* pabc : ABC* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("GetCharABCWidthsI" get-char-abcwidths-i :convention :stdcall) :int32
(hdc :pointer) ; HDC
(gi-first :uint32) ; DWORD
(cgi :uint32) ; DWORD
(pgi :pointer) ; WORD* optional
(pabc :pointer)) ; ABC* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetCharABCWidthsI = Win32::API::More->new('GDI32',
'BOOL GetCharABCWidthsI(HANDLE hdc, DWORD giFirst, DWORD cgi, LPVOID pgi, LPVOID pabc)');
# my $ret = $GetCharABCWidthsI->Call($hdc, $giFirst, $cgi, $pgi, $pabc);
# hdc : HDC -> HANDLE
# giFirst : DWORD -> DWORD
# cgi : DWORD -> DWORD
# pgi : WORD* optional -> LPVOID
# pabc : ABC* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetCharWidthW — 指定範囲の文字の幅を取得する。
- f GetOutlineTextMetricsW — アウトラインフォントのテキストメトリックを取得する。
- s OUTLINETEXTMETRICW
使用する型