| Category | Font-object metrics |
|---|
Purpose — Measure text width using a PFNT snapshot's per-byte width table, with character/word spacing and horizontal scaling applied.
Description — Sums WidthByByte[B] for each byte of Text (a single-byte-per-character model — not Unicode/multi-byte aware; for a CID/Type0 font's snapshot this is not the correct measurement path), scales by TextScale/100 (TextScale <= 0 defaults to 100), then adds CharSpacing × charCount + WordSpacing × spaceCount — the same composition as pdfGetTextWidth's verified Tc/Tw math.
Declarations
double __stdcall fntGetTextWidth(PFNT IFont, const char* Text, uint32_t Len, float CharSpacing, float WordSpacing, float TextScale);
function fntGetTextWidth(const IFont: PFNT; const Text: PAnsiChar; Len: Cardinal; CharSpacing, WordSpacing, TextScale: Single): Double; stdcall; external 'LumasPdf.dll';
Parameters
| Parameter | Type | Description |
|---|---|---|
IFont | PFNT | Snapshot handle. |
Text | PAnsiChar | Single-byte text buffer. |
Len | Cardinal | Byte length. |
CharSpacing | Single | Added per character (Tc-equivalent). |
WordSpacing | Single | Added per space byte (Tw-equivalent). |
TextScale | Single | Horizontal scale percentage; <= 0 defaults to 100. |
Return value — Width in points; 0.0 on a NULL/degenerate snapshot or NULL text.
C# (P/Invoke)
public static extern double fntGetTextWidth(IntPtr IFont, [MarshalAs(UnmanagedType.LPStr)] string Text, uint Len, float CharSpacing, float WordSpacing, float TextScale);
Font Services
fntGetTextWidth
The …A form takes UTF-8, …W
takes UTF-16; a bare name aliases the ANSI form.
Worked examples — complete programs in ten languages.