Win32 API 日本語リファレンス
ホームGlobalization › ScriptGetFontAlternateGlyphs

ScriptGetFontAlternateGlyphs

関数
指定機能における代替グリフの一覧を取得する。
DLLUSP10.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// USP10.dll
#include <windows.h>

HRESULT ScriptGetFontAlternateGlyphs(
    HDC hdc,   // optional
    void** psc,
    SCRIPT_ANALYSIS* psa,   // optional
    DWORD tagScript,
    DWORD tagLangSys,
    DWORD tagFeature,
    WORD wGlyphId,
    INT cMaxAlternates,
    WORD* pAlternateGlyphs,
    INT* pcAlternates
);

パラメーター

名前方向説明
hdcHDCinoptionalデバイス コンテキストへのハンドルです。詳細については、Caching を参照してください。
pscvoid**inoutスクリプト キャッシュを定義する SCRIPT_CACHE 構造体へのポインターです。
psaSCRIPT_ANALYSIS*inoptional

ScriptItemizeOpenType への以前の呼び出しから取得した SCRIPT_ANALYSIS 構造体へのポインターです。このパラメーターはシェーピング エンジンを識別し、代替グリフの配列を正しいスコープで作成できるようにします。

あるいは、アプリケーションはこのパラメーターを NULL に設定して、フィルター処理されていない結果を受け取ることもできます。

tagScriptDWORDin代替グリフに関連付けられたスクリプト タグを定義する OPENTYPE_TAG 構造体です。
tagLangSysDWORDin代替グリフに関連付けられた言語タグを定義する OPENTYPE_TAG 構造体です。
tagFeatureDWORDin代替グリフに関連付けられた機能タグを定義する OPENTYPE_TAG 構造体です。
wGlyphIdWORDin文字マップ テーブルからマップされた元のグリフの識別子です。
cMaxAlternatesINTinpAlternateGlyphs で指定される配列の長さです。
pAlternateGlyphsWORD*out

この関数がグリフ識別子の配列を取得するバッファーへのポインターです。配列には元のグリフが含まれ、その後に代替グリフが続きます。最初の要素は常に元のグリフです。代替形式は配列へのインデックスによって識別されます。このインデックスは 1 より大きく、pcAlternates の値より小さい値です。

ユーザーがユーザー インターフェイスから代替形式を選択すると、その代替グリフが対応する文字に適用され、レンダリングが再フォーマットされます。

pcAlternatesINT*outpAlternateGlyphs で指定される配列の要素数へのポインターです。

戻り値の型: HRESULT

公式ドキュメント

指定された文字に対して、指定された OpenType 機能を通じてアクセスできる代替グリフの一覧を取得します。

戻り値

成功した場合は 0 を返します。成功しなかった場合、この関数は 0 以外の HRESULT 値を返します。アプリケーションは、SUCCEEDED および FAILED マクロを使用して戻り値をテストできます。

代替グリフの数が cMaxAlternates の値を超える場合、この関数は E_OUTOFMEMORY で失敗します。アプリケーションは、より大きなバッファーで再度呼び出すことを試みることができます。

解説(Remarks)

代替グリフを使用する場合、アプリケーションはまず、いかなる機能タグも適用せずに元のグリフを再シェーピングし、その後で代替を選択します。元のグリフはベース グリフとして確立されます。別の代替が必要な場合、元のグリフは対応する代替リストとの照合に必要な情報を提供します。

代替グリフがベース グリフとして使用される場合、一致する出力リストは見つかりません。ユーザー インターフェイスは、別の代替を選択する機能を提供せずに、選択された最終形式を使用します。

ScriptGetFontAlternateGlyphs の動作は、ScriptSubstituteSingleGlyph によってエミュレートできます。アプリケーションは、グリフが置換される間、パラメーターを 1 つずつ試す必要があります。

Uniscribe でフォントをシェーピングする場合は、古い ScriptShape 関数よりも ScriptShapeOpenType が推奨されます。

重要 Windows 8 以降: Windows 7 上で実行する機能を維持するために、Uniscribe を使用するモジュールは、ライブラリ リスト内で gdi32.lib より前に Usp10.lib を指定する必要があります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// USP10.dll
#include <windows.h>

