Win32 API 日本語リファレンス
ホームGraphics.Gdi › NEWTEXTMETRICA

NEWTEXTMETRICA

構造体
サイズx64: 72 バイト / x86: 72 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
tmHeightINT4+0+0文字の高さ (アセント + ディセント)。
tmAscentINT4+4+4文字のアセント (ベースラインより上の単位数)。
tmDescentINT4+8+8文字のディセント (ベースラインより下の単位数)。
tmInternalLeadingINT4+12+12tmHeight メンバーによって定められる範囲の内側にあるレディング (余白) の量。アクセント記号やその他のダイアクリティカル文字がこの領域に現れることがあります。フォントの設計者はこのメンバーを 0 に設定してもかまいません。
tmExternalLeadingINT4+16+16アプリケーションが行と行の間に追加する余分なレディング (余白) の量。この領域はフォントの外側にあるため、字形は含まれず、OPAQUE モードと TRANSPARENT モードのいずれにおいてもテキスト出力呼び出しによって変更されることはありません。フォントの設計者はこのメンバーを 0 に設定してもかまいません。
tmAveCharWidthINT4+20+20フォント内の文字の平均幅 (一般に文字 x の幅として定義されます)。この値には、太字文字や斜体文字に必要なオーバーハングは含まれません。
tmMaxCharWidthINT4+24+24フォント内で最も幅の広い文字の幅。
tmWeightINT4+28+28フォントの太さ (ウェイト)。
tmOverhangINT4+32+32

一部の合成フォントで文字列ごとに追加される可能性のある余分な幅。太字や斜体などの属性を合成する際、グラフィックスデバイスインターフェイス (GDI) やデバイスは、文字単位と文字列単位の両方で文字列に幅を追加しなければならない場合があります。たとえば GDI は、各文字の間隔を広げてオフセット値で重ね打ちすることで文字列を太字にし、文字列を斜めにせん断することでフォントを斜体にします。いずれの場合も、基本となる文字列を越えたオーバーハングが生じます。太字の文字列では、オーバーハングは重ね打ちがオフセットされる距離です。斜体の文字列では、オーバーハングはフォントの上部がフォントの下部を越えてせん断される量です。

tmOverhang メンバーを使用すると、1 文字に対する GetTextExtentPoint32 関数の呼び出しで返される文字幅のうち、どれだけが実際の文字幅であり、どれだけが文字列ごとの余分な幅であるかをアプリケーションが判断できます。実際の幅は、エクステントからオーバーハングを引いた値です。

tmDigitizedAspectXINT4+36+36そのフォントが設計対象としたデバイスの水平方向のアスペクト。
tmDigitizedAspectYINT4+40+40そのフォントが設計対象としたデバイスの垂直方向のアスペクト。tmDigitizedAspectX メンバーと tmDigitizedAspectY メンバーの比が、そのフォントが設計対象としたデバイスのアスペクト比です。
tmFirstCharBYTE1+44+44フォントで定義されている最初の文字の値。
tmLastCharBYTE1+45+45フォントで定義されている最後の文字の値。
tmDefaultCharBYTE1+46+46フォントに含まれていない文字の代わりに使用される文字の値。
tmBreakCharBYTE1+47+47テキストの均等割り付けで単語の区切りを定義するために使用される文字の値。
tmItalicBYTE1+48+480 以外の場合は斜体フォントです。
tmUnderlinedBYTE1+49+490 以外の場合は下線付きフォントです。
tmStruckOutBYTE1+50+500 以外の場合は取り消し線付きフォントです。
tmPitchAndFamilyTMPF_FLAGS1+51+51

選択されているフォントのピッチとファミリ。最下位ビット (ビット 0) はフォントのピッチを指定します。1 の場合、フォントは可変ピッチ (プロポーショナル) です。0 の場合、フォントは固定ピッチ (等幅) です。ビット 1 とビット 2 はフォントの種類を指定します。両方のビットが 0 の場合、フォントはラスターフォントです。ビット 1 が 1 でビット 2 が 0 の場合、フォントはベクターフォントです。ビット 1 が 0 でビット 2 が設定されている場合、または両方のビットが 1 の場合、フォントはそれ以外の種類です。ビット 3 は、フォントがデバイスフォントの場合は 1 になり、それ以外の場合は 0 になります。

