ScriptItemizeOpenType
関数シグネチャ
// USP10.dll
#include <windows.h>
HRESULT ScriptItemizeOpenType(
LPCWSTR pwcInChars,
INT cInChars,
INT cMaxItems,
const SCRIPT_CONTROL* psControl, // optional
const SCRIPT_STATE* psState, // optional
SCRIPT_ITEM* pItems,
DWORD* pScriptTags,
INT* pcItems
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pwcInChars | LPCWSTR | in | アイテム化する Unicode 文字列へのポインター。 |
| cInChars | INT | in | アイテム化する pwcInChars 内の文字数。 |
| cMaxItems | INT | in | 処理する項目を定義する SCRIPT_ITEM 構造体の最大数。 |
| psControl | SCRIPT_CONTROL* | inoptional | 実行するアイテム化の種類を示す SCRIPT_CONTROL 構造体へのポインター。 あるいは、SCRIPT_CONTROL プロパティが不要な場合、アプリケーションはこのパラメーターに NULL を設定できます。詳細については、「解説」を参照してください。 |
| psState | SCRIPT_STATE* | inoptional | 双方向アルゴリズムの初期状態を示す SCRIPT_STATE 構造体へのポインター。 あるいは、スクリプト状態が不要な場合、アプリケーションはこのパラメーターに NULL を設定できます。詳細については、「解説」を参照してください。 |
| pItems | SCRIPT_ITEM* | out | 処理された項目を表す SCRIPT_ITEM 構造体を関数が取得するバッファーへのポインター。バッファーの長さは
|
| pScriptTags | DWORD* | out | スクリプトタグを表す OPENTYPE_TAG 構造体の配列を関数が取得するバッファーへのポインター。バッファーの長さは 注意 項目内のすべての文字が中立 (neutral) である場合、このパラメーターの値は SCRIPT_TAG_UNKNOWN (0x00000000) になります。これは、たとえば項目が句読点のみで構成されている場合に発生する可能性があります。
|
| pcItems | INT* | out | 処理された SCRIPT_ITEM 構造体の数へのポインター。 |
戻り値の型: HRESULT
公式ドキュメント
Unicode 文字列を個別にシェーピング可能な項目に分割し、OpenType 処理のために各シェーピング可能項目に対するフィーチャータグの配列を提供します。
戻り値
成功した場合は 0 を返します。成功しなかった場合、関数は 0 以外の HRESULT 値を返します。すべてのエラーケースにおいて、完全に処理される項目はなく、出力のいかなる部分にも定義された値は含まれません。アプリケーションは SUCCEEDED マクロおよび FAILED マクロを使用して戻り値をテストできます。
cMaxItems で示されたサイズが小さすぎる場合、関数は E_OUTOFMEMORY を返します。アプリケーションはより大きなバッファーで関数を再度呼び出すことを試みることができます。
次の条件のいずれか 1 つ以上が発生した場合、関数は E_INVALIDARG を返します。
- pwcInChars が NULL に設定されている
- cInChars が 0 である
- pItems が NULL に設定されている
- pScriptTags が NULL に設定されている
- cMaxItems < 2
解説(Remarks)
ScriptItemizeOpenType は、より古い ScriptItemize 関数よりも推奨されます。ScriptItemizeOpenType の利点の 1 つは、各シェーピング可能項目に対するフィーチャータグが利用できることです。
この関数が通常呼び出されるコンテキストについては、Displaying Text with Uniscribe を参照してください。
この関数は、シェーピングエンジンの変化または方向の変化のいずれかによって項目を区切ります。
アプリケーションは、ScriptItemizeOpenType によって取得された各 SCRIPT_ITEM 構造体から、単一の項目内に完全に収まる複数の範囲 (range) すなわちラン (run) を作成できます。ただし、複数の項目を 1 つのランに結合してはなりません。測定またはレンダリングの際、アプリケーションは各ランに対して ScriptShapeOpenType を呼び出すことができ、ScriptItemizeOpenType によって取得された SCRIPT_ITEM 構造体内の対応する SCRIPT_ANALYSIS 構造体を渡す必要があります。
アプリケーションが扱うテキストに右から左方向のコンテンツが含まれる可能性がある場合、アプリケーションは ScriptItemizeOpenType の呼び出し時に psControl および psState パラメーターを使用します。ただし、これは必須ではなく、アプリケーションは Uniscribe に依存せずに双方向テキストを自身で処理することもできます。psControl および psState パラメーターは、厳密に左から右のシナリオであっても役立つ場合があります。たとえば、SCRIPT_CONTROL の fLinkStringBefore メンバーが右から左方向のスクリプトに固有でない場合などです。アプリケーションが psControl と psState を NULL に設定すると、ScriptItemizeOpenType は文字コードのみによって Unicode 文字列を分割します。
アプリケーションがすべてのパラメーターを NULL 以外の値に設定すると、関数は完全な Unicode 双方向分析を実行します。正しい Unicode 双方向分析を可能にするには、SCRIPT_STATE 構造体を段落先頭の読み順に従って初期化し、ScriptItemizeOpenType に段落全体を渡す必要があります。特に、uBidiLevel メンバーは左から右の場合は 0、右から左の場合は 1 に初期化する必要があります。
SCRIPT_ANALYSIS の fRTL メンバーは SCRIPT_ITEM で参照されます。SCRIPT_PROPERTIES の fNumeric メンバーは ScriptGetProperties によって取得されます。これらのメンバーは合わせて、GetCharacterPlacement の lpResults によって参照される GCP_RESULTS の lpClass メンバーと同じ分類を提供します。
U+0030 から U+0039 までのヨーロッパ数字は、次の表に示すように各国固有の数字としてレンダリングできます。
| SCRIPT_STATE.fDigitSubstitute | SCRIPT_CONTROL.fContextDigits | Unicode U+0030 から U+0039 に対して表示される数字字形 |
|---|---|---|
| FALSE | 任意 | ヨーロッパ数字 |
| TRUE | FALSE | SCRIPT_CONTROL の uDefaultLanguage メンバーで指定されたとおり。 |
| TRUE | TRUE | 直前の強い (strong) テキストに従い、既定では SCRIPT_CONTROL の uDefaultLanguage メンバーに従う。 |
コンテキスト数字モードでは、次のいずれかの動作が発生します。
- uDefaultLanguage で指定されたスクリプトが出力と同じ方向である場合、最初の文字より前に出現するすべての数字は uDefaultLanguage で示される言語でレンダリングされます。
- uDefaultLanguage で指定されたスクリプトが出力と反対の方向である場合、最初の文字より前に出現するすべての数字はヨーロッパ数字でレンダリングされます。
詳細については、Digit Shapes を参照してください。
Unicode 制御文字とその定義、および SCRIPT_STATE メンバーへの影響を次の表に示します。Unicode 制御文字の詳細については、The Unicode Standard を参照してください。
| Unicode 制御文字 | 意味 | SCRIPT_STATE への影響 |
|---|---|---|
| NADS | ヨーロッパ数字 (NODS) を各国固有の数字字形で上書きします。 | fDigitSubstitute を設定します。 |
| NODS | 名目上の数字字形 (ヨーロッパ数字とも呼ばれる) を使用します。NADS を参照してください。 | fDigitSubstitute をクリアします。 |
| ASS | 対称ペア (たとえば括弧) のスワッピングを有効にします。これらの文字では、左と右が開きと閉じとして解釈されます。これが既定です。ISS を参照してください。 | fInhibitSymSwap をクリアします。 |
| ISS | 対称ペアのスワッピングを抑制します。ASS を参照してください。 | fInhibitSymSwap を設定します。 |
| AAFS | アラビア語表示形 (presentation forms) に対するアラビア語字形シェーピングを有効にします。IAFS を参照してください。 | fCharShape を設定します。 |
| IAFS | アラビア語表示形に対するアラビア語字形シェーピング (すなわちリガチャおよび筆記体接続) を抑制します。名目上のアラビア語文字は影響を受けません。これが既定です。AAFS を参照してください。 | fCharShape をクリアします。 |
SCRIPT_STATE の fArabicNumContext メンバーは、アラビア文字テキストにおける数字のコンテキスト依存表示をサポートします。これは、数字がネイティブのアラビア文字数字字形でレンダリングされるか、ヨーロッパ数字でレンダリングされるかを示します。段落の先頭では、このメンバーは通常、アラビア語ロケールの場合は TRUE に、それ以外のロケールの場合は FALSE に初期化する必要があります。関数は強い (strong) テキストを処理する際にスクリプト状態を更新します。
出力パラメーター pScriptTags は、項目に対応するエントリを持つ配列を示します。各項目について、この関数は以降のすべての操作でシェーピングに使用すべきスクリプトタグを取得します。
スクリプトタグは通常、入力文字から ScriptItemizeOpenType によって決定されます。関数が特定のスクリプトタグを取得した場合、アプリケーションはそれを変更せずに他の関数に渡す必要があります。ただし、文字が中立 (neutral) (たとえば数字) でスクリプトを決定できない場合は、アプリケーションが適切なスクリプトタグを選択する必要があります。たとえば、テキストに関連付けられたフォントや言語に基づいて選択します。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USP10.dll
#include <windows.h>
HRESULT ScriptItemizeOpenType(
LPCWSTR pwcInChars,
INT cInChars,
INT cMaxItems,
const SCRIPT_CONTROL* psControl, // optional
const SCRIPT_STATE* psState, // optional
SCRIPT_ITEM* pItems,
DWORD* pScriptTags,
INT* pcItems
);[DllImport("USP10.dll", ExactSpelling = true)]
static extern int ScriptItemizeOpenType(
[MarshalAs(UnmanagedType.LPWStr)] string pwcInChars, // LPCWSTR
int cInChars, // INT
int cMaxItems, // INT
IntPtr psControl, // SCRIPT_CONTROL* optional
IntPtr psState, // SCRIPT_STATE* optional
IntPtr pItems, // SCRIPT_ITEM* out
out uint pScriptTags, // DWORD* out
out int pcItems // INT* out
);<DllImport("USP10.dll", ExactSpelling:=True)>
Public Shared Function ScriptItemizeOpenType(
<MarshalAs(UnmanagedType.LPWStr)> pwcInChars As String, ' LPCWSTR
cInChars As Integer, ' INT
cMaxItems As Integer, ' INT
psControl As IntPtr, ' SCRIPT_CONTROL* optional
psState As IntPtr, ' SCRIPT_STATE* optional
pItems As IntPtr, ' SCRIPT_ITEM* out
<Out> ByRef pScriptTags As UInteger, ' DWORD* out
<Out> ByRef pcItems As Integer ' INT* out
) As Integer
End Function' pwcInChars : LPCWSTR
' cInChars : INT
' cMaxItems : INT
' psControl : SCRIPT_CONTROL* optional
' psState : SCRIPT_STATE* optional
' pItems : SCRIPT_ITEM* out
' pScriptTags : DWORD* out
' pcItems : INT* out
Declare PtrSafe Function ScriptItemizeOpenType Lib "usp10" ( _
ByVal pwcInChars As LongPtr, _
ByVal cInChars As Long, _
ByVal cMaxItems As Long, _
ByVal psControl As LongPtr, _
ByVal psState As LongPtr, _
ByVal pItems As LongPtr, _
ByRef pScriptTags As Long, _
ByRef pcItems As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ScriptItemizeOpenType = ctypes.windll.usp10.ScriptItemizeOpenType
ScriptItemizeOpenType.restype = ctypes.c_int
ScriptItemizeOpenType.argtypes = [
wintypes.LPCWSTR, # pwcInChars : LPCWSTR
ctypes.c_int, # cInChars : INT
ctypes.c_int, # cMaxItems : INT
ctypes.c_void_p, # psControl : SCRIPT_CONTROL* optional
ctypes.c_void_p, # psState : SCRIPT_STATE* optional
ctypes.c_void_p, # pItems : SCRIPT_ITEM* out
ctypes.POINTER(wintypes.DWORD), # pScriptTags : DWORD* out
ctypes.POINTER(ctypes.c_int), # pcItems : INT* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USP10.dll')
ScriptItemizeOpenType = Fiddle::Function.new(
lib['ScriptItemizeOpenType'],
[
Fiddle::TYPE_VOIDP, # pwcInChars : LPCWSTR
Fiddle::TYPE_INT, # cInChars : INT
Fiddle::TYPE_INT, # cMaxItems : INT
Fiddle::TYPE_VOIDP, # psControl : SCRIPT_CONTROL* optional
Fiddle::TYPE_VOIDP, # psState : SCRIPT_STATE* optional
Fiddle::TYPE_VOIDP, # pItems : SCRIPT_ITEM* out
Fiddle::TYPE_VOIDP, # pScriptTags : DWORD* out
Fiddle::TYPE_VOIDP, # pcItems : INT* out
],
Fiddle::TYPE_INT)#[link(name = "usp10")]
extern "system" {
fn ScriptItemizeOpenType(
pwcInChars: *const u16, // LPCWSTR
cInChars: i32, // INT
cMaxItems: i32, // INT
psControl: *const SCRIPT_CONTROL, // SCRIPT_CONTROL* optional
psState: *const SCRIPT_STATE, // SCRIPT_STATE* optional
pItems: *mut SCRIPT_ITEM, // SCRIPT_ITEM* out
pScriptTags: *mut u32, // DWORD* out
pcItems: *mut i32 // INT* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USP10.dll")]
public static extern int ScriptItemizeOpenType([MarshalAs(UnmanagedType.LPWStr)] string pwcInChars, int cInChars, int cMaxItems, IntPtr psControl, IntPtr psState, IntPtr pItems, out uint pScriptTags, out int pcItems);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USP10_ScriptItemizeOpenType' -Namespace Win32 -PassThru
# $api::ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, pScriptTags, pcItems)#uselib "USP10.dll"
#func global ScriptItemizeOpenType "ScriptItemizeOpenType" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ScriptItemizeOpenType pwcInChars, cInChars, cMaxItems, varptr(psControl), varptr(psState), varptr(pItems), varptr(pScriptTags), varptr(pcItems) ; 戻り値は stat
; pwcInChars : LPCWSTR -> "sptr"
; cInChars : INT -> "sptr"
; cMaxItems : INT -> "sptr"
; psControl : SCRIPT_CONTROL* optional -> "sptr"
; psState : SCRIPT_STATE* optional -> "sptr"
; pItems : SCRIPT_ITEM* out -> "sptr"
; pScriptTags : DWORD* out -> "sptr"
; pcItems : INT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USP10.dll" #cfunc global ScriptItemizeOpenType "ScriptItemizeOpenType" wstr, int, int, var, var, var, var, var ; res = ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, pScriptTags, pcItems) ; pwcInChars : LPCWSTR -> "wstr" ; cInChars : INT -> "int" ; cMaxItems : INT -> "int" ; psControl : SCRIPT_CONTROL* optional -> "var" ; psState : SCRIPT_STATE* optional -> "var" ; pItems : SCRIPT_ITEM* out -> "var" ; pScriptTags : DWORD* out -> "var" ; pcItems : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USP10.dll" #cfunc global ScriptItemizeOpenType "ScriptItemizeOpenType" wstr, int, int, sptr, sptr, sptr, sptr, sptr ; res = ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, varptr(psControl), varptr(psState), varptr(pItems), varptr(pScriptTags), varptr(pcItems)) ; pwcInChars : LPCWSTR -> "wstr" ; cInChars : INT -> "int" ; cMaxItems : INT -> "int" ; psControl : SCRIPT_CONTROL* optional -> "sptr" ; psState : SCRIPT_STATE* optional -> "sptr" ; pItems : SCRIPT_ITEM* out -> "sptr" ; pScriptTags : DWORD* out -> "sptr" ; pcItems : INT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; HRESULT ScriptItemizeOpenType(LPCWSTR pwcInChars, INT cInChars, INT cMaxItems, SCRIPT_CONTROL* psControl, SCRIPT_STATE* psState, SCRIPT_ITEM* pItems, DWORD* pScriptTags, INT* pcItems) #uselib "USP10.dll" #cfunc global ScriptItemizeOpenType "ScriptItemizeOpenType" wstr, int, int, var, var, var, var, var ; res = ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, pScriptTags, pcItems) ; pwcInChars : LPCWSTR -> "wstr" ; cInChars : INT -> "int" ; cMaxItems : INT -> "int" ; psControl : SCRIPT_CONTROL* optional -> "var" ; psState : SCRIPT_STATE* optional -> "var" ; pItems : SCRIPT_ITEM* out -> "var" ; pScriptTags : DWORD* out -> "var" ; pcItems : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT ScriptItemizeOpenType(LPCWSTR pwcInChars, INT cInChars, INT cMaxItems, SCRIPT_CONTROL* psControl, SCRIPT_STATE* psState, SCRIPT_ITEM* pItems, DWORD* pScriptTags, INT* pcItems) #uselib "USP10.dll" #cfunc global ScriptItemizeOpenType "ScriptItemizeOpenType" wstr, int, int, intptr, intptr, intptr, intptr, intptr ; res = ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, varptr(psControl), varptr(psState), varptr(pItems), varptr(pScriptTags), varptr(pcItems)) ; pwcInChars : LPCWSTR -> "wstr" ; cInChars : INT -> "int" ; cMaxItems : INT -> "int" ; psControl : SCRIPT_CONTROL* optional -> "intptr" ; psState : SCRIPT_STATE* optional -> "intptr" ; pItems : SCRIPT_ITEM* out -> "intptr" ; pScriptTags : DWORD* out -> "intptr" ; pcItems : INT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
usp10 = windows.NewLazySystemDLL("USP10.dll")
procScriptItemizeOpenType = usp10.NewProc("ScriptItemizeOpenType")
)
// pwcInChars (LPCWSTR), cInChars (INT), cMaxItems (INT), psControl (SCRIPT_CONTROL* optional), psState (SCRIPT_STATE* optional), pItems (SCRIPT_ITEM* out), pScriptTags (DWORD* out), pcItems (INT* out)
r1, _, err := procScriptItemizeOpenType.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwcInChars))),
uintptr(cInChars),
uintptr(cMaxItems),
uintptr(psControl),
uintptr(psState),
uintptr(pItems),
uintptr(pScriptTags),
uintptr(pcItems),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction ScriptItemizeOpenType(
pwcInChars: PWideChar; // LPCWSTR
cInChars: Integer; // INT
cMaxItems: Integer; // INT
psControl: Pointer; // SCRIPT_CONTROL* optional
psState: Pointer; // SCRIPT_STATE* optional
pItems: Pointer; // SCRIPT_ITEM* out
pScriptTags: Pointer; // DWORD* out
pcItems: Pointer // INT* out
): Integer; stdcall;
external 'USP10.dll' name 'ScriptItemizeOpenType';result := DllCall("USP10\ScriptItemizeOpenType"
, "WStr", pwcInChars ; LPCWSTR
, "Int", cInChars ; INT
, "Int", cMaxItems ; INT
, "Ptr", psControl ; SCRIPT_CONTROL* optional
, "Ptr", psState ; SCRIPT_STATE* optional
, "Ptr", pItems ; SCRIPT_ITEM* out
, "Ptr", pScriptTags ; DWORD* out
, "Ptr", pcItems ; INT* out
, "Int") ; return: HRESULT●ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, pScriptTags, pcItems) = DLL("USP10.dll", "int ScriptItemizeOpenType(char*, int, int, void*, void*, void*, void*, void*)")
# 呼び出し: ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, pScriptTags, pcItems)
# pwcInChars : LPCWSTR -> "char*"
# cInChars : INT -> "int"
# cMaxItems : INT -> "int"
# psControl : SCRIPT_CONTROL* optional -> "void*"
# psState : SCRIPT_STATE* optional -> "void*"
# pItems : SCRIPT_ITEM* out -> "void*"
# pScriptTags : DWORD* out -> "void*"
# pcItems : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "usp10" fn ScriptItemizeOpenType(
pwcInChars: [*c]const u16, // LPCWSTR
cInChars: i32, // INT
cMaxItems: i32, // INT
psControl: [*c]SCRIPT_CONTROL, // SCRIPT_CONTROL* optional
psState: [*c]SCRIPT_STATE, // SCRIPT_STATE* optional
pItems: [*c]SCRIPT_ITEM, // SCRIPT_ITEM* out
pScriptTags: [*c]u32, // DWORD* out
pcItems: [*c]i32 // INT* out
) callconv(std.os.windows.WINAPI) i32;proc ScriptItemizeOpenType(
pwcInChars: WideCString, # LPCWSTR
cInChars: int32, # INT
cMaxItems: int32, # INT
psControl: ptr SCRIPT_CONTROL, # SCRIPT_CONTROL* optional
psState: ptr SCRIPT_STATE, # SCRIPT_STATE* optional
pItems: ptr SCRIPT_ITEM, # SCRIPT_ITEM* out
pScriptTags: ptr uint32, # DWORD* out
pcItems: ptr int32 # INT* out
): int32 {.importc: "ScriptItemizeOpenType", stdcall, dynlib: "USP10.dll".}pragma(lib, "usp10");
extern(Windows)
int ScriptItemizeOpenType(
const(wchar)* pwcInChars, // LPCWSTR
int cInChars, // INT
int cMaxItems, // INT
SCRIPT_CONTROL* psControl, // SCRIPT_CONTROL* optional
SCRIPT_STATE* psState, // SCRIPT_STATE* optional
SCRIPT_ITEM* pItems, // SCRIPT_ITEM* out
uint* pScriptTags, // DWORD* out
int* pcItems // INT* out
);ccall((:ScriptItemizeOpenType, "USP10.dll"), stdcall, Int32,
(Cwstring, Int32, Int32, Ptr{SCRIPT_CONTROL}, Ptr{SCRIPT_STATE}, Ptr{SCRIPT_ITEM}, Ptr{UInt32}, Ptr{Int32}),
pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, pScriptTags, pcItems)
# pwcInChars : LPCWSTR -> Cwstring
# cInChars : INT -> Int32
# cMaxItems : INT -> Int32
# psControl : SCRIPT_CONTROL* optional -> Ptr{SCRIPT_CONTROL}
# psState : SCRIPT_STATE* optional -> Ptr{SCRIPT_STATE}
# pItems : SCRIPT_ITEM* out -> Ptr{SCRIPT_ITEM}
# pScriptTags : DWORD* out -> Ptr{UInt32}
# pcItems : INT* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ScriptItemizeOpenType(
const uint16_t* pwcInChars,
int32_t cInChars,
int32_t cMaxItems,
void* psControl,
void* psState,
void* pItems,
uint32_t* pScriptTags,
int32_t* pcItems);
]]
local usp10 = ffi.load("usp10")
-- usp10.ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, pScriptTags, pcItems)
-- pwcInChars : LPCWSTR
-- cInChars : INT
-- cMaxItems : INT
-- psControl : SCRIPT_CONTROL* optional
-- psState : SCRIPT_STATE* optional
-- pItems : SCRIPT_ITEM* out
-- pScriptTags : DWORD* out
-- pcItems : INT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USP10.dll');
const ScriptItemizeOpenType = lib.func('__stdcall', 'ScriptItemizeOpenType', 'int32_t', ['str16', 'int32_t', 'int32_t', 'void *', 'void *', 'void *', 'uint32_t *', 'int32_t *']);
// ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, pScriptTags, pcItems)
// pwcInChars : LPCWSTR -> 'str16'
// cInChars : INT -> 'int32_t'
// cMaxItems : INT -> 'int32_t'
// psControl : SCRIPT_CONTROL* optional -> 'void *'
// psState : SCRIPT_STATE* optional -> 'void *'
// pItems : SCRIPT_ITEM* out -> 'void *'
// pScriptTags : DWORD* out -> 'uint32_t *'
// pcItems : INT* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USP10.dll", {
ScriptItemizeOpenType: { parameters: ["buffer", "i32", "i32", "pointer", "pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, pScriptTags, pcItems)
// pwcInChars : LPCWSTR -> "buffer"
// cInChars : INT -> "i32"
// cMaxItems : INT -> "i32"
// psControl : SCRIPT_CONTROL* optional -> "pointer"
// psState : SCRIPT_STATE* optional -> "pointer"
// pItems : SCRIPT_ITEM* out -> "pointer"
// pScriptTags : DWORD* out -> "pointer"
// pcItems : INT* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ScriptItemizeOpenType(
const uint16_t* pwcInChars,
int32_t cInChars,
int32_t cMaxItems,
void* psControl,
void* psState,
void* pItems,
uint32_t* pScriptTags,
int32_t* pcItems);
C, "USP10.dll");
// $ffi->ScriptItemizeOpenType(pwcInChars, cInChars, cMaxItems, psControl, psState, pItems, pScriptTags, pcItems);
// pwcInChars : LPCWSTR
// cInChars : INT
// cMaxItems : INT
// psControl : SCRIPT_CONTROL* optional
// psState : SCRIPT_STATE* optional
// pItems : SCRIPT_ITEM* out
// pScriptTags : DWORD* out
// pcItems : 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 ScriptItemizeOpenType(
WString pwcInChars, // LPCWSTR
int cInChars, // INT
int cMaxItems, // INT
Pointer psControl, // SCRIPT_CONTROL* optional
Pointer psState, // SCRIPT_STATE* optional
Pointer pItems, // SCRIPT_ITEM* out
IntByReference pScriptTags, // DWORD* out
IntByReference pcItems // INT* out
);
}@[Link("usp10")]
lib LibUSP10
fun ScriptItemizeOpenType = ScriptItemizeOpenType(
pwcInChars : UInt16*, # LPCWSTR
cInChars : Int32, # INT
cMaxItems : Int32, # INT
psControl : SCRIPT_CONTROL*, # SCRIPT_CONTROL* optional
psState : SCRIPT_STATE*, # SCRIPT_STATE* optional
pItems : SCRIPT_ITEM*, # SCRIPT_ITEM* out
pScriptTags : UInt32*, # DWORD* out
pcItems : 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 ScriptItemizeOpenTypeNative = Int32 Function(Pointer<Utf16>, Int32, Int32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Int32>);
typedef ScriptItemizeOpenTypeDart = int Function(Pointer<Utf16>, int, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Int32>);
final ScriptItemizeOpenType = DynamicLibrary.open('USP10.dll')
.lookupFunction<ScriptItemizeOpenTypeNative, ScriptItemizeOpenTypeDart>('ScriptItemizeOpenType');
// pwcInChars : LPCWSTR -> Pointer<Utf16>
// cInChars : INT -> Int32
// cMaxItems : INT -> Int32
// psControl : SCRIPT_CONTROL* optional -> Pointer<Void>
// psState : SCRIPT_STATE* optional -> Pointer<Void>
// pItems : SCRIPT_ITEM* out -> Pointer<Void>
// pScriptTags : DWORD* out -> Pointer<Uint32>
// pcItems : INT* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ScriptItemizeOpenType(
pwcInChars: PWideChar; // LPCWSTR
cInChars: Integer; // INT
cMaxItems: Integer; // INT
psControl: Pointer; // SCRIPT_CONTROL* optional
psState: Pointer; // SCRIPT_STATE* optional
pItems: Pointer; // SCRIPT_ITEM* out
pScriptTags: Pointer; // DWORD* out
pcItems: Pointer // INT* out
): Integer; stdcall;
external 'USP10.dll' name 'ScriptItemizeOpenType';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ScriptItemizeOpenType"
c_ScriptItemizeOpenType :: CWString -> Int32 -> Int32 -> Ptr () -> Ptr () -> Ptr () -> Ptr Word32 -> Ptr Int32 -> IO Int32
-- pwcInChars : LPCWSTR -> CWString
-- cInChars : INT -> Int32
-- cMaxItems : INT -> Int32
-- psControl : SCRIPT_CONTROL* optional -> Ptr ()
-- psState : SCRIPT_STATE* optional -> Ptr ()
-- pItems : SCRIPT_ITEM* out -> Ptr ()
-- pScriptTags : DWORD* out -> Ptr Word32
-- pcItems : INT* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let scriptitemizeopentype =
foreign "ScriptItemizeOpenType"
((ptr uint16_t) @-> int32_t @-> int32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr uint32_t) @-> (ptr int32_t) @-> returning int32_t)
(* pwcInChars : LPCWSTR -> (ptr uint16_t) *)
(* cInChars : INT -> int32_t *)
(* cMaxItems : INT -> int32_t *)
(* psControl : SCRIPT_CONTROL* optional -> (ptr void) *)
(* psState : SCRIPT_STATE* optional -> (ptr void) *)
(* pItems : SCRIPT_ITEM* out -> (ptr void) *)
(* pScriptTags : DWORD* out -> (ptr uint32_t) *)
(* pcItems : 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 ("ScriptItemizeOpenType" script-itemize-open-type :convention :stdcall) :int32
(pwc-in-chars (:string :encoding :utf-16le)) ; LPCWSTR
(c-in-chars :int32) ; INT
(c-max-items :int32) ; INT
(ps-control :pointer) ; SCRIPT_CONTROL* optional
(ps-state :pointer) ; SCRIPT_STATE* optional
(p-items :pointer) ; SCRIPT_ITEM* out
(p-script-tags :pointer) ; DWORD* out
(pc-items :pointer)) ; INT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ScriptItemizeOpenType = Win32::API::More->new('USP10',
'int ScriptItemizeOpenType(LPCWSTR pwcInChars, int cInChars, int cMaxItems, LPVOID psControl, LPVOID psState, LPVOID pItems, LPVOID pScriptTags, LPVOID pcItems)');
# my $ret = $ScriptItemizeOpenType->Call($pwcInChars, $cInChars, $cMaxItems, $psControl, $psState, $pItems, $pScriptTags, $pcItems);
# pwcInChars : LPCWSTR -> LPCWSTR
# cInChars : INT -> int
# cMaxItems : INT -> int
# psControl : SCRIPT_CONTROL* optional -> LPVOID
# psState : SCRIPT_STATE* optional -> LPVOID
# pItems : SCRIPT_ITEM* out -> LPVOID
# pScriptTags : DWORD* out -> LPVOID
# pcItems : INT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- s SCRIPT_ANALYSIS
- f ScriptItemize — 文字列をスクリプト単位のアイテムに分割する。
- f ScriptPlaceOpenType — OpenType機能を用いてグリフの位置と幅を算出する。
- f ScriptShapeOpenType — OpenType機能を用いて文字列をグリフ列に整形する。
- f ScriptSubstituteSingleGlyph — 指定OpenType機能で単一グリフを置換する。