From 522eefbe316bff0fd3c04a26963522b80ae1ba49 Mon Sep 17 00:00:00 2001 From: Dan Minor <dminor@mozilla.com> Date: Mon, 6 Dec 2021 18:15:50 +0000 Subject: [PATCH] Bug 1719554 - Unify unicode::Script as intl::Script; r=platform-i18n-reviewers,gregtatum Differential Revision: https://phabricator.services.mozilla.com/D132278 --- .clang-format-ignore | 2 +- gfx/thebes/gfxCoreTextShaper.cpp | 7 +- gfx/thebes/gfxFont.cpp | 10 +-- gfx/thebes/gfxFont.h | 10 +-- gfx/thebes/gfxFontEntry.cpp | 5 +- gfx/thebes/gfxFontEntry.h | 4 +- gfx/thebes/gfxHarfBuzzShaper.cpp | 5 +- gfx/thebes/gfxPlatform.h | 4 +- gfx/thebes/gfxPlatformFontList.cpp | 2 +- gfx/thebes/gfxPlatformFontList.h | 2 +- gfx/thebes/gfxScriptItemizer.cpp | 19 ++--- gfx/thebes/gfxScriptItemizer.h | 4 +- gfx/thebes/gfxTextRun.cpp | 2 + gfx/thebes/gfxTextRun.h | 9 +-- intl/components/gtest/TestScript.cpp | 40 +++++----- intl/components/moz.build | 3 +- intl/components/src/Script.cpp | 40 ---------- intl/components/src/Script.h | 55 ------------- intl/components/src/UnicodeProperties.h | 78 +++++++++++++++++++ .../src/UnicodeScriptCodes.h} | 28 ++----- intl/lwbrk/WordBreaker.cpp | 8 +- .../tools/genUnicodePropertyData.pl | 40 +++------- intl/unicharutil/util/moz.build | 1 - intl/unicharutil/util/nsUnicharUtils.cpp | 3 +- intl/unicharutil/util/nsUnicodeProperties.h | 22 +++--- .../util/nsUnicodePropertyData.cpp | 4 +- layout/generic/MathMLTextRunFactory.cpp | 6 +- layout/generic/nsTextFrame.cpp | 4 +- layout/mathml/nsMathMLChar.cpp | 4 +- netwerk/dns/nsIDNService.cpp | 10 +-- netwerk/dns/nsIDNService.h | 5 +- tools/rewriting/Generated.txt | 2 +- 32 files changed, 189 insertions(+), 249 deletions(-) delete mode 100644 intl/components/src/Script.cpp delete mode 100644 intl/components/src/Script.h rename intl/{unicharutil/util/nsUnicodeScriptCodes.h => components/src/UnicodeScriptCodes.h} (85%) diff --git a/.clang-format-ignore b/.clang-format-ignore index 89f4a0d658337..65b9e29203154 100644 --- a/.clang-format-ignore +++ b/.clang-format-ignore @@ -35,9 +35,9 @@ layout/style/nsStyleStructList.h gfx/gl/GLConsts.h gfx/webrender_bindings/webrender_ffi_generated.h dom/webgpu/ffi/wgpu_ffi_generated.h +intl/components/src/UnicodeScriptCodes.h intl/unicharutil/util/nsSpecialCasingData.cpp intl/unicharutil/util/nsUnicodePropertyData.cpp -intl/unicharutil/util/nsUnicodeScriptCodes.h media/mp4parse-rust/mp4parse.h security/manager/ssl/StaticHPKPins.h widget/gtk/wayland/gtk-primary-selection-client-protocol.h diff --git a/gfx/thebes/gfxCoreTextShaper.cpp b/gfx/thebes/gfxCoreTextShaper.cpp index 0e24337bf47ed..2d9ac9fca00fa 100644 --- a/gfx/thebes/gfxCoreTextShaper.cpp +++ b/gfx/thebes/gfxCoreTextShaper.cpp @@ -69,10 +69,9 @@ gfxCoreTextShaper::~gfxCoreTextShaper() { } } -static bool IsBuggyIndicScript(unicode::Script aScript) { - return aScript == unicode::Script::BENGALI || - aScript == unicode::Script::KANNADA || - aScript == unicode::Script::ORIYA || aScript == unicode::Script::KHMER; +static bool IsBuggyIndicScript(intl::Script aScript) { + return aScript == intl::Script::BENGALI || aScript == intl::Script::KANNADA || + aScript == intl::Script::ORIYA || aScript == intl::Script::KHMER; } bool gfxCoreTextShaper::ShapeText(DrawTarget* aDrawTarget, diff --git a/gfx/thebes/gfxFont.cpp b/gfx/thebes/gfxFont.cpp index c11c8a4d28c34..2539544eb3254 100644 --- a/gfx/thebes/gfxFont.cpp +++ b/gfx/thebes/gfxFont.cpp @@ -1105,10 +1105,10 @@ static void HasLookupRuleWithGlyph(hb_face_t* aFace, hb_tag_t aTableTag, hb_set_destroy(otherLookups); } -nsTHashMap<nsUint32HashKey, Script>* gfxFont::sScriptTagToCode = nullptr; +nsTHashMap<nsUint32HashKey, intl::Script>* gfxFont::sScriptTagToCode = nullptr; nsTHashSet<uint32_t>* gfxFont::sDefaultFeatures = nullptr; -static inline bool HasSubstitution(uint32_t* aBitVector, Script aScript) { +static inline bool HasSubstitution(uint32_t* aBitVector, intl::Script aScript) { return (aBitVector[static_cast<uint32_t>(aScript) >> 5] & (1 << (static_cast<uint32_t>(aScript) & 0x1f))) != 0; } @@ -1165,9 +1165,9 @@ void gfxFont::CheckForFeaturesInvolvingSpace() { // Ensure that we don't try to look at script codes beyond what the // current version of ICU (at runtime -- in case of system ICU) // knows about. - Script scriptCount = - Script(std::min<int>(u_getIntPropertyMaxValue(UCHAR_SCRIPT) + 1, - int(Script::NUM_SCRIPT_CODES))); + Script scriptCount = Script( + std::min<int>(intl::UnicodeProperties::GetMaxNumberOfScripts() + 1, + int(Script::NUM_SCRIPT_CODES))); for (Script s = Script::ARABIC; s < scriptCount; s = Script(static_cast<int>(s) + 1)) { hb_script_t script = hb_script_t(GetScriptTagForCode(s)); diff --git a/gfx/thebes/gfxFont.h b/gfx/thebes/gfxFont.h index 7f118f457da27..64d2b4d1cc7ee 100644 --- a/gfx/thebes/gfxFont.h +++ b/gfx/thebes/gfxFont.h @@ -24,6 +24,7 @@ #include "mozilla/UniquePtr.h" #include "mozilla/gfx/MatrixFwd.h" #include "mozilla/gfx/Point.h" +#include "mozilla/intl/UnicodeScriptCodes.h" #include "nsCOMPtr.h" #include "nsColor.h" #include "nsTHashMap.h" @@ -37,7 +38,6 @@ #include "nsString.h" #include "nsTArray.h" #include "nsTHashtable.h" -#include "nsUnicodeScriptCodes.h" #include "nscore.h" // Only required for function bodys @@ -672,7 +672,7 @@ class gfxTextRunFactory { class gfxFontShaper { public: typedef mozilla::gfx::DrawTarget DrawTarget; - typedef mozilla::unicode::Script Script; + typedef mozilla::intl::Script Script; enum class RoundingFlags : uint8_t { kRoundX = 0x01, kRoundY = 0x02 }; @@ -731,7 +731,7 @@ MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(gfxFontShaper::RoundingFlags) */ class gfxShapedText { public: - typedef mozilla::unicode::Script Script; + typedef mozilla::intl::Script Script; gfxShapedText(uint32_t aLength, mozilla::gfx::ShapedTextFlags aFlags, uint16_t aAppUnitsPerDevUnit) @@ -1261,7 +1261,7 @@ class gfxShapedText { */ class gfxShapedWord final : public gfxShapedText { public: - typedef mozilla::unicode::Script Script; + typedef mozilla::intl::Script Script; // Create a ShapedWord that can hold glyphs for aLength characters, // with mCharacterGlyphs sized appropriately. @@ -1426,7 +1426,7 @@ class gfxFont { protected: using DrawTarget = mozilla::gfx::DrawTarget; - using Script = mozilla::unicode::Script; + using Script = mozilla::intl::Script; using SVGContextPaint = mozilla::SVGContextPaint; using RoundingFlags = gfxFontShaper::RoundingFlags; diff --git a/gfx/thebes/gfxFontEntry.cpp b/gfx/thebes/gfxFontEntry.cpp index c65c99dbf2dd9..b2abace1e568d 100644 --- a/gfx/thebes/gfxFontEntry.cpp +++ b/gfx/thebes/gfxFontEntry.cpp @@ -814,7 +814,7 @@ tainted_boolean_hint gfxFontEntry::HasGraphiteSpaceContextuals() { #define FEATURE_SCRIPT_MASK 0x000000ff // script index replaces low byte of tag -static_assert(int(Script::NUM_SCRIPT_CODES) <= FEATURE_SCRIPT_MASK, +static_assert(int(intl::Script::NUM_SCRIPT_CODES) <= FEATURE_SCRIPT_MASK, "Too many script codes"); // high-order three bytes of tag with script in low-order byte @@ -1780,7 +1780,8 @@ void gfxFontFamily::FindFontForChar(GlobalFontMatch* aMatchData) { LogModule* log = gfxPlatform::GetLog(eGfxLog_textrun); if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Debug))) { - Script script = GetScriptCode(aMatchData->mCh); + intl::Script script = + intl::UnicodeProperties::GetScriptCode(aMatchData->mCh); MOZ_LOG(log, LogLevel::Debug, ("(textrun-systemfallback-fonts) char: u+%6.6x " "script: %d match: [%s]\n", diff --git a/gfx/thebes/gfxFontEntry.h b/gfx/thebes/gfxFontEntry.h index 33eb8d83ce44b..8d29fc38cfc38 100644 --- a/gfx/thebes/gfxFontEntry.h +++ b/gfx/thebes/gfxFontEntry.h @@ -23,13 +23,13 @@ #include "mozilla/RefPtr.h" #include "mozilla/TypedEnumBits.h" #include "mozilla/UniquePtr.h" +#include "mozilla/intl/UnicodeScriptCodes.h" #include "nsTHashMap.h" #include "nsDebug.h" #include "nsHashKeys.h" #include "nsISupports.h" #include "nsStringFwd.h" #include "nsTArray.h" -#include "nsUnicodeScriptCodes.h" #include "nscore.h" class FontInfoData; @@ -131,7 +131,7 @@ struct gfxFontFeatureInfo { class gfxFontEntry { public: typedef mozilla::gfx::DrawTarget DrawTarget; - typedef mozilla::unicode::Script Script; + typedef mozilla::intl::Script Script; typedef mozilla::FontWeight FontWeight; typedef mozilla::FontSlantStyle FontSlantStyle; typedef mozilla::FontStretch FontStretch; diff --git a/gfx/thebes/gfxHarfBuzzShaper.cpp b/gfx/thebes/gfxHarfBuzzShaper.cpp index 7aabd9fb88656..e0e2c7b257c4a 100644 --- a/gfx/thebes/gfxHarfBuzzShaper.cpp +++ b/gfx/thebes/gfxHarfBuzzShaper.cpp @@ -12,8 +12,8 @@ #include "mozilla/Sprintf.h" #include "mozilla/intl/String.h" #include "mozilla/intl/UnicodeProperties.h" +#include "mozilla/intl/UnicodeScriptCodes.h" #include "nsUnicodeProperties.h" -#include "nsUnicodeScriptCodes.h" #include "harfbuzz/hb.h" #include "harfbuzz/hb-ot.h" @@ -992,7 +992,8 @@ static hb_unicode_general_category_t HBGetGeneralCategory( static hb_script_t HBGetScript(hb_unicode_funcs_t* ufuncs, hb_codepoint_t aCh, void* user_data) { - return hb_script_t(GetScriptTagForCode(GetScriptCode(aCh))); + return hb_script_t( + GetScriptTagForCode(intl::UnicodeProperties::GetScriptCode(aCh))); } static hb_unicode_combining_class_t HBGetCombiningClass( diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h index c81e3693946df..5ed5239cb884f 100644 --- a/gfx/thebes/gfxPlatform.h +++ b/gfx/thebes/gfxPlatform.h @@ -8,10 +8,10 @@ #include "mozilla/FontPropertyTypes.h" #include "mozilla/gfx/Types.h" +#include "mozilla/intl/UnicodeScriptCodes.h" #include "nsTArray.h" #include "nsString.h" #include "nsCOMPtr.h" -#include "nsUnicodeScriptCodes.h" #include "gfxTelemetry.h" #include "gfxTypes.h" @@ -186,7 +186,7 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener { typedef mozilla::gfx::DrawTarget DrawTarget; typedef mozilla::gfx::IntSize IntSize; typedef mozilla::gfx::SourceSurface SourceSurface; - typedef mozilla::unicode::Script Script; + typedef mozilla::intl::Script Script; /** * Return a pointer to the current active platform. diff --git a/gfx/thebes/gfxPlatformFontList.cpp b/gfx/thebes/gfxPlatformFontList.cpp index 462caa9508e30..1dbb05a6b438a 100644 --- a/gfx/thebes/gfxPlatformFontList.cpp +++ b/gfx/thebes/gfxPlatformFontList.cpp @@ -975,7 +975,7 @@ gfxFont* gfxPlatformFontList::SystemFindFontForChar( LogModule* log = gfxPlatform::GetLog(eGfxLog_textrun); if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Warning))) { - Script script = mozilla::unicode::GetScriptCode(aCh); + Script script = intl::UnicodeProperties::GetScriptCode(aCh); MOZ_LOG(log, LogLevel::Warning, ("(textrun-systemfallback-%s) char: u+%6.6x " "script: %d match: [%s]" diff --git a/gfx/thebes/gfxPlatformFontList.h b/gfx/thebes/gfxPlatformFontList.h index c5ba279e741ae..6494831605119 100644 --- a/gfx/thebes/gfxPlatformFontList.h +++ b/gfx/thebes/gfxPlatformFontList.h @@ -162,7 +162,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader { typedef mozilla::StretchRange StretchRange; typedef mozilla::SlantStyleRange SlantStyleRange; typedef mozilla::WeightRange WeightRange; - typedef mozilla::unicode::Script Script; + typedef mozilla::intl::Script Script; // For font family lists loaded from user preferences (prefs such as // font.name-list.<generic>.<langGroup>) that map CSS generics to diff --git a/gfx/thebes/gfxScriptItemizer.cpp b/gfx/thebes/gfxScriptItemizer.cpp index f2456b7b7df9c..8f78bd7421ebc 100644 --- a/gfx/thebes/gfxScriptItemizer.cpp +++ b/gfx/thebes/gfxScriptItemizer.cpp @@ -48,12 +48,12 @@ */ #include "gfxScriptItemizer.h" -#include "mozilla/intl/Script.h" #include "mozilla/intl/UnicodeProperties.h" -#include "nsUnicodeProperties.h" #include "nsCharTraits.h" +#include "nsUnicodeProperties.h" #include "harfbuzz/hb.h" +using namespace mozilla::intl; using namespace mozilla::unicode; #define MOD(sp) ((sp) % PAREN_STACK_DEPTH) @@ -117,7 +117,8 @@ static inline bool SameScript(Script runScript, Script currCharScript, uint32_t aCurrCh) { return CanMergeWithContext(runScript) || CanMergeWithContext(currCharScript) || currCharScript == runScript || - IsClusterExtender(aCurrCh) || HasScript(aCurrCh, runScript); + IsClusterExtender(aCurrCh) || + UnicodeProperties::HasScript(aCurrCh, runScript); } gfxScriptItemizer::gfxScriptItemizer(const char16_t* src, uint32_t length) @@ -163,7 +164,7 @@ bool gfxScriptItemizer::Next(uint32_t& aRunStart, uint32_t& aRunLimit, // if the character has script=COMMON, otherwise we don't care. uint8_t gc = HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED; - sc = GetScriptCode(ch); + sc = UnicodeProperties::GetScriptCode(ch); if (sc == Script::COMMON) { /* * Paired character handling: @@ -178,12 +179,12 @@ bool gfxScriptItemizer::Next(uint32_t& aRunStart, uint32_t& aRunLimit, */ gc = GetGeneralCategory(ch); if (gc == HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION) { - uint32_t endPairChar = mozilla::intl::UnicodeProperties::CharMirror(ch); + uint32_t endPairChar = UnicodeProperties::CharMirror(ch); if (endPairChar != ch) { push(endPairChar, scriptCode); } } else if (gc == HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION && - mozilla::intl::UnicodeProperties::IsMirrored(ch)) { + UnicodeProperties::IsMirrored(ch)) { while (STACK_IS_NOT_EMPTY() && TOP().endPairChar != ch) { pop(); } @@ -205,8 +206,8 @@ bool gfxScriptItemizer::Next(uint32_t& aRunStart, uint32_t& aRunLimit, } else if (fallbackScript == Script::UNKNOWN) { // See if the character has a ScriptExtensions property we can // store for use in the event the run remains unresolved. - mozilla::intl::ScriptExtensionVector extensions; - auto extResult = mozilla::intl::Script::GetExtensions(ch, extensions); + UnicodeProperties::ScriptExtensionVector extensions; + auto extResult = UnicodeProperties::GetExtensions(ch, extensions); if (extResult.isOk()) { Script ext = Script(extensions[0]); if (!CanMergeWithContext(ext)) { @@ -221,7 +222,7 @@ bool gfxScriptItemizer::Next(uint32_t& aRunStart, uint32_t& aRunLimit, * pop the matching open character from the stack */ if (gc == HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION && - mozilla::intl::UnicodeProperties::IsMirrored(ch)) { + UnicodeProperties::IsMirrored(ch)) { pop(); } } else { diff --git a/gfx/thebes/gfxScriptItemizer.h b/gfx/thebes/gfxScriptItemizer.h index b218f5c8d2cf4..6deb37e19cbaf 100644 --- a/gfx/thebes/gfxScriptItemizer.h +++ b/gfx/thebes/gfxScriptItemizer.h @@ -51,13 +51,13 @@ #define GFX_SCRIPTITEMIZER_H #include <stdint.h> -#include "nsUnicodeScriptCodes.h" +#include "mozilla/intl/UnicodeScriptCodes.h" #define PAREN_STACK_DEPTH 32 class gfxScriptItemizer { public: - typedef mozilla::unicode::Script Script; + typedef mozilla::intl::Script Script; gfxScriptItemizer(const char16_t* src, uint32_t length); diff --git a/gfx/thebes/gfxTextRun.cpp b/gfx/thebes/gfxTextRun.cpp index a5abcbf83519d..9a028910b49f8 100644 --- a/gfx/thebes/gfxTextRun.cpp +++ b/gfx/thebes/gfxTextRun.cpp @@ -24,6 +24,7 @@ #include "mozilla/Likely.h" #include "gfx2DGlue.h" #include "mozilla/gfx/Logging.h" // for gfxCriticalError +#include "mozilla/intl/UnicodeProperties.h" #include "mozilla/UniquePtr.h" #include "mozilla/Unused.h" #include "SharedFontList-impl.h" @@ -37,6 +38,7 @@ using namespace mozilla; using namespace mozilla::gfx; +using namespace mozilla::intl; using namespace mozilla::unicode; using mozilla::services::GetObserverService; diff --git a/gfx/thebes/gfxTextRun.h b/gfx/thebes/gfxTextRun.h index 95ab7d9c084c1..e59b85ca6c0f7 100644 --- a/gfx/thebes/gfxTextRun.h +++ b/gfx/thebes/gfxTextRun.h @@ -19,6 +19,7 @@ #include "gfxUserFontSet.h" #include "mozilla/MemoryReporting.h" #include "mozilla/RefPtr.h" +#include "mozilla/intl/UnicodeScriptCodes.h" #include "nsPoint.h" #include "nsString.h" #include "nsTArray.h" @@ -26,7 +27,6 @@ #include "nsTextFrameUtils.h" #include "DrawMode.h" #include "harfbuzz/hb.h" -#include "nsUnicodeScriptCodes.h" #include "nsColor.h" #include "nsFrameList.h" #include "X11UndefineNone.h" @@ -901,7 +901,7 @@ class gfxTextRun : public gfxShapedText { class gfxFontGroup final : public gfxTextRunFactory { public: - typedef mozilla::unicode::Script Script; + typedef mozilla::intl::Script Script; typedef gfxShapedText::CompressedGlyph CompressedGlyph; static void @@ -1508,7 +1508,7 @@ class gfxMissingFontRecorder { } // record this script code in our mMissingFonts bitset - void RecordScript(mozilla::unicode::Script aScriptCode) { + void RecordScript(mozilla::intl::Script aScriptCode) { mMissingFonts[static_cast<uint32_t>(aScriptCode) >> 5] |= (1 << (static_cast<uint32_t>(aScriptCode) & 0x1f)); } @@ -1524,8 +1524,7 @@ class gfxMissingFontRecorder { private: // Number of 32-bit words needed for the missing-script flags static const uint32_t kNumScriptBitsWords = - ((static_cast<int>(mozilla::unicode::Script::NUM_SCRIPT_CODES) + 31) / - 32); + ((static_cast<int>(mozilla::intl::Script::NUM_SCRIPT_CODES) + 31) / 32); uint32_t mMissingFonts[kNumScriptBitsWords]; }; diff --git a/intl/components/gtest/TestScript.cpp b/intl/components/gtest/TestScript.cpp index 280028a48d970..72d8cd108722a 100644 --- a/intl/components/gtest/TestScript.cpp +++ b/intl/components/gtest/TestScript.cpp @@ -3,60 +3,60 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "gtest/gtest.h" -#include "mozilla/intl/Script.h" -#include "nsUnicodeScriptCodes.h" +#include "mozilla/intl/UnicodeProperties.h" +#include "mozilla/intl/UnicodeScriptCodes.h" namespace mozilla::intl { TEST(IntlScript, GetExtensions) { - ScriptExtensionVector extensions; + UnicodeProperties::ScriptExtensionVector extensions; // 0x0000..0x0040 are Common. for (char32_t ch = 0; ch < 0x0041; ch++) { - ASSERT_TRUE(Script::GetExtensions(ch, extensions).isOk()); + ASSERT_TRUE(UnicodeProperties::GetExtensions(ch, extensions).isOk()); ASSERT_EQ(extensions.length(), 1u); - ASSERT_EQ(unicode::Script(extensions[0]), unicode::Script::COMMON); + ASSERT_EQ(Script(extensions[0]), Script::COMMON); } // 0x0300..0x0341 are Inherited. for (char32_t ch = 0x300; ch < 0x0341; ch++) { - ASSERT_TRUE(Script::GetExtensions(ch, extensions).isOk()); + ASSERT_TRUE(UnicodeProperties::GetExtensions(ch, extensions).isOk()); ASSERT_EQ(extensions.length(), 1u); - ASSERT_EQ(unicode::Script(extensions[0]), unicode::Script::INHERITED); + ASSERT_EQ(Script(extensions[0]), Script::INHERITED); } // 0x1cf7's script code is Common, but its script extension is Beng. - ASSERT_TRUE(Script::GetExtensions(0x1cf7, extensions).isOk()); + ASSERT_TRUE(UnicodeProperties::GetExtensions(0x1cf7, extensions).isOk()); ASSERT_EQ(extensions.length(), 1u); - ASSERT_EQ(unicode::Script(extensions[0]), unicode::Script::BENGALI); + ASSERT_EQ(Script(extensions[0]), Script::BENGALI); // Ø¿ // https://unicode-table.com/en/063F/ // This character doesn't have any script extension, so the script code is // returned. - ASSERT_TRUE(Script::GetExtensions(0x063f, extensions).isOk()); + ASSERT_TRUE(UnicodeProperties::GetExtensions(0x063f, extensions).isOk()); ASSERT_EQ(extensions.length(), 1u); - ASSERT_EQ(unicode::Script(extensions[0]), unicode::Script::ARABIC); + ASSERT_EQ(Script(extensions[0]), Script::ARABIC); // 0xff65 is the unicode character 'ï½¥', see https://unicode-table.com/en/FF65/ // Halfwidth Katakana Middle Dot. - ASSERT_TRUE(Script::GetExtensions(0xff65, extensions).isOk()); + ASSERT_TRUE(UnicodeProperties::GetExtensions(0xff65, extensions).isOk()); // 0xff65 should have the following script extensions: // Bopo Hang Hani Hira Kana Yiii. ASSERT_EQ(extensions.length(), 6u); - ASSERT_EQ(unicode::Script(extensions[0]), unicode::Script::BOPOMOFO); - ASSERT_EQ(unicode::Script(extensions[1]), unicode::Script::HAN); - ASSERT_EQ(unicode::Script(extensions[2]), unicode::Script::HANGUL); - ASSERT_EQ(unicode::Script(extensions[3]), unicode::Script::HIRAGANA); - ASSERT_EQ(unicode::Script(extensions[4]), unicode::Script::KATAKANA); - ASSERT_EQ(unicode::Script(extensions[5]), unicode::Script::YI); + ASSERT_EQ(Script(extensions[0]), Script::BOPOMOFO); + ASSERT_EQ(Script(extensions[1]), Script::HAN); + ASSERT_EQ(Script(extensions[2]), Script::HANGUL); + ASSERT_EQ(Script(extensions[3]), Script::HIRAGANA); + ASSERT_EQ(Script(extensions[4]), Script::KATAKANA); + ASSERT_EQ(Script(extensions[5]), Script::YI); // The max code point is 0x10ffff, so 0x110000 should be invalid. // Script::UNKNOWN should be returned for an invalid code point. - ASSERT_TRUE(Script::GetExtensions(0x110000, extensions).isOk()); + ASSERT_TRUE(UnicodeProperties::GetExtensions(0x110000, extensions).isOk()); ASSERT_EQ(extensions.length(), 1u); - ASSERT_EQ(unicode::Script(extensions[0]), unicode::Script::UNKNOWN); + ASSERT_EQ(Script(extensions[0]), Script::UNKNOWN); } } // namespace mozilla::intl diff --git a/intl/components/moz.build b/intl/components/moz.build index 3964038066b97..494cbc5ecd7f2 100644 --- a/intl/components/moz.build +++ b/intl/components/moz.build @@ -28,10 +28,10 @@ EXPORTS.mozilla.intl = [ "src/NumberRangeFormat.h", "src/PluralRules.h", "src/RelativeTimeFormat.h", - "src/Script.h", "src/String.h", "src/TimeZone.h", "src/UnicodeProperties.h", + "src/UnicodeScriptCodes.h", ] UNIFIED_SOURCES += [ @@ -58,7 +58,6 @@ UNIFIED_SOURCES += [ "src/NumberRangeFormat.cpp", "src/PluralRules.cpp", "src/RelativeTimeFormat.cpp", - "src/Script.cpp", "src/String.cpp", "src/TimeZone.cpp", ] diff --git a/intl/components/src/Script.cpp b/intl/components/src/Script.cpp deleted file mode 100644 index 31776f782a36a..0000000000000 --- a/intl/components/src/Script.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* 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/. */ - -#include "mozilla/intl/Script.h" - -#include "unicode/uscript.h" - -namespace mozilla::intl { - -// static -ICUResult Script::GetExtensions(char32_t aCodePoint, - ScriptExtensionVector& aExtensions) { - // Clear the vector first. - aExtensions.clear(); - - // We cannot pass aExtensions to uscript_getScriptExtension as USCriptCode - // takes 4 bytes, so create a local UScriptCode array to get the extensions. - UScriptCode ext[kMaxScripts]; - UErrorCode status = U_ZERO_ERROR; - int32_t len = uscript_getScriptExtensions(static_cast<UChar32>(aCodePoint), - ext, kMaxScripts, &status); - if (U_FAILURE(status)) { - // kMaxScripts should be large enough to hold the maximun number of script - // extensions. - MOZ_DIAGNOSTIC_ASSERT(status != U_BUFFER_OVERFLOW_ERROR); - return Err(ToICUError(status)); - } - - if (!aExtensions.reserve(len)) { - return Err(ICUError::OutOfMemory); - } - - for (int32_t i = 0; i < len; i++) { - aExtensions.infallibleAppend(ext[i]); - } - - return Ok(); -} -} // namespace mozilla::intl diff --git a/intl/components/src/Script.h b/intl/components/src/Script.h deleted file mode 100644 index fd56c47ae278b..0000000000000 --- a/intl/components/src/Script.h +++ /dev/null @@ -1,55 +0,0 @@ -/* 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/. */ -#ifndef intl_components_Script_h_ -#define intl_components_Script_h_ - -#include "mozilla/intl/ICU4CGlue.h" -#include "mozilla/Vector.h" - -namespace mozilla::intl { - -// The code point which has the most script extensions is 0x0965, which has 21 -// script extensions, so choose the vector size as 32 to prevent heap -// allocation. -constexpr size_t kMaxScripts = 32; - -// The list of script extensions, it consists of one or more script codes from -// ISO 15924, or mozilla::unicode::Script. -// -// Choose the element type as int16_t to have the same size of -// mozilla::unicode::Script. -// We didn't use mozilla::unicode::Script directly here because we cannot -// include the header in standalone JS shell build. -using ScriptExtensionVector = Vector<int16_t, kMaxScripts>; - -/** - * This component is a Mozilla-focused API for working with Unicode scripts. - */ -class Script final { - public: - /** - * Get the script extensions for the given code point, and write the script - * extensions to aExtensions vector. If the code point has script extensions, - * the script code (Script::COMMON or Script::INHERITED) will be excluded. - * - * If the code point doesn't have any script extension, then its script code - * will be written to aExtensions vector. - * - * If the code point is invalid, Script::UNKNOWN will be written to - * aExtensions vector. - * - * Note: aExtensions will be cleared after calling this method regardless of - * failure. - * - * See [1] for the script code of the code point, [2] for the script - * extensions. - * - * https://www.unicode.org/Public/UNIDATA/Scripts.txt - * https://www.unicode.org/Public/UNIDATA/ScriptExtensions.txt - */ - static ICUResult GetExtensions(char32_t aCodePoint, - ScriptExtensionVector& aExtensions); -}; -} // namespace mozilla::intl -#endif // intl_components_Script_h_ diff --git a/intl/components/src/UnicodeProperties.h b/intl/components/src/UnicodeProperties.h index 74a3173520d17..785bc356f8e61 100644 --- a/intl/components/src/UnicodeProperties.h +++ b/intl/components/src/UnicodeProperties.h @@ -5,6 +5,9 @@ #define intl_components_UnicodeProperties_h_ #include "mozilla/intl/BidiClass.h" +#include "mozilla/intl/ICU4CGlue.h" +#include "mozilla/intl/UnicodeScriptCodes.h" +#include "mozilla/Vector.h" #include "unicode/uchar.h" #include "unicode/uscript.h" @@ -221,6 +224,81 @@ class UnicodeProperties final { // Keep this function in sync with is_math_symbol in base_chars.py. return CharType(aCh) == U_MATH_SYMBOL || CharType(aCh) == U_OTHER_SYMBOL; } + + static inline Script GetScriptCode(uint32_t aCh) { + // We can safely ignore the error code here because uscript_getScript + // returns USCRIPT_INVALID_CODE in the event of an error. + UErrorCode err = U_ZERO_ERROR; + return Script(uscript_getScript(aCh, &err)); + } + + static inline bool HasScript(uint32_t aCh, Script aScript) { + return uscript_hasScript(aCh, UScriptCode(aScript)); + } + + static inline const char* GetScriptShortName(Script aScript) { + return uscript_getShortName(UScriptCode(aScript)); + } + + static inline int32_t GetMaxNumberOfScripts() { + return u_getIntPropertyMaxValue(UCHAR_SCRIPT); + } + + // The code point which has the most script extensions is 0x0965, which has 21 + // script extensions, so choose the vector size as 32 to prevent heap + // allocation. + static constexpr size_t kMaxScripts = 32; + + using ScriptExtensionVector = Vector<Script, kMaxScripts>; + + /** + * Get the script extensions for the given code point, and write the script + * extensions to aExtensions vector. If the code point has script extensions, + * the script code (Script::COMMON or Script::INHERITED) will be excluded. + * + * If the code point doesn't have any script extension, then its script code + * will be written to aExtensions vector. + * + * If the code point is invalid, Script::UNKNOWN will be written to + * aExtensions vector. + * + * Note: aExtensions will be cleared after calling this method regardless of + * failure. + * + * See [1] for the script code of the code point, [2] for the script + * extensions. + * + * https://www.unicode.org/Public/UNIDATA/Scripts.txt + * https://www.unicode.org/Public/UNIDATA/ScriptExtensions.txt + */ + static ICUResult GetExtensions(char32_t aCodePoint, + ScriptExtensionVector& aExtensions) { + // Clear the vector first. + aExtensions.clear(); + + // We cannot pass aExtensions to uscript_getScriptExtension as USCriptCode + // takes 4 bytes, so create a local UScriptCode array to get the extensions. + UScriptCode ext[kMaxScripts]; + UErrorCode status = U_ZERO_ERROR; + int32_t len = uscript_getScriptExtensions(static_cast<UChar32>(aCodePoint), + ext, kMaxScripts, &status); + if (U_FAILURE(status)) { + // kMaxScripts should be large enough to hold the maximun number of script + // extensions. + MOZ_DIAGNOSTIC_ASSERT(status != U_BUFFER_OVERFLOW_ERROR); + return Err(ToICUError(status)); + } + + if (!aExtensions.reserve(len)) { + return Err(ICUError::OutOfMemory); + } + + for (int32_t i = 0; i < len; i++) { + aExtensions.infallibleAppend(Script(ext[i])); + } + + return Ok(); + } }; } // namespace mozilla::intl diff --git a/intl/unicharutil/util/nsUnicodeScriptCodes.h b/intl/components/src/UnicodeScriptCodes.h similarity index 85% rename from intl/unicharutil/util/nsUnicodeScriptCodes.h rename to intl/components/src/UnicodeScriptCodes.h index 03756198f2d14..4bc45eeaa89d8 100644 --- a/intl/unicharutil/util/nsUnicodeScriptCodes.h +++ b/intl/components/src/UnicodeScriptCodes.h @@ -1,5 +1,3 @@ - -/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* 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/. */ @@ -11,7 +9,7 @@ */ /* - * Created on Thu Nov 18 12:50:48 2021 from UCD data files with version info: + * Created on Thu Dec 2 15:20:26 2021 from UCD data files with version info: * # Unicode Character Database @@ -45,20 +43,10 @@ for the Unicode Character Database, for Version 14.0.0 of the Unicode Standard. * * * * * This file contains MACHINE-GENERATED DATA, do not edit! * * * * * */ -#ifndef NS_UNICODE_SCRIPT_CODES -#define NS_UNICODE_SCRIPT_CODES - +#ifndef intl_components_UnicodeScriptCodes_h_ +#define intl_components_UnicodeScriptCodes_h_ -struct nsCharProps2 { - // Currently only 4 bits are defined here, so 4 more could be added without - // affecting the storage requirements for this struct. Or we could pack two - // records per byte, at the cost of a slightly more complex accessor. - unsigned char mVertOrient:2; - unsigned char mIdType:2; -}; - -namespace mozilla { -namespace unicode { +namespace mozilla::intl { enum class Script : int16_t { COMMON = 0, INHERITED = 1, @@ -263,13 +251,7 @@ enum class Script : int16_t { INVALID = -1 }; - -// mozilla::intl::ScriptExtensionVector assumes sizeof(Script) is equal to -// sizeof(int16_t), so if the data type of Script is changed then -// ScriptExtensionVector needs to be updated accordingly. -static_assert(sizeof(Script) == sizeof(int16_t)); -} // namespace unicode -} // namespace mozilla +} // namespace mozilla::intl #endif /* diff --git a/intl/lwbrk/WordBreaker.cpp b/intl/lwbrk/WordBreaker.cpp index b688947c5cb60..992cec331ef61 100644 --- a/intl/lwbrk/WordBreaker.cpp +++ b/intl/lwbrk/WordBreaker.cpp @@ -3,17 +3,17 @@ * 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/. */ +#include "mozilla/intl/UnicodeProperties.h" #include "mozilla/intl/WordBreaker.h" #include "mozilla/StaticPrefs_layout.h" #include "nsComplexBreaker.h" #include "nsTArray.h" -#include "nsUnicodeProperties.h" +using mozilla::intl::Script; +using mozilla::intl::UnicodeProperties; using mozilla::intl::WordBreaker; using mozilla::intl::WordRange; using mozilla::unicode::GetGenCategory; -using mozilla::unicode::GetScriptCode; -using mozilla::unicode::Script; #define IS_ASCII(c) (0 == (0xFF80 & (c))) #define ASCII_IS_ALPHA(c) \ @@ -40,7 +40,7 @@ using mozilla::unicode::Script; // the script is not supported by the platform, we just won't find any useful // boundaries.) static bool IsScriptioContinua(char16_t aChar) { - Script sc = GetScriptCode(aChar); + Script sc = UnicodeProperties::GetScriptCode(aChar); return sc == Script::THAI || sc == Script::MYANMAR || sc == Script::KHMER || sc == Script::JAVANESE || sc == Script::BALINESE || sc == Script::SUNDANESE || sc == Script::LAO; diff --git a/intl/unicharutil/tools/genUnicodePropertyData.pl b/intl/unicharutil/tools/genUnicodePropertyData.pl index c92bb5f57992d..f72f18f1ae0d5 100755 --- a/intl/unicharutil/tools/genUnicodePropertyData.pl +++ b/intl/unicharutil/tools/genUnicodePropertyData.pl @@ -47,7 +47,7 @@ # This will generate (or overwrite!) the files # # nsUnicodePropertyData.cpp -# nsUnicodeScriptCodes.h +# UnicodeScriptCodes.h # # in the current directory. @@ -71,7 +71,7 @@ if ($#ARGV != 1) { # This will generate (or overwrite!) the files # # nsUnicodePropertyData.cpp -# nsUnicodeScriptCodes.h +# UnicodeScriptCodes.h # # in the current directory. __EOT @@ -132,7 +132,7 @@ my %idType = ( "Deprecated" => 12 ); -# These match the IdentifierType enum in nsUnicodeProperties.h. +# These match the IdentifierType enum in UnicodeProperties.h. my %mappedIdType = ( "Restricted" => 0, "Allowed" => 1 @@ -292,9 +292,7 @@ my $timestamp = gmtime(); open DATA_TABLES, "> nsUnicodePropertyData.cpp" or die "unable to open nsUnicodePropertyData.cpp for output"; -my $licenseBlock = q[ -/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* This Source Code Form is subject to the terms of the Mozilla Public +my $licenseBlock = q[/* 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/. */ @@ -324,7 +322,7 @@ $versionInfo __END -open HEADER, "> nsUnicodeScriptCodes.h" or die "unable to open nsUnicodeScriptCodes.h for output"; +open HEADER, "> UnicodeScriptCodes.h" or die "unable to open UnicodeScriptCodes.h for output"; print HEADER <<__END; $licenseBlock @@ -338,8 +336,8 @@ $versionInfo * * * * * This file contains MACHINE-GENERATED DATA, do not edit! * * * * * */ -#ifndef NS_UNICODE_SCRIPT_CODES -#define NS_UNICODE_SCRIPT_CODES +#ifndef intl_components_UnicodeScriptCodes_h_ +#define intl_components_UnicodeScriptCodes_h_ __END @@ -351,16 +349,7 @@ sub sprintCharProps2_short return sprintf("{%d,%d},", $verticalOrientation[$usv], $idtype[$usv]); } -my $type = q| -struct nsCharProps2 { - // Currently only 4 bits are defined here, so 4 more could be added without - // affecting the storage requirements for this struct. Or we could pack two - // records per byte, at the cost of a slightly more complex accessor. - unsigned char mVertOrient:2; - unsigned char mIdType:2; -}; -|; -&genTables("CharProp2", $type, "nsCharProps2", 9, 7, \&sprintCharProps2_short, 16, 1, 1); +&genTables("CharProp2", "", "nsCharProps2", 9, 7, \&sprintCharProps2_short, 16, 1, 1); sub sprintHanVariants { @@ -485,8 +474,7 @@ __END close DATA_TABLES; -print HEADER "namespace mozilla {\n"; -print HEADER "namespace unicode {\n"; +print HEADER "namespace mozilla::intl {\n"; print HEADER "enum class Script : int16_t {\n"; for (my $i = 0; $i < scalar @scriptCodeToName; ++$i) { print HEADER " ", $scriptCodeToName[$i], " = ", $i, ",\n"; @@ -494,15 +482,7 @@ for (my $i = 0; $i < scalar @scriptCodeToName; ++$i) { print HEADER "\n NUM_SCRIPT_CODES = ", scalar @scriptCodeToName, ",\n"; print HEADER "\n INVALID = -1\n"; print HEADER "};\n"; -print HEADER <<__END; - -// mozilla::intl::ScriptExtensionVector assumes sizeof(Script) is equal to -// sizeof(int16_t), so if the data type of Script is changed then -// ScriptExtensionVector needs to be updated accordingly. -static_assert(sizeof(Script) == sizeof(int16_t)); -__END -print HEADER "} // namespace unicode\n"; -print HEADER "} // namespace mozilla\n\n"; +print HEADER "} // namespace mozilla::intl\n\n"; print HEADER <<__END; #endif diff --git a/intl/unicharutil/util/moz.build b/intl/unicharutil/util/moz.build index 301eb9a854ba7..b52920725e4f2 100644 --- a/intl/unicharutil/util/moz.build +++ b/intl/unicharutil/util/moz.build @@ -12,7 +12,6 @@ EXPORTS += [ "nsSpecialCasingData.h", "nsUnicharUtils.h", "nsUnicodeProperties.h", - "nsUnicodeScriptCodes.h", ] UNIFIED_SOURCES += [ diff --git a/intl/unicharutil/util/nsUnicharUtils.cpp b/intl/unicharutil/util/nsUnicharUtils.cpp index 7121bee043b86..38b721ebe4312 100644 --- a/intl/unicharutil/util/nsUnicharUtils.cpp +++ b/intl/unicharutil/util/nsUnicharUtils.cpp @@ -5,7 +5,6 @@ #include "nsUnicharUtils.h" #include "nsUTF8Utils.h" -#include "nsUnicodeProperties.h" #include "mozilla/Likely.h" #include "mozilla/HashFunctions.h" #include "mozilla/intl/UnicodeProperties.h" @@ -518,7 +517,7 @@ uint32_t HashUTF8AsUTF16(const char* aUTF8, uint32_t aLength, bool* aErr) { bool IsSegmentBreakSkipChar(uint32_t u) { return intl::UnicodeProperties::IsEastAsianWidthFHWexcludingEmoji(u) && - unicode::GetScriptCode(u) != unicode::Script::HANGUL; + intl::UnicodeProperties::GetScriptCode(u) != intl::Script::HANGUL; } } // namespace mozilla diff --git a/intl/unicharutil/util/nsUnicodeProperties.h b/intl/unicharutil/util/nsUnicodeProperties.h index 227a073751847..e2d42a4922ea8 100644 --- a/intl/unicharutil/util/nsUnicodeProperties.h +++ b/intl/unicharutil/util/nsUnicodeProperties.h @@ -11,9 +11,16 @@ #include "nsBidiUtils.h" #include "nsUGenCategory.h" -#include "nsUnicodeScriptCodes.h" #include "harfbuzz/hb.h" +struct nsCharProps2 { + // Currently only 4 bits are defined here, so 4 more could be added without + // affecting the storage requirements for this struct. Or we could pack two + // records per byte, at the cost of a slightly more complex accessor. + unsigned char mVertOrient : 2; + unsigned char mIdType : 2; +}; + const nsCharProps2& GetCharProps2(uint32_t aCh); namespace mozilla { @@ -69,17 +76,8 @@ inline uint8_t GetLineBreakClass(uint32_t aCh) { aCh, intl::UnicodeProperties::IntProperty::LineBreak); } -inline Script GetScriptCode(uint32_t aCh) { - UErrorCode err = U_ZERO_ERROR; - return Script(uscript_getScript(aCh, &err)); -} - -inline bool HasScript(uint32_t aCh, Script aScript) { - return uscript_hasScript(aCh, UScriptCode(aScript)); -} - -inline uint32_t GetScriptTagForCode(Script aScriptCode) { - const char* tag = uscript_getShortName(UScriptCode(aScriptCode)); +inline uint32_t GetScriptTagForCode(intl::Script aScriptCode) { + const char* tag = intl::UnicodeProperties::GetScriptShortName(aScriptCode); if (tag) { return HB_TAG(tag[0], tag[1], tag[2], tag[3]); } diff --git a/intl/unicharutil/util/nsUnicodePropertyData.cpp b/intl/unicharutil/util/nsUnicodePropertyData.cpp index 3d17562307202..7cd8eeadc9e44 100644 --- a/intl/unicharutil/util/nsUnicodePropertyData.cpp +++ b/intl/unicharutil/util/nsUnicodePropertyData.cpp @@ -1,5 +1,3 @@ - -/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* 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/. */ @@ -11,7 +9,7 @@ */ /* - * Created on Fri Oct 29 09:00:15 2021 from UCD data files with version info: + * Created on Thu Nov 25 12:44:10 2021 from UCD data files with version info: * # Unicode Character Database diff --git a/layout/generic/MathMLTextRunFactory.cpp b/layout/generic/MathMLTextRunFactory.cpp index f7d0431b2ccff..2d03e35c2d4a6 100644 --- a/layout/generic/MathMLTextRunFactory.cpp +++ b/layout/generic/MathMLTextRunFactory.cpp @@ -10,12 +10,12 @@ #include "mozilla/BinarySearch.h" #include "mozilla/ComputedStyle.h" #include "mozilla/ComputedStyleInlines.h" +#include "mozilla/intl/UnicodeScriptCodes.h" #include "nsStyleConsts.h" #include "nsTextFrameUtils.h" #include "nsFontMetrics.h" #include "nsDeviceContext.h" -#include "nsUnicodeScriptCodes.h" using namespace mozilla; @@ -564,7 +564,7 @@ void MathMLTextRunFactory::RebuildTextRun( // character is actually available. FontMatchType matchType; RefPtr<gfxFont> mathFont = fontGroup->FindFontForChar( - ch2, 0, 0, unicode::Script::COMMON, nullptr, &matchType); + ch2, 0, 0, intl::Script::COMMON, nullptr, &matchType); if (mathFont) { // Don't apply the CSS style if there is a math font for at least one // of the transformed character in this text run. @@ -573,7 +573,7 @@ void MathMLTextRunFactory::RebuildTextRun( // We fallback to the original character. ch2 = ch; if (aMFR) { - aMFR->RecordScript(unicode::Script::MATHEMATICAL_NOTATION); + aMFR->RecordScript(intl::Script::MATHEMATICAL_NOTATION); } } } diff --git a/layout/generic/nsTextFrame.cpp b/layout/generic/nsTextFrame.cpp index d8ff99bbe0c32..232edd3b92728 100644 --- a/layout/generic/nsTextFrame.cpp +++ b/layout/generic/nsTextFrame.cpp @@ -8370,8 +8370,8 @@ static bool FindFirstLetterRange(const nsTextFragment* aFrag, // want to allow this to split a ligature. bool allowSplitLigature; - typedef unicode::Script Script; - Script script = unicode::GetScriptCode(usv); + typedef intl::Script Script; + Script script = intl::UnicodeProperties::GetScriptCode(usv); switch (script) { default: allowSplitLigature = true; diff --git a/layout/mathml/nsMathMLChar.cpp b/layout/mathml/nsMathMLChar.cpp index 57d489dff9431..38aff6d94a8f2 100644 --- a/layout/mathml/nsMathMLChar.cpp +++ b/layout/mathml/nsMathMLChar.cpp @@ -11,6 +11,7 @@ #include "gfxUtils.h" #include "mozilla/dom/Document.h" #include "mozilla/gfx/2D.h" +#include "mozilla/intl/UnicodeScriptCodes.h" #include "mozilla/ComputedStyle.h" #include "mozilla/MathAlgorithms.h" #include "mozilla/UniquePtr.h" @@ -42,7 +43,6 @@ #include <algorithm> #include "gfxMathTable.h" -#include "nsUnicodeScriptCodes.h" using namespace mozilla; using namespace mozilla::gfx; @@ -1541,7 +1541,7 @@ nsresult nsMathMLChar::StretchInternal( // and record missing math script otherwise. gfxMissingFontRecorder* MFR = presContext->MissingFontRecorder(); if (MFR && !fm->GetThebesFontGroup()->GetFirstMathFont()) { - MFR->RecordScript(unicode::Script::MATHEMATICAL_NOTATION); + MFR->RecordScript(intl::Script::MATHEMATICAL_NOTATION); } // If the scale_stretchy_operators option is disabled, we are done. diff --git a/netwerk/dns/nsIDNService.cpp b/netwerk/dns/nsIDNService.cpp index cc836c6179547..cd4b72dc196c3 100644 --- a/netwerk/dns/nsIDNService.cpp +++ b/netwerk/dns/nsIDNService.cpp @@ -11,15 +11,14 @@ #include "nsServiceManagerUtils.h" #include "nsUnicharUtils.h" #include "nsUnicodeProperties.h" -#include "nsUnicodeScriptCodes.h" #include "harfbuzz/hb.h" #include "punycode.h" #include "mozilla/ArrayUtils.h" #include "mozilla/Casting.h" #include "mozilla/TextUtils.h" #include "mozilla/Utf8.h" -#include "mozilla/intl/Script.h" #include "mozilla/intl/UnicodeProperties.h" +#include "mozilla/intl/UnicodeScriptCodes.h" // Currently we use the non-transitional processing option -- see // http://unicode.org/reports/tr46/ @@ -31,6 +30,7 @@ const bool kIDNA2008_TransitionalProcessing = false; #include "ICUUtils.h" using namespace mozilla; +using namespace mozilla::intl; using namespace mozilla::unicode; using namespace mozilla::net; using mozilla::Preferences; @@ -764,7 +764,7 @@ bool nsIDNService::isLabelSafe(const nsAString& label) { MOZ_ASSERT(idType == IDTYPE_ALLOWED); // Check for mixed script - Script script = GetScriptCode(ch); + Script script = UnicodeProperties::GetScriptCode(ch); if (script != Script::COMMON && script != Script::INHERITED && script != lastScript) { if (illegalScriptCombo(script, savedScript)) { @@ -793,8 +793,8 @@ bool nsIDNService::isLabelSafe(const nsAString& label) { } // Check for marks whose expected script doesn't match the base script. if (lastScript != Script::INVALID) { - mozilla::intl::ScriptExtensionVector scripts; - auto extResult = mozilla::intl::Script::GetExtensions(ch, scripts); + UnicodeProperties::ScriptExtensionVector scripts; + auto extResult = UnicodeProperties::GetExtensions(ch, scripts); MOZ_ASSERT(extResult.isOk()); if (extResult.isErr()) { return false; diff --git a/netwerk/dns/nsIDNService.h b/netwerk/dns/nsIDNService.h index 9fdfde6de8ad5..09ebd53ed317c 100644 --- a/netwerk/dns/nsIDNService.h +++ b/netwerk/dns/nsIDNService.h @@ -8,11 +8,11 @@ #include "nsIIDNService.h" #include "nsCOMPtr.h" -#include "nsUnicodeScriptCodes.h" #include "nsWeakReference.h" #include "unicode/uidna.h" #include "mozilla/Mutex.h" +#include "mozilla/intl/UnicodeScriptCodes.h" #include "mozilla/net/IDNBlocklistUtils.h" #include "nsString.h" @@ -147,8 +147,7 @@ class nsIDNService final : public nsIIDNService, * For the "Moderately restrictive" profile, Latin is also allowed * with other scripts except Cyrillic and Greek */ - bool illegalScriptCombo(mozilla::unicode::Script script, - int32_t& savedScript); + bool illegalScriptCombo(mozilla::intl::Script script, int32_t& savedScript); /** * Convert a DNS label from ASCII to Unicode using IDNA2008 diff --git a/tools/rewriting/Generated.txt b/tools/rewriting/Generated.txt index 4bd75637a7b6f..1865e4ac32c96 100644 --- a/tools/rewriting/Generated.txt +++ b/tools/rewriting/Generated.txt @@ -6,6 +6,6 @@ devtools/client/debugger/node_modules/ dom/tests/ajax/jquery/ dom/tests/ajax/mochikit/ node_modules/ +intl/components/src/UnicodeScriptCodes.h intl/unicharutil/util/nsSpecialCasingData.cpp intl/unicharutil/util/nsUnicodePropertyData.cpp -intl/unicharutil/util/nsUnicodeScriptCodes.h -- GitLab