Bug 1719554 - Unify unicode::Script as intl::Script; r=platform-i18n-reviewers,gregtatum

Differential Revision: https://phabricator.services.mozilla.com/D132278
This commit is contained in:
Dan Minor
2021-12-06 18:15:50 +00:00
parent ef775171c2
commit 237b40ae17
32 changed files with 189 additions and 249 deletions

View File

@@ -35,9 +35,9 @@ layout/style/nsStyleStructList.h
gfx/gl/GLConsts.h gfx/gl/GLConsts.h
gfx/webrender_bindings/webrender_ffi_generated.h gfx/webrender_bindings/webrender_ffi_generated.h
dom/webgpu/ffi/wgpu_ffi_generated.h dom/webgpu/ffi/wgpu_ffi_generated.h
intl/components/src/UnicodeScriptCodes.h
intl/unicharutil/util/nsSpecialCasingData.cpp intl/unicharutil/util/nsSpecialCasingData.cpp
intl/unicharutil/util/nsUnicodePropertyData.cpp intl/unicharutil/util/nsUnicodePropertyData.cpp
intl/unicharutil/util/nsUnicodeScriptCodes.h
media/mp4parse-rust/mp4parse.h media/mp4parse-rust/mp4parse.h
security/manager/ssl/StaticHPKPins.h security/manager/ssl/StaticHPKPins.h
widget/gtk/wayland/gtk-primary-selection-client-protocol.h widget/gtk/wayland/gtk-primary-selection-client-protocol.h

View File

