Advanced Rendering Semantics
Loaded-page rendering preserves nested Form XObject state while applying transparency groups, soft masks, Type 3 glyph procedures, and resolution-aware visible image-region decoding
Native device default color spaces
The native headless Cairo PNG renderer resolves DefaultGray, DefaultRGB and DefaultCMYK from the current ColorSpace resource dictionary when the corresponding device space is selected
A replacement has the same component count as the original device space and may not be a Lab, Indexed or Pattern space; component-compatible calibrated, ICCBased, Separation, DeviceN and device definitions use their existing converters
Original device components pass unchanged to the replacement and are clamped to its valid range without an extra tint transformation; device image Decode defaults and Indexed palette scaling retain their original sample domains rather than adopting a replacement ICC Range
Device color operators, explicit color-space selections, supported images and inline images, shadings and meshes share this resolution path, including Pattern and Indexed bases and a Separation or DeviceN alternate when that alternate is actually selected
Forms and pattern child contexts retain inherited selected color spaces, while a new selection resolves against the current context's resources with the existing parent-resource fallback; subsequent color components reuse the selected space, and resource dictionaries are not merged or rewritten
Converter caching distinguishes source definitions, resource scope and active default resolution, preserving per-array ICC Range metadata; re-entry into the same active default terminates at its raw device family while other defaults in selected alternates remain available
This same-default termination is an engineering recursion policy, not a claim that the PDF specification disables defaults throughout an entire definition; an identity device replacement can therefore terminate without an infinite lookup
Image SMask samples are mask values rather than device color and are not remapped by DefaultGray; their shape or opacity interpretation follows AIS, while transparency groups retain the existing blending-space validation, working-memory, depth and cancellation limits
The replacement-family restriction is distinct from an ICCBased profile's own color space, so it does not by itself exclude ICCBased Lab or XYZ profiles; default-space replacement adds no public API
These default-space rules follow ISO 32000-1:2008, section 8.6.5.6
Native alpha source and text knockout
The native headless Cairo renderer honors the ExtGState AIS flag, whose default is false: soft-mask values and stroking or nonstroking alpha constants contribute to opacity q when false and to shape f when true, with source alpha formed from their product
Knockout compositing retains shape separately from source alpha across supported paths, text, images, patterns, shadings and transparency groups; graphics-state save and restore retain the flag, and an image's own SMask, Mask or active SMaskInData takes precedence over the graphics-state soft mask
Group boundaries apply their outer alpha and soft-mask parameters once, preserve isolated or non-isolated backdrop and blend behavior, and apply the parent and group bounding-box clips once rather than multiplying clip coverage again during source and shape composition
The TK text-knockout flag defaults to true and retains one initial backdrop for the whole text object from BT through ET, including successive text-show operations; a Type3 CharProc is composed as one glyph rather than treating each internal paint as a separate text glyph
With TK false, text follows the enclosing group's compositing rules without the additional text-object knockout backdrop; TK is set outside BT and ET, as required by ISO 32000-1 section 9.3.8
These rules follow ISO 32000-1:2008, sections 9.3.8, 11.6.4, 11.6.6 and 11.6.7; existing resource budgets and cancellation checks remain active, and this capability does not establish complete rendering or platform coverage
Native semantic resource names
The native headless Cairo PNG renderer preserves a leading slash that belongs to an already decoded color-space resource name, rather than treating that byte as a content-token delimiter
Color-space aliases, selected color-state lookups and inline-image color-space references retain the semantic key; for example, the source name /#2FRGB resolves to the resource key /RGB
Inline image color spaces decode each name exactly once: recognized abbreviations such as G, RGB and I normalize to their canonical names, while an ordinary name keeps its encoded spelling so a literal hash like /A#2320B never aliases its differently escaped neighbor and a nested array base keeps its declared channel count
Native curve flatness
The native headless Cairo PNG renderer applies the i operator and ExtGState FL entry to actual curve approximation, with the same tolerance for either entry point
Flatness is measured in output device pixels and is not multiplied by the content matrix, page UserUnit or output scale; saved graphics state restores it through q and Q, and child PDF path-rendering contexts receive the inherited value
Unspecified flatness and an explicit zero retain the original Cairo context default, normally 0.1 pixels; positive values use Cairo's approximation tolerance and its internal precision floor
The native numeric profile accepts finite values from zero through 1E9; the operator takes exactly one number and the dictionary entry must also be numeric
Independent explicit image-mask resolution
The native headless Cairo PNG renderer preserves an explicit binary image mask's independent width and height until page-space compositing, so a detailed mask retains its coverage when paired with a lower-resolution base image
The base image and mask cover the same image unit square, each with its own sample grid; the mask retains its Decode polarity and interpolation setting, and drawing opacity remains separate from mask shape
Independent explicit image-mask interpolation
When an image and its explicit binary Mask have matching sample dimensions but different Interpolate settings, the native headless Cairo PNG renderer filters image color and mask coverage independently according to their own settings
This path reuses independent explicit-mask compositing: the image and mask map to the same image unit square, mask Decode polarity is retained, and mask shape remains separate from constant drawing opacity and the existing knockout blend behavior
Matching interpolation settings and different-resolution explicit masks retain their existing rendering paths; image soft masks and Matte handling are unchanged by this correction
Independent image soft-mask resolution
The native headless Cairo PNG renderer preserves an image SMask's independent width and height when Matte is absent, retaining detailed opacity over a lower-resolution base image
Both sample grids map to the image unit square, and the soft mask retains its own Decode and interpolation setting; constant drawing alpha multiplies the resulting image opacity once
Under the default opacity interpretation, the full image rectangle remains its shape in knockout groups, including regions where soft opacity is zero; isolated and non-isolated groups retain that distinction and their blend mode
Independent image soft-mask interpolation
When an image and its SMask have matching sample dimensions but different Interpolate settings, the native headless Cairo PNG renderer uses independent color and opacity patterns, preserving smooth opacity over nearest-filtered image samples or sharp opacity over filtered image samples
On this differing-settings path, legal Matte data is unblended using corresponding source color and opacity samples before the color image and soft mask are filtered independently
Drawing alpha is applied once, while the default opacity interpretation retains the full image rectangle as knockout shape and preserves the existing isolated and non-isolated group blend behavior
Matching interpolation settings retain the existing fused color-and-opacity filtering path
Native blend-mode arrays
The native headless Cairo PNG renderer selects the first recognized mode in a BM name array and falls back to Normal when no entry is recognized, replacing any previously selected mode
Every array entry must be a name; traversal retains the renderer's cancellation and cumulative operation limits
Native compatibility sections
The native headless PNG renderer supports nested BX and EX sections and ignores unknown extension operators only while a section is open; recognized PDF operators retain their normal validation and rendering behavior
Compatibility depth belongs to one logical content stream and is independent of q/Q graphics state; concatenated page Contents arrays share that scope, while Form XObjects, Type 3 glyph procedures and soft-mask streams start their own scope
Unbalanced sections, operands supplied to BX/EX, depth limits, operation limits and cancellation fail before destination bytes are published; each compatibility or skipped extension operator still consumes the normal operation budget
The focused non-GUI regression suite is in Tests/Linux/CompatibilitySections; Linux FPC 3.3.1, Windows Delphi 64-bit and Windows FPC 3.3.1 64-bit each pass 103 native assertions, 48 render attempts and independent checks of 30 images containing 96,000 pixel cells
Extended graphics-state fonts
The native headless PNG renderer supports the Font entry of an ExtGState dictionary as a two-element array containing an indirect font dictionary and a finite numeric size; indirect arrays and sizes are resolved through the normal document access
Selections made by gs affect subsequent glyph advances and painting, survive text-object boundaries, follow q/Q restoration and are inherited by nested Form streams; explicit Tf selections continue to override them
Private aliases avoid existing resource and token names without changing source resource dictionaries; expanded prepass tokens, source-index maps, decoder registrations and alias storage use the existing limits and cancellation checkpoints
The focused non-GUI suite is in Tests/Linux/ExtStateFont; Linux FPC 3.3.1, Windows Delphi 64-bit and Windows FPC 3.3.1 64-bit each pass 127 native assertions, 54 render attempts and independent checks of 37 images containing 222,000 whole pixel cells
Ten explicit Tf companions and source-authored Type 3 geometry agree exactly in these fixtures; fifteen invalid or over-budget inputs, entry cancellation and cancellation after a real font-reference resolution preserve failed destinations and permit seventeen clean recoveries
Zero and negative sizes are accepted as finite state values; the zero-size fixture paints no zero-size glyph, and these checks do not claim a complete font-program matrix or cancellation during painting
Inline images
The native headless PNG renderer supports BI/ID/EI inline images with raw samples, ASCIIHexDecode, ASCII85Decode, FlateDecode, RunLengthDecode, LZWDecode, CCITTFaxDecode, DCTDecode and supported filter chains
Raw boundaries use the exact row byte count; ASCII filters require their explicit end marker, and binary decoders retain consumed-input boundaries instead of searching decoded samples for EI
TIFF prediction supports packed 1-, 2- and 4-bit, 8-bit and 16-bit samples; PNG prediction supports the five row filter methods with bounded row storage
CCITT supports Group 3 one-dimensional, mixed Group 3 two-dimensional and Group 4 data, row and end-of-block rules, byte alignment, explicit line markers, black/white polarity and one-bit stencil masks
DCT supports baseline and progressive eight-bit Gray, RGB and CMYK data and supported color-transform selection; dimensions and component declarations must agree with the actual JPEG header
For inline and stream DCT images alike, an Adobe APP14 transform inside the JPEG data takes precedence over DecodeParms ColorTransform, as ISO 32000-1 7.4.8 requires; data without that marker follows the dictionary value or its default of 1 for three components and 0 for four, a null value counts as absent, marker-free data without a JFIF header whose components are labelled R, G and B decodes untransformed unless the dictionary says otherwise, and an illegal ColorTransform value is rejected even when the data carries its own marker
DCT uses the supplied bounded native JPEG kernel rather than the ordinary TurboJPEG image backend; build and deployment instructions are included with Tests/Linux/InlineImages/Native, and HOTPDF_INLINE_JPEG_LIBRARY selects its absolute shared-library path
Gray, RGB and CMYK samples, supported named and direct array color spaces and stencil masks use the existing image painting path; direct array entries undergo recursive type and reference validation before resource dispatch
PDF 2.0 inline Length and L entries are validated against the consumed payload; encrypted fixtures cover AES-256 R5/R6 and Standard RC4 R2/R3 document content, including nonzero object generations and encrypted object streams in the separate legacy-security regressions
RC4 loading and reading retain user versus owner permissions and the original PDFDocEncoding password rules; the encrypted incremental update and signing profile separately describes object-aware RC4 writing and R4 crypt-filter selection
Inline images preserve clipping, surrounding paths, graphics-state restoration and nested Form state; private token masking retains source offsets
Header, token, decoder, sample and predictor storage is charged before allocation; cumulative decoded-byte, working-byte and operation limits and cancellation extend into Flate, LZW, CCITT and bounded JPEG decoding
The focused non-GUI suite passes 542 native assertions across 238 render attempts and independent checks of 177 images containing 566,400 whole pixel cells on Linux FPC 3.3.1, Windows Delphi 64-bit and Windows FPC 3.3.1 64-bit
Fifty-eight positive inputs, fifty-six rejected inputs, five cancellation controls and sixty-one clean recoveries retain the original thresholds; source-authored vector companions agree exactly with decoded samples
The bounded JPEG kernel separately passes 37 allocation-rejection ordinals and 12 cancellation checkpoints with zero remaining reservations and successful retries; these finite fixtures do not establish general renderer conformance or complete external-reader raster identity
Dashed path strokes
Native path rendering preserves complete dash arrays and their phase, including odd-length arrays, fractional lengths, and zero-length painted dashes with round or square caps; the dash pattern restarts at each subpath
Solid-color strokes and gradient-pattern stroke clips share one bounded dash geometry path, retain joins inside continuous painted sections, and join painted sections across a closed contour's start point
Dash lengths retain the renderer's mean current-transformation scale, while curve splitting uses adaptive device-space flattening; fill painting and pending clipping continue to use the original unsplit path
Transparency groups
- Form XObject
/Matrixvalues are composed with the current transformation matrix before group content runs - Isolated groups use a separate alpha plane so black content remains distinguishable from transparent pixels
- Knockout groups replace the previous group contribution in overlapping painted areas
- Group content starts from the Normal blend mode: the blend mode, constant alpha, and soft mask in force at
Doapply to the group as a whole - A group painted with another blend mode blends its own color and alpha with the backdrop; a non-isolated group whose own graphics states blend normally is drawn on black and on white to recover its alpha
- Groups are split into bounded 768-pixel tiles while GDI painting, halftone phase, nested groups, soft masks, and compositing retain absolute device coordinates
- Form bytes are decoded and tokenized once before tile execution, and temporary tile-local masks are released before the next tile
- Nested groups are supported with bounded recursion and complete graphics-state restoration after every Form invocation
Soft masks
/S /Alphaand/S /Luminositymasks are evaluated from the mask group- The mask group is drawn with Normal blending, whatever blend mode the graphics state that sets the mask carries
- Luminosity masks resolve the transparency group
/CSand weight the resolved color with the PDF DeviceGray approximation, as common viewers do; setRenderColorimetricLuminosityMasksto take colourimetric CIE Y for CIE-based spaces instead /BCis validated against the exact blending-space component count and supplies the converted luminosity outside painted mask content- Separation and DeviceN paint is converted through its alternate Lab or ICCBased space so spot components never leak into a soft mask
/TRtransfer functions support sampled, exponential, stitching, and PostScript calculator functions through the shared function evaluator/SMask /Noneclears the active mask andqorQpreserves mask state normally- Compiled masks are reused only when the source dictionary, current transformation matrix, and rendering intent all match
Transfer and sampled functions
/TR2 takes precedence over /TR, a single function applies to every RGB output channel, and a four-function array applies its first three entries independently while preserving /Identity and /Default entries
Applying a new transfer state replaces every channel atomically, so identity entries cannot inherit lookup values from an earlier graphics state
Type 0 sampled functions support one to eight input dimensions and one to thirty-two output dimensions, /BitsPerSample values 1, 2, 4, 8, 12, 16, 24, and 32, reversed or forward /Encode mappings, independent /Decode ranges, multilinear interpolation, multidimensional cubic interpolation falling back to multilinear beyond four inputs, and natural cubic splines for one-dimensional /Order 3 data
Decoded sample bytes, validated dimensions, mappings, and cubic derivatives share an eight-entry LRU capped at 64 MiB per rendering thread, while oversized or malformed functions fail without partially replacing the active transfer lookup table
Halftone screens
Type 6, Type 10, and Type 16 threshold arrays execute directly with exact decoded lengths, big-endian 16-bit thresholds, additive-component comparison, and compact periodic strips that avoid expanding angled or two-rectangle screens
Type 5 dictionaries select independent /Red, /Green, and /Blue screens with /Gray and required /Default fallbacks, while each selected screen can override the global transfer function
Validated threshold bytes and their normalized geometry share a 64-entry LRU capped at 64 MiB per renderer, and malformed dimensions, oversized allocations, nested Type 5 dictionaries, or payload-length mismatches leave the complete active screen state in continuous-tone mode
Type 3 glyphs
Type 3 CharProcs run through the complete content operator engine with the font dictionary's current resource scope, Form support, clipping, images, patterns, and bounded recursion
d0 and d1 provide glyph metrics while a d1 procedure keeps the caller-selected color as required by the PDF imaging model
Repeated CharProcs reuse decoded and tokenized display lists when font, glyph, linear device matrix, and color state match; translation remains dynamic so repeated characters at different positions share one entry
The per-renderer LRU retains at most 256 entries and 131,072 tokens, bypasses any CharProc above 16,384 tokens, and reports its behavior through GetLastType3GlyphCacheStats
Native Type 3 optional-content visibility
The native headless Cairo PNG renderer skips Type 3 glyph procedures while their enclosing optional-content group is hidden, including text rendering modes 4 through 7
Visible Type 3 glyph procedures keep painting in those modes; mode 3 remains invisible, and ordinary-font text clipping retains its existing behavior
Focused Delphi Win64 acceptance covers eight ON/OFF and mode 0, 3, 4 and 7 combinations with 80,016 independent pixel and membership checks; the preserved before-fix images expose the two hidden mode-4 and mode-7 paint leaks
Clipped and downscaled image regions
Axis-aligned image XObjects request only visible source bounds and pass the visible device-pixel size into the decode path
An image with a soft mask is decoded whole at the size it is drawn, and its mask at the same size, so the mask stays aligned with the image while clipping limits what is painted; JPEG masks use the reduced-size DCT decoder
When rendering, a decoded region at least twice the drawn size in both directions is shrunk to exactly the drawn size by area averaging before it is drawn or cached; a large image drawn small then fits the decode cache, so a group drawn twice or a repeated page reuses it, and its soft mask is applied pixel for pixel at that size. Stencil image masks keep their full resolution, and the public region-decoding methods return their documented sizes
JPEG 2000 combines the decoder's native region API with a power-of-two resolution level selected to meet both target dimensions before wavelet reconstruction and raster expansion
Tile-addressable JPEG 2000 codestreams can also decode one validated tile directly through THPDFJpeg2000Decoder.LoadTileFromByteArray, with tile-grid metadata and output-byte limits exposed by the decoder
When a native region intersects multiple independent tiles, LoadRegionFromByteArrayParallel assigns private OpenJPEG state per worker and composes completed rasters in deterministic row-major order; cancellation, output limits, and the effective peak-memory budget can stop scheduling or select the sequential fallback
Region := PDF.DecodeLoadedImageRegion(ImageStream, 128, 64, 640, 480);
try
Canvas.Draw(0, 0, Region);
finally
Region.Free;
end;
Related APIs
- THotPDF.DecodeLoadedImageRegion
- THotPDF.DecodeLoadedImageRegionAtResolution
- THotPDF.DecodeLoadedImageStream
- THotPDF.RenderLoadedPageToBitmap
- THotPDF.GetLastType3GlyphCacheStats
- THotPDF.GetLastTransparencyGroupTileStats
- Rendering Diagnostics and Operation Telemetry
Native stroke adjustment
SA=true stroke adjustment supports complete path outlines, user-space dashes, caps and joins while retaining original fill and clip paths, saved graphics state, nested consumers and existing native-cache resource boundaries