Bug 1925854 - Make gfxScriptItemizer support both 16-bit and 8-bit text 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
This commit is contained in:
@@ -122,6 +122,9 @@ static inline bool SameScript(Script runScript, Script currCharScript,
|
|||||||
}
|
}
|
||||||
|
|
||||||
gfxScriptItemizer::Run gfxScriptItemizer::Next() {
|
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 we've fallen off the end of the text, we're done */
|
||||||
if (scriptLimit >= textLength) {
|
if (scriptLimit >= textLength) {
|
||||||
return Run{};
|
return Run{};
|
||||||
@@ -136,11 +139,11 @@ gfxScriptItemizer::Run gfxScriptItemizer::Next() {
|
|||||||
Script sc;
|
Script sc;
|
||||||
uint32_t startOfChar = scriptLimit;
|
uint32_t startOfChar = scriptLimit;
|
||||||
|
|
||||||
ch = textPtr[scriptLimit];
|
ch = textIs8bit ? textPtr._1b[scriptLimit] : textPtr._2b[scriptLimit];
|
||||||
|
|
||||||
/* decode UTF-16 (may be surrogate pair) */
|
/* decode UTF-16 (may be surrogate pair) */
|
||||||
if (NS_IS_HIGH_SURROGATE(ch) && scriptLimit < textLength - 1) {
|
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)) {
|
if (NS_IS_LOW_SURROGATE(low)) {
|
||||||
ch = SURROGATE_TO_UCS4(ch, low);
|
ch = SURROGATE_TO_UCS4(ch, low);
|
||||||
scriptLimit += 1;
|
scriptLimit += 1;
|
||||||
|
|||||||
@@ -60,8 +60,21 @@ class gfxScriptItemizer {
|
|||||||
public:
|
public:
|
||||||
using Script = mozilla::intl::Script;
|
using Script = mozilla::intl::Script;
|
||||||
|
|
||||||
gfxScriptItemizer(const char16_t* aText, uint32_t aLength)
|
gfxScriptItemizer() = default;
|
||||||
: textPtr(aText), textLength(aLength) {}
|
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 {
|
struct Run {
|
||||||
uint32_t mOffset = 0;
|
uint32_t mOffset = 0;
|
||||||
@@ -83,8 +96,12 @@ class gfxScriptItemizer {
|
|||||||
Script scriptCode;
|
Script scriptCode;
|
||||||
};
|
};
|
||||||
|
|
||||||
const char16_t* const textPtr;
|
union {
|
||||||
const uint32_t textLength;
|
const char16_t* _2b;
|
||||||
|
const unsigned char* _1b;
|
||||||
|
} textPtr;
|
||||||
|
uint32_t textLength;
|
||||||
|
bool textIs8bit;
|
||||||
|
|
||||||
uint32_t scriptStart = 0;
|
uint32_t scriptStart = 0;
|
||||||
uint32_t scriptLimit = 0;
|
uint32_t scriptLimit = 0;
|
||||||
|
|||||||
@@ -2642,7 +2642,8 @@ void gfxFontGroup::InitTextRun(DrawTarget* aDrawTarget, gfxTextRun* aTextRun,
|
|||||||
|
|
||||||
// split into script runs so that script can potentially influence
|
// split into script runs so that script can potentially influence
|
||||||
// the font matching process below
|
// the font matching process below
|
||||||
gfxScriptItemizer scriptRuns(textPtr, aLength);
|
gfxScriptItemizer scriptRuns;
|
||||||
|
scriptRuns.SetText(textPtr, aLength);
|
||||||
|
|
||||||
while (gfxScriptItemizer::Run run = scriptRuns.Next()) {
|
while (gfxScriptItemizer::Run run = scriptRuns.Next()) {
|
||||||
if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Warning))) {
|
if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Warning))) {
|
||||||
|
|||||||
Reference in New Issue
Block a user