ScriptShape
関数シグネチャ
// USP10.dll
#include <windows.h>
HRESULT ScriptShape(
HDC hdc,
void** psc,
LPCWSTR pwcChars,
INT cChars,
INT cMaxGlyphs,
SCRIPT_ANALYSIS* psa,
WORD* pwOutGlyphs,
WORD* pwLogClust,
SCRIPT_VISATTR* psva,
INT* pcGlyphs
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdc | HDC | in | 省略可能。デバイスコンテキストへのハンドル。詳細については、Caching を参照してください。 |
| psc | void** | inout | スクリプトキャッシュを識別する SCRIPT_CACHE 構造体へのポインター。 |
| pwcChars | LPCWSTR | in | ランを定義する Unicode 文字の配列へのポインター。 |
| cChars | INT | in | Unicode ラン内の文字数。 |
| cMaxGlyphs | INT | in | 生成するグリフの最大数であり、pwOutGlyphs の長さでもあります。妥当な値は (1.5 * cChars + 16) ですが、状況によってはこの値では不十分な場合があります。詳細については、「解説」セクションを参照してください。 |
| psa | SCRIPT_ANALYSIS* | inout | ランに対する SCRIPT_ANALYSIS 構造体へのポインター。これには、以前の ScriptItemize の呼び出しの結果が格納されています。 |
| pwOutGlyphs | WORD* | out | cMaxGlyphs で示されるサイズのグリフ配列を、この関数が取得するバッファーへのポインター。 |
| pwLogClust | WORD* | out | 論理クラスター情報の配列を、この関数が取得するバッファーへのポインター。各配列要素は Unicode 文字配列内の文字に対応するため、この配列の要素数は cChars で示される数になります。各要素の値は、ラン内の最初のグリフから、対応する文字を含むクラスター内の最初のグリフまでのオフセットです。SCRIPT_ANALYSIS 構造体で fRTL メンバーが TRUE に設定されている場合、配列を読み進めるにつれて要素の値が減少することに注意してください。 |
| psva | SCRIPT_VISATTR* | out | 視覚的属性情報を含む SCRIPT_VISATTR 構造体の配列を、この関数が取得するバッファーへのポインター。各グリフは 1 つの視覚的属性のみを持つため、この配列の要素数は cMaxGlyphs で示される数になります。 |
| pcGlyphs | INT* | out | pwOutGlyphs に示されるグリフ数を、この関数が取得する場所へのポインター。 |
戻り値の型: HRESULT
公式ドキュメント
Unicode のランに対するグリフと視覚的属性を生成します。
戻り値
成功した場合は 0 を返します。成功しなかった場合は、0 以外の HRESULT 値を返します。すべてのエラーの場合、すべての出力パラメーターの内容は未定義です。
エラーの戻り値には次のものが含まれます。
- E_OUTOFMEMORY。cMaxGlyphs で示される出力バッファーの長さが不十分です。
- E_PENDING。psc パラメーターで指定されたスクリプトキャッシュに、文字列を整形するための十分な情報が含まれておらず、かつデバイスコンテキストが NULL として渡されているため、関数は整形処理を完了できません。アプリケーションは、ランに対する正しいデバイスコンテキストを設定し、hdc に適切な値を指定して、その他のすべてのパラメーターは同じ状態で、この関数を再度呼び出す必要があります。
- USP_E_SCRIPT_NOT_IN_FONT。デバイスコンテキストに対応するフォントが、pwcChars で示されるランに必要なスクリプトをサポートしていません。アプリケーションは、ScriptGetCMap または別の関数を使用して、別のフォントを選択する必要があります。
解説(Remarks)
この関数が通常呼び出される文脈についての説明は、Displaying Text with Uniscribe を参照してください。
この関数が E_OUTOFMEMORY を返した場合、アプリケーションは出力バッファーを順次大きくしながら、十分な大きさのバッファーが用意されるまで ScriptShape を繰り返し呼び出すことができます。コードポイントから生成されるグリフ数は、スクリプトとフォントによって異なります。単純なスクリプトの場合、1 つの Unicode コードポイントが 1 つのグリフを生成することがあります。しかし、複雑なスクリプトのフォントでは、複数のコンポーネントから文字を構成することがあり、その結果、文字数の数倍のグリフを生成する場合があります。また、無効な文字表現など、無効なシーケンスを表すために追加のグリフが付加される特殊なケースもあります。したがって、pwOutGlyphs で示されるバッファーのサイズの妥当な見積もりは、文字バッファーの長さの 1.5 倍に、無効なシーケンスの表現などのまれなケースのために追加の 16 グリフを加えた値です。
フォントまたはオペレーティングシステムがグリフインデックスをサポートできない場合、この関数は SCRIPT_ANALYSIS 構造体の fNoGlyphIndex メンバーを設定することがあります。
アプリケーションは、特定の文字列内の文字をフォントがサポートしているかどうかを判断するために ScriptShape を呼び出すことができます。関数が S_OK を返した場合、アプリケーションは出力に欠落グリフがないか確認する必要があります。SCRIPT_ANALYSIS 構造体で fLogicalOrder が TRUE に設定されている場合、関数は常に元の Unicode 文字と同じ順序でグリフを生成します。fLogicalOrder が FALSE に設定されている場合、関数は右から左方向の項目を逆順で生成するため、ScriptTextOut は ExtTextOut を呼び出す前にそれらを逆順にする必要がありません。
SCRIPT_ANALYSIS の eScript メンバーが SCRIPT_UNDEFINED に設定されている場合、整形は無効になります。この場合、ScriptShape はフォントの cmap テーブル内にあるグリフを表示します。テーブルにグリフがない場合、関数はグリフが欠落していることを示します。
ScriptShape は、ラン内のクラスターを一様に順序付け、クラスター内のグリフを一様に順序付けます。順序付けを左から右方向と右から左方向のいずれにするかを識別するために、ScriptItemize による SCRIPT_ANALYSIS の fRTL メンバーの値を使用します。
例
次の例は、ScriptShape が文字配列 (pwcChars) とグリフ配列 (pwOutGlyphs) から論理クラスター配列 (pwLogClust) をどのように生成するかを示しています。このランには 4 つのクラスターがあります。
- 1 番目のクラスター: 1 個のグリフで表される 1 文字
- 2 番目のクラスター: 3 個のグリフで表される 1 文字
- 3 番目のクラスター: 1 個のグリフで表される 3 文字
- 4 番目のクラスター: 3 個のグリフで表される 2 文字
- | c1u1 | c2u1 | c3u1 c3u2 c3u3 | c4u1 c4u2 |
- | c1g1 | c2g1 c2g2 c2g3 | c3g1 | c4g1 c4g2 c4g3 |
- | 0 | 1 | 4 4 4 | 5 5 |
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USP10.dll
#include <windows.h>
HRESULT ScriptShape(
HDC hdc,
void** psc,
LPCWSTR pwcChars,
INT cChars,
INT cMaxGlyphs,
SCRIPT_ANALYSIS* psa,
WORD* pwOutGlyphs,
WORD* pwLogClust,
SCRIPT_VISATTR* psva,
INT* pcGlyphs
);[DllImport("USP10.dll", ExactSpelling = true)]
static extern int ScriptShape(
IntPtr hdc, // HDC
IntPtr psc, // void** in/out
[MarshalAs(UnmanagedType.LPWStr)] string pwcChars, // LPCWSTR
int cChars, // INT
int cMaxGlyphs, // INT
IntPtr psa, // SCRIPT_ANALYSIS* in/out
out ushort pwOutGlyphs, // WORD* out
out ushort pwLogClust, // WORD* out
IntPtr psva, // SCRIPT_VISATTR* out
out int pcGlyphs // INT* out
);<DllImport("USP10.dll", ExactSpelling:=True)>
Public Shared Function ScriptShape(
hdc As IntPtr, ' HDC
psc As IntPtr, ' void** in/out
<MarshalAs(UnmanagedType.LPWStr)> pwcChars As String, ' LPCWSTR
cChars As Integer, ' INT
cMaxGlyphs As Integer, ' INT
psa As IntPtr, ' SCRIPT_ANALYSIS* in/out
<Out> ByRef pwOutGlyphs As UShort, ' WORD* out
<Out> ByRef pwLogClust As UShort, ' WORD* out
psva As IntPtr, ' SCRIPT_VISATTR* out
<Out> ByRef pcGlyphs As Integer ' INT* out
) As Integer
End Function' hdc : HDC
' psc : void** in/out
' pwcChars : LPCWSTR
' cChars : INT
' cMaxGlyphs : INT
' psa : SCRIPT_ANALYSIS* in/out
' pwOutGlyphs : WORD* out
' pwLogClust : WORD* out
' psva : SCRIPT_VISATTR* out
' pcGlyphs : INT* out
Declare PtrSafe Function ScriptShape Lib "usp10" ( _
ByVal hdc As LongPtr, _
ByVal psc As LongPtr, _
ByVal pwcChars As LongPtr, _
ByVal cChars As Long, _
ByVal cMaxGlyphs As Long, _
ByVal psa As LongPtr, _
ByRef pwOutGlyphs As Integer, _
ByRef pwLogClust As Integer, _
ByVal psva As LongPtr, _
ByRef pcGlyphs As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ScriptShape = ctypes.windll.usp10.ScriptShape
ScriptShape.restype = ctypes.c_int
ScriptShape.argtypes = [
wintypes.HANDLE, # hdc : HDC
ctypes.c_void_p, # psc : void** in/out
wintypes.LPCWSTR, # pwcChars : LPCWSTR
ctypes.c_int, # cChars : INT
ctypes.c_int, # cMaxGlyphs : INT
ctypes.c_void_p, # psa : SCRIPT_ANALYSIS* in/out
ctypes.POINTER(ctypes.c_ushort), # pwOutGlyphs : WORD* out
ctypes.POINTER(ctypes.c_ushort), # pwLogClust : WORD* out
ctypes.c_void_p, # psva : SCRIPT_VISATTR* out
ctypes.POINTER(ctypes.c_int), # pcGlyphs : INT* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USP10.dll')
ScriptShape = Fiddle::Function.new(
lib['ScriptShape'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_VOIDP, # psc : void** in/out
Fiddle::TYPE_VOIDP, # pwcChars : LPCWSTR
Fiddle::TYPE_INT, # cChars : INT
Fiddle::TYPE_INT, # cMaxGlyphs : INT
Fiddle::TYPE_VOIDP, # psa : SCRIPT_ANALYSIS* in/out
Fiddle::TYPE_VOIDP, # pwOutGlyphs : WORD* out
Fiddle::TYPE_VOIDP, # pwLogClust : WORD* out
Fiddle::TYPE_VOIDP, # psva : SCRIPT_VISATTR* out
Fiddle::TYPE_VOIDP, # pcGlyphs : INT* out
],
Fiddle::TYPE_INT)#[link(name = "usp10")]
extern "system" {
fn ScriptShape(
hdc: *mut core::ffi::c_void, // HDC
psc: *mut *mut (), // void** in/out
pwcChars: *const u16, // LPCWSTR
cChars: i32, // INT
cMaxGlyphs: i32, // INT
psa: *mut SCRIPT_ANALYSIS, // SCRIPT_ANALYSIS* in/out
pwOutGlyphs: *mut u16, // WORD* out
pwLogClust: *mut u16, // WORD* out
psva: *mut SCRIPT_VISATTR, // SCRIPT_VISATTR* out
pcGlyphs: *mut i32 // INT* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USP10.dll")]
public static extern int ScriptShape(IntPtr hdc, IntPtr psc, [MarshalAs(UnmanagedType.LPWStr)] string pwcChars, int cChars, int cMaxGlyphs, IntPtr psa, out ushort pwOutGlyphs, out ushort pwLogClust, IntPtr psva, out int pcGlyphs);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USP10_ScriptShape' -Namespace Win32 -PassThru
# $api::ScriptShape(hdc, psc, pwcChars, cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs)#uselib "USP10.dll"
#func global ScriptShape "ScriptShape" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ScriptShape hdc, psc, pwcChars, cChars, cMaxGlyphs, varptr(psa), varptr(pwOutGlyphs), varptr(pwLogClust), varptr(psva), varptr(pcGlyphs) ; 戻り値は stat
; hdc : HDC -> "sptr"
; psc : void** in/out -> "sptr"
; pwcChars : LPCWSTR -> "sptr"
; cChars : INT -> "sptr"
; cMaxGlyphs : INT -> "sptr"
; psa : SCRIPT_ANALYSIS* in/out -> "sptr"
; pwOutGlyphs : WORD* out -> "sptr"
; pwLogClust : WORD* out -> "sptr"
; psva : SCRIPT_VISATTR* out -> "sptr"
; pcGlyphs : INT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USP10.dll" #cfunc global ScriptShape "ScriptShape" sptr, sptr, wstr, int, int, var, var, var, var, var ; res = ScriptShape(hdc, psc, pwcChars, cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs) ; hdc : HDC -> "sptr" ; psc : void** in/out -> "sptr" ; pwcChars : LPCWSTR -> "wstr" ; cChars : INT -> "int" ; cMaxGlyphs : INT -> "int" ; psa : SCRIPT_ANALYSIS* in/out -> "var" ; pwOutGlyphs : WORD* out -> "var" ; pwLogClust : WORD* out -> "var" ; psva : SCRIPT_VISATTR* out -> "var" ; pcGlyphs : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USP10.dll" #cfunc global ScriptShape "ScriptShape" sptr, sptr, wstr, int, int, sptr, sptr, sptr, sptr, sptr ; res = ScriptShape(hdc, psc, pwcChars, cChars, cMaxGlyphs, varptr(psa), varptr(pwOutGlyphs), varptr(pwLogClust), varptr(psva), varptr(pcGlyphs)) ; hdc : HDC -> "sptr" ; psc : void** in/out -> "sptr" ; pwcChars : LPCWSTR -> "wstr" ; cChars : INT -> "int" ; cMaxGlyphs : INT -> "int" ; psa : SCRIPT_ANALYSIS* in/out -> "sptr" ; pwOutGlyphs : WORD* out -> "sptr" ; pwLogClust : WORD* out -> "sptr" ; psva : SCRIPT_VISATTR* out -> "sptr" ; pcGlyphs : INT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; HRESULT ScriptShape(HDC hdc, void** psc, LPCWSTR pwcChars, INT cChars, INT cMaxGlyphs, SCRIPT_ANALYSIS* psa, WORD* pwOutGlyphs, WORD* pwLogClust, SCRIPT_VISATTR* psva, INT* pcGlyphs) #uselib "USP10.dll" #cfunc global ScriptShape "ScriptShape" intptr, intptr, wstr, int, int, var, var, var, var, var ; res = ScriptShape(hdc, psc, pwcChars, cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs) ; hdc : HDC -> "intptr" ; psc : void** in/out -> "intptr" ; pwcChars : LPCWSTR -> "wstr" ; cChars : INT -> "int" ; cMaxGlyphs : INT -> "int" ; psa : SCRIPT_ANALYSIS* in/out -> "var" ; pwOutGlyphs : WORD* out -> "var" ; pwLogClust : WORD* out -> "var" ; psva : SCRIPT_VISATTR* out -> "var" ; pcGlyphs : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT ScriptShape(HDC hdc, void** psc, LPCWSTR pwcChars, INT cChars, INT cMaxGlyphs, SCRIPT_ANALYSIS* psa, WORD* pwOutGlyphs, WORD* pwLogClust, SCRIPT_VISATTR* psva, INT* pcGlyphs) #uselib "USP10.dll" #cfunc global ScriptShape "ScriptShape" intptr, intptr, wstr, int, int, intptr, intptr, intptr, intptr, intptr ; res = ScriptShape(hdc, psc, pwcChars, cChars, cMaxGlyphs, varptr(psa), varptr(pwOutGlyphs), varptr(pwLogClust), varptr(psva), varptr(pcGlyphs)) ; hdc : HDC -> "intptr" ; psc : void** in/out -> "intptr" ; pwcChars : LPCWSTR -> "wstr" ; cChars : INT -> "int" ; cMaxGlyphs : INT -> "int" ; psa : SCRIPT_ANALYSIS* in/out -> "intptr" ; pwOutGlyphs : WORD* out -> "intptr" ; pwLogClust : WORD* out -> "intptr" ; psva : SCRIPT_VISATTR* out -> "intptr" ; pcGlyphs : INT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
usp10 = windows.NewLazySystemDLL("USP10.dll")
procScriptShape = usp10.NewProc("ScriptShape")
)
// hdc (HDC), psc (void** in/out), pwcChars (LPCWSTR), cChars (INT), cMaxGlyphs (INT), psa (SCRIPT_ANALYSIS* in/out), pwOutGlyphs (WORD* out), pwLogClust (WORD* out), psva (SCRIPT_VISATTR* out), pcGlyphs (INT* out)
r1, _, err := procScriptShape.Call(
uintptr(hdc),
uintptr(psc),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwcChars))),
uintptr(cChars),
uintptr(cMaxGlyphs),
uintptr(psa),
uintptr(pwOutGlyphs),
uintptr(pwLogClust),
uintptr(psva),
uintptr(pcGlyphs),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction ScriptShape(
hdc: THandle; // HDC
psc: Pointer; // void** in/out
pwcChars: PWideChar; // LPCWSTR
cChars: Integer; // INT
cMaxGlyphs: Integer; // INT
psa: Pointer; // SCRIPT_ANALYSIS* in/out
pwOutGlyphs: Pointer; // WORD* out
pwLogClust: Pointer; // WORD* out
psva: Pointer; // SCRIPT_VISATTR* out
pcGlyphs: Pointer // INT* out
): Integer; stdcall;
external 'USP10.dll' name 'ScriptShape';result := DllCall("USP10\ScriptShape"
, "Ptr", hdc ; HDC
, "Ptr", psc ; void** in/out
, "WStr", pwcChars ; LPCWSTR
, "Int", cChars ; INT
, "Int", cMaxGlyphs ; INT
, "Ptr", psa ; SCRIPT_ANALYSIS* in/out
, "Ptr", pwOutGlyphs ; WORD* out
, "Ptr", pwLogClust ; WORD* out
, "Ptr", psva ; SCRIPT_VISATTR* out
, "Ptr", pcGlyphs ; INT* out
, "Int") ; return: HRESULT●ScriptShape(hdc, psc, pwcChars, cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs) = DLL("USP10.dll", "int ScriptShape(void*, void*, char*, int, int, void*, void*, void*, void*, void*)")
# 呼び出し: ScriptShape(hdc, psc, pwcChars, cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs)
# hdc : HDC -> "void*"
# psc : void** in/out -> "void*"
# pwcChars : LPCWSTR -> "char*"
# cChars : INT -> "int"
# cMaxGlyphs : INT -> "int"
# psa : SCRIPT_ANALYSIS* in/out -> "void*"
# pwOutGlyphs : WORD* out -> "void*"
# pwLogClust : WORD* out -> "void*"
# psva : SCRIPT_VISATTR* out -> "void*"
# pcGlyphs : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "usp10" fn ScriptShape(
hdc: ?*anyopaque, // HDC
psc: ?*anyopaque, // void** in/out
pwcChars: [*c]const u16, // LPCWSTR
cChars: i32, // INT
cMaxGlyphs: i32, // INT
psa: [*c]SCRIPT_ANALYSIS, // SCRIPT_ANALYSIS* in/out
pwOutGlyphs: [*c]u16, // WORD* out
pwLogClust: [*c]u16, // WORD* out
psva: [*c]SCRIPT_VISATTR, // SCRIPT_VISATTR* out
pcGlyphs: [*c]i32 // INT* out
) callconv(std.os.windows.WINAPI) i32;proc ScriptShape(
hdc: pointer, # HDC
psc: pointer, # void** in/out
pwcChars: WideCString, # LPCWSTR
cChars: int32, # INT
cMaxGlyphs: int32, # INT
psa: ptr SCRIPT_ANALYSIS, # SCRIPT_ANALYSIS* in/out
pwOutGlyphs: ptr uint16, # WORD* out
pwLogClust: ptr uint16, # WORD* out
psva: ptr SCRIPT_VISATTR, # SCRIPT_VISATTR* out
pcGlyphs: ptr int32 # INT* out
): int32 {.importc: "ScriptShape", stdcall, dynlib: "USP10.dll".}pragma(lib, "usp10");
extern(Windows)
int ScriptShape(
void* hdc, // HDC
void** psc, // void** in/out
const(wchar)* pwcChars, // LPCWSTR
int cChars, // INT
int cMaxGlyphs, // INT
SCRIPT_ANALYSIS* psa, // SCRIPT_ANALYSIS* in/out
ushort* pwOutGlyphs, // WORD* out
ushort* pwLogClust, // WORD* out
SCRIPT_VISATTR* psva, // SCRIPT_VISATTR* out
int* pcGlyphs // INT* out
);ccall((:ScriptShape, "USP10.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Cwstring, Int32, Int32, Ptr{SCRIPT_ANALYSIS}, Ptr{UInt16}, Ptr{UInt16}, Ptr{SCRIPT_VISATTR}, Ptr{Int32}),
hdc, psc, pwcChars, cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs)
# hdc : HDC -> Ptr{Cvoid}
# psc : void** in/out -> Ptr{Cvoid}
# pwcChars : LPCWSTR -> Cwstring
# cChars : INT -> Int32
# cMaxGlyphs : INT -> Int32
# psa : SCRIPT_ANALYSIS* in/out -> Ptr{SCRIPT_ANALYSIS}
# pwOutGlyphs : WORD* out -> Ptr{UInt16}
# pwLogClust : WORD* out -> Ptr{UInt16}
# psva : SCRIPT_VISATTR* out -> Ptr{SCRIPT_VISATTR}
# pcGlyphs : INT* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ScriptShape(
void* hdc,
void** psc,
const uint16_t* pwcChars,
int32_t cChars,
int32_t cMaxGlyphs,
void* psa,
uint16_t* pwOutGlyphs,
uint16_t* pwLogClust,
void* psva,
int32_t* pcGlyphs);
]]
local usp10 = ffi.load("usp10")
-- usp10.ScriptShape(hdc, psc, pwcChars, cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs)
-- hdc : HDC
-- psc : void** in/out
-- pwcChars : LPCWSTR
-- cChars : INT
-- cMaxGlyphs : INT
-- psa : SCRIPT_ANALYSIS* in/out
-- pwOutGlyphs : WORD* out
-- pwLogClust : WORD* out
-- psva : SCRIPT_VISATTR* out
-- pcGlyphs : INT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USP10.dll');
const ScriptShape = lib.func('__stdcall', 'ScriptShape', 'int32_t', ['void *', 'void *', 'str16', 'int32_t', 'int32_t', 'void *', 'uint16_t *', 'uint16_t *', 'void *', 'int32_t *']);
// ScriptShape(hdc, psc, pwcChars, cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs)
// hdc : HDC -> 'void *'
// psc : void** in/out -> 'void *'
// pwcChars : LPCWSTR -> 'str16'
// cChars : INT -> 'int32_t'
// cMaxGlyphs : INT -> 'int32_t'
// psa : SCRIPT_ANALYSIS* in/out -> 'void *'
// pwOutGlyphs : WORD* out -> 'uint16_t *'
// pwLogClust : WORD* out -> 'uint16_t *'
// psva : SCRIPT_VISATTR* out -> 'void *'
// pcGlyphs : INT* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USP10.dll", {
ScriptShape: { parameters: ["pointer", "pointer", "buffer", "i32", "i32", "pointer", "pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.ScriptShape(hdc, psc, pwcChars, cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs)
// hdc : HDC -> "pointer"
// psc : void** in/out -> "pointer"
// pwcChars : LPCWSTR -> "buffer"
// cChars : INT -> "i32"
// cMaxGlyphs : INT -> "i32"
// psa : SCRIPT_ANALYSIS* in/out -> "pointer"
// pwOutGlyphs : WORD* out -> "pointer"
// pwLogClust : WORD* out -> "pointer"
// psva : SCRIPT_VISATTR* out -> "pointer"
// pcGlyphs : INT* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ScriptShape(
void* hdc,
void** psc,
const uint16_t* pwcChars,
int32_t cChars,
int32_t cMaxGlyphs,
void* psa,
uint16_t* pwOutGlyphs,
uint16_t* pwLogClust,
void* psva,
int32_t* pcGlyphs);
C, "USP10.dll");
// $ffi->ScriptShape(hdc, psc, pwcChars, cChars, cMaxGlyphs, psa, pwOutGlyphs, pwLogClust, psva, pcGlyphs);
// hdc : HDC
// psc : void** in/out
// pwcChars : LPCWSTR
// cChars : INT
// cMaxGlyphs : INT
// psa : SCRIPT_ANALYSIS* in/out
// pwOutGlyphs : WORD* out
// pwLogClust : WORD* out
// psva : SCRIPT_VISATTR* out
// pcGlyphs : 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 ScriptShape(
Pointer hdc, // HDC
Pointer psc, // void** in/out
WString pwcChars, // LPCWSTR
int cChars, // INT
int cMaxGlyphs, // INT
Pointer psa, // SCRIPT_ANALYSIS* in/out
ShortByReference pwOutGlyphs, // WORD* out
ShortByReference pwLogClust, // WORD* out
Pointer psva, // SCRIPT_VISATTR* out
IntByReference pcGlyphs // INT* out
);
}@[Link("usp10")]
lib LibUSP10
fun ScriptShape = ScriptShape(
hdc : Void*, # HDC
psc : Void**, # void** in/out
pwcChars : UInt16*, # LPCWSTR
cChars : Int32, # INT
cMaxGlyphs : Int32, # INT
psa : SCRIPT_ANALYSIS*, # SCRIPT_ANALYSIS* in/out
pwOutGlyphs : UInt16*, # WORD* out
pwLogClust : UInt16*, # WORD* out
psva : SCRIPT_VISATTR*, # SCRIPT_VISATTR* out
pcGlyphs : 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 ScriptShapeNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Int32, Int32, Pointer<Void>, Pointer<Uint16>, Pointer<Uint16>, Pointer<Void>, Pointer<Int32>);
typedef ScriptShapeDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, int, int, Pointer<Void>, Pointer<Uint16>, Pointer<Uint16>, Pointer<Void>, Pointer<Int32>);
final ScriptShape = DynamicLibrary.open('USP10.dll')
.lookupFunction<ScriptShapeNative, ScriptShapeDart>('ScriptShape');
// hdc : HDC -> Pointer<Void>
// psc : void** in/out -> Pointer<Void>
// pwcChars : LPCWSTR -> Pointer<Utf16>
// cChars : INT -> Int32
// cMaxGlyphs : INT -> Int32
// psa : SCRIPT_ANALYSIS* in/out -> Pointer<Void>
// pwOutGlyphs : WORD* out -> Pointer<Uint16>
// pwLogClust : WORD* out -> Pointer<Uint16>
// psva : SCRIPT_VISATTR* out -> Pointer<Void>
// pcGlyphs : INT* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ScriptShape(
hdc: THandle; // HDC
psc: Pointer; // void** in/out
pwcChars: PWideChar; // LPCWSTR
cChars: Integer; // INT
cMaxGlyphs: Integer; // INT
psa: Pointer; // SCRIPT_ANALYSIS* in/out
pwOutGlyphs: Pointer; // WORD* out
pwLogClust: Pointer; // WORD* out
psva: Pointer; // SCRIPT_VISATTR* out
pcGlyphs: Pointer // INT* out
): Integer; stdcall;
external 'USP10.dll' name 'ScriptShape';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ScriptShape"
c_ScriptShape :: Ptr () -> Ptr () -> CWString -> Int32 -> Int32 -> Ptr () -> Ptr Word16 -> Ptr Word16 -> Ptr () -> Ptr Int32 -> IO Int32
-- hdc : HDC -> Ptr ()
-- psc : void** in/out -> Ptr ()
-- pwcChars : LPCWSTR -> CWString
-- cChars : INT -> Int32
-- cMaxGlyphs : INT -> Int32
-- psa : SCRIPT_ANALYSIS* in/out -> Ptr ()
-- pwOutGlyphs : WORD* out -> Ptr Word16
-- pwLogClust : WORD* out -> Ptr Word16
-- psva : SCRIPT_VISATTR* out -> Ptr ()
-- pcGlyphs : INT* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let scriptshape =
foreign "ScriptShape"
((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> int32_t @-> int32_t @-> (ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> (ptr int32_t) @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* psc : void** in/out -> (ptr void) *)
(* pwcChars : LPCWSTR -> (ptr uint16_t) *)
(* cChars : INT -> int32_t *)
(* cMaxGlyphs : INT -> int32_t *)
(* psa : SCRIPT_ANALYSIS* in/out -> (ptr void) *)
(* pwOutGlyphs : WORD* out -> (ptr uint16_t) *)
(* pwLogClust : WORD* out -> (ptr uint16_t) *)
(* psva : SCRIPT_VISATTR* out -> (ptr void) *)
(* pcGlyphs : 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 ("ScriptShape" script-shape :convention :stdcall) :int32
(hdc :pointer) ; HDC
(psc :pointer) ; void** in/out
(pwc-chars (:string :encoding :utf-16le)) ; LPCWSTR
(c-chars :int32) ; INT
(c-max-glyphs :int32) ; INT
(psa :pointer) ; SCRIPT_ANALYSIS* in/out
(pw-out-glyphs :pointer) ; WORD* out
(pw-log-clust :pointer) ; WORD* out
(psva :pointer) ; SCRIPT_VISATTR* out
(pc-glyphs :pointer)) ; INT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ScriptShape = Win32::API::More->new('USP10',
'int ScriptShape(HANDLE hdc, LPVOID psc, LPCWSTR pwcChars, int cChars, int cMaxGlyphs, LPVOID psa, LPVOID pwOutGlyphs, LPVOID pwLogClust, LPVOID psva, LPVOID pcGlyphs)');
# my $ret = $ScriptShape->Call($hdc, $psc, $pwcChars, $cChars, $cMaxGlyphs, $psa, $pwOutGlyphs, $pwLogClust, $psva, $pcGlyphs);
# hdc : HDC -> HANDLE
# psc : void** in/out -> LPVOID
# pwcChars : LPCWSTR -> LPCWSTR
# cChars : INT -> int
# cMaxGlyphs : INT -> int
# psa : SCRIPT_ANALYSIS* in/out -> LPVOID
# pwOutGlyphs : WORD* out -> LPVOID
# pwLogClust : WORD* out -> LPVOID
# psva : SCRIPT_VISATTR* out -> LPVOID
# pcGlyphs : INT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f ScriptItemize — 文字列をスクリプト単位のアイテムに分割する。
- f ScriptShapeOpenType — OpenType機能を用いて文字列をグリフ列に整形する。
- f ScriptTextOut — 整形済みグリフ列をデバイスコンテキストに描画する。