diff options
author | Shimeng (Simon) Wang <swang@google.com> | 2010-07-27 11:27:44 -0700 |
---|---|---|
committer | Shimeng (Simon) Wang <swang@google.com> | 2010-07-27 14:01:36 -0700 |
commit | f062339f766a214d9e16be4e928264d8bcfffeee (patch) | |
tree | 8e80a9193f4ecdd7e3cd23465e3952f24111f266 /WebCore/platform/text | |
parent | 767966411f0c19c445f74d2ff90ab9490c290026 (diff) | |
download | external_webkit-f062339f766a214d9e16be4e928264d8bcfffeee.zip external_webkit-f062339f766a214d9e16be4e928264d8bcfffeee.tar.gz external_webkit-f062339f766a214d9e16be4e928264d8bcfffeee.tar.bz2 |
Put the webkit version into android code base.
The original webkit change is:
http://trac.webkit.org/changeset/64087
Change-Id: Ide7141ffec0a8a37f333c06bddabe3703d79af54
Diffstat (limited to 'WebCore/platform/text')
-rw-r--r-- | WebCore/platform/text/android/HyphenationAndroid.cpp | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/WebCore/platform/text/android/HyphenationAndroid.cpp b/WebCore/platform/text/android/HyphenationAndroid.cpp index dfc614a..00ebd46 100644 --- a/WebCore/platform/text/android/HyphenationAndroid.cpp +++ b/WebCore/platform/text/android/HyphenationAndroid.cpp @@ -23,17 +23,14 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#define LOG_TAG "hyphenation_android" - #include "config.h" #include "Hyphenation.h" -#include "NotImplemented.h" -#include <utils/AssetManager.h> -#include "wtf/text/CString.h" -#include "wtf/text/WTFString.h" // For external hyphenation library. #include "hyphen.h" +#include <utils/AssetManager.h> +#include <wtf/text/CString.h> +#include <wtf/text/WTFString.h> extern android::AssetManager* globalAssetManager(); @@ -41,41 +38,37 @@ using namespace WTF; namespace WebCore { -static HyphenDict* getHyphenDict() { - static HyphenDict *dict = 0; - static bool isDictInitialized = false; - if (!isDictInitialized && !dict) { - isDictInitialized = true; - android::AssetManager* am = globalAssetManager(); - // Only support English for now. - android::Asset* a = am->open("webkit/hyph_en_US.dic", - android::Asset::ACCESS_BUFFER); - if (!a) { - LOGW("asset webkit/hyph_en_US.dic not found!"); - return 0; - } - LOGD("dictionary length is %d", a->getLength()); - const CString dictContents = String(static_cast<const char*>(a->getBuffer(false)), - a->getLength()).utf8(); - dict = hnj_hyphen_load_from_buffer(dictContents.data(), - dictContents.length()); - delete a; +static HyphenDict* loadHyphenationDictionary() +{ + android::AssetManager* am = globalAssetManager(); + // Only support English for now. + android::Asset* a = am->open("webkit/hyph_en_US.dic", + android::Asset::ACCESS_BUFFER); + if (!a) { + // Asset webkit/hyph_en_US.dic not found! + return 0; } + const CString dictContents = String(static_cast<const char*>(a->getBuffer(false)), + a->getLength()).utf8(); + HyphenDict* dict = hnj_hyphen_load_from_buffer(dictContents.data(), + dictContents.length()); + delete a; + return dict; } size_t lastHyphenLocation(const UChar* characters, size_t length, size_t beforeIndex) { - static const size_t MIN_WORD_LEN = 5; - static const size_t MAX_WORD_LEN = 100; - if (beforeIndex <= 0 || length < MIN_WORD_LEN || length > MAX_WORD_LEN) + static const size_t minWordLen = 5; + static const size_t maxWordLen = 100; + if (beforeIndex <= 0 || length < minWordLen || length > maxWordLen) return 0; - HyphenDict *dict = getHyphenDict(); + static HyphenDict* dict = loadHyphenationDictionary(); if (!dict) return 0; - char word[MAX_WORD_LEN]; + char word[maxWordLen]; for (size_t i = 0; i < length; ++i) { const UChar ch = characters[i]; // Only English for now. @@ -88,13 +81,14 @@ size_t lastHyphenLocation(const UChar* characters, size_t length, size_t beforeI word[i] = ch; } - static const int EXTRA_BUFFER = 5; - char hyphens[MAX_WORD_LEN + EXTRA_BUFFER]; - if (hnj_hyphen_hyphenate(dict, word, length, hyphens) == 0) + static const int extraBuffer = 5; + char hyphens[maxWordLen + extraBuffer]; + if (!hnj_hyphen_hyphenate(dict, word, length, hyphens)) { for (size_t i = beforeIndex - 1; i > 0; --i) { if (hyphens[i] & 1) return i + 1; } + } return 0; } |