Teknisk artikel

PDFium: low-vision color filters and reading modes in Delphi

Integrera PDFium VCL Component-flöden i Delphi- och C++Builder-applikationer, eller PDFium LCL Component-flöden i Lazarus/FPC, med källkodskomponenter för visning, rendering, formulär, utskrift, preflight-rapporter och standardinriktad validering.

Den här artikeln är skriven för developers adding viewing aids for users who need contrast, color inversion, or reduced visual strain. Den behandlar low-vision color filters and reading modes som produktionsnära dokumentteknik, inte som ett isolerat komponentanrop.

Den praktiska risken är att display filters can help users read documents, but they can also mislead review workflows if the application does not explain that the source PDF is unchanged. Därför behöver flödet ett skrivet kontrakt, observerbar diagnostik och realistiska regressionsfiler.

Arkitekturbeslut

Keep visual assistance separate from document editing. available modes such as high contrast, grayscale, inverted color, and warm background / whether filters apply to pages, thumbnails, selection highlights, and annotations

  • available modes such as high contrast, grayscale, inverted color, and warm background
  • whether filters apply to pages, thumbnails, selection highlights, and annotations
  • preference persistence per user, per document, or per application profile
  • screen capture, print, and export behavior while filters are active

Implementeringsflöde

Apply filters in the rendering pipeline. Ordningen nedan gör arbetsflödet granskbart för Delphi- och C++Builder-team.

  1. add filter selection to viewer state rather than PDF modification code
  2. render representative text, images, forms, and annotations through each mode
  3. keep selection colors and focus indicators visible under every filter
  4. show whether printing uses the original PDF appearance or the filtered view
  5. record mode settings when users report readability issues

Valideringsbevis

Usability evidence for low-vision modes. Behåll dessa fält tillsammans med utdata eller supportunderlaget.

  • filter mode, contrast ratio spot checks, zoom level, and page rendering backend
  • selection, annotation, form-field, and focus visibility under the active mode
  • preference storage decision and reset path
  • support screenshot that clearly labels filtered display state

A filter is a view, not a document change

Low-vision support should alter the rendered presentation without changing the PDF bytes. Users need predictable toggles, persistent preferences, clear print behavior, and fallback text when a document cannot be read visually.

Decision table for low-vision color filters and reading modes

A decision table keeps product ownership visible when the same workflow is reused by a desktop tool, service job, and support utility.

DecisionEngineering reasonEvidence
available modes such as high contrast, grayscale, inverted color, and warm backgroundadd filter selection to viewer state rather than PDF modification codefilter mode, contrast ratio spot checks, zoom level, and page rendering backend
whether filters apply to pages, thumbnails, selection highlights, and annotationsrender representative text, images, forms, and annotations through each modeselection, annotation, form-field, and focus visibility under the active mode
preference persistence per user, per document, or per application profilekeep selection colors and focus indicators visible under every filterpreference storage decision and reset path

Tekniska granskningsnoteringar för low-vision color filters and reading modes

Använd dessa granskningsnoteringar för att säkerställa att funktionen har passerat demo-nivån och kan försvaras under leverans, support och kundeskalering.

  • Beslut: available modes such as high contrast, grayscale, inverted color, and warm background. Implementeringspresspunkt: render representative text, images, forms, and annotations through each mode. Acceptansbevis: preference storage decision and reset path. Regressionsutlösare: dark-mode application chrome should not reduce document focus visibility
  • Beslut: whether filters apply to pages, thumbnails, selection highlights, and annotations. Implementeringspresspunkt: keep selection colors and focus indicators visible under every filter. Acceptansbevis: support screenshot that clearly labels filtered display state. Regressionsutlösare: image-heavy PDFs may lose detail under aggressive contrast transforms
  • Beslut: preference persistence per user, per document, or per application profile. Implementeringspresspunkt: show whether printing uses the original PDF appearance or the filtered view. Acceptansbevis: filter mode, contrast ratio spot checks, zoom level, and page rendering backend. Regressionsutlösare: highlight colors can disappear if filters are applied after overlay painting
  • Beslut: screen capture, print, and export behavior while filters are active. Implementeringspresspunkt: record mode settings when users report readability issues. Acceptansbevis: selection, annotation, form-field, and focus visibility under the active mode. Regressionsutlösare: printing a filtered view may be desired for accessibility but wrong for legal review

Gränsfall

  • image-heavy PDFs may lose detail under aggressive contrast transforms
  • highlight colors can disappear if filters are applied after overlay painting
  • printing a filtered view may be desired for accessibility but wrong for legal review
  • dark-mode application chrome should not reduce document focus visibility

Delphi / C++Builder notes

PDFium Component should sit behind a small service boundary that receives files, streams, profiles, and credentials, then returns output paths, warnings, metrics, and validation status. Important terms include color filter, contrast, inversion, reading mode, render pipeline, accessibility.

Delphi-kodexempel

Följande Delphi-skiss visar en praktisk servicegräns för detta ämne. Håll policykontroller, loggning och validering utanför det smala produktanropet så att arbetsflödet går att testa.

procedure TPreviewForm.ApplyReadingTheme(const Theme: TReadingTheme);
begin
  FCurrentTheme := Theme;
  RenderCurrentPage;
  ApplyBitmapColorMatrix(FPageBitmap, Theme.ColorMatrix);
  PaintContrastCheckedBitmap(FPageBitmap);
  LogAccessibilitySetting(Theme.Name);
end;

Produktionschecklista

  • Kör arbetsflödet på en tom fil, en normal kundfil och en värstafallfil
  • Öppna den genererade PDF-filen med rätt visare, validator, skrivare eller nedströmsapplikation
  • Logga produktversion, profilversion, inmatningshash, utdatasökväg, förfluten tid och antal varningar
  • Håll lösenord, certifikat, tillfälliga filer och kunddata under tydliga lagringsregler
  • Lägg till regressionsdokument när en kundfil avslöjar ett nytt gränsfall

Produktdokumentation

PDFium Component

Fler kodexempel

// Engine-level: grayscale applied during rasterization
GrayA := Pdf.RenderPage(0, 0, W, H, ro0, [reGrayscale]);

// Post-process: render in color, convert the finished bitmap
GrayB := Pdf.RenderPage(0, 0, W, H);
GrayscalePdfBitmap(GrayB);
// Affects the on-screen view only
PdfView.PageColor := $00D9EDF2;  // warm paper tone behind page content

// RenderPage output ignores PageColor; pass the color explicitly
Bmp := Pdf.RenderPage(0, 0, W, H, ro0, [], $00D9EDF2);