COLR foreground color and alpha
Starting in version 2.1100.0, COLR palette entry 0xFFFF uses application foreground color and alpha in both COLRv0 layers and COLRv1 solid or gradient paints. Ordinary CPAL entries retain their own RGBA values
Registered color glyphs
property ColorGlyphForegroundColor: TColor;
property ColorGlyphForegroundAlpha: Byte;
PDF.ColorGlyphForegroundColor := clRed;
PDF.ColorGlyphForegroundAlpha := 128;
PDF.GetRegisteredColorGlyphInfo($41, 0, 96, Info);
PDF.DrawRegisteredColorGlyph(PDF.CurrentPage, $41,
72, 300, FontName, 100, 0, 96);
The defaults are clBlack and 255. ColorToRGB resolves system colors before COLR parsing. Each inspection or draw resolves the current properties from the original registered color program; changing foreground settings does not modify font bytes, pending axis selections or previously returned records
These properties specify application foreground explicitly; they do not inspect the PDF page's current fill color, which may be a pattern or a non-RGB color space. They apply to COLR references to 0xFFFF, leaving SVG and bitmap assets unchanged
COLRv1 paint or stop alpha is clamped and multiplied by foreground alpha once. Version 2.1112.0 retains this normalized combined opacity in the appended AlphaValue: Double and HasAlphaValue: Boolean fields of THPDFCOLRv1Paint and THPDFCOLRv1ColorStop, while preserving the original Alpha: Byte conversion independently
Use HPDFCOLRv1PaintAlpha and HPDFCOLRv1ColorStopAlpha from HPDFOpenTypeAdvanced for effective opacity. Their result already includes foreground alpha for 0xFFFF, or the selected CPAL entry's alpha for ordinary entries; do not multiply either source again. When HasAlphaValue is False, the getter returns Alpha / 255
For example, local alpha 33/16384 with foreground alpha 128 retains positive combined opacity (33/16384) * (128/255) even though its compatibility byte remains zero. The mirror still follows the earlier rule of combining before byte conversion; multiplying a previously quantized byte would incorrectly produce one
The added record tail fields change their layouts and sizes, so rebuild clients and zero-initialize records created by callers before assigning fields. These changes preserve runtime alpha preparation without removing existing 16-bit sampled-gradient output, Single angular-phase calculations, finite graph limits or reader precision differences
Byte-array inspection
THPDFOpenTypeColorForeground = record
Red, Green, Blue, Alpha: Byte;
end;
function HPDFGetCOLRColorGlyphAtAxes(const FontBytes: TBytes;
GlyphID: Word; PaletteIndex: Integer;
const AxisValues: THPDFVariableFontAxisValueArray;
const Foreground: THPDFOpenTypeColorForeground;
out Info: THPDFOpenTypeColorGlyphInfo): Boolean; overload;
function HPDFGetOpenTypeColorGlyphAtAxes(const FontBytes: TBytes;
GlyphID: Word; PaletteIndex, TargetPixelsPerEm: Integer;
const AxisValues: THPDFVariableFontAxisValueArray;
const Foreground: THPDFOpenTypeColorForeground;
out Info: THPDFOpenTypeColorGlyphInfo): Boolean; overload;
The new overloads belong to HPDFOpenTypeAdvanced. Pass nil for AxisValues when default coordinates are wanted. Existing signatures and non-axis inspection APIs retain black/255 foreground defaults. PaletteEntryIndex remains 0xFFFF in returned records so callers can distinguish foreground references from ordinary CPAL colors
Drawing state and callbacks
COLRv0 layers render into one isolated DeviceRGB surface when transparency is available, so the caller's alpha, blend mode and soft mask apply once to the completed glyph. Opaque direct output remains available for strict profiles or a locked PDF version below 1.4; translucent layers use the existing callback fallback in those configurations
Native COLR drawing uses the supplied position and font size independently of inherited horizontal text scaling, text rise and text rendering mode, matching the SVG and bitmap color-glyph placement model. A scoped reset restores the caller's text state afterward; caller graphics transforms, clipping and transparency still apply
OnColorGlyphRasterize keeps its existing signature. A handler can read ColorGlyphForegroundColor and ColorGlyphForegroundAlpha from its THotPDF Sender and pass the corresponding RGBA record to the low-level overloads, together with GetRegisteredVariableFontAxes when needed
Verified scope
Thirty-two focused Delphi Win64 source/reference pairs pass 453 checks and all 1912 MuPDF/Poppler samples, against 125 check failures and 632 pixel failures on the preceding source. Coverage includes tiny alpha, changing and repeating foreground settings, frozen variable axes, all three gradient families, nested xor, caller opacity, callback context and text-state restoration
All 1792 resolved-reference samples are identical; 120 independent COLRv0 RGBA samples have maximum channel error 1. Four retained Porter-Duff outputs preserve every pixel in eight reader images. Existing gradient approximation, finite graph limits and wider reader precision differences remain separate work
The OpenType COLR specification defines the foreground palette entry and its alpha multiplication
See advanced OpenType fonts, selected-axis color glyphs and COLRv1 paint graphs