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

ScriptGetLogicalWidths

関数
グリフ幅から各文字の論理幅を算出する。
DLLUSP10.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT ScriptGetLogicalWidths(
    const SCRIPT_ANALYSIS* psa,
    INT cChars,
    INT cGlyphs,
    const INT* piGlyphWidth,
    const WORD* pwLogClust,
    const SCRIPT_VISATTR* psva,
    INT* piDx
);

パラメーター

名前方向説明
psaSCRIPT_ANALYSIS*inSCRIPT_ANALYSIS 構造体へのポインター。
cCharsINTinラン内の論理コードポイントの数。
cGlyphsINTinラン内のグリフの数。
piGlyphWidthINT*inグリフ送り幅の配列へのポインター。
pwLogClustWORD*in論理クラスターの配列へのポインター。
psvaSCRIPT_VISATTR*in視覚属性を定義する SCRIPT_VISATTR 構造体へのポインター。
piDxINT*in論理幅の配列へのポインター。

戻り値の型: HRESULT

公式ドキュメント

特定のフォントのグリフ送り幅を論理幅に変換します。

戻り値

現在はすべての場合で S_OK を返します。

解説(Remarks)

この関数は、幅をフォントに依存しない形で記録するのに役立ちます。特定のフォントに対して計算されたグリフ送り幅を、コードポイントと同じ順序で、コードポイントごとに 1 つずつの論理幅に変換します。同じ文字列を別のフォントを使用して別のデバイス上に表示する場合、ScriptApplyLogicalWidth を使用してこの論理幅を適用することで、元の配置を近似できます。この仕組みは印刷プレビューを実装する際に役立ちます。プレビュー画面では、最終的な印刷結果のレイアウトと配置を一致させることが重要です。

