Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

TEXTMETRIC (Structures)
 
.
Summary
Contains basic information about a physical font.
Remarks
Always be explicit which character set you want to use. Use either TEXTMETRICA with the character set Ansi or TEXTMETRICW with the character set Unicode. Avoid the use of Auto as it is platform dependent and might cause memory leaks.

C# Definition:

[Serializable, StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

Note
Since a type 'char' is stored in .NET within 2 bytes, but the Win32 API assumes that the type 'char' is stored within 1 bytes, it will cause compatibility problems to use the 'char' keyword by the definition of this structure. If you keep the 'char' keyword, then the whole data after tmFirstChar will be offsetted by 4 bytes so use the byte keyword and convert the characters programmically later on to use it.
Warning
This advice of using byte instead of char may cause issues as there is not enough memory reserved if the W version of the function is called with this structure. In my case it was leaking Font GDI objects, and setting the fields back to char fixed it.

[Serializable, StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct TEXTMETRIC
{
    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;    // this assumes the ANSI charset; for the UNICODE charset the type is char (or short)
    public byte tmLastChar;     // this assumes the ANSI charset; for the UNICODE charset the type is char (or short)
    public byte tmDefaultChar;  // this assumes the ANSI charset; for the UNICODE charset the type is char (or short)
    public byte tmBreakChar;    // this assumes the ANSI charset; for the UNICODE charset the type is char (or short)
    public byte tmFirstChar;    // for compatibility issues it must be byte instead of char (see the comment for further details above)
    public byte tmLastChar;    // for compatibility issues it must be byte instead of char (see the comment for further details above)
    public byte tmDefaultChar;    // for compatibility issues it must be byte instead of char (see the comment for further details above)
    public byte tmBreakChar;    // for compatibility issues it must be byte instead of char (see the comment for further details above)
    public byte tmItalic;
    public byte tmUnderlined;
    public byte tmStruckOut;
    public byte tmPitchAndFamily;
    public byte tmCharSet;
}

[Serializable, 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 ushort tmFirstChar;
    public ushort tmLastChar;
    public ushort tmDefaultChar;
    public ushort tmBreakChar;
    public byte tmItalic;
    public byte tmUnderlined;
    public byte tmStruckOut;
    public byte tmPitchAndFamily;
    public byte tmCharSet;
}

[Serializable, StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct TEXTMETRICA
{
    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 tmFirstChar;    // for compatibility issues it must be byte instead of char (see the comment for further details above)
    public byte tmLastChar;    // for compatibility issues it must be byte instead of char (see the comment for further details above)
    public byte tmDefaultChar;    // for compatibility issues it must be byte instead of char (see the comment for further details above)
    public byte tmBreakChar;    // for compatibility issues it must be byte instead of char (see the comment for further details above)
    public byte tmItalic;
    public byte tmUnderlined;
    public byte tmStruckOut;
    public byte tmPitchAndFamily;
    public byte tmCharSet;
}

VB Definition

<Serializable(), StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Public Structure TEXTMETRIC
    Public tmHeight As Int32
    Public tmAscent As Int32
    Public tmDescent As Int32
    Public tmInternalLeading As Int32
    Public tmExternalLeading As Int32
    Public tmAveCharWidth As Int32
    Public tmMaxCharWidth As Int32
    Public tmWeight As Int32
    Public tmOverhang As Int32
    Public tmDigitizedAspectX As Int32
    Public tmDigitizedAspectY As Int32
    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 Structure
    <Serializable(), StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
     Public Structure TEXTMETRIC
        Public tmHeight As Int32
        Public tmAscent As Int32
        Public tmDescent As Int32
        Public tmInternalLeading As Int32
        Public tmExternalLeading As Int32
        Public tmAveCharWidth As Int32
        Public tmMaxCharWidth As Int32
        Public tmWeight As Int32
        Public tmOverhang As Int32
        Public tmDigitizedAspectX As Int32
        Public tmDigitizedAspectY As Int32
        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 Structure

<Serializable(), StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
Public Structure TEXTMETRICW
    Public tmHeight As Int32
    Public tmAscent As Int32
    Public tmDescent As Int32
    Public tmInternalLeading As Int32
    Public tmExternalLeading As Int32
    Public tmAveCharWidth As Int32
    Public tmMaxCharWidth As Int32
    Public tmWeight As Int32
    Public tmOverhang As Int32
    Public tmDigitizedAspectX As Int32
    Public tmDigitizedAspectY As Int32
    Public tmFirstChar As UShort
    Public tmLastChar As UShort
    Public tmDefaultChar As UShort
    Public tmBreakChar As UShort
    Public tmItalic As Byte
    Public tmUnderlined As Byte
    Public tmStruckOut As Byte
    Public tmPitchAndFamily As Byte
    Public tmCharSet As Byte
End Structure
    <Serializable(), StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)> _
     Public Structure TEXTMETRICW
        Public tmHeight As Int32
        Public tmAscent As Int32
        Public tmDescent As Int32
        Public tmInternalLeading As Int32
        Public tmExternalLeading As Int32
        Public tmAveCharWidth As Int32
        Public tmMaxCharWidth As Int32
        Public tmWeight As Int32
        Public tmOverhang As Int32
        Public tmDigitizedAspectX As Int32
        Public tmDigitizedAspectY As Int32
        Public tmFirstChar As UShort
        Public tmLastChar As UShort
        Public tmDefaultChar As UShort
        Public tmBreakChar As UShort
        Public tmItalic As Byte
        Public tmUnderlined As Byte
        Public tmStruckOut As Byte
        Public tmPitchAndFamily As Byte
        Public tmCharSet As Byte
    End Structure

<Serializable(), StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Public Structure TEXTMETRICA
    Public tmHeight As Int32
    Public tmAscent As Int32
    Public tmDescent As Int32
    Public tmInternalLeading As Int32
    Public tmExternalLeading As Int32
    Public tmAveCharWidth As Int32
    Public tmMaxCharWidth As Int32
    Public tmWeight As Int32
    Public tmOverhang As Int32
    Public tmDigitizedAspectX As Int32
    Public tmDigitizedAspectY As Int32
    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 Structure
       <Serializable(), StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
     Public Structure TEXTMETRICA
        Public tmHeight As Int32
        Public tmAscent As Int32
        Public tmDescent As Int32
        Public tmInternalLeading As Int32
        Public tmExternalLeading As Int32
        Public tmAveCharWidth As Int32
        Public tmMaxCharWidth As Int32
        Public tmWeight As Int32
        Public tmOverhang As Int32
        Public tmDigitizedAspectX As Int32
        Public tmDigitizedAspectY As Int32
        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 Structure

Notes:

None.

Documentation
TEXTMETRIC on MSDN

Please edit this page!

Do you have...

  • helpful tips?
  • corrections to the existing content?
  • alternate definitions?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions