Skip to content

Commit

Permalink
Bug 1925854 - Run all text through gfxScriptItemizer, even if purely …
Browse files Browse the repository at this point in the history
…8-bit. r=gfx-reviewers,lsalzman

This is important for script-based font selection, as it avoids forcing
Latin script on 8-bit text runs that contain only Common characters such
as punctuation, and may be better rendered according to the context
language.

By itself this does not change user-visible behavior, but it will affect
how CSS generic font families are resolved in some cases once we implement
bug 1748636.

Differential Revision: https://phabricator.services.mozilla.com/D226287
  • Loading branch information
jfkthame committed Oct 21, 2024
1 parent 7651294 commit 2c8012c
Showing 1 changed file with 35 additions and 50 deletions.
85 changes: 35 additions & 50 deletions gfx/thebes/gfxTextRun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2601,78 +2601,63 @@ void gfxFontGroup::InitTextRun(DrawTarget* aDrawTarget, gfxTextRun* aTextRun,
do {
redo = false;

// split into script runs so that script can potentially influence
// the font matching process below
gfxScriptItemizer scriptRuns;
const char16_t* textPtr = nullptr;

if (sizeof(T) == sizeof(uint8_t) && !transformedString) {
scriptRuns.SetText(aString, aLength);
} else {
if (transformedString) {
textPtr = transformedString.get();
} else {
// typecast to avoid compilation error for the 8-bit version,
// even though this is dead code in that case
textPtr = reinterpret_cast<const char16_t*>(aString);
}

scriptRuns.SetText(textPtr, aLength);
}

while (gfxScriptItemizer::Run run = scriptRuns.Next()) {
if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Warning))) {
nsAutoCString lang;
mLanguage->ToUTF8String(lang);
nsAutoCString str((const char*)aString, aLength);
nsAutoCString styleString;
mStyle.style.ToString(styleString);
auto defaultLanguageGeneric = GetDefaultGeneric(mLanguage);
MOZ_LOG(
log, LogLevel::Warning,
("(%s) fontgroup: [%s] default: %s lang: %s script: %d "
"len %d weight: %g stretch: %g%% style: %s size: %6.2f %zu-byte "
"TEXTRUN [%s] ENDTEXTRUN\n",
"len %d weight: %g stretch: %g%% style: %s size: %6.2f "
"%zu-byte TEXTRUN [%s] ENDTEXTRUN\n",
(mStyle.systemFont ? "textrunui" : "textrun"),
FamilyListToString(mFamilyList).get(),
(defaultLanguageGeneric == StyleGenericFontFamily::Serif
? "serif"
: (defaultLanguageGeneric == StyleGenericFontFamily::SansSerif
? "sans-serif"
: "none")),
lang.get(), static_cast<int>(Script::LATIN), aLength,
lang.get(), static_cast<int>(run.mScript), run.mLength,
mStyle.weight.ToFloat(), mStyle.stretch.ToFloat(),
styleString.get(), mStyle.size, sizeof(T), str.get()));
}

// the text is still purely 8-bit; bypass the script-run itemizer
// and treat it as a single Latin run
InitScriptRun(aDrawTarget, aTextRun, aString, 0, aLength, Script::LATIN,
aMFR);
} else {
const char16_t* textPtr;
if (transformedString) {
textPtr = transformedString.get();
} else {
// typecast to avoid compilation error for the 8-bit version,
// even though this is dead code in that case
textPtr = reinterpret_cast<const char16_t*>(aString);
}

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

while (gfxScriptItemizer::Run run = scriptRuns.Next()) {
if (MOZ_UNLIKELY(MOZ_LOG_TEST(log, LogLevel::Warning))) {
nsAutoCString lang;
mLanguage->ToUTF8String(lang);
nsAutoCString styleString;
mStyle.style.ToString(styleString);
auto defaultLanguageGeneric = GetDefaultGeneric(mLanguage);
MOZ_LOG(log, LogLevel::Warning,
("(%s) fontgroup: [%s] default: %s lang: %s script: %d "
"len %d weight: %g stretch: %g%% style: %s size: %6.2f "
"%zu-byte TEXTRUN [%s] ENDTEXTRUN\n",
(mStyle.systemFont ? "textrunui" : "textrun"),
FamilyListToString(mFamilyList).get(),
(defaultLanguageGeneric == StyleGenericFontFamily::Serif
? "serif"
: (defaultLanguageGeneric ==
StyleGenericFontFamily::SansSerif
? "sans-serif"
: "none")),
lang.get(), static_cast<int>(run.mScript), run.mLength,
mStyle.weight.ToFloat(), mStyle.stretch.ToFloat(),
styleString.get(), mStyle.size, sizeof(T),
NS_ConvertUTF16toUTF8(textPtr + run.mOffset, run.mLength)
styleString.get(), mStyle.size, sizeof(T),
textPtr
? NS_ConvertUTF16toUTF8(textPtr + run.mOffset, run.mLength)
.get()
: nsPromiseFlatCString(
nsDependentCSubstring(
reinterpret_cast<const char*>(aString) + run.mOffset,
run.mLength))
.get()));
}
}

if (textPtr) {
InitScriptRun(aDrawTarget, aTextRun, textPtr + run.mOffset, run.mOffset,
run.mLength, run.mScript, aMFR);
} else {
InitScriptRun(aDrawTarget, aTextRun, aString + run.mOffset, run.mOffset,
run.mLength, run.mScript, aMFR);
}
}

Expand Down

0 comments on commit 2c8012c

Please sign in to comment.