Bug 1945341 - Count characters more correctly for hyphenate-limit-chars thresholds. r=layout-reviewers,emilio
In particular, this avoids counting a combining mark at the end of the word as if it were a separate character. Differential Revision: https://phabricator.services.mozilla.com/D236467
This commit is contained in:
@@ -437,7 +437,11 @@ void nsLineBreaker::FindHyphenationPoints(nsHyphenator* aHyphenator,
|
||||
uint8_t mState;
|
||||
};
|
||||
AutoTArray<BreakInfo, 16> oldBreaks;
|
||||
for (uint32_t i = 0; i + 1 < string.Length(); ++i) {
|
||||
// Don't consider setting any breaks where i >= endLimit, as they will
|
||||
// definitely be too near the end of the word to be accepted.
|
||||
uint32_t endLimit =
|
||||
string.Length() - std::max<uint32_t>(1u, mHyphenateLimitEnd);
|
||||
for (uint32_t i = 0; i < string.Length(); ++i) {
|
||||
// Get current character, converting surrogate pairs to UCS4 for char
|
||||
// category lookup.
|
||||
uint32_t ch = string[i];
|
||||
@@ -470,8 +474,13 @@ void nsLineBreaker::FindHyphenationPoints(nsHyphenator* aHyphenator,
|
||||
break;
|
||||
}
|
||||
|
||||
// Don't accept any breaks until we're far enough into the word.
|
||||
if (length >= mHyphenateLimitStart && hyphens[i]) {
|
||||
// Don't accept any breaks until we're far enough into the word, or if
|
||||
// we're too near the end for it to possibly be accepted. (Note that the
|
||||
// check against endLimit is just an initial worst-case check that assumes
|
||||
// all the remaining characters are countable; if there are combining
|
||||
// marks, etc., in the trailing part of the word we may need to reset the
|
||||
// potential break later, after we've fully counted length.)
|
||||
if (hyphens[i] && length >= mHyphenateLimitStart && i < endLimit) {
|
||||
// Keep track of hyphen position and "countable" length of the word.
|
||||
oldBreaks.AppendElement(BreakInfo{i + 1, length, aBreakState[i + 1]});
|
||||
aBreakState[i + 1] = gfxTextRun::CompressedGlyph::FLAG_BREAK_TYPE_HYPHEN;
|
||||
@@ -482,7 +491,6 @@ void nsLineBreaker::FindHyphenationPoints(nsHyphenator* aHyphenator,
|
||||
++i;
|
||||
}
|
||||
}
|
||||
++length; // Account for the last character (not counted by the loop above).
|
||||
|
||||
if (length < mHyphenateLimitWord) {
|
||||
// After discounting combining marks, punctuation, controls, etc., the word
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<div lang="hi" style="width:0; hyphens:manual;">
|
||||
सभी मनु­ष्यों को गौरव और अधि­का­रों के मा­म­ले में जन्म­जात स्व­त­न्त्र­ता और समा­न­ता प्रा­प्त है ।
|
||||
सभी मनु­ष्यों को गौरव और अधि­का­रों के मामले में जन्म­जात स्व­त­न्त्र­ता और समा­न­ता प्रा­प्त है ।
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<div lang="kn" style="width:0; hyphens:manual;">
|
||||
ಎಲ್ಲಾ ಮಾ­ನ­ವ­ರೂ ಸ್ವ­ತಂ­ತ್ರ­ರಾ­ಗಿ­ಯೇ ಜನಿ­ಸಿ­ದ್ದಾ­ರೆ. ಹಾಗೂ ಘನತೆ ಮತ್ತು ಹಕ್ಕು­ಗ­ಳ­ಲ್ಲಿ ಸಮಾ­ನ­ರಾ­ಗಿ­ದ್ದಾ­ರೆ.
|
||||
ಎಲ್ಲಾ ಮಾ­ನ­ವ­ರೂ ಸ್ವ­ತಂ­ತ್ರ­ರಾ­ಗಿ­ಯೇ ಜನಿ­ಸಿ­ದ್ದಾರೆ. ಹಾಗೂ ಘನತೆ ಮತ್ತು ಹಕ್ಕು­ಗ­ಳ­ಲ್ಲಿ ಸಮಾ­ನ­ರಾ­ಗಿ­ದ್ದಾರೆ.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<div lang="ml" style="width:0; hyphens:manual;">
|
||||
മനു­ഷ്യ­രെ­ല്ലാ­വ­രും തുല്യാ­വ­കാ­ശ­ങ്ങ­ളോ­ടും അന്ത­സ്സോ­ടും സ്വാ­ത­ന്ത്ര്യ­ത്തോ­ടും­കൂ­ടി ജനി­ച്ചി­ട്ടു­ള്ള­വ­രാ­ണ്.
|
||||
മനു­ഷ്യ­രെ­ല്ലാ­വ­രും തുല്യാ­വ­കാ­ശ­ങ്ങ­ളോ­ടും അന്ത­സ്സോ­ടും സ്വാ­ത­ന്ത്ര്യ­ത്തോ­ടും­കൂ­ടി ജനി­ച്ചി­ട്ടു­ള്ള­വ­രാണ്.
|
||||
|
||||
Reference in New Issue
Block a user