Skip to content

Commit

Permalink
Bug 1925854 - Make gfxScriptItemizer support both 16-bit and 8-bit te…
Browse files Browse the repository at this point in the history
…xt buffers. r=gfx-reviewers,lsalzman

This does not change behavior yet, just prepares for the next patch
which will actually use the 8-bit version.

Differential Revision: https://phabricator.services.mozilla.com/D226286
  • Loading branch information
jfkthame committed Oct 21, 2024
1 parent 929f034 commit 7651294
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
7 changes: 5 additions & 2 deletions gfx/thebes/gfxScriptItemizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ static inline bool SameScript(Script runScript, Script currCharScript,
}

gfxScriptItemizer::Run gfxScriptItemizer::Next() {
MOZ_ASSERT(textLength == 0 || (textIs8bit && textPtr._1b) ||
(!textIs8bit && textPtr._2b));

/* if we've fallen off the end of the text, we're done */
if (scriptLimit >= textLength) {
return Run{};
Expand All @@ -136,11 +139,11 @@ gfxScriptItemizer::Run gfxScriptItemizer::Next() {
Script sc;
uint32_t startOfChar = scriptLimit;

ch = textPtr[scriptLimit];
ch = textIs8bit ? textPtr._1b[scriptLimit] : textPtr._2b[scriptLimit];

/* decode UTF-16 (may be surrogate pair) */
if (NS_IS_HIGH_SURROGATE(ch) && scriptLimit < textLength - 1) {
uint32_t low = textPtr[scriptLimit + 1];
uint32_t low = textPtr._2b[scriptLimit + 1];
if (NS_IS_LOW_SURROGATE(low)) {
ch = SURROGATE_TO_UCS4(ch, low);
scriptLimit += 1;
Expand Down
25 changes: 21 additions & 4 deletions gfx/thebes/gfxScriptItemizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,21 @@ class gfxScriptItemizer {
public:
using Script = mozilla::intl::Script;

gfxScriptItemizer(const char16_t* aText, uint32_t aLength)
: textPtr(aText), textLength(aLength) {}
gfxScriptItemizer() = default;
gfxScriptItemizer(const gfxScriptItemizer& aOther) = delete;
gfxScriptItemizer(gfxScriptItemizer&& aOther) = delete;

void SetText(const char16_t* aText, uint32_t aLength) {
textPtr._2b = aText;
textLength = aLength;
textIs8bit = false;
}

void SetText(const unsigned char* aText, uint32_t aLength) {
textPtr._1b = aText;
textLength = aLength;
textIs8bit = true;
}

struct Run {
uint32_t mOffset = 0;
Expand All @@ -83,8 +96,12 @@ class gfxScriptItemizer {
Script scriptCode;
};

const char16_t* const textPtr;
const uint32_t textLength;
union {
const char16_t* _2b;
const unsigned char* _1b;
} textPtr;
uint32_t textLength;
bool textIs8bit;

uint32_t scriptStart = 0;
uint32_t scriptLimit = 0;
Expand Down
3 changes: 2 additions & 1 deletion gfx/thebes/gfxTextRun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2642,7 +2642,8 @@ void gfxFontGroup::InitTextRun(DrawTarget* aDrawTarget, gfxTextRun* aTextRun,

// split into script runs so that script can potentially influence
// the font matching process below
gfxScriptItemizer scriptRuns(textPtr, aLength);
gfxScriptItemizer scriptRuns;
scriptRuns.SetText(textPtr, aLength);

while (gfxScriptItemizer::Run run = scriptRuns.Next()) {
if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Warning))) {
Expand Down

0 comments on commit 7651294

Please sign in to comment.