API referenceFonts

psrSetAltFont

Register an alternate font name in a psr context (see

CategoryInteractive text replacement (alt-font registry)
Exported namespsrSetAltFontA, psrSetAltFontW
Notea real, functioning mechanism (unlike the document-level alt-font-list confusion in E03); Style/Size/Embed/CP accepted but unused

Purpose — Register an alternate font name in a psr context (see [Interactive Text Search, Selection & Replacement](../V06_Text/E05_InteractiveTextSearchAndReplace.md) for the psr* workflow), for use when replacing selected text with characters the selection's own font can't represent.

Description — genuinely consumed, verified. Appends Name to Ctx.AltFontNames, returning its 1-based handle. This registry, together with psrChangeAltFont, is read by psrReplaceSelText: if an alt font is the current selection (via psrChangeAltFont) and the replacement text contains non-Latin-1 characters, that call currently fails (full alt-font re-encoding isn't implemented) rather than corrupting output — see that entry for the exact behavior. This is a separate, working mechanism from the confusingly-named, non-functional document-level pdfCreateAltFontList/ pdfActivateAltFontList/pdfSetAltFontsA family documented in E03 — don't confuse the two.

Declarations

C
int32_t __stdcall psrSetAltFontA(PPDF IPDF, IPSR Ctx, const char* Name, TFStyle Style, double Size, BOOL32 Embed, TCodepage CP);
int32_t __stdcall psrSetAltFontW(PPDF IPDF, IPSR Ctx, const wchar_t* Name, TFStyle Style, double Size, BOOL32 Embed, TCodepage CP);
Delphi
function psrSetAltFontA(const IPDF: PPDF; const Ctx: IPSR; const Name: PAnsiChar; Style: TFStyle; Size: Double; Embed: LongBool; CP: TCodepage): Integer; stdcall; external 'LumasPdf.dll';
function psrSetAltFontW(const IPDF: PPDF; const Ctx: IPSR; const Name: PWideChar; Style: TFStyle; Size: Double; Embed: LongBool; CP: TCodepage): Integer; stdcall; external 'LumasPdf.dll';

Parameters

ParameterTypeDescription
IPDFPPDFInstance handle.
CtxIPSRA parsed psr context (from psrParsePage).
NamestringAlt font name to register. Only this parameter is actually used.
Style, Size, Embed, CPvariousAll accepted but not read by this implementation — the registry stores only the name.

Return value — 1-based handle for the newly registered entry; 0 if Ctx is invalid.

See alsopsrChangeAltFont, psrReplaceSelText

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int psrSetAltFontA(IntPtr IPDF, IntPtr Ctx, [MarshalAs(UnmanagedType.LPStr)] string Name, int Style, double Size, [MarshalAs(UnmanagedType.Bool)] bool Embed, TCodepage CP);
public static extern int psrSetAltFontW(IntPtr IPDF, IntPtr Ctx, [MarshalAs(UnmanagedType.LPWStr)] string Name, int Style, double Size, [MarshalAs(UnmanagedType.Bool)] bool Embed, TCodepage CP);
Area
Fonts
Category

Misc

Exported names

psrSetAltFontA psrSetAltFontW

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.