Bug 1402049 - Remove support for using legacy Gecko normalization in gfxHarfBuzzShaper, as ICU is always available. r=jrmuizel
authorJonathan Kew <jkew@mozilla.com>
Fri, 22 Sep 2017 10:37:16 +0100
changeset 669131 762cf727dc750b6f26650313c693dfa282969f24
parent 669130 be26c0a0a56f7cfe70d12a7c40dab13229622839
child 669132 e64e1579a464ea35cb45c23cdc9163554aa32625
push id81223
push usergpascutto@mozilla.com
push dateFri, 22 Sep 2017 15:21:17 +0000
reviewersjrmuizel
bugs1402049
milestone58.0a1
Bug 1402049 - Remove support for using legacy Gecko normalization in gfxHarfBuzzShaper, as ICU is always available. r=jrmuizel
gfx/thebes/gfxHarfBuzzShaper.cpp
gfx/thebes/moz.build
--- a/gfx/thebes/gfxHarfBuzzShaper.cpp
+++ b/gfx/thebes/gfxHarfBuzzShaper.cpp
@@ -7,30 +7,24 @@
 #include "gfxContext.h"
 #include "gfxFontConstants.h"
 #include "gfxHarfBuzzShaper.h"
 #include "gfxFontUtils.h"
 #include "gfxTextRun.h"
 #include "mozilla/Sprintf.h"
 #include "nsUnicodeProperties.h"
 #include "nsUnicodeScriptCodes.h"
-#include "nsUnicodeNormalizer.h"
 
 #include "harfbuzz/hb.h"
 #include "harfbuzz/hb-ot.h"
 
-#if ENABLE_INTL_API // ICU is available: we'll use it for Unicode composition
-                    // and decomposition in preference to nsUnicodeNormalizer.
 #include "unicode/unorm.h"
 #include "unicode/utext.h"
-#define MOZ_HB_SHAPER_USE_ICU_NORMALIZATION 1
-static const UNormalizer2 * sNormalizer = nullptr;
-#else
-#undef MOZ_HB_SHAPER_USE_ICU_NORMALIZATION
-#endif
+
+static const UNormalizer2* sNormalizer = nullptr;
 
 #include <algorithm>
 
 #define FloatToFixed(f) (65536 * (f))
 #define FixedToFloat(f) ((f) * (1.0 / 65536.0))
 // Right shifts of negative (signed) integers are undefined, as are overflows
 // when converting unsigned to negative signed integers.
 // (If speed were an issue we could make some 2's complement assumptions.)
@@ -1101,34 +1095,24 @@ static const char16_t sDageshForms[0x05E
 
 static hb_bool_t
 HBUnicodeCompose(hb_unicode_funcs_t *ufuncs,
                  hb_codepoint_t      a,
                  hb_codepoint_t      b,
                  hb_codepoint_t     *ab,
                  void               *user_data)
 {
-#if MOZ_HB_SHAPER_USE_ICU_NORMALIZATION
-
     if (sNormalizer) {
         UChar32 ch = unorm2_composePair(sNormalizer, a, b);
         if (ch >= 0) {
             *ab = ch;
             return true;
         }
     }
 
-#else // no ICU available, use the old nsUnicodeNormalizer
-
-    if (nsUnicodeNormalizer::Compose(a, b, ab)) {
-        return true;
-    }
-
-#endif
-
     return false;
 }
 
 static hb_bool_t
 HBUnicodeDecompose(hb_unicode_funcs_t *ufuncs,
                    hb_codepoint_t      ab,
                    hb_codepoint_t     *a,
                    hb_codepoint_t     *b,
@@ -1139,18 +1123,16 @@ HBUnicodeDecompose(hb_unicode_funcs_t *u
     // support U+0972 by decomposing it.
     if (ab == 0x0972) {
         *a = 0x0905;
         *b = 0x0945;
         return true;
     }
 #endif
 
-#if MOZ_HB_SHAPER_USE_ICU_NORMALIZATION
-
     if (!sNormalizer) {
         return false;
     }
 
     // Canonical decompositions are never more than two characters,
     // or a maximum of 4 utf-16 code units.
     const unsigned MAX_DECOMP_LENGTH = 4;
 
@@ -1172,22 +1154,16 @@ HBUnicodeDecompose(hb_unicode_funcs_t *u
     }
     ch = UTEXT_NEXT32(&text);
     if (ch != U_SENTINEL) {
         *b = ch;
     }
     utext_close(&text);
 
     return *b != 0 || *a != ab;
-
-#else // no ICU available, use the old nsUnicodeNormalizer
-
-    return nsUnicodeNormalizer::DecomposeNonRecursively(ab, a, b);
-
-#endif
 }
 
 static void
 AddOpenTypeFeature(const uint32_t& aTag, uint32_t& aValue, void *aUserArg)
 {
     nsTArray<hb_feature_t>* features = static_cast<nsTArray<hb_feature_t>*> (aUserArg);
 
     hb_feature_t feat = { 0, 0, 0, UINT_MAX };
@@ -1260,21 +1236,19 @@ gfxHarfBuzzShaper::Initialize()
                                                   nullptr, nullptr);
         hb_unicode_funcs_set_compose_func(sHBUnicodeFuncs,
                                           HBUnicodeCompose,
                                           nullptr, nullptr);
         hb_unicode_funcs_set_decompose_func(sHBUnicodeFuncs,
                                             HBUnicodeDecompose,
                                             nullptr, nullptr);
 
-#if MOZ_HB_SHAPER_USE_ICU_NORMALIZATION
         UErrorCode error = U_ZERO_ERROR;
         sNormalizer = unorm2_getNFCInstance(&error);
-        NS_ASSERTION(U_SUCCESS(error), "failed to get ICU normalizer");
-#endif
+        MOZ_ASSERT(U_SUCCESS(error), "failed to get ICU normalizer");
     }
 
     gfxFontEntry *entry = mFont->GetFontEntry();
     if (!mUseFontGetGlyph) {
         // get the cmap table and find offset to our subtable
         mCmapTable = entry->GetFontTable(TRUETYPE_TAG('c','m','a','p'));
         if (!mCmapTable) {
             NS_WARNING("failed to load cmap, glyphs will be missing");
--- a/gfx/thebes/moz.build
+++ b/gfx/thebes/moz.build
@@ -228,22 +228,20 @@ elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'wi
 if CONFIG['MOZ_ENABLE_SKIA_PDF']:
     EXPORTS.mozilla.gfx += [
         'PrintTargetSkPDF.h',
     ]
     SOURCES += [
         'PrintTargetSkPDF.cpp',
     ]
 
-# We prefer to use ICU for normalization functions, but currently it is only
-# available if we're building with the Intl API enabled:
-if CONFIG['ENABLE_INTL_API']:
-    USE_LIBS += [
-        'icu',
-    ]
+# We use ICU for normalization functions:
+USE_LIBS += [
+    'icu',
+]
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
     '/dom/base',
     '/dom/workers',