Bug 953385 - Set math script where applicable in /gfx. r=jfkthame
authorJames Kitchener <jkitch.bug@gmail.com>
Thu, 30 Jan 2014 10:59:16 -0500
changeset 181996 3844d3117861eb9ec8deb8594a72b7d1bc618901
parent 181995 11fe654f16d844f16ba922beaaf52bab01c450ce
child 181997 172f9773a08578ff76e6aec5695f50a4a2fc9c2a
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs953385
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 953385 - Set math script where applicable in /gfx. r=jfkthame
gfx/thebes/gfxFont.cpp
gfx/thebes/gfxFont.h
gfx/thebes/gfxHarfBuzzShaper.cpp
layout/media/symbols.def.in
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -3540,17 +3540,18 @@ gfxFont::SplitAndInitTextRun(gfxContext 
 
     InitWordCache();
     uint32_t wordCacheCharLimit =
         gfxPlatform::GetPlatform()->WordCacheCharLimit();
 
     // the only flags we care about for ShapedWord construction/caching
     uint32_t flags = aTextRun->GetFlags();
     flags &= (gfxTextRunFactory::TEXT_IS_RTL |
-              gfxTextRunFactory::TEXT_DISABLE_OPTIONAL_LIGATURES);
+              gfxTextRunFactory::TEXT_DISABLE_OPTIONAL_LIGATURES |
+              gfxTextRunFactory::TEXT_USE_MATH_SCRIPT);
     if (sizeof(T) == sizeof(uint8_t)) {
         flags |= gfxTextRunFactory::TEXT_IS_8BIT;
     }
 
     const T *text = aString + aRunStart;
     uint32_t wordStart = 0;
     uint32_t hash = 0;
     bool wordIs8Bit = true;
--- a/gfx/thebes/gfxFont.h
+++ b/gfx/thebes/gfxFont.h
@@ -1146,17 +1146,20 @@ public:
         TEXT_TRAILING_ARABICCHAR = 0x20000000,
         /**
          * When set, the previous character for this textrun was an Arabic
          * character.  This is used for the context detection necessary for
          * bidi.numeral implementation.
          */
         TEXT_INCOMING_ARABICCHAR = 0x40000000,
 
-        TEXT_UNUSED_FLAGS = 0x90000000
+        // Set if the textrun should use the OpenType 'math' script.
+        TEXT_USE_MATH_SCRIPT = 0x80000000,
+
+        TEXT_UNUSED_FLAGS = 0x10000000
     };
 
     /**
      * This record contains all the parameters needed to initialize a textrun.
      */
     struct Parameters {
         // A reference context suggesting where the textrun will be rendered
         gfxContext   *mContext;
--- a/gfx/thebes/gfxHarfBuzzShaper.cpp
+++ b/gfx/thebes/gfxHarfBuzzShaper.cpp
@@ -791,16 +791,18 @@ AddOpenTypeFeature(const uint32_t& aTag,
 }
 
 /*
  * gfxFontShaper override to initialize the text run using HarfBuzz
  */
 
 static hb_font_funcs_t * sHBFontFuncs = nullptr;
 static hb_unicode_funcs_t * sHBUnicodeFuncs = nullptr;
+static const hb_script_t sMathScript =
+    hb_ot_tag_to_script(HB_TAG('m','a','t','h'));
 
 bool
 gfxHarfBuzzShaper::ShapeText(gfxContext      *aContext,
                              const char16_t *aText,
                              uint32_t         aOffset,
                              uint32_t         aLength,
                              int32_t          aScript,
                              gfxShapedText   *aShapedText)
@@ -935,22 +937,27 @@ gfxHarfBuzzShaper::ShapeText(gfxContext 
         mergedFeatures.Enumerate(AddOpenTypeFeature, &features);
     }
 
     bool isRightToLeft = aShapedText->IsRightToLeft();
     hb_buffer_t *buffer = hb_buffer_create();
     hb_buffer_set_unicode_funcs(buffer, sHBUnicodeFuncs);
     hb_buffer_set_direction(buffer, isRightToLeft ? HB_DIRECTION_RTL :
                                                     HB_DIRECTION_LTR);
-    // For unresolved "common" or "inherited" runs, default to Latin for now.
-    // (Should we somehow use the language or locale to try and infer
-    // a better default?)
-    hb_script_t scriptTag = (aScript <= MOZ_SCRIPT_INHERITED) ?
-        HB_SCRIPT_LATIN :
-        hb_script_t(GetScriptTagForCode(aScript));
+    hb_script_t scriptTag;
+    if (aShapedText->Flags() & gfxTextRunFactory::TEXT_USE_MATH_SCRIPT) {
+        scriptTag = sMathScript;
+    } else if (aScript <= MOZ_SCRIPT_INHERITED) {
+        // For unresolved "common" or "inherited" runs, default to Latin for
+        // now.  (Should we somehow use the language or locale to try and infer
+        // a better default?)
+        scriptTag = HB_SCRIPT_LATIN;
+    } else {
+        scriptTag = hb_script_t(GetScriptTagForCode(aScript));
+    }
     hb_buffer_set_script(buffer, scriptTag);
 
     hb_language_t language;
     if (style->languageOverride) {
         language = hb_ot_tag_to_language(style->languageOverride);
     } else if (entry->mLanguageOverride) {
         language = hb_ot_tag_to_language(entry->mLanguageOverride);
     } else {
--- a/layout/media/symbols.def.in
+++ b/layout/media/symbols.def.in
@@ -590,16 +590,17 @@ hb_ot_layout_has_substitution
 hb_ot_layout_language_get_feature_indexes
 hb_ot_layout_language_get_feature_tags
 hb_ot_layout_language_get_required_feature_index
 hb_ot_layout_lookup_collect_glyphs
 hb_ot_layout_script_get_language_tags
 hb_ot_layout_table_choose_script
 hb_ot_layout_table_get_script_tags
 hb_ot_tag_to_language
+hb_ot_tag_to_script
 hb_ot_tags_from_script
 hb_set_add
 hb_set_clear
 hb_set_create
 hb_set_destroy
 hb_set_has
 hb_set_is_empty
 hb_set_next