注意 合字グリフの幅は、それが表す文字間で均等に分割されます。
重要 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 ScriptGetLogicalWidths(
    const SCRIPT_ANALYSIS* psa,
    INT cChars,
    INT cGlyphs,
    const INT* piGlyphWidth,
    const WORD* pwLogClust,
    const SCRIPT_VISATTR* psva,
    INT* piDx
);
[DllImport("USP10.dll", ExactSpelling = true)]
static extern int ScriptGetLogicalWidths(
    IntPtr psa,   // SCRIPT_ANALYSIS*
    int cChars,   // INT
    int cGlyphs,   // INT
    ref int piGlyphWidth,   // INT*
    ref ushort pwLogClust,   // WORD*
    IntPtr psva,   // SCRIPT_VISATTR*
    ref int piDx   // INT*
);
<DllImport("USP10.dll", ExactSpelling:=True)>
Public Shared Function ScriptGetLogicalWidths(
    psa As IntPtr,   ' SCRIPT_ANALYSIS*
    cChars As Integer,   ' INT
    cGlyphs As Integer,   ' INT
    ByRef piGlyphWidth As Integer,   ' INT*
    ByRef pwLogClust As UShort,   ' WORD*
    psva As IntPtr,   ' SCRIPT_VISATTR*
    ByRef piDx As Integer   ' INT*
) As Integer
End Function
' psa : SCRIPT_ANALYSIS*
' cChars : INT
' cGlyphs : INT
' piGlyphWidth : INT*
' pwLogClust : WORD*
' psva : SCRIPT_VISATTR*
' piDx : INT*
Declare PtrSafe Function ScriptGetLogicalWidths Lib "usp10" ( _
    ByVal psa As LongPtr, _
    ByVal cChars As Long, _
    ByVal cGlyphs As Long, _
    ByRef piGlyphWidth As Long, _
    ByRef pwLogClust As Integer, _
    ByVal psva As LongPtr, _
    ByRef piDx As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ScriptGetLogicalWidths = ctypes.windll.usp10.ScriptGetLogicalWidths
ScriptGetLogicalWidths.restype = ctypes.c_int
ScriptGetLogicalWidths.argtypes = [
    ctypes.c_void_p,  # psa : SCRIPT_ANALYSIS*
    ctypes.c_int,  # cChars : INT
    ctypes.c_int,  # cGlyphs : INT
    ctypes.POINTER(ctypes.c_int),  # piGlyphWidth : INT*
    ctypes.POINTER(ctypes.c_ushort),  # pwLogClust : WORD*
    ctypes.c_void_p,  # psva : SCRIPT_VISATTR*
    ctypes.POINTER(ctypes.c_int),  # piDx : INT*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USP10.dll')
ScriptGetLogicalWidths = Fiddle::Function.new(
  lib['ScriptGetLogicalWidths'],
  [
    Fiddle::TYPE_VOIDP,  # psa : SCRIPT_ANALYSIS*
    Fiddle::TYPE_INT,  # cChars : INT
    Fiddle::TYPE_INT,  # cGlyphs : INT
    Fiddle::TYPE_VOIDP,  # piGlyphWidth : INT*
    Fiddle::TYPE_VOIDP,  # pwLogClust : WORD*
    Fiddle::TYPE_VOIDP,  # psva : SCRIPT_VISATTR*
    Fiddle::TYPE_VOIDP,  # piDx : INT*
  ],
  Fiddle::TYPE_INT)
#[link(name = "usp10")]
extern "system" {
    fn ScriptGetLogicalWidths(
        psa: *const SCRIPT_ANALYSIS,  // SCRIPT_ANALYSIS*
        cChars: i32,  // INT
        cGlyphs: i32,  // INT
        piGlyphWidth: *const i32,  // INT*
        pwLogClust: *const u16,  // WORD*
        psva: *const SCRIPT_VISATTR,  // SCRIPT_VISATTR*
        piDx: *mut i32  // INT*
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USP10.dll")]
public static extern int ScriptGetLogicalWidths(IntPtr psa, int cChars, int cGlyphs, ref int piGlyphWidth, ref ushort pwLogClust, IntPtr psva, ref int piDx);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USP10_ScriptGetLogicalWidths' -Namespace Win32 -PassThru
# $api::ScriptGetLogicalWidths(psa, cChars, cGlyphs, piGlyphWidth, pwLogClust, psva, piDx)
#uselib "USP10.dll"
#func global ScriptGetLogicalWidths "ScriptGetLogicalWidths" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ScriptGetLogicalWidths varptr(psa), cChars, cGlyphs, varptr(piGlyphWidth), varptr(pwLogClust), varptr(psva), varptr(piDx)   ; 戻り値は stat
; psa : SCRIPT_ANALYSIS* -> "sptr"
; cChars : INT -> "sptr"
; cGlyphs : INT -> "sptr"
; piGlyphWidth : INT* -> "sptr"
; pwLogClust : WORD* -> "sptr"
; psva : SCRIPT_VISATTR* -> "sptr"
; piDx : INT* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USP10.dll"
#cfunc global ScriptGetLogicalWidths "ScriptGetLogicalWidths" var, int, int, var, var, var, var
; res = ScriptGetLogicalWidths(psa, cChars, cGlyphs, piGlyphWidth, pwLogClust, psva, piDx)
; psa : SCRIPT_ANALYSIS* -> "var"
; cChars : INT -> "int"
; cGlyphs : INT -> "int"
; piGlyphWidth : INT* -> "var"
; pwLogClust : WORD* -> "var"
; psva : SCRIPT_VISATTR* -> "var"
; piDx : INT* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT ScriptGetLogicalWidths(SCRIPT_ANALYSIS* psa, INT cChars, INT cGlyphs, INT* piGlyphWidth, WORD* pwLogClust, SCRIPT_VISATTR* psva, INT* piDx)
#uselib "USP10.dll"
#cfunc global ScriptGetLogicalWidths "ScriptGetLogicalWidths" var, int, int, var, var, var, var
; res = ScriptGetLogicalWidths(psa, cChars, cGlyphs, piGlyphWidth, pwLogClust, psva, piDx)
; psa : SCRIPT_ANALYSIS* -> "var"
; cChars : INT -> "int"
; cGlyphs : INT -> "int"
; piGlyphWidth : INT* -> "var"
; pwLogClust : WORD* -> "var"
; psva : SCRIPT_VISATTR* -> "var"
; piDx : INT* -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	usp10 = windows.NewLazySystemDLL("USP10.dll")
	procScriptGetLogicalWidths = usp10.NewProc("ScriptGetLogicalWidths")
)

// psa (SCRIPT_ANALYSIS*), cChars (INT), cGlyphs (INT), piGlyphWidth (INT*), pwLogClust (WORD*), psva (SCRIPT_VISATTR*), piDx (INT*)
r1, _, err := procScriptGetLogicalWidths.Call(
	uintptr(psa),
	uintptr(cChars),
	uintptr(cGlyphs),
	uintptr(piGlyphWidth),
	uintptr(pwLogClust),
	uintptr(psva),
	uintptr(piDx),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function ScriptGetLogicalWidths(
  psa: Pointer;   // SCRIPT_ANALYSIS*
  cChars: Integer;   // INT
  cGlyphs: Integer;   // INT
  piGlyphWidth: Pointer;   // INT*
  pwLogClust: Pointer;   // WORD*
  psva: Pointer;   // SCRIPT_VISATTR*
  piDx: Pointer   // INT*
): Integer; stdcall;
  external 'USP10.dll' name 'ScriptGetLogicalWidths';
result := DllCall("USP10\ScriptGetLogicalWidths"
    , "Ptr", psa   ; SCRIPT_ANALYSIS*
    , "Int", cChars   ; INT
    , "Int", cGlyphs   ; INT
    , "Ptr", piGlyphWidth   ; INT*
    , "Ptr", pwLogClust   ; WORD*
    , "Ptr", psva   ; SCRIPT_VISATTR*
    , "Ptr", piDx   ; INT*
    , "Int")   ; return: HRESULT
●ScriptGetLogicalWidths(psa, cChars, cGlyphs, piGlyphWidth, pwLogClust, psva, piDx) = DLL("USP10.dll", "int ScriptGetLogicalWidths(void*, int, int, void*, void*, void*, void*)")
# 呼び出し: ScriptGetLogicalWidths(psa, cChars, cGlyphs, piGlyphWidth, pwLogClust, psva, piDx)
# psa : SCRIPT_ANALYSIS* -> "void*"
# cChars : INT -> "int"
# cGlyphs : INT -> "int"
# piGlyphWidth : INT* -> "void*"
# pwLogClust : WORD* -> "void*"
# psva : SCRIPT_VISATTR* -> "void*"
# piDx : INT* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef ScriptGetLogicalWidthsNative = Int32 Function(Pointer<Void>, Int32, Int32, Pointer<Int32>, Pointer<Uint16>, Pointer<Void>, Pointer<Int32>);
typedef ScriptGetLogicalWidthsDart = int Function(Pointer<Void>, int, int, Pointer<Int32>, Pointer<Uint16>, Pointer<Void>, Pointer<Int32>);
final ScriptGetLogicalWidths = DynamicLibrary.open('USP10.dll')
    .lookupFunction<ScriptGetLogicalWidthsNative, ScriptGetLogicalWidthsDart>('ScriptGetLogicalWidths');
// psa : SCRIPT_ANALYSIS* -> Pointer<Void>
// cChars : INT -> Int32
// cGlyphs : INT -> Int32
// piGlyphWidth : INT* -> Pointer<Int32>
// pwLogClust : WORD* -> Pointer<Uint16>
// psva : SCRIPT_VISATTR* -> Pointer<Void>
// piDx : INT* -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ScriptGetLogicalWidths(
  psa: Pointer;   // SCRIPT_ANALYSIS*
  cChars: Integer;   // INT
  cGlyphs: Integer;   // INT
  piGlyphWidth: Pointer;   // INT*
  pwLogClust: Pointer;   // WORD*
  psva: Pointer;   // SCRIPT_VISATTR*
  piDx: Pointer   // INT*
): Integer; stdcall;
  external 'USP10.dll' name 'ScriptGetLogicalWidths';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ScriptGetLogicalWidths"
  c_ScriptGetLogicalWidths :: Ptr () -> Int32 -> Int32 -> Ptr Int32 -> Ptr Word16 -> Ptr () -> Ptr Int32 -> IO Int32
-- psa : SCRIPT_ANALYSIS* -> Ptr ()
-- cChars : INT -> Int32
-- cGlyphs : INT -> Int32
-- piGlyphWidth : INT* -> Ptr Int32
-- pwLogClust : WORD* -> Ptr Word16
-- psva : SCRIPT_VISATTR* -> Ptr ()
-- piDx : INT* -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let scriptgetlogicalwidths =
  foreign "ScriptGetLogicalWidths"
    ((ptr void) @-> int32_t @-> int32_t @-> (ptr int32_t) @-> (ptr uint16_t) @-> (ptr void) @-> (ptr int32_t) @-> returning int32_t)
(* psa : SCRIPT_ANALYSIS* -> (ptr void) *)
(* cChars : INT -> int32_t *)
(* cGlyphs : INT -> int32_t *)
(* piGlyphWidth : INT* -> (ptr int32_t) *)
(* pwLogClust : WORD* -> (ptr uint16_t) *)
(* psva : SCRIPT_VISATTR* -> (ptr void) *)
(* piDx : INT* -> (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 ("ScriptGetLogicalWidths" script-get-logical-widths :convention :stdcall) :int32
  (psa :pointer)   ; SCRIPT_ANALYSIS*
  (c-chars :int32)   ; INT
  (c-glyphs :int32)   ; INT
  (pi-glyph-width :pointer)   ; INT*
  (pw-log-clust :pointer)   ; WORD*
  (psva :pointer)   ; SCRIPT_VISATTR*
  (pi-dx :pointer))   ; INT*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ScriptGetLogicalWidths = Win32::API::More->new('USP10',
    'int ScriptGetLogicalWidths(LPVOID psa, int cChars, int cGlyphs, LPVOID piGlyphWidth, LPVOID pwLogClust, LPVOID psva, LPVOID piDx)');
# my $ret = $ScriptGetLogicalWidths->Call($psa, $cChars, $cGlyphs, $piGlyphWidth, $pwLogClust, $psva, $piDx);
# psa : SCRIPT_ANALYSIS* -> LPVOID
# cChars : INT -> int
# cGlyphs : INT -> int
# piGlyphWidth : INT* -> LPVOID
# pwLogClust : WORD* -> LPVOID
# psva : SCRIPT_VISATTR* -> LPVOID
# piDx : INT* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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