技術記事

PDFium Component: Delphi での low-vision color filters and reading modes

Delphi/C++Builder には PDFium VCL Component のワークフローを、Lazarus/FPC には PDFium LCL Component のワークフローを組み込み、表示、レンダリング、フォーム、印刷、プリフライトレポート、標準対応の検証をソースコード付きコンポーネントで実装できます。

この記事は developers adding viewing aids for users who need contrast, color inversion, or reduced visual strain 向けです。low-vision color filters and reading modes を単なるコンポーネント呼び出しではなく、本番向けのドキュメントエンジニアリングとして扱います。

実務上のリスクは 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 です。そのため、明確な契約、観測可能な診断、実際の顧客ファイルに近い回帰サンプルが必要です。

アーキテクチャ上の判断

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

実装フロー

Apply filters in the rendering pipeline. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  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

検証エビデンス

Usability evidence for low-vision modes. Keep these fields with the output or support record.

  • 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

low-vision color filters and reading modes に関する技術レビューの注意点

これらのレビュー項目を使って、機能がデモ段階を超え、リリース、サポート、顧客エスカレーションの場で説明できることを確認します

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

境界ケース

  • 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 の補足

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. 重要な用語には color filter, contrast, inversion, reading mode, render pipeline, accessibility.

Delphi コード例

次の Delphi スケッチは、このテーマに対する実用的なサービス境界を示します。ポリシー確認、ログ記録、検証を製品呼び出しの狭い部分の外側に置くと、ワークフローをテストしやすくなります。

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

本番チェックリスト

  • ワークフローは、空のファイル、通常の顧客ファイル、最悪ケースのファイルで実行します
  • 生成された PDF は、対象のビューアー、検証ツール、プリンター、または downstream アプリケーションで開きます
  • 製品バージョン、プロファイルバージョン、入力ハッシュ、出力パス、経過時間、警告数を記録します
  • パスワード、証明書、一時ファイル、顧客データは明確な保持ルールの下で管理します
  • 顧客ファイルが新しい境界ケースを示したら、回帰用ドキュメントを追加します

製品ドキュメント

PDFium Component

追加のコード例

// 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);