From 3d478b5e48c4889835f25450a9f3112870acfdc4 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Sat, 7 Jan 2017 22:20:25 +0000 Subject: [PATCH] Bug 1324739 - patch 2 - Enable use of sfntly in Skia-PDF to subset fonts. r=lsalzman,glandium --- build/clang-plugin/Utils.h | 2 + gfx/moz.build | 3 ++ gfx/sfntly/cpp/src/moz.build | 97 +++++++++++++++++++++++++++++++++++ gfx/skia/generate_mozbuild.py | 6 +++ gfx/skia/moz.build | 6 +++ toolkit/moz.configure | 25 +++++++++ 6 files changed, 139 insertions(+) create mode 100644 gfx/sfntly/cpp/src/moz.build diff --git a/build/clang-plugin/Utils.h b/build/clang-plugin/Utils.h index f56d32f93a82..e7fff8c8c5b7 100644 --- a/build/clang-plugin/Utils.h +++ b/build/clang-plugin/Utils.h @@ -184,6 +184,7 @@ inline bool isIgnoredPathForImplicitCtor(const Decl *Declaration) { End = llvm::sys::path::rend(FileName); for (; Begin != End; ++Begin) { if (Begin->compare_lower(StringRef("skia")) == 0 || + Begin->compare_lower(StringRef("sfntly")) == 0 || Begin->compare_lower(StringRef("angle")) == 0 || Begin->compare_lower(StringRef("harfbuzz")) == 0 || Begin->compare_lower(StringRef("hunspell")) == 0 || @@ -241,6 +242,7 @@ inline bool isIgnoredPathForSprintfLiteral(const CallExpr *Call, const SourceMan Begin->compare_lower(StringRef("mtransport")) == 0 || Begin->compare_lower(StringRef("protobuf")) == 0 || Begin->compare_lower(StringRef("skia")) == 0 || + Begin->compare_lower(StringRef("sfntly")) == 0 || // Gtest uses snprintf as GTEST_SNPRINTF_ with sizeof Begin->compare_lower(StringRef("testing")) == 0) { return true; diff --git a/gfx/moz.build b/gfx/moz.build index 250919891281..edd080c3faad 100644 --- a/gfx/moz.build +++ b/gfx/moz.build @@ -27,6 +27,9 @@ DIRS += [ if CONFIG['MOZ_ENABLE_SKIA']: DIRS += ['skia'] +if CONFIG['MOZ_ENABLE_SKIA_PDF_SFNTLY'] and CONFIG['ENABLE_INTL_API']: + DIRS += ['sfntly/cpp/src'] + if CONFIG['ENABLE_TESTS']: DIRS += ['tests/gtest'] diff --git a/gfx/sfntly/cpp/src/moz.build b/gfx/sfntly/cpp/src/moz.build new file mode 100644 index 000000000000..44cb69e67df6 --- /dev/null +++ b/gfx/sfntly/cpp/src/moz.build @@ -0,0 +1,97 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +EXPORTS += [ + 'sample/chromium/font_subsetter.h', +] + +UNIFIED_SOURCES += [ + 'sample/chromium/font_subsetter.cc', + 'sample/chromium/subsetter_impl.cc', +] + +UNIFIED_SOURCES += [ + 'sfntly/data/byte_array.cc', + 'sfntly/data/font_data.cc', + 'sfntly/data/font_input_stream.cc', + 'sfntly/data/font_output_stream.cc', + 'sfntly/data/growable_memory_byte_array.cc', + 'sfntly/data/memory_byte_array.cc', + 'sfntly/data/readable_font_data.cc', + 'sfntly/data/writable_font_data.cc', +] + +UNIFIED_SOURCES += [ + 'sfntly/font.cc', + 'sfntly/font_factory.cc', + 'sfntly/tag.cc', +] + +UNIFIED_SOURCES += [ + 'sfntly/port/file_input_stream.cc', + 'sfntly/port/lock.cc', + 'sfntly/port/memory_input_stream.cc', + 'sfntly/port/memory_output_stream.cc', +] + +UNIFIED_SOURCES += [ + 'sfntly/table/byte_array_table_builder.cc', + 'sfntly/table/font_data_table.cc', + 'sfntly/table/generic_table_builder.cc', + 'sfntly/table/header.cc', + 'sfntly/table/subtable.cc', + 'sfntly/table/table.cc', + 'sfntly/table/table_based_table_builder.cc', +] + +UNIFIED_SOURCES += [ + 'sfntly/table/bitmap/big_glyph_metrics.cc', + 'sfntly/table/bitmap/bitmap_glyph.cc', + 'sfntly/table/bitmap/bitmap_glyph_info.cc', + 'sfntly/table/bitmap/bitmap_size_table.cc', + 'sfntly/table/bitmap/composite_bitmap_glyph.cc', + 'sfntly/table/bitmap/ebdt_table.cc', + 'sfntly/table/bitmap/eblc_table.cc', + 'sfntly/table/bitmap/ebsc_table.cc', + 'sfntly/table/bitmap/glyph_metrics.cc', + 'sfntly/table/bitmap/index_sub_table.cc', + 'sfntly/table/bitmap/index_sub_table_format1.cc', + 'sfntly/table/bitmap/index_sub_table_format2.cc', + 'sfntly/table/bitmap/index_sub_table_format3.cc', + 'sfntly/table/bitmap/index_sub_table_format4.cc', + 'sfntly/table/bitmap/index_sub_table_format5.cc', + 'sfntly/table/bitmap/simple_bitmap_glyph.cc', + 'sfntly/table/bitmap/small_glyph_metrics.cc', +] + +UNIFIED_SOURCES += [ + 'sfntly/table/core/cmap_table.cc', + 'sfntly/table/core/font_header_table.cc', + 'sfntly/table/core/horizontal_device_metrics_table.cc', + 'sfntly/table/core/horizontal_header_table.cc', + 'sfntly/table/core/horizontal_metrics_table.cc', + 'sfntly/table/core/maximum_profile_table.cc', + 'sfntly/table/core/name_table.cc', + 'sfntly/table/core/os2_table.cc', +] + +UNIFIED_SOURCES += [ + 'sfntly/table/truetype/glyph_table.cc', + 'sfntly/table/truetype/loca_table.cc', +] + +UNIFIED_SOURCES += [ + 'sfntly/tools/subsetter/glyph_table_subsetter.cc', + 'sfntly/tools/subsetter/subsetter.cc', + 'sfntly/tools/subsetter/table_subsetter_impl.cc', +] + +# We allow warnings for third-party code that can be updated from upstream. +ALLOW_COMPILER_WARNINGS = True + +FINAL_LIBRARY = 'gkmedias' + +DEFINES['SFNTLY_NO_EXCEPTION'] = 1 diff --git a/gfx/skia/generate_mozbuild.py b/gfx/skia/generate_mozbuild.py index bb069870a8a5..e06ae3457a47 100755 --- a/gfx/skia/generate_mozbuild.py +++ b/gfx/skia/generate_mozbuild.py @@ -111,6 +111,9 @@ elif CONFIG['CPU_ARCH'] == 'arm' and CONFIG['GNU_CC'] and CONFIG['BUILD_ARM_NEON DEFINES['SKIA_IMPLEMENTATION'] = 1 +if CONFIG['MOZ_ENABLE_SKIA_PDF_SFNTLY'] and CONFIG['ENABLE_INTL_API']: + DEFINES['SK_PDF_USE_SFNTLY'] = 1 + if not CONFIG['MOZ_ENABLE_SKIA_GPU']: DEFINES['SK_SUPPORT_GPU'] = 0 @@ -146,6 +149,9 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'android'): if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3'): CXXFLAGS += CONFIG['MOZ_PANGO_CFLAGS'] + +if CONFIG['MOZ_ENABLE_SKIA_PDF_SFNTLY']: + LOCAL_INCLUDES += CONFIG['SFNTLY_INCLUDES'] """ import json diff --git a/gfx/skia/moz.build b/gfx/skia/moz.build index 7a3ef654918b..2118677ca3a8 100644 --- a/gfx/skia/moz.build +++ b/gfx/skia/moz.build @@ -721,6 +721,9 @@ elif CONFIG['CPU_ARCH'] == 'arm' and CONFIG['GNU_CC'] and CONFIG['BUILD_ARM_NEON DEFINES['SKIA_IMPLEMENTATION'] = 1 +if CONFIG['MOZ_ENABLE_SKIA_PDF_SFNTLY'] and CONFIG['ENABLE_INTL_API']: + DEFINES['SK_PDF_USE_SFNTLY'] = 1 + if not CONFIG['MOZ_ENABLE_SKIA_GPU']: DEFINES['SK_SUPPORT_GPU'] = 0 @@ -756,3 +759,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'android'): if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3'): CXXFLAGS += CONFIG['MOZ_PANGO_CFLAGS'] + +if CONFIG['MOZ_ENABLE_SKIA_PDF_SFNTLY']: + LOCAL_INCLUDES += CONFIG['SFNTLY_INCLUDES'] diff --git a/toolkit/moz.configure b/toolkit/moz.configure index 25ade12da9e6..4ca6f502fe44 100644 --- a/toolkit/moz.configure +++ b/toolkit/moz.configure @@ -823,6 +823,31 @@ def skia_pdf(value, skia, milestone): set_config('MOZ_ENABLE_SKIA_PDF', skia_pdf) set_define('MOZ_ENABLE_SKIA_PDF', skia_pdf) +option('--enable-skia-pdf-sfntly', help='Enable SFNTLY font subsetting in Skia PDF') + +@depends('--enable-skia-pdf-sfntly', skia_pdf) +def skia_pdf_sfntly(value, skia_pdf): + if value.origin == 'default': + return skia_pdf + if value and not skia_pdf: + die('Cannot enable SFNTLY subsetting without enabling Skia PDF') + if skia_pdf and value: + return True + +set_config('MOZ_ENABLE_SKIA_PDF_SFNTLY', skia_pdf_sfntly) +set_define('MOZ_ENABLE_SKIA_PDF_SFNTLY', skia_pdf_sfntly) + +@depends(skia_pdf_sfntly) +def sfntly_includes(skia_pdf_sfntly): + includes = [] + if skia_pdf_sfntly: + includes += [ + '/gfx/sfntly/cpp/src', + ] + return includes + +set_config('SFNTLY_INCLUDES', sfntly_includes) + @depends(skia, skia_gpu) def skia_includes(skia, skia_gpu): includes = []