ホーム › Graphics.GdiPlus › GdipCreateFont
GdipCreateFont
関数フォントファミリーとサイズからフォントを作成する。
シグネチャ
// gdiplus.dll
#include <windows.h>
Status GdipCreateFont(
const GpFontFamily* fontFamily,
FLOAT emSize,
INT style,
Unit unit,
GpFont** font
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| fontFamily | GpFontFamily* | in | 生成するフォントの基となるフォントファミリーオブジェクトへのポインタ。NULL不可。 |
| emSize | FLOAT | in | フォントのemサイズ。unitで指定した単位で解釈される正の浮動小数点値。 |
| style | INT | in | フォントスタイルを示すフラグ。FontStyle列挙(Regular/Bold/Italic/Underline/Strikeout)のビット組み合わせ。 |
| unit | Unit | in | emSizeの測定単位を示すUnit列挙値。Point/Pixel/Inch等を指定する。 |
| font | GpFont** | inout | 生成されたGpFontオブジェクトへのポインタを受け取る出力先。 |
戻り値の型: Status
各言語での呼び出し定義
// gdiplus.dll
#include <windows.h>
Status GdipCreateFont(
const GpFontFamily* fontFamily,
FLOAT emSize,
INT style,
Unit unit,
GpFont** font
);[DllImport("gdiplus.dll", ExactSpelling = true)]
static extern int GdipCreateFont(
IntPtr fontFamily, // GpFontFamily*
float emSize, // FLOAT
int style, // INT
int unit, // Unit
IntPtr font // GpFont** in/out
);<DllImport("gdiplus.dll", ExactSpelling:=True)>
Public Shared Function GdipCreateFont(
fontFamily As IntPtr, ' GpFontFamily*
emSize As Single, ' FLOAT
style As Integer, ' INT
unit As Integer, ' Unit
font As IntPtr ' GpFont** in/out
) As Integer
End Function' fontFamily : GpFontFamily*
' emSize : FLOAT
' style : INT
' unit : Unit
' font : GpFont** in/out
Declare PtrSafe Function GdipCreateFont Lib "gdiplus" ( _
ByVal fontFamily As LongPtr, _
ByVal emSize As Single, _
ByVal style As Long, _
ByVal unit As Long, _
ByVal font As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GdipCreateFont = ctypes.windll.gdiplus.GdipCreateFont
GdipCreateFont.restype = ctypes.c_int
GdipCreateFont.argtypes = [
ctypes.c_void_p, # fontFamily : GpFontFamily*
ctypes.c_float, # emSize : FLOAT
ctypes.c_int, # style : INT
ctypes.c_int, # unit : Unit
ctypes.c_void_p, # font : GpFont** in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('gdiplus.dll')
GdipCreateFont = Fiddle::Function.new(
lib['GdipCreateFont'],
[
Fiddle::TYPE_VOIDP, # fontFamily : GpFontFamily*
Fiddle::TYPE_FLOAT, # emSize : FLOAT
Fiddle::TYPE_INT, # style : INT
Fiddle::TYPE_INT, # unit : Unit
Fiddle::TYPE_VOIDP, # font : GpFont** in/out
],
Fiddle::TYPE_INT)#[link(name = "gdiplus")]
extern "system" {
fn GdipCreateFont(
fontFamily: *const GpFontFamily, // GpFontFamily*
emSize: f32, // FLOAT
style: i32, // INT
unit: i32, // Unit
font: *mut *mut GpFont // GpFont** in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("gdiplus.dll")]
public static extern int GdipCreateFont(IntPtr fontFamily, float emSize, int style, int unit, IntPtr font);
"@
$api = Add-Type -MemberDefinition $sig -Name 'gdiplus_GdipCreateFont' -Namespace Win32 -PassThru
# $api::GdipCreateFont(fontFamily, emSize, style, unit, font)#uselib "gdiplus.dll"
#func global GdipCreateFont "GdipCreateFont" sptr, float, sptr, sptr, sptr
; GdipCreateFont varptr(fontFamily), emSize, style, unit, varptr(font) ; 戻り値は stat
; fontFamily : GpFontFamily* -> "sptr"
; emSize : FLOAT -> "float"
; style : INT -> "sptr"
; unit : Unit -> "sptr"
; font : GpFont** in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "gdiplus.dll" #cfunc global GdipCreateFont "GdipCreateFont" var, float, int, int, var ; res = GdipCreateFont(fontFamily, emSize, style, unit, font) ; fontFamily : GpFontFamily* -> "var" ; emSize : FLOAT -> "float" ; style : INT -> "int" ; unit : Unit -> "int" ; font : GpFont** in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "gdiplus.dll" #cfunc global GdipCreateFont "GdipCreateFont" sptr, float, int, int, sptr ; res = GdipCreateFont(varptr(fontFamily), emSize, style, unit, varptr(font)) ; fontFamily : GpFontFamily* -> "sptr" ; emSize : FLOAT -> "float" ; style : INT -> "int" ; unit : Unit -> "int" ; font : GpFont** in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; Status GdipCreateFont(GpFontFamily* fontFamily, FLOAT emSize, INT style, Unit unit, GpFont** font) #uselib "gdiplus.dll" #cfunc global GdipCreateFont "GdipCreateFont" var, float, int, int, var ; res = GdipCreateFont(fontFamily, emSize, style, unit, font) ; fontFamily : GpFontFamily* -> "var" ; emSize : FLOAT -> "float" ; style : INT -> "int" ; unit : Unit -> "int" ; font : GpFont** in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; Status GdipCreateFont(GpFontFamily* fontFamily, FLOAT emSize, INT style, Unit unit, GpFont** font) #uselib "gdiplus.dll" #cfunc global GdipCreateFont "GdipCreateFont" intptr, float, int, int, intptr ; res = GdipCreateFont(varptr(fontFamily), emSize, style, unit, varptr(font)) ; fontFamily : GpFontFamily* -> "intptr" ; emSize : FLOAT -> "float" ; style : INT -> "int" ; unit : Unit -> "int" ; font : GpFont** in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"math"
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdiplus = windows.NewLazySystemDLL("gdiplus.dll")
procGdipCreateFont = gdiplus.NewProc("GdipCreateFont")
)
// fontFamily (GpFontFamily*), emSize (FLOAT), style (INT), unit (Unit), font (GpFont** in/out)
r1, _, err := procGdipCreateFont.Call(
uintptr(fontFamily),
uintptr(math.Float32bits(emSize)),
uintptr(style),
uintptr(unit),
uintptr(font),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // Status
// 注意: float/double 引数は proc.Call では XMM レジスタに渡せません。
// windows.SyscallN(proc.Addr(), math.Float64bits(x), ...) もしくは cgo を使用してください。function GdipCreateFont(
fontFamily: Pointer; // GpFontFamily*
emSize: Single; // FLOAT
style: Integer; // INT
unit: Integer; // Unit
font: Pointer // GpFont** in/out
): Integer; stdcall;
external 'gdiplus.dll' name 'GdipCreateFont';result := DllCall("gdiplus\GdipCreateFont"
, "Ptr", fontFamily ; GpFontFamily*
, "Float", emSize ; FLOAT
, "Int", style ; INT
, "Int", unit ; Unit
, "Ptr", font ; GpFont** in/out
, "Int") ; return: Status●GdipCreateFont(fontFamily, emSize, style, unit, font) = DLL("gdiplus.dll", "int GdipCreateFont(void*, float, int, int, void*)")
# 呼び出し: GdipCreateFont(fontFamily, emSize, style, unit, font)
# fontFamily : GpFontFamily* -> "void*"
# emSize : FLOAT -> "float"
# style : INT -> "int"
# unit : Unit -> "int"
# font : GpFont** in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdiplus" fn GdipCreateFont(
fontFamily: [*c]GpFontFamily, // GpFontFamily*
emSize: f32, // FLOAT
style: i32, // INT
unit: i32, // Unit
font: [*c][*c]GpFont // GpFont** in/out
) callconv(std.os.windows.WINAPI) i32;proc GdipCreateFont(
fontFamily: ptr GpFontFamily, # GpFontFamily*
emSize: float32, # FLOAT
style: int32, # INT
unit: int32, # Unit
font: ptr GpFont # GpFont** in/out
): int32 {.importc: "GdipCreateFont", stdcall, dynlib: "gdiplus.dll".}pragma(lib, "gdiplus");
extern(Windows)
int GdipCreateFont(
GpFontFamily* fontFamily, // GpFontFamily*
float emSize, // FLOAT
int style, // INT
int unit, // Unit
GpFont** font // GpFont** in/out
);ccall((:GdipCreateFont, "gdiplus.dll"), stdcall, Int32,
(Ptr{GpFontFamily}, Float32, Int32, Int32, Ptr{GpFont}),
fontFamily, emSize, style, unit, font)
# fontFamily : GpFontFamily* -> Ptr{GpFontFamily}
# emSize : FLOAT -> Float32
# style : INT -> Int32
# unit : Unit -> Int32
# font : GpFont** in/out -> Ptr{GpFont}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GdipCreateFont(
void* fontFamily,
float emSize,
int32_t style,
int32_t unit,
void* font);
]]
local gdiplus = ffi.load("gdiplus")
-- gdiplus.GdipCreateFont(fontFamily, emSize, style, unit, font)
-- fontFamily : GpFontFamily*
-- emSize : FLOAT
-- style : INT
-- unit : Unit
-- font : GpFont** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('gdiplus.dll');
const GdipCreateFont = lib.func('__stdcall', 'GdipCreateFont', 'int32_t', ['void *', 'float', 'int32_t', 'int32_t', 'void *']);
// GdipCreateFont(fontFamily, emSize, style, unit, font)
// fontFamily : GpFontFamily* -> 'void *'
// emSize : FLOAT -> 'float'
// style : INT -> 'int32_t'
// unit : Unit -> 'int32_t'
// font : GpFont** in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("gdiplus.dll", {
GdipCreateFont: { parameters: ["pointer", "f32", "i32", "i32", "pointer"], result: "i32" },
});
// lib.symbols.GdipCreateFont(fontFamily, emSize, style, unit, font)
// fontFamily : GpFontFamily* -> "pointer"
// emSize : FLOAT -> "f32"
// style : INT -> "i32"
// unit : Unit -> "i32"
// font : GpFont** in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GdipCreateFont(
void* fontFamily,
float emSize,
int32_t style,
int32_t unit,
void* font);
C, "gdiplus.dll");
// $ffi->GdipCreateFont(fontFamily, emSize, style, unit, font);
// fontFamily : GpFontFamily*
// emSize : FLOAT
// style : INT
// unit : Unit
// font : GpFont** 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 GdipCreateFont(
Pointer fontFamily, // GpFontFamily*
float emSize, // FLOAT
int style, // INT
int unit, // Unit
Pointer font // GpFont** in/out
);
}@[Link("gdiplus")]
lib Libgdiplus
fun GdipCreateFont = GdipCreateFont(
fontFamily : GpFontFamily*, # GpFontFamily*
emSize : Float32, # FLOAT
style : Int32, # INT
unit : Int32, # Unit
font : GpFont** # GpFont** 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 GdipCreateFontNative = Int32 Function(Pointer<Void>, Float, Int32, Int32, Pointer<Void>);
typedef GdipCreateFontDart = int Function(Pointer<Void>, double, int, int, Pointer<Void>);
final GdipCreateFont = DynamicLibrary.open('gdiplus.dll')
.lookupFunction<GdipCreateFontNative, GdipCreateFontDart>('GdipCreateFont');
// fontFamily : GpFontFamily* -> Pointer<Void>
// emSize : FLOAT -> Float
// style : INT -> Int32
// unit : Unit -> Int32
// font : GpFont** in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GdipCreateFont(
fontFamily: Pointer; // GpFontFamily*
emSize: Single; // FLOAT
style: Integer; // INT
unit: Integer; // Unit
font: Pointer // GpFont** in/out
): Integer; stdcall;
external 'gdiplus.dll' name 'GdipCreateFont';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GdipCreateFont"
c_GdipCreateFont :: Ptr () -> CFloat -> Int32 -> Int32 -> Ptr () -> IO Int32
-- fontFamily : GpFontFamily* -> Ptr ()
-- emSize : FLOAT -> CFloat
-- style : INT -> Int32
-- unit : Unit -> Int32
-- font : GpFont** in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let gdipcreatefont =
foreign "GdipCreateFont"
((ptr void) @-> float @-> int32_t @-> int32_t @-> (ptr void) @-> returning int32_t)
(* fontFamily : GpFontFamily* -> (ptr void) *)
(* emSize : FLOAT -> float *)
(* style : INT -> int32_t *)
(* unit : Unit -> int32_t *)
(* font : GpFont** in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdiplus (t "gdiplus.dll"))
(cffi:use-foreign-library gdiplus)
(cffi:defcfun ("GdipCreateFont" gdip-create-font :convention :stdcall) :int32
(font-family :pointer) ; GpFontFamily*
(em-size :float) ; FLOAT
(style :int32) ; INT
(unit :int32) ; Unit
(font :pointer)) ; GpFont** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GdipCreateFont = Win32::API::More->new('gdiplus',
'int GdipCreateFont(LPVOID fontFamily, float emSize, int style, int unit, LPVOID font)');
# my $ret = $GdipCreateFont->Call($fontFamily, $emSize, $style, $unit, $font);
# fontFamily : GpFontFamily* -> LPVOID
# emSize : FLOAT -> float
# style : INT -> int
# unit : Unit -> int
# font : GpFont** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。