上位 4 ビットはフォントファミリを表します。tmPitchAndFamily メンバーは、ビット単位のAND演算子を使用して 16 進値 0xF0 と組み合わせることができ、その結果をフォントファミリ名と比較して完全に一致するかどうかを判定できます。フォントファミリの詳細については、LOGFONT を参照してください。

tmCharSetBYTE1+52+52フォントの文字セット。
ntmFlagsDWORD4+56+56

フォントが斜体、下線付き、アウトライン、太字などであるかどうかを指定します。次の値の妥当な組み合わせを指定できます。

ビット 名前 意味
0 NTM_ITALIC 斜体
5 NTM_BOLD 太字
8 NTM_REGULAR 標準
16 NTM_NONNEGATIVE_AC フォント内のどのサイズのグリフにも、負の A スペースまたは C スペースがありません。
17 NTM_PS_OPENTYPE PostScript OpenType フォント
18 NTM_TT_OPENTYPE TrueType OpenType フォント
19 NTM_MULTIPLEMASTER マルチプルマスターフォント
20 NTM_TYPE1 Type 1 フォント
21 NTM_DSIG デジタル署名付きのフォント。これによりトレーサビリティが確保され、フォントがテスト済みで破損していないことが保証されます
ntmSizeEMDWORD4+60+60フォントの em スクエアのサイズ。この値は表記単位 (notional unit、つまりそのフォントが設計された際の単位) で表されます。
ntmCellHeightDWORD4+64+64フォントの高さ (表記単位)。この値は ntmSizeEM メンバーの値と比較してください。
ntmAvgWidthDWORD4+68+68フォント内の文字の平均幅 (表記単位)。この値は ntmSizeEM メンバーの値と比較してください。

公式ドキュメント

NEWTEXTMETRIC 構造体は、物理フォントを説明するデータを格納します。

解説(Remarks)

NEWTEXTMETRIC 構造体の最後の 4 つのメンバーは TEXTMETRIC 構造体には含まれていません。それ以外の点では、両者の構造体は同一です。

NEWTEXTMETRIC 構造体内のサイズは、通常は論理単位で指定されます。つまり、ディスプレイコンテキストの現在のマッピングモードに依存します。

メモ

wingdi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版と Unicode 版を自動的に選択するエイリアスとして NEWTEXTMETRIC を定義しています。エンコーディング中立のエイリアスの使用と、エンコーディング中立でないコードを混在させると、不一致が生じてコンパイルエラーや実行時エラーの原因となる場合があります。詳細については、関数プロトタイプの規則を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での定義

#include <windows.h>

