diff --git a/BUILD.gn b/BUILD.gn index 34d01752bf..2bb0d647a7 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -17,9 +17,10 @@ group("default") { config("pdfium_common_config") { cflags = [] - cflags_cc = [] - ldflags = [] - include_dirs = [ "." ] + include_dirs = [ + ".", + target_gen_dir, + ] inputs = [ "unsafe_buffers_paths.txt" ] defines = [] @@ -31,14 +32,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" ] } @@ -165,6 +158,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") { @@ -174,7 +173,6 @@ config("pdfium_core_config") { ":pdfium_public_config", "//build/config/compiler:noshadowing", ] - defines = [] if (is_clang) { cflags += [ "-Wcovered-switch-default", diff --git a/DEPS b/DEPS index bc799f7de5..a37659b2f0 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. @@ -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': '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. @@ -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. @@ -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. @@ -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. @@ -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. @@ -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': '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. @@ -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. diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 611e3ae68b..1ad3e0fd1f 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/core/fpdfapi/parser/BUILD.gn b/core/fpdfapi/parser/BUILD.gn index 69f6ec612a..83c8b2ba55 100644 --- a/core/fpdfapi/parser/BUILD.gn +++ b/core/fpdfapi/parser/BUILD.gn @@ -199,7 +199,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/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index 305eb7b8bc..cfa69c46c7 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 15f29cd70c..e295d2b694 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 78ded83b60..0f6bcf0423 100644 --- a/core/fpdfapi/parser/cpdf_document.cpp +++ b/core/fpdfapi/parser/cpdf_document.cpp @@ -236,6 +236,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. @@ -1140,6 +1149,24 @@ void CPDF_Document::InvalidateCachedInfoDict() { info_dict_.Reset(); } +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 bf15385ff1..b73b482163 100644 --- a/core/fpdfapi/parser/cpdf_document.h +++ b/core/fpdfapi/parser/cpdf_document.h @@ -64,6 +64,12 @@ class CPDF_Document : public Observable, virtual ~LinkListIface() = default; }; + class DestructionObserverIface { + public: + virtual ~DestructionObserverIface() = default; + virtual void OnDocumentDestroyed() = 0; + }; + class PageDataIface { public: PageDataIface(); @@ -126,6 +132,9 @@ class CPDF_Document : public Observable, extension_ = std::move(pExt); } + void AddDestructionObserver(DestructionObserverIface* observer); + void RemoveDestructionObserver(DestructionObserverIface* observer); + // EmbedPDF(signatures): an opaque cache an SDK layer (the revision view) // attaches to this document for its lifetime. The bytes a document was // loaded from never change, so nothing invalidates it; it is destroyed @@ -373,8 +382,20 @@ class CPDF_Document : public Observable, virtual bool ShouldReplaceDeletedPageWithNull(uint32_t page_obj_num) const; private: - // EmbedPDF(measurement): see GetMeasureStorage(). - std::unique_ptr measure_storage_; + 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(); @@ -419,6 +440,12 @@ 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_; + + // EmbedPDF(measurement): see GetMeasureStorage(). + std::unique_ptr measure_storage_; + std::unique_ptr parser_; RetainPtr root_dict_; RetainPtr info_dict_; 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 9c49dcf23d..0000000000 --- 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 bc13fef9bc..d0794d3a6a 100644 --- a/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp +++ b/core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp @@ -42,14 +42,6 @@ TEST_F(FPDFRenderPatternEmbedderTest, ShadingStrokePaintsAfterSolidFill) { } } -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/core/fpdftext/cpdf_textpage.cpp b/core/fpdftext/cpdf_textpage.cpp index 5492ada288..3aea3313b4 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" @@ -908,8 +909,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; } @@ -962,7 +970,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/core/fxcodec/BUILD.gn b/core/fxcodec/BUILD.gn index ab7cf9da67..d32cfdd1e8 100644 --- a/core/fxcodec/BUILD.gn +++ b/core/fxcodec/BUILD.gn @@ -143,7 +143,6 @@ source_set("fxcodec") { "../../third_party:zlib", "../fxge", ] - defines = [] if (pdf_enable_brotli) { sources += [ "brotli/brotli_decoder.cpp", diff --git a/core/fxcrt/observed_ptr.cpp b/core/fxcrt/observed_ptr.cpp index a9b8030cc4..89a02a7ae8 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 7b93b1257e..fda88772bb 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 diff --git a/core/fxge/BUILD.gn b/core/fxge/BUILD.gn index c452174e40..74a020f099 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", @@ -89,6 +80,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", @@ -198,10 +191,8 @@ source_set("fxge") { } if (pdf_enable_fontations) { - configs += [ ":skrifa_cxx_config" ] deps += [ ":skrifa_cxx", - ":skrifa_cxx_cpp", "//build/rust:cxx_cppdeps", ] } @@ -271,27 +262,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", - ] - configs += [ ":skrifa_cxx_config" ] - } - - source_set("skrifa_cxx_cpp") { - sources = [ - "skrifa/src/outlines.cpp", - "skrifa/src/outlines.h", - ] - deps = [ - ":skrifa_cxx", - "//build/rust:cxx_cppdeps", - ] - configs -= [ "//build/config/compiler:chromium_code" ] - configs += [ - "//build/config/compiler:no_chromium_code", - ":skrifa_cxx_config", + "//third_party/rust/read_fonts/v0_47:lib", + "//third_party/rust/skrifa/v0_50:lib", ] - visibility = [ ":*" ] + configs += [ "../../:pdfium_common_config" ] } } @@ -373,10 +347,8 @@ pdfium_unittest_source_set("unittests") { sources += [ "skrifa/fx_skrifa_unittest.cpp" ] deps += [ ":skrifa_cxx", - ":skrifa_cxx_cpp", "//build/rust:cxx_cppdeps", ] - configs += [ ":skrifa_cxx_config" ] } } diff --git a/core/fxge/dib/cfx_dibitmap.cpp b/core/fxge/dib/cfx_dibitmap.cpp index 6d63bc7d6b..7d665ff00b 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 0000000000..459ef3352e --- /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 0000000000..12d4c39c42 --- /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 3efbb1265e..36cd0cf5f6 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); + } + } +} diff --git a/core/fxge/dib/cfx_scanlinecompositor_hwy.cpp b/core/fxge/dib/cfx_scanlinecompositor_hwy.cpp index f8d8e493f0..dea4e047e8 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); } diff --git a/core/fxge/dib/cfx_scanlinecompositor_unittest.cpp b/core/fxge/dib/cfx_scanlinecompositor_unittest.cpp index 4631476276..d5a3b76951 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); diff --git a/core/fxge/skia/fx_skia_device_embeddertest.cpp b/core/fxge/skia/fx_skia_device_embeddertest.cpp index 26c8a9d272..d23b28d39a 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; diff --git a/core/fxge/skrifa/fx_skrifa_unittest.cpp b/core/fxge/skrifa/fx_skrifa_unittest.cpp index c549e5e0bc..d4334888b7 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 346ad3e636..4c904a4eec 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}, @@ -171,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!("outlines.h"); - - fn run(font_path: &str); - } } use skrifa_ffi::{ @@ -385,7 +377,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, @@ -1072,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 a5b475f8c2..0000000000 --- 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 58f3c7b9c7..0000000000 --- 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); -} diff --git a/docs/embedpdf/syncs/2026-11-24-bd217de841.md b/docs/embedpdf/syncs/2026-11-24-bd217de841.md new file mode 100644 index 0000000000..bc9d261bb2 --- /dev/null +++ b/docs/embedpdf/syncs/2026-11-24-bd217de841.md @@ -0,0 +1,140 @@ +# Sync 2026-11-24: upstream 1f02bc7d9..bd217de84 (34 commits) + +## Summary + +Upstream from 2026-11-15 to 2026-11-23, merged into `f596d901c`. + +FreeType is now 2.15.0, the text page no longer overflows on extreme pages, and `ObservedPtr` lost +its virtual base. Four conflicts, all small. Upstream removed the `HashBitmap()` test helper our +tests use, so we keep our own, and moved a few embedder tests to a new runner our CI does not run +(below). + +## Likely security fixes + +- `721a620a0a` 2026-11-19 Fix float-cast-overflow in FindTextlineFlowOrientation() +- `5f70cd3483` 2026-11-16 Move pdf_jpx_fuzzer decoding logic into pdf_jpx_fuzzer_common + +Taken as upstream wrote them. `721a620a0a` is in our builds (text extraction of pages with a huge +`/MediaBox`, or text scaled to extremes); `5f70cd3483` only moves fuzzer code, not built by us. Also +security-relevant: the FreeType roll (below). + +## Conflicts (4 files, 5 blocks) + +A block with an `EPDF_TLS` count is never resolved by taking upstream's side without putting +`EPDF_TLS` back (rule thread-confined-globals). + +| File | Blocks | Rules in the blocks | EPDF_TLS | Upstream commits | Resolution | +| :-- | --: | :-- | --: | :-- | :-- | +| `core/fpdfapi/parser/cpdf_document.cpp` | 1 | layer-seam | | `0fb188cc6c` Split CPDF_Document::DestructionObserverIface from Observable | Both: our cached `/Root` and `/Info` setters, then upstream's `DestructionNotifier`. | +| `core/fpdfapi/parser/cpdf_document.h` | 2 | fonts, layer-door, layer-save, layer-seam, layer-transaction, measurement, reads-dont-write, rich-text, save-traversal, signatures | | `0fb188cc6c` Split CPDF_Document::DestructionObserverIface from Observable | Both. Upstream's `AddDestructionObserver()`/`RemoveDestructionObserver()` go where upstream has them, before our seams; our virtual `/Root`, `/Info` and parser accessors stay. Upstream requires the notifier to be the first member (destroyed after all others), so our `measure_storage_` moves down to the data members, right after it: it still outlives everything else of ours, as before. | +| `core/fpdfapi/render/fpdf_render_pattern_embeddertest.cpp` | 1 | untagged | | `aff95024b4` Migrate pure display list embedder tests to drawing tests | Our shading-stroke test; upstream's `LoadError547706` is dropped, upstream moved it to a drawing test. | +| `public/cpp/fpdf_deleters.h` | 1 | untagged | | `b1a236fed0` Create ScopedFPDFXObject | Our relative includes (the headers are packaged on their own), plus upstream's new `fpdf_ppo.h`. | + +## Write audit (0 lines) + +None. + +## Upstream changes outside the conflicts + +- **FreeType 2.14.3-146 to 2.15.0-10 (`0b43db186f`, `0d0cf3a356`, `96cb92b773`, 16 commits):** + bounds the `hdmx` advance lookup (`023fd06e3`) and fixes overflows in CFF blend (`79d80cadf`) and + variable composite axis values (`e2526d30e`), among others. PDFium's custom config still turns + variable fonts off (`TT_CONFIG_OPTION_GX_VAR_SUPPORT`), so its `avar` version 2 change does not + reach us. No new golden differences. +- **Text page overflow (`721a620a0a`):** `CPDF_TextPage::FindTextlineFlowOrientation()` checks page + size before casting to `int` and saturates the line height. Upstream's two new tests pass. +- **Destruction observers (`0fb188cc6c`, `b47c2e370e`):** `CPDF_DataAvail` now watches a document + through `CPDF_Document::DestructionNotifier`; `ObservedPtr` no longer needs a virtual base class. + Nothing of ours implemented the old `Observable::ObserverIface`. +- **Form-fill JS call-outs (`66ed17ef8f`):** every remaining `IPDF_JSPLATFORM` call-out sets + `in_active_ffi_callback_`, which makes destroying the form-fill environment from inside one a + CHECK. The engine never drives the form-fill environment. +- **Rendering (`8a07c5de59`, `cb73733715`, `4c92ae872b`):** Highway versions of `MultiplyAlpha()` + and `MultiplyAlphaMask()` for BGRA, and BGRA-to-mask compositing in 16-bit lanes; upstream's tests + check them against the scalar loops. +- **`HashBitmap()` removed (`afcec981f6`):** `EmbedderTest::BitmapsEqual()` replaces it. Our tests + compare renders of documents that close in between, so a digest suits them; a copy of the helper + now lives in `fpdfsdk/epdf_edit_test_util.{h,cpp}`, and our 42 uses are unchanged. + `epdf_save_embeddertest.cpp` and `epdf_layer_embeddertest.cpp` include it now. +- **Drawing tests (`2bc1255c48`, `aff95024b4`, `873ded4e41`):** a new runner, + `run_drawing_tests.py`, compares `pdfium_test --dump` output with expected text. It takes over + tests from the embedder suite (`LoadError547706`, `RenderAnnotWithOnlyRolloverAP`, + `RenderPageToDisplayList` and the whole of `fpdf_parser_decode_embeddertest.cpp`), and our CI does + not run it. See Tests and Proposed, not done. +- **Build:** `PDF_ENABLE_FONTATIONS` and `PDF_ENABLE_FREETYPE` move to the public config + (`6372d801de`), `pdfium_common_config` loses its empty `cflags_cc` and `ldflags` lists + (`bd217de841`) and gains `target_gen_dir`. None of our additions used the removed lists. +- Not in our builds: XFA and V8 (`c9a1ea6d05`, `20e2d231bb`, `dd810f17f5`), Skia and Fontations + (`30f1c04da5`, `171c17bfd4`, `b5232dabe0`), XFA's barcode and text-out tests (`c6a3053418`, + `86e81c6e7c`), fuzzers (`5f70cd3483`). + +## Upstream appearance generator + +None. + +## Globals + +No new globals by the heuristic. `check-globals.py` on the darwin-arm64 release build: ok (263 +shared writable, 26 thread-local; one thread-local more than S18: our own +`g_thread_users`, from fork PR #128). + +## Build and patches + +- `DEPS` changed in 10 commits: FreeType (3), llvm-libc, rust (2), V8, Code Coverage, goldctl, + Instrumented Libraries. FreeType is in our builds, and llvm-libc through the bundled libc++. + Synced with `gclient sync --no-history --shallow`. +- All of `patches/embedpdf-runtime/` apply: every target's patches dry-run against clean sources, + and darwin-arm64 and wasm32 build. + +## API diff + +None from upstream: `ScopedFPDFXObject` (`b1a236fed0`) is a C++ helper in `public/cpp`. The +darwin-arm64 exports match the public headers, as in S18. + +## Tests + +- [x] fork unit + embedder tests (darwin-arm64): 1412 unit tests pass, upstream's new ones included. + Embedder: 1904 tests run, 9 skipped, 12 failing: exactly S18's list, every one "Pixels do not + match" against a Mac PNG golden. Linux runs in the PR's CI. + The 12, as the baseline for the next sync: + - `EPDFMeasureEmbedderTest.CaptionAppearanceGolden` + - `FPDFEditEmbedderTest.SetTextRenderMode` + - `FPDFProgressiveRenderEmbedderTest.RenderAnnotWithPause` + - `FPDFProgressiveRenderEmbedderTest.RenderFormsWithPause` + - `FPDFProgressiveRenderEmbedderTest.RenderHighlightWithColorScheme` + - `FPDFProgressiveRenderEmbedderTest.RenderHighlightWithColorSchemeAndConvertFillToStroke` + - `FPDFProgressiveRenderEmbedderTest.RenderStampWithColorScheme` + - `FPDFProgressiveRenderEmbedderTest.RenderTextWithColorScheme` + - `FPDFProgressiveRenderEmbedderTest.RenderWithPause` + - `FPDFProgressiveRenderEmbedderTest.RenderWithoutPause` + - `FPDFViewEmbedderTest.RenderBug664284WithNoNativeText` + - `FPDFViewEmbedderTest.RenderHelloWorldWithFlags` +- [x] upstream's drawing tests (`run_drawing_tests.py`, not part of our CI), on the darwin-arm64 + test build: 5 of 7 pass, five of the six migrated ones (`bug_547706`, + `annotation_highlight_rollover_ap`, `rectangles`, `bug_552046`, `bug_555784`). The sixth, + `bug_455199`, and upstream's new `hello_world` differ in the font only: the fork draws the + standard fonts with its built-in faces (only the embedder tests ask for the system's), and the + expectations name the system fonts. Glyph positions match. +- [x] layer mode: exit 0; 213 layer-only failures, all expected; 185 crashes as in S18; 588 writers + (519 in S18; the fork's own PRs recorded theirs, and this sync adds none and changes no count). + One warning: `EPDFSlicedLoadEmbedderTest.SlicesKeepToTheirBudget` failed under load and passed + alone, a timing test, as before. (A Mac recording drops the Linux-only + `TransFormWithClipAndSaveWithLocale`; its line stays.) +- [x] tag check (`--base bd217de841`): 1017 blocks, 0 untagged. +- [x] C API check: ok, 604 functions in 24 headers (599 in S18; the fork's own PRs). +- [x] globals check: ok. +- [x] wasm build: builds locally. +- [ ] ThreadSanitizer soak: in the PR's CI. +- [ ] engine tests and engine-conformance with the local runtime: not run for this sync. +- changed expectations, each with its reason: none. `fpdf_render_pattern_embeddertest.cpp` loses + `LoadError547706` (moved to a drawing test by `aff95024b4`). + +## Ledger changes proposed + +None. + +## Proposed, not done + +- Run upstream's drawing tests in our CI, so the tests moved out of the embedder suite stay covered. + `pdfium_test` would need the standard fonts from the system, as + `CFX_FontMapper::SetStandardFontsFromSystemForTesting()` gives the embedder tests. diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp index f931b2ae50..d737b76f42 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 a25cc62877..02a9520709 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/epdf_edit_test_util.cpp b/fpdfsdk/epdf_edit_test_util.cpp index 83f9321e34..5d7515fcfd 100644 --- a/fpdfsdk/epdf_edit_test_util.cpp +++ b/fpdfsdk/epdf_edit_test_util.cpp @@ -18,6 +18,7 @@ #include "testing/embedder_test.h" #include "testing/fx_string_testhelpers.h" #include "testing/gtest/include/gtest/gtest.h" +#include "testing/utils/hash.h" namespace { @@ -200,6 +201,23 @@ uint32_t ColorAt(FPDF_PAGE page, int x, int y_from_bottom) { return (pixel[2] << 16) | (pixel[1] << 8) | pixel[0]; } +std::string HashBitmap(FPDF_BITMAP bitmap) { + const size_t stride = FPDFBitmap_GetStride(bitmap); + const size_t row_bytes = + static_cast( + EmbedderTest::BytesPerPixelForFormat(FPDFBitmap_GetFormat(bitmap))) * + FPDFBitmap_GetWidth(bitmap); + const auto* pixels = + static_cast(FPDFBitmap_GetBuffer(bitmap)); + std::vector rows; + rows.reserve(row_bytes * FPDFBitmap_GetHeight(bitmap)); + for (int i = 0; i < FPDFBitmap_GetHeight(bitmap); ++i) { + const uint8_t* row = pixels + i * stride; + rows.insert(rows.end(), row, row + row_bytes); + } + return GenerateMD5Base16(rows); +} + std::string AnnotString(FPDF_ANNOTATION annot, const char* key) { const unsigned long length = FPDFAnnot_GetStringValue(annot, key, nullptr, 0); if (length < sizeof(FPDF_WCHAR)) { diff --git a/fpdfsdk/epdf_edit_test_util.h b/fpdfsdk/epdf_edit_test_util.h index b4e5f0b01c..b0948e6855 100644 --- a/fpdfsdk/epdf_edit_test_util.h +++ b/fpdfsdk/epdf_edit_test_util.h @@ -81,6 +81,10 @@ void AddPngStamp(FPDF_DOCUMENT doc, // The colour at a point of a page rendered with its annotations, as 0xRRGGBB. uint32_t ColorAt(FPDF_PAGE page, int x, int y_from_bottom); +// A digest of the pixels of `bitmap`, without the padding after each row: for +// comparing renders whose bitmaps don't live side by side. +std::string HashBitmap(FPDF_BITMAP bitmap); + // An annotation's string value |key| as UTF-8; empty when it has none or the // handle is invalid. std::string AnnotString(FPDF_ANNOTATION annot, const char* key); diff --git a/fpdfsdk/epdf_layer_embeddertest.cpp b/fpdfsdk/epdf_layer_embeddertest.cpp index 23d1ff5b48..1a0abc7c73 100644 --- a/fpdfsdk/epdf_layer_embeddertest.cpp +++ b/fpdfsdk/epdf_layer_embeddertest.cpp @@ -16,6 +16,7 @@ #include "core/fpdfapi/parser/cpdf_document.h" #include "core/fpdfapi/parser/cpdf_reference.h" #include "fpdfsdk/cpdfsdk_helpers.h" +#include "fpdfsdk/epdf_edit_test_util.h" #include "public/cpp/fpdf_scopers.h" #include "public/epdf_annot.h" #include "public/epdf_doc.h" diff --git a/fpdfsdk/epdf_save_embeddertest.cpp b/fpdfsdk/epdf_save_embeddertest.cpp index aba5a4ba14..94e93ee2d5 100644 --- a/fpdfsdk/epdf_save_embeddertest.cpp +++ b/fpdfsdk/epdf_save_embeddertest.cpp @@ -43,6 +43,7 @@ #include "core/fxcrt/cfx_read_only_span_stream.h" #include "core/fxcrt/data_vector.h" #include "fpdfsdk/cpdfsdk_helpers.h" +#include "fpdfsdk/epdf_edit_test_util.h" #include "public/cpp/fpdf_scopers.h" #include "public/epdf_annot.h" #include "public/epdf_layer.h" diff --git a/fpdfsdk/formfiller/cffl_combobox.cpp b/fpdfsdk/formfiller/cffl_combobox.cpp index ab1f3d3bc6..6c8e3c2e8e 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 fd0c6d80fc..c659be0873 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 9d76623891..9008893447 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 d919f7ee3b..27a32ef613 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, diff --git a/fpdfsdk/fpdf_annot_embeddertest.cpp b/fpdfsdk/fpdf_annot_embeddertest.cpp index babd272360..9a6334ca62 100644 --- a/fpdfsdk/fpdf_annot_embeddertest.cpp +++ b/fpdfsdk/fpdf_annot_embeddertest.cpp @@ -519,20 +519,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_edit_embeddertest.cpp b/fpdfsdk/fpdf_edit_embeddertest.cpp index 985f78fe9b..8c89f8940c 100644 --- a/fpdfsdk/fpdf_edit_embeddertest.cpp +++ b/fpdfsdk/fpdf_edit_embeddertest.cpp @@ -5599,22 +5599,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()); } }; @@ -5646,29 +5644,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 a130f75d1c..c3a35fb92a 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 adaf336641..d684c73e64 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()); } }; @@ -167,8 +166,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 +178,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 +201,6 @@ TEST_F(FPDFPPOEmbedderTest, ImportPageToXObject) { } EXPECT_TRUE(FPDF_SaveAsCopy(output_doc.get(), this, 0)); - - FPDF_CloseXObject(xobject); } static constexpr int kExpectedPageCount = 2; @@ -256,7 +254,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 +262,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 +275,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"); @@ -699,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( @@ -712,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` @@ -723,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) { @@ -740,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 @@ -751,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 1a09c2e807..44de57f2f1 100644 --- a/fpdfsdk/fpdf_save_embeddertest.cpp +++ b/fpdfsdk/fpdf_save_embeddertest.cpp @@ -154,7 +154,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) { @@ -163,7 +163,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); } // EmbedPDF(layer-mode): the whole file, as layer mode loads it. Loading the @@ -193,7 +193,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())); } } @@ -264,7 +264,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) { @@ -324,8 +323,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_text_embeddertest.cpp b/fpdfsdk/fpdf_text_embeddertest.cpp index 85769373fa..0e519b96b7 100644 --- a/fpdfsdk/fpdf_text_embeddertest.cpp +++ b/fpdfsdk/fpdf_text_embeddertest.cpp @@ -14,6 +14,7 @@ #include "public/cpp/fpdf_scopers.h" #include "public/epdf_text.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" @@ -2726,3 +2727,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)); + } +} diff --git a/fpdfsdk/fpdf_view_embeddertest.cpp b/fpdfsdk/fpdf_view_embeddertest.cpp index 99b9c94abf..30149c7a60 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(); @@ -2288,15 +2284,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/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp index 062c387dfa..b46ade7ddb 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( diff --git a/fxbarcode/BUILD.gn b/fxbarcode/BUILD.gn index 78fce1a6d9..21abdd8ecb 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 53ccec1780..7528be888e 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) { diff --git a/fxjs/xfa/cfxjse_class.cpp b/fxjs/xfa/cfxjse_class.cpp index d8102edf4d..fc84c7165a 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 6132fe0c0e..71590fa13f 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 e0fc3a14b0..a738850cb9 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 24d79b6e04..5bb4b603a4 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 f253d6d46b..f1d176e62b 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); @@ -190,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, diff --git a/fxjs/xfa/cfxjse_resolveprocessor.cpp b/fxjs/xfa/cfxjse_resolveprocessor.cpp index 96cec1b38e..bcdea2dbba 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/fxjs/xfa/cjx_object.cpp b/fxjs/xfa/cjx_object.cpp index f4d813d3f9..b4ed9cbb2a 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/public/cpp/fpdf_deleters.h b/public/cpp/fpdf_deleters.h index 55b85d9ed7..c2a9a615ac 100644 --- a/public/cpp/fpdf_deleters.h +++ b/public/cpp/fpdf_deleters.h @@ -10,6 +10,7 @@ #include "../fpdf_edit.h" #include "../fpdf_formfill.h" #include "../fpdf_javascript.h" +#include "../fpdf_ppo.h" #include "../fpdf_structtree.h" #include "../fpdf_text.h" #include "../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 34cf9c46a9..a87b112dbd 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_ diff --git a/skia/BUILD.gn b/skia/BUILD.gn index 07988a8d78..36bb0ea044 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_47:lib", + "//third_party/rust/skrifa/v0_50:lib", ] configs -= [ "//build/config/compiler:chromium_code" ] configs += [ diff --git a/testing/BUILD.gn b/testing/BUILD.gn index ae87f02a43..f1d7050ef0 100644 --- a/testing/BUILD.gn +++ b/testing/BUILD.gn @@ -246,7 +246,6 @@ source_set("embedder_test_support") { ] deps = [ ":path_service", - "../core/fdrm", "../core/fxge", "../fpdfsdk", "../fpdfsdk:test_support", diff --git a/testing/SUPPRESSIONS b/testing/SUPPRESSIONS index ebd08760d4..d288ab8a03 100644 --- a/testing/SUPPRESSIONS +++ b/testing/SUPPRESSIONS @@ -62,8 +62,8 @@ 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 * * * fontations fuzzy=25,0.25,15 +3bigpreview.pdf * * * * fuzzy=21,0.15,25 +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 diff --git a/testing/embedder_test.cpp b/testing/embedder_test.cpp index 926a4e2983..e941c4c06c 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" @@ -40,7 +39,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" @@ -1282,24 +1280,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 7d7402798b..e5db80e50f 100644 --- a/testing/embedder_test.h +++ b/testing/embedder_test.h @@ -348,9 +348,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`. diff --git a/testing/embedder_test_constants.h b/testing/embedder_test_constants.h index d1c68d4a1d..4ba242e7a0 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/fuzzers/BUILD.gn b/testing/fuzzers/BUILD.gn index ec350de5b7..d0a85bf87b 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,6 +189,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) { @@ -567,12 +584,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", - ] + deps = [ ":pdf_jpx_fuzzer_common" ] } pdfium_fuzzer("pdf_psengine_fuzzer") { diff --git a/testing/fuzzers/pdf_jpx_fuzzer.cc b/testing/fuzzers/pdf_jpx_fuzzer.cc index 2800f7eb44..8ce75a7599 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 0000000000..780eb8b2a2 --- /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 0000000000..4b317ff0f3 --- /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_ diff --git a/testing/resources/bug_552046.pdf b/testing/resources/bug_552046.pdf deleted file mode 100644 index a60432dc95..0000000000 Binary files a/testing/resources/bug_552046.pdf and /dev/null differ diff --git a/testing/resources/bug_555784.pdf b/testing/resources/bug_555784.pdf deleted file mode 100644 index 5c56a958d2..0000000000 Binary files a/testing/resources/bug_555784.pdf and /dev/null differ 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 0000000000..6aae497e6a --- /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 0000000000..2a03794224 --- /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 0000000000..114b2f67b6 --- /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 2afc252c75..f0610ee178 100644 Binary files a/testing/resources/bug_552046.in and b/testing/resources/drawing/bug_552046.in differ diff --git a/testing/resources/drawing/bug_552046_expected.pdf.0.dump.txt b/testing/resources/drawing/bug_552046_expected.pdf.0.dump.txt new file mode 100644 index 0000000000..c12b8ef305 --- /dev/null +++ b/testing/resources/drawing/bug_552046_expected.pdf.0.dump.txt @@ -0,0 +1,6 @@ +SaveState +SetBaseClip [0,0,612,792] +SetClip_PathFill rule=winding matrix=none points=[move(0.0000,792.0000) line(0.0000,0.0000) line(612.0000,0.0000) line(612.0000,792.0000) line(0.0000,792.0000,close)] +SaveState +RestoreState +RestoreState diff --git a/testing/resources/bug_555784.in b/testing/resources/drawing/bug_555784.in similarity index 99% rename from testing/resources/bug_555784.in rename to testing/resources/drawing/bug_555784.in index 95018f8ff3..3f9dcfda55 100644 --- a/testing/resources/bug_555784.in +++ b/testing/resources/drawing/bug_555784.in @@ -35,6 +35,10 @@ endobj >> 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/hello_world.in b/testing/resources/drawing/hello_world.in new file mode 100644 index 0000000000..910ef317b3 --- /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 0000000000..2a03794224 --- /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/rectangles.in b/testing/resources/drawing/rectangles.in new file mode 100644 index 0000000000..73345161af --- /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 0000000000..b2d23ce470 --- /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 diff --git a/testing/resources/drawing/xfa_specific/README.md b/testing/resources/drawing/xfa_specific/README.md new file mode 100644 index 0000000000..46ba3c0f52 --- /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 0000000000..de59049520 --- /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 9edd9b5994..f33ae168c5 100644 --- a/testing/tools/test_runner.py +++ b/testing/tools/test_runner.py @@ -6,7 +6,9 @@ import argparse from dataclasses import dataclass, field from datetime import timedelta +import difflib from io import BytesIO +import itertools import multiprocessing import os import re @@ -33,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 @@ -317,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): @@ -404,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) @@ -498,7 +511,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() @@ -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() @@ -673,6 +686,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 +713,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 +729,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: @@ -723,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): @@ -736,22 +875,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') diff --git a/third_party/freetype/README.pdfium b/third_party/freetype/README.pdfium index 7e3e6cb401..ab033efc22 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-146 -Revision: 25167984d2435930f9178e8d9d2ca3bdfa71a4e7 +Version: VER-2-15-0-10 +Revision: 2b01fa2d6723bf12490822268c9627697ed89643 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 diff --git a/third_party/freetype/include/freetype-custom-config/ftoption.h b/third_party/freetype/include/freetype-custom-config/ftoption.h index 73abe17277..d3f43a0e3f 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 */ diff --git a/xfa/fde/BUILD.gn b/xfa/fde/BUILD.gn index c524733003..6ecb79e458 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 54980b78f5..1953160b38 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) diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp index d16de943ad..eae58a49cc 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 10255f2fd7..be999a2f06 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_; } diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 303d1f910d..6431bde9a0 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);