From 3c49d0dad3e5b5e4622d7bc5db067c2e757e5499 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 14 Oct 2023 18:54:46 -0400 Subject: [PATCH] LibPDF: Add a CFF_DEBUG toggle I'd like to put some debug prints behind this soon. No behavior change. --- AK/Debug.h.in | 4 ++++ Meta/CMake/all_the_debug_macros.cmake | 1 + Meta/gn/secondary/AK/BUILD.gn | 1 + Userland/Libraries/LibPDF/Fonts/CFF.cpp | 8 ++++++-- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/AK/Debug.h.in b/AK/Debug.h.in index 1bada8a86c..58215b9485 100644 --- a/AK/Debug.h.in +++ b/AK/Debug.h.in @@ -38,6 +38,10 @@ # cmakedefine01 CANVAS_RENDERING_CONTEXT_2D_DEBUG #endif +#ifndef CFF_DEBUG +# cmakedefine01 CFF_DEBUG +#endif + #ifndef CMAKE_DEBUG # cmakedefine01 CMAKE_DEBUG #endif diff --git a/Meta/CMake/all_the_debug_macros.cmake b/Meta/CMake/all_the_debug_macros.cmake index 83d7848eac..03aa94e562 100644 --- a/Meta/CMake/all_the_debug_macros.cmake +++ b/Meta/CMake/all_the_debug_macros.cmake @@ -14,6 +14,7 @@ set(BXVGA_DEBUG ON) set(CACHE_DEBUG ON) set(CALLBACK_MACHINE_DEBUG ON) set(CANVAS_RENDERING_CONTEXT_2D_DEBUG ON) +set(CFF_DEBUG ON) set(CMAKE_DEBUG ON) set(COMMIT_DEBUG ON) set(COMPOSE_DEBUG ON) diff --git a/Meta/gn/secondary/AK/BUILD.gn b/Meta/gn/secondary/AK/BUILD.gn index 3d07c0363a..352428abd0 100644 --- a/Meta/gn/secondary/AK/BUILD.gn +++ b/Meta/gn/secondary/AK/BUILD.gn @@ -243,6 +243,7 @@ write_cmake_config("ak_debug_gen") { "CACHE_DEBUG=", "CALLBACK_MACHINE_DEBUG=", "CANVAS_RENDERING_CONTEXT_2D_DEBUG=", + "CFF_DEBUG=", "CMAKE_DEBUG=", "COMPOSE_DEBUG=", "COPY_DEBUG=", diff --git a/Userland/Libraries/LibPDF/Fonts/CFF.cpp b/Userland/Libraries/LibPDF/Fonts/CFF.cpp index 34a1e0310a..121a7a2876 100644 --- a/Userland/Libraries/LibPDF/Fonts/CFF.cpp +++ b/Userland/Libraries/LibPDF/Fonts/CFF.cpp @@ -6,6 +6,7 @@ // CFF spec: https://adobe-type-tools.github.io/font-tech-notes/pdfs/5176.CFF.pdf +#include #include #include #include @@ -31,8 +32,9 @@ PDFErrorOr> CFF::create(ReadonlyBytes const& cff_bytes, RefPt // CFF spec, "7 Name INDEX" Vector font_names; TRY(parse_index(reader, [&](ReadonlyBytes const& data) -> PDFErrorOr { - auto string = TRY(String::from_utf8(data)); - return TRY(font_names.try_append(string)); + auto font_name = TRY(String::from_utf8(data)); + dbgln_if(CFF_DEBUG, "CFF font name '{}'", font_name); + return TRY(font_names.try_append(font_name)); })); auto cff = adopt_ref(*new CFF()); @@ -130,8 +132,10 @@ PDFErrorOr> CFF::create(ReadonlyBytes const& cff_bytes, RefPt // Encoding given or read if (encoding) { + dbgln_if(CFF_DEBUG, "CFF using external encoding"); cff->set_encoding(move(encoding)); } else { + dbgln_if(CFF_DEBUG, "CFF using embedded encoding"); auto encoding = Encoding::create(); for (size_t i = 0; i < glyphs.size(); i++) { if (i == 0) {