@@ -69,10 +69,9 @@ gfxCoreTextShaper::~gfxCoreTextShaper() {
} }
} }
static bool IsBuggyIndicScript(unicode::Script aScript) { static bool IsBuggyIndicScript(intl::Script aScript) {
return aScript == unicode::Script::BENGALI || return aScript == intl::Script::BENGALI || aScript == intl::Script::KANNADA ||
aScript == unicode::Script::KANNADA || aScript == intl::Script::ORIYA || aScript == intl::Script::KHMER;
aScript == unicode::Script::ORIYA || aScript == unicode::Script::KHMER;
} }
bool gfxCoreTextShaper::ShapeText(DrawTarget* aDrawTarget, bool gfxCoreTextShaper::ShapeText(DrawTarget* aDrawTarget,

View File

@@ -1105,10 +1105,10 @@ static void HasLookupRuleWithGlyph(hb_face_t* aFace, hb_tag_t aTableTag,
hb_set_destroy(otherLookups); hb_set_destroy(otherLookups);
} }
nsTHashMap<nsUint32HashKey, Script>* gfxFont::sScriptTagToCode = nullptr; nsTHashMap<nsUint32HashKey, intl::Script>* gfxFont::sScriptTagToCode = nullptr;
nsTHashSet<uint32_t>* gfxFont::sDefaultFeatures = 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] & return (aBitVector[static_cast<uint32_t>(aScript) >> 5] &
(1 << (static_cast<uint32_t>(aScript) & 0x1f))) != 0; (1 << (static_cast<uint32_t>(aScript) & 0x1f))) != 0;
} }
@@ -1165,8 +1165,8 @@ void gfxFont::CheckForFeaturesInvolvingSpace() {
// Ensure that we don't try to look at script codes beyond what the // 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) // current version of ICU (at runtime -- in case of system ICU)
// knows about. // knows about.
Script scriptCount = Script scriptCount = Script(
Script(std::min<int>(u_getIntPropertyMaxValue(UCHAR_SCRIPT) + 1, std::min<int>(intl::UnicodeProperties::GetMaxNumberOfScripts() + 1,
int(Script::NUM_SCRIPT_CODES))); int(Script::NUM_SCRIPT_CODES)));
for (Script s = Script::ARABIC; s < scriptCount; for (Script s = Script::ARABIC; s < scriptCount;
s = Script(static_cast<int>(s) + 1)) { s = Script(static_cast<int>(s) + 1)) {

View File

@@ -24,6 +24,7 @@
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
#include "mozilla/gfx/MatrixFwd.h" #include "mozilla/gfx/MatrixFwd.h"
#include "mozilla/gfx/Point.h" #include "mozilla/gfx/Point.h"
#include "mozilla/intl/UnicodeScriptCodes.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsColor.h" #include "nsColor.h"
#include "nsTHashMap.h" #include "nsTHashMap.h"
@@ -37,7 +38,6 @@
#include "nsString.h" #include "nsString.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "nsTHashtable.h" #include "nsTHashtable.h"
#include "nsUnicodeScriptCodes.h"
#include "nscore.h" #include "nscore.h"
// Only required for function bodys // Only required for function bodys
@@ -672,7 +672,7 @@ class gfxTextRunFactory {
class gfxFontShaper { class gfxFontShaper {
public: public:
typedef mozilla::gfx::DrawTarget DrawTarget; typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::unicode::Script Script; typedef mozilla::intl::Script Script;
enum class RoundingFlags : uint8_t { kRoundX = 0x01, kRoundY = 0x02 }; enum class RoundingFlags : uint8_t { kRoundX = 0x01, kRoundY = 0x02 };
@@ -731,7 +731,7 @@ MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(gfxFontShaper::RoundingFlags)
*/ */
class gfxShapedText { class gfxShapedText {
public: public:
typedef mozilla::unicode::Script Script; typedef mozilla::intl::Script Script;
gfxShapedText(uint32_t aLength, mozilla::gfx::ShapedTextFlags aFlags, gfxShapedText(uint32_t aLength, mozilla::gfx::ShapedTextFlags aFlags,
uint16_t aAppUnitsPerDevUnit) uint16_t aAppUnitsPerDevUnit)
@@ -1261,7 +1261,7 @@ class gfxShapedText {
*/ */
class gfxShapedWord final : public gfxShapedText { class gfxShapedWord final : public gfxShapedText {
public: public:
typedef mozilla::unicode::Script Script; typedef mozilla::intl::Script Script;
// Create a ShapedWord that can hold glyphs for aLength characters, // Create a ShapedWord that can hold glyphs for aLength characters,
// with mCharacterGlyphs sized appropriately. // with mCharacterGlyphs sized appropriately.
@@ -1426,7 +1426,7 @@ class gfxFont {
protected: protected:
using DrawTarget = mozilla::gfx::DrawTarget; using DrawTarget = mozilla::gfx::DrawTarget;
using Script = mozilla::unicode::Script; using Script = mozilla::intl::Script;
using SVGContextPaint = mozilla::SVGContextPaint; using SVGContextPaint = mozilla::SVGContextPaint;
using RoundingFlags = gfxFontShaper::RoundingFlags; using RoundingFlags = gfxFontShaper::RoundingFlags;

View File

@@ -814,7 +814,7 @@ tainted_boolean_hint gfxFontEntry::HasGraphiteSpaceContextuals() {
#define FEATURE_SCRIPT_MASK 0x000000ff // script index replaces low byte of tag #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"); "Too many script codes");
// high-order three bytes of tag with script in low-order byte // 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); LogModule* log = gfxPlatform::GetLog(eGfxLog_textrun);
if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Debug))) { 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, MOZ_LOG(log, LogLevel::Debug,
("(textrun-systemfallback-fonts) char: u+%6.6x " ("(textrun-systemfallback-fonts) char: u+%6.6x "
"script: %d match: [%s]\n", "script: %d match: [%s]\n",

View File

@@ -23,13 +23,13 @@
#include "mozilla/RefPtr.h" #include "mozilla/RefPtr.h"
#include "mozilla/TypedEnumBits.h" #include "mozilla/TypedEnumBits.h"
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
#include "mozilla/intl/UnicodeScriptCodes.h"
#include "nsTHashMap.h" #include "nsTHashMap.h"
#include "nsDebug.h" #include "nsDebug.h"
#include "nsHashKeys.h" #include "nsHashKeys.h"
#include "nsISupports.h" #include "nsISupports.h"
#include "nsStringFwd.h" #include "nsStringFwd.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "nsUnicodeScriptCodes.h"
#include "nscore.h" #include "nscore.h"
class FontInfoData; class FontInfoData;
@@ -131,7 +131,7 @@ struct gfxFontFeatureInfo {
class gfxFontEntry { class gfxFontEntry {
public: public:
typedef mozilla::gfx::DrawTarget DrawTarget; typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::unicode::Script Script; typedef mozilla::intl::Script Script;
typedef mozilla::FontWeight FontWeight; typedef mozilla::FontWeight FontWeight;
typedef mozilla::FontSlantStyle FontSlantStyle; typedef mozilla::FontSlantStyle FontSlantStyle;
typedef mozilla::FontStretch FontStretch; typedef mozilla::FontStretch FontStretch;

View File

@@ -12,8 +12,8 @@
#include "mozilla/Sprintf.h" #include "mozilla/Sprintf.h"
#include "mozilla/intl/String.h" #include "mozilla/intl/String.h"
#include "mozilla/intl/UnicodeProperties.h" #include "mozilla/intl/UnicodeProperties.h"
#include "mozilla/intl/UnicodeScriptCodes.h"
#include "nsUnicodeProperties.h" #include "nsUnicodeProperties.h"
#include "nsUnicodeScriptCodes.h"
#include "harfbuzz/hb.h" #include "harfbuzz/hb.h"
#include "harfbuzz/hb-ot.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, static hb_script_t HBGetScript(hb_unicode_funcs_t* ufuncs, hb_codepoint_t aCh,
void* user_data) { 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( static hb_unicode_combining_class_t HBGetCombiningClass(

View File

@@ -8,10 +8,10 @@
#include "mozilla/FontPropertyTypes.h" #include "mozilla/FontPropertyTypes.h"
#include "mozilla/gfx/Types.h" #include "mozilla/gfx/Types.h"
#include "mozilla/intl/UnicodeScriptCodes.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "nsString.h" #include "nsString.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsUnicodeScriptCodes.h"
#include "gfxTelemetry.h" #include "gfxTelemetry.h"
#include "gfxTypes.h" #include "gfxTypes.h"
@@ -186,7 +186,7 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener {
typedef mozilla::gfx::DrawTarget DrawTarget; typedef mozilla::gfx::DrawTarget DrawTarget;
typedef mozilla::gfx::IntSize IntSize; typedef mozilla::gfx::IntSize IntSize;
typedef mozilla::gfx::SourceSurface SourceSurface; typedef mozilla::gfx::SourceSurface SourceSurface;
typedef mozilla::unicode::Script Script; typedef mozilla::intl::Script Script;
/** /**
* Return a pointer to the current active platform. * Return a pointer to the current active platform.

View File

@@ -975,7 +975,7 @@ gfxFont* gfxPlatformFontList::SystemFindFontForChar(
LogModule* log = gfxPlatform::GetLog(eGfxLog_textrun); LogModule* log = gfxPlatform::GetLog(eGfxLog_textrun);
if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Warning))) { 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, MOZ_LOG(log, LogLevel::Warning,
("(textrun-systemfallback-%s) char: u+%6.6x " ("(textrun-systemfallback-%s) char: u+%6.6x "
"script: %d match: [%s]" "script: %d match: [%s]"

View File

@@ -162,7 +162,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
typedef mozilla::StretchRange StretchRange; typedef mozilla::StretchRange StretchRange;
typedef mozilla::SlantStyleRange SlantStyleRange; typedef mozilla::SlantStyleRange SlantStyleRange;
typedef mozilla::WeightRange WeightRange; 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 // For font family lists loaded from user preferences (prefs such as
// font.name-list.<generic>.<langGroup>) that map CSS generics to // font.name-list.<generic>.<langGroup>) that map CSS generics to

View File

@@ -48,12 +48,12 @@
*/ */
#include "gfxScriptItemizer.h" #include "gfxScriptItemizer.h"
#include "mozilla/intl/Script.h"
#include "mozilla/intl/UnicodeProperties.h" #include "mozilla/intl/UnicodeProperties.h"
#include "nsUnicodeProperties.h"
#include "nsCharTraits.h" #include "nsCharTraits.h"
#include "nsUnicodeProperties.h"
#include "harfbuzz/hb.h" #include "harfbuzz/hb.h"
using namespace mozilla::intl;
using namespace mozilla::unicode; using namespace mozilla::unicode;
#define MOD(sp) ((sp) % PAREN_STACK_DEPTH) #define MOD(sp) ((sp) % PAREN_STACK_DEPTH)
@@ -117,7 +117,8 @@ static inline bool SameScript(Script runScript, Script currCharScript,
uint32_t aCurrCh) { uint32_t aCurrCh) {
return CanMergeWithContext(runScript) || return CanMergeWithContext(runScript) ||
CanMergeWithContext(currCharScript) || currCharScript == 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) 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. // if the character has script=COMMON, otherwise we don't care.
uint8_t gc = HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED; uint8_t gc = HB_UNICODE_GENERAL_CATEGORY_UNASSIGNED;
sc = GetScriptCode(ch); sc = UnicodeProperties::GetScriptCode(ch);
if (sc == Script::COMMON) { if (sc == Script::COMMON) {
/* /*
* Paired character handling: * Paired character handling:
@@ -178,12 +179,12 @@ bool gfxScriptItemizer::Next(uint32_t& aRunStart, uint32_t& aRunLimit,
*/ */
gc = GetGeneralCategory(ch); gc = GetGeneralCategory(ch);
if (gc == HB_UNICODE_GENERAL_CATEGORY_OPEN_PUNCTUATION) { 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) { if (endPairChar != ch) {
push(endPairChar, scriptCode); push(endPairChar, scriptCode);
} }
} else if (gc == HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION && } 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) { while (STACK_IS_NOT_EMPTY() && TOP().endPairChar != ch) {
pop(); pop();
} }
@@ -205,8 +206,8 @@ bool gfxScriptItemizer::Next(uint32_t& aRunStart, uint32_t& aRunLimit,
} else if (fallbackScript == Script::UNKNOWN) { } else if (fallbackScript == Script::UNKNOWN) {
// See if the character has a ScriptExtensions property we can // See if the character has a ScriptExtensions property we can
// store for use in the event the run remains unresolved. // store for use in the event the run remains unresolved.
mozilla::intl::ScriptExtensionVector extensions; UnicodeProperties::ScriptExtensionVector extensions;
auto extResult = mozilla::intl::Script::GetExtensions(ch, extensions); auto extResult = UnicodeProperties::GetExtensions(ch, extensions);
if (extResult.isOk()) { if (extResult.isOk()) {
Script ext = Script(extensions[0]); Script ext = Script(extensions[0]);
if (!CanMergeWithContext(ext)) { if (!CanMergeWithContext(ext)) {
@@ -221,7 +222,7 @@ bool gfxScriptItemizer::Next(uint32_t& aRunStart, uint32_t& aRunLimit,
* pop the matching open character from the stack * pop the matching open character from the stack
*/ */
if (gc == HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION && if (gc == HB_UNICODE_GENERAL_CATEGORY_CLOSE_PUNCTUATION &&
mozilla::intl::UnicodeProperties::IsMirrored(ch)) { UnicodeProperties::IsMirrored(ch)) {
pop(); pop();
} }
} else { } else {

View File

@@ -51,13 +51,13 @@
#define GFX_SCRIPTITEMIZER_H #define GFX_SCRIPTITEMIZER_H
#include <stdint.h> #include <stdint.h>
#include "nsUnicodeScriptCodes.h" #include "mozilla/intl/UnicodeScriptCodes.h"
#define PAREN_STACK_DEPTH 32 #define PAREN_STACK_DEPTH 32
class gfxScriptItemizer { class gfxScriptItemizer {
public: public:
typedef mozilla::unicode::Script Script; typedef mozilla::intl::Script Script;
gfxScriptItemizer(const char16_t* src, uint32_t length); gfxScriptItemizer(const char16_t* src, uint32_t length);

View File

@@ -24,6 +24,7 @@
#include "mozilla/Likely.h" #include "mozilla/Likely.h"
#include "gfx2DGlue.h" #include "gfx2DGlue.h"
#include "mozilla/gfx/Logging.h" // for gfxCriticalError #include "mozilla/gfx/Logging.h" // for gfxCriticalError
#include "mozilla/intl/UnicodeProperties.h"
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
#include "mozilla/Unused.h" #include "mozilla/Unused.h"
#include "SharedFontList-impl.h" #include "SharedFontList-impl.h"
@@ -37,6 +38,7 @@
using namespace mozilla; using namespace mozilla;
using namespace mozilla::gfx; using namespace mozilla::gfx;
using namespace mozilla::intl;
using namespace mozilla::unicode; using namespace mozilla::unicode;
using mozilla::services::GetObserverService; using mozilla::services::GetObserverService;

View File

@@ -19,6 +19,7 @@
#include "gfxUserFontSet.h" #include "gfxUserFontSet.h"
#include "mozilla/MemoryReporting.h" #include "mozilla/MemoryReporting.h"
#include "mozilla/RefPtr.h" #include "mozilla/RefPtr.h"
#include "mozilla/intl/UnicodeScriptCodes.h"
#include "nsPoint.h" #include "nsPoint.h"
#include "nsString.h" #include "nsString.h"
#include "nsTArray.h" #include "nsTArray.h"
@@ -26,7 +27,6 @@
#include "nsTextFrameUtils.h" #include "nsTextFrameUtils.h"
#include "DrawMode.h" #include "DrawMode.h"
#include "harfbuzz/hb.h" #include "harfbuzz/hb.h"
#include "nsUnicodeScriptCodes.h"
#include "nsColor.h" #include "nsColor.h"
#include "nsFrameList.h" #include "nsFrameList.h"
#include "X11UndefineNone.h" #include "X11UndefineNone.h"
@@ -901,7 +901,7 @@ class gfxTextRun : public gfxShapedText {
class gfxFontGroup final : public gfxTextRunFactory { class gfxFontGroup final : public gfxTextRunFactory {
public: public:
typedef mozilla::unicode::Script Script; typedef mozilla::intl::Script Script;
typedef gfxShapedText::CompressedGlyph CompressedGlyph; typedef gfxShapedText::CompressedGlyph CompressedGlyph;
static void static void
@@ -1508,7 +1508,7 @@ class gfxMissingFontRecorder {
} }
// record this script code in our mMissingFonts bitset // 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] |= mMissingFonts[static_cast<uint32_t>(aScriptCode) >> 5] |=
(1 << (static_cast<uint32_t>(aScriptCode) & 0x1f)); (1 << (static_cast<uint32_t>(aScriptCode) & 0x1f));
} }
@@ -1524,8 +1524,7 @@ class gfxMissingFontRecorder {
private: private:
// Number of 32-bit words needed for the missing-script flags // Number of 32-bit words needed for the missing-script flags
static const uint32_t kNumScriptBitsWords = static const uint32_t kNumScriptBitsWords =
((static_cast<int>(mozilla::unicode::Script::NUM_SCRIPT_CODES) + 31) / ((static_cast<int>(mozilla::intl::Script::NUM_SCRIPT_CODES) + 31) / 32);
32);
uint32_t mMissingFonts[kNumScriptBitsWords]; uint32_t mMissingFonts[kNumScriptBitsWords];
}; };

View File

@@ -3,60 +3,60 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "mozilla/intl/Script.h" #include "mozilla/intl/UnicodeProperties.h"
#include "nsUnicodeScriptCodes.h" #include "mozilla/intl/UnicodeScriptCodes.h"
namespace mozilla::intl { namespace mozilla::intl {
TEST(IntlScript, GetExtensions) TEST(IntlScript, GetExtensions)
{ {
ScriptExtensionVector extensions; UnicodeProperties::ScriptExtensionVector extensions;
// 0x0000..0x0040 are Common. // 0x0000..0x0040 are Common.
for (char32_t ch = 0; ch < 0x0041; ch++) { 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(extensions.length(), 1u);
ASSERT_EQ(unicode::Script(extensions[0]), unicode::Script::COMMON); ASSERT_EQ(Script(extensions[0]), Script::COMMON);
} }
// 0x0300..0x0341 are Inherited. // 0x0300..0x0341 are Inherited.
for (char32_t ch = 0x300; ch < 0x0341; ch++) { 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(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. // 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(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/ // https://unicode-table.com/en/063F/
// This character doesn't have any script extension, so the script code is // This character doesn't have any script extension, so the script code is
// returned. // returned.
ASSERT_TRUE(Script::GetExtensions(0x063f, extensions).isOk()); ASSERT_TRUE(UnicodeProperties::GetExtensions(0x063f, extensions).isOk());
ASSERT_EQ(extensions.length(), 1u); 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/ // 0xff65 is the unicode character '・', see https://unicode-table.com/en/FF65/
// Halfwidth Katakana Middle Dot. // 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: // 0xff65 should have the following script extensions:
// Bopo Hang Hani Hira Kana Yiii. // Bopo Hang Hani Hira Kana Yiii.
ASSERT_EQ(extensions.length(), 6u); ASSERT_EQ(extensions.length(), 6u);
ASSERT_EQ(unicode::Script(extensions[0]), unicode::Script::BOPOMOFO); ASSERT_EQ(Script(extensions[0]), Script::BOPOMOFO);
ASSERT_EQ(unicode::Script(extensions[1]), unicode::Script::HAN); ASSERT_EQ(Script(extensions[1]), Script::HAN);
ASSERT_EQ(unicode::Script(extensions[2]), unicode::Script::HANGUL); ASSERT_EQ(Script(extensions[2]), Script::HANGUL);
ASSERT_EQ(unicode::Script(extensions[3]), unicode::Script::HIRAGANA); ASSERT_EQ(Script(extensions[3]), Script::HIRAGANA);
ASSERT_EQ(unicode::Script(extensions[4]), unicode::Script::KATAKANA); ASSERT_EQ(Script(extensions[4]), Script::KATAKANA);
ASSERT_EQ(unicode::Script(extensions[5]), unicode::Script::YI); ASSERT_EQ(Script(extensions[5]), Script::YI);
// The max code point is 0x10ffff, so 0x110000 should be invalid. // The max code point is 0x10ffff, so 0x110000 should be invalid.
// Script::UNKNOWN should be returned for an invalid code point. // 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(extensions.length(), 1u);
ASSERT_EQ(unicode::Script(extensions[0]), unicode::Script::UNKNOWN); ASSERT_EQ(Script(extensions[0]), Script::UNKNOWN);
} }
} // namespace mozilla::intl } // namespace mozilla::intl

View File

@@ -28,10 +28,10 @@ EXPORTS.mozilla.intl = [
"src/NumberRangeFormat.h", "src/NumberRangeFormat.h",
"src/PluralRules.h", "src/PluralRules.h",
"src/RelativeTimeFormat.h", "src/RelativeTimeFormat.h",
"src/Script.h",
"src/String.h", "src/String.h",
"src/TimeZone.h", "src/TimeZone.h",
"src/UnicodeProperties.h", "src/UnicodeProperties.h",
"src/UnicodeScriptCodes.h",
] ]
UNIFIED_SOURCES += [ UNIFIED_SOURCES += [
@@ -58,7 +58,6 @@ UNIFIED_SOURCES += [
"src/NumberRangeFormat.cpp", "src/NumberRangeFormat.cpp",
"src/PluralRules.cpp", "src/PluralRules.cpp",
"src/RelativeTimeFormat.cpp", "src/RelativeTimeFormat.cpp",
"src/Script.cpp",
"src/String.cpp", "src/String.cpp",
"src/TimeZone.cpp", "src/TimeZone.cpp",
] ]

View File

@@ -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

View File

@@ -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_

View File

@@ -5,6 +5,9 @@
#define intl_components_UnicodeProperties_h_ #define intl_components_UnicodeProperties_h_
#include "mozilla/intl/BidiClass.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/uchar.h"
#include "unicode/uscript.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. // Keep this function in sync with is_math_symbol in base_chars.py.
return CharType(aCh) == U_MATH_SYMBOL || CharType(aCh) == U_OTHER_SYMBOL; 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 } // namespace mozilla::intl

View File

@@ -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 /* 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 * 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/. */ * 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 # 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! * * * * * * * * * * This file contains MACHINE-GENERATED DATA, do not edit! * * * * *
*/ */
#ifndef NS_UNICODE_SCRIPT_CODES #ifndef intl_components_UnicodeScriptCodes_h_
#define NS_UNICODE_SCRIPT_CODES #define intl_components_UnicodeScriptCodes_h_
namespace mozilla::intl {
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 {
enum class Script : int16_t { enum class Script : int16_t {
COMMON = 0, COMMON = 0,
INHERITED = 1, INHERITED = 1,
@@ -263,13 +251,7 @@ enum class Script : int16_t {
INVALID = -1 INVALID = -1
}; };
} // namespace mozilla::intl
// 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
#endif #endif
/* /*

View File

@@ -3,17 +3,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/intl/UnicodeProperties.h"
#include "mozilla/intl/WordBreaker.h" #include "mozilla/intl/WordBreaker.h"
#include "mozilla/StaticPrefs_layout.h" #include "mozilla/StaticPrefs_layout.h"
#include "nsComplexBreaker.h" #include "nsComplexBreaker.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "nsUnicodeProperties.h"
using mozilla::intl::Script;
using mozilla::intl::UnicodeProperties;
using mozilla::intl::WordBreaker; using mozilla::intl::WordBreaker;
using mozilla::intl::WordRange; using mozilla::intl::WordRange;
using mozilla::unicode::GetGenCategory; using mozilla::unicode::GetGenCategory;
using mozilla::unicode::GetScriptCode;
using mozilla::unicode::Script;
#define IS_ASCII(c) (0 == (0xFF80 & (c))) #define IS_ASCII(c) (0 == (0xFF80 & (c)))
#define ASCII_IS_ALPHA(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 // the script is not supported by the platform, we just won't find any useful
// boundaries.) // boundaries.)
static bool IsScriptioContinua(char16_t aChar) { 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 || return sc == Script::THAI || sc == Script::MYANMAR || sc == Script::KHMER ||
sc == Script::JAVANESE || sc == Script::BALINESE || sc == Script::JAVANESE || sc == Script::BALINESE ||
sc == Script::SUNDANESE || sc == Script::LAO; sc == Script::SUNDANESE || sc == Script::LAO;

View File

@@ -47,7 +47,7 @@
# This will generate (or overwrite!) the files # This will generate (or overwrite!) the files
# #
# nsUnicodePropertyData.cpp # nsUnicodePropertyData.cpp
# nsUnicodeScriptCodes.h # UnicodeScriptCodes.h
# #
# in the current directory. # in the current directory.
@@ -71,7 +71,7 @@ if ($#ARGV != 1) {
# This will generate (or overwrite!) the files # This will generate (or overwrite!) the files
# #
# nsUnicodePropertyData.cpp # nsUnicodePropertyData.cpp
# nsUnicodeScriptCodes.h # UnicodeScriptCodes.h
# #
# in the current directory. # in the current directory.
__EOT __EOT
@@ -132,7 +132,7 @@ my %idType = (
"Deprecated" => 12 "Deprecated" => 12
); );
# These match the IdentifierType enum in nsUnicodeProperties.h. # These match the IdentifierType enum in UnicodeProperties.h.
my %mappedIdType = ( my %mappedIdType = (
"Restricted" => 0, "Restricted" => 0,
"Allowed" => 1 "Allowed" => 1
@@ -292,9 +292,7 @@ my $timestamp = gmtime();
open DATA_TABLES, "> nsUnicodePropertyData.cpp" or die "unable to open nsUnicodePropertyData.cpp for output"; open DATA_TABLES, "> nsUnicodePropertyData.cpp" or die "unable to open nsUnicodePropertyData.cpp for output";
my $licenseBlock = q[ my $licenseBlock = q[/* This Source Code Form is subject to the terms of the Mozilla Public
/* -*- 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 * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -324,7 +322,7 @@ $versionInfo
__END __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; print HEADER <<__END;
$licenseBlock $licenseBlock
@@ -338,8 +336,8 @@ $versionInfo
* * * * * This file contains MACHINE-GENERATED DATA, do not edit! * * * * * * * * * * This file contains MACHINE-GENERATED DATA, do not edit! * * * * *
*/ */
#ifndef NS_UNICODE_SCRIPT_CODES #ifndef intl_components_UnicodeScriptCodes_h_
#define NS_UNICODE_SCRIPT_CODES #define intl_components_UnicodeScriptCodes_h_
__END __END
@@ -351,16 +349,7 @@ sub sprintCharProps2_short
return sprintf("{%d,%d},", return sprintf("{%d,%d},",
$verticalOrientation[$usv], $idtype[$usv]); $verticalOrientation[$usv], $idtype[$usv]);
} }
my $type = q| &genTables("CharProp2", "", "nsCharProps2", 9, 7, \&sprintCharProps2_short, 16, 1, 1);
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);
sub sprintHanVariants sub sprintHanVariants
{ {
@@ -485,8 +474,7 @@ __END
close DATA_TABLES; close DATA_TABLES;
print HEADER "namespace mozilla {\n"; print HEADER "namespace mozilla::intl {\n";
print HEADER "namespace unicode {\n";
print HEADER "enum class Script : int16_t {\n"; print HEADER "enum class Script : int16_t {\n";
for (my $i = 0; $i < scalar @scriptCodeToName; ++$i) { for (my $i = 0; $i < scalar @scriptCodeToName; ++$i) {
print HEADER " ", $scriptCodeToName[$i], " = ", $i, ",\n"; 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 NUM_SCRIPT_CODES = ", scalar @scriptCodeToName, ",\n";
print HEADER "\n INVALID = -1\n"; print HEADER "\n INVALID = -1\n";
print HEADER "};\n"; print HEADER "};\n";
print HEADER <<__END; print HEADER "} // namespace mozilla::intl\n\n";
// 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 <<__END; print HEADER <<__END;
#endif #endif

View File

@@ -12,7 +12,6 @@ EXPORTS += [
"nsSpecialCasingData.h", "nsSpecialCasingData.h",
"nsUnicharUtils.h", "nsUnicharUtils.h",
"nsUnicodeProperties.h", "nsUnicodeProperties.h",
"nsUnicodeScriptCodes.h",
] ]
UNIFIED_SOURCES += [ UNIFIED_SOURCES += [

View File

@@ -5,7 +5,6 @@
#include "nsUnicharUtils.h" #include "nsUnicharUtils.h"
#include "nsUTF8Utils.h" #include "nsUTF8Utils.h"
#include "nsUnicodeProperties.h"
#include "mozilla/Likely.h" #include "mozilla/Likely.h"
#include "mozilla/HashFunctions.h" #include "mozilla/HashFunctions.h"
#include "mozilla/intl/UnicodeProperties.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) { bool IsSegmentBreakSkipChar(uint32_t u) {
return intl::UnicodeProperties::IsEastAsianWidthFHWexcludingEmoji(u) && return intl::UnicodeProperties::IsEastAsianWidthFHWexcludingEmoji(u) &&
unicode::GetScriptCode(u) != unicode::Script::HANGUL; intl::UnicodeProperties::GetScriptCode(u) != intl::Script::HANGUL;
} }
} // namespace mozilla } // namespace mozilla

View File

@@ -11,9 +11,16 @@
#include "nsBidiUtils.h" #include "nsBidiUtils.h"
#include "nsUGenCategory.h" #include "nsUGenCategory.h"
#include "nsUnicodeScriptCodes.h"
#include "harfbuzz/hb.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); const nsCharProps2& GetCharProps2(uint32_t aCh);
namespace mozilla { namespace mozilla {
@@ -69,17 +76,8 @@ inline uint8_t GetLineBreakClass(uint32_t aCh) {
aCh, intl::UnicodeProperties::IntProperty::LineBreak); aCh, intl::UnicodeProperties::IntProperty::LineBreak);
} }
inline Script GetScriptCode(uint32_t aCh) { inline uint32_t GetScriptTagForCode(intl::Script aScriptCode) {
UErrorCode err = U_ZERO_ERROR; const char* tag = intl::UnicodeProperties::GetScriptShortName(aScriptCode);
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));
if (tag) { if (tag) {
return HB_TAG(tag[0], tag[1], tag[2], tag[3]); return HB_TAG(tag[0], tag[1], tag[2], tag[3]);
} }

View File

@@ -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 /* 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 * 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/. */ * 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 # Unicode Character Database

View File

@@ -10,12 +10,12 @@
#include "mozilla/BinarySearch.h" #include "mozilla/BinarySearch.h"
#include "mozilla/ComputedStyle.h" #include "mozilla/ComputedStyle.h"
#include "mozilla/ComputedStyleInlines.h" #include "mozilla/ComputedStyleInlines.h"
#include "mozilla/intl/UnicodeScriptCodes.h"
#include "nsStyleConsts.h" #include "nsStyleConsts.h"
#include "nsTextFrameUtils.h" #include "nsTextFrameUtils.h"
#include "nsFontMetrics.h" #include "nsFontMetrics.h"
#include "nsDeviceContext.h" #include "nsDeviceContext.h"
#include "nsUnicodeScriptCodes.h"
using namespace mozilla; using namespace mozilla;
@@ -564,7 +564,7 @@ void MathMLTextRunFactory::RebuildTextRun(
// character is actually available. // character is actually available.
FontMatchType matchType; FontMatchType matchType;
RefPtr<gfxFont> mathFont = fontGroup->FindFontForChar( RefPtr<gfxFont> mathFont = fontGroup->FindFontForChar(
ch2, 0, 0, unicode::Script::COMMON, nullptr, &matchType); ch2, 0, 0, intl::Script::COMMON, nullptr, &matchType);
if (mathFont) { if (mathFont) {
// Don't apply the CSS style if there is a math font for at least one // Don't apply the CSS style if there is a math font for at least one
// of the transformed character in this text run. // of the transformed character in this text run.
@@ -573,7 +573,7 @@ void MathMLTextRunFactory::RebuildTextRun(
// We fallback to the original character. // We fallback to the original character.
ch2 = ch; ch2 = ch;
if (aMFR) { if (aMFR) {
aMFR->RecordScript(unicode::Script::MATHEMATICAL_NOTATION); aMFR->RecordScript(intl::Script::MATHEMATICAL_NOTATION);
} }
} }
} }

View File

@@ -8370,8 +8370,8 @@ static bool FindFirstLetterRange(const nsTextFragment* aFrag,
// want to allow this to split a ligature. // want to allow this to split a ligature.
bool allowSplitLigature; bool allowSplitLigature;
typedef unicode::Script Script; typedef intl::Script Script;
Script script = unicode::GetScriptCode(usv); Script script = intl::UnicodeProperties::GetScriptCode(usv);
switch (script) { switch (script) {
default: default:
allowSplitLigature = true; allowSplitLigature = true;

View File

@@ -11,6 +11,7 @@
#include "gfxUtils.h" #include "gfxUtils.h"
#include "mozilla/dom/Document.h" #include "mozilla/dom/Document.h"
#include "mozilla/gfx/2D.h" #include "mozilla/gfx/2D.h"
#include "mozilla/intl/UnicodeScriptCodes.h"
#include "mozilla/ComputedStyle.h" #include "mozilla/ComputedStyle.h"
#include "mozilla/MathAlgorithms.h" #include "mozilla/MathAlgorithms.h"
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
@@ -42,7 +43,6 @@
#include <algorithm> #include <algorithm>
#include "gfxMathTable.h" #include "gfxMathTable.h"
#include "nsUnicodeScriptCodes.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::gfx; using namespace mozilla::gfx;
@@ -1541,7 +1541,7 @@ nsresult nsMathMLChar::StretchInternal(
// and record missing math script otherwise. // and record missing math script otherwise.
gfxMissingFontRecorder* MFR = presContext->MissingFontRecorder(); gfxMissingFontRecorder* MFR = presContext->MissingFontRecorder();
if (MFR && !fm->GetThebesFontGroup()->GetFirstMathFont()) { 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. // If the scale_stretchy_operators option is disabled, we are done.

View File

@@ -11,15 +11,14 @@
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
#include "nsUnicharUtils.h" #include "nsUnicharUtils.h"
#include "nsUnicodeProperties.h" #include "nsUnicodeProperties.h"
#include "nsUnicodeScriptCodes.h"
#include "harfbuzz/hb.h" #include "harfbuzz/hb.h"
#include "punycode.h" #include "punycode.h"
#include "mozilla/ArrayUtils.h" #include "mozilla/ArrayUtils.h"
#include "mozilla/Casting.h" #include "mozilla/Casting.h"
#include "mozilla/TextUtils.h" #include "mozilla/TextUtils.h"
#include "mozilla/Utf8.h" #include "mozilla/Utf8.h"
#include "mozilla/intl/Script.h"
#include "mozilla/intl/UnicodeProperties.h" #include "mozilla/intl/UnicodeProperties.h"
#include "mozilla/intl/UnicodeScriptCodes.h"
// Currently we use the non-transitional processing option -- see // Currently we use the non-transitional processing option -- see
// http://unicode.org/reports/tr46/ // http://unicode.org/reports/tr46/
@@ -31,6 +30,7 @@ const bool kIDNA2008_TransitionalProcessing = false;
#include "ICUUtils.h" #include "ICUUtils.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::intl;
using namespace mozilla::unicode; using namespace mozilla::unicode;
using namespace mozilla::net; using namespace mozilla::net;
using mozilla::Preferences; using mozilla::Preferences;
@@ -764,7 +764,7 @@ bool nsIDNService::isLabelSafe(const nsAString& label) {
MOZ_ASSERT(idType == IDTYPE_ALLOWED); MOZ_ASSERT(idType == IDTYPE_ALLOWED);
// Check for mixed script // Check for mixed script
Script script = GetScriptCode(ch); Script script = UnicodeProperties::GetScriptCode(ch);
if (script != Script::COMMON && script != Script::INHERITED && if (script != Script::COMMON && script != Script::INHERITED &&
script != lastScript) { script != lastScript) {
if (illegalScriptCombo(script, savedScript)) { 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. // Check for marks whose expected script doesn't match the base script.
if (lastScript != Script::INVALID) { if (lastScript != Script::INVALID) {
mozilla::intl::ScriptExtensionVector scripts; UnicodeProperties::ScriptExtensionVector scripts;
auto extResult = mozilla::intl::Script::GetExtensions(ch, scripts); auto extResult = UnicodeProperties::GetExtensions(ch, scripts);
MOZ_ASSERT(extResult.isOk()); MOZ_ASSERT(extResult.isOk());
if (extResult.isErr()) { if (extResult.isErr()) {
return false; return false;

View File

@@ -8,11 +8,11 @@
#include "nsIIDNService.h" #include "nsIIDNService.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsUnicodeScriptCodes.h"
#include "nsWeakReference.h" #include "nsWeakReference.h"
#include "unicode/uidna.h" #include "unicode/uidna.h"
#include "mozilla/Mutex.h" #include "mozilla/Mutex.h"
#include "mozilla/intl/UnicodeScriptCodes.h"
#include "mozilla/net/IDNBlocklistUtils.h" #include "mozilla/net/IDNBlocklistUtils.h"
#include "nsString.h" #include "nsString.h"
@@ -147,8 +147,7 @@ class nsIDNService final : public nsIIDNService,
* For the "Moderately restrictive" profile, Latin is also allowed * For the "Moderately restrictive" profile, Latin is also allowed
* with other scripts except Cyrillic and Greek * with other scripts except Cyrillic and Greek
*/ */
bool illegalScriptCombo(mozilla::unicode::Script script, bool illegalScriptCombo(mozilla::intl::Script script, int32_t& savedScript);
int32_t& savedScript);
/** /**
* Convert a DNS label from ASCII to Unicode using IDNA2008 * Convert a DNS label from ASCII to Unicode using IDNA2008

View File

@@ -6,6 +6,6 @@ devtools/client/debugger/node_modules/
dom/tests/ajax/jquery/ dom/tests/ajax/jquery/
dom/tests/ajax/mochikit/ dom/tests/ajax/mochikit/
node_modules/ node_modules/
intl/components/src/UnicodeScriptCodes.h
intl/unicharutil/util/nsSpecialCasingData.cpp intl/unicharutil/util/nsSpecialCasingData.cpp
intl/unicharutil/util/nsUnicodePropertyData.cpp intl/unicharutil/util/nsUnicodePropertyData.cpp
intl/unicharutil/util/nsUnicodeScriptCodes.h