ホーム › Graphics.GdiPlus › GdipMeasureString
GdipMeasureString
関数文字列を描画した際の境界矩形や収まる文字数を測定する。
シグネチャ
// gdiplus.dll
#include <windows.h>
Status GdipMeasureString(
GpGraphics* graphics,
LPCWSTR string,
INT length,
const GpFont* font,
const RectF* layoutRect,
const GpStringFormat* stringFormat,
RectF* boundingBox,
INT* codepointsFitted,
INT* linesFilled
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| graphics | GpGraphics* | inout | 測定の基準とするGpGraphicsオブジェクトへのポインタ。 |
| string | LPCWSTR | in | 測定する文字列を示すワイド文字列。 |
| length | INT | in | 文字列の長さ(文字数)。-1指定でNULL終端まで測定する。 |
| font | GpFont* | in | 測定に使用するGpFontオブジェクトへのポインタ。 |
| layoutRect | RectF* | in | 文字列のレイアウト範囲を示すRectF構造体へのポインタ。 |
| stringFormat | GpStringFormat* | in | 配置や折り返し等を制御するGpStringFormatへのポインタ。NULL可。 |
| boundingBox | RectF* | inout | 測定結果の外接矩形を受け取る出力先のRectFポインタ。 |
| codepointsFitted | INT* | inout | 範囲内に収まった文字数を受け取る出力先のINTポインタ。NULL可。 |
| linesFilled | INT* | inout | 描画された行数を受け取る出力先のINTポインタ。NULL可。 |
戻り値の型: Status
各言語での呼び出し定義
// gdiplus.dll
#include <windows.h>
Status GdipMeasureString(
GpGraphics* graphics,
LPCWSTR string,
INT length,
const GpFont* font,
const RectF* layoutRect,
const GpStringFormat* stringFormat,
RectF* boundingBox,
INT* codepointsFitted,
INT* linesFilled
);[DllImport("gdiplus.dll", ExactSpelling = true)]
static extern int GdipMeasureString(
IntPtr graphics, // GpGraphics* in/out
[MarshalAs(UnmanagedType.LPWStr)] string string, // LPCWSTR
int length, // INT
IntPtr font, // GpFont*
IntPtr layoutRect, // RectF*
IntPtr stringFormat, // GpStringFormat*
IntPtr boundingBox, // RectF* in/out
ref int codepointsFitted, // INT* in/out
ref int linesFilled // INT* in/out
);<DllImport("gdiplus.dll", ExactSpelling:=True)>
Public Shared Function GdipMeasureString(
graphics As IntPtr, ' GpGraphics* in/out
<MarshalAs(UnmanagedType.LPWStr)> [string] As String, ' LPCWSTR
length As Integer, ' INT
font As IntPtr, ' GpFont*
layoutRect As IntPtr, ' RectF*
stringFormat As IntPtr, ' GpStringFormat*
boundingBox As IntPtr, ' RectF* in/out
ByRef codepointsFitted As Integer, ' INT* in/out
ByRef linesFilled As Integer ' INT* in/out
) As Integer
End Function' graphics : GpGraphics* in/out
' string : LPCWSTR
' length : INT
' font : GpFont*
' layoutRect : RectF*
' stringFormat : GpStringFormat*
' boundingBox : RectF* in/out
' codepointsFitted : INT* in/out
' linesFilled : INT* in/out
Declare PtrSafe Function GdipMeasureString Lib "gdiplus" ( _
ByVal graphics As LongPtr, _
ByVal string As LongPtr, _
ByVal length As Long, _
ByVal font As LongPtr, _
ByVal layoutRect As LongPtr, _
ByVal stringFormat As LongPtr, _
ByVal boundingBox As LongPtr, _
ByRef codepointsFitted As Long, _
ByRef linesFilled As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GdipMeasureString = ctypes.windll.gdiplus.GdipMeasureString
GdipMeasureString.restype = ctypes.c_int
GdipMeasureString.argtypes = [
ctypes.c_void_p, # graphics : GpGraphics* in/out
wintypes.LPCWSTR, # string : LPCWSTR
ctypes.c_int, # length : INT
ctypes.c_void_p, # font : GpFont*
ctypes.c_void_p, # layoutRect : RectF*
ctypes.c_void_p, # stringFormat : GpStringFormat*
ctypes.c_void_p, # boundingBox : RectF* in/out
ctypes.POINTER(ctypes.c_int), # codepointsFitted : INT* in/out
ctypes.POINTER(ctypes.c_int), # linesFilled : INT* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('gdiplus.dll')
GdipMeasureString = Fiddle::Function.new(
lib['GdipMeasureString'],
[
Fiddle::TYPE_VOIDP, # graphics : GpGraphics* in/out
Fiddle::TYPE_VOIDP, # string : LPCWSTR
Fiddle::TYPE_INT, # length : INT
Fiddle::TYPE_VOIDP, # font : GpFont*
Fiddle::TYPE_VOIDP, # layoutRect : RectF*
Fiddle::TYPE_VOIDP, # stringFormat : GpStringFormat*
Fiddle::TYPE_VOIDP, # boundingBox : RectF* in/out
Fiddle::TYPE_VOIDP, # codepointsFitted : INT* in/out
Fiddle::TYPE_VOIDP, # linesFilled : INT* in/out
],
Fiddle::TYPE_INT)#[link(name = "gdiplus")]
extern "system" {
fn GdipMeasureString(
graphics: *mut GpGraphics, // GpGraphics* in/out
string: *const u16, // LPCWSTR
length: i32, // INT
font: *const GpFont, // GpFont*
layoutRect: *const RectF, // RectF*
stringFormat: *const GpStringFormat, // GpStringFormat*
boundingBox: *mut RectF, // RectF* in/out
codepointsFitted: *mut i32, // INT* in/out
linesFilled: *mut i32 // INT* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("gdiplus.dll")]
public static extern int GdipMeasureString(IntPtr graphics, [MarshalAs(UnmanagedType.LPWStr)] string string, int length, IntPtr font, IntPtr layoutRect, IntPtr stringFormat, IntPtr boundingBox, ref int codepointsFitted, ref int linesFilled);
"@
$api = Add-Type -MemberDefinition $sig -Name 'gdiplus_GdipMeasureString' -Namespace Win32 -PassThru
# $api::GdipMeasureString(graphics, string, length, font, layoutRect, stringFormat, boundingBox, codepointsFitted, linesFilled)#uselib "gdiplus.dll"
#func global GdipMeasureString "GdipMeasureString" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GdipMeasureString varptr(graphics), string, length, varptr(font), varptr(layoutRect), varptr(stringFormat), varptr(boundingBox), varptr(codepointsFitted), varptr(linesFilled) ; 戻り値は stat
; graphics : GpGraphics* in/out -> "sptr"
; string : LPCWSTR -> "sptr"
; length : INT -> "sptr"
; font : GpFont* -> "sptr"
; layoutRect : RectF* -> "sptr"
; stringFormat : GpStringFormat* -> "sptr"
; boundingBox : RectF* in/out -> "sptr"
; codepointsFitted : INT* in/out -> "sptr"
; linesFilled : INT* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "gdiplus.dll" #cfunc global GdipMeasureString "GdipMeasureString" var, wstr, int, var, var, var, var, var, var ; res = GdipMeasureString(graphics, string, length, font, layoutRect, stringFormat, boundingBox, codepointsFitted, linesFilled) ; graphics : GpGraphics* in/out -> "var" ; string : LPCWSTR -> "wstr" ; length : INT -> "int" ; font : GpFont* -> "var" ; layoutRect : RectF* -> "var" ; stringFormat : GpStringFormat* -> "var" ; boundingBox : RectF* in/out -> "var" ; codepointsFitted : INT* in/out -> "var" ; linesFilled : INT* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "gdiplus.dll" #cfunc global GdipMeasureString "GdipMeasureString" sptr, wstr, int, sptr, sptr, sptr, sptr, sptr, sptr ; res = GdipMeasureString(varptr(graphics), string, length, varptr(font), varptr(layoutRect), varptr(stringFormat), varptr(boundingBox), varptr(codepointsFitted), varptr(linesFilled)) ; graphics : GpGraphics* in/out -> "sptr" ; string : LPCWSTR -> "wstr" ; length : INT -> "int" ; font : GpFont* -> "sptr" ; layoutRect : RectF* -> "sptr" ; stringFormat : GpStringFormat* -> "sptr" ; boundingBox : RectF* in/out -> "sptr" ; codepointsFitted : INT* in/out -> "sptr" ; linesFilled : INT* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; Status GdipMeasureString(GpGraphics* graphics, LPCWSTR string, INT length, GpFont* font, RectF* layoutRect, GpStringFormat* stringFormat, RectF* boundingBox, INT* codepointsFitted, INT* linesFilled) #uselib "gdiplus.dll" #cfunc global GdipMeasureString "GdipMeasureString" var, wstr, int, var, var, var, var, var, var ; res = GdipMeasureString(graphics, string, length, font, layoutRect, stringFormat, boundingBox, codepointsFitted, linesFilled) ; graphics : GpGraphics* in/out -> "var" ; string : LPCWSTR -> "wstr" ; length : INT -> "int" ; font : GpFont* -> "var" ; layoutRect : RectF* -> "var" ; stringFormat : GpStringFormat* -> "var" ; boundingBox : RectF* in/out -> "var" ; codepointsFitted : INT* in/out -> "var" ; linesFilled : INT* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; Status GdipMeasureString(GpGraphics* graphics, LPCWSTR string, INT length, GpFont* font, RectF* layoutRect, GpStringFormat* stringFormat, RectF* boundingBox, INT* codepointsFitted, INT* linesFilled) #uselib "gdiplus.dll" #cfunc global GdipMeasureString "GdipMeasureString" intptr, wstr, int, intptr, intptr, intptr, intptr, intptr, intptr ; res = GdipMeasureString(varptr(graphics), string, length, varptr(font), varptr(layoutRect), varptr(stringFormat), varptr(boundingBox), varptr(codepointsFitted), varptr(linesFilled)) ; graphics : GpGraphics* in/out -> "intptr" ; string : LPCWSTR -> "wstr" ; length : INT -> "int" ; font : GpFont* -> "intptr" ; layoutRect : RectF* -> "intptr" ; stringFormat : GpStringFormat* -> "intptr" ; boundingBox : RectF* in/out -> "intptr" ; codepointsFitted : INT* in/out -> "intptr" ; linesFilled : INT* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdiplus = windows.NewLazySystemDLL("gdiplus.dll")
procGdipMeasureString = gdiplus.NewProc("GdipMeasureString")
)
// graphics (GpGraphics* in/out), string (LPCWSTR), length (INT), font (GpFont*), layoutRect (RectF*), stringFormat (GpStringFormat*), boundingBox (RectF* in/out), codepointsFitted (INT* in/out), linesFilled (INT* in/out)
r1, _, err := procGdipMeasureString.Call(
uintptr(graphics),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(string))),
uintptr(length),
uintptr(font),
uintptr(layoutRect),
uintptr(stringFormat),
uintptr(boundingBox),
uintptr(codepointsFitted),
uintptr(linesFilled),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // Statusfunction GdipMeasureString(
graphics: Pointer; // GpGraphics* in/out
string: PWideChar; // LPCWSTR
length: Integer; // INT
font: Pointer; // GpFont*
layoutRect: Pointer; // RectF*
stringFormat: Pointer; // GpStringFormat*
boundingBox: Pointer; // RectF* in/out
codepointsFitted: Pointer; // INT* in/out
linesFilled: Pointer // INT* in/out
): Integer; stdcall;
external 'gdiplus.dll' name 'GdipMeasureString';result := DllCall("gdiplus\GdipMeasureString"
, "Ptr", graphics ; GpGraphics* in/out
, "WStr", string ; LPCWSTR
, "Int", length ; INT
, "Ptr", font ; GpFont*
, "Ptr", layoutRect ; RectF*
, "Ptr", stringFormat ; GpStringFormat*
, "Ptr", boundingBox ; RectF* in/out
, "Ptr", codepointsFitted ; INT* in/out
, "Ptr", linesFilled ; INT* in/out
, "Int") ; return: Status●GdipMeasureString(graphics, string, length, font, layoutRect, stringFormat, boundingBox, codepointsFitted, linesFilled) = DLL("gdiplus.dll", "int GdipMeasureString(void*, char*, int, void*, void*, void*, void*, void*, void*)")
# 呼び出し: GdipMeasureString(graphics, string, length, font, layoutRect, stringFormat, boundingBox, codepointsFitted, linesFilled)
# graphics : GpGraphics* in/out -> "void*"
# string : LPCWSTR -> "char*"
# length : INT -> "int"
# font : GpFont* -> "void*"
# layoutRect : RectF* -> "void*"
# stringFormat : GpStringFormat* -> "void*"
# boundingBox : RectF* in/out -> "void*"
# codepointsFitted : INT* in/out -> "void*"
# linesFilled : INT* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdiplus" fn GdipMeasureString(
graphics: [*c]GpGraphics, // GpGraphics* in/out
string: [*c]const u16, // LPCWSTR
length: i32, // INT
font: [*c]GpFont, // GpFont*
layoutRect: [*c]RectF, // RectF*
stringFormat: [*c]GpStringFormat, // GpStringFormat*
boundingBox: [*c]RectF, // RectF* in/out
codepointsFitted: [*c]i32, // INT* in/out
linesFilled: [*c]i32 // INT* in/out
) callconv(std.os.windows.WINAPI) i32;proc GdipMeasureString(
graphics: ptr GpGraphics, # GpGraphics* in/out
string: WideCString, # LPCWSTR
length: int32, # INT
font: ptr GpFont, # GpFont*
layoutRect: ptr RectF, # RectF*
stringFormat: ptr GpStringFormat, # GpStringFormat*
boundingBox: ptr RectF, # RectF* in/out
codepointsFitted: ptr int32, # INT* in/out
linesFilled: ptr int32 # INT* in/out
): int32 {.importc: "GdipMeasureString", stdcall, dynlib: "gdiplus.dll".}pragma(lib, "gdiplus");
extern(Windows)
int GdipMeasureString(
GpGraphics* graphics, // GpGraphics* in/out
const(wchar)* string, // LPCWSTR
int length, // INT
GpFont* font, // GpFont*
RectF* layoutRect, // RectF*
GpStringFormat* stringFormat, // GpStringFormat*
RectF* boundingBox, // RectF* in/out
int* codepointsFitted, // INT* in/out
int* linesFilled // INT* in/out
);ccall((:GdipMeasureString, "gdiplus.dll"), stdcall, Int32,
(Ptr{GpGraphics}, Cwstring, Int32, Ptr{GpFont}, Ptr{RectF}, Ptr{GpStringFormat}, Ptr{RectF}, Ptr{Int32}, Ptr{Int32}),
graphics, string, length, font, layoutRect, stringFormat, boundingBox, codepointsFitted, linesFilled)
# graphics : GpGraphics* in/out -> Ptr{GpGraphics}
# string : LPCWSTR -> Cwstring
# length : INT -> Int32
# font : GpFont* -> Ptr{GpFont}
# layoutRect : RectF* -> Ptr{RectF}
# stringFormat : GpStringFormat* -> Ptr{GpStringFormat}
# boundingBox : RectF* in/out -> Ptr{RectF}
# codepointsFitted : INT* in/out -> Ptr{Int32}
# linesFilled : INT* in/out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GdipMeasureString(
void* graphics,
const uint16_t* string,
int32_t length,
void* font,
void* layoutRect,
void* stringFormat,
void* boundingBox,
int32_t* codepointsFitted,
int32_t* linesFilled);
]]
local gdiplus = ffi.load("gdiplus")
-- gdiplus.GdipMeasureString(graphics, string, length, font, layoutRect, stringFormat, boundingBox, codepointsFitted, linesFilled)
-- graphics : GpGraphics* in/out
-- string : LPCWSTR
-- length : INT
-- font : GpFont*
-- layoutRect : RectF*
-- stringFormat : GpStringFormat*
-- boundingBox : RectF* in/out
-- codepointsFitted : INT* in/out
-- linesFilled : INT* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('gdiplus.dll');
const GdipMeasureString = lib.func('__stdcall', 'GdipMeasureString', 'int32_t', ['void *', 'str16', 'int32_t', 'void *', 'void *', 'void *', 'void *', 'int32_t *', 'int32_t *']);
// GdipMeasureString(graphics, string, length, font, layoutRect, stringFormat, boundingBox, codepointsFitted, linesFilled)
// graphics : GpGraphics* in/out -> 'void *'
// string : LPCWSTR -> 'str16'
// length : INT -> 'int32_t'
// font : GpFont* -> 'void *'
// layoutRect : RectF* -> 'void *'
// stringFormat : GpStringFormat* -> 'void *'
// boundingBox : RectF* in/out -> 'void *'
// codepointsFitted : INT* in/out -> 'int32_t *'
// linesFilled : INT* in/out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("gdiplus.dll", {
GdipMeasureString: { parameters: ["pointer", "buffer", "i32", "pointer", "pointer", "pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.GdipMeasureString(graphics, string, length, font, layoutRect, stringFormat, boundingBox, codepointsFitted, linesFilled)
// graphics : GpGraphics* in/out -> "pointer"
// string : LPCWSTR -> "buffer"
// length : INT -> "i32"
// font : GpFont* -> "pointer"
// layoutRect : RectF* -> "pointer"
// stringFormat : GpStringFormat* -> "pointer"
// boundingBox : RectF* in/out -> "pointer"
// codepointsFitted : INT* in/out -> "pointer"
// linesFilled : INT* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GdipMeasureString(
void* graphics,
const uint16_t* string,
int32_t length,
void* font,
void* layoutRect,
void* stringFormat,
void* boundingBox,
int32_t* codepointsFitted,
int32_t* linesFilled);
C, "gdiplus.dll");
// $ffi->GdipMeasureString(graphics, string, length, font, layoutRect, stringFormat, boundingBox, codepointsFitted, linesFilled);
// graphics : GpGraphics* in/out
// string : LPCWSTR
// length : INT
// font : GpFont*
// layoutRect : RectF*
// stringFormat : GpStringFormat*
// boundingBox : RectF* in/out
// codepointsFitted : INT* in/out
// linesFilled : INT* in/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 Gdiplus extends StdCallLibrary {
Gdiplus INSTANCE = Native.load("gdiplus", Gdiplus.class);
int GdipMeasureString(
Pointer graphics, // GpGraphics* in/out
WString string, // LPCWSTR
int length, // INT
Pointer font, // GpFont*
Pointer layoutRect, // RectF*
Pointer stringFormat, // GpStringFormat*
Pointer boundingBox, // RectF* in/out
IntByReference codepointsFitted, // INT* in/out
IntByReference linesFilled // INT* in/out
);
}@[Link("gdiplus")]
lib Libgdiplus
fun GdipMeasureString = GdipMeasureString(
graphics : GpGraphics*, # GpGraphics* in/out
string : UInt16*, # LPCWSTR
length : Int32, # INT
font : GpFont*, # GpFont*
layoutRect : RectF*, # RectF*
stringFormat : GpStringFormat*, # GpStringFormat*
boundingBox : RectF*, # RectF* in/out
codepointsFitted : Int32*, # INT* in/out
linesFilled : Int32* # INT* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GdipMeasureStringNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Int32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Int32>, Pointer<Int32>);
typedef GdipMeasureStringDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Int32>, Pointer<Int32>);
final GdipMeasureString = DynamicLibrary.open('gdiplus.dll')
.lookupFunction<GdipMeasureStringNative, GdipMeasureStringDart>('GdipMeasureString');
// graphics : GpGraphics* in/out -> Pointer<Void>
// string : LPCWSTR -> Pointer<Utf16>
// length : INT -> Int32
// font : GpFont* -> Pointer<Void>
// layoutRect : RectF* -> Pointer<Void>
// stringFormat : GpStringFormat* -> Pointer<Void>
// boundingBox : RectF* in/out -> Pointer<Void>
// codepointsFitted : INT* in/out -> Pointer<Int32>
// linesFilled : INT* in/out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GdipMeasureString(
graphics: Pointer; // GpGraphics* in/out
string: PWideChar; // LPCWSTR
length: Integer; // INT
font: Pointer; // GpFont*
layoutRect: Pointer; // RectF*
stringFormat: Pointer; // GpStringFormat*
boundingBox: Pointer; // RectF* in/out
codepointsFitted: Pointer; // INT* in/out
linesFilled: Pointer // INT* in/out
): Integer; stdcall;
external 'gdiplus.dll' name 'GdipMeasureString';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GdipMeasureString"
c_GdipMeasureString :: Ptr () -> CWString -> Int32 -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> Ptr Int32 -> Ptr Int32 -> IO Int32
-- graphics : GpGraphics* in/out -> Ptr ()
-- string : LPCWSTR -> CWString
-- length : INT -> Int32
-- font : GpFont* -> Ptr ()
-- layoutRect : RectF* -> Ptr ()
-- stringFormat : GpStringFormat* -> Ptr ()
-- boundingBox : RectF* in/out -> Ptr ()
-- codepointsFitted : INT* in/out -> Ptr Int32
-- linesFilled : INT* in/out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let gdipmeasurestring =
foreign "GdipMeasureString"
((ptr void) @-> (ptr uint16_t) @-> int32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr int32_t) @-> (ptr int32_t) @-> returning int32_t)
(* graphics : GpGraphics* in/out -> (ptr void) *)
(* string : LPCWSTR -> (ptr uint16_t) *)
(* length : INT -> int32_t *)
(* font : GpFont* -> (ptr void) *)
(* layoutRect : RectF* -> (ptr void) *)
(* stringFormat : GpStringFormat* -> (ptr void) *)
(* boundingBox : RectF* in/out -> (ptr void) *)
(* codepointsFitted : INT* in/out -> (ptr int32_t) *)
(* linesFilled : INT* in/out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdiplus (t "gdiplus.dll"))
(cffi:use-foreign-library gdiplus)
(cffi:defcfun ("GdipMeasureString" gdip-measure-string :convention :stdcall) :int32
(graphics :pointer) ; GpGraphics* in/out
(string (:string :encoding :utf-16le)) ; LPCWSTR
(length :int32) ; INT
(font :pointer) ; GpFont*
(layout-rect :pointer) ; RectF*
(string-format :pointer) ; GpStringFormat*
(bounding-box :pointer) ; RectF* in/out
(codepoints-fitted :pointer) ; INT* in/out
(lines-filled :pointer)) ; INT* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GdipMeasureString = Win32::API::More->new('gdiplus',
'int GdipMeasureString(LPVOID graphics, LPCWSTR string, int length, LPVOID font, LPVOID layoutRect, LPVOID stringFormat, LPVOID boundingBox, LPVOID codepointsFitted, LPVOID linesFilled)');
# my $ret = $GdipMeasureString->Call($graphics, $string, $length, $font, $layoutRect, $stringFormat, $boundingBox, $codepointsFitted, $linesFilled);
# graphics : GpGraphics* in/out -> LPVOID
# string : LPCWSTR -> LPCWSTR
# length : INT -> int
# font : GpFont* -> LPVOID
# layoutRect : RectF* -> LPVOID
# stringFormat : GpStringFormat* -> LPVOID
# boundingBox : RectF* in/out -> LPVOID
# codepointsFitted : INT* in/out -> LPVOID
# linesFilled : INT* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。