diff options
author | Shimeng (Simon) Wang <swang@google.com> | 2010-10-28 17:14:27 -0700 |
---|---|---|
committer | Shimeng (Simon) Wang <swang@google.com> | 2010-10-29 10:40:05 -0700 |
commit | 5a2ec43c8db3d26ffadd4e5ffd6ff1b76844bab6 (patch) | |
tree | 8ddb3a8b0fc043db294eba02ae0ea903ef4a287b /WebCore/platform/text | |
parent | 279165f3ff7e77ac27d38b497b670a3b3cea5c3f (diff) | |
download | external_webkit-5a2ec43c8db3d26ffadd4e5ffd6ff1b76844bab6.zip external_webkit-5a2ec43c8db3d26ffadd4e5ffd6ff1b76844bab6.tar.gz external_webkit-5a2ec43c8db3d26ffadd4e5ffd6ff1b76844bab6.tar.bz2 |
Enhance auto hyphenation.
1. Bypass leading white spaces, since webkit does pass them down.
2. Return better hyphenation point, since previously it's more
aggressive and causes display issue in Google books.
issue: 2672163
Change-Id: I8ae47f7c553f533f752d6f7c697cf2fffd421e5b
Diffstat (limited to 'WebCore/platform/text')
-rw-r--r-- | WebCore/platform/text/android/HyphenationAndroid.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/WebCore/platform/text/android/HyphenationAndroid.cpp b/WebCore/platform/text/android/HyphenationAndroid.cpp index e8ba5ef..cff0a66 100644 --- a/WebCore/platform/text/android/HyphenationAndroid.cpp +++ b/WebCore/platform/text/android/HyphenationAndroid.cpp @@ -75,6 +75,7 @@ size_t lastHyphenLocation(const UChar* characters, size_t length, size_t beforeI return 0; char word[maxWordLen]; + int wordLength = 0; for (size_t i = 0; i < length; ++i) { const UChar ch = characters[i]; // Only English for now. @@ -82,17 +83,24 @@ size_t lastHyphenLocation(const UChar* characters, size_t length, size_t beforeI // detection or rely on the langAttr in the html element. Though // seems right now the langAttr is not used or quite implemented in // webkit. - if (!isASCIIAlpha(ch)) + if (!isASCIIAlpha(ch)) { + // Bypass leading spaces. + if (isASCIISpace(ch) && !wordLength) + continue; return 0; - word[i] = ch; + } + word[wordLength++] = ch; } + if (wordLength < minWordLen) + return 0; static const int extraBuffer = 5; + const int leadingSpacesCount = length - wordLength; char hyphens[maxWordLen + extraBuffer]; - if (!hnj_hyphen_hyphenate(dict, word, length, hyphens)) { - for (size_t i = beforeIndex - 1; i > 0; --i) { + if (!hnj_hyphen_hyphenate(dict, word, wordLength, hyphens)) { + for (size_t i = beforeIndex - 2 - leadingSpacesCount; i > 0; --i) { if (hyphens[i] & 1) - return i + 1; + return i + 1 + leadingSpacesCount; } } |