HRESULT ScriptGetFontAlternateGlyphs(
    HDC hdc,   // optional
    void** psc,
    SCRIPT_ANALYSIS* psa,   // optional
    DWORD tagScript,
    DWORD tagLangSys,
    DWORD tagFeature,
    WORD wGlyphId,
    INT cMaxAlternates,
    WORD* pAlternateGlyphs,
    INT* pcAlternates
);
[DllImport("USP10.dll", ExactSpelling = true)]
static extern int ScriptGetFontAlternateGlyphs(
    IntPtr hdc,   // HDC optional
    IntPtr psc,   // void** in/out
    IntPtr psa,   // SCRIPT_ANALYSIS* optional
    uint tagScript,   // DWORD
    uint tagLangSys,   // DWORD
    uint tagFeature,   // DWORD
    ushort wGlyphId,   // WORD
    int cMaxAlternates,   // INT
    out ushort pAlternateGlyphs,   // WORD* out
    out int pcAlternates   // INT* out
);
<DllImport("USP10.dll", ExactSpelling:=True)>
Public Shared Function ScriptGetFontAlternateGlyphs(
    hdc As IntPtr,   ' HDC optional
    psc As IntPtr,   ' void** in/out
    psa As IntPtr,   ' SCRIPT_ANALYSIS* optional
    tagScript As UInteger,   ' DWORD
    tagLangSys As UInteger,   ' DWORD
    tagFeature As UInteger,   ' DWORD
    wGlyphId As UShort,   ' WORD
    cMaxAlternates As Integer,   ' INT
    <Out> ByRef pAlternateGlyphs As UShort,   ' WORD* out
    <Out> ByRef pcAlternates As Integer   ' INT* out
) As Integer
End Function
' hdc : HDC optional
' psc : void** in/out
' psa : SCRIPT_ANALYSIS* optional
' tagScript : DWORD
' tagLangSys : DWORD
' tagFeature : DWORD
' wGlyphId : WORD
' cMaxAlternates : INT
' pAlternateGlyphs : WORD* out
' pcAlternates : INT* out
Declare PtrSafe Function ScriptGetFontAlternateGlyphs Lib "usp10" ( _
    ByVal hdc As LongPtr, _
    ByVal psc As LongPtr, _
    ByVal psa As LongPtr, _
    ByVal tagScript As Long, _
    ByVal tagLangSys As Long, _
    ByVal tagFeature As Long, _
    ByVal wGlyphId As Integer, _
    ByVal cMaxAlternates As Long, _
    ByRef pAlternateGlyphs As Integer, _
    ByRef pcAlternates As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ScriptGetFontAlternateGlyphs = ctypes.windll.usp10.ScriptGetFontAlternateGlyphs
ScriptGetFontAlternateGlyphs.restype = ctypes.c_int
ScriptGetFontAlternateGlyphs.argtypes = [
    wintypes.HANDLE,  # hdc : HDC optional
    ctypes.c_void_p,  # psc : void** in/out
    ctypes.c_void_p,  # psa : SCRIPT_ANALYSIS* optional
    wintypes.DWORD,  # tagScript : DWORD
    wintypes.DWORD,  # tagLangSys : DWORD
    wintypes.DWORD,  # tagFeature : DWORD
    ctypes.c_ushort,  # wGlyphId : WORD
    ctypes.c_int,  # cMaxAlternates : INT
    ctypes.POINTER(ctypes.c_ushort),  # pAlternateGlyphs : WORD* out
    ctypes.POINTER(ctypes.c_int),  # pcAlternates : INT* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USP10.dll')
ScriptGetFontAlternateGlyphs = Fiddle::Function.new(
  lib['ScriptGetFontAlternateGlyphs'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC optional
    Fiddle::TYPE_VOIDP,  # psc : void** in/out
    Fiddle::TYPE_VOIDP,  # psa : SCRIPT_ANALYSIS* optional
    -Fiddle::TYPE_INT,  # tagScript : DWORD
    -Fiddle::TYPE_INT,  # tagLangSys : DWORD
    -Fiddle::TYPE_INT,  # tagFeature : DWORD
    -Fiddle::TYPE_SHORT,  # wGlyphId : WORD
    Fiddle::TYPE_INT,  # cMaxAlternates : INT
    Fiddle::TYPE_VOIDP,  # pAlternateGlyphs : WORD* out
    Fiddle::TYPE_VOIDP,  # pcAlternates : INT* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "usp10")]
extern "system" {
    fn ScriptGetFontAlternateGlyphs(
        hdc: *mut core::ffi::c_void,  // HDC optional
        psc: *mut *mut (),  // void** in/out
        psa: *mut SCRIPT_ANALYSIS,  // SCRIPT_ANALYSIS* optional
        tagScript: u32,  // DWORD
        tagLangSys: u32,  // DWORD
        tagFeature: u32,  // DWORD
        wGlyphId: u16,  // WORD
        cMaxAlternates: i32,  // INT
        pAlternateGlyphs: *mut u16,  // WORD* out
        pcAlternates: *mut i32  // INT* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USP10.dll")]
public static extern int ScriptGetFontAlternateGlyphs(IntPtr hdc, IntPtr psc, IntPtr psa, uint tagScript, uint tagLangSys, uint tagFeature, ushort wGlyphId, int cMaxAlternates, out ushort pAlternateGlyphs, out int pcAlternates);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USP10_ScriptGetFontAlternateGlyphs' -Namespace Win32 -PassThru
# $api::ScriptGetFontAlternateGlyphs(hdc, psc, psa, tagScript, tagLangSys, tagFeature, wGlyphId, cMaxAlternates, pAlternateGlyphs, pcAlternates)
#uselib "USP10.dll"
#func global ScriptGetFontAlternateGlyphs "ScriptGetFontAlternateGlyphs" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ScriptGetFontAlternateGlyphs hdc, psc, varptr(psa), tagScript, tagLangSys, tagFeature, wGlyphId, cMaxAlternates, varptr(pAlternateGlyphs), varptr(pcAlternates)   ; 戻り値は stat
; hdc : HDC optional -> "sptr"
; psc : void** in/out -> "sptr"
; psa : SCRIPT_ANALYSIS* optional -> "sptr"
; tagScript : DWORD -> "sptr"
; tagLangSys : DWORD -> "sptr"
; tagFeature : DWORD -> "sptr"
; wGlyphId : WORD -> "sptr"
; cMaxAlternates : INT -> "sptr"
; pAlternateGlyphs : WORD* out -> "sptr"
; pcAlternates : INT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USP10.dll"
#cfunc global ScriptGetFontAlternateGlyphs "ScriptGetFontAlternateGlyphs" sptr, sptr, var, int, int, int, int, int, var, var
; res = ScriptGetFontAlternateGlyphs(hdc, psc, psa, tagScript, tagLangSys, tagFeature, wGlyphId, cMaxAlternates, pAlternateGlyphs, pcAlternates)
; hdc : HDC optional -> "sptr"
; psc : void** in/out -> "sptr"
; psa : SCRIPT_ANALYSIS* optional -> "var"
; tagScript : DWORD -> "int"
; tagLangSys : DWORD -> "int"
; tagFeature : DWORD -> "int"
; wGlyphId : WORD -> "int"
; cMaxAlternates : INT -> "int"
; pAlternateGlyphs : WORD* out -> "var"
; pcAlternates : INT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT ScriptGetFontAlternateGlyphs(HDC hdc, void** psc, SCRIPT_ANALYSIS* psa, DWORD tagScript, DWORD tagLangSys, DWORD tagFeature, WORD wGlyphId, INT cMaxAlternates, WORD* pAlternateGlyphs, INT* pcAlternates)
#uselib "USP10.dll"
#cfunc global ScriptGetFontAlternateGlyphs "ScriptGetFontAlternateGlyphs" intptr, intptr, var, int, int, int, int, int, var, var
; res = ScriptGetFontAlternateGlyphs(hdc, psc, psa, tagScript, tagLangSys, tagFeature, wGlyphId, cMaxAlternates, pAlternateGlyphs, pcAlternates)
; hdc : HDC optional -> "intptr"
; psc : void** in/out -> "intptr"
; psa : SCRIPT_ANALYSIS* optional -> "var"
; tagScript : DWORD -> "int"
; tagLangSys : DWORD -> "int"
; tagFeature : DWORD -> "int"
; wGlyphId : WORD -> "int"
; cMaxAlternates : INT -> "int"
; pAlternateGlyphs : WORD* out -> "var"
; pcAlternates : INT* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	usp10 = windows.NewLazySystemDLL("USP10.dll")
	procScriptGetFontAlternateGlyphs = usp10.NewProc("ScriptGetFontAlternateGlyphs")
)

// hdc (HDC optional), psc (void** in/out), psa (SCRIPT_ANALYSIS* optional), tagScript (DWORD), tagLangSys (DWORD), tagFeature (DWORD), wGlyphId (WORD), cMaxAlternates (INT), pAlternateGlyphs (WORD* out), pcAlternates (INT* out)
r1, _, err := procScriptGetFontAlternateGlyphs.Call(
	uintptr(hdc),
	uintptr(psc),
	uintptr(psa),
	uintptr(tagScript),
	uintptr(tagLangSys),
	uintptr(tagFeature),
	uintptr(wGlyphId),
	uintptr(cMaxAlternates),
	uintptr(pAlternateGlyphs),
	uintptr(pcAlternates),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function ScriptGetFontAlternateGlyphs(
  hdc: THandle;   // HDC optional
  psc: Pointer;   // void** in/out
  psa: Pointer;   // SCRIPT_ANALYSIS* optional
  tagScript: DWORD;   // DWORD
  tagLangSys: DWORD;   // DWORD
  tagFeature: DWORD;   // DWORD
  wGlyphId: Word;   // WORD
  cMaxAlternates: Integer;   // INT
  pAlternateGlyphs: Pointer;   // WORD* out
  pcAlternates: Pointer   // INT* out
): Integer; stdcall;
  external 'USP10.dll' name 'ScriptGetFontAlternateGlyphs';
result := DllCall("USP10\ScriptGetFontAlternateGlyphs"
    , "Ptr", hdc   ; HDC optional
    , "Ptr", psc   ; void** in/out
    , "Ptr", psa   ; SCRIPT_ANALYSIS* optional
    , "UInt", tagScript   ; DWORD
    , "UInt", tagLangSys   ; DWORD
    , "UInt", tagFeature   ; DWORD
    , "UShort", wGlyphId   ; WORD
    , "Int", cMaxAlternates   ; INT
    , "Ptr", pAlternateGlyphs   ; WORD* out
    , "Ptr", pcAlternates   ; INT* out
    , "Int")   ; return: HRESULT
●ScriptGetFontAlternateGlyphs(hdc, psc, psa, tagScript, tagLangSys, tagFeature, wGlyphId, cMaxAlternates, pAlternateGlyphs, pcAlternates) = DLL("USP10.dll", "int ScriptGetFontAlternateGlyphs(void*, void*, void*, dword, dword, dword, int, int, void*, void*)")
# 呼び出し: ScriptGetFontAlternateGlyphs(hdc, psc, psa, tagScript, tagLangSys, tagFeature, wGlyphId, cMaxAlternates, pAlternateGlyphs, pcAlternates)
# hdc : HDC optional -> "void*"
# psc : void** in/out -> "void*"
# psa : SCRIPT_ANALYSIS* optional -> "void*"
# tagScript : DWORD -> "dword"
# tagLangSys : DWORD -> "dword"
# tagFeature : DWORD -> "dword"
# wGlyphId : WORD -> "int"
# cMaxAlternates : INT -> "int"
# pAlternateGlyphs : WORD* out -> "void*"
# pcAlternates : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "usp10" fn ScriptGetFontAlternateGlyphs(
    hdc: ?*anyopaque, // HDC optional
    psc: ?*anyopaque, // void** in/out
    psa: [*c]SCRIPT_ANALYSIS, // SCRIPT_ANALYSIS* optional
    tagScript: u32, // DWORD
    tagLangSys: u32, // DWORD
    tagFeature: u32, // DWORD
    wGlyphId: u16, // WORD
    cMaxAlternates: i32, // INT
    pAlternateGlyphs: [*c]u16, // WORD* out
    pcAlternates: [*c]i32 // INT* out
) callconv(std.os.windows.WINAPI) i32;
proc ScriptGetFontAlternateGlyphs(
    hdc: pointer,  # HDC optional
    psc: pointer,  # void** in/out
    psa: ptr SCRIPT_ANALYSIS,  # SCRIPT_ANALYSIS* optional
    tagScript: uint32,  # DWORD
    tagLangSys: uint32,  # DWORD
    tagFeature: uint32,  # DWORD
    wGlyphId: uint16,  # WORD
    cMaxAlternates: int32,  # INT
    pAlternateGlyphs: ptr uint16,  # WORD* out
    pcAlternates: ptr int32  # INT* out
): int32 {.importc: "ScriptGetFontAlternateGlyphs", stdcall, dynlib: "USP10.dll".}
pragma(lib, "usp10");
extern(Windows)
int ScriptGetFontAlternateGlyphs(
    void* hdc,   // HDC optional
    void** psc,   // void** in/out
    SCRIPT_ANALYSIS* psa,   // SCRIPT_ANALYSIS* optional
    uint tagScript,   // DWORD
    uint tagLangSys,   // DWORD
    uint tagFeature,   // DWORD
    ushort wGlyphId,   // WORD
    int cMaxAlternates,   // INT
    ushort* pAlternateGlyphs,   // WORD* out
    int* pcAlternates   // INT* out
);
ccall((:ScriptGetFontAlternateGlyphs, "USP10.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{SCRIPT_ANALYSIS}, UInt32, UInt32, UInt32, UInt16, Int32, Ptr{UInt16}, Ptr{Int32}),
      hdc, psc, psa, tagScript, tagLangSys, tagFeature, wGlyphId, cMaxAlternates, pAlternateGlyphs, pcAlternates)
# hdc : HDC optional -> Ptr{Cvoid}
# psc : void** in/out -> Ptr{Cvoid}
# psa : SCRIPT_ANALYSIS* optional -> Ptr{SCRIPT_ANALYSIS}
# tagScript : DWORD -> UInt32
# tagLangSys : DWORD -> UInt32
# tagFeature : DWORD -> UInt32
# wGlyphId : WORD -> UInt16
# cMaxAlternates : INT -> Int32
# pAlternateGlyphs : WORD* out -> Ptr{UInt16}
# pcAlternates : INT* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t ScriptGetFontAlternateGlyphs(
    void* hdc,
    void** psc,
    void* psa,
    uint32_t tagScript,
    uint32_t tagLangSys,
    uint32_t tagFeature,
    uint16_t wGlyphId,
    int32_t cMaxAlternates,
    uint16_t* pAlternateGlyphs,
    int32_t* pcAlternates);
]]
local usp10 = ffi.load("usp10")
-- usp10.ScriptGetFontAlternateGlyphs(hdc, psc, psa, tagScript, tagLangSys, tagFeature, wGlyphId, cMaxAlternates, pAlternateGlyphs, pcAlternates)
-- hdc : HDC optional
-- psc : void** in/out
-- psa : SCRIPT_ANALYSIS* optional
-- tagScript : DWORD
-- tagLangSys : DWORD
-- tagFeature : DWORD
-- wGlyphId : WORD
-- cMaxAlternates : INT
-- pAlternateGlyphs : WORD* out
-- pcAlternates : INT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('USP10.dll');
const ScriptGetFontAlternateGlyphs = lib.func('__stdcall', 'ScriptGetFontAlternateGlyphs', 'int32_t', ['void *', 'void *', 'void *', 'uint32_t', 'uint32_t', 'uint32_t', 'uint16_t', 'int32_t', 'uint16_t *', 'int32_t *']);
// ScriptGetFontAlternateGlyphs(hdc, psc, psa, tagScript, tagLangSys, tagFeature, wGlyphId, cMaxAlternates, pAlternateGlyphs, pcAlternates)
// hdc : HDC optional -> 'void *'
// psc : void** in/out -> 'void *'
// psa : SCRIPT_ANALYSIS* optional -> 'void *'
// tagScript : DWORD -> 'uint32_t'
// tagLangSys : DWORD -> 'uint32_t'
// tagFeature : DWORD -> 'uint32_t'
// wGlyphId : WORD -> 'uint16_t'
// cMaxAlternates : INT -> 'int32_t'
// pAlternateGlyphs : WORD* out -> 'uint16_t *'
// pcAlternates : INT* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("USP10.dll", {
  ScriptGetFontAlternateGlyphs: { parameters: ["pointer", "pointer", "pointer", "u32", "u32", "u32", "u16", "i32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.ScriptGetFontAlternateGlyphs(hdc, psc, psa, tagScript, tagLangSys, tagFeature, wGlyphId, cMaxAlternates, pAlternateGlyphs, pcAlternates)
// hdc : HDC optional -> "pointer"
// psc : void** in/out -> "pointer"
// psa : SCRIPT_ANALYSIS* optional -> "pointer"
// tagScript : DWORD -> "u32"
// tagLangSys : DWORD -> "u32"
// tagFeature : DWORD -> "u32"
// wGlyphId : WORD -> "u16"
// cMaxAlternates : INT -> "i32"
// pAlternateGlyphs : WORD* out -> "pointer"
// pcAlternates : INT* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ScriptGetFontAlternateGlyphs(
    void* hdc,
    void** psc,
    void* psa,
    uint32_t tagScript,
    uint32_t tagLangSys,
    uint32_t tagFeature,
    uint16_t wGlyphId,
    int32_t cMaxAlternates,
    uint16_t* pAlternateGlyphs,
    int32_t* pcAlternates);
C, "USP10.dll");
// $ffi->ScriptGetFontAlternateGlyphs(hdc, psc, psa, tagScript, tagLangSys, tagFeature, wGlyphId, cMaxAlternates, pAlternateGlyphs, pcAlternates);
// hdc : HDC optional
// psc : void** in/out
// psa : SCRIPT_ANALYSIS* optional
// tagScript : DWORD
// tagLangSys : DWORD
// tagFeature : DWORD
// wGlyphId : WORD
// cMaxAlternates : INT
// pAlternateGlyphs : WORD* out
// pcAlternates : INT* 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 Usp10 extends StdCallLibrary {
    Usp10 INSTANCE = Native.load("usp10", Usp10.class);
    int ScriptGetFontAlternateGlyphs(
        Pointer hdc,   // HDC optional
        Pointer psc,   // void** in/out
        Pointer psa,   // SCRIPT_ANALYSIS* optional
        int tagScript,   // DWORD
        int tagLangSys,   // DWORD
        int tagFeature,   // DWORD
        short wGlyphId,   // WORD
        int cMaxAlternates,   // INT
        ShortByReference pAlternateGlyphs,   // WORD* out
        IntByReference pcAlternates   // INT* out
    );
}
@[Link("usp10")]
lib LibUSP10
  fun ScriptGetFontAlternateGlyphs = ScriptGetFontAlternateGlyphs(
    hdc : Void*,   # HDC optional
    psc : Void**,   # void** in/out
    psa : SCRIPT_ANALYSIS*,   # SCRIPT_ANALYSIS* optional
    tagScript : UInt32,   # DWORD
    tagLangSys : UInt32,   # DWORD
    tagFeature : UInt32,   # DWORD
    wGlyphId : UInt16,   # WORD
    cMaxAlternates : Int32,   # INT
    pAlternateGlyphs : UInt16*,   # WORD* out
    pcAlternates : Int32*   # INT* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ScriptGetFontAlternateGlyphsNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint32, Uint32, Uint32, Uint16, Int32, Pointer<Uint16>, Pointer<Int32>);
typedef ScriptGetFontAlternateGlyphsDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int, int, int, int, int, Pointer<Uint16>, Pointer<Int32>);
final ScriptGetFontAlternateGlyphs = DynamicLibrary.open('USP10.dll')
    .lookupFunction<ScriptGetFontAlternateGlyphsNative, ScriptGetFontAlternateGlyphsDart>('ScriptGetFontAlternateGlyphs');
// hdc : HDC optional -> Pointer<Void>
// psc : void** in/out -> Pointer<Void>
// psa : SCRIPT_ANALYSIS* optional -> Pointer<Void>
// tagScript : DWORD -> Uint32
// tagLangSys : DWORD -> Uint32
// tagFeature : DWORD -> Uint32
// wGlyphId : WORD -> Uint16
// cMaxAlternates : INT -> Int32
// pAlternateGlyphs : WORD* out -> Pointer<Uint16>
// pcAlternates : INT* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ScriptGetFontAlternateGlyphs(
  hdc: THandle;   // HDC optional
  psc: Pointer;   // void** in/out
  psa: Pointer;   // SCRIPT_ANALYSIS* optional
  tagScript: DWORD;   // DWORD
  tagLangSys: DWORD;   // DWORD
  tagFeature: DWORD;   // DWORD
  wGlyphId: Word;   // WORD
  cMaxAlternates: Integer;   // INT
  pAlternateGlyphs: Pointer;   // WORD* out
  pcAlternates: Pointer   // INT* out
): Integer; stdcall;
  external 'USP10.dll' name 'ScriptGetFontAlternateGlyphs';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ScriptGetFontAlternateGlyphs"
  c_ScriptGetFontAlternateGlyphs :: Ptr () -> Ptr () -> Ptr () -> Word32 -> Word32 -> Word32 -> Word16 -> Int32 -> Ptr Word16 -> Ptr Int32 -> IO Int32
-- hdc : HDC optional -> Ptr ()
-- psc : void** in/out -> Ptr ()
-- psa : SCRIPT_ANALYSIS* optional -> Ptr ()
-- tagScript : DWORD -> Word32
-- tagLangSys : DWORD -> Word32
-- tagFeature : DWORD -> Word32
-- wGlyphId : WORD -> Word16
-- cMaxAlternates : INT -> Int32
-- pAlternateGlyphs : WORD* out -> Ptr Word16
-- pcAlternates : INT* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let scriptgetfontalternateglyphs =
  foreign "ScriptGetFontAlternateGlyphs"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> uint32_t @-> uint32_t @-> uint32_t @-> uint16_t @-> int32_t @-> (ptr uint16_t) @-> (ptr int32_t) @-> returning int32_t)
