ScriptBreak
関数シグネチャ
// USP10.dll
#include <windows.h>
HRESULT ScriptBreak(
LPCWSTR pwcChars,
INT cChars,
const SCRIPT_ANALYSIS* psa,
SCRIPT_LOGATTR* psla
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pwcChars | LPCWSTR | in | 処理する Unicode 文字へのポインター。 |
| cChars | INT | in | 処理する Unicode 文字の数。 |
| psa | SCRIPT_ANALYSIS* | in | 以前の ScriptItemize の呼び出しで取得した SCRIPT_ANALYSIS 構造体へのポインター。 |
| psla | SCRIPT_LOGATTR* | out | この関数が文字属性を SCRIPT_LOGATTR 構造体として取得するバッファーへのポインター。 |
戻り値の型: HRESULT
公式ドキュメント
改行位置を決定するための情報を取得します。
戻り値
成功した場合は 0 を返します。成功しなかった場合は、0 以外の HRESULT 値を返します。アプリケーションは SUCCEEDED マクロおよび FAILED マクロを使用して戻り値をテストできます。
解説(Remarks)
この関数が通常呼び出される文脈については、Displaying Text with Uniscribe を参照してください。
この関数はデバイス コンテキストを必要とせず、グリフ シェーピングも行いません。
この関数は、SCRIPT_LOGATTR 構造体の配列内の項目について、カーソル移動位置と書式上の改行位置を取得します。1 つの単語内に複数の書式が混在する場合に正しく処理するには、ScriptBreak の呼び出しでは、より細かい書式ランではなく、ScriptItemize で取得した項目全体を渡す必要があります。
SCRIPT_LOGATTR 構造体は、有効なキャレット位置と改行位置を示します。fCharStop メンバーは、クラスター内部への移動が慣例的に制限されているスクリプトについて、クラスター境界を示すフラグを指定します。同じ境界は、ScriptShape で取得した論理クラスター情報を調べることでも推測できます。ただし、ScriptBreak は実装上かなり高速であり、デバイス コンテキストの準備を必要としません。
SCRIPT_LOGATTR の fWordStop、fSoftBreak、fWhiteSpace の各メンバーで指定されるフラグは、ScriptBreak を通じてのみ取得できます。
無効なシーケンスを識別するほとんどのシェーピング エンジンは、ScriptBreak において SCRIPT_LOGATTR の fInvalid メンバーで示されるフラグを設定します。SCRIPT_PROPERTIES の fInvalidLogAttr メンバーは、該当するスクリプトを識別します。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// USP10.dll
#include <windows.h>
HRESULT ScriptBreak(
LPCWSTR pwcChars,
INT cChars,
const SCRIPT_ANALYSIS* psa,
SCRIPT_LOGATTR* psla
);[DllImport("USP10.dll", ExactSpelling = true)]
static extern int ScriptBreak(
[MarshalAs(UnmanagedType.LPWStr)] string pwcChars, // LPCWSTR
int cChars, // INT
IntPtr psa, // SCRIPT_ANALYSIS*
IntPtr psla // SCRIPT_LOGATTR* out
);<DllImport("USP10.dll", ExactSpelling:=True)>
Public Shared Function ScriptBreak(
<MarshalAs(UnmanagedType.LPWStr)> pwcChars As String, ' LPCWSTR
cChars As Integer, ' INT
psa As IntPtr, ' SCRIPT_ANALYSIS*
psla As IntPtr ' SCRIPT_LOGATTR* out
) As Integer
End Function' pwcChars : LPCWSTR
' cChars : INT
' psa : SCRIPT_ANALYSIS*
' psla : SCRIPT_LOGATTR* out
Declare PtrSafe Function ScriptBreak Lib "usp10" ( _
ByVal pwcChars As LongPtr, _
ByVal cChars As Long, _
ByVal psa As LongPtr, _
ByVal psla As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ScriptBreak = ctypes.windll.usp10.ScriptBreak
ScriptBreak.restype = ctypes.c_int
ScriptBreak.argtypes = [
wintypes.LPCWSTR, # pwcChars : LPCWSTR
ctypes.c_int, # cChars : INT
ctypes.c_void_p, # psa : SCRIPT_ANALYSIS*
ctypes.c_void_p, # psla : SCRIPT_LOGATTR* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USP10.dll')
ScriptBreak = Fiddle::Function.new(
lib['ScriptBreak'],
[
Fiddle::TYPE_VOIDP, # pwcChars : LPCWSTR
Fiddle::TYPE_INT, # cChars : INT
Fiddle::TYPE_VOIDP, # psa : SCRIPT_ANALYSIS*
Fiddle::TYPE_VOIDP, # psla : SCRIPT_LOGATTR* out
],
Fiddle::TYPE_INT)#[link(name = "usp10")]
extern "system" {
fn ScriptBreak(
pwcChars: *const u16, // LPCWSTR
cChars: i32, // INT
psa: *const SCRIPT_ANALYSIS, // SCRIPT_ANALYSIS*
psla: *mut SCRIPT_LOGATTR // SCRIPT_LOGATTR* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USP10.dll")]
public static extern int ScriptBreak([MarshalAs(UnmanagedType.LPWStr)] string pwcChars, int cChars, IntPtr psa, IntPtr psla);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USP10_ScriptBreak' -Namespace Win32 -PassThru
# $api::ScriptBreak(pwcChars, cChars, psa, psla)#uselib "USP10.dll"
#func global ScriptBreak "ScriptBreak" sptr, sptr, sptr, sptr
; ScriptBreak pwcChars, cChars, varptr(psa), varptr(psla) ; 戻り値は stat
; pwcChars : LPCWSTR -> "sptr"
; cChars : INT -> "sptr"
; psa : SCRIPT_ANALYSIS* -> "sptr"
; psla : SCRIPT_LOGATTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USP10.dll" #cfunc global ScriptBreak "ScriptBreak" wstr, int, var, var ; res = ScriptBreak(pwcChars, cChars, psa, psla) ; pwcChars : LPCWSTR -> "wstr" ; cChars : INT -> "int" ; psa : SCRIPT_ANALYSIS* -> "var" ; psla : SCRIPT_LOGATTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "USP10.dll" #cfunc global ScriptBreak "ScriptBreak" wstr, int, sptr, sptr ; res = ScriptBreak(pwcChars, cChars, varptr(psa), varptr(psla)) ; pwcChars : LPCWSTR -> "wstr" ; cChars : INT -> "int" ; psa : SCRIPT_ANALYSIS* -> "sptr" ; psla : SCRIPT_LOGATTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; HRESULT ScriptBreak(LPCWSTR pwcChars, INT cChars, SCRIPT_ANALYSIS* psa, SCRIPT_LOGATTR* psla) #uselib "USP10.dll" #cfunc global ScriptBreak "ScriptBreak" wstr, int, var, var ; res = ScriptBreak(pwcChars, cChars, psa, psla) ; pwcChars : LPCWSTR -> "wstr" ; cChars : INT -> "int" ; psa : SCRIPT_ANALYSIS* -> "var" ; psla : SCRIPT_LOGATTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT ScriptBreak(LPCWSTR pwcChars, INT cChars, SCRIPT_ANALYSIS* psa, SCRIPT_LOGATTR* psla) #uselib "USP10.dll" #cfunc global ScriptBreak "ScriptBreak" wstr, int, intptr, intptr ; res = ScriptBreak(pwcChars, cChars, varptr(psa), varptr(psla)) ; pwcChars : LPCWSTR -> "wstr" ; cChars : INT -> "int" ; psa : SCRIPT_ANALYSIS* -> "intptr" ; psla : SCRIPT_LOGATTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
usp10 = windows.NewLazySystemDLL("USP10.dll")
procScriptBreak = usp10.NewProc("ScriptBreak")
)
// pwcChars (LPCWSTR), cChars (INT), psa (SCRIPT_ANALYSIS*), psla (SCRIPT_LOGATTR* out)
r1, _, err := procScriptBreak.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwcChars))),
uintptr(cChars),
uintptr(psa),
uintptr(psla),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction ScriptBreak(
pwcChars: PWideChar; // LPCWSTR
cChars: Integer; // INT
psa: Pointer; // SCRIPT_ANALYSIS*
psla: Pointer // SCRIPT_LOGATTR* out
): Integer; stdcall;
external 'USP10.dll' name 'ScriptBreak';result := DllCall("USP10\ScriptBreak"
, "WStr", pwcChars ; LPCWSTR
, "Int", cChars ; INT
, "Ptr", psa ; SCRIPT_ANALYSIS*
, "Ptr", psla ; SCRIPT_LOGATTR* out
, "Int") ; return: HRESULT●ScriptBreak(pwcChars, cChars, psa, psla) = DLL("USP10.dll", "int ScriptBreak(char*, int, void*, void*)")
# 呼び出し: ScriptBreak(pwcChars, cChars, psa, psla)
# pwcChars : LPCWSTR -> "char*"
# cChars : INT -> "int"
# psa : SCRIPT_ANALYSIS* -> "void*"
# psla : SCRIPT_LOGATTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "usp10" fn ScriptBreak(
pwcChars: [*c]const u16, // LPCWSTR
cChars: i32, // INT
psa: [*c]SCRIPT_ANALYSIS, // SCRIPT_ANALYSIS*
psla: [*c]SCRIPT_LOGATTR // SCRIPT_LOGATTR* out
) callconv(std.os.windows.WINAPI) i32;proc ScriptBreak(
pwcChars: WideCString, # LPCWSTR
cChars: int32, # INT
psa: ptr SCRIPT_ANALYSIS, # SCRIPT_ANALYSIS*
psla: ptr SCRIPT_LOGATTR # SCRIPT_LOGATTR* out
): int32 {.importc: "ScriptBreak", stdcall, dynlib: "USP10.dll".}pragma(lib, "usp10");
extern(Windows)
int ScriptBreak(
const(wchar)* pwcChars, // LPCWSTR
int cChars, // INT
SCRIPT_ANALYSIS* psa, // SCRIPT_ANALYSIS*
SCRIPT_LOGATTR* psla // SCRIPT_LOGATTR* out
);ccall((:ScriptBreak, "USP10.dll"), stdcall, Int32,
(Cwstring, Int32, Ptr{SCRIPT_ANALYSIS}, Ptr{SCRIPT_LOGATTR}),
pwcChars, cChars, psa, psla)
# pwcChars : LPCWSTR -> Cwstring
# cChars : INT -> Int32
# psa : SCRIPT_ANALYSIS* -> Ptr{SCRIPT_ANALYSIS}
# psla : SCRIPT_LOGATTR* out -> Ptr{SCRIPT_LOGATTR}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ScriptBreak(
const uint16_t* pwcChars,
int32_t cChars,
void* psa,
void* psla);
]]
local usp10 = ffi.load("usp10")
-- usp10.ScriptBreak(pwcChars, cChars, psa, psla)
-- pwcChars : LPCWSTR
-- cChars : INT
-- psa : SCRIPT_ANALYSIS*
-- psla : SCRIPT_LOGATTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('USP10.dll');
const ScriptBreak = lib.func('__stdcall', 'ScriptBreak', 'int32_t', ['str16', 'int32_t', 'void *', 'void *']);
// ScriptBreak(pwcChars, cChars, psa, psla)
// pwcChars : LPCWSTR -> 'str16'
// cChars : INT -> 'int32_t'
// psa : SCRIPT_ANALYSIS* -> 'void *'
// psla : SCRIPT_LOGATTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("USP10.dll", {
ScriptBreak: { parameters: ["buffer", "i32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.ScriptBreak(pwcChars, cChars, psa, psla)
// pwcChars : LPCWSTR -> "buffer"
// cChars : INT -> "i32"
// psa : SCRIPT_ANALYSIS* -> "pointer"
// psla : SCRIPT_LOGATTR* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ScriptBreak(
const uint16_t* pwcChars,
int32_t cChars,
void* psa,
void* psla);
C, "USP10.dll");
// $ffi->ScriptBreak(pwcChars, cChars, psa, psla);
// pwcChars : LPCWSTR
// cChars : INT
// psa : SCRIPT_ANALYSIS*
// psla : SCRIPT_LOGATTR* 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 ScriptBreak(
WString pwcChars, // LPCWSTR
int cChars, // INT
Pointer psa, // SCRIPT_ANALYSIS*
Pointer psla // SCRIPT_LOGATTR* out
);
}@[Link("usp10")]
lib LibUSP10
fun ScriptBreak = ScriptBreak(
pwcChars : UInt16*, # LPCWSTR
cChars : Int32, # INT
psa : SCRIPT_ANALYSIS*, # SCRIPT_ANALYSIS*
psla : SCRIPT_LOGATTR* # SCRIPT_LOGATTR* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ScriptBreakNative = Int32 Function(Pointer<Utf16>, Int32, Pointer<Void>, Pointer<Void>);
typedef ScriptBreakDart = int Function(Pointer<Utf16>, int, Pointer<Void>, Pointer<Void>);
final ScriptBreak = DynamicLibrary.open('USP10.dll')
.lookupFunction<ScriptBreakNative, ScriptBreakDart>('ScriptBreak');
// pwcChars : LPCWSTR -> Pointer<Utf16>
// cChars : INT -> Int32
// psa : SCRIPT_ANALYSIS* -> Pointer<Void>
// psla : SCRIPT_LOGATTR* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ScriptBreak(
pwcChars: PWideChar; // LPCWSTR
cChars: Integer; // INT
psa: Pointer; // SCRIPT_ANALYSIS*
psla: Pointer // SCRIPT_LOGATTR* out
): Integer; stdcall;
external 'USP10.dll' name 'ScriptBreak';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ScriptBreak"
c_ScriptBreak :: CWString -> Int32 -> Ptr () -> Ptr () -> IO Int32
-- pwcChars : LPCWSTR -> CWString
-- cChars : INT -> Int32
-- psa : SCRIPT_ANALYSIS* -> Ptr ()
-- psla : SCRIPT_LOGATTR* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let scriptbreak =
foreign "ScriptBreak"
((ptr uint16_t) @-> int32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* pwcChars : LPCWSTR -> (ptr uint16_t) *)
(* cChars : INT -> int32_t *)
(* psa : SCRIPT_ANALYSIS* -> (ptr void) *)
(* psla : SCRIPT_LOGATTR* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library usp10 (t "USP10.dll"))
(cffi:use-foreign-library usp10)
(cffi:defcfun ("ScriptBreak" script-break :convention :stdcall) :int32
(pwc-chars (:string :encoding :utf-16le)) ; LPCWSTR
(c-chars :int32) ; INT
(psa :pointer) ; SCRIPT_ANALYSIS*
(psla :pointer)) ; SCRIPT_LOGATTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ScriptBreak = Win32::API::More->new('USP10',
'int ScriptBreak(LPCWSTR pwcChars, int cChars, LPVOID psa, LPVOID psla)');
# my $ret = $ScriptBreak->Call($pwcChars, $cChars, $psa, $psla);
# pwcChars : LPCWSTR -> LPCWSTR
# cChars : INT -> int
# psa : SCRIPT_ANALYSIS* -> LPVOID
# psla : SCRIPT_LOGATTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f ScriptItemize — 文字列をスクリプト単位のアイテムに分割する。
- f ScriptShape — 文字列をグリフ列に整形(シェイピング)する。