Skip to content

Commit

Permalink
Bug 1719554 - Unify unicode::Script as intl::Script; r=platform-i18n-…
Browse files Browse the repository at this point in the history
…reviewers,gregtatum

Differential Revision: https://phabricator.services.mozilla.com/D132278
  • Loading branch information
dminor committed Dec 3, 2021
1 parent 3f30502 commit 8f1fd30
Show file tree
Hide file tree
Showing 31 changed files with 187 additions and 249 deletions.
2 changes: 1 addition & 1 deletion .clang-format-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions gfx/thebes/gfxCoreTextShaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions gfx/thebes/gfxFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
Expand Down
10 changes: 5 additions & 5 deletions gfx/thebes/gfxFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -37,7 +38,6 @@
#include "nsString.h"
#include "nsTArray.h"
#include "nsTHashtable.h"
#include "nsUnicodeScriptCodes.h"
#include "nscore.h"

// Only required for function bodys
Expand Down Expand Up @@ -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 };

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions gfx/thebes/gfxFontEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions gfx/thebes/gfxFontEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions gfx/thebes/gfxHarfBuzzShaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions gfx/thebes/gfxPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion gfx/thebes/gfxPlatformFontList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]"
Expand Down
2 changes: 1 addition & 1 deletion gfx/thebes/gfxPlatformFontList.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions gfx/thebes/gfxScriptItemizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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();
}
Expand All @@ -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)) {
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions gfx/thebes/gfxScriptItemizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 4 additions & 5 deletions gfx/thebes/gfxTextRun.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
#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"
#include "nsTHashSet.h"
#include "nsTextFrameUtils.h"
#include "DrawMode.h"
#include "harfbuzz/hb.h"
#include "nsUnicodeScriptCodes.h"
#include "nsColor.h"
#include "nsFrameList.h"
#include "X11UndefineNone.h"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
Expand All @@ -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];
};

Expand Down
Loading

0 comments on commit 8f1fd30

Please sign in to comment.