Bug 1341085 - Implement a pref that allows OpenType Variation tables to bypass the sanitizer, as it doesn't know about them. r=jrmuizel
authorJonathan Kew <jkew@mozilla.com>
Mon, 20 Feb 2017 18:00:54 +0000
changeset 372938 f305383515a1f74e0c34edd81f0590d3f44c45c1
parent 372937 e745c540c6ed60d4d097167e35249fa6744a47da
child 372939 711456564e1e73cc1e5c101e55a8f28bfb43a108
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1341085
milestone54.0a1
Bug 1341085 - Implement a pref that allows OpenType Variation tables to bypass the sanitizer, as it doesn't know about them. r=jrmuizel
gfx/thebes/gfxPrefs.h
gfx/thebes/gfxUserFontSet.cpp
modules/libpref/init/all.js
--- a/gfx/thebes/gfxPrefs.h
+++ b/gfx/thebes/gfxPrefs.h
@@ -378,16 +378,17 @@ private:
 
   DECL_GFX_PREF(Once, "gfx.device-reset.limit",                DeviceResetLimitCount, int32_t, 10);
   DECL_GFX_PREF(Once, "gfx.device-reset.threshold-ms",         DeviceResetThresholdMilliseconds, int32_t, -1);
 
   DECL_GFX_PREF(Once, "gfx.direct2d.disabled",                 Direct2DDisabled, bool, false);
   DECL_GFX_PREF(Once, "gfx.direct2d.force-enabled",            Direct2DForceEnabled, bool, false);
   DECL_GFX_PREF(Live, "gfx.direct3d11.reuse-decoder-device",   Direct3D11ReuseDecoderDevice, int32_t, -1);
   DECL_GFX_PREF(Live, "gfx.direct3d11.allow-intel-mutex",      Direct3D11AllowIntelMutex, bool, true);
+  DECL_GFX_PREF(Live, "gfx.downloadable_fonts.keep_variation_tables", KeepVariationTables, bool, false);
   DECL_GFX_PREF(Live, "gfx.downloadable_fonts.otl_validation", ValidateOTLTables, bool, true);
   DECL_GFX_PREF(Live, "gfx.draw-color-bars",                   CompositorDrawColorBars, bool, false);
   DECL_GFX_PREF(Once, "gfx.e10s.hide-plugins-for-scroll",      HidePluginsForScroll, bool, true);
   DECL_GFX_PREF(Live, "gfx.layerscope.enabled",                LayerScopeEnabled, bool, false);
   DECL_GFX_PREF(Live, "gfx.layerscope.port",                   LayerScopePort, int32_t, 23456);
   // Note that        "gfx.logging.level" is defined in Logging.h.
   DECL_GFX_PREF(Live, "gfx.logging.level",                     GfxLoggingLevel, int32_t, mozilla::gfx::LOG_DEFAULT);
   DECL_GFX_PREF(Once, "gfx.logging.crash.length",              GfxLoggingCrashLength, uint32_t, 16);
--- a/gfx/thebes/gfxUserFontSet.cpp
+++ b/gfx/thebes/gfxUserFontSet.cpp
@@ -176,25 +176,35 @@ gfxUserFontEntry::CreateFontInstance(con
 
 class gfxOTSContext : public ots::OTSContext {
 public:
     explicit gfxOTSContext(gfxUserFontEntry* aUserFontEntry)
         : mUserFontEntry(aUserFontEntry)
     {
         // Whether to apply OTS validation to OpenType Layout tables
         mCheckOTLTables = gfxPrefs::ValidateOTLTables();
+        // Whether to preserve Variation tables in downloaded fonts
+        mKeepVariationTables = gfxPrefs::KeepVariationTables();
     }
 
     virtual ots::TableAction GetTableAction(uint32_t aTag) override {
         // Preserve Graphite, color glyph and SVG tables,
-        // and possibly OTL tables (depending on pref)
+        // and possibly OTL and Variation tables (depending on prefs)
         if ((!mCheckOTLTables &&
              (aTag == TRUETYPE_TAG('G', 'D', 'E', 'F') ||
               aTag == TRUETYPE_TAG('G', 'P', 'O', 'S') ||
               aTag == TRUETYPE_TAG('G', 'S', 'U', 'B'))) ||
+            (mKeepVariationTables &&
+             (aTag == TRUETYPE_TAG('a', 'v', 'a', 'r') ||
+              aTag == TRUETYPE_TAG('c', 'v', 'a', 'r') ||
+              aTag == TRUETYPE_TAG('f', 'v', 'a', 'r') ||
+              aTag == TRUETYPE_TAG('g', 'v', 'a', 'r') ||
+              aTag == TRUETYPE_TAG('H', 'V', 'A', 'R') ||
+              aTag == TRUETYPE_TAG('M', 'V', 'A', 'R') ||
+              aTag == TRUETYPE_TAG('V', 'V', 'A', 'R'))) ||
             aTag == TRUETYPE_TAG('S', 'i', 'l', 'f') ||
             aTag == TRUETYPE_TAG('S', 'i', 'l', 'l') ||
             aTag == TRUETYPE_TAG('G', 'l', 'o', 'c') ||
             aTag == TRUETYPE_TAG('G', 'l', 'a', 't') ||
             aTag == TRUETYPE_TAG('F', 'e', 'a', 't') ||
             aTag == TRUETYPE_TAG('S', 'V', 'G', ' ') ||
             aTag == TRUETYPE_TAG('C', 'O', 'L', 'R') ||
             aTag == TRUETYPE_TAG('C', 'P', 'A', 'L')) {
@@ -224,16 +234,17 @@ public:
 
         mUserFontEntry->mFontSet->LogMessage(mUserFontEntry, msg.get());
     }
 
 private:
     gfxUserFontEntry* mUserFontEntry;
     nsTHashtable<nsCStringHashKey> mWarningsIssued;
     bool mCheckOTLTables;
+    bool mKeepVariationTables;
 };
 
 // Call the OTS library to sanitize an sfnt before attempting to use it.
 // Returns a newly-allocated block, or nullptr in case of fatal errors.
 const uint8_t*
 gfxUserFontEntry::SanitizeOpenTypeData(const uint8_t* aData,
                                        uint32_t       aLength,
                                        uint32_t&      aSaneLength,
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -743,16 +743,19 @@ pref("gfx.downloadable_fonts.woff2.enabl
 
 // Whether OTS validation should be applied to OpenType Layout (OTL) tables
 #ifdef RELEASE_OR_BETA
 pref("gfx.downloadable_fonts.otl_validation", false);
 #else
 pref("gfx.downloadable_fonts.otl_validation", true);
 #endif
 
+// Whether to preserve OpenType variation tables in fonts (bypassing OTS)
+pref("gfx.downloadable_fonts.keep_variation_tables", false);
+
 #ifdef ANDROID
 pref("gfx.bundled_fonts.enabled", true);
 pref("gfx.bundled_fonts.force-enabled", false);
 #endif
 
 // Do we fire a notification about missing fonts, so the front-end can decide
 // whether to try and do something about it (e.g. download additional fonts)?
 pref("gfx.missing_fonts.notify", false);