From d87a8615e382cf84245e4634b4c43a44c3ae5cae Mon Sep 17 00:00:00 2001 From: "pdfium-autoroll@skia-public.iam.gserviceaccount.com" Date: Sun, 15 Nov 2026 20:29:06 -0800 Subject: [PATCH 01/34] Roll goldctl from 212e4f24d414 to bcc67c5b5447 If this roll has caused a breakage, revert this CL and set the roller to dry run mode using the controls here: https://autoroll.skia.org/r/goldctl-pdfium Please CC thestig@chromium.org,thestig@google.com on the revert to ensure that a human is aware of the problem. To file a bug in goldctl: https://issues.skia.org To file a bug in PDFium: https://crbug.com/pdfium To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md Bug: None Change-Id: I27319624c740a71440c9ee4e724bed3d884f532d Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164610 Bot-Commit: pdfium-autoroll@skia-public.iam.gserviceaccount.com Commit-Queue: pdfium-autoroll@skia-public.iam.gserviceaccount.com --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index bc799f7de..3e7e2902d 100644 --- a/DEPS +++ b/DEPS @@ -150,7 +150,7 @@ vars = { # Three lines of non-changing comments so that # the commit queue can handle CLs rolling goldctl CIPD package version # and whatever else without interference from each other. - 'goldctl_version': 'git_revision:d528c7cb34ccc8dc701485b2ec6981044203bed5', + 'goldctl_version': 'git_revision:bcc67c5b5447ca23aa2771884031fa18ac6176ac', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling gtest # and whatever else without interference from each other. From c787761e427ac4911580ba2ab176279cab056cc8 Mon Sep 17 00:00:00 2001 From: "pdfium-autoroll@skia-public.iam.gserviceaccount.com" Date: Sun, 15 Nov 2026 23:05:24 -0800 Subject: [PATCH 02/34] Roll Instrumented Libraries from 83128b60913a to 490c778c3a20 (2 revisions) https://chromium.googlesource.com/chromium/third_party/instrumented_libraries.git/+log/83128b60913a..490c778c3a20 If this roll has caused a breakage, revert this CL and set the roller to dry run mode using the controls here: https://autoroll.skia.org/r/instrumented-libraries-pdfium Please CC dhoss@chromium.org,thestig@chromium.org,thestig@google.com on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md Bug: None Change-Id: I1fc265463b1e5c51a6cbfb7f56f47caba8c39228 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164630 Bot-Commit: pdfium-autoroll@skia-public.iam.gserviceaccount.com Commit-Queue: pdfium-autoroll@skia-public.iam.gserviceaccount.com --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 3e7e2902d..2a3c04036 100644 --- a/DEPS +++ b/DEPS @@ -170,7 +170,7 @@ vars = { # Three lines of non-changing comments so that # the commit queue can handle CLs rolling instrumented_lib # and whatever else without interference from each other. - 'instrumented_lib_revision': '83128b60913a82a39d01055312687a27bb959b59', + 'instrumented_lib_revision': '490c778c3a20405a7bfbe42bc426e5d18e5b3bab', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling jinja2 # and whatever else without interference from each other. From 5f70cd34836c5e82cd40dd14381c19d4bc60bf4f Mon Sep 17 00:00:00 2001 From: Antonio Alphonse Date: Mon, 16 Nov 2026 10:34:28 -0800 Subject: [PATCH 03/34] Move pdf_jpx_fuzzer decoding logic into pdf_jpx_fuzzer_common Move the JPX decoding logic out of pdf_jpx_fuzzer.cc into a new pdf_jpx_fuzzer_common source set, so it can be shared with an upcoming FuzzTest version of the fuzzer. pdf_jpx_fuzzer.cc now only parses the decoder parameters from the fuzzer input and calls DecodeJpxForFuzzing(). No functional change intended. Bug: 581810614 Change-Id: I574d19eb0c685f541b2291df1287facb7b9f30e0 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164230 Commit-Queue: Lei Zhang Reviewed-by: Tom Sepez Reviewed-by: Lei Zhang --- testing/fuzzers/BUILD.gn | 23 +++++-- testing/fuzzers/pdf_jpx_fuzzer.cc | 78 ++------------------- testing/fuzzers/pdf_jpx_fuzzer_common.cc | 87 ++++++++++++++++++++++++ testing/fuzzers/pdf_jpx_fuzzer_common.h | 20 ++++++ 4 files changed, 130 insertions(+), 78 deletions(-) create mode 100644 testing/fuzzers/pdf_jpx_fuzzer_common.cc create mode 100644 testing/fuzzers/pdf_jpx_fuzzer_common.h diff --git a/testing/fuzzers/BUILD.gn b/testing/fuzzers/BUILD.gn index ec350de5b..7e8749fe6 100644 --- a/testing/fuzzers/BUILD.gn +++ b/testing/fuzzers/BUILD.gn @@ -190,6 +190,24 @@ source_set("fuzzer_utils") { include_dirs = [ "../.." ] } +source_set("pdf_jpx_fuzzer_common"){ + testonly = !is_component_build + sources = [ + "pdf_jpx_fuzzer_common.cc", + "pdf_jpx_fuzzer_common.h", + ] + configs += [ ":fuzzer_config" ] + public_deps = [ + "../../core/fxcodec", + "../../core/fxcrt", + ] + deps = [ + ":fuzzer_utils", + "../../core/fpdfapi/page", + "../../core/fxge", + ] +} + template("pdfium_fuzzer") { is_public = defined(invoker.public_fuzzer) && invoker.public_fuzzer if (is_public) { @@ -568,10 +586,7 @@ pdfium_fuzzer("pdf_hint_table_fuzzer") { pdfium_fuzzer("pdf_jpx_fuzzer") { sources = [ "pdf_jpx_fuzzer.cc" ] deps = [ - "../../core/fpdfapi/page", - "../../core/fxcodec", - "../../core/fxcrt", - "../../core/fxge", + ":pdf_jpx_fuzzer_common", ] } diff --git a/testing/fuzzers/pdf_jpx_fuzzer.cc b/testing/fuzzers/pdf_jpx_fuzzer.cc index 2800f7eb4..8ce75a759 100644 --- a/testing/fuzzers/pdf_jpx_fuzzer.cc +++ b/testing/fuzzers/pdf_jpx_fuzzer.cc @@ -3,28 +3,10 @@ // found in the LICENSE file. #include -#include -#include "core/fpdfapi/page/cpdf_colorspace.h" -#include "core/fpdfapi/page/jpx_decode_conversion.h" #include "core/fxcodec/jpx/cjpx_decoder.h" -#include "core/fxcrt/fx_safe_types.h" -#include "core/fxge/dib/cfx_dibitmap.h" -#include "core/fxge/dib/fx_dib.h" - -namespace { - -const uint32_t kMaxJPXFuzzSize = 100 * 1024 * 1024; // 100 MB - -bool CheckImageSize(const CJPX_Decoder::JpxImageInfo& image_info) { - static constexpr uint32_t kMemLimitBytes = 1024 * 1024 * 1024; // 1 GB. - FX_SAFE_UINT32 mem = image_info.width; - mem *= image_info.height; - mem *= image_info.channels; - return mem.IsValid() && mem.ValueOrDie() <= kMemLimitBytes; -} - -} // namespace +#include "core/fxcrt/span.h" +#include "testing/fuzzers/pdf_jpx_fuzzer_common.h" extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { if (size < 3) { @@ -39,59 +21,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { uint8_t resolution_levels_to_skip = pre[1]; bool strict_mode = !!pre[2]; - std::unique_ptr decoder = CJPX_Decoder::Create( - span, color_space_option, resolution_levels_to_skip, strict_mode); - if (!decoder) { - return 0; - } - - // A call to StartDecode could be too expensive if image size is very big, so - // check size before calling StartDecode(). - CJPX_Decoder::JpxImageInfo image_info = decoder->GetInfo(); - if (!CheckImageSize(image_info)) { - return 0; - } - - if (!decoder->StartDecode()) { - return 0; - } - - // StartDecode() could change image size, so check again. - image_info = decoder->GetInfo(); - if (!CheckImageSize(image_info)) { - return 0; - } - - // TODO(thestig): Add colorspace support. - RetainPtr color_space; - auto maybe_conversion = - JpxDecodeConversion::Create(image_info, color_space.Get()); - if (!maybe_conversion.has_value()) { - return 0; - } - - const auto& conversion = maybe_conversion.value(); - int components = conversion.jpx_components_count().value_or(0); - if (components <= 0) { - return 0; - } - - image_info.width = conversion.width(); - - auto bitmap = pdfium::MakeRetain(); - if (!bitmap->Create(image_info.width, image_info.height, - conversion.format())) { - return 0; - } - - if (bitmap->GetHeight() <= 0 || - kMaxJPXFuzzSize / bitmap->GetPitch() < - static_cast(bitmap->GetHeight())) { - return 0; - } - - decoder->Decode(bitmap->GetWritableBuffer(), bitmap->GetPitch(), - conversion.swap_rgb(), components); - + DecodeJpxForFuzzing(span, color_space_option, resolution_levels_to_skip, + strict_mode); return 0; } diff --git a/testing/fuzzers/pdf_jpx_fuzzer_common.cc b/testing/fuzzers/pdf_jpx_fuzzer_common.cc new file mode 100644 index 000000000..780eb8b2a --- /dev/null +++ b/testing/fuzzers/pdf_jpx_fuzzer_common.cc @@ -0,0 +1,87 @@ +// Copyright 2026 The PDFium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "testing/fuzzers/pdf_jpx_fuzzer_common.h" + +#include + +#include "core/fpdfapi/page/cpdf_colorspace.h" +#include "core/fpdfapi/page/jpx_decode_conversion.h" +#include "core/fxcrt/fx_safe_types.h" +#include "core/fxcrt/retain_ptr.h" +#include "core/fxge/dib/cfx_dibitmap.h" +#include "core/fxge/dib/fx_dib.h" + +namespace { + +constexpr uint32_t kMaxJPXFuzzSize = 100 * 1024 * 1024; // 100 MB + +bool CheckImageSize(const CJPX_Decoder::JpxImageInfo& image_info) { + static constexpr uint32_t kMemLimitBytes = 1024 * 1024 * 1024; // 1 GB. + FX_SAFE_UINT32 mem = image_info.width; + mem *= image_info.height; + mem *= image_info.channels; + return mem.IsValid() && mem.ValueOrDie() <= kMemLimitBytes; +} + +} // namespace + +void DecodeJpxForFuzzing(pdfium::span data, + CJPX_Decoder::ColorSpaceOption color_space_option, + uint8_t resolution_levels_to_skip, + bool strict_mode) { + std::unique_ptr decoder = CJPX_Decoder::Create( + data, color_space_option, resolution_levels_to_skip, strict_mode); + if (!decoder) { + return; + } + + // A call to StartDecode could be too expensive if image size is very big, so + // check size before calling StartDecode(). + CJPX_Decoder::JpxImageInfo image_info = decoder->GetInfo(); + if (!CheckImageSize(image_info)) { + return; + } + + if (!decoder->StartDecode()) { + return; + } + + // StartDecode() could change image size, so check again. + image_info = decoder->GetInfo(); + if (!CheckImageSize(image_info)) { + return; + } + + // TODO(thestig): Add colorspace support. + RetainPtr color_space; + auto maybe_conversion = + JpxDecodeConversion::Create(image_info, color_space.Get()); + if (!maybe_conversion.has_value()) { + return; + } + + const auto& conversion = maybe_conversion.value(); + int components = conversion.jpx_components_count().value_or(0); + if (components <= 0) { + return; + } + + image_info.width = conversion.width(); + + auto bitmap = pdfium::MakeRetain(); + if (!bitmap->Create(image_info.width, image_info.height, + conversion.format())) { + return; + } + + if (bitmap->GetHeight() <= 0 || + kMaxJPXFuzzSize / bitmap->GetPitch() < + static_cast(bitmap->GetHeight())) { + return; + } + + decoder->Decode(bitmap->GetWritableBuffer(), bitmap->GetPitch(), + conversion.swap_rgb(), components); +} diff --git a/testing/fuzzers/pdf_jpx_fuzzer_common.h b/testing/fuzzers/pdf_jpx_fuzzer_common.h new file mode 100644 index 000000000..4b317ff0f --- /dev/null +++ b/testing/fuzzers/pdf_jpx_fuzzer_common.h @@ -0,0 +1,20 @@ +// Copyright 2026 The PDFium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef TESTING_FUZZERS_PDF_JPX_FUZZER_UTILS_H_ +#define TESTING_FUZZERS_PDF_JPX_FUZZER_UTILS_H_ + +#include + +#include "core/fxcodec/jpx/cjpx_decoder.h" +#include "core/fxcrt/span.h" + +// Decodes `data` as a JPEG 2000 image with the given decoder parameters, +// bailing out early on images that are too large to decode in a fuzzer. +void DecodeJpxForFuzzing(pdfium::span data, + CJPX_Decoder::ColorSpaceOption color_space_option, + uint8_t resolution_levels_to_skip, + bool strict_mode); + +#endif // TESTING_FUZZERS_PDF_JPX_FUZZER_UTILS_H_ From 0d0cf3a356583ee4bf03f06cbd8a0cd471517804 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 16 Nov 2026 12:13:28 -0800 Subject: [PATCH 04/34] Roll third_party/freetype/src/ 25167984d..d5d4bef0c (1 commit) https://chromium.googlesource.com/chromium/src/third_party/freetype2.git/+log/25167984d243..d5d4bef0c6d5 Created with: roll-dep third_party/freetype/src Also roll DEPS for testing/corpus to pick up the corresponding test expectation change in https://pdfium-review.googlesource.com/c/164510. Change-Id: If474dd60dab87178af4e2393252b5351f76f13d2 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164490 Reviewed-by: Andy Phan Commit-Queue: Lei Zhang --- DEPS | 4 ++-- testing/SUPPRESSIONS | 2 +- third_party/freetype/README.pdfium | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DEPS b/DEPS index 2a3c04036..6312a707a 100644 --- a/DEPS +++ b/DEPS @@ -142,7 +142,7 @@ vars = { # Three lines of non-changing comments so that # the commit queue can handle CLs rolling freetype # and whatever else without interference from each other. - 'freetype_revision': '25167984d2435930f9178e8d9d2ca3bdfa71a4e7', + 'freetype_revision': 'd5d4bef0c6d5363931d346a6b2380317a32b8601', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling GN CIPD package version # and whatever else without interference from each other. @@ -224,7 +224,7 @@ vars = { # Three lines of non-changing comments so that # the commit queue can handle CLs rolling pdfium_tests # and whatever else without interference from each other. - 'pdfium_tests_revision': 'f7a1d03ba45e874b7d3cdf722959a2b8ba4dbfa5', + 'pdfium_tests_revision': '2bcc4fdc9abe4c4c115c82c486ac4c46f1d474c5', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling result_adapter_revision # and whatever else without interference from each other. diff --git a/testing/SUPPRESSIONS b/testing/SUPPRESSIONS index ebd08760d..0dff7ee02 100644 --- a/testing/SUPPRESSIONS +++ b/testing/SUPPRESSIONS @@ -62,7 +62,7 @@ 3_interpolate_image.pdf * * * fontations fuzzy=10,0.1,15 3_interpolate_image.pdf mac * skia * fuzzy 3bigpreview.pdf mac * agg * diff -3bigpreview.pdf * * * * fuzzy=21,0.15,10.0 +3bigpreview.pdf * * * * fuzzy=21,0.15,25 3bigpreview.pdf * * * fontations fuzzy=25,0.25,15 4_35.pdf mac * agg * diff 4_35.pdf * * * fontations fuzzy=10,0.1,15 diff --git a/third_party/freetype/README.pdfium b/third_party/freetype/README.pdfium index 7e3e6cb40..8f879b966 100644 --- a/third_party/freetype/README.pdfium +++ b/third_party/freetype/README.pdfium @@ -1,7 +1,7 @@ Name: FreeType URL: https://gitlab.freedesktop.org/freetype/freetype -Version: VER-2-14-3-146 -Revision: 25167984d2435930f9178e8d9d2ca3bdfa71a4e7 +Version: VER-2-14-3-147 +Revision: d5d4bef0c6d5363931d346a6b2380317a32b8601 Update Mechanism: Manual CPEPrefix: cpe:/a:freetype:freetype:2.14.3 Security Critical: yes From 0b43db186fb9e87388f6527b6520435cd8c74fe7 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 16 Nov 2026 12:39:51 -0800 Subject: [PATCH 05/34] Roll third_party/freetype/src/ d5d4bef0c..a5877f48f (12 commits) https://chromium.googlesource.com/chromium/src/third_party/freetype2.git/+log/d5d4bef0c6d5..a5877f48fff8 Created with: roll-dep third_party/freetype/src Change-Id: I519a7fe59de82a90a04eae158153c4162c221dcf Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164590 Commit-Queue: Lei Zhang Reviewed-by: Andy Phan --- DEPS | 2 +- third_party/freetype/README.pdfium | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DEPS b/DEPS index 6312a707a..b250f8159 100644 --- a/DEPS +++ b/DEPS @@ -142,7 +142,7 @@ vars = { # Three lines of non-changing comments so that # the commit queue can handle CLs rolling freetype # and whatever else without interference from each other. - 'freetype_revision': 'd5d4bef0c6d5363931d346a6b2380317a32b8601', + 'freetype_revision': 'a5877f48fff8dd6cf8d53c505ce055499376aee2', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling GN CIPD package version # and whatever else without interference from each other. diff --git a/third_party/freetype/README.pdfium b/third_party/freetype/README.pdfium index 8f879b966..68ef6e87e 100644 --- a/third_party/freetype/README.pdfium +++ b/third_party/freetype/README.pdfium @@ -1,9 +1,9 @@ Name: FreeType URL: https://gitlab.freedesktop.org/freetype/freetype -Version: VER-2-14-3-147 -Revision: d5d4bef0c6d5363931d346a6b2380317a32b8601 +Version: VER-2-15-0-7 +Revision: a5877f48fff8dd6cf8d53c505ce055499376aee2 Update Mechanism: Manual -CPEPrefix: cpe:/a:freetype:freetype:2.14.3 +CPEPrefix: cpe:/a:freetype:freetype:2.15.0 Security Critical: yes Shipped: yes License: FTL From dd810f17f56a076aeb08d830bf364b67041b1623 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 16 Nov 2026 14:02:12 -0800 Subject: [PATCH 06/34] Use GCedVector for stack-local collections across node creation Defensive coding based upon patterns in previous reports. Hold stack-local node collections in CJX_Object::SetContent() and CXFA_Node::InsertItem() using cppgc::Persistent> instead of unrooted std::vector. These code paths allocate new nodes via CreateSamePacketNode(), which triggers cppgc heap allocation. Rooting the collections protects them against premature garbage collection during allocation-triggered sweeps. Change-Id: I9a338f886ea50cae78f2610bb890f3fd24542e3b Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164451 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- fxjs/xfa/cjx_object.cpp | 29 +++++++++++++++++++---------- xfa/fxfa/parser/cxfa_node.cpp | 14 ++++++++------ 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp index f4d813d3f..b4ed9cbb2 100644 --- a/fxjs/xfa/cjx_object.cpp +++ b/fxjs/xfa/cjx_object.cpp @@ -13,6 +13,7 @@ #include "core/fxcrt/check.h" #include "core/fxcrt/check_op.h" #include "core/fxcrt/containers/contains.h" +#include "core/fxcrt/containers/to_vector.h" #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/span.h" @@ -21,12 +22,14 @@ #include "fxjs/cjs_result.h" #include "fxjs/fxv8.h" #include "fxjs/gc/container_trace.h" +#include "fxjs/gc/containers.h" #include "fxjs/xfa/cfxjse_engine.h" #include "fxjs/xfa/cfxjse_mapmodule.h" #include "fxjs/xfa/cjx_boolean.h" #include "fxjs/xfa/cjx_draw.h" #include "fxjs/xfa/cjx_field.h" #include "fxjs/xfa/cjx_instancemanager.h" +#include "v8/include/cppgc/persistent.h" #include "v8/include/v8-forward.h" #include "v8/include/v8-object.h" #include "v8/include/v8-primitive.h" @@ -585,18 +588,22 @@ void CJX_Object::SetContent(const WideString& wsContent, if (bSyncData && pBind) { std::vector wsSaveTextArray = fxcrt::Split(wsContent, L'\n'); - std::vector valueNodes = - pBind->GetNodeListForType(XFA_Element::DataValue); + cppgc::Persistent> value_nodes = + cppgc::MakeGarbageCollected>( + GetDocument()->GetHeap()->GetAllocationHandle()); + value_nodes->storage = pdfium::ToVector>( + pBind->GetNodeListForType(XFA_Element::DataValue)); // Adusting node count might have side effects, do not trust that // we'll ever actually get there. size_t tries = 0; - while (valueNodes.size() != wsSaveTextArray.size()) { + while (value_nodes->storage.size() != wsSaveTextArray.size()) { if (++tries > 4) { return; } - if (valueNodes.size() < wsSaveTextArray.size()) { - size_t iAddNodes = wsSaveTextArray.size() - valueNodes.size(); + if (value_nodes->storage.size() < wsSaveTextArray.size()) { + size_t iAddNodes = + wsSaveTextArray.size() - value_nodes->storage.size(); while (iAddNodes-- > 0) { CXFA_Node* pValueNodes = pBind->CreateSamePacketNode(XFA_Element::DataValue); @@ -606,16 +613,18 @@ void CJX_Object::SetContent(const WideString& wsContent, pBind->InsertChildAndNotify(pValueNodes, nullptr); } } else { - size_t iDelNodes = valueNodes.size() - wsSaveTextArray.size(); + size_t iDelNodes = + value_nodes->storage.size() - wsSaveTextArray.size(); for (size_t i = 0; i < iDelNodes; ++i) { - pBind->RemoveChildAndNotify(valueNodes[i], true); + pBind->RemoveChildAndNotify(value_nodes->storage[i], true); } } - valueNodes = pBind->GetNodeListForType(XFA_Element::DataValue); + value_nodes->storage = pdfium::ToVector>( + pBind->GetNodeListForType(XFA_Element::DataValue)); } - DCHECK_EQ(valueNodes.size(), wsSaveTextArray.size()); + DCHECK_EQ(value_nodes->storage.size(), wsSaveTextArray.size()); size_t i = 0; - for (CXFA_Node* pValueNode : valueNodes) { + for (CXFA_Node* pValueNode : value_nodes->storage) { pValueNode->JSObject()->SetAttributeValue(wsSaveTextArray[i], wsSaveTextArray[i]); i++; diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 303d1f910..6431bde9a 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -4705,14 +4705,16 @@ void CXFA_Node::InsertItem(const WideString& wsLabel, wsNewValue = wsLabel; } - std::vector listitems; + cppgc::Persistent> listitems = + cppgc::MakeGarbageCollected>( + GetDocument()->GetHeap()->GetAllocationHandle()); for (CXFA_Node* pItem = GetFirstChild(); pItem; pItem = pItem->GetNextSibling()) { if (pItem->GetElementType() == XFA_Element::Items) { - listitems.push_back(pItem); + listitems->storage.push_back(pItem); } } - if (listitems.empty()) { + if (listitems->storage.empty()) { CXFA_Node* pItems = CreateSamePacketNode(XFA_Element::Items); InsertChildAndNotify(-1, pItems); InsertListTextItem(pItems, wsLabel, nIndex); @@ -4720,9 +4722,9 @@ void CXFA_Node::InsertItem(const WideString& wsLabel, InsertChildAndNotify(-1, pSaveItems); pSaveItems->JSObject()->SetBoolean(XFA_Attribute::Save, true, false); InsertListTextItem(pSaveItems, wsNewValue, nIndex); - } else if (listitems.size() > 1) { + } else if (listitems->storage.size() > 1) { for (int32_t i = 0; i < 2; i++) { - CXFA_Node* pNode = listitems[i]; + CXFA_Node* pNode = listitems->storage[i]; bool bHasSave = pNode->JSObject()->GetBoolean(XFA_Attribute::Save); if (bHasSave) { InsertListTextItem(pNode, wsNewValue, nIndex); @@ -4731,7 +4733,7 @@ void CXFA_Node::InsertItem(const WideString& wsLabel, } } } else { - CXFA_Node* pNode = listitems[0]; + CXFA_Node* pNode = listitems->storage[0]; pNode->JSObject()->SetBoolean(XFA_Attribute::Save, false, false); pNode->JSObject()->SetEnum(XFA_Attribute::Presence, XFA_AttributeValue::Visible, false); From 20e2d231bbebb05b545f752571fe21bce9550764 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 16 Nov 2026 14:28:27 -0800 Subject: [PATCH 07/34] Use vector of Persistent for CFXJSE_Engine::ResolveResult::objects Hold candidate collections in CFXJSE_Engine::ResolveResult using std::vector> instead of untraced std::vector>. Holding candidates in Persistent handles ensures they remain rooted across arbitrary re-entrant script execution without allocating ephemeral garbage on the Oilpan heap. Add an overload for CXFA_Document::GetNotBindNode() to accept spans of Persistent CXFA_Object pointers alongside Member CXFA_Object pointers. Fixed: 575092452, 575095388 Change-Id: I653f5bd776db68893c8deb3616e671ffaee14e13 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164650 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- fxjs/xfa/cfxjse_engine.h | 5 ++--- fxjs/xfa/cfxjse_resolveprocessor.cpp | 21 +++++++-------------- xfa/fxfa/parser/cxfa_document.cpp | 20 +++++++++++++++++--- xfa/fxfa/parser/cxfa_document.h | 4 +++- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/fxjs/xfa/cfxjse_engine.h b/fxjs/xfa/cfxjse_engine.h index f253d6d46..988979c15 100644 --- a/fxjs/xfa/cfxjse_engine.h +++ b/fxjs/xfa/cfxjse_engine.h @@ -75,9 +75,8 @@ class CFXJSE_Engine final : public CFX_IsolateWrapper { Type type = Type::kNodes; XFA_SCRIPTATTRIBUTEINFO script_attribute = {}; - // Vector of Member would be correct for stack-based vectors, if - // STL worked with cppgc. - std::vector> objects; + // Vector of Persistent protects stack-based vectors from premature GC. + std::vector> objects; }; static CXFA_Object* ToObject(const v8::FunctionCallbackInfo& info); diff --git a/fxjs/xfa/cfxjse_resolveprocessor.cpp b/fxjs/xfa/cfxjse_resolveprocessor.cpp index 96cec1b38..bcdea2dbb 100644 --- a/fxjs/xfa/cfxjse_resolveprocessor.cpp +++ b/fxjs/xfa/cfxjse_resolveprocessor.cpp @@ -15,7 +15,6 @@ #include "core/fxcrt/containers/to_vector.h" #include "core/fxcrt/fx_extension.h" #include "fxjs/fxv8.h" -#include "fxjs/gc/containers.h" #include "fxjs/xfa/cfxjse_engine.h" #include "fxjs/xfa/cfxjse_isolatetracker.h" #include "fxjs/xfa/cfxjse_nodehelper.h" @@ -124,7 +123,7 @@ bool CFXJSE_ResolveProcessor::ResolveAnyChild(v8::Isolate* pIsolate, std::vector siblings = pChild->GetSiblings(bClassName); nodes.insert(nodes.end(), siblings.begin(), siblings.end()); - rnd.result_.objects = pdfium::ToVector>(nodes); + rnd.result_.objects = pdfium::ToVector>(nodes); FilterCondition(pIsolate, wsCondition, &rnd); return !rnd.result_.objects.empty(); } @@ -341,7 +340,7 @@ bool CFXJSE_ResolveProcessor::ResolveNormal(v8::Isolate* pIsolate, } if (upArrayNodes.size() > rnd.result_.objects.size()) { CXFA_Object* pSaveObject = rnd.result_.objects.front().Get(); - rnd.result_.objects = std::vector>( + rnd.result_.objects = std::vector>( upArrayNodes.begin(), upArrayNodes.end()); rnd.result_.objects.front() = pSaveObject; } @@ -483,7 +482,7 @@ bool CFXJSE_ResolveProcessor::ResolveNormal(v8::Isolate* pIsolate, } if (upArrayNodes.size() > rnd.result_.objects.size()) { CXFA_Object* pSaveObject = rnd.result_.objects.front().Get(); - rnd.result_.objects = std::vector>( + rnd.result_.objects = std::vector>( upArrayNodes.begin(), upArrayNodes.end()); rnd.result_.objects.front() = pSaveObject; } @@ -669,7 +668,7 @@ void CFXJSE_ResolveProcessor::ConditionArray(size_t iCurIndex, } pRnd->result_.objects.clear(); } else { - pRnd->result_.objects = std::vector>( + pRnd->result_.objects = std::vector>( 1, pRnd->result_.objects[index]); } } @@ -708,7 +707,7 @@ void CFXJSE_ResolveProcessor::FilterCondition(v8::Isolate* pIsolate, return; } - pRnd->result_.objects = std::vector>( + pRnd->result_.objects = std::vector>( 1, pRnd->result_.objects[iCurIndex]); return; } @@ -766,16 +765,11 @@ void CFXJSE_ResolveProcessor::DoPredicateFilter(v8::Isolate* pIsolate, return; } WideString wsExpression = wsCondition.Substr(2, wsCondition.GetLength() - 3); - - cppgc::Persistent> candidates = - cppgc::MakeGarbageCollected>( - engine_->GetDocument()->GetHeap()->GetAllocationHandle()); - candidates->storage = std::move(pRnd->result_.objects); for (size_t i = iFoundCount; i > 0; --i) { bool bool_val = false; CFXJSE_Context::ExecutionResult exec_result = engine_->RunScript(eLangType, wsExpression.AsStringView(), - candidates->storage[i - 1].Get()); + pRnd->result_.objects[i - 1].Get()); if (exec_result.status) { CFXJSE_ScopeUtil_IsolateHandleRootContext scope(pIsolate); v8::Local local_val = @@ -783,10 +777,9 @@ void CFXJSE_ResolveProcessor::DoPredicateFilter(v8::Isolate* pIsolate, bool_val = fxv8::ReentrantToBooleanHelper(pIsolate, local_val); } if (!bool_val) { - candidates->storage.erase(candidates->storage.begin() + i - 1); + pRnd->result_.objects.erase(pRnd->result_.objects.begin() + i - 1); } } - pRnd->result_.objects = std::move(candidates->storage); } CFXJSE_ResolveProcessor::NodeData::NodeData() = default; diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp index d16de943a..eae58a49c 100644 --- a/xfa/fxfa/parser/cxfa_document.cpp +++ b/xfa/fxfa/parser/cxfa_document.cpp @@ -1775,9 +1775,11 @@ void CXFA_Document::DataMerge_UpdateBindingRelations( UpdateBindingRelations(this, pFormUpdateRoot, pDataScope, true, false); } -CXFA_Node* CXFA_Document::GetNotBindNode( - pdfium::span> arrayObjects) const { - for (auto& pObject : arrayObjects) { +namespace { + +template +CXFA_Node* GetNotBindNodeImpl(pdfium::span array_objects) { + for (auto& pObject : array_objects) { CXFA_Node* pNode = pObject->AsNode(); if (pNode && !pNode->HasBindItem()) { return pNode; @@ -1786,6 +1788,18 @@ CXFA_Node* CXFA_Document::GetNotBindNode( return nullptr; } +} // namespace + +CXFA_Node* CXFA_Document::GetNotBindNode( + pdfium::span> array_objects) const { + return GetNotBindNodeImpl(array_objects); +} + +CXFA_Node* CXFA_Document::GetNotBindNode( + pdfium::span> array_objects) const { + return GetNotBindNodeImpl(array_objects); +} + void CXFA_Document::DoDataMerge() { CXFA_Node* pDatasetsRoot = ToNode(GetXFAObject(XFA_HASHCODE_Datasets)); if (!pDatasetsRoot) { diff --git a/xfa/fxfa/parser/cxfa_document.h b/xfa/fxfa/parser/cxfa_document.h index 10255f2fd..be999a2f0 100644 --- a/xfa/fxfa/parser/cxfa_document.h +++ b/xfa/fxfa/parser/cxfa_document.h @@ -98,7 +98,9 @@ class CXFA_Document final : public cppgc::GarbageCollected { CXFA_Object* GetXFAObject(XFA_HashCode wsNodeNameHash); CXFA_Node* GetNodeByID(CXFA_Node* pRoot, WideStringView wsID) const; CXFA_Node* GetNotBindNode( - pdfium::span> arrayNodes) const; + pdfium::span> array_objects) const; + CXFA_Node* GetNotBindNode( + pdfium::span> array_objects) const; LayoutProcessorIface* GetLayoutProcessor() const { return layout_processor_; } CXFA_Node* GetRoot() const { return root_node_; } From 873ded4e412f8be6878aae8fce78b1c0de06153d Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 17 Nov 2026 10:15:06 -0800 Subject: [PATCH 08/34] Use in-process python difflib in test_runner.py Replace the external Python subprocess invocation of text_diff.py in TestText() with Python's standard library difflib.unified_diff directly in-process. In addition, extract _GetFontArgs() and _GetCommonFeatureArgs() on _TestCaseRunner to share font directory and feature argument construction across TestText() and TestPixel(). Change-Id: I2e7cb3ea9168c1f8bd0553c9de31aba5eec60a39 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164730 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- testing/tools/test_runner.py | 74 +++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/testing/tools/test_runner.py b/testing/tools/test_runner.py index 9edd9b599..7846d726f 100644 --- a/testing/tools/test_runner.py +++ b/testing/tools/test_runner.py @@ -6,6 +6,7 @@ import argparse from dataclasses import dataclass, field from datetime import timedelta +import difflib from io import BytesIO import multiprocessing import os @@ -498,7 +499,6 @@ def __init__(self, config): finder = config.NewFinder() self.pdfium_test_path = config.GetPdfiumTestPath(finder) self.fixup_path = finder.ScriptPath('fixup_pdf_template.py') - self.text_diff_path = finder.ScriptPath('text_diff.py') self.font_dir = os.path.join(finder.TestingDir(), 'resources', 'fonts') self.third_party_font_dir = finder.ThirdPartyFontsDir() @@ -673,6 +673,26 @@ def Generate(self): f'--output-dir={self.working_dir}', template_path ]) + def _GetCommonFeatureArgs(self): + args = [] + if self.options.disable_javascript: + args.append('--disable-javascript') + if self.options.disable_xfa: + args.append('--disable-xfa') + return args + + def _GetFontArgs(self): + if 'use_ahem' in self.source_dir: + font_path = os.path.join(_per_process_state.font_dir, 'ahem') + return [f'--font-dir={font_path}'] + if 'use_symbolneu' in self.source_dir: + font_path = os.path.join(_per_process_state.font_dir, 'symbolneu') + return [f'--font-dir={font_path}'] + return [ + f'--font-dir={_per_process_state.third_party_font_dir}', + '--croscore-font-names', + ] + def TestText(self): txt_path = os.path.join(self.working_dir, f'{self.test_id}.txt') with open(txt_path, 'w') as outfile: @@ -680,13 +700,7 @@ def TestText(self): _per_process_state.pdfium_test_path, '--send-events', f'--time={TEST_SEED_TIME}' ] - - if self.options.disable_javascript: - cmd_to_run.append('--disable-javascript') - - if self.options.disable_xfa: - cmd_to_run.append('--disable-xfa') - + cmd_to_run.extend(self._GetCommonFeatureArgs()) cmd_to_run.append(self.pdf_path) test_result = self.RunCommand(cmd_to_run, stdout=outfile) if not test_result.IsPass(): @@ -702,13 +716,25 @@ def TestText(self): if self.options.disable_javascript: return self._VerifyEmptyText(txt_path) - test_result = self.RunCommand([ - sys.executable, _per_process_state.text_diff_path, expected_txt_path, - txt_path - ]) - # The differ does nothing but compare, so a plain failure is a mismatch. - test_result.comparison_failure = test_result.status == result_types.FAIL - return test_result + with open(expected_txt_path, 'r', errors='backslashreplace') as f1: + expected_lines = f1.readlines() + with open(txt_path, 'r', errors='backslashreplace') as f2: + actual_lines = f2.readlines() + + diff = list( + difflib.unified_diff( + expected_lines, + actual_lines, + fromfile=expected_txt_path, + tofile=txt_path)) + if diff: + return self.test_case.NewResult( + result_types.FAIL, + log=''.join(diff), + reason='Text output differs', + comparison_failure=True) + + return self.test_case.NewResult(result_types.PASS) def _VerifyEmptyText(self, txt_path): with open(txt_path, 'rb') as txt_file: @@ -736,22 +762,8 @@ def TestPixel(self): _per_process_state.pdfium_test_path, '--send-events', '--png', '--md5', f'--time={TEST_SEED_TIME}' ] - - if 'use_ahem' in self.source_dir: - font_path = os.path.join(_per_process_state.font_dir, 'ahem') - cmd_to_run.append(f'--font-dir={font_path}') - elif 'use_symbolneu' in self.source_dir: - font_path = os.path.join(_per_process_state.font_dir, 'symbolneu') - cmd_to_run.append(f'--font-dir={font_path}') - else: - cmd_to_run.append(f'--font-dir={_per_process_state.third_party_font_dir}') - cmd_to_run.append('--croscore-font-names') - - if self.options.disable_javascript: - cmd_to_run.append('--disable-javascript') - - if self.options.disable_xfa: - cmd_to_run.append('--disable-xfa') + cmd_to_run.extend(self._GetFontArgs()) + cmd_to_run.extend(self._GetCommonFeatureArgs()) if self.options.render_oneshot: cmd_to_run.append('--render-oneshot') From 4c92ae872b78160ac423d760d37d3fc2d5445490 Mon Sep 17 00:00:00 2001 From: Wang Yongjie Date: Tue, 17 Nov 2026 10:42:31 -0800 Subject: [PATCH 09/34] Expand BGRA-to-mask compositor test coverage Exercise every source-alpha and clip-alpha pair with destination alpha values 0, 1, 127, 128, 254, and 255. This checks the two successive truncating divisions by 255 and their largest products, in addition to exposing the clipped alpha with a zero destination. Add row widths 8, 9, 15, 16, 31, and 32 to the constant-alpha and tail tests to cover more vector boundaries. These cases verify existing behavior and pass independently of changes to the SIMD implementation. Test: Compositor tests with SSE2, SSSE3, SSE4, AVX2, and SCALAR. Change-Id: Ibcf7260bfd6a64b58c6f4f1e42cf04e15a9fcf76 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164570 Reviewed-by: Tom Sepez Reviewed-by: Lei Zhang Commit-Queue: Lei Zhang --- .../dib/cfx_scanlinecompositor_unittest.cpp | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/core/fxge/dib/cfx_scanlinecompositor_unittest.cpp b/core/fxge/dib/cfx_scanlinecompositor_unittest.cpp index 463147627..d5a3b7695 100644 --- a/core/fxge/dib/cfx_scanlinecompositor_unittest.cpp +++ b/core/fxge/dib/cfx_scanlinecompositor_unittest.cpp @@ -1058,23 +1058,28 @@ TEST(ScanlineCompositorSimdTest, Bgra2MaskMatchesScalar) { } TEST(ScanlineCompositorSimdTest, Bgra2MaskAllSourceAndClipAlphaCombinations) { - // A zero destination exposes the clipped alpha, covering every input pair - // and the rounding boundaries of the first division by 255. + // A zero destination exposes the clipped alpha. Nonzero destination + // boundaries also check both successive divisions and their largest products. constexpr size_t kWidth = 256 * 256; std::vector> src(kWidth); std::vector clip(kWidth); - std::vector dest(kWidth); - std::vector expected(kWidth); for (size_t i = 0; i < kWidth; ++i) { const uint32_t alpha = static_cast(i / 256); const uint32_t clip_alpha = static_cast(i % 256); src[i] = { .blue = 1, .green = 2, .red = 3, .alpha = static_cast(alpha)}; clip[i] = static_cast(clip_alpha); - expected[i] = static_cast(alpha * clip_alpha / 255); } - CompositeRowBgra2MaskSimd(src, clip, dest); - ASSERT_EQ(dest, expected); + for (uint8_t back : {0, 1, 127, 128, 254, 255}) { + std::vector dest(kWidth, back); + std::vector expected(kWidth); + for (auto [input, cover, want] : fxcrt::Zip(src, clip, expected)) { + const uint32_t alpha = input.alpha * cover / 255; + want = static_cast(back + alpha - back * alpha / 255); + } + CompositeRowBgra2MaskSimd(src, clip, dest); + ASSERT_EQ(dest, expected) << "destination alpha=" << static_cast(back); + } } TEST(ScanlineCompositorSimdTest, Bgra2MaskAllSourceAndDestAlphaCombinations) { @@ -1099,7 +1104,7 @@ TEST(ScanlineCompositorSimdTest, Bgra2MaskAllSourceAndDestAlphaCombinations) { TEST(ScanlineCompositorSimdTest, Bgra2MaskConstantAlphaAndTails) { // Exercise the same extreme inputs in full vectors and scalar tails. static constexpr std::array kAlpha = {0, 1, 127, 128, 254, 255}; - for (size_t width : {1u, 3u, 7u, 17u, 33u, 65u}) { + for (size_t width : {1u, 3u, 7u, 8u, 9u, 15u, 16u, 17u, 31u, 32u, 33u, 65u}) { std::vector> src(width); std::vector clip(width); std::vector dest(width); From cb73733715a15f6889364b298ea173ec5efb2c23 Mon Sep 17 00:00:00 2001 From: Wang Yongjie Date: Tue, 17 Nov 2026 10:48:10 -0800 Subject: [PATCH 10/34] Use 16-bit lanes for BGRA-to-mask compositing The current 32-bit lane kernel emulates multiplication on SSE2 and SSSE3 and processes only four pixels per iteration on 128-bit targets. On short clipped rows with mostly transparent pixels, the full vector calculation can also cost more than the scalar fast paths. Use 16-bit arithmetic for all SIMD mask kernels. Each vector processes twice as many pixels: eight on SSE targets and sixteen on AVX2. This uses native multiplication and exact high-half multiplication for division by 255. For products in [0, 65025], ((x + 1) * 257) >> 16 gives floor(x / 255), with no overflow in x + 1. Preserve the separate truncations for clipping and alpha union, producing bit-identical results. Expanded test coverage is submitted separately in CL 164570: https://pdfium-review.googlesource.com/c/pdfium/+/164570 Benchmark on Ryzen 7 9800X3D, Windows x64, clang-cl Release, with each target forced and pinned to the same logical CPU. Report medians of seven samples across 468 SIMD scenarios per target: 39 widths >= 128, with/without clip, and six alpha distributions. Timings include destination reset and dispatch. Compared with the current 32-bit SIMD implementation, AVX2 has a median speedup of 1.261x. All 468 AVX2 scenarios improve, with speedups ranging from 1.094x to 2.023x. For a 2048-pixel mixed-alpha row with clipping, time decreases from 332.847 ns to 165.054 ns (2.017x). Compared with the original pre-SIMD scalar implementation, all 468 scenarios are faster on each x86 target. Minimum speedups are 1.438x for SSE2, 1.442x for SSSE3, 1.348x for SSE4, and 1.548x for AVX2. Highway has no separate SSE3 target; CPUs supporting SSE3 but not SSSE3 use the SSE2 path. Validation: - Compositor tests pass on SSE2, SSSE3, SSE4, AVX2, and SCALAR. - All 256^3 source/destination/clip alpha combinations pass on each of the four x86 targets; 528 guard-page cases pass. - ARM64 Windows compilation of the production source passes. - AVX2 pixel/corpus output matches the current 32-bit SIMD implementation for all 1,344 PNGs, with no new failures in the full test suites. Change-Id: I9866e7cca0da80cdd0a2c66a78adf2d35963899c Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164370 Commit-Queue: Andy Phan Reviewed-by: Lei Zhang Reviewed-by: Andy Phan --- core/fxge/dib/cfx_scanlinecompositor_hwy.cpp | 42 +++++++++++++------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/core/fxge/dib/cfx_scanlinecompositor_hwy.cpp b/core/fxge/dib/cfx_scanlinecompositor_hwy.cpp index f8d8e493f..dea4e047e 100644 --- a/core/fxge/dib/cfx_scanlinecompositor_hwy.cpp +++ b/core/fxge/dib/cfx_scanlinecompositor_hwy.cpp @@ -160,9 +160,18 @@ void RunBgra2BgrxForceOpaque(pdfium::span> src, } } -// Keep the clip decision outside the loop. Both products passed to Div255() -// are at most 255 * 255, so its exact, truncating division matches -// AlphaUnion(). +#if HWY_TARGET != HWY_SCALAR +// Exact floor(x / 255) for uint16_t lanes and x in [0, 65025]. +// x + 1 <= 65026, so the addition does not overflow. +template +HWY_INLINE V Div255U16(V x) { + const hn::DFromV d; + return hn::MulHigh(hn::Add(x, hn::Set(d, 1)), hn::Set(d, 257)); +} +#endif + +// Keep the clip decision outside the loop. Both products are at most +// 255 * 255, so the exact, truncating division matches AlphaUnion(). template void Bgra2Mask(pdfium::span> src, pdfium::span clip, @@ -173,26 +182,31 @@ void Bgra2Mask(pdfium::span> src, clip = clip.first(src.size()); } #if HWY_TARGET != HWY_SCALAR - const hn::ScalableTag d; + // Use 16-bit products to process twice as many pixels per iteration as + // 32-bit lanes. This also avoids emulated multiplication on SSE2 and SSSE3. + const hn::ScalableTag d32; const hn::ScalableTag d8; + const hn::ScalableTag d; + const hn::Half dh; const hn::Rebind dn; const size_t n = hn::Lanes(d); while (src.size() >= n) { - // The BGRA load reads 4*n bytes; the narrow descriptor reads/writes n - // bytes for clip and dest. The span sizes bound every vector access. - const auto packed = hn::BitCast( - d, hn::LoadU(d8, reinterpret_cast(src.data()))); - auto alpha = hn::ShiftRight<24>(packed); + // Each load covers n/2 BGRA pixels, together supplying n alpha values. + const auto lo = hn::ShiftRight<24>(hn::BitCast( + d32, hn::LoadU(d8, reinterpret_cast(src.data())))); + const auto hi = hn::ShiftRight<24>( + hn::BitCast(d32, hn::LoadU(d8, reinterpret_cast( + src.subspan(n / 2).data())))); + auto alpha = hn::Combine(d, hn::DemoteTo(dh, hi), hn::DemoteTo(dh, lo)); if constexpr (kHasClip) { - alpha = - Div255(hn::Mul(alpha, hn::PromoteTo(d, hn::LoadU(dn, clip.data())))); + alpha = Div255U16( + hn::Mul(alpha, hn::PromoteTo(d, hn::LoadU(dn, clip.data())))); clip = clip.subspan(n); } const auto back = hn::PromoteTo(d, hn::LoadU(dn, dest.data())); const auto result = - hn::Sub(hn::Add(back, alpha), Div255(hn::Mul(back, alpha))); - // Alpha union is in [0, 255], satisfying U8FromU32()'s precondition. - hn::StoreU(hn::U8FromU32(result), dn, dest.data()); + hn::Sub(hn::Add(back, alpha), Div255U16(hn::Mul(back, alpha))); + hn::StoreU(hn::DemoteTo(dn, result), dn, dest.data()); src = src.subspan(n); dest = dest.subspan(n); } From 2bc1255c482ae91677ce1bf7b7bd44378ab6175a Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 17 Nov 2026 11:13:00 -0800 Subject: [PATCH 11/34] Introduce run_drawing_tests.py and testing/resources/drawing Add run_drawing_tests.py to execute drawing comparison tests in parallel using test_runner.py. Drawing tests render PDF pages to DisplayListDeviceDriver using `pdfium_test --dump`, producing structured text representations of vector drawing commands (.dump.txt) for each page. These are compared against golden expectations via text diffing, avoiding binary PNG artifacts and cross-platform rasterization discrepancies. Add an initial test under testing/resources/drawing/hello_world.in with its corresponding golden expectation, along with an xfa_specific sub-directory to support XFA tests that automatically skip on non-XFA builds. Change-Id: Ib8f09d4a1105913d0ca2692633dfab5896dfe78a Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164710 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- PRESUBMIT.py | 5 +- testing/resources/drawing/hello_world.in | 55 ++++++++ .../hello_world_expected.pdf.0.dump.txt | 8 ++ .../resources/drawing/xfa_specific/README.md | 4 + testing/tools/run_drawing_tests.py | 17 +++ testing/tools/test_runner.py | 117 +++++++++++++++++- 6 files changed, 202 insertions(+), 4 deletions(-) create mode 100644 testing/resources/drawing/hello_world.in create mode 100644 testing/resources/drawing/hello_world_expected.pdf.0.dump.txt create mode 100644 testing/resources/drawing/xfa_specific/README.md create mode 100755 testing/tools/run_drawing_tests.py diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 611e3ae68..1ad3e0fd1 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -464,8 +464,9 @@ def _CheckTestDuplicates(input_api, output_api): for f in input_api.AffectedFiles(): if f.Action() == 'D': continue - if not f.LocalPath().startswith(('testing/resources/pixel/', - 'testing/resources/javascript/')): + if not f.LocalPath().startswith( + ('testing/resources/drawing/', 'testing/resources/javascript/', + 'testing/resources/pixel/')): continue end_len = 0 if f.LocalPath().endswith('.in'): diff --git a/testing/resources/drawing/hello_world.in b/testing/resources/drawing/hello_world.in new file mode 100644 index 000000000..910ef317b --- /dev/null +++ b/testing/resources/drawing/hello_world.in @@ -0,0 +1,55 @@ +{{header}} +{{object 1 0}} << + /Type /Catalog + /Pages 2 0 R +>> +endobj +{{object 2 0}} << + /Type /Pages + /MediaBox [0 0 200 200] + /Count 1 + /Kids [3 0 R] +>> +endobj +{{object 3 0}} << + /Type /Page + /Parent 2 0 R + /Resources << + /Font << + /F1 4 0 R + /F2 5 0 R + >> + >> + /Contents 6 0 R +>> +endobj +{{object 4 0}} << + /Type /Font + /Subtype /Type1 + /BaseFont /Times-Roman +>> +endobj +{{object 5 0}} << + /Type /Font + /Subtype /Type1 + /BaseFont /Helvetica +>> +endobj +{{object 6 0}} << + {{streamlen}} +>> +stream +BT +20 50 Td +/F1 12 Tf +(Hello, world!) Tj +0 50 Td +/F2 16 Tf +(Goodbye, world!) Tj +ET +endstream +endobj +{{xref}} +{{trailer}} +{{startxref}} +%%EOF diff --git a/testing/resources/drawing/hello_world_expected.pdf.0.dump.txt b/testing/resources/drawing/hello_world_expected.pdf.0.dump.txt new file mode 100644 index 000000000..2a0379422 --- /dev/null +++ b/testing/resources/drawing/hello_world_expected.pdf.0.dump.txt @@ -0,0 +1,8 @@ +SaveState +SetBaseClip [0,0,200,200] +SetClip_PathFill rule=winding matrix=none points=[move(0.0000,200.0000) line(0.0000,0.0000) line(200.0000,0.0000) line(200.0000,200.0000) line(0.0000,200.0000,close)] +SaveState +DrawDeviceText font="Tinos" size=12.0000 color=0xff000000 matrix=[1.0000,0.0000,0.0000,-1.0000,20.0000,150.0000] glyphs=[(idx=43,u=U+0048,origin=(0.0000,0.0000)) (idx=72,u=U+0065,origin=(8.6640,0.0000)) (idx=79,u=U+006C,origin=(13.9920,0.0000)) (idx=79,u=U+006C,origin=(17.3280,0.0000)) (idx=82,u=U+006F,origin=(20.6640,0.0000)) (idx=15,u=U+002C,origin=(26.6640,0.0000)) (idx=3,u=U+0020,origin=(29.6640,0.0000)) (idx=90,u=U+0077,origin=(32.6640,0.0000)) (idx=82,u=U+006F,origin=(41.3280,0.0000)) (idx=85,u=U+0072,origin=(47.3280,0.0000)) (idx=79,u=U+006C,origin=(51.3240,0.0000)) (idx=71,u=U+0064,origin=(54.6600,0.0000)) (idx=4,u=U+0021,origin=(60.6600,0.0000))] +DrawDeviceText font="Arimo" size=16.0000 color=0xff000000 matrix=[1.0000,0.0000,0.0000,-1.0000,20.0000,100.0000] glyphs=[(idx=42,u=U+0047,origin=(0.0000,0.0000)) (idx=82,u=U+006F,origin=(12.4480,0.0000)) (idx=82,u=U+006F,origin=(21.3440,0.0000)) (idx=71,u=U+0064,origin=(30.2400,0.0000)) (idx=69,u=U+0062,origin=(39.1360,0.0000)) (idx=92,u=U+0079,origin=(48.0320,0.0000)) (idx=72,u=U+0065,origin=(56.0320,0.0000)) (idx=15,u=U+002C,origin=(64.9280,0.0000)) (idx=3,u=U+0020,origin=(69.3760,0.0000)) (idx=90,u=U+0077,origin=(73.8240,0.0000)) (idx=82,u=U+006F,origin=(85.3760,0.0000)) (idx=85,u=U+0072,origin=(94.2720,0.0000)) (idx=79,u=U+006C,origin=(99.6000,0.0000)) (idx=71,u=U+0064,origin=(103.1520,0.0000)) (idx=4,u=U+0021,origin=(112.0480,0.0000))] +RestoreState +RestoreState diff --git a/testing/resources/drawing/xfa_specific/README.md b/testing/resources/drawing/xfa_specific/README.md new file mode 100644 index 000000000..46ba3c0f5 --- /dev/null +++ b/testing/resources/drawing/xfa_specific/README.md @@ -0,0 +1,4 @@ +# XFA-specific drawing tests + +Tests placed in this directory will be automatically skipped on builds without +XFA support. diff --git a/testing/tools/run_drawing_tests.py b/testing/tools/run_drawing_tests.py new file mode 100755 index 000000000..de5904952 --- /dev/null +++ b/testing/tools/run_drawing_tests.py @@ -0,0 +1,17 @@ +#!/usr/bin/env vpython3 +# Copyright 2026 The PDFium Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import sys + +import test_runner + + +def main(): + runner = test_runner.TestRunner('drawing') + return runner.Run() + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/testing/tools/test_runner.py b/testing/tools/test_runner.py index 7846d726f..f33ae168c 100644 --- a/testing/tools/test_runner.py +++ b/testing/tools/test_runner.py @@ -8,6 +8,7 @@ from datetime import timedelta import difflib from io import BytesIO +import itertools import multiprocessing import os import re @@ -34,7 +35,7 @@ TEST_DEFAULT_TIMEZONE = 'America/Los_Angeles' # List of test types that should run text tests instead of pixel tests. -TEXT_TESTS = ['javascript'] +TEXT_TESTS = ['drawing', 'javascript'] # Timeout (in seconds) for individual test commands. # TODO(crbug.com/42270974): array_buffer.in is slow under MSan, so need a @@ -318,8 +319,10 @@ def Run(self): processes=self.options.num_workers, initializer=_InitializePerProcessState, initargs=[self.per_process_config]) as pool: - if self.per_process_config.test_type in TEXT_TESTS: + if self.per_process_config.test_type == 'javascript': test_function = _RunTextTest + elif self.per_process_config.test_type == 'drawing': + test_function = _RunDrawingTest else: test_function = _RunPixelTest for result in pool.imap(test_function, self.test_cases): @@ -405,6 +408,15 @@ def _RunTextTest(test_case): return test_case_runner.test_result +def _RunDrawingTest(test_case): + """Runs a drawing test case.""" + test_case_runner = _TestCaseRunner(test_case) + with test_case_runner: + test_case_runner.test_result = test_case_runner.GenerateAndTest( + test_case_runner.TestDrawing) + return test_case_runner.test_result + + def _RunPixelTest(test_case): """Runs a pixel test case.""" test_case_runner = _TestCaseRunner(test_case) @@ -541,6 +553,7 @@ def __init__(self, test_case): self.test_case.input_path) self.pdf_path = os.path.join(self.working_dir, f'{self.test_id}.pdf') self.actual_images = None + self.actual_dumps = None def __enter__(self): self.duration_start = time.perf_counter_ns() @@ -749,6 +762,106 @@ def _VerifyEmptyText(self, txt_path): return self.test_case.NewResult(result_types.PASS) + def _GetActualDumpFiles(self): + dumps = [] + for page in itertools.count(): + dump_path = os.path.join(self.working_dir, + f'{self.test_id}.pdf.{page}.dump.txt') + if os.path.exists(dump_path): + dumps.append(dump_path) + else: + break + return dumps + + def _CleanupDrawingTest(self): + if self.actual_dumps: + for actual_dump in self.actual_dumps: + if os.path.exists(actual_dump): + os.remove(actual_dump) + + def _DiffDrawingFiles(self): + diff_log = [] + for page, actual_dump in enumerate(self.actual_dumps): + expected_dump = os.path.join( + self.source_dir, f'{self.test_id}_expected.pdf.{page}.dump.txt') + if not os.path.exists(expected_dump): + if self.options.regenerate_expected: + shutil.copyfile(actual_dump, expected_dump) + continue + diff_log.append( + f'missing expected file: {os.path.basename(expected_dump)}\n') + continue + + with open(expected_dump, 'r', errors='backslashreplace') as f1: + expected_lines = f1.readlines() + with open(actual_dump, 'r', errors='backslashreplace') as f2: + actual_lines = f2.readlines() + + diff = list( + difflib.unified_diff( + expected_lines, + actual_lines, + fromfile=expected_dump, + tofile=actual_dump)) + if diff: + if self.options.regenerate_expected: + shutil.copyfile(actual_dump, expected_dump) + continue + actual_name = os.path.basename(actual_dump) + expected_name = os.path.basename(expected_dump) + diff_log.append(f'{actual_name} vs. {expected_name}:\n') + diff_log.extend(diff) + + extra_page = len(self.actual_dumps) + while True: + extra_expected = os.path.join( + self.source_dir, f'{self.test_id}_expected.pdf.{extra_page}.dump.txt') + if os.path.exists(extra_expected): + extra_name = os.path.basename(extra_expected) + diff_log.append( + f'extra expected file for non-existent page: {extra_name}\n') + extra_page += 1 + else: + break + + return diff_log + + def TestDrawing(self): + self.actual_dumps = self._GetActualDumpFiles() + self._CleanupDrawingTest() + + cmd_to_run = [ + _per_process_state.pdfium_test_path, '--send-events', '--dump', + f'--time={TEST_SEED_TIME}' + ] + cmd_to_run.extend(self._GetFontArgs()) + cmd_to_run.extend(self._GetCommonFeatureArgs()) + cmd_to_run.append(self.pdf_path) + + test_result = self.RunCommand(cmd_to_run) + if not test_result.IsPass(): + return test_result + + self.actual_dumps = self._GetActualDumpFiles() + if not self.actual_dumps: + test_result.status = result_types.FAIL + test_result.reason = 'No drawing output generated' + test_result.comparison_failure = True + return test_result + + diff_log = self._DiffDrawingFiles() + if diff_log: + test_result.status = result_types.FAIL + test_result.reason = 'Drawing commands differ' + test_result.comparison_failure = True + test_result.log = ''.join(diff_log) + return test_result + + if _per_process_state.delete_output_on_success: + self._CleanupDrawingTest() + + return test_result + # TODO(crbug.com/42270661): Remove when ready to fully switch over to # Skia Gold def TestPixel(self): From aff95024b41ea460469d190cd1930b287fb88766 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 17 Nov 2026 16:04:54 -0800 Subject: [PATCH 12/34] Migrate pure display list embedder tests to drawing tests Move embedder tests that only open a document and compare its rendered display list over to the drawing test suite in testing/resources/drawing. Migrate: - bug_552046: Move .in to drawing/, remove .pdf. - bug_555784: Move .in to drawing/, remove .pdf, move expectation. - bug_455199: Move .pdf to drawing/, add expectation. - Remove fpdf_parser_decode_embeddertest.cpp now that all its tests have moved. - bug_547706: Copy .in to drawing/, move expectation, and remove LoadError547706 from fpdf_render_pattern_embeddertest.cpp. Retain bug_547706.pdf for fpdf_transformpage_embeddertest. - annotation_highlight_rollover_ap: Copy .in to drawing/, move expectation, and remove RenderAnnotWithOnlyRolloverAP from fpdf_annot_embeddertest.cpp. Retain .pdf for ModifyAnnotationFlags. - rectangles: Copy .in to drawing/, add expectation, and remove RenderPageToDisplayList from fpdf_view_embeddertest.cpp. Retain rectangles.pdf and expectation for other embedder tests. Change-Id: I55b8c41b9a8426b210d8909d0bb28998d5be730c Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164750 SLSA-Policy-Verified: SLSA Policy Verification Service Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fpdfapi/parser/BUILD.gn | 1 - .../fpdf_parser_decode_embeddertest.cpp | 42 --------- .../fpdf_render_pattern_embeddertest.cpp | 8 -- fpdfsdk/fpdf_annot_embeddertest.cpp | 14 --- fpdfsdk/fpdf_view_embeddertest.cpp | 9 -- testing/embedder_test_constants.h | 2 +- testing/resources/bug_552046.pdf | Bin 746 -> 0 bytes testing/resources/bug_555784.pdf | Bin 36626 -> 0 bytes .../annotation_highlight_rollover_ap.in | 86 ++++++++++++++++++ ...light_rollover_ap_expected.pdf.0.dump.txt} | 0 .../resources/{ => drawing}/bug_455199.pdf | Bin .../bug_455199_expected.pdf.0.dump.txt | 8 ++ testing/resources/drawing/bug_547706.in | 41 +++++++++ .../bug_547706_expected.pdf.0.dump.txt} | 0 testing/resources/{ => drawing}/bug_552046.in | Bin 624 -> 754 bytes .../bug_552046_expected.pdf.0.dump.txt | 6 ++ testing/resources/{ => drawing}/bug_555784.in | 4 + .../bug_555784_expected.pdf.0.dump.txt} | 0 testing/resources/drawing/rectangles.in | 43 +++++++++ .../rectangles_expected.pdf.0.dump.txt | 14 +++ 20 files changed, 203 insertions(+), 75 deletions(-) delete mode 100644 core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp delete mode 100644 testing/resources/bug_552046.pdf delete mode 100644 testing/resources/bug_555784.pdf create mode 100644 testing/resources/drawing/annotation_highlight_rollover_ap.in rename testing/resources/{embedder_tests/fpdf_annot_render_annot_with_only_rollover_ap.dump.txt => drawing/annotation_highlight_rollover_ap_expected.pdf.0.dump.txt} (100%) rename testing/resources/{ => drawing}/bug_455199.pdf (100%) create mode 100644 testing/resources/drawing/bug_455199_expected.pdf.0.dump.txt create mode 100644 testing/resources/drawing/bug_547706.in rename testing/resources/{embedder_tests/bug_547706.dump.txt => drawing/bug_547706_expected.pdf.0.dump.txt} (100%) rename testing/resources/{ => drawing}/bug_552046.in (82%) create mode 100644 testing/resources/drawing/bug_552046_expected.pdf.0.dump.txt rename testing/resources/{ => drawing}/bug_555784.in (99%) rename testing/resources/{embedder_tests/bug_555784.dump.txt => drawing/bug_555784_expected.pdf.0.dump.txt} (100%) create mode 100644 testing/resources/drawing/rectangles.in create mode 100644 testing/resources/drawing/rectangles_expected.pdf.0.dump.txt diff --git a/core/fpdfapi/parser/BUILD.gn b/core/fpdfapi/parser/BUILD.gn index 6064d2928..45ac22e31 100644 --- a/core/fpdfapi/parser/BUILD.gn +++ b/core/fpdfapi/parser/BUILD.gn @@ -162,7 +162,6 @@ pdfium_embeddertest_source_set("embeddertests") { sources = [ "cpdf_parser_embeddertest.cpp", "cpdf_security_handler_embeddertest.cpp", - "fpdf_parser_decode_embeddertest.cpp", "object_tree_traversal_util_embeddertest.cpp", ] deps = [ diff --git a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp b/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp deleted file mode 100644 index 9c49dcf23..000000000 --- a/core/fpdfapi/parser/fpdf_parser_decode_embeddertest.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2015 The PDFium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "core/fpdfapi/parser/fpdf_parser_decode.h" - -#include "public/cpp/fpdf_scopers.h" -#include "testing/embedder_test.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "testing/test_support.h" - -using FPDFParserDecodeEmbedderTest = EmbedderTest; - -TEST_F(FPDFParserDecodeEmbedderTest, Bug552046) { - // Tests specifying multiple image filters for a stream. Should not cause a - // crash when rendered and should produce a blank page. - ASSERT_TRUE(OpenDocument("bug_552046.pdf")); - ScopedPage page = LoadScopedPage(0); - ASSERT_TRUE(page); - CompareDisplayList(RenderLoadedPageToDisplayList(page.get()), - "blank_page_612x792"); -} - -TEST_F(FPDFParserDecodeEmbedderTest, Bug555784) { - // Tests bad input to the run length decoder that caused a heap overflow. - // Should not cause a crash when rendered. The image is 81915 pixels wide - // with 3277 DeviceN components at 16 bits each, which is a valid but - // enormous pitch, so its one scanline does get decoded and drawn. - ASSERT_TRUE(OpenDocument("bug_555784.pdf")); - ScopedPage page = LoadScopedPage(0); - ASSERT_TRUE(page); - CompareDisplayList(RenderLoadedPageToDisplayList(page.get()), "bug_555784"); -} - -TEST_F(FPDFParserDecodeEmbedderTest, Bug455199) { - // Tests object numbers with a value > 01000000. - // Should open successfully. - ASSERT_TRUE(OpenDocument("bug_455199.pdf")); - ScopedPage page = LoadScopedPage(0); - ASSERT_TRUE(page); - CompareDisplayList(RenderLoadedPageToDisplayList(page.get()), "hello_world"); -} diff --git a/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp b/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp index 2c7af39a3..ea1feea94 100644 --- a/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp +++ b/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp @@ -8,14 +8,6 @@ class FPDFRenderPatternEmbedderTest : public EmbedderTest {}; -TEST_F(FPDFRenderPatternEmbedderTest, LoadError547706) { - // Test shading where object is a dictionary instead of a stream. - ASSERT_TRUE(OpenDocument("bug_547706.pdf")); - ScopedPage page = LoadScopedPage(0); - ASSERT_TRUE(page); - CompareDisplayList(RenderLoadedPageToDisplayList(page.get()), "bug_547706"); -} - TEST_F(FPDFRenderPatternEmbedderTest, ZeroTilingPatternStep509964646) { // Rendering a tiling pattern with a zero step should not hang. ASSERT_TRUE(OpenDocument("bug_509964646.pdf")); diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp index 8ac1e7291..b8c97229f 100644 --- a/fpdfsdk/fpdf_annot_embeddertest.cpp +++ b/fpdfsdk/fpdf_annot_embeddertest.cpp @@ -515,20 +515,6 @@ TEST_F(FPDFAnnotEmbedderTest, BadAnnotsEntry) { EXPECT_FALSE(FPDFPage_GetAnnot(page.get(), 0)); } -TEST_F(FPDFAnnotEmbedderTest, RenderAnnotWithOnlyRolloverAP) { - // Open a file with one annotation and load its first page. - ASSERT_TRUE(OpenDocument("annotation_highlight_rollover_ap.pdf")); - ScopedPage page = LoadScopedPage(0); - ASSERT_TRUE(page); - - // This annotation has a malformed appearance stream, which does not have its - // normal appearance defined, only its rollover appearance. In this case, no - // normal appearance is rendered. - CompareDisplayList( - RenderLoadedPageWithFlagsToDisplayList(page.get(), FPDF_ANNOT), - "fpdf_annot_render_annot_with_only_rollover_ap"); -} - TEST_F(FPDFAnnotEmbedderTest, RenderMultilineMarkupAnnotWithoutAP) { // Open a file with multiline markup annotations. ASSERT_TRUE(OpenDocument("annotation_markup_multiline_no_ap.pdf")); diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp index 99b9c94ab..758883a47 100644 --- a/fpdfsdk/fpdf_view_embeddertest.cpp +++ b/fpdfsdk/fpdf_view_embeddertest.cpp @@ -2288,15 +2288,6 @@ TEST_F(FPDFViewEmbedderTest, DocumentVersionInCatalog) { EXPECT_EQ(16, version); } -TEST_F(FPDFViewEmbedderTest, RenderPageToDisplayList) { - ASSERT_TRUE(OpenDocument("rectangles.pdf")); - ScopedPage page = LoadScopedPage(0); - ASSERT_TRUE(page); - - std::string display_list = RenderPageToDisplayList(page.get()); - CompareDisplayList(display_list, "rectangles"); -} - TEST_F(FPDFViewEmbedderTest, RenderHelloWorldToDisplayList) { ASSERT_TRUE(OpenDocument("hello_world.pdf")); ScopedPage page = LoadScopedPage(0); diff --git a/testing/embedder_test_constants.h b/testing/embedder_test_constants.h index d1c68d4a1..4ba242e7a 100644 --- a/testing/embedder_test_constants.h +++ b/testing/embedder_test_constants.h @@ -20,7 +20,7 @@ inline constexpr char kBlankPage612By792Png[] = "blank_612x792"; // Expectation file basename for rendering bug_890322.pdf. inline constexpr char kBug890322Png[] = "bug_890322"; -// Expectation file basename for rendering hello_world.pdf or bug_455199.pdf. +// Expectation file basename for rendering hello_world.pdf. inline constexpr char kHelloWorldPng[] = "hello_world"; // Expectation file basename for rendering many_rectangles.pdf. diff --git a/testing/resources/bug_552046.pdf b/testing/resources/bug_552046.pdf deleted file mode 100644 index a60432dc95eda8ba20bb7b618064bdcab4cb6c79..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 746 zcmZWn&r2IY6jm>lIe8Khk$1^SG&5^9iJ%_hny4)p6H$wJ*zAtF60W?fnf>;g?|tt_s_YcU*+h<{&Yv&;69yE*+8&vn zCIIQOyTc=}3|1ktvxGN%{6`Q-NFM_~g3U=JZFRCTZ&(}4wLR`hXbKzYje_fg-BboJ z+8y#JmB?3k6dnrC_&~u5+L{X+k~d@oxhB$a6@mCFYDQ9Ucb~+$oUrX5(snNUQx1&9O?8EA7G<+MNu}nOi{u6Ogv@aO diff --git a/testing/resources/bug_555784.pdf b/testing/resources/bug_555784.pdf deleted file mode 100644 index 5c56a958d29a650f1725bf0168a7f2b80e780399..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 36626 zcmeI*&5mSAVFloQJwUcz${QFn{y( zgC9ISKY#YK+pq55KF901FQ0z+!>9ZE*Zp%(`-$&9=pWv_e*65@bJ`#E{L4T8xc$_3 zANTo(_aE=?KYsgM{INIIluIJ^4pK!+;3k$<sk|nSXuv`tjG#J&aKH4}Wrh_p4uj zd=C5jpMUu6hi`uVyW6@yfA!fH_kVl0?*H`s)zfFUm*>xJ;d;dDk*-I+9_4z}>(Q=9 zzaHay+^)yG9_xC%UXSaw+}^H75U>-%jtDy=?2xci!j1_$C+wiGlfsS)J1gw4u+zeh z3p+3Fyyz9}ytwn?&Wk%Q?!373;?9dZFYdg!^Wx5nJ1_3MxbxD^OFJ+5E$+Ou^U}^s zJ1_0LwDZ!=OFJ*^ytMPu&PzKl?YzA6^3KaUFFUiHmv>&?d3opMotJlB-g$ZF<(-#z zUfy|m=arpTc3#m7Q01UfFqN=hdB8cV69jb?4Qc zS9f0Bd3ER2omY2W-FbEA)ty&&Ufp?h=e3>Jc3#_gZRfR}*LGgpd2Q!iZ;I=io!53= z+j(v0wVl^?UfX$n=k=Y}cV6FledqO^*LPmud41>go!56>-+6uK^_|yuUf+3R=Z&2= zcHY=|W9N;XH+J6Gd1L2|oi}#g*m+~;jh#1k-q?BG5Z)2q65bQu6y6oy7Ty=$80Vd_ z^Sn2_IlMc(J-k2WetmPlzPVrD+^=u$*Ejd;oBQ?6{rcv9eRIFQx%1|JeRIFQxnJMh zuW#&U@W?uRHH`=e_Q{*PZve^Imt}>&|=Kd9OR~zVq%o@4oZyJMX^p?mO?k^X@zE zzVq%o@4oZyJMX^p?mO?k^X@zEZRfr1ytkeAw)5V0-rLT5+j(z0?``M3?Yy_0_qOxi zcHZ00d)s+$J1@NK!0@sY!^@5gFFP~5?9lMCQ^U)S4KF)4yzJocvXjHhjt(z7JG|`h z@Uqjx%Z?8(@;`wn|B!f0JSZL&4~xge1LKkL(0FV-I367jk9-V(41^5P>t|$uWT0fg zWZ+}~WgulhWng81WuRriW#DB1W*}xjW=PHlnt_@Dn}M4FoPnGHoq?SJo`IeLpMjqN zpn;$Pp@E?xJAaA>j0TPdkOqqT;0EFb;~@cHgf&hBX2-&U~hnLpl`r$;BNqMAaFo%U~qtNpm4x&;BWwOAaOu(U~zzP zpmD%);Bf%*RYCTvLULeofO4R6z;fVn0COO7KyzSofODX8z;obpIE{tS0nvfc0n&le z0n>rg0n~xiL5m5j4zLci4!91d&j33RJ0LqSJ3u>7J77C-JAgZoJD@wTJHR{8JK#I; zI{-WoJRm$UJU~29JYYO?WJwQEBJzza>J%Bxs zJ)k|XJ-|KCJ>Wg?JpeusJ|I3YK0rQDK43m@K7c-uKA=9ZKEOWEKHxs^J^()uKOjFa zKR`cFKVUy_KY%}wKcGLbKfpiGKj1&`Kk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5F zKk`5FKk`3@{pUaOKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKc0Sk3i79hy#0@-BcGCd zTJovMrzfAHe46s9%BL%zvV7X|smuJ2{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P z{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P z{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P z{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P z{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez&P{Ez4Vv+_UkKk`5F zKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5F zKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5F zKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk`5F zKk`5FKk`5FKk`5FKk`5FKk`5FKk`5FKk+~DKk+~DKk+~DKk+~DKk+~DKk+~DKk+~D zKk+~DKk+~DKk+~DKk+~DKk+~DKk+~DKk+~DKk+~DKk+~DKk+~DKk5I8|B3&J|B3&J z|B3&J|B3&J|B3&J|B3(UTrW8nOwJXPPnS$~|4-+l$+>EBE}NX|Cg;M*xpHzYot$eY z=iPd-=C&t>#;9sOKLKUdPvrSx+x{aj2xSJThs zbpB`lXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mY zXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mY zXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mY zXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mY zXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mY zXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ~mYXZ=6(Kl4BH zKl4BHKl4BHKl4BHKl4BHKl4BHKl4BHKl4BHKl4BHKl4BHKl4BHKl8uvzwp2Czwp2C zzwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2C zzwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2Czwp2C zzwp2Czwp2Czwp2Czwp2Czwp2Czwp24|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB z|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB z|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB z|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB z|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB z|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB z|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB z|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgB|AqgR|CRrh|CRrh|CRrh|CRrh z|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh z|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh z|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh z|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh z|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh z|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh z|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh z|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh z|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh z|CRrh|CRrh|CRrh|CRrh|CRrh|CRrh|CRrZ|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R z|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R z|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R z|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R z|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R z|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R z|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R z|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R z|Be5R|Be5R|Be5R|Be5R|Be5R|Be5R|82cp*V`Na8~+>s8~+>s8~+>s8~+>s8~+>s z8~+>s8~+>s8~+>s8~+>s8~+>s8~+>s8~+>s8~+>s8~+>s8~+>s8~+>s8~+>s8~+>s z8~+>s8~+>s8~+>s8~+>s8~+>s8~;21JO4ZXJO4ZXJO4ZXJO4ZXJO4ZXJO4ZXJO4ZX zJO4ZXJO4ZXJO4ZXJO4ZXJO4ZXudms^u6}p^cm8+&cm8+&cm8+&cm8+&cm8+&cm8+& zcm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+& zcm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+& zcm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+& zcm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+& zcm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+& zcm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm8+& zcm8+&cm8+&cm8+&cm8+&cm8+&cm8+&cm2Qfzw^KIzw^KIzw^KIzw^KIzw^KIzw^KI zzw^KIzw^KIzw^KIzw^KIzw^KIzw^KIzw^KIzw^KIzw^KIzw^KIzw^KIzw^KIzw^KI zzw^KIzw^KIzw^KIzw^KIzw>|afAD|sfAD|sfAD|sfAD|sfAD|sfAD|sfAD|sfAD|s zfAD|sfAD|s|5|2U&JX?%{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S z{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S z{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S z{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S z{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S z{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S z{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S z{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S z{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S{tx~S z{tx~S{tx~S{tx~S{@?h2)A7(J^R@+pgjxPGod{j+UrYy_GjV$nbDpd?HSUZCGDBgo-OSe z)1Ec$nbV#4?iu8sMedp8o=xr<<(^gUndP2c?iuEuW$u~go^9?K=bm-$ndg4m z=kou0gY7>p{J;Ka`o2Fu{J-)4#{V1tZ~VW0fsfq#%^Ux3{J-)4#{V1t&tmsXcF$(_ zjCRjz_sn+BZubm#&vN%nch7eBjCap^_sndcKlT5q z|4;pY@_+Jw>i<*!pZfpQ|EK;x_5Z2=PyK)D|5N{;`v27br~W_n|Ed2^{!ji-{eSBJ zQ~#g(|J47d{y+8qssB&?f9n5J|DXE*)c>dcKlT5~|H=QU|4;pY>i<*!pZfpQ|EK;x z_5Z2=PyK)D|5N{;`v27br~W_n|Ed2^{eSBJQ~#g(|J47d{y+8qssB&?f9n5J|DXE* z)c>dcKlT5q|4;pY>i<*!pZfpQ|EK;x_5Z2=PyK)D|5N{;`v27br~W_n|Ed2^{eSBJ zQ~#g(|J47d{y+8qssB&?f9n5J|DXE*)c>dcKlT5q|4;pY>i<*!pZfpQ|EK;x_5Z2= zPyK)D|5N{;`v27br~W_n|Ed2^{eSBJQ~#g(|J47d{y+8qssB&?fAW9wfAW9wf9n5} z|C9fd|C9fd|C9ey|DXJy{Ga@v{Ga@v`v27br~W_n|Ed2^{eRB=_3cytpZfpQ|EK;x z_5Z2=PyK)D|5N{;`v27br~W_n|Ed2^{eSBJQ~#g(|J47d{y+8qssB&?f9n5J|DXE* z)c>dcKlT5q|4;pY>i<*!pZfpQ|EK;x_5Z2=PyK)D|5N{;`v27br~W_n|Ed2^{eSBJ zQ~#g(|J47d{y+8qssB&?f9n5J|DXE*)c>dcKlT5q|4;pY>i<*!pZfpQ|EK;x_5Z2= zPyK)D|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N z|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N z|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N z|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N z|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N z|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N z|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N|BL^N z|BL^N|BL_2^`FK6#s9_s#s9_s#s9_s#s9_s#s9_s#s9_s#s9_s#s9_s#s9_s#s9U| z(=VT|e?HyK>&w6Y(ep*mbsw=`?)!cH=-tO}e|G=o^ABJD?!)`*erM02?x%nJ?zbQB z-(0r<``e#?{?niSr6;2J|; zUrYFM-BtTfzk}!{{1+C#|b=6;Bf+v6L_4!;{+Zj@Hm0T2|P~V zaRQGMc$~oF1Rf{wIDy9rJWk+o0*@1ToWSD*9w+cPfyW6vPT+9@j}v&D!2jh0t{YEY ze}mK8^|y-O?oapkub&3}*Y`fm-#k6JcfkJM4}RcA0l$C0KEC_#{$Kw1yZdw8&wTOW z>)X5c&tJWK|K&Mck5B)0w}H=J&hyuE=f~mstNk(8!;k;zIXwOFhx@boTz~lH{`PeJ zYUOUhH(NLd`sIfY*G(Aq{TcRQ k{`}p)-}mqTI+Sle-oE+hM6SO`I+dsIeedu7`NvQH1L1X&m;e9( diff --git a/testing/resources/drawing/annotation_highlight_rollover_ap.in b/testing/resources/drawing/annotation_highlight_rollover_ap.in new file mode 100644 index 000000000..6aae497e6 --- /dev/null +++ b/testing/resources/drawing/annotation_highlight_rollover_ap.in @@ -0,0 +1,86 @@ +{{header}} +{{object 1 0}} << + /Type /Catalog + /Pages 2 0 R + /OpenAction 20 0 R +>> +endobj +{{object 2 0}} << + /Type /Pages + /Count 1 + /Kids [ + 3 0 R + ] +>> +endobj +% Page number 0. +{{object 3 0}} << + /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Annots [ + 4 0 R + ] + /Tabs /R +>> +endobj + +% This annotation has a malformed appearance stream, which does not have its +% normal appearance defined, only its rollover appearance. In this case, no +% normal appearance is rendered. +{{object 4 0}} << + /Type /Annot + /Subtype /Highlight + /Rect [ 75 681 512 690 ] + /NM (Annot-1) + /F 4 + /QuadPoints [ 75 688 512 688 75 679 512 679 ] + /C [ 0.0001108646 0.001760244 0.9982184 ] + /Contents () + /AP << + /R 5 0 R + >> +>> +endobj + +{{object 5 0}} << + /BBox [ + 67.7299 + 704.296 + 136.325 + 721.292 + ] + /FormType 1 + /Matrix [ + 1.0 + 0.0 + 0.0 + 1.0 + -67.7299 + -704.296 + ] + /Resources << + /ProcSet [ + /PDF + ] + >> + /Subtype /Form + /Type /XObject + /Length 165 +>> +stream +1 0.819611 0 rg +0.9997 w +72 704.7961 m +68.2298 708.5663 68.2298 717.0216 72 720.7918 c +132.0551 720.7918 l +135.8253 717.0216 135.8253 708.5663 132.0551 704.7961 c +f +endstream +>> +endobj + +{{xref}} +{{trailer}} +{{startxref}} +%%EOF diff --git a/testing/resources/embedder_tests/fpdf_annot_render_annot_with_only_rollover_ap.dump.txt b/testing/resources/drawing/annotation_highlight_rollover_ap_expected.pdf.0.dump.txt similarity index 100% rename from testing/resources/embedder_tests/fpdf_annot_render_annot_with_only_rollover_ap.dump.txt rename to testing/resources/drawing/annotation_highlight_rollover_ap_expected.pdf.0.dump.txt diff --git a/testing/resources/bug_455199.pdf b/testing/resources/drawing/bug_455199.pdf similarity index 100% rename from testing/resources/bug_455199.pdf rename to testing/resources/drawing/bug_455199.pdf diff --git a/testing/resources/drawing/bug_455199_expected.pdf.0.dump.txt b/testing/resources/drawing/bug_455199_expected.pdf.0.dump.txt new file mode 100644 index 000000000..2a0379422 --- /dev/null +++ b/testing/resources/drawing/bug_455199_expected.pdf.0.dump.txt @@ -0,0 +1,8 @@ +SaveState +SetBaseClip [0,0,200,200] +SetClip_PathFill rule=winding matrix=none points=[move(0.0000,200.0000) line(0.0000,0.0000) line(200.0000,0.0000) line(200.0000,200.0000) line(0.0000,200.0000,close)] +SaveState +DrawDeviceText font="Tinos" size=12.0000 color=0xff000000 matrix=[1.0000,0.0000,0.0000,-1.0000,20.0000,150.0000] glyphs=[(idx=43,u=U+0048,origin=(0.0000,0.0000)) (idx=72,u=U+0065,origin=(8.6640,0.0000)) (idx=79,u=U+006C,origin=(13.9920,0.0000)) (idx=79,u=U+006C,origin=(17.3280,0.0000)) (idx=82,u=U+006F,origin=(20.6640,0.0000)) (idx=15,u=U+002C,origin=(26.6640,0.0000)) (idx=3,u=U+0020,origin=(29.6640,0.0000)) (idx=90,u=U+0077,origin=(32.6640,0.0000)) (idx=82,u=U+006F,origin=(41.3280,0.0000)) (idx=85,u=U+0072,origin=(47.3280,0.0000)) (idx=79,u=U+006C,origin=(51.3240,0.0000)) (idx=71,u=U+0064,origin=(54.6600,0.0000)) (idx=4,u=U+0021,origin=(60.6600,0.0000))] +DrawDeviceText font="Arimo" size=16.0000 color=0xff000000 matrix=[1.0000,0.0000,0.0000,-1.0000,20.0000,100.0000] glyphs=[(idx=42,u=U+0047,origin=(0.0000,0.0000)) (idx=82,u=U+006F,origin=(12.4480,0.0000)) (idx=82,u=U+006F,origin=(21.3440,0.0000)) (idx=71,u=U+0064,origin=(30.2400,0.0000)) (idx=69,u=U+0062,origin=(39.1360,0.0000)) (idx=92,u=U+0079,origin=(48.0320,0.0000)) (idx=72,u=U+0065,origin=(56.0320,0.0000)) (idx=15,u=U+002C,origin=(64.9280,0.0000)) (idx=3,u=U+0020,origin=(69.3760,0.0000)) (idx=90,u=U+0077,origin=(73.8240,0.0000)) (idx=82,u=U+006F,origin=(85.3760,0.0000)) (idx=85,u=U+0072,origin=(94.2720,0.0000)) (idx=79,u=U+006C,origin=(99.6000,0.0000)) (idx=71,u=U+0064,origin=(103.1520,0.0000)) (idx=4,u=U+0021,origin=(112.0480,0.0000))] +RestoreState +RestoreState diff --git a/testing/resources/drawing/bug_547706.in b/testing/resources/drawing/bug_547706.in new file mode 100644 index 000000000..114b2f67b --- /dev/null +++ b/testing/resources/drawing/bug_547706.in @@ -0,0 +1,41 @@ +{{header}} + +{{object 1 0}} +<< /Pages 2 0 R >> +endobj + +{{object 2 0}} +<< /Kids [ 3 0 R ] >> +endobj + +% Test shading where object is a dictionary instead of a stream. +{{object 3 0}} +<< /Contents 4 0 R /Resources << /Pattern 6 0 R >>>> +endobj + +{{object 4 0}} +<< /Length 5 0 R >> +stream +/R9 scn +0 0 2479 3508 re +/R11 36 Tf +[(1)-12288.9(2)]TJ +endstream +endobj + +{{object 6 0}} +<< /R9 7 0 R >> +endobj + +{{object 7 0}} +<< /PatternType 2 /Shading 8 0 R >> +endobj + +{{object 8 0}} +<< /BitsPerComponent 16 /ColorSpace /DeviceRGB /ShadingType 5 >> +endobj + +{{xref}} +{{trailer}} +{{startxref}} +%%EOF diff --git a/testing/resources/embedder_tests/bug_547706.dump.txt b/testing/resources/drawing/bug_547706_expected.pdf.0.dump.txt similarity index 100% rename from testing/resources/embedder_tests/bug_547706.dump.txt rename to testing/resources/drawing/bug_547706_expected.pdf.0.dump.txt diff --git a/testing/resources/bug_552046.in b/testing/resources/drawing/bug_552046.in similarity index 82% rename from testing/resources/bug_552046.in rename to testing/resources/drawing/bug_552046.in index 2afc252c7578d9058e959c97e743466dec97d8e7..f0610ee17839ce41e9ed53ca202ab93a0d23a24d 100644 GIT binary patch delta 143 zcmXBKJqiLb5C%{p+F0rZzGmCKjMl=KOtQiJF_W-Zc_qP%i6>C-)$hIi?4C#Sm~dw8 z3T> endobj +% Tests bad input to the run length decoder that caused a heap overflow. +% Should not cause a crash when rendered. The image is 81915 pixels wide +% with 3277 DeviceN components at 16 bits each, which is a valid but +% enormous pitch, so its one scanline does get decoded and drawn. {{object 7 0}} << /Type /XObject diff --git a/testing/resources/embedder_tests/bug_555784.dump.txt b/testing/resources/drawing/bug_555784_expected.pdf.0.dump.txt similarity index 100% rename from testing/resources/embedder_tests/bug_555784.dump.txt rename to testing/resources/drawing/bug_555784_expected.pdf.0.dump.txt diff --git a/testing/resources/drawing/rectangles.in b/testing/resources/drawing/rectangles.in new file mode 100644 index 000000000..73345161a --- /dev/null +++ b/testing/resources/drawing/rectangles.in @@ -0,0 +1,43 @@ +{{header}} +{{object 1 0}} << + /Type /Catalog + /Pages 2 0 R +>> +endobj +{{object 2 0}} << + /Type /Pages + /MediaBox [0 0 200 300] + /Count 1 + /Kids [3 0 R] +>> +endobj +{{object 3 0}} << + /Type /Page + /Parent 2 0 R + /Contents 4 0 R +>> +endobj +{{object 4 0}} << + {{streamlen}} +>> +stream +q +0 0 0 rg +0 290 10 10 re B* +10 150 50 30 re B* +0 0 1 rg +190 290 10 10 re B* +70 232 50 30 re B* +0 1 0 rg +190 0 10 10 re B* +130 150 50 30 re B* +1 0 0 rg +0 0 10 10 re B* +70 67 50 30 re B* +Q +endstream +endobj +{{xref}} +{{trailer}} +{{startxref}} +%%EOF diff --git a/testing/resources/drawing/rectangles_expected.pdf.0.dump.txt b/testing/resources/drawing/rectangles_expected.pdf.0.dump.txt new file mode 100644 index 000000000..b2d23ce47 --- /dev/null +++ b/testing/resources/drawing/rectangles_expected.pdf.0.dump.txt @@ -0,0 +1,14 @@ +SaveState +SetBaseClip [0,0,200,300] +SetClip_PathFill rule=winding matrix=none points=[move(0.0000,300.0000) line(0.0000,0.0000) line(200.0000,0.0000) line(200.0000,300.0000) line(0.0000,300.0000,close)] +SaveState +DrawPath fill=0xff000000 stroke=0xff000000 rule=even-odd stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] matrix=[1.0000,0.0000,0.0000,-1.0000,0.0000,300.0000] points=[move(0.0000,290.0000) line(10.0000,290.0000) line(10.0000,300.0000) line(0.0000,300.0000) line(0.0000,290.0000,close)] +DrawPath fill=0xff000000 stroke=0xff000000 rule=even-odd stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] matrix=[1.0000,0.0000,0.0000,-1.0000,0.0000,300.0000] points=[move(10.0000,150.0000) line(60.0000,150.0000) line(60.0000,180.0000) line(10.0000,180.0000) line(10.0000,150.0000,close)] +DrawPath fill=0xff0000ff stroke=0xff000000 rule=even-odd stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] matrix=[1.0000,0.0000,0.0000,-1.0000,0.0000,300.0000] points=[move(190.0000,290.0000) line(200.0000,290.0000) line(200.0000,300.0000) line(190.0000,300.0000) line(190.0000,290.0000,close)] +DrawPath fill=0xff0000ff stroke=0xff000000 rule=even-odd stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] matrix=[1.0000,0.0000,0.0000,-1.0000,0.0000,300.0000] points=[move(70.0000,232.0000) line(120.0000,232.0000) line(120.0000,262.0000) line(70.0000,262.0000) line(70.0000,232.0000,close)] +DrawPath fill=0xff00ff00 stroke=0xff000000 rule=even-odd stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] matrix=[1.0000,0.0000,0.0000,-1.0000,0.0000,300.0000] points=[move(190.0000,0.0000) line(200.0000,0.0000) line(200.0000,10.0000) line(190.0000,10.0000) line(190.0000,0.0000,close)] +DrawPath fill=0xff00ff00 stroke=0xff000000 rule=even-odd stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] matrix=[1.0000,0.0000,0.0000,-1.0000,0.0000,300.0000] points=[move(130.0000,150.0000) line(180.0000,150.0000) line(180.0000,180.0000) line(130.0000,180.0000) line(130.0000,150.0000,close)] +DrawPath fill=0xffff0000 stroke=0xff000000 rule=even-odd stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] matrix=[1.0000,0.0000,0.0000,-1.0000,0.0000,300.0000] points=[move(0.0000,0.0000) line(10.0000,0.0000) line(10.0000,10.0000) line(0.0000,10.0000) line(0.0000,0.0000,close)] +DrawPath fill=0xffff0000 stroke=0xff000000 rule=even-odd stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] matrix=[1.0000,0.0000,0.0000,-1.0000,0.0000,300.0000] points=[move(70.0000,67.0000) line(120.0000,67.0000) line(120.0000,97.0000) line(70.0000,97.0000) line(70.0000,67.0000,close)] +RestoreState +RestoreState From 68f43efa71ac66ba843ba286bb76d075aa1c49df Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 17 Nov 2026 17:35:02 -0800 Subject: [PATCH 13/34] Roll third_party/rust/ 79a8603b9..7661f9bcc (48 commits) Out-of-schedule roll to allow pdfium to build with fontations when part of a chrome checkout. https://chromium.googlesource.com/chromium/src/third_party/rust/+log/79a8603b966b..7661f9bcc77d Created with: roll-dep third_party/rust Then update PDFium for skrifa/v0_49: - bump hard-coded read_fonts versions (v0_45 to v0_46) - bump hard-coded skrifa versions (v0_48 to v0_49) - Replace skrifa_cxx_config include_dirs with relative paths. - Updated read_fonts::ps imports to to match API changes. - Remove redundant cast. - Visually-indistinguishable MSE bump for 3bigpreview.pdf - Expand pdfium_common_config to cover generated files. - Replace skrifa_cxx_config with updated pdfium_common_config - Use properly based path in main.rs. Change-Id: I8d5e32df8f0b0132d00b0548d5e23fe9bb49e816 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164870 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- BUILD.gn | 5 ++++- DEPS | 2 +- core/fxge/BUILD.gn | 19 ++++--------------- core/fxge/skrifa/src/main.rs | 8 +++----- skia/BUILD.gn | 4 ++-- testing/SUPPRESSIONS | 2 +- 6 files changed, 15 insertions(+), 25 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 6834a5e15..42715bddb 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -19,7 +19,10 @@ config("pdfium_common_config") { cflags = [] cflags_cc = [] ldflags = [] - include_dirs = [ "." ] + include_dirs = [ + ".", + target_gen_dir, + ] inputs = [ "unsafe_buffers_paths.txt" ] defines = [] diff --git a/DEPS b/DEPS index b250f8159..42270b345 100644 --- a/DEPS +++ b/DEPS @@ -232,7 +232,7 @@ vars = { # Three lines of non-changing comments so that # the commit queue can handle CLs rolling rust # and whatever else without interference from each other. - 'rust_revision': '79a8603b966b612119e3498bcf7e535dfa096c1c', + 'rust_revision': '7661f9bcc77d614626b818bc40bd8398e4a48d9c', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling simdutf # and whatever else without interference from each other. diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn index e8436791c..d9ffcb824 100644 --- a/core/fxge/BUILD.gn +++ b/core/fxge/BUILD.gn @@ -10,15 +10,6 @@ if (pdf_enable_fontations) { import("//build/rust/rust_static_library.gni") } -if (pdf_enable_fontations) { - config("skrifa_cxx_config") { - include_dirs = [ - "//core/fxge/skrifa/src", - "$root_gen_dir/core/fxge/skrifa/src", - ] - } -} - source_set("fxge") { sources = [ "calculate_pitch.cpp", @@ -176,7 +167,6 @@ source_set("fxge") { } if (pdf_enable_fontations) { - configs += [ ":skrifa_cxx_config" ] deps += [ ":skrifa_cxx", ":skrifa_cxx_cpp", @@ -249,10 +239,10 @@ if (pdf_enable_fontations) { features = [ "agl" ] deps = [ "//build/rust:cxx_cppdeps", - "//third_party/rust/read_fonts/v0_45:lib", - "//third_party/rust/skrifa/v0_48:lib", + "//third_party/rust/read_fonts/v0_46:lib", + "//third_party/rust/skrifa/v0_49:lib", ] - configs += [ ":skrifa_cxx_config" ] + configs += [ "../../:pdfium_common_config" ] } source_set("skrifa_cxx_cpp") { @@ -267,7 +257,7 @@ if (pdf_enable_fontations) { configs -= [ "//build/config/compiler:chromium_code" ] configs += [ "//build/config/compiler:no_chromium_code", - ":skrifa_cxx_config", + "../../:pdfium_common_config", ] visibility = [ ":*" ] } @@ -353,7 +343,6 @@ pdfium_unittest_source_set("unittests") { ":skrifa_cxx_cpp", "//build/rust:cxx_cppdeps", ] - configs += [ ":skrifa_cxx_config" ] } } diff --git a/core/fxge/skrifa/src/main.rs b/core/fxge/skrifa/src/main.rs index 346ad3e63..acffb7037 100644 --- a/core/fxge/skrifa/src/main.rs +++ b/core/fxge/skrifa/src/main.rs @@ -9,10 +9,8 @@ use read_fonts::{ charset::Charset as CffCharset, CffFontRef, Encoding as CffEncoding, Metadata as CffMetadata, Subfont as CffSubfont, }, - charmap::Charmap as PsCharmap, - encoding::PredefinedEncoding, - string::Sid, type1::Type1Font, + PredefinedEncoding, Sid, UnicodeCharmap as PsCharmap, }, tables::{cmap::Cmap, head::MacStyle, os2::SelectionFlags}, types::{Fixed, GlyphId, Tag}, @@ -173,7 +171,7 @@ mod skrifa_ffi { } unsafe extern "C++" { - include!("outlines.h"); + include!("core/fxge/skrifa/src/outlines.h"); fn run(font_path: &str); } @@ -385,7 +383,7 @@ impl SkrifaFont<'_> { fn num_glyphs(&self) -> u32 { match self { - Self::Sfnt(sfnt) => sfnt.metrics.glyph_count as u32, + Self::Sfnt(sfnt) => sfnt.metrics.glyph_count, Self::Type1(type1) => type1.num_glyphs(), Self::Cff(cff) => cff.cid_count.unwrap_or_else(|| cff.font.num_glyphs()), Self::Error => 0, diff --git a/skia/BUILD.gn b/skia/BUILD.gn index d174c8f36..68bd82d18 100644 --- a/skia/BUILD.gn +++ b/skia/BUILD.gn @@ -43,8 +43,8 @@ if (pdf_enable_fontations) { deps = [ ":path_bridge", "//third_party/rust/font_types/v0_12:lib", - "//third_party/rust/read_fonts/v0_45:lib", - "//third_party/rust/skrifa/v0_48:lib", + "//third_party/rust/read_fonts/v0_46:lib", + "//third_party/rust/skrifa/v0_49:lib", ] configs -= [ "//build/config/compiler:chromium_code" ] configs += [ diff --git a/testing/SUPPRESSIONS b/testing/SUPPRESSIONS index 0dff7ee02..d288ab8a0 100644 --- a/testing/SUPPRESSIONS +++ b/testing/SUPPRESSIONS @@ -63,7 +63,7 @@ 3_interpolate_image.pdf mac * skia * fuzzy 3bigpreview.pdf mac * agg * diff 3bigpreview.pdf * * * * fuzzy=21,0.15,25 -3bigpreview.pdf * * * fontations fuzzy=25,0.25,15 +3bigpreview.pdf * * * fontations fuzzy=25,0.25,25 4_35.pdf mac * agg * diff 4_35.pdf * * * fontations fuzzy=10,0.1,15 4_39.pdf mac * agg * diff From 86e81c6e7c4734de49923da0cff94fb3c17fb537 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 18 Nov 2026 13:44:42 -0800 Subject: [PATCH 14/34] Convert cfde_textout_unittest to DisplayListDeviceDriver CFDE_TextOut::DrawLogicText() performs logical text breaking and piece layout rather than pixel rasterization. Use DisplayListDeviceDriver and compare the emitted display lists directly, removing all renderer- and font-backend-specific checksums. Without MD5 hashing, xfa/fde:unittests no longer depends on core/fdrm, so drop that dependency as well. Change-Id: I2fbd152cb7fa8717b465f93fcf253116ae2383de Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164910 Reviewed-by: Lei Zhang --- xfa/fde/BUILD.gn | 2 +- xfa/fde/cfde_textout_unittest.cpp | 144 ++++++++++++------------------ 2 files changed, 59 insertions(+), 87 deletions(-) diff --git a/xfa/fde/BUILD.gn b/xfa/fde/BUILD.gn index c52473300..6ecb79e45 100644 --- a/xfa/fde/BUILD.gn +++ b/xfa/fde/BUILD.gn @@ -38,8 +38,8 @@ pdfium_unittest_source_set("unittests") { ] deps = [ ":fde", - "../../core/fdrm", "../../core/fxge", + "../../core/fxge:test_support", "../../testing:test_environments", "../../testing:test_support", "../fgas/font", diff --git a/xfa/fde/cfde_textout_unittest.cpp b/xfa/fde/cfde_textout_unittest.cpp index 54980b78f..1953160b3 100644 --- a/xfa/fde/cfde_textout_unittest.cpp +++ b/xfa/fde/cfde_textout_unittest.cpp @@ -5,19 +5,16 @@ #include "xfa/fde/cfde_textout.h" #include +#include #include "build/build_config.h" -#include "core/fdrm/fx_crypt.h" #include "core/fxcrt/bytestring.h" #include "core/fxcrt/fx_codepage.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/retain_ptr.h" -#include "core/fxge/cfx_gemodule.h" -#include "core/fxge/cfx_glyphcache.h" #include "core/fxge/cfx_renderdevice.h" -#include "core/fxge/dib/cfx_dibitmap.h" +#include "core/fxge/display_list_device_driver.h" #include "testing/gtest/include/gtest/gtest.h" -#include "testing/utils/hash.h" #include "xfa/fgas/font/cfgas_fontmgr.h" #include "xfa/fgas/font/cfgas_gefont.h" #include "xfa/fgas/font/cfgas_gemodule.h" @@ -30,12 +27,11 @@ class CFDETextOutTest : public testing::Test { ~CFDETextOutTest() override = default; void SetUp() override { - CFX_Size bitmap_size = GetBitmapSize(); - bitmap_ = MakeRetain(); - ASSERT_TRUE(bitmap_->Create(bitmap_size.width, bitmap_size.height, - FXDIB_Format::kBgra)); - - device_ = CFX_RenderDevice::CreateForBitmap(bitmap_); + CFX_Size device_size = GetDeviceSize(); + auto driver = std::make_unique(device_size.width, + device_size.height); + driver_ = driver.get(); + device_ = CFX_RenderDevice::CreateWithDriver(std::move(driver)); ASSERT_TRUE(device_); font_ = LoadFont(); @@ -45,15 +41,15 @@ class CFDETextOutTest : public testing::Test { text_out_->SetFont(font_); text_out_->SetFontSize(12.0f); - EXPECT_EQ(GetEmptyBitmapChecksum(), GetBitmapChecksum()); + EXPECT_TRUE(driver_->display_list().IsEmpty()); } void TearDown() override { - // reverse order form SetUp() + // reverse order from SetUp() text_out_.reset(); font_.Reset(); + driver_ = nullptr; device_.reset(); - bitmap_.Reset(); } virtual RetainPtr LoadFont() { @@ -62,69 +58,43 @@ class CFDETextOutTest : public testing::Test { FX_CodePage::kDefANSI); } - virtual CFX_Size GetBitmapSize() { return CFX_Size(200, 100); } - - virtual const char* GetEmptyBitmapChecksum() { - static const char kEmptyBitmapChecksum[] = - "a042237c5493fdb9656b94a83608d11a"; - return kEmptyBitmapChecksum; - } + virtual CFX_Size GetDeviceSize() { return CFX_Size(200, 100); } CFX_RenderDevice* device() { return device_.get(); } + const ByteString& display_list() const { return driver_->display_list(); } CFDE_TextOut& text_out() { return *text_out_; } - ByteString GetBitmapChecksum() { - CryptMd5Context context = CryptMd5Start(); - for (int i = 0; i < bitmap_->GetHeight(); ++i) { - CryptMd5Update(&context, bitmap_->GetScanline(i)); - } - uint8_t digest[16]; - CryptMd5Finish(&context, digest); - return ByteString(CryptToBase16(digest).c_str()); - } - private: - RetainPtr bitmap_; std::unique_ptr device_; + DisplayListDeviceDriver* driver_ = nullptr; RetainPtr font_; std::unique_ptr text_out_; }; TEST_F(CFDETextOutTest, DrawLogicTextBasic) { text_out().DrawLogicText(device(), L"foo", CFX_RectF(0, 0, 2100, 100)); - const char* checksum = []() { -#if defined(PDF_USE_SKIA) - if (CFX_GEModule::IsSkiaRenderer()) { -#if BUILDFLAG(IS_WIN) - return "02c55ce12d3c31ae32fa08fe59c38996"; -#elif defined(PDF_ENABLE_FONTATIONS) - if (CFX_GEModule::IsFontations()) { - return "8a6b320f8a4ae1febfc6e50513506dcf"; - } -#endif - } -#endif -#if defined(PDF_ENABLE_FONTATIONS) - if (CFX_GEModule::IsFontations()) { - return "0064590d0532663140d521a2ea6780b1"; - } -#endif - return "c143f8450f661a489cc9423de7cc1acc"; - }(); - EXPECT_EQ(checksum, GetBitmapChecksum()); + static constexpr char kExpected[] = + "SaveState\n" + "DrawDeviceText font=\"Arimo\" size=-12.0000 color=0xff000000 " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "glyphs=[(idx=73,origin=(0.0000,9.7312)) " + "(idx=82,origin=(3.9960,9.7312)) " + "(idx=82,origin=(11.3160,9.7312))]\n" + "RestoreState\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(CFDETextOutTest, DrawLogicTextEmptyRect) { text_out().DrawLogicText(device(), L"foo", CFX_RectF()); - EXPECT_EQ(GetEmptyBitmapChecksum(), GetBitmapChecksum()); + EXPECT_TRUE(display_list().IsEmpty()); } #if !BUILDFLAG(IS_WIN) // This test depends on a particular font being present. -class CFDETextOutLargeBitmapTest : public CFDETextOutTest { +class CFDETextOutLargeTest : public CFDETextOutTest { public: - CFDETextOutLargeBitmapTest() = default; - ~CFDETextOutLargeBitmapTest() override = default; + CFDETextOutLargeTest() = default; + ~CFDETextOutLargeTest() override = default; RetainPtr LoadFont() override { const wchar_t kFontFamily[] = L"DejaVu Sans"; @@ -133,35 +103,37 @@ class CFDETextOutLargeBitmapTest : public CFDETextOutTest { FX_CodePage::kFailure); } - CFX_Size GetBitmapSize() override { return CFX_Size(2100, 20); } - - const char* GetEmptyBitmapChecksum() override { - static const char kEmptyLargeBitmapChecksum[] = - "101745f76351fd5d916bf3817b71563c"; - return kEmptyLargeBitmapChecksum; - } - - const char* GetLargeTextBlobChecksum() { -#if defined(PDF_USE_SKIA) - if (CFX_GEModule::IsSkiaRenderer()) { -#if defined(PDF_ENABLE_FONTATIONS) - if (CFX_GEModule::IsFontations()) { - return "8b657167ef063bca5adb38f6a5d5ae54"; - } -#endif - return "e9aaffff1ea680bd5dc40a7b8904788d"; - } -#endif -#if defined(PDF_ENABLE_FONTATIONS) - if (CFX_GEModule::IsFontations()) { - return "78842f43dce9b89af92f17b56d9ceaab"; - } -#endif - return "add7cf2819b3e1397d8a60a9ec436a86"; - } + CFX_Size GetDeviceSize() override { return CFX_Size(2100, 20); } + + static constexpr char kExpectedLargeDisplayList[] = + "SaveState\n" + "DrawDeviceText font=\"DejaVu Sans\" size=-10.0000 color=0xff000000 " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "glyphs=[(idx=76,origin=(2079.1499,11.9794))]\n" + "DrawDeviceText font=\"DejaVu Sans\" size=-10.0000 color=0xff000000 " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "glyphs=[(idx=5300,origin=(1954.7100,11.9794))]\n" + "DrawDeviceText font=\"DejaVu Sans\" size=-10.0000 color=0xff000000 " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "glyphs=[(idx=54,origin=(1966.9600,11.9794)) " + "(idx=86,origin=(1973.2999,11.9794)) " + "(idx=86,origin=(1978.4999,11.9794)) " + "(idx=86,origin=(1983.6998,11.9794)) " + "(idx=86,origin=(1988.8998,11.9794)) " + "(idx=86,origin=(1994.0997,11.9794)) " + "(idx=86,origin=(1999.2997,11.9794)) " + "(idx=86,origin=(2004.4996,11.9794)) " + "(idx=86,origin=(2009.6996,11.9794)) " + "(idx=86,origin=(2014.8995,11.9794)) " + "(idx=86,origin=(2020.0995,11.9794)) " + "(idx=86,origin=(2025.2994,11.9794)) " + "(idx=86,origin=(2030.4994,11.9794)) " + "(idx=86,origin=(2035.6993,11.9794)) " + "(idx=86,origin=(2040.8993,11.9794))]\n" + "RestoreState\n"; }; -TEST_F(CFDETextOutLargeBitmapTest, DrawLogicTextBug953881) { +TEST_F(CFDETextOutLargeTest, DrawLogicTextBug953881) { FDE_TextStyle styles; styles.single_line_ = true; text_out().SetStyles(styles); @@ -180,10 +152,10 @@ TEST_F(CFDETextOutLargeBitmapTest, DrawLogicTextBug953881) { L"iiiiisssss"; text_out().DrawLogicText(device(), WideString(kText), CFX_RectF(3, 3, 2048, 10)); - EXPECT_EQ(GetLargeTextBlobChecksum(), GetBitmapChecksum()); + EXPECT_EQ(kExpectedLargeDisplayList, display_list()); } -TEST_F(CFDETextOutLargeBitmapTest, DrawLogicTextBug1342078) { +TEST_F(CFDETextOutLargeTest, DrawLogicTextBug1342078) { FDE_TextStyle styles; styles.single_line_ = true; text_out().SetStyles(styles); @@ -202,7 +174,7 @@ TEST_F(CFDETextOutLargeBitmapTest, DrawLogicTextBug1342078) { L"iiiiiiiiiisssss"; text_out().DrawLogicText(device(), WideString(kText), CFX_RectF(3, 3, 2048, 10)); - EXPECT_EQ(GetLargeTextBlobChecksum(), GetBitmapChecksum()); + EXPECT_EQ(kExpectedLargeDisplayList, display_list()); } #endif // !BUILDFLAG(IS_WIN) From c6a305341809f32416e4000b64a4969b43654583 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 18 Nov 2026 17:25:57 -0800 Subject: [PATCH 15/34] Convert cfx_barcode_unittest to DisplayListDeviceDriver CFX_Barcode::RenderDevice() emits logical path and rectangle geometry into CFX_RenderDevice, so compare the emitted display lists directly, and remove all renderer-specific MD5 checksums. Change-Id: I9cfa04e6717c9005e43a508f5c5c4a0583c356fb Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164950 Commit-Queue: Lei Zhang Reviewed-by: Lei Zhang --- fxbarcode/BUILD.gn | 1 + fxbarcode/cfx_barcode_unittest.cpp | 1213 +++++++++++++++++++++++++--- 2 files changed, 1097 insertions(+), 117 deletions(-) diff --git a/fxbarcode/BUILD.gn b/fxbarcode/BUILD.gn index 78fce1a6d..21abdd8ec 100644 --- a/fxbarcode/BUILD.gn +++ b/fxbarcode/BUILD.gn @@ -157,6 +157,7 @@ pdfium_unittest_source_set("unittests") { deps = [ ":fxbarcode", "../core/fxge", + "../core/fxge:test_support", "../testing:test_support", ] pdfium_root_dir = "../" diff --git a/fxbarcode/cfx_barcode_unittest.cpp b/fxbarcode/cfx_barcode_unittest.cpp index 53ccec178..7528be888 100644 --- a/fxbarcode/cfx_barcode_unittest.cpp +++ b/fxbarcode/cfx_barcode_unittest.cpp @@ -8,31 +8,26 @@ #include #include +#include "core/fxcrt/bytestring.h" #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/fx_string.h" #include "core/fxge/cfx_renderdevice.h" -#include "core/fxge/dib/cfx_dibitmap.h" +#include "core/fxge/display_list_device_driver.h" #include "testing/gtest/include/gtest/gtest.h" -#include "testing/utils/bitmap_saver.h" -#include "testing/utils/hash.h" class BarcodeTest : public testing::Test { public: void SetUp() override { BC_Library_Init(); - auto bitmap = pdfium::MakeRetain(); - if (bitmap->Create(640, 480, FXDIB_Format::kBgrx)) { - bitmap_ = bitmap; - } - ASSERT_TRUE(bitmap_); - auto device = CFX_RenderDevice::CreateForBitmap(bitmap_); - ASSERT_TRUE(device); - device_ = std::move(device); + auto driver = std::make_unique(640, 480); + driver_ = driver.get(); + device_ = CFX_RenderDevice::CreateWithDriver(std::move(driver)); + ASSERT_TRUE(device_); } void TearDown() override { - bitmap_.Reset(); + driver_ = nullptr; device_.reset(); barcode_.reset(); BC_Library_Destroy(); @@ -48,48 +43,154 @@ class BarcodeTest : public testing::Test { bool RenderDevice() { return barcode_->RenderDevice(device_.get(), matrix_); } - std::string BitmapChecksum() { - return GenerateMD5Base16(bitmap_->GetBuffer()); - } - - // Manually insert calls to this as needed for debugging. - void SaveBitmap(const std::string& filename) { - BitmapSaver::WriteBitmapToPng(bitmap_.Get(), filename); - } + const ByteString& display_list() const { return driver_->display_list(); } protected: CFX_Matrix matrix_; std::unique_ptr barcode_; std::unique_ptr device_; - RetainPtr bitmap_; + DisplayListDeviceDriver* driver_ = nullptr; }; TEST_F(BarcodeTest, Code39) { Create(BC_TYPE::kCode39); EXPECT_TRUE(barcode()->Encode(L"CLAMS")); RenderDevice(); -#if defined(PDF_USE_SKIA) - static constexpr char kExpectedChecksum[] = - "f1a566abd7813ad9e2593e873b870653"; -#else - static constexpr char kExpectedChecksum[] = - "cd4cd3f36da38ff58d9f621827018903"; -#endif - EXPECT_EQ(kExpectedChecksum, BitmapChecksum()); + static constexpr char kExpected[] = + "DrawPath fill=0xffffffff stroke=0xffffffff rule=even-odd " + "stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "points=[move(0.0000,0.0000) line(0.0000,298.0000) " + "line(418.0000,298.0000) line(418.0000,0.0000) " + "line(0.0000,0.0000,close)]\n" + "FillRect [0,0,4,298] color=0xff000000\n" + "FillRect [15,0,19,298] color=0xff000000\n" + "FillRect [22,0,26,298] color=0xff000000\n" + "FillRect [26,0,30,298] color=0xff000000\n" + "FillRect [30,0,34,298] color=0xff000000\n" + "FillRect [38,0,42,298] color=0xff000000\n" + "FillRect [41,0,45,298] color=0xff000000\n" + "FillRect [45,0,49,298] color=0xff000000\n" + "FillRect [53,0,57,298] color=0xff000000\n" + "FillRect [60,0,64,298] color=0xff000000\n" + "FillRect [64,0,68,298] color=0xff000000\n" + "FillRect [68,0,72,298] color=0xff000000\n" + "FillRect [75,0,79,298] color=0xff000000\n" + "FillRect [79,0,83,298] color=0xff000000\n" + "FillRect [83,0,87,298] color=0xff000000\n" + "FillRect [90,0,94,298] color=0xff000000\n" + "FillRect [105,0,109,298] color=0xff000000\n" + "FillRect [113,0,117,298] color=0xff000000\n" + "FillRect [120,0,124,298] color=0xff000000\n" + "FillRect [128,0,132,298] color=0xff000000\n" + "FillRect [132,0,136,298] color=0xff000000\n" + "FillRect [135,0,139,298] color=0xff000000\n" + "FillRect [143,0,147,298] color=0xff000000\n" + "FillRect [151,0,155,298] color=0xff000000\n" + "FillRect [166,0,170,298] color=0xff000000\n" + "FillRect [169,0,173,298] color=0xff000000\n" + "FillRect [173,0,177,298] color=0xff000000\n" + "FillRect [181,0,185,298] color=0xff000000\n" + "FillRect [184,0,188,298] color=0xff000000\n" + "FillRect [188,0,192,298] color=0xff000000\n" + "FillRect [196,0,200,298] color=0xff000000\n" + "FillRect [203,0,207,298] color=0xff000000\n" + "FillRect [218,0,222,298] color=0xff000000\n" + "FillRect [226,0,230,298] color=0xff000000\n" + "FillRect [230,0,234,298] color=0xff000000\n" + "FillRect [233,0,237,298] color=0xff000000\n" + "FillRect [241,0,245,298] color=0xff000000\n" + "FillRect [245,0,249,298] color=0xff000000\n" + "FillRect [248,0,252,298] color=0xff000000\n" + "FillRect [256,0,260,298] color=0xff000000\n" + "FillRect [260,0,264,298] color=0xff000000\n" + "FillRect [263,0,267,298] color=0xff000000\n" + "FillRect [271,0,275,298] color=0xff000000\n" + "FillRect [279,0,283,298] color=0xff000000\n" + "FillRect [294,0,298,298] color=0xff000000\n" + "FillRect [301,0,305,298] color=0xff000000\n" + "FillRect [309,0,313,298] color=0xff000000\n" + "FillRect [312,0,316,298] color=0xff000000\n" + "FillRect [316,0,320,298] color=0xff000000\n" + "FillRect [324,0,328,298] color=0xff000000\n" + "FillRect [331,0,335,298] color=0xff000000\n" + "FillRect [335,0,339,298] color=0xff000000\n" + "FillRect [339,0,343,298] color=0xff000000\n" + "FillRect [354,0,358,298] color=0xff000000\n" + "FillRect [361,0,365,298] color=0xff000000\n" + "FillRect [376,0,380,298] color=0xff000000\n" + "FillRect [384,0,388,298] color=0xff000000\n" + "FillRect [388,0,392,298] color=0xff000000\n" + "FillRect [392,0,396,298] color=0xff000000\n" + "FillRect [399,0,403,298] color=0xff000000\n" + "FillRect [403,0,407,298] color=0xff000000\n" + "FillRect [407,0,411,298] color=0xff000000\n" + "FillRect [414,0,418,298] color=0xff000000\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(BarcodeTest, CodaBar) { Create(BC_TYPE::kCodabar); EXPECT_TRUE(barcode()->Encode(L"$123-456")); RenderDevice(); -#if defined(PDF_USE_SKIA) - static constexpr char kExpectedChecksum[] = - "5f229b391517f1140b95770a57e31990"; -#else - static constexpr char kExpectedChecksum[] = - "5fad4fc19f099001a0fe83c89430c977"; -#endif - EXPECT_EQ(kExpectedChecksum, BitmapChecksum()); + static constexpr char kExpected[] = + "DrawPath fill=0xffffffff stroke=0xffffffff rule=even-odd " + "stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "points=[move(0.0000,0.0000) line(0.0000,298.0000) " + "line(418.0000,298.0000) line(418.0000,0.0000) " + "line(0.0000,0.0000,close)]\n" + "FillRect [0,0,5,298] color=0xff000000\n" + "FillRect [8,0,13,298] color=0xff000000\n" + "FillRect [12,0,17,298] color=0xff000000\n" + "FillRect [24,0,29,298] color=0xff000000\n" + "FillRect [37,0,42,298] color=0xff000000\n" + "FillRect [45,0,50,298] color=0xff000000\n" + "FillRect [53,0,58,298] color=0xff000000\n" + "FillRect [58,0,63,298] color=0xff000000\n" + "FillRect [70,0,75,298] color=0xff000000\n" + "FillRect [78,0,83,298] color=0xff000000\n" + "FillRect [86,0,91,298] color=0xff000000\n" + "FillRect [95,0,100,298] color=0xff000000\n" + "FillRect [103,0,108,298] color=0xff000000\n" + "FillRect [107,0,112,298] color=0xff000000\n" + "FillRect [120,0,125,298] color=0xff000000\n" + "FillRect [128,0,133,298] color=0xff000000\n" + "FillRect [136,0,141,298] color=0xff000000\n" + "FillRect [149,0,154,298] color=0xff000000\n" + "FillRect [157,0,162,298] color=0xff000000\n" + "FillRect [161,0,166,298] color=0xff000000\n" + "FillRect [169,0,174,298] color=0xff000000\n" + "FillRect [173,0,178,298] color=0xff000000\n" + "FillRect [186,0,191,298] color=0xff000000\n" + "FillRect [194,0,199,298] color=0xff000000\n" + "FillRect [202,0,207,298] color=0xff000000\n" + "FillRect [211,0,216,298] color=0xff000000\n" + "FillRect [219,0,224,298] color=0xff000000\n" + "FillRect [231,0,236,298] color=0xff000000\n" + "FillRect [235,0,240,298] color=0xff000000\n" + "FillRect [244,0,249,298] color=0xff000000\n" + "FillRect [252,0,257,298] color=0xff000000\n" + "FillRect [260,0,265,298] color=0xff000000\n" + "FillRect [264,0,269,298] color=0xff000000\n" + "FillRect [273,0,278,298] color=0xff000000\n" + "FillRect [285,0,290,298] color=0xff000000\n" + "FillRect [293,0,298,298] color=0xff000000\n" + "FillRect [298,0,303,298] color=0xff000000\n" + "FillRect [306,0,311,298] color=0xff000000\n" + "FillRect [314,0,319,298] color=0xff000000\n" + "FillRect [327,0,332,298] color=0xff000000\n" + "FillRect [335,0,340,298] color=0xff000000\n" + "FillRect [347,0,352,298] color=0xff000000\n" + "FillRect [355,0,360,298] color=0xff000000\n" + "FillRect [364,0,369,298] color=0xff000000\n" + "FillRect [368,0,373,298] color=0xff000000\n" + "FillRect [376,0,381,298] color=0xff000000\n" + "FillRect [389,0,394,298] color=0xff000000\n" + "FillRect [401,0,406,298] color=0xff000000\n" + "FillRect [409,0,414,298] color=0xff000000\n" + "FillRect [413,0,418,298] color=0xff000000\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(BarcodeTest, CodaBarLetters) { @@ -101,70 +202,266 @@ TEST_F(BarcodeTest, Code128) { Create(BC_TYPE::kCode128); EXPECT_TRUE(barcode()->Encode(L"Clams")); RenderDevice(); -#if defined(PDF_USE_SKIA) - static constexpr char kExpectedChecksum[] = - "a33a5f68755842561064e4f57fcab06b"; -#else - static constexpr char kExpectedChecksum[] = - "6351f0f6e997050e4658bbb4777aef74"; -#endif - EXPECT_EQ(kExpectedChecksum, BitmapChecksum()); + static constexpr char kExpected[] = + "DrawPath fill=0xffffffff stroke=0xffffffff rule=even-odd " + "stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "points=[move(0.0000,0.0000) line(0.0000,298.0000) " + "line(418.0000,298.0000) line(418.0000,0.0000) " + "line(0.0000,0.0000,close)]\n" + "FillRect [0,0,5,298] color=0xff000000\n" + "FillRect [4,0,9,298] color=0xff000000\n" + "FillRect [14,0,19,298] color=0xff000000\n" + "FillRect [28,0,33,298] color=0xff000000\n" + "FillRect [51,0,56,298] color=0xff000000\n" + "FillRect [69,0,74,298] color=0xff000000\n" + "FillRect [88,0,93,298] color=0xff000000\n" + "FillRect [93,0,98,298] color=0xff000000\n" + "FillRect [102,0,107,298] color=0xff000000\n" + "FillRect [107,0,112,298] color=0xff000000\n" + "FillRect [121,0,126,298] color=0xff000000\n" + "FillRect [130,0,135,298] color=0xff000000\n" + "FillRect [153,0,158,298] color=0xff000000\n" + "FillRect [167,0,172,298] color=0xff000000\n" + "FillRect [176,0,181,298] color=0xff000000\n" + "FillRect [181,0,186,298] color=0xff000000\n" + "FillRect [204,0,209,298] color=0xff000000\n" + "FillRect [209,0,214,298] color=0xff000000\n" + "FillRect [213,0,218,298] color=0xff000000\n" + "FillRect [218,0,223,298] color=0xff000000\n" + "FillRect [227,0,232,298] color=0xff000000\n" + "FillRect [232,0,237,298] color=0xff000000\n" + "FillRect [237,0,242,298] color=0xff000000\n" + "FillRect [246,0,251,298] color=0xff000000\n" + "FillRect [255,0,260,298] color=0xff000000\n" + "FillRect [265,0,270,298] color=0xff000000\n" + "FillRect [269,0,274,298] color=0xff000000\n" + "FillRect [274,0,279,298] color=0xff000000\n" + "FillRect [278,0,283,298] color=0xff000000\n" + "FillRect [292,0,297,298] color=0xff000000\n" + "FillRect [306,0,311,298] color=0xff000000\n" + "FillRect [311,0,316,298] color=0xff000000\n" + "FillRect [325,0,330,298] color=0xff000000\n" + "FillRect [334,0,339,298] color=0xff000000\n" + "FillRect [357,0,362,298] color=0xff000000\n" + "FillRect [362,0,367,298] color=0xff000000\n" + "FillRect [381,0,386,298] color=0xff000000\n" + "FillRect [385,0,390,298] color=0xff000000\n" + "FillRect [390,0,395,298] color=0xff000000\n" + "FillRect [399,0,404,298] color=0xff000000\n" + "FillRect [409,0,414,298] color=0xff000000\n" + "FillRect [413,0,418,298] color=0xff000000\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(BarcodeTest, Code128B) { Create(BC_TYPE::kCode128B); EXPECT_TRUE(barcode()->Encode(L"Clams")); RenderDevice(); -#if defined(PDF_USE_SKIA) - static constexpr char kExpectedChecksum[] = - "a33a5f68755842561064e4f57fcab06b"; -#else - static constexpr char kExpectedChecksum[] = - "6351f0f6e997050e4658bbb4777aef74"; -#endif - EXPECT_EQ(kExpectedChecksum, BitmapChecksum()); + static constexpr char kExpected[] = + "DrawPath fill=0xffffffff stroke=0xffffffff rule=even-odd " + "stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "points=[move(0.0000,0.0000) line(0.0000,298.0000) " + "line(418.0000,298.0000) line(418.0000,0.0000) " + "line(0.0000,0.0000,close)]\n" + "FillRect [0,0,5,298] color=0xff000000\n" + "FillRect [4,0,9,298] color=0xff000000\n" + "FillRect [14,0,19,298] color=0xff000000\n" + "FillRect [28,0,33,298] color=0xff000000\n" + "FillRect [51,0,56,298] color=0xff000000\n" + "FillRect [69,0,74,298] color=0xff000000\n" + "FillRect [88,0,93,298] color=0xff000000\n" + "FillRect [93,0,98,298] color=0xff000000\n" + "FillRect [102,0,107,298] color=0xff000000\n" + "FillRect [107,0,112,298] color=0xff000000\n" + "FillRect [121,0,126,298] color=0xff000000\n" + "FillRect [130,0,135,298] color=0xff000000\n" + "FillRect [153,0,158,298] color=0xff000000\n" + "FillRect [167,0,172,298] color=0xff000000\n" + "FillRect [176,0,181,298] color=0xff000000\n" + "FillRect [181,0,186,298] color=0xff000000\n" + "FillRect [204,0,209,298] color=0xff000000\n" + "FillRect [209,0,214,298] color=0xff000000\n" + "FillRect [213,0,218,298] color=0xff000000\n" + "FillRect [218,0,223,298] color=0xff000000\n" + "FillRect [227,0,232,298] color=0xff000000\n" + "FillRect [232,0,237,298] color=0xff000000\n" + "FillRect [237,0,242,298] color=0xff000000\n" + "FillRect [246,0,251,298] color=0xff000000\n" + "FillRect [255,0,260,298] color=0xff000000\n" + "FillRect [265,0,270,298] color=0xff000000\n" + "FillRect [269,0,274,298] color=0xff000000\n" + "FillRect [274,0,279,298] color=0xff000000\n" + "FillRect [278,0,283,298] color=0xff000000\n" + "FillRect [292,0,297,298] color=0xff000000\n" + "FillRect [306,0,311,298] color=0xff000000\n" + "FillRect [311,0,316,298] color=0xff000000\n" + "FillRect [325,0,330,298] color=0xff000000\n" + "FillRect [334,0,339,298] color=0xff000000\n" + "FillRect [357,0,362,298] color=0xff000000\n" + "FillRect [362,0,367,298] color=0xff000000\n" + "FillRect [381,0,386,298] color=0xff000000\n" + "FillRect [385,0,390,298] color=0xff000000\n" + "FillRect [390,0,395,298] color=0xff000000\n" + "FillRect [399,0,404,298] color=0xff000000\n" + "FillRect [409,0,414,298] color=0xff000000\n" + "FillRect [413,0,418,298] color=0xff000000\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(BarcodeTest, Code128C) { Create(BC_TYPE::kCode128C); EXPECT_TRUE(barcode()->Encode(L"123456")); RenderDevice(); -#if defined(PDF_USE_SKIA) - static constexpr char kExpectedChecksum[] = - "4e599185bfb9625664756e5009468c8e"; -#else - static constexpr char kExpectedChecksum[] = - "fba730a807ba6363f9bd2bc7f8c56d1f"; -#endif - EXPECT_EQ(kExpectedChecksum, BitmapChecksum()); + static constexpr char kExpected[] = + "DrawPath fill=0xffffffff stroke=0xffffffff rule=even-odd " + "stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "points=[move(0.0000,0.0000) line(0.0000,298.0000) " + "line(418.0000,298.0000) line(418.0000,0.0000) " + "line(0.0000,0.0000,close)]\n" + "FillRect [0,0,7,298] color=0xff000000\n" + "FillRect [6,0,13,298] color=0xff000000\n" + "FillRect [18,0,25,298] color=0xff000000\n" + "FillRect [36,0,43,298] color=0xff000000\n" + "FillRect [43,0,50,298] color=0xff000000\n" + "FillRect [49,0,56,298] color=0xff000000\n" + "FillRect [67,0,74,298] color=0xff000000\n" + "FillRect [79,0,86,298] color=0xff000000\n" + "FillRect [86,0,93,298] color=0xff000000\n" + "FillRect [104,0,111,298] color=0xff000000\n" + "FillRect [110,0,117,298] color=0xff000000\n" + "FillRect [116,0,123,298] color=0xff000000\n" + "FillRect [135,0,142,298] color=0xff000000\n" + "FillRect [159,0,166,298] color=0xff000000\n" + "FillRect [172,0,179,298] color=0xff000000\n" + "FillRect [178,0,185,298] color=0xff000000\n" + "FillRect [202,0,209,298] color=0xff000000\n" + "FillRect [209,0,216,298] color=0xff000000\n" + "FillRect [215,0,222,298] color=0xff000000\n" + "FillRect [239,0,246,298] color=0xff000000\n" + "FillRect [252,0,259,298] color=0xff000000\n" + "FillRect [258,0,265,298] color=0xff000000\n" + "FillRect [270,0,277,298] color=0xff000000\n" + "FillRect [295,0,302,298] color=0xff000000\n" + "FillRect [301,0,308,298] color=0xff000000\n" + "FillRect [313,0,320,298] color=0xff000000\n" + "FillRect [319,0,326,298] color=0xff000000\n" + "FillRect [325,0,332,298] color=0xff000000\n" + "FillRect [338,0,345,298] color=0xff000000\n" + "FillRect [344,0,351,298] color=0xff000000\n" + "FillRect [368,0,375,298] color=0xff000000\n" + "FillRect [375,0,382,298] color=0xff000000\n" + "FillRect [381,0,388,298] color=0xff000000\n" + "FillRect [393,0,400,298] color=0xff000000\n" + "FillRect [405,0,412,298] color=0xff000000\n" + "FillRect [411,0,418,298] color=0xff000000\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(BarcodeTest, Code128CLetters) { Create(BC_TYPE::kCode128C); EXPECT_TRUE(barcode()->Encode(L"clams")); RenderDevice(); -#if defined(PDF_USE_SKIA) - static constexpr char kExpectedChecksum[] = - "8276a6082d77c3db7abd8bc8850e8467"; -#else - static constexpr char kExpectedChecksum[] = - "6284ec8503d5a948c9518108da33cdd3"; -#endif - EXPECT_EQ(kExpectedChecksum, BitmapChecksum()); + static constexpr char kExpected[] = + "DrawPath fill=0xffffffff stroke=0xffffffff rule=even-odd " + "stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "points=[move(0.0000,0.0000) line(0.0000,298.0000) " + "line(418.0000,298.0000) line(418.0000,0.0000) " + "line(0.0000,0.0000,close)]\n" + "FillRect [0,0,7,298] color=0xff000000\n" + "FillRect [6,0,13,298] color=0xff000000\n" + "FillRect [18,0,25,298] color=0xff000000\n" + "FillRect [36,0,43,298] color=0xff000000\n" + "FillRect [43,0,50,298] color=0xff000000\n" + "FillRect [49,0,56,298] color=0xff000000\n" + "FillRect [67,0,74,298] color=0xff000000\n" + "FillRect [79,0,86,298] color=0xff000000\n" + "FillRect [86,0,93,298] color=0xff000000\n" + "FillRect [92,0,99,298] color=0xff000000\n" + "FillRect [104,0,111,298] color=0xff000000\n" + "FillRect [110,0,117,298] color=0xff000000\n" + "FillRect [116,0,123,298] color=0xff000000\n" + "FillRect [123,0,130,298] color=0xff000000\n" + "FillRect [135,0,142,298] color=0xff000000\n" + "FillRect [141,0,148,298] color=0xff000000\n" + "FillRect [147,0,154,298] color=0xff000000\n" + "FillRect [153,0,160,298] color=0xff000000\n" + "FillRect [166,0,173,298] color=0xff000000\n" + "FillRect [178,0,185,298] color=0xff000000\n" + "FillRect [202,0,209,298] color=0xff000000\n" + "FillRect [209,0,216,298] color=0xff000000\n" + "FillRect [221,0,228,298] color=0xff000000\n" + "FillRect [227,0,234,298] color=0xff000000\n" + "FillRect [245,0,252,298] color=0xff000000\n" + "FillRect [252,0,259,298] color=0xff000000\n" + "FillRect [270,0,277,298] color=0xff000000\n" + "FillRect [276,0,283,298] color=0xff000000\n" + "FillRect [288,0,295,298] color=0xff000000\n" + "FillRect [295,0,302,298] color=0xff000000\n" + "FillRect [307,0,314,298] color=0xff000000\n" + "FillRect [313,0,320,298] color=0xff000000\n" + "FillRect [319,0,326,298] color=0xff000000\n" + "FillRect [325,0,332,298] color=0xff000000\n" + "FillRect [338,0,345,298] color=0xff000000\n" + "FillRect [344,0,351,298] color=0xff000000\n" + "FillRect [368,0,375,298] color=0xff000000\n" + "FillRect [375,0,382,298] color=0xff000000\n" + "FillRect [381,0,388,298] color=0xff000000\n" + "FillRect [393,0,400,298] color=0xff000000\n" + "FillRect [405,0,412,298] color=0xff000000\n" + "FillRect [411,0,418,298] color=0xff000000\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(BarcodeTest, Ean8) { Create(BC_TYPE::kEAN8); EXPECT_TRUE(barcode()->Encode(L"123456")); RenderDevice(); -#if defined(PDF_USE_SKIA) - static constexpr char kExpectedChecksum[] = - "a8969be3f36f6f4b155d58f8171d7827"; -#else - static constexpr char kExpectedChecksum[] = - "aff88491ac46ca6217d780d185300cde"; -#endif - EXPECT_EQ(kExpectedChecksum, BitmapChecksum()); + static constexpr char kExpected[] = + "DrawPath fill=0xffffffff stroke=0xffffffff rule=even-odd " + "stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "points=[move(0.0000,0.0000) line(0.0000,298.0000) " + "line(418.0000,298.0000) line(418.0000,0.0000) " + "line(0.0000,0.0000,close)]\n" + "FillRect [0,0,7,298] color=0xff000000\n" + "FillRect [12,0,19,298] color=0xff000000\n" + "FillRect [37,0,44,298] color=0xff000000\n" + "FillRect [43,0,50,298] color=0xff000000\n" + "FillRect [56,0,63,298] color=0xff000000\n" + "FillRect [74,0,81,298] color=0xff000000\n" + "FillRect [81,0,88,298] color=0xff000000\n" + "FillRect [99,0,106,298] color=0xff000000\n" + "FillRect [118,0,125,298] color=0xff000000\n" + "FillRect [137,0,144,298] color=0xff000000\n" + "FillRect [143,0,150,298] color=0xff000000\n" + "FillRect [156,0,163,298] color=0xff000000\n" + "FillRect [162,0,169,298] color=0xff000000\n" + "FillRect [168,0,175,298] color=0xff000000\n" + "FillRect [174,0,181,298] color=0xff000000\n" + "FillRect [187,0,194,298] color=0xff000000\n" + "FillRect [199,0,206,298] color=0xff000000\n" + "FillRect [212,0,219,298] color=0xff000000\n" + "FillRect [224,0,231,298] color=0xff000000\n" + "FillRect [237,0,244,298] color=0xff000000\n" + "FillRect [243,0,250,298] color=0xff000000\n" + "FillRect [249,0,256,298] color=0xff000000\n" + "FillRect [268,0,275,298] color=0xff000000\n" + "FillRect [287,0,294,298] color=0xff000000\n" + "FillRect [293,0,300,298] color=0xff000000\n" + "FillRect [299,0,306,298] color=0xff000000\n" + "FillRect [312,0,319,298] color=0xff000000\n" + "FillRect [324,0,331,298] color=0xff000000\n" + "FillRect [355,0,362,298] color=0xff000000\n" + "FillRect [374,0,381,298] color=0xff000000\n" + "FillRect [380,0,387,298] color=0xff000000\n" + "FillRect [386,0,393,298] color=0xff000000\n" + "FillRect [399,0,406,298] color=0xff000000\n" + "FillRect [411,0,418,298] color=0xff000000\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(BarcodeTest, Ean8Letters) { @@ -176,14 +473,58 @@ TEST_F(BarcodeTest, UPCA) { Create(BC_TYPE::kUPCA); EXPECT_TRUE(barcode()->Encode(L"123456")); RenderDevice(); -#if defined(PDF_USE_SKIA) - static constexpr char kExpectedChecksum[] = - "d9004b9e6feef54c91a6403a718bbe06"; -#else - static constexpr char kExpectedChecksum[] = - "fe26a5714cff7ffe3f9b02183efc435b"; -#endif - EXPECT_EQ(kExpectedChecksum, BitmapChecksum()); + static constexpr char kExpected[] = + "DrawPath fill=0xffffffff stroke=0xffffffff rule=even-odd " + "stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "points=[move(0.0000,0.0000) line(0.0000,298.0000) " + "line(418.0000,298.0000) line(418.0000,0.0000) " + "line(0.0000,0.0000,close)]\n" + "FillRect [27,0,31,298] color=0xff000000\n" + "FillRect [34,0,38,298] color=0xff000000\n" + "FillRect [50,0,54,298] color=0xff000000\n" + "FillRect [54,0,58,298] color=0xff000000\n" + "FillRect [61,0,65,298] color=0xff000000\n" + "FillRect [77,0,81,298] color=0xff000000\n" + "FillRect [80,0,84,298] color=0xff000000\n" + "FillRect [88,0,92,298] color=0xff000000\n" + "FillRect [103,0,107,298] color=0xff000000\n" + "FillRect [107,0,111,298] color=0xff000000\n" + "FillRect [115,0,119,298] color=0xff000000\n" + "FillRect [130,0,134,298] color=0xff000000\n" + "FillRect [134,0,138,298] color=0xff000000\n" + "FillRect [142,0,146,298] color=0xff000000\n" + "FillRect [157,0,161,298] color=0xff000000\n" + "FillRect [161,0,165,298] color=0xff000000\n" + "FillRect [169,0,173,298] color=0xff000000\n" + "FillRect [180,0,184,298] color=0xff000000\n" + "FillRect [184,0,188,298] color=0xff000000\n" + "FillRect [195,0,199,298] color=0xff000000\n" + "FillRect [203,0,207,298] color=0xff000000\n" + "FillRect [211,0,215,298] color=0xff000000\n" + "FillRect [219,0,223,298] color=0xff000000\n" + "FillRect [222,0,226,298] color=0xff000000\n" + "FillRect [230,0,234,298] color=0xff000000\n" + "FillRect [234,0,238,298] color=0xff000000\n" + "FillRect [245,0,249,298] color=0xff000000\n" + "FillRect [265,0,269,298] color=0xff000000\n" + "FillRect [272,0,276,298] color=0xff000000\n" + "FillRect [280,0,284,298] color=0xff000000\n" + "FillRect [284,0,288,298] color=0xff000000\n" + "FillRect [288,0,292,298] color=0xff000000\n" + "FillRect [299,0,303,298] color=0xff000000\n" + "FillRect [311,0,315,298] color=0xff000000\n" + "FillRect [314,0,318,298] color=0xff000000\n" + "FillRect [318,0,322,298] color=0xff000000\n" + "FillRect [326,0,330,298] color=0xff000000\n" + "FillRect [334,0,338,298] color=0xff000000\n" + "FillRect [353,0,357,298] color=0xff000000\n" + "FillRect [364,0,368,298] color=0xff000000\n" + "FillRect [368,0,372,298] color=0xff000000\n" + "FillRect [372,0,376,298] color=0xff000000\n" + "FillRect [380,0,384,298] color=0xff000000\n" + "FillRect [387,0,391,298] color=0xff000000\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(BarcodeTest, UPCALetters) { @@ -195,14 +536,58 @@ TEST_F(BarcodeTest, Ean13) { Create(BC_TYPE::kEAN13); EXPECT_TRUE(barcode()->Encode(L"123456")); RenderDevice(); -#if defined(PDF_USE_SKIA) - static constexpr char kExpectedChecksum[] = - "efc7a49c967901efa6f63c59a10fedab"; -#else - static constexpr char kExpectedChecksum[] = - "72d2190b98d635c32834bf67552e561e"; -#endif - EXPECT_EQ(kExpectedChecksum, BitmapChecksum()); + static constexpr char kExpected[] = + "DrawPath fill=0xffffffff stroke=0xffffffff rule=even-odd " + "stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "points=[move(0.0000,0.0000) line(0.0000,298.0000) " + "line(418.0000,298.0000) line(418.0000,0.0000) " + "line(0.0000,0.0000,close)]\n" + "FillRect [28,0,33,298] color=0xff000000\n" + "FillRect [36,0,41,298] color=0xff000000\n" + "FillRect [53,0,58,298] color=0xff000000\n" + "FillRect [57,0,62,298] color=0xff000000\n" + "FillRect [65,0,70,298] color=0xff000000\n" + "FillRect [82,0,87,298] color=0xff000000\n" + "FillRect [86,0,91,298] color=0xff000000\n" + "FillRect [94,0,99,298] color=0xff000000\n" + "FillRect [110,0,115,298] color=0xff000000\n" + "FillRect [114,0,119,298] color=0xff000000\n" + "FillRect [122,0,127,298] color=0xff000000\n" + "FillRect [139,0,144,298] color=0xff000000\n" + "FillRect [143,0,148,298] color=0xff000000\n" + "FillRect [151,0,156,298] color=0xff000000\n" + "FillRect [168,0,173,298] color=0xff000000\n" + "FillRect [172,0,177,298] color=0xff000000\n" + "FillRect [180,0,185,298] color=0xff000000\n" + "FillRect [192,0,197,298] color=0xff000000\n" + "FillRect [196,0,201,298] color=0xff000000\n" + "FillRect [209,0,214,298] color=0xff000000\n" + "FillRect [217,0,222,298] color=0xff000000\n" + "FillRect [225,0,230,298] color=0xff000000\n" + "FillRect [233,0,238,298] color=0xff000000\n" + "FillRect [237,0,242,298] color=0xff000000\n" + "FillRect [245,0,250,298] color=0xff000000\n" + "FillRect [250,0,255,298] color=0xff000000\n" + "FillRect [262,0,267,298] color=0xff000000\n" + "FillRect [282,0,287,298] color=0xff000000\n" + "FillRect [291,0,296,298] color=0xff000000\n" + "FillRect [299,0,304,298] color=0xff000000\n" + "FillRect [303,0,308,298] color=0xff000000\n" + "FillRect [307,0,312,298] color=0xff000000\n" + "FillRect [319,0,324,298] color=0xff000000\n" + "FillRect [331,0,336,298] color=0xff000000\n" + "FillRect [336,0,341,298] color=0xff000000\n" + "FillRect [340,0,345,298] color=0xff000000\n" + "FillRect [348,0,353,298] color=0xff000000\n" + "FillRect [356,0,361,298] color=0xff000000\n" + "FillRect [377,0,382,298] color=0xff000000\n" + "FillRect [389,0,394,298] color=0xff000000\n" + "FillRect [393,0,398,298] color=0xff000000\n" + "FillRect [397,0,402,298] color=0xff000000\n" + "FillRect [405,0,410,298] color=0xff000000\n" + "FillRect [413,0,418,298] color=0xff000000\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(BarcodeTest, Ean13Letters) { @@ -214,42 +599,636 @@ TEST_F(BarcodeTest, Pdf417) { Create(BC_TYPE::kPDF417); EXPECT_TRUE(barcode()->Encode(L"clams")); RenderDevice(); -#if defined(PDF_USE_SKIA) - static constexpr char kExpectedChecksum[] = - "63ee1988d3de512df2c3037d21bdf917"; -#else - static constexpr char kExpectedChecksum[] = - "191e35d11613901b7d5d51033689aa89"; -#endif - EXPECT_EQ(kExpectedChecksum, BitmapChecksum()); + static constexpr char kExpected[] = + "DrawPath fill=0xffffffff stroke=0xffffffff rule=even-odd " + "stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "points=[move(0.0000,0.0000) line(0.0000,298.0000) " + "line(418.0000,298.0000) line(418.0000,0.0000) " + "line(0.0000,0.0000,close)]\n" + "FillRect [54,44,57,86] color=0xff000000\n" + "FillRect [54,86,57,128] color=0xff000000\n" + "FillRect [54,128,57,170] color=0xff000000\n" + "FillRect [54,170,57,212] color=0xff000000\n" + "FillRect [54,212,57,254] color=0xff000000\n" + "FillRect [57,44,60,86] color=0xff000000\n" + "FillRect [57,86,60,128] color=0xff000000\n" + "FillRect [57,128,60,170] color=0xff000000\n" + "FillRect [57,170,60,212] color=0xff000000\n" + "FillRect [57,212,60,254] color=0xff000000\n" + "FillRect [60,44,63,86] color=0xff000000\n" + "FillRect [60,86,63,128] color=0xff000000\n" + "FillRect [60,128,63,170] color=0xff000000\n" + "FillRect [60,170,63,212] color=0xff000000\n" + "FillRect [60,212,63,254] color=0xff000000\n" + "FillRect [63,44,66,86] color=0xff000000\n" + "FillRect [63,86,66,128] color=0xff000000\n" + "FillRect [63,128,66,170] color=0xff000000\n" + "FillRect [63,170,66,212] color=0xff000000\n" + "FillRect [63,212,66,254] color=0xff000000\n" + "FillRect [66,44,69,86] color=0xff000000\n" + "FillRect [66,86,69,128] color=0xff000000\n" + "FillRect [66,128,69,170] color=0xff000000\n" + "FillRect [66,170,69,212] color=0xff000000\n" + "FillRect [66,212,69,254] color=0xff000000\n" + "FillRect [69,44,72,86] color=0xff000000\n" + "FillRect [69,86,72,128] color=0xff000000\n" + "FillRect [69,128,72,170] color=0xff000000\n" + "FillRect [69,170,72,212] color=0xff000000\n" + "FillRect [69,212,72,254] color=0xff000000\n" + "FillRect [72,44,75,86] color=0xff000000\n" + "FillRect [72,86,75,128] color=0xff000000\n" + "FillRect [72,128,75,170] color=0xff000000\n" + "FillRect [72,170,75,212] color=0xff000000\n" + "FillRect [72,212,75,254] color=0xff000000\n" + "FillRect [75,44,78,86] color=0xff000000\n" + "FillRect [75,86,78,128] color=0xff000000\n" + "FillRect [75,128,78,170] color=0xff000000\n" + "FillRect [75,170,78,212] color=0xff000000\n" + "FillRect [75,212,78,254] color=0xff000000\n" + "FillRect [81,44,84,86] color=0xff000000\n" + "FillRect [81,86,84,128] color=0xff000000\n" + "FillRect [81,128,84,170] color=0xff000000\n" + "FillRect [81,170,84,212] color=0xff000000\n" + "FillRect [81,212,84,254] color=0xff000000\n" + "FillRect [87,44,90,86] color=0xff000000\n" + "FillRect [87,86,90,128] color=0xff000000\n" + "FillRect [87,128,90,170] color=0xff000000\n" + "FillRect [87,170,90,212] color=0xff000000\n" + "FillRect [87,212,90,254] color=0xff000000\n" + "FillRect [93,44,96,86] color=0xff000000\n" + "FillRect [93,86,96,128] color=0xff000000\n" + "FillRect [93,128,96,170] color=0xff000000\n" + "FillRect [93,170,96,212] color=0xff000000\n" + "FillRect [93,212,96,254] color=0xff000000\n" + "FillRect [105,44,108,86] color=0xff000000\n" + "FillRect [105,86,108,128] color=0xff000000\n" + "FillRect [105,128,108,170] color=0xff000000\n" + "FillRect [105,170,108,212] color=0xff000000\n" + "FillRect [105,212,108,254] color=0xff000000\n" + "FillRect [108,44,111,86] color=0xff000000\n" + "FillRect [108,86,111,128] color=0xff000000\n" + "FillRect [108,128,111,170] color=0xff000000\n" + "FillRect [108,212,111,254] color=0xff000000\n" + "FillRect [111,44,114,86] color=0xff000000\n" + "FillRect [111,86,114,128] color=0xff000000\n" + "FillRect [111,128,114,170] color=0xff000000\n" + "FillRect [111,170,114,212] color=0xff000000\n" + "FillRect [111,212,114,254] color=0xff000000\n" + "FillRect [114,44,117,86] color=0xff000000\n" + "FillRect [114,86,117,128] color=0xff000000\n" + "FillRect [117,86,120,128] color=0xff000000\n" + "FillRect [117,128,120,170] color=0xff000000\n" + "FillRect [117,170,120,212] color=0xff000000\n" + "FillRect [117,212,120,254] color=0xff000000\n" + "FillRect [120,44,123,86] color=0xff000000\n" + "FillRect [120,86,123,128] color=0xff000000\n" + "FillRect [120,170,123,212] color=0xff000000\n" + "FillRect [123,128,126,170] color=0xff000000\n" + "FillRect [123,170,126,212] color=0xff000000\n" + "FillRect [123,212,126,254] color=0xff000000\n" + "FillRect [126,44,129,86] color=0xff000000\n" + "FillRect [126,86,129,128] color=0xff000000\n" + "FillRect [126,170,129,212] color=0xff000000\n" + "FillRect [126,212,129,254] color=0xff000000\n" + "FillRect [129,128,132,170] color=0xff000000\n" + "FillRect [129,212,132,254] color=0xff000000\n" + "FillRect [132,44,135,86] color=0xff000000\n" + "FillRect [132,86,135,128] color=0xff000000\n" + "FillRect [132,128,135,170] color=0xff000000\n" + "FillRect [135,44,138,86] color=0xff000000\n" + "FillRect [135,128,138,170] color=0xff000000\n" + "FillRect [135,170,138,212] color=0xff000000\n" + "FillRect [138,44,141,86] color=0xff000000\n" + "FillRect [138,128,141,170] color=0xff000000\n" + "FillRect [138,170,141,212] color=0xff000000\n" + "FillRect [141,44,144,86] color=0xff000000\n" + "FillRect [141,86,144,128] color=0xff000000\n" + "FillRect [141,128,144,170] color=0xff000000\n" + "FillRect [141,170,144,212] color=0xff000000\n" + "FillRect [141,212,144,254] color=0xff000000\n" + "FillRect [144,86,147,128] color=0xff000000\n" + "FillRect [144,128,147,170] color=0xff000000\n" + "FillRect [144,170,147,212] color=0xff000000\n" + "FillRect [144,212,147,254] color=0xff000000\n" + "FillRect [147,86,150,128] color=0xff000000\n" + "FillRect [156,44,159,86] color=0xff000000\n" + "FillRect [156,86,159,128] color=0xff000000\n" + "FillRect [156,128,159,170] color=0xff000000\n" + "FillRect [156,170,159,212] color=0xff000000\n" + "FillRect [156,212,159,254] color=0xff000000\n" + "FillRect [159,44,162,86] color=0xff000000\n" + "FillRect [159,170,162,212] color=0xff000000\n" + "FillRect [165,44,168,86] color=0xff000000\n" + "FillRect [165,128,168,170] color=0xff000000\n" + "FillRect [165,170,168,212] color=0xff000000\n" + "FillRect [168,128,171,170] color=0xff000000\n" + "FillRect [168,170,171,212] color=0xff000000\n" + "FillRect [168,212,171,254] color=0xff000000\n" + "FillRect [171,44,174,86] color=0xff000000\n" + "FillRect [174,86,177,128] color=0xff000000\n" + "FillRect [174,170,177,212] color=0xff000000\n" + "FillRect [174,212,177,254] color=0xff000000\n" + "FillRect [177,128,180,170] color=0xff000000\n" + "FillRect [177,212,180,254] color=0xff000000\n" + "FillRect [180,86,183,128] color=0xff000000\n" + "FillRect [180,212,183,254] color=0xff000000\n" + "FillRect [183,44,186,86] color=0xff000000\n" + "FillRect [183,86,186,128] color=0xff000000\n" + "FillRect [183,212,186,254] color=0xff000000\n" + "FillRect [186,44,189,86] color=0xff000000\n" + "FillRect [186,86,189,128] color=0xff000000\n" + "FillRect [186,212,189,254] color=0xff000000\n" + "FillRect [189,86,192,128] color=0xff000000\n" + "FillRect [192,170,195,212] color=0xff000000\n" + "FillRect [195,86,198,128] color=0xff000000\n" + "FillRect [195,128,198,170] color=0xff000000\n" + "FillRect [195,212,198,254] color=0xff000000\n" + "FillRect [198,128,201,170] color=0xff000000\n" + "FillRect [198,212,201,254] color=0xff000000\n" + "FillRect [201,128,204,170] color=0xff000000\n" + "FillRect [207,44,210,86] color=0xff000000\n" + "FillRect [207,86,210,128] color=0xff000000\n" + "FillRect [207,128,210,170] color=0xff000000\n" + "FillRect [207,170,210,212] color=0xff000000\n" + "FillRect [207,212,210,254] color=0xff000000\n" + "FillRect [210,128,213,170] color=0xff000000\n" + "FillRect [210,170,213,212] color=0xff000000\n" + "FillRect [210,212,213,254] color=0xff000000\n" + "FillRect [213,170,216,212] color=0xff000000\n" + "FillRect [213,212,216,254] color=0xff000000\n" + "FillRect [216,86,219,128] color=0xff000000\n" + "FillRect [216,170,219,212] color=0xff000000\n" + "FillRect [216,212,219,254] color=0xff000000\n" + "FillRect [222,44,225,86] color=0xff000000\n" + "FillRect [222,128,225,170] color=0xff000000\n" + "FillRect [225,44,228,86] color=0xff000000\n" + "FillRect [225,86,228,128] color=0xff000000\n" + "FillRect [225,128,228,170] color=0xff000000\n" + "FillRect [225,170,228,212] color=0xff000000\n" + "FillRect [225,212,228,254] color=0xff000000\n" + "FillRect [228,86,231,128] color=0xff000000\n" + "FillRect [228,128,231,170] color=0xff000000\n" + "FillRect [228,170,231,212] color=0xff000000\n" + "FillRect [231,86,234,128] color=0xff000000\n" + "FillRect [231,128,234,170] color=0xff000000\n" + "FillRect [231,170,234,212] color=0xff000000\n" + "FillRect [234,86,237,128] color=0xff000000\n" + "FillRect [234,128,237,170] color=0xff000000\n" + "FillRect [237,44,240,86] color=0xff000000\n" + "FillRect [237,170,240,212] color=0xff000000\n" + "FillRect [237,212,240,254] color=0xff000000\n" + "FillRect [240,44,243,86] color=0xff000000\n" + "FillRect [243,128,246,170] color=0xff000000\n" + "FillRect [246,170,249,212] color=0xff000000\n" + "FillRect [249,44,252,86] color=0xff000000\n" + "FillRect [249,170,252,212] color=0xff000000\n" + "FillRect [252,86,255,128] color=0xff000000\n" + "FillRect [252,128,255,170] color=0xff000000\n" + "FillRect [252,212,255,254] color=0xff000000\n" + "FillRect [258,44,261,86] color=0xff000000\n" + "FillRect [258,86,261,128] color=0xff000000\n" + "FillRect [258,128,261,170] color=0xff000000\n" + "FillRect [258,170,261,212] color=0xff000000\n" + "FillRect [258,212,261,254] color=0xff000000\n" + "FillRect [261,44,264,86] color=0xff000000\n" + "FillRect [261,86,264,128] color=0xff000000\n" + "FillRect [261,128,264,170] color=0xff000000\n" + "FillRect [261,212,264,254] color=0xff000000\n" + "FillRect [264,44,267,86] color=0xff000000\n" + "FillRect [264,86,267,128] color=0xff000000\n" + "FillRect [264,128,267,170] color=0xff000000\n" + "FillRect [264,170,267,212] color=0xff000000\n" + "FillRect [264,212,267,254] color=0xff000000\n" + "FillRect [267,44,270,86] color=0xff000000\n" + "FillRect [267,86,270,128] color=0xff000000\n" + "FillRect [270,86,273,128] color=0xff000000\n" + "FillRect [270,128,273,170] color=0xff000000\n" + "FillRect [270,170,273,212] color=0xff000000\n" + "FillRect [270,212,273,254] color=0xff000000\n" + "FillRect [273,44,276,86] color=0xff000000\n" + "FillRect [273,86,276,128] color=0xff000000\n" + "FillRect [273,170,276,212] color=0xff000000\n" + "FillRect [276,128,279,170] color=0xff000000\n" + "FillRect [276,170,279,212] color=0xff000000\n" + "FillRect [276,212,279,254] color=0xff000000\n" + "FillRect [279,44,282,86] color=0xff000000\n" + "FillRect [279,86,282,128] color=0xff000000\n" + "FillRect [279,170,282,212] color=0xff000000\n" + "FillRect [279,212,282,254] color=0xff000000\n" + "FillRect [282,212,285,254] color=0xff000000\n" + "FillRect [285,44,288,86] color=0xff000000\n" + "FillRect [285,86,288,128] color=0xff000000\n" + "FillRect [285,128,288,170] color=0xff000000\n" + "FillRect [288,44,291,86] color=0xff000000\n" + "FillRect [288,128,291,170] color=0xff000000\n" + "FillRect [288,170,291,212] color=0xff000000\n" + "FillRect [291,44,294,86] color=0xff000000\n" + "FillRect [291,86,294,128] color=0xff000000\n" + "FillRect [291,128,294,170] color=0xff000000\n" + "FillRect [291,170,294,212] color=0xff000000\n" + "FillRect [291,212,294,254] color=0xff000000\n" + "FillRect [294,44,297,86] color=0xff000000\n" + "FillRect [294,86,297,128] color=0xff000000\n" + "FillRect [294,128,297,170] color=0xff000000\n" + "FillRect [294,170,297,212] color=0xff000000\n" + "FillRect [294,212,297,254] color=0xff000000\n" + "FillRect [297,86,300,128] color=0xff000000\n" + "FillRect [297,128,300,170] color=0xff000000\n" + "FillRect [297,170,300,212] color=0xff000000\n" + "FillRect [300,128,303,170] color=0xff000000\n" + "FillRect [309,44,312,86] color=0xff000000\n" + "FillRect [309,86,312,128] color=0xff000000\n" + "FillRect [309,128,312,170] color=0xff000000\n" + "FillRect [309,170,312,212] color=0xff000000\n" + "FillRect [309,212,312,254] color=0xff000000\n" + "FillRect [312,44,315,86] color=0xff000000\n" + "FillRect [312,86,315,128] color=0xff000000\n" + "FillRect [312,128,315,170] color=0xff000000\n" + "FillRect [312,170,315,212] color=0xff000000\n" + "FillRect [312,212,315,254] color=0xff000000\n" + "FillRect [315,44,318,86] color=0xff000000\n" + "FillRect [315,86,318,128] color=0xff000000\n" + "FillRect [315,128,318,170] color=0xff000000\n" + "FillRect [315,170,318,212] color=0xff000000\n" + "FillRect [315,212,318,254] color=0xff000000\n" + "FillRect [318,44,321,86] color=0xff000000\n" + "FillRect [318,86,321,128] color=0xff000000\n" + "FillRect [318,128,321,170] color=0xff000000\n" + "FillRect [318,170,321,212] color=0xff000000\n" + "FillRect [318,212,321,254] color=0xff000000\n" + "FillRect [321,44,324,86] color=0xff000000\n" + "FillRect [321,86,324,128] color=0xff000000\n" + "FillRect [321,128,324,170] color=0xff000000\n" + "FillRect [321,170,324,212] color=0xff000000\n" + "FillRect [321,212,324,254] color=0xff000000\n" + "FillRect [324,44,327,86] color=0xff000000\n" + "FillRect [324,86,327,128] color=0xff000000\n" + "FillRect [324,128,327,170] color=0xff000000\n" + "FillRect [324,170,327,212] color=0xff000000\n" + "FillRect [324,212,327,254] color=0xff000000\n" + "FillRect [327,44,330,86] color=0xff000000\n" + "FillRect [327,86,330,128] color=0xff000000\n" + "FillRect [327,128,330,170] color=0xff000000\n" + "FillRect [327,170,330,212] color=0xff000000\n" + "FillRect [327,212,330,254] color=0xff000000\n" + "FillRect [333,44,336,86] color=0xff000000\n" + "FillRect [333,86,336,128] color=0xff000000\n" + "FillRect [333,128,336,170] color=0xff000000\n" + "FillRect [333,170,336,212] color=0xff000000\n" + "FillRect [333,212,336,254] color=0xff000000\n" + "FillRect [345,44,348,86] color=0xff000000\n" + "FillRect [345,86,348,128] color=0xff000000\n" + "FillRect [345,128,348,170] color=0xff000000\n" + "FillRect [345,170,348,212] color=0xff000000\n" + "FillRect [345,212,348,254] color=0xff000000\n" + "FillRect [351,44,354,86] color=0xff000000\n" + "FillRect [351,86,354,128] color=0xff000000\n" + "FillRect [351,128,354,170] color=0xff000000\n" + "FillRect [351,170,354,212] color=0xff000000\n" + "FillRect [351,212,354,254] color=0xff000000\n" + "FillRect [360,44,363,86] color=0xff000000\n" + "FillRect [360,86,363,128] color=0xff000000\n" + "FillRect [360,128,363,170] color=0xff000000\n" + "FillRect [360,170,363,212] color=0xff000000\n" + "FillRect [360,212,363,254] color=0xff000000\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(BarcodeTest, DataMatrix) { Create(BC_TYPE::kDataMatrix); EXPECT_TRUE(barcode()->Encode(L"clams")); RenderDevice(); -#if defined(PDF_USE_SKIA) - static constexpr char kExpectedChecksum[] = - "de33aa8fe06e24b6ab191643da8dd336"; -#else - static constexpr char kExpectedChecksum[] = - "5e5cd9a680b86fcd4ffd53ed36e3c980"; -#endif - EXPECT_EQ(kExpectedChecksum, BitmapChecksum()); + static constexpr char kExpected[] = + "DrawPath fill=0xffffffff stroke=0xffffffff rule=even-odd " + "stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "points=[move(0.0000,0.0000) line(0.0000,298.0000) " + "line(418.0000,298.0000) line(418.0000,0.0000) " + "line(0.0000,0.0000,close)]\n" + "FillRect [203,143,204,144] color=0xff000000\n" + "FillRect [203,144,204,145] color=0xff000000\n" + "FillRect [203,145,204,146] color=0xff000000\n" + "FillRect [203,146,204,147] color=0xff000000\n" + "FillRect [203,147,204,148] color=0xff000000\n" + "FillRect [203,148,204,149] color=0xff000000\n" + "FillRect [203,149,204,150] color=0xff000000\n" + "FillRect [203,150,204,151] color=0xff000000\n" + "FillRect [203,151,204,152] color=0xff000000\n" + "FillRect [203,152,204,153] color=0xff000000\n" + "FillRect [203,153,204,154] color=0xff000000\n" + "FillRect [203,154,204,155] color=0xff000000\n" + "FillRect [204,145,205,146] color=0xff000000\n" + "FillRect [204,146,205,147] color=0xff000000\n" + "FillRect [204,151,205,152] color=0xff000000\n" + "FillRect [204,153,205,154] color=0xff000000\n" + "FillRect [204,154,205,155] color=0xff000000\n" + "FillRect [205,143,206,144] color=0xff000000\n" + "FillRect [205,144,206,145] color=0xff000000\n" + "FillRect [205,150,206,151] color=0xff000000\n" + "FillRect [205,152,206,153] color=0xff000000\n" + "FillRect [205,154,206,155] color=0xff000000\n" + "FillRect [206,145,207,146] color=0xff000000\n" + "FillRect [206,146,207,147] color=0xff000000\n" + "FillRect [206,148,207,149] color=0xff000000\n" + "FillRect [206,149,207,150] color=0xff000000\n" + "FillRect [206,150,207,151] color=0xff000000\n" + "FillRect [206,151,207,152] color=0xff000000\n" + "FillRect [206,154,207,155] color=0xff000000\n" + "FillRect [207,143,208,144] color=0xff000000\n" + "FillRect [207,144,208,145] color=0xff000000\n" + "FillRect [207,146,208,147] color=0xff000000\n" + "FillRect [207,147,208,148] color=0xff000000\n" + "FillRect [207,148,208,149] color=0xff000000\n" + "FillRect [207,151,208,152] color=0xff000000\n" + "FillRect [207,154,208,155] color=0xff000000\n" + "FillRect [208,145,209,146] color=0xff000000\n" + "FillRect [208,146,209,147] color=0xff000000\n" + "FillRect [208,148,209,149] color=0xff000000\n" + "FillRect [208,150,209,151] color=0xff000000\n" + "FillRect [208,152,209,153] color=0xff000000\n" + "FillRect [208,153,209,154] color=0xff000000\n" + "FillRect [208,154,209,155] color=0xff000000\n" + "FillRect [209,143,210,144] color=0xff000000\n" + "FillRect [209,144,210,145] color=0xff000000\n" + "FillRect [209,145,210,146] color=0xff000000\n" + "FillRect [209,148,210,149] color=0xff000000\n" + "FillRect [209,150,210,151] color=0xff000000\n" + "FillRect [209,151,210,152] color=0xff000000\n" + "FillRect [209,152,210,153] color=0xff000000\n" + "FillRect [209,154,210,155] color=0xff000000\n" + "FillRect [210,145,211,146] color=0xff000000\n" + "FillRect [210,147,211,148] color=0xff000000\n" + "FillRect [210,150,211,151] color=0xff000000\n" + "FillRect [210,153,211,154] color=0xff000000\n" + "FillRect [210,154,211,155] color=0xff000000\n" + "FillRect [211,143,212,144] color=0xff000000\n" + "FillRect [211,144,212,145] color=0xff000000\n" + "FillRect [211,147,212,148] color=0xff000000\n" + "FillRect [211,150,212,151] color=0xff000000\n" + "FillRect [211,151,212,152] color=0xff000000\n" + "FillRect [211,152,212,153] color=0xff000000\n" + "FillRect [211,154,212,155] color=0xff000000\n" + "FillRect [212,145,213,146] color=0xff000000\n" + "FillRect [212,146,213,147] color=0xff000000\n" + "FillRect [212,149,213,150] color=0xff000000\n" + "FillRect [212,151,213,152] color=0xff000000\n" + "FillRect [212,152,213,153] color=0xff000000\n" + "FillRect [212,154,213,155] color=0xff000000\n" + "FillRect [213,143,214,144] color=0xff000000\n" + "FillRect [213,144,214,145] color=0xff000000\n" + "FillRect [213,151,214,152] color=0xff000000\n" + "FillRect [213,153,214,154] color=0xff000000\n" + "FillRect [213,154,214,155] color=0xff000000\n" + "FillRect [214,144,215,145] color=0xff000000\n" + "FillRect [214,146,215,147] color=0xff000000\n" + "FillRect [214,148,215,149] color=0xff000000\n" + "FillRect [214,150,215,151] color=0xff000000\n" + "FillRect [214,152,215,153] color=0xff000000\n" + "FillRect [214,154,215,155] color=0xff000000\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(BarcodeTest, QrCode) { Create(BC_TYPE::kQRCode); EXPECT_TRUE(barcode()->Encode(L"clams")); RenderDevice(); -#if defined(PDF_USE_SKIA) - static constexpr char kExpectedChecksum[] = - "74d2e6de981088e69740a970b567efc0"; -#else - static constexpr char kExpectedChecksum[] = - "4751c6e0f67749fabe24f787128decee"; -#endif - EXPECT_EQ(kExpectedChecksum, BitmapChecksum()); + static constexpr char kExpected[] = + "DrawPath fill=0xffffffff stroke=0xffffffff rule=even-odd " + "stroke_state=[width=1.0000 cap=butt join=miter miter=10.0000] " + "matrix=[1.0000,0.0000,0.0000,1.0000,0.0000,0.0000] " + "points=[move(0.0000,0.0000) line(0.0000,298.0000) " + "line(418.0000,298.0000) line(418.0000,0.0000) " + "line(0.0000,0.0000,close)]\n" + "FillRect [198,138,199,139] color=0xff000000\n" + "FillRect [198,139,199,140] color=0xff000000\n" + "FillRect [198,140,199,141] color=0xff000000\n" + "FillRect [198,141,199,142] color=0xff000000\n" + "FillRect [198,142,199,143] color=0xff000000\n" + "FillRect [198,143,199,144] color=0xff000000\n" + "FillRect [198,144,199,145] color=0xff000000\n" + "FillRect [198,146,199,147] color=0xff000000\n" + "FillRect [198,147,199,148] color=0xff000000\n" + "FillRect [198,149,199,150] color=0xff000000\n" + "FillRect [198,152,199,153] color=0xff000000\n" + "FillRect [198,153,199,154] color=0xff000000\n" + "FillRect [198,154,199,155] color=0xff000000\n" + "FillRect [198,155,199,156] color=0xff000000\n" + "FillRect [198,156,199,157] color=0xff000000\n" + "FillRect [198,157,199,158] color=0xff000000\n" + "FillRect [198,158,199,159] color=0xff000000\n" + "FillRect [199,138,200,139] color=0xff000000\n" + "FillRect [199,144,200,145] color=0xff000000\n" + "FillRect [199,147,200,148] color=0xff000000\n" + "FillRect [199,152,200,153] color=0xff000000\n" + "FillRect [199,158,200,159] color=0xff000000\n" + "FillRect [200,138,201,139] color=0xff000000\n" + "FillRect [200,140,201,141] color=0xff000000\n" + "FillRect [200,141,201,142] color=0xff000000\n" + "FillRect [200,142,201,143] color=0xff000000\n" + "FillRect [200,144,201,145] color=0xff000000\n" + "FillRect [200,146,201,147] color=0xff000000\n" + "FillRect [200,148,201,149] color=0xff000000\n" + "FillRect [200,150,201,151] color=0xff000000\n" + "FillRect [200,152,201,153] color=0xff000000\n" + "FillRect [200,154,201,155] color=0xff000000\n" + "FillRect [200,155,201,156] color=0xff000000\n" + "FillRect [200,156,201,157] color=0xff000000\n" + "FillRect [200,158,201,159] color=0xff000000\n" + "FillRect [201,138,202,139] color=0xff000000\n" + "FillRect [201,140,202,141] color=0xff000000\n" + "FillRect [201,141,202,142] color=0xff000000\n" + "FillRect [201,142,202,143] color=0xff000000\n" + "FillRect [201,144,202,145] color=0xff000000\n" + "FillRect [201,146,202,147] color=0xff000000\n" + "FillRect [201,152,202,153] color=0xff000000\n" + "FillRect [201,154,202,155] color=0xff000000\n" + "FillRect [201,155,202,156] color=0xff000000\n" + "FillRect [201,156,202,157] color=0xff000000\n" + "FillRect [201,158,202,159] color=0xff000000\n" + "FillRect [202,138,203,139] color=0xff000000\n" + "FillRect [202,140,203,141] color=0xff000000\n" + "FillRect [202,141,203,142] color=0xff000000\n" + "FillRect [202,142,203,143] color=0xff000000\n" + "FillRect [202,144,203,145] color=0xff000000\n" + "FillRect [202,146,203,147] color=0xff000000\n" + "FillRect [202,148,203,149] color=0xff000000\n" + "FillRect [202,152,203,153] color=0xff000000\n" + "FillRect [202,154,203,155] color=0xff000000\n" + "FillRect [202,155,203,156] color=0xff000000\n" + "FillRect [202,156,203,157] color=0xff000000\n" + "FillRect [202,158,203,159] color=0xff000000\n" + "FillRect [203,138,204,139] color=0xff000000\n" + "FillRect [203,144,204,145] color=0xff000000\n" + "FillRect [203,146,204,147] color=0xff000000\n" + "FillRect [203,148,204,149] color=0xff000000\n" + "FillRect [203,150,204,151] color=0xff000000\n" + "FillRect [203,152,204,153] color=0xff000000\n" + "FillRect [203,158,204,159] color=0xff000000\n" + "FillRect [204,138,205,139] color=0xff000000\n" + "FillRect [204,139,205,140] color=0xff000000\n" + "FillRect [204,140,205,141] color=0xff000000\n" + "FillRect [204,141,205,142] color=0xff000000\n" + "FillRect [204,142,205,143] color=0xff000000\n" + "FillRect [204,143,205,144] color=0xff000000\n" + "FillRect [204,144,205,145] color=0xff000000\n" + "FillRect [204,146,205,147] color=0xff000000\n" + "FillRect [204,148,205,149] color=0xff000000\n" + "FillRect [204,150,205,151] color=0xff000000\n" + "FillRect [204,152,205,153] color=0xff000000\n" + "FillRect [204,153,205,154] color=0xff000000\n" + "FillRect [204,154,205,155] color=0xff000000\n" + "FillRect [204,155,205,156] color=0xff000000\n" + "FillRect [204,156,205,157] color=0xff000000\n" + "FillRect [204,157,205,158] color=0xff000000\n" + "FillRect [204,158,205,159] color=0xff000000\n" + "FillRect [205,147,206,148] color=0xff000000\n" + "FillRect [205,148,206,149] color=0xff000000\n" + "FillRect [205,149,206,150] color=0xff000000\n" + "FillRect [205,150,206,151] color=0xff000000\n" + "FillRect [206,140,207,141] color=0xff000000\n" + "FillRect [206,141,207,142] color=0xff000000\n" + "FillRect [206,142,207,143] color=0xff000000\n" + "FillRect [206,143,207,144] color=0xff000000\n" + "FillRect [206,144,207,145] color=0xff000000\n" + "FillRect [206,145,207,146] color=0xff000000\n" + "FillRect [206,150,207,151] color=0xff000000\n" + "FillRect [206,151,207,152] color=0xff000000\n" + "FillRect [206,153,207,154] color=0xff000000\n" + "FillRect [206,154,207,155] color=0xff000000\n" + "FillRect [206,155,207,156] color=0xff000000\n" + "FillRect [206,156,207,157] color=0xff000000\n" + "FillRect [206,158,207,159] color=0xff000000\n" + "FillRect [207,138,208,139] color=0xff000000\n" + "FillRect [207,140,208,141] color=0xff000000\n" + "FillRect [207,142,208,143] color=0xff000000\n" + "FillRect [207,147,208,148] color=0xff000000\n" + "FillRect [207,148,208,149] color=0xff000000\n" + "FillRect [207,149,208,150] color=0xff000000\n" + "FillRect [207,151,208,152] color=0xff000000\n" + "FillRect [207,152,208,153] color=0xff000000\n" + "FillRect [207,153,208,154] color=0xff000000\n" + "FillRect [207,154,208,155] color=0xff000000\n" + "FillRect [208,138,209,139] color=0xff000000\n" + "FillRect [208,141,209,142] color=0xff000000\n" + "FillRect [208,143,209,144] color=0xff000000\n" + "FillRect [208,144,209,145] color=0xff000000\n" + "FillRect [208,145,209,146] color=0xff000000\n" + "FillRect [208,146,209,147] color=0xff000000\n" + "FillRect [208,147,209,148] color=0xff000000\n" + "FillRect [208,148,209,149] color=0xff000000\n" + "FillRect [208,149,209,150] color=0xff000000\n" + "FillRect [208,153,209,154] color=0xff000000\n" + "FillRect [208,156,209,157] color=0xff000000\n" + "FillRect [209,138,210,139] color=0xff000000\n" + "FillRect [209,140,210,141] color=0xff000000\n" + "FillRect [209,143,210,144] color=0xff000000\n" + "FillRect [209,146,210,147] color=0xff000000\n" + "FillRect [209,147,210,148] color=0xff000000\n" + "FillRect [209,149,210,150] color=0xff000000\n" + "FillRect [209,152,210,153] color=0xff000000\n" + "FillRect [209,154,210,155] color=0xff000000\n" + "FillRect [209,155,210,156] color=0xff000000\n" + "FillRect [209,157,210,158] color=0xff000000\n" + "FillRect [210,140,211,141] color=0xff000000\n" + "FillRect [210,141,211,142] color=0xff000000\n" + "FillRect [210,142,211,143] color=0xff000000\n" + "FillRect [210,144,211,145] color=0xff000000\n" + "FillRect [210,147,211,148] color=0xff000000\n" + "FillRect [210,148,211,149] color=0xff000000\n" + "FillRect [210,149,211,150] color=0xff000000\n" + "FillRect [210,150,211,151] color=0xff000000\n" + "FillRect [210,151,211,152] color=0xff000000\n" + "FillRect [210,155,211,156] color=0xff000000\n" + "FillRect [210,156,211,157] color=0xff000000\n" + "FillRect [210,157,211,158] color=0xff000000\n" + "FillRect [210,158,211,159] color=0xff000000\n" + "FillRect [211,147,212,148] color=0xff000000\n" + "FillRect [211,149,212,150] color=0xff000000\n" + "FillRect [211,152,212,153] color=0xff000000\n" + "FillRect [211,154,212,155] color=0xff000000\n" + "FillRect [211,155,212,156] color=0xff000000\n" + "FillRect [211,157,212,158] color=0xff000000\n" + "FillRect [212,138,213,139] color=0xff000000\n" + "FillRect [212,139,213,140] color=0xff000000\n" + "FillRect [212,140,213,141] color=0xff000000\n" + "FillRect [212,141,213,142] color=0xff000000\n" + "FillRect [212,142,213,143] color=0xff000000\n" + "FillRect [212,143,213,144] color=0xff000000\n" + "FillRect [212,144,213,145] color=0xff000000\n" + "FillRect [212,146,213,147] color=0xff000000\n" + "FillRect [212,147,213,148] color=0xff000000\n" + "FillRect [212,148,213,149] color=0xff000000\n" + "FillRect [212,149,213,150] color=0xff000000\n" + "FillRect [212,155,213,156] color=0xff000000\n" + "FillRect [212,156,213,157] color=0xff000000\n" + "FillRect [212,157,213,158] color=0xff000000\n" + "FillRect [213,138,214,139] color=0xff000000\n" + "FillRect [213,144,214,145] color=0xff000000\n" + "FillRect [213,146,214,147] color=0xff000000\n" + "FillRect [213,148,214,149] color=0xff000000\n" + "FillRect [213,150,214,151] color=0xff000000\n" + "FillRect [213,151,214,152] color=0xff000000\n" + "FillRect [213,153,214,154] color=0xff000000\n" + "FillRect [213,155,214,156] color=0xff000000\n" + "FillRect [213,156,214,157] color=0xff000000\n" + "FillRect [213,158,214,159] color=0xff000000\n" + "FillRect [214,138,215,139] color=0xff000000\n" + "FillRect [214,140,215,141] color=0xff000000\n" + "FillRect [214,141,215,142] color=0xff000000\n" + "FillRect [214,142,215,143] color=0xff000000\n" + "FillRect [214,144,215,145] color=0xff000000\n" + "FillRect [214,146,215,147] color=0xff000000\n" + "FillRect [214,152,215,153] color=0xff000000\n" + "FillRect [214,153,215,154] color=0xff000000\n" + "FillRect [214,154,215,155] color=0xff000000\n" + "FillRect [214,157,215,158] color=0xff000000\n" + "FillRect [215,138,216,139] color=0xff000000\n" + "FillRect [215,140,216,141] color=0xff000000\n" + "FillRect [215,141,216,142] color=0xff000000\n" + "FillRect [215,142,216,143] color=0xff000000\n" + "FillRect [215,144,216,145] color=0xff000000\n" + "FillRect [215,146,216,147] color=0xff000000\n" + "FillRect [215,147,216,148] color=0xff000000\n" + "FillRect [215,149,216,150] color=0xff000000\n" + "FillRect [215,152,216,153] color=0xff000000\n" + "FillRect [215,153,216,154] color=0xff000000\n" + "FillRect [215,155,216,156] color=0xff000000\n" + "FillRect [215,156,216,157] color=0xff000000\n" + "FillRect [215,157,216,158] color=0xff000000\n" + "FillRect [215,158,216,159] color=0xff000000\n" + "FillRect [216,138,217,139] color=0xff000000\n" + "FillRect [216,140,217,141] color=0xff000000\n" + "FillRect [216,141,217,142] color=0xff000000\n" + "FillRect [216,142,217,143] color=0xff000000\n" + "FillRect [216,144,217,145] color=0xff000000\n" + "FillRect [216,146,217,147] color=0xff000000\n" + "FillRect [216,148,217,149] color=0xff000000\n" + "FillRect [216,149,217,150] color=0xff000000\n" + "FillRect [216,151,217,152] color=0xff000000\n" + "FillRect [216,152,217,153] color=0xff000000\n" + "FillRect [216,153,217,154] color=0xff000000\n" + "FillRect [216,156,217,157] color=0xff000000\n" + "FillRect [216,157,217,158] color=0xff000000\n" + "FillRect [217,138,218,139] color=0xff000000\n" + "FillRect [217,144,218,145] color=0xff000000\n" + "FillRect [217,148,218,149] color=0xff000000\n" + "FillRect [217,149,218,150] color=0xff000000\n" + "FillRect [217,152,218,153] color=0xff000000\n" + "FillRect [217,153,218,154] color=0xff000000\n" + "FillRect [217,154,218,155] color=0xff000000\n" + "FillRect [217,158,218,159] color=0xff000000\n" + "FillRect [218,138,219,139] color=0xff000000\n" + "FillRect [218,139,219,140] color=0xff000000\n" + "FillRect [218,140,219,141] color=0xff000000\n" + "FillRect [218,141,219,142] color=0xff000000\n" + "FillRect [218,142,219,143] color=0xff000000\n" + "FillRect [218,143,219,144] color=0xff000000\n" + "FillRect [218,144,219,145] color=0xff000000\n" + "FillRect [218,147,219,148] color=0xff000000\n" + "FillRect [218,149,219,150] color=0xff000000\n" + "FillRect [218,151,219,152] color=0xff000000\n"; + EXPECT_EQ(kExpected, display_list()); } TEST_F(BarcodeTest, GetType) { From c9a1ea6d054f1b7fb0b845631eebc28d8e2fd8f0 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Wed, 18 Nov 2026 17:39:12 -0800 Subject: [PATCH 16/34] Clear host bindings in ~CFXJSE_Context() and guard context init Move global object unbinding for contexts from ~CFXJSE_Engine() into ~CFXJSE_Context() so any context destroyed before engine teardown clears its global object's host-object pointer before dropping `this_proxy_`. In addition: - Suppress microtask execution during EnableCompatibleMode() so bootstrap script execution does not drain pending microtasks while a context is still being initialized. - Return std::unique_ptr from CreateVariablesContext() and use try_emplace() in RunVariablesScript() so re-entrant script resolution does not overwrite an existing map entry. - Check for a null result from ToObject() in GlobalPropertyGetter() and GlobalPropertySetter() to handle unbound global objects safely. - Require FXJSE_ClassPropType::kProperty in DynPropSetterAdapter() so properties returning kNone do not invoke dynPropSetter. Fixed: 587005930 Change-Id: I0615a8c26d468e436122cc9bee6209335af5ddf4 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164951 Reviewed-by: Lei Zhang Commit-Queue: Lei Zhang --- fxjs/xfa/cfxjse_class.cpp | 2 +- fxjs/xfa/cfxjse_context.cpp | 14 ++++++++++++- fxjs/xfa/cfxjse_context.h | 3 +++ fxjs/xfa/cfxjse_engine.cpp | 41 ++++++++++++++++++++++++++----------- fxjs/xfa/cfxjse_engine.h | 5 +++-- 5 files changed, 49 insertions(+), 16 deletions(-) diff --git a/fxjs/xfa/cfxjse_class.cpp b/fxjs/xfa/cfxjse_class.cpp index d8102edf4..fc84c7165 100644 --- a/fxjs/xfa/cfxjse_class.cpp +++ b/fxjs/xfa/cfxjse_class.cpp @@ -199,7 +199,7 @@ void DynPropSetterAdapter(v8::Isolate* pIsolate, false) : FXJSE_ClassPropType::kProperty; - if (nPropType != FXJSE_ClassPropType::kMethod && + if (nPropType == FXJSE_ClassPropType::kProperty && pClassDescriptor->dynPropSetter) { pClassDescriptor->dynPropSetter(pIsolate, pObject, szPropName, value); } diff --git a/fxjs/xfa/cfxjse_context.cpp b/fxjs/xfa/cfxjse_context.cpp index 6132fe0c0..71590fa13 100644 --- a/fxjs/xfa/cfxjse_context.cpp +++ b/fxjs/xfa/cfxjse_context.cpp @@ -20,6 +20,7 @@ #include "fxjs/xfa/cjx_object.h" #include "v8/include/v8-exception.h" #include "v8/include/v8-function.h" +#include "v8/include/v8-isolate.h" #include "v8/include/v8-message.h" #include "v8/include/v8-script.h" #include "v8/include/v8-template.h" @@ -207,7 +208,15 @@ std::unique_ptr CFXJSE_Context::Create( CFXJSE_Context::CFXJSE_Context(v8::Isolate* pIsolate, CXFA_ThisProxy* pProxy) : isolate_(pIsolate), this_proxy_(pProxy) {} -CFXJSE_Context::~CFXJSE_Context() = default; +CFXJSE_Context::~CFXJSE_Context() { + // Clear the global object binding before dropping `this_proxy_` so any + // retained reference to the global object cannot access a destroyed host + // object. + if (!context_.IsEmpty()) { + CFXJSE_ScopeUtil_IsolateHandle scope(GetIsolate()); + FXJSE_ClearObjectBinding(GetGlobalObject()); + } +} v8::Local CFXJSE_Context::GetGlobalObject() { v8::Isolate::Scope isolate_scope(GetIsolate()); @@ -235,6 +244,9 @@ CFXJSE_Class* CFXJSE_Context::GetClassByName(ByteStringView szName) const { } void CFXJSE_Context::EnableCompatibleMode() { + v8::Isolate::Scope isolate_scope(GetIsolate()); + v8::Isolate::SuppressMicrotaskExecutionScope suppress_microtasks( + GetIsolate()); ExecuteScript(szCompatibleModeScript, v8::Local()); ExecuteScript(szConsoleScript, v8::Local()); } diff --git a/fxjs/xfa/cfxjse_context.h b/fxjs/xfa/cfxjse_context.h index e0fc3a14b..a738850cb 100644 --- a/fxjs/xfa/cfxjse_context.h +++ b/fxjs/xfa/cfxjse_context.h @@ -40,6 +40,7 @@ class CFXJSE_Context { CFXJSE_HostObject* pGlobalObject, CXFA_ThisProxy* pProxy); + // Clears the host object binding on the context's global object. ~CFXJSE_Context(); v8::Isolate* GetIsolate() const { return isolate_; } @@ -48,6 +49,8 @@ class CFXJSE_Context { void AddClass(std::unique_ptr pClass); CFXJSE_Class* GetClassByName(ByteStringView szName) const; + + // Executes compatibility bootstrap scripts with microtasks suppressed. void EnableCompatibleMode(); // Note: `pNewThisObject` may be empty. diff --git a/fxjs/xfa/cfxjse_engine.cpp b/fxjs/xfa/cfxjse_engine.cpp index 24d79b6e0..5bb4b603a 100644 --- a/fxjs/xfa/cfxjse_engine.cpp +++ b/fxjs/xfa/cfxjse_engine.cpp @@ -168,15 +168,13 @@ CFXJSE_Engine::CFXJSE_Engine(CXFA_Document* document, v8::Isolate* isolate) CFXJSE_Engine::~CFXJSE_Engine() { // This is what ensures that the v8 object bound to a CJX_Object // no longer retains that binding since it will outlive that object. + // `CFXJSE_Context` and `CFXJSE_FormCalcContext` clear their own bindings on + // destruction. CFXJSE_ScopeUtil_IsolateHandleContext scope(GetJseContext()); for (const auto& pair : map_object_to_object_) { const v8::Global& binding = pair.second; FXJSE_ClearObjectBinding(v8::Local::New(GetIsolate(), binding)); } - for (const auto& pair : map_variable_to_context_) { - FXJSE_ClearObjectBinding(pair.second->GetGlobalObject()); - } - FXJSE_ClearObjectBinding(js_context_->GetGlobalObject()); } CFXJSE_Engine::EventParamScope::EventParamScope(CFXJSE_Engine* pEngine, @@ -311,6 +309,10 @@ void CFXJSE_Engine::GlobalPropertySetter(v8::Isolate* pIsolate, ByteStringView szPropName, v8::Local pValue) { CXFA_Object* pOriginalNode = ToObject(pIsolate, pObject); + if (!pOriginalNode) { + return; + } + CXFA_Document* doc = pOriginalNode->GetDocument(); CFXJSE_Engine* pScriptContext = doc->GetScriptContext(); CXFA_Node* pRefNode = ToNode(pScriptContext->GetThisObject()); @@ -347,6 +349,10 @@ v8::Local CFXJSE_Engine::GlobalPropertyGetter( v8::Local pObject, ByteStringView szPropName) { CXFA_Object* pOriginalObject = ToObject(pIsolate, pObject); + if (!pOriginalObject) { + return fxv8::NewUndefinedHelper(pIsolate); + } + CXFA_Document* doc = pOriginalObject->GetDocument(); CFXJSE_Engine* pScriptContext = doc->GetScriptContext(); WideString wsPropName = WideString::FromUTF8(szPropName); @@ -625,8 +631,9 @@ CXFA_Node* CFXJSE_Engine::LastObjectFromUpArray() { : nullptr; } -CFXJSE_Context* CFXJSE_Engine::CreateVariablesContext(CXFA_Script* pScriptNode, - CXFA_Node* pSubform) { +std::unique_ptr CFXJSE_Engine::CreateVariablesContext( + CXFA_Script* pScriptNode, + CXFA_Node* pSubform) { if (!pScriptNode || !pSubform) { return nullptr; } @@ -638,9 +645,7 @@ CFXJSE_Context* CFXJSE_Engine::CreateVariablesContext(CXFA_Script* pScriptNode, GetIsolate(), &kVariablesClassDescriptor, proxy->JSObject(), proxy); RemoveBuiltInObjs(pNewContext.get()); pNewContext->EnableCompatibleMode(); - CFXJSE_Context* pResult = pNewContext.get(); - map_variable_to_context_[pScriptNode->JSObject()] = std::move(pNewContext); - return pResult; + return pNewContext; } CXFA_Object* CFXJSE_Engine::GetVariablesThis(CXFA_Object* pObject) { @@ -681,12 +686,24 @@ void CFXJSE_Engine::RunVariablesScript(CXFA_Script* pScriptNode) { ByteString btScript = wsScript->ToUTF8(); CXFA_Node* pThisObject = pParent->GetParent(); - CFXJSE_Context* pVariablesContext = + std::unique_ptr pVariablesContext = CreateVariablesContext(pScriptNode, pThisObject); + if (!pVariablesContext) { + return; + } + + // Defense-in-depth: avoid overwriting an entry if `CreateVariablesContext()` + // ever re-entrantly initialized this node. + auto [emplaced_it, inserted] = map_variable_to_context_.try_emplace( + pScriptNode->JSObject(), std::move(pVariablesContext)); + if (!inserted) { + return; + } + AutoRestorer> nodeRestorer(&this_object_); this_object_ = pThisObject; - pVariablesContext->ExecuteScript(btScript.AsStringView(), - v8::Local()); + emplaced_it->second->ExecuteScript(btScript.AsStringView(), + v8::Local()); } CFXJSE_Context* CFXJSE_Engine::VariablesContextForScriptNode( diff --git a/fxjs/xfa/cfxjse_engine.h b/fxjs/xfa/cfxjse_engine.h index 988979c15..f1d176e62 100644 --- a/fxjs/xfa/cfxjse_engine.h +++ b/fxjs/xfa/cfxjse_engine.h @@ -189,8 +189,9 @@ class CFXJSE_Engine final : public CFX_IsolateWrapper { private: CJS_Runtime* GetCJSRuntime() const; CFXJSE_Context* GetJseContext() const { return js_context_.get(); } - CFXJSE_Context* CreateVariablesContext(CXFA_Script* pScriptNode, - CXFA_Node* pSubform); + std::unique_ptr CreateVariablesContext( + CXFA_Script* pScriptNode, + CXFA_Node* pSubform); void RemoveBuiltInObjs(CFXJSE_Context* context); bool QueryNodeByFlag(CXFA_Node* refNode, WideStringView propname, From 78f446fb97918d1d1f421210c48a34a3d942fa91 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 19 Nov 2026 12:39:27 -0800 Subject: [PATCH 17/34] Roll third_party/rust/ 7661f9bcc..aee344506 (3 commits) Out-of-cycle roll to keep PDFium in-sync with Chromium. https://chromium.googlesource.com/chromium/src/third_party/rust/+log/7661f9bcc77d..aee3445062d8 Created with: roll-dep third_party/rust -- Manually adjust directory versions in GN files. Change-Id: I606ab7c1005713fd6ab1d9c4cb6368f5648b2e03 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164890 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- DEPS | 2 +- core/fxge/BUILD.gn | 4 ++-- skia/BUILD.gn | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DEPS b/DEPS index 42270b345..4d8998bf5 100644 --- a/DEPS +++ b/DEPS @@ -232,7 +232,7 @@ vars = { # Three lines of non-changing comments so that # the commit queue can handle CLs rolling rust # and whatever else without interference from each other. - 'rust_revision': '7661f9bcc77d614626b818bc40bd8398e4a48d9c', + 'rust_revision': 'aee3445062d8cf2b53941d0ee7eb14fcab91e5b1', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling simdutf # and whatever else without interference from each other. diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn index d9ffcb824..51ad9754d 100644 --- a/core/fxge/BUILD.gn +++ b/core/fxge/BUILD.gn @@ -239,8 +239,8 @@ if (pdf_enable_fontations) { features = [ "agl" ] deps = [ "//build/rust:cxx_cppdeps", - "//third_party/rust/read_fonts/v0_46:lib", - "//third_party/rust/skrifa/v0_49:lib", + "//third_party/rust/read_fonts/v0_47:lib", + "//third_party/rust/skrifa/v0_50:lib", ] configs += [ "../../:pdfium_common_config" ] } diff --git a/skia/BUILD.gn b/skia/BUILD.gn index 68bd82d18..de234af9d 100644 --- a/skia/BUILD.gn +++ b/skia/BUILD.gn @@ -43,8 +43,8 @@ if (pdf_enable_fontations) { deps = [ ":path_bridge", "//third_party/rust/font_types/v0_12:lib", - "//third_party/rust/read_fonts/v0_46:lib", - "//third_party/rust/skrifa/v0_49:lib", + "//third_party/rust/read_fonts/v0_47:lib", + "//third_party/rust/skrifa/v0_50:lib", ] configs -= [ "//build/config/compiler:chromium_code" ] configs += [ From 721a620a0a0a7c26cec2a6fd97ca3c73eec298a9 Mon Sep 17 00:00:00 2001 From: Copybara Date: Thu, 19 Nov 2026 12:56:37 -0800 Subject: [PATCH 18/34] Fix float-cast-overflow in FindTextlineFlowOrientation() `CPDF_TextPage::FindTextlineFlowOrientation()` casts page width, page height, and `2 * fLineHeight` directly from float to `int32_t`. Pages with extreme MediaBox dimensions or text objects with extreme vertical scale can exceed `int32_t` bounds and trigger UBSan float-cast-overflow. Validate page width and height with `pdfium::IsValueInRangeForNumericType()` before casting, returning `TextOrientation::kUnknown` when out of range so text extraction proceeds. Checking range rather than saturating also ensures promoting `nPageWidth` and `nPageHeight` back to float in `std::clamp()` stays within `int32_t` bounds (at most 2147483520.0f). Use `pdfium::saturated_cast()` for `nDoubleLineHeight` so overflowing line heights saturate to `INT32_MAX` instead of invoking undefined behavior. Add embedder tests covering overflowing text line heights and page dimensions. PiperOrigin-RevId: 1025695828 Change-Id: Idb53d9b091a31fb31909551eb382ae6e9a13dc98 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165050 Commit-Queue: Lei Zhang Reviewed-by: Lei Zhang --- core/fpdftext/cpdf_textpage.cpp | 15 ++++++-- fpdfsdk/fpdf_text_embeddertest.cpp | 62 ++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) diff --git a/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index c048ba3a8..79e01f109 100644 --- a/core/fpdftext/cpdf_textpage.cpp +++ b/core/fpdftext/cpdf_textpage.cpp @@ -33,6 +33,7 @@ #include "core/fxcrt/fx_extension.h" #include "core/fxcrt/fx_unicode.h" #include "core/fxcrt/notreached.h" +#include "core/fxcrt/numerics/safe_conversions.h" #include "core/fxcrt/span.h" #include "core/fxcrt/stl_util.h" #include "core/fxcrt/zip.h" @@ -653,8 +654,15 @@ bool CPDF_TextPage::GetRect(int rectIndex, CFX_FloatRect* pRect) const { CPDF_TextPage::TextOrientation CPDF_TextPage::FindTextlineFlowOrientation() const { - const int32_t nPageWidth = static_cast(page_->GetPageWidth()); - const int32_t nPageHeight = static_cast(page_->GetPageHeight()); + const float page_width = page_->GetPageWidth(); + const float page_height = page_->GetPageHeight(); + if (!pdfium::IsValueInRangeForNumericType(page_width) || + !pdfium::IsValueInRangeForNumericType(page_height)) { + return TextOrientation::kUnknown; + } + + const int32_t nPageWidth = static_cast(page_width); + const int32_t nPageHeight = static_cast(page_height); if (nPageWidth <= 0 || nPageHeight <= 0) { return TextOrientation::kUnknown; } @@ -707,7 +715,8 @@ CPDF_TextPage::TextOrientation CPDF_TextPage::FindTextlineFlowOrientation() fLineHeight = rect.Height(); } } - const int32_t nDoubleLineHeight = 2 * fLineHeight; + const int32_t nDoubleLineHeight = + pdfium::saturated_cast(2 * fLineHeight); if ((nEndV - nStartV) < nDoubleLineHeight) { return TextOrientation::kHorizontal; } diff --git a/fpdfsdk/fpdf_text_embeddertest.cpp b/fpdfsdk/fpdf_text_embeddertest.cpp index 62daa5d20..f8af2e92b 100644 --- a/fpdfsdk/fpdf_text_embeddertest.cpp +++ b/fpdfsdk/fpdf_text_embeddertest.cpp @@ -13,6 +13,7 @@ #include "core/fxge/fx_font.h" #include "public/cpp/fpdf_scopers.h" #include "public/fpdf_doc.h" +#include "public/fpdf_edit.h" #include "public/fpdf_text.h" #include "public/fpdf_transformpage.h" #include "public/fpdfview.h" @@ -2702,3 +2703,64 @@ TEST_F(FPDFTextEmbedderTest, RtlMultiCharGlyph) { EXPECT_THAT(pdfium::span(buffer).first(), ElementsAreArray(kExpectedText)); } + +TEST_F(FPDFTextEmbedderTest, OverflowingLineHeight) { + CreateEmptyDocument(); + ScopedFPDFPage page(FPDFPage_New(document(), 0, 500, 750)); + ASSERT_TRUE(page); + + ScopedFPDFPageObject text_obj( + FPDFPageObj_NewTextObj(document(), "Helvetica", 12.0f)); + ASSERT_TRUE(text_obj); + ScopedFPDFWideString text = GetFPDFWideString(L"X"); + ASSERT_TRUE(FPDFText_SetText(text_obj.get(), text.get())); + static constexpr FS_MATRIX kMatrix{1, 0, 0, 200000000.0f, 100, 100}; + ASSERT_TRUE(FPDFPageObj_SetMatrix(text_obj.get(), &kMatrix)); + ASSERT_TRUE(FPDFPage_InsertObject(page.get(), text_obj.release())); + + ScopedFPDFTextPage text_page(FPDFText_LoadPage(page.get())); + ASSERT_TRUE(text_page); + + static constexpr auto kExpectedText = std::to_array({'X', '\0'}); + std::array buffer = {}; + int num_chars = FPDFText_GetText( + text_page.get(), 0, static_cast(buffer.size() - 1), buffer.data()); + ASSERT_EQ(static_cast(kExpectedText.size()), num_chars); + EXPECT_THAT(pdfium::span(buffer).first(), + ElementsAreArray(kExpectedText)); +} + +TEST_F(FPDFTextEmbedderTest, OverflowingPageDimensions) { + static constexpr std::array, 2> kPageSizes = {{ + {3000000000.0, 750.0}, + {500.0, 3000000000.0}, + }}; + static constexpr auto kExpectedText = + std::to_array({'H', 'e', 'l', 'l', 'o', '\0'}); + + CreateEmptyDocument(); + int page_index = 0; + for (const auto& [width, height] : kPageSizes) { + ScopedFPDFPage page(FPDFPage_New(document(), page_index++, width, height)); + ASSERT_TRUE(page); + + ScopedFPDFPageObject text_obj( + FPDFPageObj_NewTextObj(document(), "Helvetica", 12.0f)); + ASSERT_TRUE(text_obj); + ScopedFPDFWideString text = GetFPDFWideString(L"Hello"); + ASSERT_TRUE(FPDFText_SetText(text_obj.get(), text.get())); + static constexpr FS_MATRIX kMatrix{1, 0, 0, 1, 100, 300}; + ASSERT_TRUE(FPDFPageObj_SetMatrix(text_obj.get(), &kMatrix)); + ASSERT_TRUE(FPDFPage_InsertObject(page.get(), text_obj.release())); + + ScopedFPDFTextPage text_page(FPDFText_LoadPage(page.get())); + ASSERT_TRUE(text_page); + + std::array buffer = {}; + int num_chars = FPDFText_GetText( + text_page.get(), 0, static_cast(buffer.size() - 1), buffer.data()); + ASSERT_EQ(static_cast(kExpectedText.size()), num_chars); + EXPECT_THAT(pdfium::span(buffer).first(), + ElementsAreArray(kExpectedText)); + } +} From 2a0fa0ce28a64c47b2e8e926dbe017771a9a6dce Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 19 Nov 2026 13:10:35 -0800 Subject: [PATCH 19/34] Roll third_party/llvm-libc/src/ d8f204500..7840ec9fb (285 commits) https://chromium.googlesource.com/external/github.com/llvm/llvm-project/libc.git/+log/d8f2045008e2..7840ec9fbb6b Created with: roll-dep third_party/llvm-libc/src Change-Id: Ia275820c21256ae86f79df642c78f496e9a1aa99 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165070 Reviewed-by: Andy Phan Auto-Submit: Lei Zhang Commit-Queue: Andy Phan --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 4d8998bf5..6017992a4 100644 --- a/DEPS +++ b/DEPS @@ -204,7 +204,7 @@ vars = { # Three lines of non-changing comments so that # the commit queue can handle CLs rolling llvm-libc # and whatever else without interference from each other. - 'llvm_libc_revision': 'd8f2045008e230f3c5f50095d918c11f1997e477', + 'llvm_libc_revision': '7840ec9fbb6be122103494a8f763e45775ef6353', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling markupsafe # and whatever else without interference from each other. From 96cb92b773d8586b241514ac7144ed4aabbd40ab Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 19 Nov 2026 13:11:52 -0800 Subject: [PATCH 20/34] Roll third_party/freetype/src/ a5877f48f..2b01fa2d6 (3 commits) https://chromium.googlesource.com/chromium/src/third_party/freetype2.git/+log/a5877f48fff8..2b01fa2d6723 Then remove `TT_CONFIG_OPTION_NO_BORING_EXPANSION` from ftoption.h, since FreeType removed this upstream. Same as crrev.com/1746067. Created with: roll-dep third_party/freetype/src Change-Id: I81b4c12fa49f371f8b125af629cb0a0bdc10c89c Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165090 Reviewed-by: Andy Phan Commit-Queue: Andy Phan Auto-Submit: Lei Zhang --- DEPS | 2 +- third_party/freetype/README.pdfium | 4 ++-- .../include/freetype-custom-config/ftoption.h | 18 ------------------ 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/DEPS b/DEPS index 6017992a4..4b2deec2c 100644 --- a/DEPS +++ b/DEPS @@ -142,7 +142,7 @@ vars = { # Three lines of non-changing comments so that # the commit queue can handle CLs rolling freetype # and whatever else without interference from each other. - 'freetype_revision': 'a5877f48fff8dd6cf8d53c505ce055499376aee2', + 'freetype_revision': '2b01fa2d6723bf12490822268c9627697ed89643', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling GN CIPD package version # and whatever else without interference from each other. diff --git a/third_party/freetype/README.pdfium b/third_party/freetype/README.pdfium index 68ef6e87e..ab033efc2 100644 --- a/third_party/freetype/README.pdfium +++ b/third_party/freetype/README.pdfium @@ -1,7 +1,7 @@ Name: FreeType URL: https://gitlab.freedesktop.org/freetype/freetype -Version: VER-2-15-0-7 -Revision: a5877f48fff8dd6cf8d53c505ce055499376aee2 +Version: VER-2-15-0-10 +Revision: 2b01fa2d6723bf12490822268c9627697ed89643 Update Mechanism: Manual CPEPrefix: cpe:/a:freetype:freetype:2.15.0 Security Critical: yes diff --git a/third_party/freetype/include/freetype-custom-config/ftoption.h b/third_party/freetype/include/freetype-custom-config/ftoption.h index 73abe1727..d3f43a0e3 100644 --- a/third_party/freetype/include/freetype-custom-config/ftoption.h +++ b/third_party/freetype/include/freetype-custom-config/ftoption.h @@ -700,24 +700,6 @@ FT_BEGIN_HEADER #undef TT_CONFIG_OPTION_BDF - /************************************************************************** - * - * Define `TT_CONFIG_OPTION_NO_BORING_EXPANSION` if you want to exclude - * support for 'boring' OpenType specification expansions. - * - * https://github.com/harfbuzz/boring-expansion-spec - * - * Right now, the following features are covered: - * - * - 'avar' version 2.0 - * - * Most likely, this is a temporary configuration option to be removed in - * the near future, since it is assumed that eventually those features are - * added to the OpenType standard. - */ -#define TT_CONFIG_OPTION_NO_BORING_EXPANSION - - /*************************************************************************/ /* */ /* Option TT_CONFIG_OPTION_MAX_RUNNABLE_OPCODES controls the maximum */ From e5275e1ec3b1b970ba936aa60e3e1fd9ed0ea60a Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 19 Nov 2026 13:14:42 -0800 Subject: [PATCH 21/34] Roll v8/ bb54fc4e8..b5156d2a7 (305 commits) https://chromium.googlesource.com/v8/v8.git/+log/bb54fc4e853a..b5156d2a71b5 Version 15.9.100 Created with: roll-dep v8 Change-Id: I46e8a449cd645bae3c84810b3dcd7bb080e1c675 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165071 Commit-Queue: Lei Zhang Reviewed-by: Andy Phan --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 4b2deec2c..074ae9a1a 100644 --- a/DEPS +++ b/DEPS @@ -268,7 +268,7 @@ vars = { # Three lines of non-changing comments so that # the commit queue can handle CLs rolling v8 # and whatever else without interference from each other. - 'v8_revision': 'bb54fc4e853a1ef1640b160e5e854d0a3b514e29', + 'v8_revision': 'b5156d2a71b52cab0b53a82a165c77612179098b', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling zlib # and whatever else without interference from each other. From fcdc443487be7095bb56736cc691f04f8b7b2b16 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 20 Nov 2026 09:00:10 -0800 Subject: [PATCH 22/34] Remove unnecessary CFFL_TextObject::OnChar() overrides CFFL_ComboBox::OnChar() and CFFL_ListBox::OnChar() have implementations that just call CFFL_TextObject::OnChar(), which is unnecessary. Delete them. Change-Id: Ib1fdd7dddd62c038c6c73249130946e3670cba80 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165150 Reviewed-by: Tom Sepez Commit-Queue: Lei Zhang --- fpdfsdk/formfiller/cffl_combobox.cpp | 6 ------ fpdfsdk/formfiller/cffl_combobox.h | 3 --- fpdfsdk/formfiller/cffl_listbox.cpp | 6 ------ fpdfsdk/formfiller/cffl_listbox.h | 3 --- 4 files changed, 18 deletions(-) diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp index ab1f3d3bc..6c8e3c2e8 100644 --- a/fpdfsdk/formfiller/cffl_combobox.cpp +++ b/fpdfsdk/formfiller/cffl_combobox.cpp @@ -63,12 +63,6 @@ std::unique_ptr CFFL_ComboBox::NewPWLWindow( return pWnd; } -bool CFFL_ComboBox::OnChar(CPDFSDK_Widget* pWidget, - uint32_t nChar, - Mask nFlags) { - return CFFL_TextObject::OnChar(pWidget, nChar, nFlags); -} - bool CFFL_ComboBox::IsDataChanged(const CPDFSDK_PageView* pPageView) { auto* pWnd = GetPWLComboBox(pPageView); if (!pWnd) { diff --git a/fpdfsdk/formfiller/cffl_combobox.h b/fpdfsdk/formfiller/cffl_combobox.h index fd0c6d80f..c659be087 100644 --- a/fpdfsdk/formfiller/cffl_combobox.h +++ b/fpdfsdk/formfiller/cffl_combobox.h @@ -32,9 +32,6 @@ class CFFL_ComboBox final : public CFFL_TextObject { std::unique_ptr NewPWLWindow( const CPWL_Wnd::CreateParams& cp, std::unique_ptr pAttachedData) override; - bool OnChar(CPDFSDK_Widget* pWidget, - uint32_t nChar, - Mask nFlags) override; bool IsDataChanged(const CPDFSDK_PageView* pPageView) override; void SaveData(const CPDFSDK_PageView* pPageView) override; void GetActionData(const CPDFSDK_PageView* pPageView, diff --git a/fpdfsdk/formfiller/cffl_listbox.cpp b/fpdfsdk/formfiller/cffl_listbox.cpp index 9d7662389..900889344 100644 --- a/fpdfsdk/formfiller/cffl_listbox.cpp +++ b/fpdfsdk/formfiller/cffl_listbox.cpp @@ -81,12 +81,6 @@ std::unique_ptr CFFL_ListBox::NewPWLWindow( return pWnd; } -bool CFFL_ListBox::OnChar(CPDFSDK_Widget* pWidget, - uint32_t nChar, - Mask nFlags) { - return CFFL_TextObject::OnChar(pWidget, nChar, nFlags); -} - bool CFFL_ListBox::IsDataChanged(const CPDFSDK_PageView* pPageView) { CPWL_ListBox* pListBox = GetPWLListBox(pPageView); if (!pListBox) { diff --git a/fpdfsdk/formfiller/cffl_listbox.h b/fpdfsdk/formfiller/cffl_listbox.h index d919f7ee3..27a32ef61 100644 --- a/fpdfsdk/formfiller/cffl_listbox.h +++ b/fpdfsdk/formfiller/cffl_listbox.h @@ -26,9 +26,6 @@ class CFFL_ListBox final : public CFFL_TextObject { std::unique_ptr NewPWLWindow( const CPWL_Wnd::CreateParams& cp, std::unique_ptr pAttachedData) override; - bool OnChar(CPDFSDK_Widget* pWidget, - uint32_t nChar, - Mask nFlags) override; bool IsDataChanged(const CPDFSDK_PageView* pPageView) override; void SaveData(const CPDFSDK_PageView* pPageView) override; void GetActionData(const CPDFSDK_PageView* pPageView, From b5232dabe03a801e894a72f8b22f6adaa1673c82 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 20 Nov 2026 09:53:12 -0800 Subject: [PATCH 23/34] Fix gn check --check-generated cycle for skrifa_cxx Move skrifa/src/outlines.h out of :skrifa_cxx_cpp into a header-only source_set (:skrifa_cxx_outlines_h) with public_deps on //build/rust:cxx_cppdeps, and add it to public_deps of :skrifa_cxx so rust_target.gni forwards it to :skrifa_cxx_cxx_generated. Fixed: 588163918 Change-Id: I2ee34dff2debd7cf8ff324dff832b324c84fbf60 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165210 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fxge/BUILD.gn | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn index 51ad9754d..97725967a 100644 --- a/core/fxge/BUILD.gn +++ b/core/fxge/BUILD.gn @@ -230,6 +230,12 @@ source_set("fxge") { } if (pdf_enable_fontations) { + source_set("skrifa_cxx_outlines_h") { + sources = [ "skrifa/src/outlines.h" ] + visibility = [ ":*" ] + public_deps = [ "//build/rust:cxx_cppdeps" ] + } + rust_static_library("skrifa_cxx") { crate_name = "skrifa_cxx" allow_unsafe = true @@ -242,14 +248,12 @@ if (pdf_enable_fontations) { "//third_party/rust/read_fonts/v0_47:lib", "//third_party/rust/skrifa/v0_50:lib", ] + public_deps = [ ":skrifa_cxx_outlines_h" ] configs += [ "../../:pdfium_common_config" ] } source_set("skrifa_cxx_cpp") { - sources = [ - "skrifa/src/outlines.cpp", - "skrifa/src/outlines.h", - ] + sources = [ "skrifa/src/outlines.cpp" ] deps = [ ":skrifa_cxx", "//build/rust:cxx_cppdeps", From b1a236fed093e71dd4692bc82ab8a52052578bfe Mon Sep 17 00:00:00 2001 From: April Kallmeyer Date: Fri, 20 Nov 2026 11:48:03 -0800 Subject: [PATCH 24/34] Create ScopedFPDFXObject Also use it in the only two places it is applicable in PDFium. Change-Id: I5d08b4b75dddb480f0311366feedb41674d4797d Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165270 Auto-Submit: April Kallmeyer Commit-Queue: April Kallmeyer Commit-Queue: Lei Zhang Reviewed-by: Lei Zhang --- fpdfsdk/fpdf_ppo_embeddertest.cpp | 15 ++++++--------- public/cpp/fpdf_deleters.h | 5 +++++ public/cpp/fpdf_scopers.h | 4 ++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/fpdfsdk/fpdf_ppo_embeddertest.cpp b/fpdfsdk/fpdf_ppo_embeddertest.cpp index adaf33664..58c8b8970 100644 --- a/fpdfsdk/fpdf_ppo_embeddertest.cpp +++ b/fpdfsdk/fpdf_ppo_embeddertest.cpp @@ -167,8 +167,8 @@ TEST_F(FPDFPPOEmbedderTest, ImportPageToXObject) { ScopedFPDFDocument output_doc(FPDF_CreateNewDocument()); ASSERT_TRUE(output_doc); - FPDF_XOBJECT xobject = - FPDF_NewXObjectFromPage(output_doc.get(), document(), 0); + ScopedFPDFXObject xobject( + FPDF_NewXObjectFromPage(output_doc.get(), document(), 0)); ASSERT_TRUE(xobject); // After creating `xobject`, the source document is no longer required. @@ -179,7 +179,8 @@ TEST_F(FPDFPPOEmbedderTest, ImportPageToXObject) { ScopedFPDFPage page(FPDFPage_New(output_doc.get(), 0, 612, 792)); ASSERT_TRUE(page); - FPDF_PAGEOBJECT page_object = FPDF_NewFormObjectFromXObject(xobject); + FPDF_PAGEOBJECT page_object = + FPDF_NewFormObjectFromXObject(xobject.get()); ASSERT_TRUE(page_object); EXPECT_EQ(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(page_object)); FPDFPage_InsertObject(page.get(), page_object); @@ -201,8 +202,6 @@ TEST_F(FPDFPPOEmbedderTest, ImportPageToXObject) { } EXPECT_TRUE(FPDF_SaveAsCopy(output_doc.get(), this, 0)); - - FPDF_CloseXObject(xobject); } static constexpr int kExpectedPageCount = 2; @@ -256,7 +255,7 @@ TEST_F(FPDFPPOEmbedderTest, ImportPageToXObject) { TEST_F(FPDFPPOEmbedderTest, ImportPageToXObjectWithSameDoc) { ASSERT_TRUE(OpenDocument("rectangles.pdf")); - FPDF_XOBJECT xobject = FPDF_NewXObjectFromPage(document(), document(), 0); + ScopedFPDFXObject xobject(FPDF_NewXObjectFromPage(document(), document(), 0)); ASSERT_TRUE(xobject); ScopedPage page = LoadScopedPage(0); @@ -264,7 +263,7 @@ TEST_F(FPDFPPOEmbedderTest, ImportPageToXObjectWithSameDoc) { CompareDisplayList(RenderLoadedPageToDisplayList(page.get()), "rectangles"); - FPDF_PAGEOBJECT page_object = FPDF_NewFormObjectFromXObject(xobject); + FPDF_PAGEOBJECT page_object = FPDF_NewFormObjectFromXObject(xobject.get()); ASSERT_TRUE(page_object); ASSERT_EQ(FPDF_PAGEOBJ_FORM, FPDFPageObj_GetType(page_object)); @@ -277,8 +276,6 @@ TEST_F(FPDFPPOEmbedderTest, ImportPageToXObjectWithSameDoc) { CompareDisplayList(RenderLoadedPageToDisplayList(page.get()), "import_page_to_xobject_with_same_doc"); - FPDF_CloseXObject(xobject); - EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); VerifySavedDocumentWithDisplayList("import_page_to_xobject_with_same_doc"); diff --git a/public/cpp/fpdf_deleters.h b/public/cpp/fpdf_deleters.h index d58f8d593..60d875105 100644 --- a/public/cpp/fpdf_deleters.h +++ b/public/cpp/fpdf_deleters.h @@ -10,6 +10,7 @@ #include "public/fpdf_edit.h" #include "public/fpdf_formfill.h" #include "public/fpdf_javascript.h" +#include "public/fpdf_ppo.h" #include "public/fpdf_structtree.h" #include "public/fpdf_text.h" #include "public/fpdf_transformpage.h" @@ -83,4 +84,8 @@ struct FPDFTextPageDeleter { inline void operator()(FPDF_TEXTPAGE text) { FPDFText_ClosePage(text); } }; +struct FPDFXObjectDeleter { + inline void operator()(FPDF_XOBJECT xobj) { FPDF_CloseXObject(xobj); } +}; + #endif // PUBLIC_CPP_FPDF_DELETERS_H_ diff --git a/public/cpp/fpdf_scopers.h b/public/cpp/fpdf_scopers.h index fd9ce6997..08763e0be 100644 --- a/public/cpp/fpdf_scopers.h +++ b/public/cpp/fpdf_scopers.h @@ -64,4 +64,8 @@ using ScopedFPDFTextPage = std::unique_ptr::type, FPDFTextPageDeleter>; +using ScopedFPDFXObject = + std::unique_ptr::type, + FPDFXObjectDeleter>; + #endif // PUBLIC_CPP_FPDF_SCOPERS_H_ From 30f1c04da5fd75f4c9b05b1a207e58912e0a0bdb Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 20 Nov 2026 11:51:56 -0800 Subject: [PATCH 25/34] Remove obsolete fxge.SkiaStateText embedder test The deferred SkiaState batching and clip-caching layer that this test verified no longer exists in CFX_SkiaDeviceDriver, which now forwards drawing and state calls directly to SkCanvas. Relying on an aliased .notdef glyph from a substituted ShiftJIS font hitting pixel (0, 0) also made the test sensitive to font-backend rasterization differences under Fontations. -- Turn off other features no longer required by tests. Change-Id: I1d9fc9a8fcbd0fc9994faf7ff60986b68a13937c Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164911 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- .../fxge/skia/fx_skia_device_embeddertest.cpp | 41 +------------------ 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/core/fxge/skia/fx_skia_device_embeddertest.cpp b/core/fxge/skia/fx_skia_device_embeddertest.cpp index 26c8a9d27..d23b28d39 100644 --- a/core/fxge/skia/fx_skia_device_embeddertest.cpp +++ b/core/fxge/skia/fx_skia_device_embeddertest.cpp @@ -10,16 +10,12 @@ #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/render/cpdf_pagerendercontext.h" -#include "core/fxcrt/fx_codepage.h" #include "core/fxge/cfx_fillrenderoptions.h" -#include "core/fxge/cfx_font.h" #include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_graphstatedata.h" #include "core/fxge/cfx_path.h" #include "core/fxge/cfx_renderdevice.h" -#include "core/fxge/cfx_textrenderoptions.h" #include "core/fxge/dib/cfx_dibitmap.h" -#include "core/fxge/text_char_pos.h" #include "fpdfsdk/cpdfsdk_helpers.h" #include "fpdfsdk/cpdfsdk_renderpage.h" #include "public/cpp/fpdf_scopers.h" @@ -42,7 +38,7 @@ struct State { enum class Change { kNo, kYes }; enum class Save { kNo, kYes }; enum class Clip { kNo, kSame, kDifferentPath, kDifferentMatrix }; - enum class Graphic { kNone, kPath, kText }; + enum class Graphic { kNone, kPath }; Change change_; Save save_; @@ -58,17 +54,6 @@ void EmptyTest(CFX_SkiaDeviceDriver* driver, const State&) { } void CommonTest(CFX_SkiaDeviceDriver* driver, const State& state) { - TextCharPos charPos = { - .origin_ = CFX_PointF(0, 1), - .glyph_index_ = 0, - .font_char_width_ = 4, - }; - - CFX_Font font; - font.LoadSubstFace("Courier", /*bTrueType=*/true, /*flags=*/0, - /*weight=*/400, /*italic_angle=*/0, FX_CodePage::kShiftJIS, - /*bVertical=*/false); - float fontSize = 20; CFX_Path clipPath; CFX_Path clipPath2; clipPath.AppendRect(0, 0, 3, 1); @@ -83,10 +68,6 @@ void CommonTest(CFX_SkiaDeviceDriver* driver, const State& state) { CFX_Matrix matrix2; matrix2.Translate(1, 0); CFX_GraphStateData graphState; - // Turn off anti-aliasing so that pixels with transitional colors can be - // avoided. - static constexpr CFX_TextRenderOptions kTextOptions( - CFX_TextRenderOptions::kAliasing); if (state.save_ == State::Save::kYes) { driver->SaveState(); } @@ -97,9 +78,6 @@ void CommonTest(CFX_SkiaDeviceDriver* driver, const State& state) { driver->DrawPath(path1, &matrix, &graphState, 0xFF112233, 0, /*group_knockout=*/false, CFX_FillRenderOptions::WindingOptions()); - } else if (state.graphic_ == State::Graphic::kText) { - driver->DrawDeviceText(pdfium::span_from_ref(charPos), &font, matrix, - fontSize, 0xFF445566, kTextOptions); } if (state.save_ == State::Save::kYes) { driver->RestoreState(true); @@ -109,8 +87,6 @@ void CommonTest(CFX_SkiaDeviceDriver* driver, const State& state) { if (state.change_ == State::Change::kYes) { if (state.graphic_ == State::Graphic::kPath) { graphState.set_line_cap(CFX_GraphStateData::LineCap::kRound); - } else if (state.graphic_ == State::Graphic::kText) { - fontSize = 2; } } if (state.clip_ == State::Clip::kSame) { @@ -124,9 +100,6 @@ void CommonTest(CFX_SkiaDeviceDriver* driver, const State& state) { driver->DrawPath(path2, &matrix2, &graphState, 0xFF112233, 0, /*group_knockout=*/false, CFX_FillRenderOptions::WindingOptions()); - } else if (state.graphic_ == State::Graphic::kText) { - driver->DrawDeviceText(pdfium::span_from_ref(charPos), &font, matrix2, - fontSize, 0xFF445566, kTextOptions); } if (state.save_ == State::Save::kYes) { driver->RestoreState(false); @@ -238,18 +211,6 @@ TEST(fxge, SkiaStatePath) { State::Graphic::kPath, 0xFF112233}); } -TEST(fxge, SkiaStateText) { - if (!CFX_GEModule::IsSkiaRenderer()) { - return; - } - - Harness(&CommonTest, - {State::Change::kNo, State::Save::kYes, State::Clip::kDifferentMatrix, - State::Graphic::kText, 0xFF445566}); - Harness(&CommonTest, {State::Change::kNo, State::Save::kYes, - State::Clip::kSame, State::Graphic::kText, 0xFF445566}); -} - TEST(fxge, SkiaStateOOSClip) { if (!CFX_GEModule::IsSkiaRenderer()) { return; From 171c17bfd426d6cb76cff2e8bd0cd790739966a8 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 20 Nov 2026 13:24:01 -0800 Subject: [PATCH 26/34] Remove skrifa demo outlines.{h,cpp} and extern C++ bridge Nothing in Rust calls skrifa::run; only FxSkrifaTest.TestFoxitFixedCff calls it from C++. Move the assertions into fx_skrifa_unittest.cpp using GTest macros, remove the extern "C++" block and unused main() from main.rs, and delete outlines.h, outlines.cpp, and the :skrifa_cxx_cpp and :skrifa_cxx_outlines_h GN targets. Follow-on CL from https://pdfium-review.googlesource.com/165210 for easy rollback to that safe CL if needed. -- Improve test assertions. Change-Id: Ia971602c25d4f38a742b443fab4b060569f1b232 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165230 Reviewed-by: Lei Zhang Commit-Queue: Tom Sepez --- core/fxge/BUILD.gn | 23 ----- core/fxge/skrifa/fx_skrifa_unittest.cpp | 50 +++++++++- core/fxge/skrifa/src/main.rs | 9 -- core/fxge/skrifa/src/outlines.cpp | 124 ------------------------ core/fxge/skrifa/src/outlines.h | 11 --- 5 files changed, 48 insertions(+), 169 deletions(-) delete mode 100644 core/fxge/skrifa/src/outlines.cpp delete mode 100644 core/fxge/skrifa/src/outlines.h diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn index 97725967a..2b46c649b 100644 --- a/core/fxge/BUILD.gn +++ b/core/fxge/BUILD.gn @@ -169,7 +169,6 @@ source_set("fxge") { if (pdf_enable_fontations) { deps += [ ":skrifa_cxx", - ":skrifa_cxx_cpp", "//build/rust:cxx_cppdeps", ] } @@ -230,12 +229,6 @@ source_set("fxge") { } if (pdf_enable_fontations) { - source_set("skrifa_cxx_outlines_h") { - sources = [ "skrifa/src/outlines.h" ] - visibility = [ ":*" ] - public_deps = [ "//build/rust:cxx_cppdeps" ] - } - rust_static_library("skrifa_cxx") { crate_name = "skrifa_cxx" allow_unsafe = true @@ -248,23 +241,8 @@ if (pdf_enable_fontations) { "//third_party/rust/read_fonts/v0_47:lib", "//third_party/rust/skrifa/v0_50:lib", ] - public_deps = [ ":skrifa_cxx_outlines_h" ] configs += [ "../../:pdfium_common_config" ] } - - source_set("skrifa_cxx_cpp") { - sources = [ "skrifa/src/outlines.cpp" ] - deps = [ - ":skrifa_cxx", - "//build/rust:cxx_cppdeps", - ] - configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ - "//build/config/compiler:no_chromium_code", - "../../:pdfium_common_config", - ] - visibility = [ ":*" ] - } } source_set("test_support") { @@ -344,7 +322,6 @@ pdfium_unittest_source_set("unittests") { sources += [ "skrifa/fx_skrifa_unittest.cpp" ] deps += [ ":skrifa_cxx", - ":skrifa_cxx_cpp", "//build/rust:cxx_cppdeps", ] } diff --git a/core/fxge/skrifa/fx_skrifa_unittest.cpp b/core/fxge/skrifa/fx_skrifa_unittest.cpp index c549e5e0b..d4334888b 100644 --- a/core/fxge/skrifa/fx_skrifa_unittest.cpp +++ b/core/fxge/skrifa/fx_skrifa_unittest.cpp @@ -3,12 +3,14 @@ // found in the LICENSE file. #include +#include #include #include #include #include "core/fxcrt/cfx_read_only_span_stream.h" #include "core/fxcrt/compiler_specific.h" +#include "core/fxcrt/span.h" #include "core/fxge/cfx_face.h" #include "core/fxge/cfx_gemodule.h" #include "core/fxge/cfx_glyphbitmap.h" @@ -18,14 +20,58 @@ #include "core/fxge/fx_font.h" #include "core/fxge/fx_fontencoding.h" #include "core/fxge/skrifa/src/main.rs.h" -#include "core/fxge/skrifa/src/outlines.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/utils/file_util.h" #include "testing/utils/path_service.h" TEST(FxSkrifaTest, TestFoxitFixedCff) { std::string font_path = PathService::GetTestFilePath("fonts/foxit_fixed.cff"); - skrifa::run(rust::Str(font_path)); + std::vector bytes = GetFileContents(font_path.c_str()); + + auto font = skrifa::new_font(rust::Slice(bytes), 0); + ASSERT_TRUE(font->is_ok()); + + EXPECT_EQ(font->postscript_name(), "ChromFixedOTF"); + EXPECT_EQ(font->family_name(), "Chrom Fixed OTF"); + EXPECT_EQ(font->font_type(), skrifa::FaceFormat::Cff); + EXPECT_FALSE(font->is_sfnt()); + EXPECT_FALSE(font->is_fixed_pitch()); + EXPECT_EQ(font->units_per_em(), 1000); + EXPECT_EQ(font->num_glyphs(), 244u); + EXPECT_EQ(font->encoding(), skrifa::PsEncodingKind::Standard); + EXPECT_TRUE(font->has_glyph_names()); + + uint32_t gid_from_code = font->code_to_gid(120); + uint32_t gid = font->unicode_to_gid('x'); + EXPECT_EQ(gid_from_code, gid); + EXPECT_EQ(font->glyph_name(gid), "x"); + EXPECT_EQ(font->name_index("x"), gid); + + uint32_t gid_a = font->code_to_gid('A'); + EXPECT_NE(gid_a, 0u); + EXPECT_NE(gid_a, gid); + EXPECT_EQ(font->unicode_to_gid('A'), gid_a); + EXPECT_EQ(font->glyph_name(gid_a), "A"); + + skrifa::Outline outline; + EXPECT_TRUE(font->unscaled_outline(gid, outline)); + EXPECT_EQ(outline.verbs.size(), 29u); + EXPECT_EQ(outline.points.size(), 28u); + EXPECT_FLOAT_EQ(outline.advance_width, 600.0f); + + EXPECT_TRUE(font->scaled_outline(gid, 16.0f, outline)); + EXPECT_EQ(outline.verbs.size(), 29u); + EXPECT_EQ(outline.points.size(), 28u); + EXPECT_FLOAT_EQ(outline.advance_width, 9.59375f); + + uint32_t period_unicode = 0; + EXPECT_TRUE(skrifa::agl_name_to_unicode("period", period_unicode)); + EXPECT_EQ(period_unicode, static_cast('.')); + + std::array period_name = {}; + auto period_slice = + skrifa::agl_unicode_to_name('.', rust::Slice(period_name)); + EXPECT_EQ(ByteStringView(period_slice), "period"); } TEST(FxSkrifaTest, TestGetOs2CodePageRange) { diff --git a/core/fxge/skrifa/src/main.rs b/core/fxge/skrifa/src/main.rs index acffb7037..4c904a4ee 100644 --- a/core/fxge/skrifa/src/main.rs +++ b/core/fxge/skrifa/src/main.rs @@ -169,12 +169,6 @@ mod skrifa_ffi { fn agl_unicode_to_name(unicode: u32, name: &mut [u8]) -> &[u8]; fn get_num_faces(data: &[u8]) -> u32; } - - unsafe extern "C++" { - include!("core/fxge/skrifa/src/outlines.h"); - - fn run(font_path: &str); - } } use skrifa_ffi::{ @@ -1070,6 +1064,3 @@ fn get_num_faces(data: &[u8]) -> u32 { } 0 } -fn main() { - skrifa_ffi::run(""); -} diff --git a/core/fxge/skrifa/src/outlines.cpp b/core/fxge/skrifa/src/outlines.cpp deleted file mode 100644 index a5b475f8c..000000000 --- a/core/fxge/skrifa/src/outlines.cpp +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright 2026 The PDFium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// Based on https://github.com/googlefonts/fontations/pull/1820 - -#include "core/fxge/skrifa/src/outlines.h" - -#include -#include - -#include -#include -#include -#include -#include - -#include "core/fxge/skrifa/src/main.rs.h" - -void dump_outline(skrifa::Outline& outline); - -void skrifa::run(rust::Str font_path) { - // Load the font data - std::string path_str(font_path.data(), font_path.size()); - std::ifstream input(path_str, std::ios::binary); - std::vector bytes((std::istreambuf_iterator(input)), - (std::istreambuf_iterator())); - input.close(); - - rust::Slice slice(bytes); - - // Load the font. Note that the bytes vector must live as long as the font - auto font = skrifa::new_font(slice, 0); - if (!font->is_ok()) { - printf("Failed to load font!\n"); - return; - } - - // Get the PostScript name - std::string name(font->postscript_name()); - - // And the family name - auto family_name = std::string(font->family_name()); - - printf("ps name = %s, family name = %s\n", name.c_str(), family_name.c_str()); - - // How many glyphs? - printf("Font has %d glyphs\n", font->num_glyphs()); - - // The font's encoding is Adobe standard - assert(font->encoding() == PsEncodingKind::Standard); - - // The Adobe standard code for 'x' is 120 - auto gid_from_code = font->code_to_gid(120); - - // But we also generate a Unicode mapping for glyphs present in the AGL - auto gid = font->unicode_to_gid('x'); - - assert(gid_from_code == gid); - - // Storage for our outline - skrifa::Outline outline; - - // Load an unscaled outline - font->unscaled_outline(gid, outline); - dump_outline(outline); - - // Load the same outline at 16px - font->scaled_outline(gid, 16.0, outline); - dump_outline(outline); - - // Convert glyph name to unicode - uint32_t period_unicode; - assert(skrifa::agl_name_to_unicode("period", period_unicode)); - assert(period_unicode == '.'); - - // Convert unicode to glyph name - uint8_t period_name[64] = {}; - auto period_slice = - skrifa::agl_unicode_to_name('.', rust::Slice(period_name, 40)); - assert(std::string_view(reinterpret_cast(period_slice.data()), - period_slice.size()) == "period"); -} - -void dump_outline(skrifa::Outline& outline) { - auto point_idx = 0; - for (auto verb : outline.verbs) { - switch (verb) { - case skrifa::PathVerb::MoveTo: { - auto p = outline.points[point_idx]; - point_idx += 1; - printf("M%f,%f ", p.x, p.y); - break; - } - case skrifa::PathVerb::LineTo: { - auto p = outline.points[point_idx]; - point_idx += 1; - printf("L%f,%f ", p.x, p.y); - break; - } - case skrifa::PathVerb::QuadTo: { - auto c0 = outline.points[point_idx]; - auto p = outline.points[point_idx + 1]; - point_idx += 2; - printf("Q%f,%f %f,%f ", c0.x, c0.y, p.x, p.y); - break; - } - case skrifa::PathVerb::CurveTo: { - auto c0 = outline.points[point_idx]; - auto c1 = outline.points[point_idx + 1]; - auto p = outline.points[point_idx + 2]; - point_idx += 3; - printf("C%f,%f %f,%f %f,%f ", c0.x, c0.y, c1.x, c1.y, p.x, p.y); - break; - } - case skrifa::PathVerb::Close: - printf("Z"); - break; - default: - break; - } - } - printf("\nadvance = %f\n", outline.advance_width); -} diff --git a/core/fxge/skrifa/src/outlines.h b/core/fxge/skrifa/src/outlines.h deleted file mode 100644 index 58f3c7b9c..000000000 --- a/core/fxge/skrifa/src/outlines.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2026 The PDFium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. -// -// Based on https://github.com/googlefonts/fontations/pull/1820 - -#pragma once -#include "third_party/rust/chromium_crates_io/vendor/cxx-v1/include/cxx.h" -namespace skrifa { -void run(rust::Str font_path); -} From 0fb188cc6c5baf18b9dde2ac513d49e8c41f7e5f Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 20 Nov 2026 14:26:13 -0800 Subject: [PATCH 27/34] Split CPDF_Document::DestructionObserverIface from Observable CPDF_DataAvail was the only non-ObservedPtr class implementing Observable::ObserverIface. Add CPDF_Document::DestructionObserverIface with OnObservableDestroyed() and migrate CPDF_DataAvail to use it. This is a prequel to devirtualizing ObservedPtr. Change-Id: I79c103f9a01117ad846db656d3917b6a5f69e04c Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165231 Reviewed-by: Andy Phan Commit-Queue: Tom Sepez --- core/fpdfapi/parser/cpdf_data_avail.cpp | 6 +++--- core/fpdfapi/parser/cpdf_data_avail.h | 6 +++--- core/fpdfapi/parser/cpdf_document.cpp | 27 +++++++++++++++++++++++++ core/fpdfapi/parser/cpdf_document.h | 26 ++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index 305eb7b8b..cfa69c46c 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -84,11 +84,11 @@ CPDF_DataAvail::CPDF_DataAvail(FileAvail* pFileAvail, CPDF_DataAvail::~CPDF_DataAvail() { hint_tables_.reset(); if (document_) { - document_->RemoveObserver(this); + document_->RemoveDestructionObserver(this); } } -void CPDF_DataAvail::OnObservableDestroyed() { +void CPDF_DataAvail::OnDocumentDestroyed() { document_ = nullptr; form_avail_.reset(); pages_array_.clear(); @@ -1096,7 +1096,7 @@ CPDF_DataAvail::ParseDocument( } auto document = std::make_unique(std::move(pRenderData), std::move(pPageData)); - document->AddObserver(this); + document->AddDestructionObserver(this); CPDF_ReadValidator::ScopedSession read_session(GetValidator()); CPDF_Parser::Error error = diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index 15f29cd70..e295d2b69 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -28,7 +28,7 @@ class CPDF_PageObjectAvail; class CPDF_ReadValidator; class CPDF_SyntaxParser; -class CPDF_DataAvail final : public Observable::ObserverIface { +class CPDF_DataAvail final : public CPDF_Document::DestructionObserverIface { public: // Must match PDF_DATA_* definitions in public/fpdf_dataavail.h, but cannot // #include that header. fpdfsdk/fpdf_dataavail.cpp has static_asserts @@ -74,8 +74,8 @@ class CPDF_DataAvail final : public Observable::ObserverIface { RetainPtr pFileRead); ~CPDF_DataAvail() override; - // Observable::ObserverIface: - void OnObservableDestroyed() override; + // CPDF_Document::DestructionObserverIface: + void OnDocumentDestroyed() override; DocAvailStatus IsDocAvail(DownloadHints* pHints); DocAvailStatus IsPageAvail(uint32_t dwPage, DownloadHints* pHints); diff --git a/core/fpdfapi/parser/cpdf_document.cpp b/core/fpdfapi/parser/cpdf_document.cpp index b70120bbb..605e3cdf7 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -190,6 +190,15 @@ CPDF_Document::~CPDF_Document() { extension_.reset(); } +void CPDF_Document::AddDestructionObserver(DestructionObserverIface* observer) { + destruction_notifier_.AddObserver(observer); +} + +void CPDF_Document::RemoveDestructionObserver( + DestructionObserverIface* observer) { + destruction_notifier_.RemoveObserver(observer); +} + // static bool CPDF_Document::IsValidPageObject(const CPDF_Object* obj) { // See ISO 32000-1:2008 spec, table 30. @@ -766,6 +775,24 @@ void CPDF_Document::ResizePageListForTesting(size_t size) { page_list_.resize(size); } +CPDF_Document::DestructionNotifier::DestructionNotifier() = default; + +CPDF_Document::DestructionNotifier::~DestructionNotifier() { + for (auto* observer : observers_) { + observer->OnDocumentDestroyed(); + } +} + +void CPDF_Document::DestructionNotifier::AddObserver( + DestructionObserverIface* observer) { + CHECK(observers_.insert(observer).second); +} + +void CPDF_Document::DestructionNotifier::RemoveObserver( + DestructionObserverIface* observer) { + CHECK_EQ(observers_.erase(observer), 1u); +} + CPDF_Document::StockFontClearer::StockFontClearer( CPDF_Document::PageDataIface* pPageData) : page_data_(pPageData) {} diff --git a/core/fpdfapi/parser/cpdf_document.h b/core/fpdfapi/parser/cpdf_document.h index cd8f91a2c..400e18e84 100644 --- a/core/fpdfapi/parser/cpdf_document.h +++ b/core/fpdfapi/parser/cpdf_document.h @@ -46,6 +46,12 @@ class CPDF_Document : public Observable, virtual ~LinkListIface() = default; }; + class DestructionObserverIface { + public: + virtual ~DestructionObserverIface() = default; + virtual void OnDocumentDestroyed() = 0; + }; + class PageDataIface { public: PageDataIface(); @@ -94,6 +100,9 @@ class CPDF_Document : public Observable, extension_ = std::move(pExt); } + void AddDestructionObserver(DestructionObserverIface* observer); + void RemoveDestructionObserver(DestructionObserverIface* observer); + CPDF_Parser* GetParser() const { return parser_.get(); } const CPDF_Dictionary* GetRoot() const { return root_dict_.Get(); } RetainPtr GetMutableRoot() { return root_dict_; } @@ -170,6 +179,20 @@ class CPDF_Document : public Observable, void ResizePageListForTesting(size_t size); private: + class DestructionNotifier { + public: + DestructionNotifier(); + DestructionNotifier(const DestructionNotifier&) = delete; + DestructionNotifier& operator=(const DestructionNotifier&) = delete; + ~DestructionNotifier(); + + void AddObserver(DestructionObserverIface* observer); + void RemoveObserver(DestructionObserverIface* observer); + + private: + std::set observers_; + }; + class [[maybe_unused, nodiscard]] StockFontClearer { public: FX_STACK_ALLOCATED(); @@ -214,6 +237,9 @@ class CPDF_Document : public Observable, void ResetTraversal(); CPDF_Parser::Error HandleLoadResult(CPDF_Parser::Error error); + // Must be first, so it is destroyed after all other members. + DestructionNotifier destruction_notifier_; + std::unique_ptr parser_; RetainPtr root_dict_; RetainPtr info_dict_; From b47c2e370e4739a4d978630e3e4cf3877f857302 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 20 Nov 2026 14:52:56 -0800 Subject: [PATCH 28/34] Devirtualize ObservedPtr via ObservedPtrBase Now that ObservedPtr is the sole consumer of Observable notifications, replace Observable::ObserverIface with a non-virtual ObservedPtrBase. ObservedPtr shrinks by one vptr and Observable::NotifyObservers() zeros out observable_ directly without virtual dispatch. Change-Id: Id5be3c44faef3b8c1d2d020594b37edc02a24984 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165232 Commit-Queue: Tom Sepez Reviewed-by: Andy Phan --- core/fxcrt/observed_ptr.cpp | 4 +-- core/fxcrt/observed_ptr.h | 63 ++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/core/fxcrt/observed_ptr.cpp b/core/fxcrt/observed_ptr.cpp index a9b8030cc..89a02a7ae 100644 --- a/core/fxcrt/observed_ptr.cpp +++ b/core/fxcrt/observed_ptr.cpp @@ -15,12 +15,12 @@ Observable::~Observable() { NotifyObservers(); } -void Observable::AddObserver(ObserverIface* pObserver) { +void Observable::AddObserver(ObservedPtrBase* pObserver) { DCHECK(!pdfium::Contains(observers_, pObserver)); observers_.insert(pObserver); } -void Observable::RemoveObserver(ObserverIface* pObserver) { +void Observable::RemoveObserver(ObservedPtrBase* pObserver) { DCHECK(pdfium::Contains(observers_, pObserver)); observers_.erase(pObserver); } diff --git a/core/fxcrt/observed_ptr.h b/core/fxcrt/observed_ptr.h index 7b93b1257..fda88772b 100644 --- a/core/fxcrt/observed_ptr.h +++ b/core/fxcrt/observed_ptr.h @@ -14,29 +14,43 @@ namespace fxcrt { -class Observable { +class ObservedPtrBase { public: - // General-purpose interface for more complicated cleanup. - class ObserverIface { - public: - virtual ~ObserverIface() = default; - virtual void OnObservableDestroyed() = 0; - }; + ObservedPtrBase(const ObservedPtrBase&) = delete; + ObservedPtrBase& operator=(const ObservedPtrBase&) = delete; + + protected: + ObservedPtrBase() = default; + explicit ObservedPtrBase(void* observable) : observable_(observable) {} + ~ObservedPtrBase() = default; + + UNOWNED_PTR_EXCLUSION void* observable_ = nullptr; + + private: + friend class Observable; + + void OnObservableDestroyed() { + DCHECK(observable_); + observable_ = nullptr; + } +}; +class Observable { + public: Observable(); Observable(const Observable& that) = delete; Observable& operator=(const Observable& that) = delete; ~Observable(); - void AddObserver(ObserverIface* pObserver); - void RemoveObserver(ObserverIface* pObserver); + void AddObserver(ObservedPtrBase* pObserver); + void RemoveObserver(ObservedPtrBase* pObserver); void NotifyObservers(); protected: size_t ActiveObserversForTesting() const { return observers_.size(); } private: - std::set observers_; + std::set observers_; }; // Simple case of a self-nulling pointer. @@ -46,33 +60,29 @@ class Observable { // best practice is to only refer to that object by the UnownedPtr<> and // not the original reference. template -class ObservedPtr final : public Observable::ObserverIface { +class ObservedPtr final : public ObservedPtrBase { public: ObservedPtr() = default; - explicit ObservedPtr(T* pObservable) : observable_(pObservable) { + explicit ObservedPtr(T* pObservable) : ObservedPtrBase(pObservable) { if (observable_) { - observable_->AddObserver(this); + Get()->AddObserver(this); } } ObservedPtr(const ObservedPtr& that) : ObservedPtr(that.Get()) {} - ~ObservedPtr() override { + ~ObservedPtr() { if (observable_) { - observable_->RemoveObserver(this); + Get()->RemoveObserver(this); } } void Reset(T* pObservable = nullptr) { if (observable_) { - observable_->RemoveObserver(this); + Get()->RemoveObserver(this); } observable_ = pObservable; if (observable_) { - observable_->AddObserver(this); + Get()->AddObserver(this); } } - void OnObservableDestroyed() override { - DCHECK(observable_); - observable_ = nullptr; - } bool HasObservable() const { return !!observable_; } ObservedPtr& operator=(const ObservedPtr& that) { Reset(that.Get()); @@ -85,16 +95,13 @@ class ObservedPtr final : public Observable::ObserverIface { template friend inline bool operator==(const ObservedPtr& lhs, const U* rhs) { - return lhs.observable_ == rhs; + return lhs.Get() == rhs; } explicit operator bool() const { return HasObservable(); } - T* Get() const { return observable_; } - T& operator*() const { return *observable_; } - T* operator->() const { return observable_; } - - private: - UNOWNED_PTR_EXCLUSION T* observable_ = nullptr; + T* Get() const { return static_cast(observable_); } + T& operator*() const { return *Get(); } + T* operator->() const { return Get(); } }; } // namespace fxcrt From afcec981f67b471bff54787331fd7c4d3635107e Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 20 Nov 2026 16:09:54 -0800 Subject: [PATCH 29/34] Replace EmbedderTest::HashBitmap() with BitmapsEqual() All remaining callers of EmbedderTest::HashBitmap() only compare two in-memory bitmaps against each other rather than against hardcoded MD5 strings. Replace HashBitmap() with BitmapsEqual() in EmbedderTest to compare bitmap dimensions, formats, and row pixel data directly, and drop the core/fdrm dependency from testing:embedder_test_support. Change-Id: I852564da09f4664bc27a5ffb1c65eb8517e2664c Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165191 Commit-Queue: Tom Sepez Reviewed-by: Andy Phan --- fpdfsdk/fpdf_edit_embeddertest.cpp | 43 +++++++++------------ fpdfsdk/fpdf_formfill_embeddertest.cpp | 6 +-- fpdfsdk/fpdf_ppo_embeddertest.cpp | 53 +++++++++++++++----------- fpdfsdk/fpdf_save_embeddertest.cpp | 10 ++--- fpdfsdk/fpdf_view_embeddertest.cpp | 24 +++++------- testing/BUILD.gn | 1 - testing/embedder_test.cpp | 48 ++++++++++++++--------- testing/embedder_test.h | 6 +-- 8 files changed, 98 insertions(+), 93 deletions(-) diff --git a/fpdfsdk/fpdf_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp index 6c0fe5006..93b0da829 100644 --- a/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/fpdfsdk/fpdf_edit_embeddertest.cpp @@ -5596,22 +5596,20 @@ TEST_F(FPDFEditEmbedderTest, PageObjTransformFWithBadParameters) { class FPDFEditMoveEmbedderTest : public EmbedderTest { protected: - std::vector HashesForDocument(int page_count) { - std::vector hashes; - hashes.reserve(page_count); + std::vector PagesForDocument(int page_count) { + std::vector pages; + pages.reserve(page_count); for (int i = 0; i < page_count; ++i) { - hashes.push_back(HashForPage(i)); + pages.push_back(RenderPageByIndex(i)); } - return hashes; + return pages; } private: - std::string HashForPage(int page_index) { + ScopedFPDFBitmap RenderPageByIndex(int page_index) { ScopedPage page = LoadScopedPage(page_index); EXPECT_TRUE(page); - ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get()); - std::string hash = HashBitmap(bitmap.get()); - return hash; + return RenderLoadedPage(page.get()); } }; @@ -5643,29 +5641,22 @@ TEST_F(FPDFEditMoveEmbedderTest, MovePagesTest) { ASSERT_THAT(tc.expected_order, testing::SizeIs(0)); } - // Cache the original pages' hashes. - std::vector orig_hashes = HashesForDocument(page_count); - ASSERT_THAT(orig_hashes, testing::SizeIs(page_count)); + // Cache the original rendered pages. + std::vector orig_pages = PagesForDocument(page_count); + ASSERT_THAT(orig_pages, testing::SizeIs(page_count)); EXPECT_EQ(FPDF_MovePages(document(), &tc.page_indices[0], tc.page_indices_len, tc.dest_page_index), tc.expected_result) << tc; - if (tc.expected_result) { - // Check for updated page order. - std::vector new_hashes = HashesForDocument(page_count); - std::vector expected_hashes; - expected_hashes.reserve(page_count); - for (int i = 0; i < page_count; ++i) { - expected_hashes.push_back(orig_hashes[tc.expected_order[i]]); - } - EXPECT_THAT(new_hashes, testing::ContainerEq(expected_hashes)) << tc; - } else { - // Check that pages are unchanged. - EXPECT_THAT(HashesForDocument(page_count), - testing::ContainerEq(orig_hashes)) - << tc; + std::vector new_pages = PagesForDocument(page_count); + ASSERT_THAT(new_pages, testing::SizeIs(page_count)); + for (int i = 0; i < page_count; ++i) { + int expected_index = tc.expected_result ? tc.expected_order[i] : i; + EXPECT_TRUE( + BitmapsEqual(new_pages[i].get(), orig_pages[expected_index].get())) + << tc << " page " << i; } CloseDocument(); diff --git a/fpdfsdk/fpdf_formfill_embeddertest.cpp b/fpdfsdk/fpdf_formfill_embeddertest.cpp index a130f75d1..c3a35fb92 100644 --- a/fpdfsdk/fpdf_formfill_embeddertest.cpp +++ b/fpdfsdk/fpdf_formfill_embeddertest.cpp @@ -1689,9 +1689,9 @@ TEST_F(FPDFFormFillEmbedderTest, ScopedFPDFBitmap bitmap_ltr = RenderLoadedPage(page.get()); // Rendering should be visually different when the text direction changes. - EXPECT_NE(HashBitmap(bitmap_auto.get()), HashBitmap(bitmap_rtl.get())); - EXPECT_NE(HashBitmap(bitmap_rtl.get()), HashBitmap(bitmap_ltr.get())); - EXPECT_EQ(HashBitmap(bitmap_auto.get()), HashBitmap(bitmap_ltr.get())); + EXPECT_FALSE(BitmapsEqual(bitmap_auto.get(), bitmap_rtl.get())); + EXPECT_FALSE(BitmapsEqual(bitmap_rtl.get(), bitmap_ltr.get())); + EXPECT_TRUE(BitmapsEqual(bitmap_auto.get(), bitmap_ltr.get())); } TEST_F(FPDFFormFillTextFormEmbedderTest, FormTextFieldBiDiLiveEdit) { diff --git a/fpdfsdk/fpdf_ppo_embeddertest.cpp b/fpdfsdk/fpdf_ppo_embeddertest.cpp index 58c8b8970..d684c73e6 100644 --- a/fpdfsdk/fpdf_ppo_embeddertest.cpp +++ b/fpdfsdk/fpdf_ppo_embeddertest.cpp @@ -35,10 +35,9 @@ namespace { class FPDFPPOEmbedderTest : public EmbedderTest { public: - std::string GetPageChecksum(FPDF_DOCUMENT doc, int index) { + ScopedFPDFBitmap RenderPageBitmap(FPDF_DOCUMENT doc, int index) { ScopedFPDFPage page(FPDF_LoadPage(doc, index)); - auto bitmap = RenderPage(page.get()); - return HashBitmap(bitmap.get()); + return RenderPage(page.get()); } }; @@ -696,10 +695,10 @@ TEST_F(FPDFPPOEmbedderTest, XFAImportTest) { EXPECT_EQ(FPDF_GetFormType(dest_doc), FORMTYPE_XFA_FOREGROUND); EXPECT_EQ(FPDF_GetPageCount(dest_doc), 5); - // Capture initial checksums of dest_doc (all original pages) - std::vector dest_doc_checksums; + // Capture initial renderings of dest_doc (all original pages) + std::vector dest_doc_bitmaps; for (int i = 0; i < 5; i++) { - dest_doc_checksums.push_back(GetPageChecksum(dest_doc, i)); + dest_doc_bitmaps.push_back(RenderPageBitmap(dest_doc, i)); } ScopedFPDFDocument source_doc(FPDF_LoadDocument( @@ -709,10 +708,10 @@ TEST_F(FPDFPPOEmbedderTest, XFAImportTest) { EXPECT_EQ(FPDF_GetFormType(source_doc.get()), FORMTYPE_NONE); EXPECT_EQ(FPDF_GetPageCount(source_doc.get()), 5); - // Capture checksums of source_doc (all pages) - std::vector source_doc_checksums; + // Capture renderings of source_doc (all pages) + std::vector source_doc_bitmaps; for (int i = 0; i < 5; i++) { - source_doc_checksums.push_back(GetPageChecksum(source_doc.get(), i)); + source_doc_bitmaps.push_back(RenderPageBitmap(source_doc.get(), i)); } // Insert 3 pages into `dest_doc` @@ -720,14 +719,19 @@ TEST_F(FPDFPPOEmbedderTest, XFAImportTest) { EXPECT_EQ(FPDF_GetPageCount(dest_doc), 8); for (int i = 0; i < 4; i++) { - EXPECT_EQ(GetPageChecksum(dest_doc, i), dest_doc_checksums[i]); + EXPECT_TRUE(BitmapsEqual(RenderPageBitmap(dest_doc, i).get(), + dest_doc_bitmaps[i].get())); } - EXPECT_EQ(GetPageChecksum(dest_doc, 4), source_doc_checksums[0]); - EXPECT_EQ(GetPageChecksum(dest_doc, 5), source_doc_checksums[3]); - EXPECT_EQ(GetPageChecksum(dest_doc, 6), source_doc_checksums[1]); + EXPECT_TRUE(BitmapsEqual(RenderPageBitmap(dest_doc, 4).get(), + source_doc_bitmaps[0].get())); + EXPECT_TRUE(BitmapsEqual(RenderPageBitmap(dest_doc, 5).get(), + source_doc_bitmaps[3].get())); + EXPECT_TRUE(BitmapsEqual(RenderPageBitmap(dest_doc, 6).get(), + source_doc_bitmaps[1].get())); - EXPECT_EQ(GetPageChecksum(dest_doc, 7), dest_doc_checksums[4]); + EXPECT_TRUE(BitmapsEqual(RenderPageBitmap(dest_doc, 7).get(), + dest_doc_bitmaps[4].get())); } TEST_F(FPDFPPOEmbedderTest, XFAMoveTest) { @@ -737,10 +741,10 @@ TEST_F(FPDFPPOEmbedderTest, XFAMoveTest) { EXPECT_EQ(FPDF_GetFormType(document()), FORMTYPE_XFA_FOREGROUND); EXPECT_EQ(FPDF_GetPageCount(document()), 5); - // Capture initial checksums of the document (all original pages) - std::vector target_doc_checksums; + // Capture initial renderings of the document (all original pages) + std::vector target_doc_bitmaps; for (int i = 0; i < 5; i++) { - target_doc_checksums.push_back(GetPageChecksum(document(), i)); + target_doc_bitmaps.push_back(RenderPageBitmap(document(), i)); } // Move 3 pages to the start of the PDF @@ -748,9 +752,14 @@ TEST_F(FPDFPPOEmbedderTest, XFAMoveTest) { ASSERT_TRUE(FPDF_MovePages(document(), kPages, std::size(kPages), 0)); EXPECT_EQ(FPDF_GetPageCount(document()), 5); - EXPECT_EQ(GetPageChecksum(document(), 0), target_doc_checksums[1]); - EXPECT_EQ(GetPageChecksum(document(), 1), target_doc_checksums[2]); - EXPECT_EQ(GetPageChecksum(document(), 2), target_doc_checksums[3]); - EXPECT_EQ(GetPageChecksum(document(), 3), target_doc_checksums[0]); - EXPECT_EQ(GetPageChecksum(document(), 4), target_doc_checksums[4]); + EXPECT_TRUE(BitmapsEqual(RenderPageBitmap(document(), 0).get(), + target_doc_bitmaps[1].get())); + EXPECT_TRUE(BitmapsEqual(RenderPageBitmap(document(), 1).get(), + target_doc_bitmaps[2].get())); + EXPECT_TRUE(BitmapsEqual(RenderPageBitmap(document(), 2).get(), + target_doc_bitmaps[3].get())); + EXPECT_TRUE(BitmapsEqual(RenderPageBitmap(document(), 3).get(), + target_doc_bitmaps[0].get())); + EXPECT_TRUE(BitmapsEqual(RenderPageBitmap(document(), 4).get(), + target_doc_bitmaps[4].get())); } diff --git a/fpdfsdk/fpdf_save_embeddertest.cpp b/fpdfsdk/fpdf_save_embeddertest.cpp index 4901d5738..6872d0b8b 100644 --- a/fpdfsdk/fpdf_save_embeddertest.cpp +++ b/fpdfsdk/fpdf_save_embeddertest.cpp @@ -148,7 +148,7 @@ TEST_F(FPDFSaveEmbedderTest, Bug42271133) { TEST_F(FPDFSaveEmbedderTest, SaveLinearizedDoc) { const int kPageCount = 3; - std::array original_md5; + std::array original_bitmaps; ASSERT_TRUE(OpenDocument("linearized.pdf")); for (int i = 0; i < kPageCount; ++i) { @@ -157,7 +157,7 @@ TEST_F(FPDFSaveEmbedderTest, SaveLinearizedDoc) { ScopedFPDFBitmap bitmap = RenderLoadedPage(page.get()); EXPECT_EQ(612, FPDFBitmap_GetWidth(bitmap.get())); EXPECT_EQ(792, FPDFBitmap_GetHeight(bitmap.get())); - original_md5[i] = HashBitmap(bitmap.get()); + original_bitmaps[i] = std::move(bitmap); } EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0)); @@ -178,7 +178,7 @@ TEST_F(FPDFSaveEmbedderTest, SaveLinearizedDoc) { ScopedSavedPage page = LoadScopedSavedPage(i); ASSERT_TRUE(page); ScopedFPDFBitmap bitmap = RenderSavedPage(page.get()); - EXPECT_EQ(original_md5[i], HashBitmap(bitmap.get())); + EXPECT_TRUE(BitmapsEqual(original_bitmaps[i].get(), bitmap.get())); } } @@ -249,7 +249,6 @@ TEST_F(FPDFSaveEmbedderTest, IncrementalSaveWithModifications) { // Get the original bitmap for comparison ScopedFPDFBitmap original_bitmap = RenderLoadedPage(page.get()); - std::string original_md5 = HashBitmap(original_bitmap.get()); // Count text objects on a page auto count_text_objects = [](FPDF_PAGE page) { @@ -309,8 +308,7 @@ TEST_F(FPDFSaveEmbedderTest, IncrementalSaveWithModifications) { // The rendered output should be different from the original ScopedFPDFBitmap saved_bitmap = RenderSavedPage(saved_page.get()); - std::string saved_md5 = HashBitmap(saved_bitmap.get()); - EXPECT_NE(original_md5, saved_md5); + EXPECT_FALSE(BitmapsEqual(original_bitmap.get(), saved_bitmap.get())); // Verify the text object exists after the save EXPECT_EQ(1, count_text_objects(saved_page.get())); diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp index 758883a47..30149c7a6 100644 --- a/fpdfsdk/fpdf_view_embeddertest.cpp +++ b/fpdfsdk/fpdf_view_embeddertest.cpp @@ -2054,7 +2054,7 @@ TEST_F(FPDFViewEmbedderTest, Bug2087) { FPDF_DestroyLibrary(); auto* env = EmbedderTestEnvironment::GetInstance(); - std::string agg_checksum; + ScopedFPDFBitmap agg_bitmap; const FPDF_LIBRARY_CONFIG kAggConfig = { .version = 5, .m_pUserFontPaths = nullptr, @@ -2068,13 +2068,12 @@ TEST_F(FPDFViewEmbedderTest, Bug2087) { ASSERT_TRUE(OpenDocument("rectangles.pdf")); { ScopedPage page = LoadScopedPage(0); - ScopedFPDFBitmap bitmap = RenderPage(page.get()); - agg_checksum = HashBitmap(bitmap.get()); + agg_bitmap = RenderPage(page.get()); } CloseDocument(); FPDF_DestroyLibrary(); - std::string skia_checksum; + ScopedFPDFBitmap skia_bitmap; const FPDF_LIBRARY_CONFIG kSkiaConfig = { .version = 5, .m_pUserFontPaths = nullptr, @@ -2088,12 +2087,11 @@ TEST_F(FPDFViewEmbedderTest, Bug2087) { ASSERT_TRUE(OpenDocument("rectangles.pdf")); { ScopedPage page = LoadScopedPage(0); - ScopedFPDFBitmap bitmap = RenderPage(page.get()); - skia_checksum = HashBitmap(bitmap.get()); + skia_bitmap = RenderPage(page.get()); } CloseDocument(); - EXPECT_NE(agg_checksum, skia_checksum); + EXPECT_FALSE(BitmapsEqual(agg_bitmap.get(), skia_bitmap.get())); env->TearDown(); env->SetUp(); @@ -2105,7 +2103,7 @@ TEST_F(FPDFViewEmbedderTest, ToggleFreetypeFontationsInit) { FPDF_DestroyLibrary(); auto* env = EmbedderTestEnvironment::GetInstance(); - std::string freetype_checksum; + ScopedFPDFBitmap freetype_bitmap; const FPDF_LIBRARY_CONFIG kFreetypeConfig = { .version = 5, .m_pUserFontPaths = nullptr, @@ -2119,13 +2117,12 @@ TEST_F(FPDFViewEmbedderTest, ToggleFreetypeFontationsInit) { ASSERT_TRUE(OpenDocument("text_color.pdf")); { ScopedPage page = LoadScopedPage(0); - ScopedFPDFBitmap bitmap = RenderPage(page.get()); - freetype_checksum = HashBitmap(bitmap.get()); + freetype_bitmap = RenderPage(page.get()); } CloseDocument(); FPDF_DestroyLibrary(); - std::string fontations_checksum; + ScopedFPDFBitmap fontations_bitmap; const FPDF_LIBRARY_CONFIG kFontationsConfig = { .version = 5, .m_pUserFontPaths = nullptr, @@ -2139,12 +2136,11 @@ TEST_F(FPDFViewEmbedderTest, ToggleFreetypeFontationsInit) { ASSERT_TRUE(OpenDocument("text_color.pdf")); { ScopedPage page = LoadScopedPage(0); - ScopedFPDFBitmap bitmap = RenderPage(page.get()); - fontations_checksum = HashBitmap(bitmap.get()); + fontations_bitmap = RenderPage(page.get()); } CloseDocument(); - EXPECT_NE(freetype_checksum, fontations_checksum); + EXPECT_FALSE(BitmapsEqual(freetype_bitmap.get(), fontations_bitmap.get())); env->TearDown(); env->SetUp(); diff --git a/testing/BUILD.gn b/testing/BUILD.gn index 0513bfad3..f1596e387 100644 --- a/testing/BUILD.gn +++ b/testing/BUILD.gn @@ -236,7 +236,6 @@ source_set("embedder_test_support") { ] deps = [ ":path_service", - "../core/fdrm", "../core/fxge", "../fpdfsdk", "../fpdfsdk:test_support", diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index e57e02bee..c31b5629c 100644 --- a/testing/embedder_test.cpp +++ b/testing/embedder_test.cpp @@ -11,7 +11,6 @@ #include #include -#include "core/fdrm/fx_crypt.h" #include "core/fxcrt/check.h" #include "core/fxcrt/check_op.h" #include "core/fxcrt/compiler_specific.h" @@ -39,7 +38,6 @@ #include "testing/test_loader.h" #include "testing/utils/bitmap_saver.h" #include "testing/utils/file_util.h" -#include "testing/utils/hash.h" #include "testing/utils/path_service.h" #include "testing/utils/pixel_diff_util.h" #include "third_party/simdutf/simdutf.h" @@ -1224,24 +1222,38 @@ FPDF_PAGE EmbedderTest::Delegate::GetPage(FPDF_FORMFILLINFO* info, } // static -std::string EmbedderTest::HashBitmap(FPDF_BITMAP bitmap) { - int stride = FPDFBitmap_GetStride(bitmap); - int usable_bytes_per_row = - GetBitmapBytesPerPixel(bitmap) * FPDFBitmap_GetWidth(bitmap); - int height = FPDFBitmap_GetHeight(bitmap); - auto span = UNSAFE_TODO( - pdfium::span(static_cast(FPDFBitmap_GetBuffer(bitmap)), - static_cast(stride) * height)); - - CryptMd5Context context = CryptMd5Start(); +bool EmbedderTest::BitmapsEqual(FPDF_BITMAP bitmap1, FPDF_BITMAP bitmap2) { + if (!bitmap1 || !bitmap2) { + return bitmap1 == bitmap2; + } + const int width = FPDFBitmap_GetWidth(bitmap1); + const int height = FPDFBitmap_GetHeight(bitmap1); + const int format = FPDFBitmap_GetFormat(bitmap1); + if (width != FPDFBitmap_GetWidth(bitmap2) || + height != FPDFBitmap_GetHeight(bitmap2) || + format != FPDFBitmap_GetFormat(bitmap2)) { + return false; + } + const int stride1 = FPDFBitmap_GetStride(bitmap1); + const int stride2 = FPDFBitmap_GetStride(bitmap2); + const size_t usable_bytes_per_row = + static_cast(GetBitmapBytesPerPixel(bitmap1)) * width; + auto span1 = UNSAFE_TODO( + pdfium::span(static_cast(FPDFBitmap_GetBuffer(bitmap1)), + static_cast(stride1) * height)); + auto span2 = UNSAFE_TODO( + pdfium::span(static_cast(FPDFBitmap_GetBuffer(bitmap2)), + static_cast(stride2) * height)); for (int i = 0; i < height; ++i) { - CryptMd5Update(&context, - span.subspan(static_cast(i * stride), - static_cast(usable_bytes_per_row))); + auto row1 = + span1.subspan(static_cast(i) * stride1, usable_bytes_per_row); + auto row2 = + span2.subspan(static_cast(i) * stride2, usable_bytes_per_row); + if (!std::ranges::equal(row1, row2)) { + return false; + } } - uint8_t digest[16]; - CryptMd5Finish(&context, digest); - return CryptToBase16(digest); + return true; } // static diff --git a/testing/embedder_test.h b/testing/embedder_test.h index 19ebdfc03..2c57fde45 100644 --- a/testing/embedder_test.h +++ b/testing/embedder_test.h @@ -345,9 +345,9 @@ class EmbedderTest : public ::testing::Test, FPDF_FORMHANDLE SetupFormFillEnvironment(FPDF_DOCUMENT doc, JavaScriptOption javascript_option); - // Return the hash of only the pixels in `bitmap`. i.e. Excluding the gap, if - // any, at the end of a row where the stride is larger than width * bpp. - static std::string HashBitmap(FPDF_BITMAP bitmap); + // Returns whether the pixels in `bitmap1` and `bitmap2` match, excluding any + // stride padding at the end of each row. + static bool BitmapsEqual(FPDF_BITMAP bitmap1, FPDF_BITMAP bitmap2); // For debugging purposes. // Write `bitmap` as a PNG to `filename`. From 66ed17ef8fa00526ba3e2633361b6cc312321dc9 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Fri, 20 Nov 2026 16:32:15 -0800 Subject: [PATCH 30/34] Guard remaining IPDF_JSPLATFORM call-outs with in_active_ffi_callback_ Set in_active_ffi_callback_ across the remaining IPDF_JSPLATFORM call-outs in CPDFSDK_FormFillEnvironment: JS_fieldBrowse(), JS_docmailForm(), JS_docprint(), JS_docgotoPage(), GetFilePath(), and SubmitForm(). Also route CPDFXFA_DocEnvironment::Print() through CPDFSDK_FormFillEnvironment::JS_docprint() so XFA printing shares the same guard. Defense-in-depth for embedders; none of these call-out paths should be reachable for synchronous environment destruction from the Chromium embedder. Fixed: 586732845 Change-Id: I15e99ecf1ee6cf64a993e40bf0a306341f55a528 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165290 Commit-Queue: Tom Sepez Reviewed-by: Lei Zhang --- fpdfsdk/cpdfsdk_formfillenvironment.cpp | 8 +++++++- fpdfsdk/cpdfsdk_formfillenvironment.h | 2 +- fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp | 19 +++++++------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp index 124f504e1..4453c82ad 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp +++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp @@ -263,6 +263,7 @@ WideString CPDFSDK_FormFillEnvironment::JS_fieldBrowse() { return WideString(); } + AutoRestorer restorer(&in_active_ffi_callback_, true); const int required_len = js_platform->Field_browse(js_platform, nullptr, 0); if (required_len <= 0) { return WideString(); @@ -300,6 +301,7 @@ void CPDFSDK_FormFillEnvironment::JS_docmailForm( ByteString bsCC = CC.ToUTF16LE(); ByteString bsBcc = BCC.ToUTF16LE(); ByteString bsMsg = Msg.ToUTF16LE(); + AutoRestorer restorer(&in_active_ffi_callback_, true); js_platform->Doc_mail(js_platform, const_cast(mailData.data()), pdfium::checked_cast(mailData.size()), bUI, AsFPDFWideString(&bsTo), AsFPDFWideString(&bsSubject), @@ -320,6 +322,7 @@ void CPDFSDK_FormFillEnvironment::JS_docprint(FPDF_BOOL bUI, return; } + AutoRestorer restorer(&in_active_ffi_callback_, true); js_platform->Doc_print(js_platform, bUI, nStart, nEnd, bSilent, bShrinkToFit, bPrintAsImage, bReverse, bAnnotations); } @@ -330,6 +333,7 @@ void CPDFSDK_FormFillEnvironment::JS_docgotoPage(int nPageNum) { return; } + AutoRestorer restorer(&in_active_ffi_callback_, true); js_platform->Doc_gotoPage(js_platform, nPageNum); } @@ -338,12 +342,13 @@ WideString CPDFSDK_FormFillEnvironment::JS_docGetFilePath() { } #endif // PDF_ENABLE_V8 -WideString CPDFSDK_FormFillEnvironment::GetFilePath() const { +WideString CPDFSDK_FormFillEnvironment::GetFilePath() { IPDF_JSPLATFORM* js_platform = GetJSPlatform(); if (!js_platform || !js_platform->Doc_getFilePath) { return WideString(); } + AutoRestorer restorer(&in_active_ffi_callback_, true); const int required_len = js_platform->Doc_getFilePath(js_platform, nullptr, 0); if (required_len <= 0) { @@ -373,6 +378,7 @@ void CPDFSDK_FormFillEnvironment::SubmitForm( } ByteString bsUrl = URL.ToUTF16LE(); + AutoRestorer restorer(&in_active_ffi_callback_, true); js_platform->Doc_submitForm( js_platform, const_cast(form_data.data()), fxcrt::CollectionSize(form_data), AsFPDFWideString(&bsUrl)); diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h index a25cc6287..02a952070 100644 --- a/fpdfsdk/cpdfsdk_formfillenvironment.h +++ b/fpdfsdk/cpdfsdk_formfillenvironment.h @@ -236,7 +236,7 @@ class CPDFSDK_FormFillEnvironment final #endif // PDF_ENABLE_XFA #endif // PDF_ENABLE_V8 - WideString GetFilePath() const; + WideString GetFilePath(); ByteString GetAppName() const { return ByteString(); } void SubmitForm(pdfium::span form_data, const WideString& URL); diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 062c387df..b46ade7dd 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp @@ -657,18 +657,13 @@ void CPDFXFA_DocEnvironment::Print(CXFA_FFDoc* hDoc, return; } - IPDF_JSPLATFORM* js_platform = pFormFillEnv->GetJSPlatform(); - if (!js_platform || !js_platform->Doc_print) { - return; - } - - js_platform->Doc_print(js_platform, !!(dwOptions & XFA_PrintOpt::kShowDialog), - nStartPage, nEndPage, - !!(dwOptions & XFA_PrintOpt::kCanCancel), - !!(dwOptions & XFA_PrintOpt::kShrinkPage), - !!(dwOptions & XFA_PrintOpt::kAsImage), - !!(dwOptions & XFA_PrintOpt::kReverseOrder), - !!(dwOptions & XFA_PrintOpt::kPrintAnnot)); + pFormFillEnv->JS_docprint(!!(dwOptions & XFA_PrintOpt::kShowDialog), + nStartPage, nEndPage, + !!(dwOptions & XFA_PrintOpt::kCanCancel), + !!(dwOptions & XFA_PrintOpt::kShrinkPage), + !!(dwOptions & XFA_PrintOpt::kAsImage), + !!(dwOptions & XFA_PrintOpt::kReverseOrder), + !!(dwOptions & XFA_PrintOpt::kPrintAnnot)); } FX_ARGB CPDFXFA_DocEnvironment::GetHighlightColor( From 5a04ac96d72b6ebdfa1a45379779b40ee47b68e9 Mon Sep 17 00:00:00 2001 From: "pdfium-autoroll@skia-public.iam.gserviceaccount.com" Date: Sun, 22 Nov 2026 20:27:13 -0800 Subject: [PATCH 31/34] Roll Code Coverage from 084f00efb99d to ed426db3b2fb (13 revisions) https://chromium.googlesource.com/chromium/src/tools/code_coverage.git/+log/084f00efb99d..ed426db3b2fb If this roll has caused a breakage, revert this CL and set the roller to dry run mode using the controls here: https://autoroll.skia.org/r/code-coverage-pdfium Please CC dhoss@chromium.org,thestig@chromium.org,thestig@google.com on the revert to ensure that a human is aware of the problem. To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md Bug: None Change-Id: Ib2d4f09fd5ef8bdf0aa470f101154f68f590014c Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165350 Bot-Commit: pdfium-autoroll@skia-public.iam.gserviceaccount.com Commit-Queue: pdfium-autoroll@skia-public.iam.gserviceaccount.com --- DEPS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 074ae9a1a..a37659b2f 100644 --- a/DEPS +++ b/DEPS @@ -114,7 +114,7 @@ vars = { # Three lines of non-changing comments so that # the commit queue can handle CLs rolling code_coverage # and whatever else without interference from each other. - 'code_coverage_revision': '084f00efb99dc9a1726ed68cc2e05d25bc52802b', + 'code_coverage_revision': 'ed426db3b2fbd831f3fa795d6c2603b812a8c6f7', # Three lines of non-changing comments so that # the commit queue can handle CLs rolling cpu_features # and whatever else without interference from each other. From 8a07c5de59aeb42991bd313948bfdcfdd32a3052 Mon Sep 17 00:00:00 2001 From: Nithya V S Date: Mon, 23 Nov 2026 11:57:12 -0800 Subject: [PATCH 32/34] Highway: MultiplyAlpha()/MultiplyAlphaMask() kBgra Add core/fxge/dib/cfx_dibitmap_hwy.{h,cpp} exposing MultiplyAlphaSimd() and MultiplyAlphaMaskSimd(), and call them from the kBgra per-row loops in cfx_dibitmap.cpp. This CL is partly AI-generated. Bug: 581458360 Change-Id: I49d0d9afb9da5618b5a25e78487515b46c477f04 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/164330 Reviewed-by: Andy Phan Reviewed-by: Tom Sepez Commit-Queue: Andy Phan --- core/fxge/BUILD.gn | 2 + core/fxge/dib/cfx_dibitmap.cpp | 11 +- core/fxge/dib/cfx_dibitmap_hwy.cpp | 141 +++++++++++++++++++++++ core/fxge/dib/cfx_dibitmap_hwy.h | 27 +++++ core/fxge/dib/cfx_dibitmap_unittest.cpp | 144 ++++++++++++++++++++++++ 5 files changed, 318 insertions(+), 7 deletions(-) create mode 100644 core/fxge/dib/cfx_dibitmap_hwy.cpp create mode 100644 core/fxge/dib/cfx_dibitmap_hwy.h diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn index 2b46c649b..5f620b876 100644 --- a/core/fxge/BUILD.gn +++ b/core/fxge/BUILD.gn @@ -62,6 +62,8 @@ source_set("fxge") { "dib/cfx_dibbase.h", "dib/cfx_dibitmap.cpp", "dib/cfx_dibitmap.h", + "dib/cfx_dibitmap_hwy.cpp", + "dib/cfx_dibitmap_hwy.h", "dib/cfx_imagestretcher.cpp", "dib/cfx_imagestretcher.h", "dib/cfx_imagetransformer.cpp", diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp index 6d63bc7d6..7d665ff00 100644 --- a/core/fxge/dib/cfx_dibitmap.cpp +++ b/core/fxge/dib/cfx_dibitmap.cpp @@ -26,6 +26,7 @@ #include "core/fxcrt/span_util.h" #include "core/fxge/calculate_pitch.h" #include "core/fxge/cfx_gemodule.h" +#include "core/fxge/dib/cfx_dibitmap_hwy.h" #include "core/fxge/dib/cfx_scanlinecompositor.h" #if defined(PDF_USE_LIBYUV) @@ -381,9 +382,7 @@ bool CFX_DIBitmap::MultiplyAlphaMask(RetainPtr mask) { static_cast(GetWidth())); auto mask_scan = mask->GetScanline(row).first(static_cast(GetWidth())); - for (int col = 0; col < GetWidth(); col++) { - dest_scan[col].alpha = dest_scan[col].alpha * mask_scan[col] / 255; - } + MultiplyAlphaMaskSimd(dest_scan, mask_scan); } return true; } @@ -407,13 +406,11 @@ bool CFX_DIBitmap::MultiplyAlpha(float alpha) { return false; } - const int bitmap_alpha = static_cast(alpha * 255.0f); + const uint8_t bitmap_alpha = static_cast(alpha * 255.0f); for (int row = 0; row < GetHeight(); row++) { auto dest_scan = GetWritableScanlineAs>(row).first( static_cast(GetWidth())); - for (auto& pixel : dest_scan) { - pixel.alpha = pixel.alpha * bitmap_alpha / 255; - } + MultiplyAlphaSimd(dest_scan, bitmap_alpha); } return true; } diff --git a/core/fxge/dib/cfx_dibitmap_hwy.cpp b/core/fxge/dib/cfx_dibitmap_hwy.cpp new file mode 100644 index 000000000..459ef3352 --- /dev/null +++ b/core/fxge/dib/cfx_dibitmap_hwy.cpp @@ -0,0 +1,141 @@ +// Copyright 2026 The PDFium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "core/fxge/dib/cfx_dibitmap_hwy.h" + +#include +#include + +#include "core/fxcrt/check_op.h" +#include "core/fxcrt/compiler_specific.h" +#include "core/fxcrt/span.h" +#include "core/fxcrt/zip.h" + +#undef HWY_TARGET_INCLUDE +#define HWY_TARGET_INCLUDE "core/fxge/dib/cfx_dibitmap_hwy.cpp" +#include "third_party/highway/src/hwy/foreach_target.h" // IWYU pragma: keep + +#include "third_party/highway/src/hwy/highway.h" + +HWY_BEFORE_NAMESPACE(); +namespace fxge_dibitmap_simd { +namespace HWY_NAMESPACE { +namespace { + +namespace hn = hwy::HWY_NAMESPACE; + +#if HWY_TARGET != HWY_SCALAR +using D32 = hn::ScalableTag; +using D16 = hn::Repartition; +using D8 = hn::Repartition; + +// exact x/255 for x <= 65025 +HWY_INLINE hn::Vec Div255(hn::Vec x) { + const D32 d; + return hn::ShiftRight<8>( + hn::Add(hn::Add(x, hn::Set(d, 1)), hn::ShiftRight<8>(x))); +} + +// u16 multiply: alpha in even lanes, odd lanes 0, so odd products are 0. +HWY_INLINE hn::Vec ScaleAlpha(hn::Vec v, hn::Vec f) { + const D32 d; + const D16 d16; + const hn::Vec a = hn::BitCast(d16, hn::ShiftRight<24>(v)); + const hn::Vec na = Div255(hn::BitCast(d, hn::Mul(a, f))); + // Not OrAnd: AVX-512 ternlog blocks the byte-blend fold. + return hn::Or(hn::And(v, hn::Set(d, 0x00FFFFFFu)), hn::ShiftLeft<24>(na)); +} +#endif // HWY_TARGET != HWY_SCALAR + +// alpha = alpha * factor / 255; BGR kept. +void RunMultiplyAlpha(pdfium::span> dest, + uint8_t factor) { +#if HWY_TARGET != HWY_SCALAR + const D32 d; + const D16 d16; + const D8 d8; + const size_t n = hn::Lanes(d); // pixels/vector + const hn::Vec f = hn::Set(d16, factor); + + while (dest.size() >= n) { + const hn::Vec v = + hn::BitCast(d, hn::LoadU(d8, pdfium::as_bytes(dest).data())); + const hn::Vec out = ScaleAlpha(v, f); + hn::StoreU(hn::BitCast(d8, out), d8, + pdfium::as_writable_bytes(dest).data()); + dest = dest.subspan(n); + } +#endif // HWY_TARGET != HWY_SCALAR + for (auto& pixel : dest) { + pixel.alpha = pixel.alpha * factor / 255; + } +} + +// alpha = alpha * mask / 255, one mask byte per pixel; BGR kept. +void RunMultiplyAlphaMask(pdfium::span> dest, + pdfium::span mask) { + // Make sure the compiler can see equal span sizes after the dispatch. + mask = mask.first(dest.size()); +#if HWY_TARGET != HWY_SCALAR + const D32 d; + const D16 d16; + const D8 d8; + const hn::Rebind d8r; // promote to u32 + const size_t n = hn::Lanes(d); // pixels/vector + + while (dest.size() >= n) { + const hn::Vec v = + hn::BitCast(d, hn::LoadU(d8, pdfium::as_bytes(dest).data())); + const hn::Vec m = + hn::BitCast(d16, hn::PromoteTo(d, hn::LoadU(d8r, mask.data()))); + const hn::Vec out = ScaleAlpha(v, m); + hn::StoreU(hn::BitCast(d8, out), d8, + pdfium::as_writable_bytes(dest).data()); + dest = dest.subspan(n); + mask = mask.subspan(n); + } +#endif // HWY_TARGET != HWY_SCALAR + for (auto [pixel, m] : fxcrt::Zip(dest, mask)) { + pixel.alpha = pixel.alpha * m / 255; + } +} + +} // namespace +} // namespace HWY_NAMESPACE +} // namespace fxge_dibitmap_simd +HWY_AFTER_NAMESPACE(); + +#if HWY_ONCE +namespace fxge_dibitmap_simd { + +HWY_EXPORT(RunMultiplyAlpha); +HWY_EXPORT(RunMultiplyAlphaMask); + +// Unqualified name, in-namespace: a qualified name breaks single-target +// HWY_STATIC_DISPATCH. +void DispatchMultiplyAlpha(pdfium::span> dest, + uint8_t factor) { + // SAFETY: dispatch indexes Highway's per-target table; no span macro form. + UNSAFE_BUFFERS(HWY_DYNAMIC_DISPATCH(RunMultiplyAlpha)(dest, factor)); +} + +void DispatchMultiplyAlphaMask(pdfium::span> dest, + pdfium::span mask) { + // SAFETY: see DispatchMultiplyAlpha(). + UNSAFE_BUFFERS(HWY_DYNAMIC_DISPATCH(RunMultiplyAlphaMask)(dest, mask)); +} + +} // namespace fxge_dibitmap_simd + +void MultiplyAlphaSimd(pdfium::span> dest_span, + uint8_t bitmap_alpha) { + fxge_dibitmap_simd::DispatchMultiplyAlpha(dest_span, bitmap_alpha); +} + +void MultiplyAlphaMaskSimd(pdfium::span> dest_span, + pdfium::span mask_span) { + CHECK_LE(dest_span.size(), mask_span.size()); + fxge_dibitmap_simd::DispatchMultiplyAlphaMask(dest_span, mask_span); +} +#endif // HWY_ONCE diff --git a/core/fxge/dib/cfx_dibitmap_hwy.h b/core/fxge/dib/cfx_dibitmap_hwy.h new file mode 100644 index 000000000..12d4c39c4 --- /dev/null +++ b/core/fxge/dib/cfx_dibitmap_hwy.h @@ -0,0 +1,27 @@ +// Copyright 2026 The PDFium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CORE_FXGE_DIB_CFX_DIBITMAP_HWY_H_ +#define CORE_FXGE_DIB_CFX_DIBITMAP_HWY_H_ + +#include + +#include "core/fxcrt/span.h" +#include "core/fxge/dib/fx_dib.h" + +// Highway kernels for the kBgra alpha-scaling cases, each bit-exact with the +// scalar reference it replaces. Only the alpha byte changes; BGR bytes are +// preserved. Runtime target selection is internal. + +// SIMD replacement for the kBgra CFX_DIBitmap::MultiplyAlpha() inner loop: +// alpha <- alpha * bitmap_alpha / 255. +void MultiplyAlphaSimd(pdfium::span> dest_span, + uint8_t bitmap_alpha); + +// SIMD replacement for the kBgra CFX_DIBitmap::MultiplyAlphaMask() inner loop: +// alpha <- alpha * mask / 255, one mask byte per pixel. +void MultiplyAlphaMaskSimd(pdfium::span> dest_span, + pdfium::span mask_span); + +#endif // CORE_FXGE_DIB_CFX_DIBITMAP_HWY_H_ diff --git a/core/fxge/dib/cfx_dibitmap_unittest.cpp b/core/fxge/dib/cfx_dibitmap_unittest.cpp index 3efbb1265..36cd0cf5f 100644 --- a/core/fxge/dib/cfx_dibitmap_unittest.cpp +++ b/core/fxge/dib/cfx_dibitmap_unittest.cpp @@ -6,8 +6,12 @@ #include +#include +#include + #include "core/fxcrt/fx_coordinates.h" #include "core/fxcrt/span.h" +#include "core/fxge/dib/cfx_dibitmap_hwy.h" #include "core/fxge/dib/fx_dib.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -16,6 +20,51 @@ namespace { using ::testing::ElementsAre; +// Boundary widths spanning the SSE4/AVX2/AVX-512 lane counts (4/8/16) plus +// their one-off neighbours, the empty row, and a long run. +constexpr auto kSimdWidths = + std::to_array({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 15, + 16, 17, 31, 32, 33, 63, 64, 65, 100, 257}); + +void ExpectBgraEq(const FX_BGRA_STRUCT& expected, + const FX_BGRA_STRUCT& actual, + size_t width, + size_t i) { + EXPECT_EQ(expected.blue, actual.blue) << "width " << width << " pixel " << i; + EXPECT_EQ(expected.green, actual.green) + << "width " << width << " pixel " << i; + EXPECT_EQ(expected.red, actual.red) << "width " << width << " pixel " << i; + EXPECT_EQ(expected.alpha, actual.alpha) + << "width " << width << " pixel " << i; +} + +std::vector> MakeBgraRow(size_t width) { + std::vector> row(width); + for (size_t i = 0; i < width; ++i) { + row[i] = {.blue = static_cast(i * 7 + 1), + .green = static_cast(i * 13 + 2), + .red = static_cast(i * 29 + 3), + .alpha = static_cast(i)}; // cycles all 256 alphas + } + return row; +} + +// 64 + 3: several vector iterations and a 3-pixel tail on every target. +constexpr int kApiWidth = 67; +constexpr int kApiHeight = 2; + +FX_BGRA_STRUCT MakeApiPixel(int row, int i) { + return {.blue = static_cast(10 + i + row), + .green = static_cast(40 + i + row), + .red = static_cast(70 + i + row), + .alpha = static_cast(255 - 15 * i - 5 * row)}; +} + +// Includes 0 and 255. +uint8_t MakeApiMask(int row, int i) { + return static_cast(17 * i + 3 * row); +} + } // namespace TEST(CFXDIBitmapTest, Create) { @@ -228,3 +277,98 @@ TEST(CFXDIBitmapTest, MultiplyAlphaMaskFromBgrx) { EXPECT_EQ(60u, out_row[1].red); EXPECT_EQ(0x34u, out_row[1].alpha); } + +// Vector body + sub-vector tail: SIMD matches the scalar alpha * f / 255 +// across lane-count boundaries and every constant alpha factor. +TEST(CFXDIBitmapTest, MultiplyAlphaSimdMatchesScalar) { + for (size_t width : kSimdWidths) { + const std::vector> src = MakeBgraRow(width); + std::vector> work; + for (int factor = 0; factor <= 255; ++factor) { + work = src; + MultiplyAlphaSimd(work, static_cast(factor)); + for (size_t i = 0; i < width; ++i) { + FX_BGRA_STRUCT expected = src[i]; + expected.alpha = static_cast(src[i].alpha * factor / 255); + ExpectBgraEq(expected, work[i], width, i); + } + } + } +} + +// Same, for the per-pixel mask variant alpha * mask / 255. Mask bytes vary +// across pixels, and the shift sweeps every mask value over each alpha. +TEST(CFXDIBitmapTest, MultiplyAlphaMaskSimdMatchesScalar) { + for (size_t width : kSimdWidths) { + const std::vector> src = MakeBgraRow(width); + std::vector mask(width); + std::vector> work; + for (size_t shift = 0; shift < 256; ++shift) { + for (size_t i = 0; i < width; ++i) { + mask[i] = static_cast(i * 37 + 11 + shift); + } + work = src; + MultiplyAlphaMaskSimd(work, mask); + for (size_t i = 0; i < width; ++i) { + FX_BGRA_STRUCT expected = src[i]; + expected.alpha = static_cast(src[i].alpha * mask[i] / 255); + ExpectBgraEq(expected, work[i], width, i); + } + } + } +} + +// Public API, multi-row kBgra: row loop, float -> uint8_t factor, BGR kept. +TEST(CFXDIBitmapTest, MultiplyAlphaOnBgra) { + auto bitmap = pdfium::MakeRetain(); + ASSERT_TRUE(bitmap->Create(kApiWidth, kApiHeight, FXDIB_Format::kBgra)); + for (int row = 0; row < kApiHeight; ++row) { + auto dest = bitmap->GetWritableScanlineAs>(row); + for (int i = 0; i < kApiWidth; ++i) { + dest[i] = MakeApiPixel(row, i); + } + } + + constexpr uint8_t kBitmapAlpha = 127; // uint8_t(0.5f * 255.0f) + ASSERT_TRUE(bitmap->MultiplyAlpha(0.5f)); + + EXPECT_EQ(FXDIB_Format::kBgra, bitmap->GetFormat()); + for (int row = 0; row < kApiHeight; ++row) { + auto out_row = bitmap->GetScanlineAs>(row); + for (int i = 0; i < kApiWidth; ++i) { + FX_BGRA_STRUCT expected = MakeApiPixel(row, i); + expected.alpha = + static_cast(expected.alpha * kBitmapAlpha / 255); + ExpectBgraEq(expected, out_row[i], kApiWidth, i); + } + } +} + +// Public API, multi-row kBgra: alpha * mask, unlike kBgrx (alpha = mask). +TEST(CFXDIBitmapTest, MultiplyAlphaMaskOnBgra) { + auto bitmap = pdfium::MakeRetain(); + ASSERT_TRUE(bitmap->Create(kApiWidth, kApiHeight, FXDIB_Format::kBgra)); + auto mask = pdfium::MakeRetain(); + ASSERT_TRUE(mask->Create(kApiWidth, kApiHeight, FXDIB_Format::k8bppMask)); + for (int row = 0; row < kApiHeight; ++row) { + auto dest = bitmap->GetWritableScanlineAs>(row); + auto mask_row = mask->GetWritableScanline(row); + for (int i = 0; i < kApiWidth; ++i) { + dest[i] = MakeApiPixel(row, i); + mask_row[i] = MakeApiMask(row, i); + } + } + + ASSERT_TRUE(bitmap->MultiplyAlphaMask(mask)); + + EXPECT_EQ(FXDIB_Format::kBgra, bitmap->GetFormat()); + for (int row = 0; row < kApiHeight; ++row) { + auto out_row = bitmap->GetScanlineAs>(row); + for (int i = 0; i < kApiWidth; ++i) { + FX_BGRA_STRUCT expected = MakeApiPixel(row, i); + expected.alpha = + static_cast(expected.alpha * MakeApiMask(row, i) / 255); + ExpectBgraEq(expected, out_row[i], kApiWidth, i); + } + } +} From 6372d801de6e6fa59a1aa0f56af6fe9f7c5faf54 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 23 Nov 2026 12:11:40 -0800 Subject: [PATCH 33/34] Expose PDF_ENABLE_FONTATIONS and PDF_ENABLE_FREETYPE in public config These now match PDF_USE_AGG and PDF_USE_SKIA. Embedders depending on //third_party/pdfium can then inspect these preprocessor defines. Change-Id: I3afdd8fac3f62a93c08358b6ebce1cd4ffa63332 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165390 Reviewed-by: Andy Phan Commit-Queue: Tom Sepez --- BUILD.gn | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 42715bddb..30ceb793d 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -34,14 +34,6 @@ config("pdfium_common_config") { defines += [ "PDF_ENABLE_CLICK_LOGGING" ] } - if (pdf_enable_fontations) { - defines += [ "PDF_ENABLE_FONTATIONS" ] - } - - if (pdf_enable_freetype) { - defines += [ "PDF_ENABLE_FREETYPE" ] - } - if (pdf_enable_rust_bmp) { defines += [ "PDF_ENABLE_RUST_BMP" ] } @@ -161,6 +153,12 @@ config("pdfium_public_config") { if (pdf_use_skia) { defines += [ "PDF_USE_SKIA" ] } + if (pdf_enable_fontations) { + defines += [ "PDF_ENABLE_FONTATIONS" ] + } + if (pdf_enable_freetype) { + defines += [ "PDF_ENABLE_FREETYPE" ] + } } config("pdfium_core_config") { From bd217de84120979acf43258c77af22e166651f9a Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 23 Nov 2026 12:14:25 -0800 Subject: [PATCH 34/34] Remove unused empty list assignments in BUILD.gn files Drop cflags_cc = [], ldflags = [], and defines = [] in configs and source_sets that never append to them. Change-Id: Ib9d4c21648f29de9f3658d7d602c88779d6ec925 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/165410 Auto-Submit: Tom Sepez Reviewed-by: Andy Phan Commit-Queue: Tom Sepez --- BUILD.gn | 3 --- core/fxcodec/BUILD.gn | 1 - testing/fuzzers/BUILD.gn | 7 ++----- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 30ceb793d..ea7c028fd 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -17,8 +17,6 @@ group("default") { config("pdfium_common_config") { cflags = [] - cflags_cc = [] - ldflags = [] include_dirs = [ ".", target_gen_dir, @@ -168,7 +166,6 @@ config("pdfium_core_config") { ":pdfium_public_config", "//build/config/compiler:noshadowing", ] - defines = [] if (is_clang) { cflags += [ "-Wcovered-switch-default", diff --git a/core/fxcodec/BUILD.gn b/core/fxcodec/BUILD.gn index 77d827d84..9e783391c 100644 --- a/core/fxcodec/BUILD.gn +++ b/core/fxcodec/BUILD.gn @@ -138,7 +138,6 @@ source_set("fxcodec") { "../../third_party:zlib", "../fxge", ] - defines = [] if (pdf_enable_brotli) { sources += [ "brotli/brotli_decoder.cpp", diff --git a/testing/fuzzers/BUILD.gn b/testing/fuzzers/BUILD.gn index 7e8749fe6..d0a85bf87 100644 --- a/testing/fuzzers/BUILD.gn +++ b/testing/fuzzers/BUILD.gn @@ -9,7 +9,6 @@ config("fuzzer_config") { "../..:pdfium_strict_config", "../..:pdfium_noshorten_config", ] - defines = [] include_dirs = [ "../.." ] } @@ -190,7 +189,7 @@ source_set("fuzzer_utils") { include_dirs = [ "../.." ] } -source_set("pdf_jpx_fuzzer_common"){ +source_set("pdf_jpx_fuzzer_common") { testonly = !is_component_build sources = [ "pdf_jpx_fuzzer_common.cc", @@ -585,9 +584,7 @@ pdfium_fuzzer("pdf_hint_table_fuzzer") { pdfium_fuzzer("pdf_jpx_fuzzer") { sources = [ "pdf_jpx_fuzzer.cc" ] - deps = [ - ":pdf_jpx_fuzzer_common", - ] + deps = [ ":pdf_jpx_fuzzer_common" ] } pdfium_fuzzer("pdf_psengine_fuzzer") {