ホーム › Graphics.Gdi › GetGlyphIndicesW
GetGlyphIndicesW
関数文字列をグリフインデックスに変換して取得する。
シグネチャ
// GDI32.dll (Unicode / -W)
#include <windows.h>
DWORD GetGlyphIndicesW(
HDC hdc,
LPCWSTR lpstr,
INT c,
WORD* pgi,
DWORD fl
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||
|---|---|---|---|---|---|---|---|
| hdc | HDC | in | デバイスコンテキストへのハンドル。 | ||||
| lpstr | LPCWSTR | in | 変換する文字列へのポインター。 | ||||
| c | INT | in | lpstr が指す文字列の長さと、pgi が指すバッファーのサイズ(WORD 単位)の両方を表します。 | ||||
| pgi | WORD* | out | このバッファーは次元 c でなければなりません。正常に復帰すると、文字列内の文字に対応するグリフインデックスの配列が格納されます。 | ||||
| fl | DWORD | in | グリフがサポートされていない場合の処理方法を指定します。このパラメーターには次の値を指定できます。
|
戻り値の型: DWORD
公式ドキュメント
GetGlyphIndices 関数は、文字列をグリフインデックスの配列に変換します。この関数を使用すると、フォント内にグリフが存在するかどうかを判別できます。(Unicode)
戻り値
関数が成功した場合、変換されたバイト数(ANSI 関数の場合)または WORD 数(Unicode 関数の場合)を返します。
関数が失敗した場合、戻り値は GDI_ERROR です。
解説(Remarks)
この関数は、lpstr が指す文字列内の各文字について、単一グリフによる表現を特定しようとします。これは特定の低レベルな目的(フォントファイルの操作など)には有用ですが、文字列をグリフにマッピングしたい高レベルなアプリケーションでは、通常 Uniscribe 関数の使用が望まれます。
メモ
wingdi.h ヘッダーは、GetGlyphIndices を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不一致が生じる可能性があります。詳細については、「Conventions for Function Prototypes」を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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 (Unicode / -W)
#include <windows.h>
DWORD GetGlyphIndicesW(
HDC hdc,
LPCWSTR lpstr,
INT c,
WORD* pgi,
DWORD fl
);[DllImport("GDI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint GetGlyphIndicesW(
IntPtr hdc, // HDC
[MarshalAs(UnmanagedType.LPWStr)] string lpstr, // LPCWSTR
int c, // INT
out ushort pgi, // WORD* out
uint fl // DWORD
);<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetGlyphIndicesW(
hdc As IntPtr, ' HDC
<MarshalAs(UnmanagedType.LPWStr)> lpstr As String, ' LPCWSTR
c As Integer, ' INT
<Out> ByRef pgi As UShort, ' WORD* out
fl As UInteger ' DWORD
) As UInteger
End Function' hdc : HDC
' lpstr : LPCWSTR
' c : INT
' pgi : WORD* out
' fl : DWORD
Declare PtrSafe Function GetGlyphIndicesW Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal lpstr As LongPtr, _
ByVal c As Long, _
ByRef pgi As Integer, _
ByVal fl As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetGlyphIndicesW = ctypes.windll.gdi32.GetGlyphIndicesW
GetGlyphIndicesW.restype = wintypes.DWORD
GetGlyphIndicesW.argtypes = [
wintypes.HANDLE, # hdc : HDC
wintypes.LPCWSTR, # lpstr : LPCWSTR
ctypes.c_int, # c : INT
ctypes.POINTER(ctypes.c_ushort), # pgi : WORD* out
wintypes.DWORD, # fl : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
GetGlyphIndicesW = Fiddle::Function.new(
lib['GetGlyphIndicesW'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_VOIDP, # lpstr : LPCWSTR
Fiddle::TYPE_INT, # c : INT
Fiddle::TYPE_VOIDP, # pgi : WORD* out
-Fiddle::TYPE_INT, # fl : DWORD
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "gdi32")]
extern "system" {
fn GetGlyphIndicesW(
hdc: *mut core::ffi::c_void, // HDC
lpstr: *const u16, // LPCWSTR
c: i32, // INT
pgi: *mut u16, // WORD* out
fl: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("GDI32.dll", CharSet = CharSet.Unicode)]
public static extern uint GetGlyphIndicesW(IntPtr hdc, [MarshalAs(UnmanagedType.LPWStr)] string lpstr, int c, out ushort pgi, uint fl);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetGlyphIndicesW' -Namespace Win32 -PassThru
# $api::GetGlyphIndicesW(hdc, lpstr, c, pgi, fl)#uselib "GDI32.dll"
#func global GetGlyphIndicesW "GetGlyphIndicesW" wptr, wptr, wptr, wptr, wptr
; GetGlyphIndicesW hdc, lpstr, c, varptr(pgi), fl ; 戻り値は stat
; hdc : HDC -> "wptr"
; lpstr : LPCWSTR -> "wptr"
; c : INT -> "wptr"
; pgi : WORD* out -> "wptr"
; fl : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "GDI32.dll" #cfunc global GetGlyphIndicesW "GetGlyphIndicesW" sptr, wstr, int, var, int ; res = GetGlyphIndicesW(hdc, lpstr, c, pgi, fl) ; hdc : HDC -> "sptr" ; lpstr : LPCWSTR -> "wstr" ; c : INT -> "int" ; pgi : WORD* out -> "var" ; fl : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "GDI32.dll" #cfunc global GetGlyphIndicesW "GetGlyphIndicesW" sptr, wstr, int, sptr, int ; res = GetGlyphIndicesW(hdc, lpstr, c, varptr(pgi), fl) ; hdc : HDC -> "sptr" ; lpstr : LPCWSTR -> "wstr" ; c : INT -> "int" ; pgi : WORD* out -> "sptr" ; fl : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD GetGlyphIndicesW(HDC hdc, LPCWSTR lpstr, INT c, WORD* pgi, DWORD fl) #uselib "GDI32.dll" #cfunc global GetGlyphIndicesW "GetGlyphIndicesW" intptr, wstr, int, var, int ; res = GetGlyphIndicesW(hdc, lpstr, c, pgi, fl) ; hdc : HDC -> "intptr" ; lpstr : LPCWSTR -> "wstr" ; c : INT -> "int" ; pgi : WORD* out -> "var" ; fl : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD GetGlyphIndicesW(HDC hdc, LPCWSTR lpstr, INT c, WORD* pgi, DWORD fl) #uselib "GDI32.dll" #cfunc global GetGlyphIndicesW "GetGlyphIndicesW" intptr, wstr, int, intptr, int ; res = GetGlyphIndicesW(hdc, lpstr, c, varptr(pgi), fl) ; hdc : HDC -> "intptr" ; lpstr : LPCWSTR -> "wstr" ; c : INT -> "int" ; pgi : WORD* out -> "intptr" ; fl : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procGetGlyphIndicesW = gdi32.NewProc("GetGlyphIndicesW")
)
// hdc (HDC), lpstr (LPCWSTR), c (INT), pgi (WORD* out), fl (DWORD)
r1, _, err := procGetGlyphIndicesW.Call(
uintptr(hdc),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpstr))),
uintptr(c),
uintptr(pgi),
uintptr(fl),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction GetGlyphIndicesW(
hdc: THandle; // HDC
lpstr: PWideChar; // LPCWSTR
c: Integer; // INT
pgi: Pointer; // WORD* out
fl: DWORD // DWORD
): DWORD; stdcall;
external 'GDI32.dll' name 'GetGlyphIndicesW';result := DllCall("GDI32\GetGlyphIndicesW"
, "Ptr", hdc ; HDC
, "WStr", lpstr ; LPCWSTR
, "Int", c ; INT
, "Ptr", pgi ; WORD* out
, "UInt", fl ; DWORD
, "UInt") ; return: DWORD●GetGlyphIndicesW(hdc, lpstr, c, pgi, fl) = DLL("GDI32.dll", "dword GetGlyphIndicesW(void*, char*, int, void*, dword)")
# 呼び出し: GetGlyphIndicesW(hdc, lpstr, c, pgi, fl)
# hdc : HDC -> "void*"
# lpstr : LPCWSTR -> "char*"
# c : INT -> "int"
# pgi : WORD* out -> "void*"
# fl : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "gdi32" fn GetGlyphIndicesW(
hdc: ?*anyopaque, // HDC
lpstr: [*c]const u16, // LPCWSTR
c: i32, // INT
pgi: [*c]u16, // WORD* out
fl: u32 // DWORD
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc GetGlyphIndicesW(
hdc: pointer, # HDC
lpstr: WideCString, # LPCWSTR
c: int32, # INT
pgi: ptr uint16, # WORD* out
fl: uint32 # DWORD
): uint32 {.importc: "GetGlyphIndicesW", stdcall, dynlib: "GDI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "gdi32");
extern(Windows)
uint GetGlyphIndicesW(
void* hdc, // HDC
const(wchar)* lpstr, // LPCWSTR
int c, // INT
ushort* pgi, // WORD* out
uint fl // DWORD
);ccall((:GetGlyphIndicesW, "GDI32.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Cwstring, Int32, Ptr{UInt16}, UInt32),
hdc, lpstr, c, pgi, fl)
# hdc : HDC -> Ptr{Cvoid}
# lpstr : LPCWSTR -> Cwstring
# c : INT -> Int32
# pgi : WORD* out -> Ptr{UInt16}
# fl : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetGlyphIndicesW(
void* hdc,
const uint16_t* lpstr,
int32_t c,
uint16_t* pgi,
uint32_t fl);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.GetGlyphIndicesW(hdc, lpstr, c, pgi, fl)
-- hdc : HDC
-- lpstr : LPCWSTR
-- c : INT
-- pgi : WORD* out
-- fl : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const GetGlyphIndicesW = lib.func('__stdcall', 'GetGlyphIndicesW', 'uint32_t', ['void *', 'str16', 'int32_t', 'uint16_t *', 'uint32_t']);
// GetGlyphIndicesW(hdc, lpstr, c, pgi, fl)
// hdc : HDC -> 'void *'
// lpstr : LPCWSTR -> 'str16'
// c : INT -> 'int32_t'
// pgi : WORD* out -> 'uint16_t *'
// fl : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
GetGlyphIndicesW: { parameters: ["pointer", "buffer", "i32", "pointer", "u32"], result: "u32" },
});
// lib.symbols.GetGlyphIndicesW(hdc, lpstr, c, pgi, fl)
// hdc : HDC -> "pointer"
// lpstr : LPCWSTR -> "buffer"
// c : INT -> "i32"
// pgi : WORD* out -> "pointer"
// fl : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetGlyphIndicesW(
void* hdc,
const uint16_t* lpstr,
int32_t c,
uint16_t* pgi,
uint32_t fl);
C, "GDI32.dll");
// $ffi->GetGlyphIndicesW(hdc, lpstr, c, pgi, fl);
// hdc : HDC
// lpstr : LPCWSTR
// c : INT
// pgi : WORD* out
// fl : DWORD
// 構造体/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, W32APIOptions.UNICODE_OPTIONS);
int GetGlyphIndicesW(
Pointer hdc, // HDC
WString lpstr, // LPCWSTR
int c, // INT
ShortByReference pgi, // WORD* out
int fl // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("gdi32")]
lib LibGDI32
fun GetGlyphIndicesW = GetGlyphIndicesW(
hdc : Void*, # HDC
lpstr : UInt16*, # LPCWSTR
c : Int32, # INT
pgi : UInt16*, # WORD* out
fl : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetGlyphIndicesWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Int32, Pointer<Uint16>, Uint32);
typedef GetGlyphIndicesWDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Uint16>, int);
final GetGlyphIndicesW = DynamicLibrary.open('GDI32.dll')
.lookupFunction<GetGlyphIndicesWNative, GetGlyphIndicesWDart>('GetGlyphIndicesW');
// hdc : HDC -> Pointer<Void>
// lpstr : LPCWSTR -> Pointer<Utf16>
// c : INT -> Int32
// pgi : WORD* out -> Pointer<Uint16>
// fl : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetGlyphIndicesW(
hdc: THandle; // HDC
lpstr: PWideChar; // LPCWSTR
c: Integer; // INT
pgi: Pointer; // WORD* out
fl: DWORD // DWORD
): DWORD; stdcall;
external 'GDI32.dll' name 'GetGlyphIndicesW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetGlyphIndicesW"
c_GetGlyphIndicesW :: Ptr () -> CWString -> Int32 -> Ptr Word16 -> Word32 -> IO Word32
-- hdc : HDC -> Ptr ()
-- lpstr : LPCWSTR -> CWString
-- c : INT -> Int32
-- pgi : WORD* out -> Ptr Word16
-- fl : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getglyphindicesw =
foreign "GetGlyphIndicesW"
((ptr void) @-> (ptr uint16_t) @-> int32_t @-> (ptr uint16_t) @-> uint32_t @-> returning uint32_t)
(* hdc : HDC -> (ptr void) *)
(* lpstr : LPCWSTR -> (ptr uint16_t) *)
(* c : INT -> int32_t *)
(* pgi : WORD* out -> (ptr uint16_t) *)
(* fl : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("GetGlyphIndicesW" get-glyph-indices-w :convention :stdcall) :uint32
(hdc :pointer) ; HDC
(lpstr (:string :encoding :utf-16le)) ; LPCWSTR
(c :int32) ; INT
(pgi :pointer) ; WORD* out
(fl :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetGlyphIndicesW = Win32::API::More->new('GDI32',
'DWORD GetGlyphIndicesW(HANDLE hdc, LPCWSTR lpstr, int c, LPVOID pgi, DWORD fl)');
# my $ret = $GetGlyphIndicesW->Call($hdc, $lpstr, $c, $pgi, $fl);
# hdc : HDC -> HANDLE
# lpstr : LPCWSTR -> LPCWSTR
# c : INT -> int
# pgi : WORD* out -> LPVOID
# fl : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f GetGlyphIndicesA (ANSI版) — 文字列をグリフインデックスに変換して取得する。
公式の関連項目
- f GetFontUnicodeRanges — フォントが対応するUnicode範囲を取得する。