API referenceFonts

fntGetTextWidth

Measure text width using a PFNT snapshot's per-byte width

CategoryFont-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

C
double __stdcall fntGetTextWidth(PFNT IFont, const char* Text, uint32_t Len, float CharSpacing, float WordSpacing, float TextScale);
Delphi
function fntGetTextWidth(const IFont: PFNT; const Text: PAnsiChar; Len: Cardinal; CharSpacing, WordSpacing, TextScale: Single): Double; stdcall; external 'LumasPdf.dll';

Parameters

ParameterTypeDescription
IFontPFNTSnapshot handle.
TextPAnsiCharSingle-byte text buffer.
LenCardinalByte length.
CharSpacingSingleAdded per character (Tc-equivalent).
WordSpacingSingleAdded per space byte (Tw-equivalent).
TextScaleSingleHorizontal scale percentage; <= 0 defaults to 100.

Return value — Width in points; 0.0 on a NULL/degenerate snapshot or NULL text.

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern double fntGetTextWidth(IntPtr IFont, [MarshalAs(UnmanagedType.LPStr)] string Text, uint Len, float CharSpacing, float WordSpacing, float TextScale);
Area
Fonts
Category

Font Services

Exported names

fntGetTextWidth

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.