TEXTMETRICW
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| tmHeight | INT | 4 | +0 | +0 | 文字の高さ (アセント + ディセント) です。 | ||||||||||
| tmAscent | INT | 4 | +4 | +4 | 文字のアセント (ベースラインより上の単位数) です。 | ||||||||||
| tmDescent | INT | 4 | +8 | +8 | 文字のディセント (ベースラインより下の単位数) です。 | ||||||||||
| tmInternalLeading | INT | 4 | +12 | +12 | tmHeight メンバーで設定される範囲の内側にあるレディング (空き) の量です。アクセント記号やその他のダイアクリティカルマークがこの領域に配置されることがあります。デザイナーはこのメンバーを 0 に設定することもできます。 | ||||||||||
| tmExternalLeading | INT | 4 | +16 | +16 | アプリケーションが行と行の間に追加する余分なレディング (空き) の量です。この領域はフォントの外側にあるため、記号は含まれず、OPAQUE モードでも TRANSPARENT モードでもテキスト出力の呼び出しによって変更されることはありません。デザイナーはこのメンバーを 0 に設定することもできます。 | ||||||||||
| tmAveCharWidth | INT | 4 | +20 | +20 | フォント内の文字の平均幅です (一般に文字 x の幅として定義されます)。この値には、太字や斜体の文字に必要なオーバーハングは含まれません。 | ||||||||||
| tmMaxCharWidth | INT | 4 | +24 | +24 | フォント内で最も広い文字の幅です。 | ||||||||||
| tmWeight | INT | 4 | +28 | +28 | フォントの太さ (ウェイト) です。 | ||||||||||
| tmOverhang | INT | 4 | +32 | +32 | 一部の合成フォントで文字列ごとに追加されることがある余分な幅です。太字や斜体などの属性を合成する際、グラフィックスデバイスインターフェイス (GDI) またはデバイスは、文字単位と文字列単位の両方で文字列に幅を追加しなければならない場合があります。たとえば GDI は、各文字の間隔を広げてオフセット値だけ重ね打ちすることで文字列を太字にし、文字列を傾けることでフォントを斜体にします。いずれの場合も、本来の文字列を越えたオーバーハングが生じます。太字の文字列では、オーバーハングは重ね打ちがオフセットされる距離です。斜体の文字列では、オーバーハングはフォントの上端がフォントの下端を越えて傾けられる量です。 tmOverhang メンバーにより、アプリケーションは、単一の文字に対する GetTextExtentPoint32 関数の呼び出しで返される文字幅のうち、どれだけが実際の文字幅で、どれだけが文字列単位の余分な幅であるかを判断できます。実際の幅は、エクステントからオーバーハングを引いた値です。 | ||||||||||
| tmDigitizedAspectX | INT | 4 | +36 | +36 | このフォントが設計対象としたデバイスの水平方向のアスペクトです。 | ||||||||||
| tmDigitizedAspectY | INT | 4 | +40 | +40 | このフォントが設計対象としたデバイスの垂直方向のアスペクトです。tmDigitizedAspectX メンバーと tmDigitizedAspectY メンバーの比が、このフォントが設計対象としたデバイスのアスペクト比になります。 | ||||||||||
| tmFirstChar | WCHAR | 2 | +44 | +44 | フォント内で定義されている最初の文字の値です。 | ||||||||||
| tmLastChar | WCHAR | 2 | +46 | +46 | フォント内で定義されている最後の文字の値です。 | ||||||||||
| tmDefaultChar | WCHAR | 2 | +48 | +48 | フォントに含まれない文字の代わりに使用される文字の値です。 | ||||||||||
| tmBreakChar | WCHAR | 2 | +50 | +50 | テキストの均等割り付けで単語の区切りを定義するために使用される文字の値です。 | ||||||||||
| tmItalic | BYTE | 1 | +52 | +52 | 0 以外の場合、斜体フォントであることを指定します。 | ||||||||||
| tmUnderlined | BYTE | 1 | +53 | +53 | 0 以外の場合、下線付きフォントであることを指定します。 | ||||||||||
| tmStruckOut | BYTE | 1 | +54 | +54 | 0 以外の場合、取り消し線付きフォントです。 | ||||||||||
| tmPitchAndFamily | TMPF_FLAGS | 1 | +55 | +55 | 物理フォントのピッチ、テクノロジ、およびファミリに関する情報を指定します。 このメンバーの下位 4 ビットは、フォントのピッチとテクノロジに関する情報を指定します。4 つの各ビットに対して定数が定義されています。
アプリケーションは、これらの下位ビットにエンコードされた特性を慎重に判定し、勝手な想定をしないようにしてください。たとえば TrueType フォントと PostScript フォントは、それぞれ固有のビットに加えて TMPF_VECTOR ビットもセットします。等幅のビットマップフォントはこれらの下位ビットがすべてクリアされ、プロポーショナルのビットマップフォントは TMPF_FIXED_PITCH ビットをセットします。PostScript プリンターのデバイスフォントは、TMPF_DEVICE、TMPF_VECTOR、TMPF_FIXED_PITCH の各ビットをセットします。 tmPitchAndFamily の上位 4 ビットは、そのフォントのフォントファミリを示します。アプリケーションは、値 0xF0 とビット単位の AND 演算子を使用して tmPitchAndFamily の下位 4 ビットをマスクすることで、フォントファミリ名と直接比較して完全に一致するものを見つけられる値を取得できます。フォントファミリについては、LOGFONT 構造体の説明を参照してください。 | ||||||||||
| tmCharSet | BYTE | 1 | +56 | +56 | フォントの文字セットです。指定できる値の一覧については、LOGFONT 構造体の lfCharSet フィールドを参照してください。 |
公式ドキュメント
TEXTMETRIC 構造体は、物理フォントに関する基本的な情報を格納します。すべてのサイズは論理単位で指定されます。つまり、ディスプレイコンテキストの現在のマッピングモードに依存します。
解説(Remarks)
wingdi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版と Unicode 版を自動的に選択するエイリアスとして TEXTMETRIC を定義しています。エンコーディング中立のエイリアスの使用と、エンコーディング中立でないコードを混在させると、不一致が生じてコンパイルエラーや実行時エラーの原因となる場合があります。詳細については、関数プロトタイプの規則を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での定義
#include <windows.h>
// TEXTMETRICW (x64 60 / x86 60 バイト)
typedef struct TEXTMETRICW {
INT tmHeight;
INT tmAscent;
INT tmDescent;
INT tmInternalLeading;
INT tmExternalLeading;
INT tmAveCharWidth;
INT tmMaxCharWidth;
INT tmWeight;
INT tmOverhang;
INT tmDigitizedAspectX;
INT tmDigitizedAspectY;
WCHAR tmFirstChar;
WCHAR tmLastChar;
WCHAR tmDefaultChar;
WCHAR tmBreakChar;
BYTE tmItalic;
BYTE tmUnderlined;
BYTE tmStruckOut;
TMPF_FLAGS tmPitchAndFamily;
BYTE tmCharSet;
} TEXTMETRICW;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct TEXTMETRICW
{
public int tmHeight;
public int tmAscent;
public int tmDescent;
public int tmInternalLeading;
public int tmExternalLeading;
public int tmAveCharWidth;
public int tmMaxCharWidth;
public int tmWeight;
public int tmOverhang;
public int tmDigitizedAspectX;
public int tmDigitizedAspectY;
public char tmFirstChar;
public char tmLastChar;
public char tmDefaultChar;
public char tmBreakChar;
public byte tmItalic;
public byte tmUnderlined;
public byte tmStruckOut;
public byte tmPitchAndFamily;
public byte tmCharSet;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure TEXTMETRICW
Public tmHeight As Integer
Public tmAscent As Integer
Public tmDescent As Integer
Public tmInternalLeading As Integer
Public tmExternalLeading As Integer
Public tmAveCharWidth As Integer
Public tmMaxCharWidth As Integer
Public tmWeight As Integer
Public tmOverhang As Integer
Public tmDigitizedAspectX As Integer
Public tmDigitizedAspectY As Integer
Public tmFirstChar As Char
Public tmLastChar As Char
Public tmDefaultChar As Char
Public tmBreakChar As Char
Public tmItalic As Byte
Public tmUnderlined As Byte
Public tmStruckOut As Byte
Public tmPitchAndFamily As Byte
Public tmCharSet As Byte
End Structureimport ctypes
from ctypes import wintypes
class TEXTMETRICW(ctypes.Structure):
_fields_ = [
("tmHeight", ctypes.c_int),
("tmAscent", ctypes.c_int),
("tmDescent", ctypes.c_int),
("tmInternalLeading", ctypes.c_int),
("tmExternalLeading", ctypes.c_int),
("tmAveCharWidth", ctypes.c_int),
("tmMaxCharWidth", ctypes.c_int),
("tmWeight", ctypes.c_int),
("tmOverhang", ctypes.c_int),
("tmDigitizedAspectX", ctypes.c_int),
("tmDigitizedAspectY", ctypes.c_int),
("tmFirstChar", ctypes.c_wchar),
("tmLastChar", ctypes.c_wchar),
("tmDefaultChar", ctypes.c_wchar),
("tmBreakChar", ctypes.c_wchar),
("tmItalic", ctypes.c_ubyte),
("tmUnderlined", ctypes.c_ubyte),
("tmStruckOut", ctypes.c_ubyte),
("tmPitchAndFamily", ctypes.c_ubyte),
("tmCharSet", ctypes.c_ubyte),
]#[repr(C)]
pub struct TEXTMETRICW {
pub tmHeight: i32,
pub tmAscent: i32,
pub tmDescent: i32,
pub tmInternalLeading: i32,
pub tmExternalLeading: i32,
pub tmAveCharWidth: i32,
pub tmMaxCharWidth: i32,
pub tmWeight: i32,
pub tmOverhang: i32,
pub tmDigitizedAspectX: i32,
pub tmDigitizedAspectY: i32,
pub tmFirstChar: u16,
pub tmLastChar: u16,
pub tmDefaultChar: u16,
pub tmBreakChar: u16,
pub tmItalic: u8,
pub tmUnderlined: u8,
pub tmStruckOut: u8,
pub tmPitchAndFamily: u8,
pub tmCharSet: u8,
}import "golang.org/x/sys/windows"
type TEXTMETRICW struct {
tmHeight int32
tmAscent int32
tmDescent int32
tmInternalLeading int32
tmExternalLeading int32
tmAveCharWidth int32
tmMaxCharWidth int32
tmWeight int32
tmOverhang int32
tmDigitizedAspectX int32
tmDigitizedAspectY int32
tmFirstChar uint16
tmLastChar uint16
tmDefaultChar uint16
tmBreakChar uint16
tmItalic byte
tmUnderlined byte
tmStruckOut byte
tmPitchAndFamily byte
tmCharSet byte
}type
TEXTMETRICW = record
tmHeight: Integer;
tmAscent: Integer;
tmDescent: Integer;
tmInternalLeading: Integer;
tmExternalLeading: Integer;
tmAveCharWidth: Integer;
tmMaxCharWidth: Integer;
tmWeight: Integer;
tmOverhang: Integer;
tmDigitizedAspectX: Integer;
tmDigitizedAspectY: Integer;
tmFirstChar: WideChar;
tmLastChar: WideChar;
tmDefaultChar: WideChar;
tmBreakChar: WideChar;
tmItalic: Byte;
tmUnderlined: Byte;
tmStruckOut: Byte;
tmPitchAndFamily: Byte;
tmCharSet: Byte;
end;const TEXTMETRICW = extern struct {
tmHeight: i32,
tmAscent: i32,
tmDescent: i32,
tmInternalLeading: i32,
tmExternalLeading: i32,
tmAveCharWidth: i32,
tmMaxCharWidth: i32,
tmWeight: i32,
tmOverhang: i32,
tmDigitizedAspectX: i32,
tmDigitizedAspectY: i32,
tmFirstChar: u16,
tmLastChar: u16,
tmDefaultChar: u16,
tmBreakChar: u16,
tmItalic: u8,
tmUnderlined: u8,
tmStruckOut: u8,
tmPitchAndFamily: u8,
tmCharSet: u8,
};type
TEXTMETRICW {.bycopy.} = object
tmHeight: int32
tmAscent: int32
tmDescent: int32
tmInternalLeading: int32
tmExternalLeading: int32
tmAveCharWidth: int32
tmMaxCharWidth: int32
tmWeight: int32
tmOverhang: int32
tmDigitizedAspectX: int32
tmDigitizedAspectY: int32
tmFirstChar: uint16
tmLastChar: uint16
tmDefaultChar: uint16
tmBreakChar: uint16
tmItalic: uint8
tmUnderlined: uint8
tmStruckOut: uint8
tmPitchAndFamily: uint8
tmCharSet: uint8struct TEXTMETRICW
{
int tmHeight;
int tmAscent;
int tmDescent;
int tmInternalLeading;
int tmExternalLeading;
int tmAveCharWidth;
int tmMaxCharWidth;
int tmWeight;
int tmOverhang;
int tmDigitizedAspectX;
int tmDigitizedAspectY;
wchar tmFirstChar;
wchar tmLastChar;
wchar tmDefaultChar;
wchar tmBreakChar;
ubyte tmItalic;
ubyte tmUnderlined;
ubyte tmStruckOut;
ubyte tmPitchAndFamily;
ubyte tmCharSet;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; TEXTMETRICW サイズ: 60 バイト(x64)
dim st, 15 ; 4byte整数×15(構造体サイズ 60 / 4 切り上げ)
; tmHeight : INT (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; tmAscent : INT (+4, 4byte) st.1 = 値 / 値 = st.1 (lpoke/lpeek も可)
; tmDescent : INT (+8, 4byte) st.2 = 値 / 値 = st.2 (lpoke/lpeek も可)
; tmInternalLeading : INT (+12, 4byte) st.3 = 値 / 値 = st.3 (lpoke/lpeek も可)
; tmExternalLeading : INT (+16, 4byte) st.4 = 値 / 値 = st.4 (lpoke/lpeek も可)
; tmAveCharWidth : INT (+20, 4byte) st.5 = 値 / 値 = st.5 (lpoke/lpeek も可)
; tmMaxCharWidth : INT (+24, 4byte) st.6 = 値 / 値 = st.6 (lpoke/lpeek も可)
; tmWeight : INT (+28, 4byte) st.7 = 値 / 値 = st.7 (lpoke/lpeek も可)
; tmOverhang : INT (+32, 4byte) st.8 = 値 / 値 = st.8 (lpoke/lpeek も可)
; tmDigitizedAspectX : INT (+36, 4byte) st.9 = 値 / 値 = st.9 (lpoke/lpeek も可)
; tmDigitizedAspectY : INT (+40, 4byte) st.10 = 値 / 値 = st.10 (lpoke/lpeek も可)
; tmFirstChar : WCHAR (+44, 2byte) wpoke st,44,値 / 値 = wpeek(st,44)
; tmLastChar : WCHAR (+46, 2byte) wpoke st,46,値 / 値 = wpeek(st,46)
; tmDefaultChar : WCHAR (+48, 2byte) wpoke st,48,値 / 値 = wpeek(st,48)
; tmBreakChar : WCHAR (+50, 2byte) wpoke st,50,値 / 値 = wpeek(st,50)
; tmItalic : BYTE (+52, 1byte) poke st,52,値 / 値 = peek(st,52)
; tmUnderlined : BYTE (+53, 1byte) poke st,53,値 / 値 = peek(st,53)
; tmStruckOut : BYTE (+54, 1byte) poke st,54,値 / 値 = peek(st,54)
; tmPitchAndFamily : TMPF_FLAGS (+55, 1byte) poke st,55,値 / 値 = peek(st,55)
; tmCharSet : BYTE (+56, 1byte) poke st,56,値 / 値 = peek(st,56)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global TEXTMETRICW
#field int tmHeight
#field int tmAscent
#field int tmDescent
#field int tmInternalLeading
#field int tmExternalLeading
#field int tmAveCharWidth
#field int tmMaxCharWidth
#field int tmWeight
#field int tmOverhang
#field int tmDigitizedAspectX
#field int tmDigitizedAspectY
#field short tmFirstChar
#field short tmLastChar
#field short tmDefaultChar
#field short tmBreakChar
#field byte tmItalic
#field byte tmUnderlined
#field byte tmStruckOut
#field byte tmPitchAndFamily
#field byte tmCharSet
#endstruct
stdim st, TEXTMETRICW ; NSTRUCT 変数を確保
st->tmHeight = 100
mes "tmHeight=" + st->tmHeight