Add public API to support forced colors mode
The CL extends support for color scheme in PDFium to a forced
color scheme which is applied when calling the new progressive
render API.
The color scheme is currently applied to only text and path.
For text rendering, the color of the text (fill and stroke) is
changed to the color mentioned in the color scheme.
Similarly colors for fill and stroke can be set for path rendering.
In addition to this there is an option to change the fill paths to
strokes, which is required since with fill paths using a single
color, a graphics with multiple adjacent fill paths will not be
decipherable.
All annotations also follow the above rules, except forms (PDF
annotation widgets like text box, combo box etc.) which
are not part of this change, and will be taken up separately.
There also needs to be a special handling for highlight since
the Multiply blend mode leads to the highlights being less visible
in some color schemes, which will be taken up separately.
The above is achieved by the following changes:
1. Adding a struct for the various graphics objects in a pdf for
which a color can be specified and honored. The
corresponding colors are set by the caller. The CL adds support
for only fill and stroke color of paths and text. Subsequent CLs
will add support for more objects.
2. Adding a new API in the progressive rendering public APIs to
pass in the forced color scheme from the caller.
3. Adding a structure in CPDF_RenderOptions to keep a cache of the
color scheme, and a setter method for the same.
4. Adding a new method CPDF_RenderOptions::TranslateOjectColor()
to translate the color of an object based on its type and
render type to the corresponding forced color.
5. Modifying CPDF_RenderStatus::GetFillArgbInternal() and
CPDF_RenderStatus::GetStrokeArgb() to call the above added method for
translating the color for stroke and fill paths.
6. Modifying CPDF_RenderStatus::ProcessPathPattern() to add code to
convert fill paths to stroke.
7. Adding embedder test for testing rendering using the forced color
scheme in public APIs with different content types.
8. Adding command line flags to pdfium_test to test forced color
scheme rendering using a sample color scheme.
Bug: pdfium:1391
Change-Id: I8b3f43eb0290d11b6a1ee2d5a36dfd1f0c0993e8
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/62270
Commit-Queue: Gourab Kundu <gourabk@microsoft.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index 4f0ab7e..d7f211c 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -108,6 +108,8 @@
bool lcd_text = false;
bool no_nativetext = false;
bool grayscale = false;
+ bool forced_color = false;
+ bool fill_to_stroke = false;
bool limit_cache = false;
bool force_halftone = false;
bool printing = false;
@@ -153,6 +155,8 @@
flags |= FPDF_NO_NATIVETEXT;
if (options.grayscale)
flags |= FPDF_GRAYSCALE;
+ if (options.fill_to_stroke)
+ flags |= FPDF_CONVERT_FILL_TO_STROKE;
if (options.limit_cache)
flags |= FPDF_RENDER_LIMITEDIMAGECACHE;
if (options.force_halftone)
@@ -422,6 +426,10 @@
options->no_nativetext = true;
} else if (cur_arg == "--grayscale") {
options->grayscale = true;
+ } else if (cur_arg == "--forced-color") {
+ options->forced_color = true;
+ } else if (cur_arg == "--fill-to-stroke") {
+ options->fill_to_stroke = true;
} else if (cur_arg == "--limit-cache") {
options->limit_cache = true;
} else if (cur_arg == "--force-halftone") {
@@ -747,8 +755,16 @@
pause.version = 1;
pause.NeedToPauseNow = &NeedToPauseNow;
- int rv = FPDF_RenderPageBitmap_Start(bitmap.get(), page, 0, 0, width,
- height, 0, flags, &pause);
+ // Client programs will be setting these values when rendering.
+ // This is a sample color scheme with distinct colors.
+ // Used only when |options.forced_color| is true.
+ const FPDF_COLORSCHEME color_scheme{
+ /*path_fill_color=*/0xFFFF0000, /*path_stroke_color=*/0xFF00FF00,
+ /*text_fill_color=*/0xFF0000FF, /*text_stroke_color=*/0xFF00FFFF};
+
+ int rv = FPDF_RenderPageBitmapWithColorScheme_Start(
+ bitmap.get(), page, 0, 0, width, height, 0, flags,
+ options.forced_color ? &color_scheme : nullptr, &pause);
while (rv == FPDF_RENDER_TOBECONTINUED)
rv = FPDF_RenderPage_Continue(page, &pause);
}
@@ -1032,6 +1048,8 @@
" --lcd-text - render text optimized for LCD displays\n"
" --no-nativetext - render without using the native text output\n"
" --grayscale - render grayscale output\n"
+ " --forced-color - render in forced color mode\n"
+ " --fill-to-stroke - render fill as stroke in forced color mode\n"
" --limit-cache - render limiting image cache size\n"
" --force-halftone - render forcing halftone\n"
" --printing - render as if for printing\n"