// NEWTEXTMETRICA  (x64 72 / x86 72 バイト)
typedef struct NEWTEXTMETRICA {
    INT tmHeight;
    INT tmAscent;
    INT tmDescent;
    INT tmInternalLeading;
    INT tmExternalLeading;
    INT tmAveCharWidth;
    INT tmMaxCharWidth;
    INT tmWeight;
    INT tmOverhang;
    INT tmDigitizedAspectX;
    INT tmDigitizedAspectY;
    BYTE tmFirstChar;
    BYTE tmLastChar;
    BYTE tmDefaultChar;
    BYTE tmBreakChar;
    BYTE tmItalic;
    BYTE tmUnderlined;
    BYTE tmStruckOut;
    TMPF_FLAGS tmPitchAndFamily;
    BYTE tmCharSet;
    DWORD ntmFlags;
    DWORD ntmSizeEM;
    DWORD ntmCellHeight;
    DWORD ntmAvgWidth;
} NEWTEXTMETRICA;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct NEWTEXTMETRICA
{
    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 byte tmFirstChar;
    public byte tmLastChar;
    public byte tmDefaultChar;
    public byte tmBreakChar;
    public byte tmItalic;
    public byte tmUnderlined;
    public byte tmStruckOut;
    public byte tmPitchAndFamily;
    public byte tmCharSet;
    public uint ntmFlags;
    public uint ntmSizeEM;
    public uint ntmCellHeight;
    public uint ntmAvgWidth;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure NEWTEXTMETRICA
    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 Byte
    Public tmLastChar As Byte
    Public tmDefaultChar As Byte
    Public tmBreakChar As Byte
    Public tmItalic As Byte
    Public tmUnderlined As Byte
    Public tmStruckOut As Byte
    Public tmPitchAndFamily As Byte
    Public tmCharSet As Byte
    Public ntmFlags As UInteger
    Public ntmSizeEM As UInteger
    Public ntmCellHeight As UInteger
    Public ntmAvgWidth As UInteger
End Structure
import ctypes
from ctypes import wintypes

class NEWTEXTMETRICA(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_ubyte),
        ("tmLastChar", ctypes.c_ubyte),
        ("tmDefaultChar", ctypes.c_ubyte),
        ("tmBreakChar", ctypes.c_ubyte),
        ("tmItalic", ctypes.c_ubyte),
        ("tmUnderlined", ctypes.c_ubyte),
        ("tmStruckOut", ctypes.c_ubyte),
        ("tmPitchAndFamily", ctypes.c_ubyte),
        ("tmCharSet", ctypes.c_ubyte),
        ("ntmFlags", wintypes.DWORD),
        ("ntmSizeEM", wintypes.DWORD),
        ("ntmCellHeight", wintypes.DWORD),
        ("ntmAvgWidth", wintypes.DWORD),
    ]
#[repr(C)]
pub struct NEWTEXTMETRICA {
    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: u8,
    pub tmLastChar: u8,
    pub tmDefaultChar: u8,
    pub tmBreakChar: u8,
    pub tmItalic: u8,
    pub tmUnderlined: u8,
    pub tmStruckOut: u8,
    pub tmPitchAndFamily: u8,
    pub tmCharSet: u8,
    pub ntmFlags: u32,
    pub ntmSizeEM: u32,
    pub ntmCellHeight: u32,
    pub ntmAvgWidth: u32,
}
import "golang.org/x/sys/windows"

type NEWTEXTMETRICA struct {
	tmHeight int32
	tmAscent int32
	tmDescent int32
	tmInternalLeading int32
	tmExternalLeading int32
	tmAveCharWidth int32
	tmMaxCharWidth int32
	tmWeight int32
	tmOverhang int32
	tmDigitizedAspectX int32
	tmDigitizedAspectY int32
	tmFirstChar byte
	tmLastChar byte
	tmDefaultChar byte
	tmBreakChar byte
	tmItalic byte
	tmUnderlined byte
	tmStruckOut byte
	tmPitchAndFamily byte
	tmCharSet byte
	ntmFlags uint32
	ntmSizeEM uint32
	ntmCellHeight uint32
	ntmAvgWidth uint32
}
type
  NEWTEXTMETRICA = record
    tmHeight: Integer;
    tmAscent: Integer;
    tmDescent: Integer;
    tmInternalLeading: Integer;
    tmExternalLeading: Integer;
    tmAveCharWidth: Integer;
    tmMaxCharWidth: Integer;
    tmWeight: Integer;
    tmOverhang: Integer;
    tmDigitizedAspectX: Integer;
    tmDigitizedAspectY: Integer;
    tmFirstChar: Byte;
    tmLastChar: Byte;
    tmDefaultChar: Byte;
    tmBreakChar: Byte;
    tmItalic: Byte;
    tmUnderlined: Byte;
    tmStruckOut: Byte;
    tmPitchAndFamily: Byte;
    tmCharSet: Byte;
    ntmFlags: DWORD;
    ntmSizeEM: DWORD;
    ntmCellHeight: DWORD;
    ntmAvgWidth: DWORD;
  end;
