SkPDF: Stop `#include PREPROCESSOR_DEFINE` pattern No more: #include SK_SFNTLY_SUBSETTER #include ZLIB_INCLUDE Also, rename SK_SFNTLY_SUBSETTER to SK_PDF_USE_SFNTLY to follow my pattern of prefixing SkPDF-specific defines with 'SK_PDF_'. The ZLIB_INCLUDE define is no longer is used by anyone. TODO: rename Sfntly to something pronounceable. GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2273343002 Review-Url: https://codereview.chromium.org/2273343002
diff --git a/BUILD.gn b/BUILD.gn index 6774890..bb451c3 100644 --- a/BUILD.gn +++ b/BUILD.gn
@@ -285,10 +285,7 @@ if (skia_use_sfntly) { deps += [ "//third_party/sfntly" ] - public_defines += [ - # TODO(halcanary): make this the default; this is the value Android uses. - "SK_SFNTLY_SUBSETTER=\"sample/chromium/font_subsetter.h\"", - ] + public_defines += [ "SK_PDF_USE_SFNTLY" ] } }
diff --git a/gyp/common_conditions.gypi b/gyp/common_conditions.gypi index c91f46a..df766b3 100644 --- a/gyp/common_conditions.gypi +++ b/gyp/common_conditions.gypi
@@ -381,7 +381,6 @@ # using freetype's embolden allows us to adjust fake bold settings at # draw-time, at which point we know which SkTypeface is being drawn 'SK_USE_FREETYPE_EMBOLDEN', - 'SK_SFNTLY_SUBSETTER "sample/chromium/font_subsetter.h"', # When built as part of the system image we can enable certian non-NDK # compliant optimizations. 'SK_BUILD_FOR_ANDROID_FRAMEWORK',
diff --git a/gyp/pdf.gyp b/gyp/pdf.gyp index aa8d6bf..be3ac4d 100644 --- a/gyp/pdf.gyp +++ b/gyp/pdf.gyp
@@ -38,13 +38,15 @@ 'conditions': [ [ 'skia_pdf_use_sfntly and not skia_android_framework and \ skia_os in ["win", "android", "linux", "mac"]', - { 'dependencies': [ 'sfntly.gyp:sfntly' ] } + { + 'dependencies': [ 'sfntly.gyp:sfntly' ], + 'defines': [ 'SK_PDF_USE_SFNTLY' ], + } ], [ 'skia_android_framework', { # Add SFTNLY support for PDF (which in turns depends on ICU) - 'include_dirs': [ - 'external/sfntly/cpp/src', - ], + 'include_dirs': [ 'external/sfntly/cpp/src' ], + 'defines': [ 'SK_PDF_USE_SFNTLY' ], 'libraries': [ 'libsfntly.a', '-licuuc',
diff --git a/gyp/sfntly.gyp b/gyp/sfntly.gyp index 7ee7b98..09d4094 100644 --- a/gyp/sfntly.gyp +++ b/gyp/sfntly.gyp
@@ -15,9 +15,6 @@ }, 'direct_dependent_settings': { 'include_dirs': [ '<(sfntly_src_path)', ], - 'defines': [ - 'SK_SFNTLY_SUBSETTER="sample/chromium/font_subsetter.h"', - ], }, 'sources': [ '<(sfntly_src_path)/sample/chromium/font_subsetter.cc',
diff --git a/public.bzl b/public.bzl index 39926b5..ddd8c6a 100644 --- a/public.bzl +++ b/public.bzl
@@ -567,7 +567,7 @@ "PNG_SKIP_SETJMP_CHECK", "SK_BUILD_FOR_UNIX", "SK_SAMPLES_FOR_X", - "SK_SFNTLY_SUBSETTER", + "SK_PDF_USE_SFNTLY", "SK_CODEC_DECODES_RAW", "SK_HAS_GIF_LIBRARY", "SK_HAS_JPEG_LIBRARY",
diff --git a/src/pdf/SkDeflate.cpp b/src/pdf/SkDeflate.cpp index d4a8429..2c5a3ca 100644 --- a/src/pdf/SkDeflate.cpp +++ b/src/pdf/SkDeflate.cpp
@@ -9,11 +9,7 @@ #include "SkData.h" #include "SkDeflate.h" -#ifdef ZLIB_INCLUDE - #include ZLIB_INCLUDE -#else - #include "zlib.h" -#endif +#include "zlib.h" namespace {
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp index 2619724..389df62 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp
@@ -22,13 +22,13 @@ #include "SkTypes.h" #include "SkUtils.h" -#if defined (SK_SFNTLY_SUBSETTER) - #if defined (GOOGLE3) - // #including #defines doesn't work with this build system. - #include "sample/chromium/font_subsetter.h" - #else - #include SK_SFNTLY_SUBSETTER - #endif +// TODO(halcanary): Switch Chrome from SK_SFNTLY_SUBSETTER to SK_PDF_USE_SFNTLY. +#if defined(SK_SFNTLY_SUBSETTER) && !defined(SK_PDF_USE_SFNTLY) + #define SK_PDF_USE_SFNTLY +#endif + +#ifdef SK_PDF_USE_SFNTLY + #include "sample/chromium/font_subsetter.h" #endif namespace { @@ -142,7 +142,7 @@ return !SkToBool(metrics.fFlags & SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag); } -#ifdef SK_SFNTLY_SUBSETTER +#ifdef SK_PDF_USE_SFNTLY static bool can_subset(const SkAdvancedTypefaceMetrics& metrics) { return !SkToBool(metrics.fFlags & SkAdvancedTypefaceMetrics::kNotSubsettable_FontFlag); } @@ -336,7 +336,7 @@ } #endif -#ifdef SK_SFNTLY_SUBSETTER +#ifdef SK_PDF_USE_SFNTLY // if possible, make no copy. static sk_sp<SkData> stream_to_data(std::unique_ptr<SkStreamAsset> stream) { SkASSERT(stream); @@ -387,7 +387,7 @@ subsetStream->dict()->insertInt("Length1", subsetFontSize); return subsetStream; } -#endif // SK_SFNTLY_SUBSETTER +#endif // SK_PDF_USE_SFNTLY void SkPDFType0Font::getFontSubset(SkPDFCanon* canon) { const SkAdvancedTypefaceMetrics* metricsPtr = @@ -417,7 +417,7 @@ return; } - #ifdef SK_SFNTLY_SUBSETTER + #ifdef SK_PDF_USE_SFNTLY if (can_subset(metrics)) { // Generate glyph id array. in format needed by sfntly SkTDArray<uint32_t> glyphIDs; @@ -434,7 +434,7 @@ // If subsetting fails, fall back to original font data. fontAsset.reset(face->openStream(&ttcIndex)); } - #endif // SK_SFNTLY_SUBSETTER + #endif // SK_PDF_USE_SFNTLY auto fontStream = sk_make_sp<SkPDFSharedStream>(std::move(fontAsset)); fontStream->dict()->insertInt("Length1", fontSize); descriptor->insertObjRef("FontFile2", std::move(fontStream));
diff --git a/tests/PDFDeflateWStreamTest.cpp b/tests/PDFDeflateWStreamTest.cpp index 91c8c3f..2627508 100644 --- a/tests/PDFDeflateWStreamTest.cpp +++ b/tests/PDFDeflateWStreamTest.cpp
@@ -11,11 +11,7 @@ namespace { -#ifdef ZLIB_INCLUDE - #include ZLIB_INCLUDE -#else - #include "zlib.h" -#endif +#include "zlib.h" // Different zlib implementations use different T. // We've seen size_t and unsigned.