(* hdc : HDC optional -> (ptr void) *)
(* psc : void** in/out -> (ptr void) *)
(* psa : SCRIPT_ANALYSIS* optional -> (ptr void) *)
(* tagScript : DWORD -> uint32_t *)
(* tagLangSys : DWORD -> uint32_t *)
(* tagFeature : DWORD -> uint32_t *)
(* wGlyphId : WORD -> uint16_t *)
(* cMaxAlternates : INT -> int32_t *)
(* pAlternateGlyphs : WORD* out -> (ptr uint16_t) *)
(* pcAlternates : INT* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library usp10 (t "USP10.dll"))
(cffi:use-foreign-library usp10)

(cffi:defcfun ("ScriptGetFontAlternateGlyphs" script-get-font-alternate-glyphs :convention :stdcall) :int32
  (hdc :pointer)   ; HDC optional
  (psc :pointer)   ; void** in/out
  (psa :pointer)   ; SCRIPT_ANALYSIS* optional
  (tag-script :uint32)   ; DWORD
  (tag-lang-sys :uint32)   ; DWORD
  (tag-feature :uint32)   ; DWORD
  (w-glyph-id :uint16)   ; WORD
  (c-max-alternates :int32)   ; INT
  (p-alternate-glyphs :pointer)   ; WORD* out
  (pc-alternates :pointer))   ; INT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ScriptGetFontAlternateGlyphs = Win32::API::More->new('USP10',
    'int ScriptGetFontAlternateGlyphs(HANDLE hdc, LPVOID psc, LPVOID psa, DWORD tagScript, DWORD tagLangSys, DWORD tagFeature, WORD wGlyphId, int cMaxAlternates, LPVOID pAlternateGlyphs, LPVOID pcAlternates)');
# my $ret = $ScriptGetFontAlternateGlyphs->Call($hdc, $psc, $psa, $tagScript, $tagLangSys, $tagFeature, $wGlyphId, $cMaxAlternates, $pAlternateGlyphs, $pcAlternates);
# hdc : HDC optional -> HANDLE
# psc : void** in/out -> LPVOID
# psa : SCRIPT_ANALYSIS* optional -> LPVOID
# tagScript : DWORD -> DWORD
# tagLangSys : DWORD -> DWORD
# tagFeature : DWORD -> DWORD
# wGlyphId : WORD -> WORD
# cMaxAlternates : INT -> int
# pAlternateGlyphs : WORD* out -> LPVOID
# pcAlternates : INT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型