skia-harfbuzz-3.0.0.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Minimal diff for harfbuzz 3.0.0 support; based on:
  2. # https://github.com/google/skia/commit/66684b17b382
  3. # https://github.com/google/skia/commit/51d83abcd24a
  4. diff --git a/gn/skia.gni b/gn/skia.gni
  5. index d98fdc19ee..199335d5c4 100644
  6. --- a/gn/skia.gni
  7. +++ b/gn/skia.gni
  8. @@ -34,8 +34,6 @@ declare_args() {
  9. skia_include_multiframe_procs = false
  10. skia_lex = false
  11. skia_libgifcodec_path = "third_party/externals/libgifcodec"
  12. - skia_pdf_subset_harfbuzz =
  13. - false # TODO: set skia_pdf_subset_harfbuzz to skia_use_harfbuzz.
  14. skia_qt_path = getenv("QT_PATH")
  15. skia_skqp_global_error_tolerance = 0
  16. skia_tools_require_resources = false
  17. @@ -99,6 +97,10 @@ declare_args() {
  18. skia_use_libfuzzer_defaults = true
  19. }
  20. +declare_args() {
  21. + skia_pdf_subset_harfbuzz = skia_use_harfbuzz
  22. +}
  23. +
  24. declare_args() {
  25. skia_compile_sksl_tests = skia_compile_processors
  26. skia_enable_fontmgr_android = skia_use_expat && skia_use_freetype
  27. diff --git a/src/pdf/SkPDFSubsetFont.cpp b/src/pdf/SkPDFSubsetFont.cpp
  28. index 81c37eef3a..2340a7937b 100644
  29. --- a/src/pdf/SkPDFSubsetFont.cpp
  30. +++ b/src/pdf/SkPDFSubsetFont.cpp
  31. @@ -49,6 +49,37 @@ static sk_sp<SkData> to_data(HBBlob blob) {
  32. blob.release());
  33. }
  34. +template<typename...> using void_t = void;
  35. +template<typename T, typename = void>
  36. +struct SkPDFHarfBuzzSubset {
  37. + // This is the HarfBuzz 3.0 interface.
  38. + // hb_subset_flags_t does not exist in 2.0. It isn't dependent on T, so inline the value of
  39. + // HB_SUBSET_FLAGS_RETAIN_GIDS until 2.0 is no longer supported.
  40. + static HBFace Make(T input, hb_face_t* face) {
  41. + // TODO: When possible, check if a font is 'tricky' with FT_IS_TRICKY.
  42. + // If it isn't known if a font is 'tricky', retain the hints.
  43. + hb_subset_input_set_flags(input, 2/*HB_SUBSET_FLAGS_RETAIN_GIDS*/);
  44. + return HBFace(hb_subset_or_fail(face, input));
  45. + }
  46. +};
  47. +template<typename T>
  48. +struct SkPDFHarfBuzzSubset<T, void_t<
  49. + decltype(hb_subset_input_set_retain_gids(std::declval<T>(), std::declval<bool>())),
  50. + decltype(hb_subset_input_set_drop_hints(std::declval<T>(), std::declval<bool>())),
  51. + decltype(hb_subset(std::declval<hb_face_t*>(), std::declval<T>()))
  52. + >>
  53. +{
  54. + // This is the HarfBuzz 2.0 (non-public) interface, used if it exists.
  55. + // This code should be removed as soon as all users are migrated to the newer API.
  56. + static HBFace Make(T input, hb_face_t* face) {
  57. + hb_subset_input_set_retain_gids(input, true);
  58. + // TODO: When possible, check if a font is 'tricky' with FT_IS_TRICKY.
  59. + // If it isn't known if a font is 'tricky', retain the hints.
  60. + hb_subset_input_set_drop_hints(input, false);
  61. + return HBFace(hb_subset(face, input));
  62. + }
  63. +};
  64. +
  65. static sk_sp<SkData> subset_harfbuzz(sk_sp<SkData> fontData,
  66. const SkPDFGlyphUse& glyphUsage,
  67. int ttcIndex) {
  68. @@ -71,11 +102,10 @@ static sk_sp<SkData> subset_harfbuzz(sk_sp<SkData> fontData,
  69. hb_set_t* glyphs = hb_subset_input_glyph_set(input.get());
  70. glyphUsage.getSetValues([&glyphs](unsigned gid) { hb_set_add(glyphs, gid);});
  71. - hb_subset_input_set_retain_gids(input.get(), true);
  72. - // TODO: When possible, check if a font is 'tricky' with FT_IS_TRICKY.
  73. - // If it isn't known if a font is 'tricky', retain the hints.
  74. - hb_subset_input_set_drop_hints(input.get(), false);
  75. - HBFace subset(hb_subset(face.get(), input.get()));
  76. + HBFace subset = SkPDFHarfBuzzSubset<hb_subset_input_t*>::Make(input.get(), face.get());
  77. + if (!subset) {
  78. + return nullptr;
  79. + }
  80. HBBlob result(hb_face_reference_blob(subset.get()));
  81. return to_data(std::move(result));
  82. }
  83. diff --git a/third_party/harfbuzz/BUILD.gn b/third_party/harfbuzz/BUILD.gn
  84. index 173830de62..4156607ef9 100644
  85. --- a/third_party/harfbuzz/BUILD.gn
  86. +++ b/third_party/harfbuzz/BUILD.gn
  87. @@ -14,6 +14,9 @@ if (skia_use_system_harfbuzz) {
  88. system("harfbuzz") {
  89. include_dirs = [ "/usr/include/harfbuzz" ]
  90. libs = [ "harfbuzz" ]
  91. + if (skia_pdf_subset_harfbuzz) {
  92. + libs += [ "harfbuzz-subset" ]
  93. + }
  94. }
  95. } else {
  96. third_party("harfbuzz") {