Commit 33af59cf authored by kojii's avatar kojii Committed by Commit bot

Soft hyphens with long suffix may add unnecessary hyphens

This patch fixes unnecessary hyphens appear when soft hyphens are used
and its suffix is too long to fit.

In that case, m_lineBreak is still pointing to the last break
opportunity, which is the beginning of the line, and the character
before is on the previous line.

Also, different code doing the same logic for when the word with soft
hyphen is at the end of a text node and is not are unified.

BUG=627715

Review-Url: https://codereview.chromium.org/2167093002
Cr-Commit-Position: refs/heads/master@{#407025}
parent 89eb8019
...@@ -10,7 +10,7 @@ div { ...@@ -10,7 +10,7 @@ div {
} }
</style> </style>
</head> </head>
<div>M M-M-M-M-M-M-M-M-M-M-M-M-M-M-</div> <div>M-M-M-M-M-M-M-M-M-M-M-M-M-M-M-</div>
<script> <script>
document.execCommand('SelectAll') document.execCommand('SelectAll')
</script> </script>
<!DOCTYPE html>
<style>
div {
width: 10ch;
border: solid;
}
</style>
<p>H should be followed by a hyphen, and x should not.</p>
<div>xxxxxxxxxxxxxxxH-<br>xxxx</div>
<div>xxxxxH-<br>xxxxxxxxxxxxxxxH-<br>xxxx</div>
<div>xxxxxH-<br>xxxxxH-<br>xxxxxxx</div>
<div>xxxxxH-<br>xxxxxxxxxxxxxxxx</div>
<div>xxxxxH-<br>xxxxxxxxxxxxxxxx xxxxxxx</div>
<!DOCTYPE html>
<style>
div {
width: 10ch;
border: solid;
}
</style>
<p>H should be followed by a hyphen, and x should not.</p>
<div>xxxxxxxxxxxxxxxH&shy;xxxx</div>
<div>xxxxxH&shy;xxxxxxxxxxxxxxxH&shy;xxxx</div>
<div>xxxxxH&shy;xxxxxH&shy;xxxxxxx</div>
<div>xxxxxH&shy;xxxxxxxxxxxxxxxx</div>
<div>xxxxxH&shy;xxxxxxxxxxxxxxxx xxxxxxx</div>
...@@ -123,6 +123,7 @@ private: ...@@ -123,6 +123,7 @@ private:
bool rewindToFirstMidWordBreak(LineLayoutText, const ComputedStyle&, const Font&, bool breakAll, WordMeasurement&); bool rewindToFirstMidWordBreak(LineLayoutText, const ComputedStyle&, const Font&, bool breakAll, WordMeasurement&);
bool rewindToMidWordBreak(LineLayoutText, const ComputedStyle&, const Font&, bool breakAll, WordMeasurement&); bool rewindToMidWordBreak(LineLayoutText, const ComputedStyle&, const Font&, bool breakAll, WordMeasurement&);
bool hyphenate(LineLayoutText, const ComputedStyle&, const Font&, const Hyphenation&, float lastSpaceWordSpacing, WordMeasurement&); bool hyphenate(LineLayoutText, const ComputedStyle&, const Font&, const Hyphenation&, float lastSpaceWordSpacing, WordMeasurement&);
bool isBreakAtSoftHyphen() const;
InlineBidiResolver& m_resolver; InlineBidiResolver& m_resolver;
...@@ -697,6 +698,13 @@ ALWAYS_INLINE bool BreakingContext::hyphenate(LineLayoutText text, ...@@ -697,6 +698,13 @@ ALWAYS_INLINE bool BreakingContext::hyphenate(LineLayoutText text,
font.getCharacterRange(run, 0, prefixLength).width() + hyphenWidth); font.getCharacterRange(run, 0, prefixLength).width() + hyphenWidth);
} }
ALWAYS_INLINE bool BreakingContext::isBreakAtSoftHyphen() const
{
return m_lineBreak != m_resolver.position()
? m_lineBreak.previousInSameNode() == softHyphenCharacter
: m_current.previousInSameNode() == softHyphenCharacter;
}
inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool& hyphenated) inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool& hyphenated)
{ {
if (!m_current.offset()) if (!m_current.offset())
...@@ -983,9 +991,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool ...@@ -983,9 +991,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
} }
m_width.addUncommittedWidth(wordMeasurement.width); m_width.addUncommittedWidth(wordMeasurement.width);
} }
if (!hyphenated if (!hyphenated && isBreakAtSoftHyphen() && !disableSoftHyphen) {
&& m_lineBreak.previousInSameNode() == softHyphenCharacter
&& !disableSoftHyphen) {
hyphenated = true; hyphenated = true;
m_atEnd = true; m_atEnd = true;
} }
...@@ -1081,7 +1087,7 @@ inline bool BreakingContext::canBreakAtWhitespace(bool breakWords, WordMeasureme ...@@ -1081,7 +1087,7 @@ inline bool BreakingContext::canBreakAtWhitespace(bool breakWords, WordMeasureme
m_lineInfo.setPreviousLineBrokeCleanly(true); m_lineInfo.setPreviousLineBrokeCleanly(true);
wordMeasurement.endOffset = m_lineBreak.offset(); wordMeasurement.endOffset = m_lineBreak.offset();
} }
if (m_lineBreak.getLineLayoutItem() && m_lineBreak.offset() && m_lineBreak.getLineLayoutItem().isText() && LineLayoutText(m_lineBreak.getLineLayoutItem()).textLength() && LineLayoutText(m_lineBreak.getLineLayoutItem()).characterAt(m_lineBreak.offset() - 1) == softHyphenCharacter && !disableSoftHyphen) if (isBreakAtSoftHyphen() && !disableSoftHyphen)
hyphenated = true; hyphenated = true;
if (m_lineBreak.offset() && m_lineBreak.offset() != (unsigned)wordMeasurement.endOffset && !wordMeasurement.width) { if (m_lineBreak.offset() && m_lineBreak.offset() != (unsigned)wordMeasurement.endOffset && !wordMeasurement.width) {
if (charWidth) { if (charWidth) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment