Native rich-text media queries
The native XHTML decoder evaluates a style element's media attribute and nested @media groups before cascading supported declarations into actual rich-text runs
Media evaluation uses an explicit native host profile and does not inspect a desktop, browser or display device
Options := THPDFHeadlessRichTextDecodeOptions.Default;
Options.MediaType := hrmtScreen;
SetLength(Options.MediaFeatures, 2);
Options.MediaFeatures[0].Name := 'width';
Options.MediaFeatures[0].Value := '800px';
Options.MediaFeatures[1].Name := 'resolution';
Options.MediaFeatures[1].Value := '2dppx';
Runs := HPDFDecodeHeadlessRichText(XHTML, Options);
<style media="screen and (width >= 600px)">
@media (resolution >= 2dppx) {
span.notice { font-size: 14pt }
}
</style>
Conditions and cascading
Queries support all, print and screen media types, only and not modifiers, comma-separated alternatives and parenthesized not, and and or conditions
Numeric features accept colon equality, min-/max- forms and forward, reversed or chained range comparisons using =, <, <=, > and >=
Nested groups retain source order, declaration importance, selector specificity and inherited namespace declarations; a style media attribute and all enclosing media groups must match
CSS identifier escapes, comments, exponent notation and balanced function tokens are scanned within the same bounded parser
Unknown features, unsupported values and general-enclosed conditions retain an unknown truth value through negation and Boolean evaluation; only a final true query enables its declarations
Providing a host entry for a future feature does not make that feature part of the supported query vocabulary
Host profile
Supported numeric features are width, height, device-width, device-height, resolution, aspect-ratio, device-aspect-ratio, color, color-index, monochrome and grid
Discrete features are orientation, scan, update, overflow-block, overflow-inline, color-gamut, pointer, any-pointer, hover and any-hover
Length units are pt, px, in, pc, cm, mm, q, em and rem; resolution units are dpi, dpcm, dppx and x, and ratios use slash notation
Media em and rem use MediaInitialFontSize rather than a cascaded element font size; its default is 12 points, and zero retains the same 12-point initial value for zero-initialised legacy records
An omitted orientation or aspect-ratio may be derived from supplied width and height; zero height leaves the ratio unknown, whilst equal width and height use portrait orientation
any-pointer may contain both coarse and fine; none cannot be combined with another pointer value, and color-gamut includes the lower supported gamut ranks
The default medium is print, with 8 colour bits, no indexed or monochrome colour, grid 0 and sRGB gamut; its update, overflow-inline, pointer, hover and scan capabilities are absent, and overflow-block is paged
Dimensions and resolution have no invented device defaults; screen capabilities other than the shared colour defaults require an explicit host value when relevant
MediaFeatures permits at most 32 distinct ASCII-insensitive names, each with 1 to 64 ASCII letters, digits or hyphens and a value of 1 to 256 UTF-16 code units; recognised entries must use a valid non-negative numeric or supported discrete value
MediaInitialFontSize must be finite and either zero or between 0.000001 and 1000000 points; invalid host profiles raise EHPDFHeadlessRichTextCodecError before returning runs
Explicit preferences and accessibility
Supply preferences as MediaFeatures entries; they describe the caller's rendering environment and do not inspect an operating system, browser or active desktop
| Feature | Accepted values | False Boolean value |
|---|---|---|
| prefers-color-scheme | light, dark | Neither value |
| prefers-reduced-motion | no-preference, reduce | no-preference |
| prefers-reduced-transparency | no-preference, reduce | no-preference |
| prefers-contrast | no-preference, less, more, custom | no-preference |
| prefers-reduced-data | no-preference, reduce | no-preference |
| forced-colors | none, active | none |
| inverted-colors | none, inverted | none |
| scripting | none, initial-only, enabled | none |
Options := THPDFHeadlessRichTextDecodeOptions.Default;
Options.MediaType := hrmtScreen;
SetLength(Options.MediaFeatures, 2);
Options.MediaFeatures[0].Name := 'prefers-color-scheme';
Options.MediaFeatures[0].Value := 'dark';
Options.MediaFeatures[1].Name := 'prefers-contrast';
Options.MediaFeatures[1].Value := 'more';
Runs := HPDFDecodeHeadlessRichText(XHTML, Options);
@media (prefers-color-scheme: dark) and (prefers-contrast: more) {
span.notice { font-size: 20pt; font-weight: bold }
}
All eight features are discrete: use equality or a Boolean condition, and do not use min-/max- or ordered range comparisons
Light is an active color-scheme value in a Boolean query, and less or custom is an active contrast preference; custom does not imply more
An omitted preference remains unknown for both print and screen, including under not; the decoder does not invent no-preference, light, none or another fallback value
Invalid values for recognised host features reject the profile before runs are returned; CSS identifier escapes and comments use the existing bounded tokenizer, including comments consumed through end of input
The scripting feature only describes availability supplied by the caller; evaluating the query does not execute JavaScript
Style media attributes, nested groups and caller-supplied external sheets share these feature semantics and existing cascade rules
Saved documents and bounds
Native callers can configure a custom host profile through THPDFHeadlessRichTextDecodeOptions and pass it directly to HPDFDecodeHeadlessRichText
Computed runs retain the chosen styles in saved RV and embedded appearances; ordinary FDF/XFDF imports use the default print profile
Media tokens, nested groups, host-value parsing and matching share MaxNodes, MaxTotalCodeUnits, MaxDepth and cancellation accounting with the existing stylesheet parser
Failed decoding does not publish partial runs, and failed imports retain the surrounding transaction's prior document state
Import layers and supports conditions, calc and viewport units, further media features and general CSS layout remain separate work
Internal style sheets · Native options
External link and import conditions use the same media evaluator