const NEWTEXTMETRICA = 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: u8,
    tmLastChar: u8,
    tmDefaultChar: u8,
    tmBreakChar: u8,
    tmItalic: u8,
    tmUnderlined: u8,
    tmStruckOut: u8,
    tmPitchAndFamily: u8,
    tmCharSet: u8,
    ntmFlags: u32,
    ntmSizeEM: u32,
    ntmCellHeight: u32,
    ntmAvgWidth: u32,
};
type
  NEWTEXTMETRICA {.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: uint8
    tmLastChar: uint8
    tmDefaultChar: uint8
    tmBreakChar: uint8
    tmItalic: uint8
    tmUnderlined: uint8
    tmStruckOut: uint8
    tmPitchAndFamily: uint8
    tmCharSet: uint8
    ntmFlags: uint32
    ntmSizeEM: uint32
    ntmCellHeight: uint32
    ntmAvgWidth: uint32
struct NEWTEXTMETRICA
{
    int tmHeight;
    int tmAscent;
    int tmDescent;
    int tmInternalLeading;
    int tmExternalLeading;
    int tmAveCharWidth;
    int tmMaxCharWidth;
    int tmWeight;
    int tmOverhang;
    int tmDigitizedAspectX;
    int tmDigitizedAspectY;
    ubyte tmFirstChar;
    ubyte tmLastChar;
    ubyte tmDefaultChar;
    ubyte tmBreakChar;
    ubyte tmItalic;
    ubyte tmUnderlined;
    ubyte tmStruckOut;
    ubyte tmPitchAndFamily;
    ubyte tmCharSet;
    uint ntmFlags;
    uint ntmSizeEM;
    uint ntmCellHeight;
    uint ntmAvgWidth;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; NEWTEXTMETRICA サイズ: 72 バイト(x64)
dim st, 18    ; 4byte整数×18(構造体サイズ 72 / 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 : BYTE (+44, 1byte)  poke st,44,値  /  値 = peek(st,44)
; tmLastChar : BYTE (+45, 1byte)  poke st,45,値  /  値 = peek(st,45)
; tmDefaultChar : BYTE (+46, 1byte)  poke st,46,値  /  値 = peek(st,46)
; tmBreakChar : BYTE (+47, 1byte)  poke st,47,値  /  値 = peek(st,47)
; tmItalic : BYTE (+48, 1byte)  poke st,48,値  /  値 = peek(st,48)
; tmUnderlined : BYTE (+49, 1byte)  poke st,49,値  /  値 = peek(st,49)
; tmStruckOut : BYTE (+50, 1byte)  poke st,50,値  /  値 = peek(st,50)
; tmPitchAndFamily : TMPF_FLAGS (+51, 1byte)  poke st,51,値  /  値 = peek(st,51)
; tmCharSet : BYTE (+52, 1byte)  poke st,52,値  /  値 = peek(st,52)
; ntmFlags : DWORD (+56, 4byte)  st.14 = 値  /  値 = st.14   (lpoke/lpeek も可)
; ntmSizeEM : DWORD (+60, 4byte)  st.15 = 値  /  値 = st.15   (lpoke/lpeek も可)
; ntmCellHeight : DWORD (+64, 4byte)  st.16 = 値  /  値 = st.16   (lpoke/lpeek も可)
; ntmAvgWidth : DWORD (+68, 4byte)  st.17 = 値  /  値 = st.17   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global NEWTEXTMETRICA
    #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 byte tmFirstChar
    #field byte tmLastChar
    #field byte tmDefaultChar
    #field byte tmBreakChar
    #field byte tmItalic
    #field byte tmUnderlined
    #field byte tmStruckOut
    #field byte tmPitchAndFamily
    #field byte tmCharSet
    #field int ntmFlags
    #field int ntmSizeEM
    #field int ntmCellHeight
    #field int ntmAvgWidth
#endstruct

stdim st, NEWTEXTMETRICA        ; NSTRUCT 変数を確保
st->tmHeight = 100
mes "tmHeight=" + st->tmHeight