diff options
-rw-r--r-- | WebCore/platform/graphics/android/FontAndroid.cpp | 33 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/LayerAndroid.cpp | 21 | ||||
-rw-r--r-- | WebCore/platform/graphics/android/LayerAndroid.h | 1 | ||||
-rw-r--r-- | WebCore/platform/text/android/HyphenationAndroid.cpp | 60 |
4 files changed, 80 insertions, 35 deletions
diff --git a/WebCore/platform/graphics/android/FontAndroid.cpp b/WebCore/platform/graphics/android/FontAndroid.cpp index 71d66e6..5bcb8d5 100644 --- a/WebCore/platform/graphics/android/FontAndroid.cpp +++ b/WebCore/platform/graphics/android/FontAndroid.cpp @@ -47,6 +47,7 @@ #include <unicode/uchar.h> #include <wtf/OwnArrayPtr.h> #include <wtf/OwnPtr.h> +#include <wtf/unicode/Unicode.h> #endif using namespace android; @@ -323,10 +324,20 @@ public: m_item.face = 0; m_item.font = allocHarfbuzzFont(); - m_item.string = m_run.characters(); - m_item.stringLength = m_run.length(); m_item.item.bidiLevel = m_run.rtl(); + int length = m_run.length(); + m_item.stringLength = length; + + if (!m_item.item.bidiLevel) + m_item.string = m_run.characters(); + else { + // Assume mirrored character is in the same Unicode multilingual plane as the original one. + UChar* string = new UChar[length]; + mirrorCharacters(string, m_run.characters(), length); + m_item.string = string; + } + reset(); } @@ -335,6 +346,8 @@ public: fastFree(m_item.font); deleteGlyphArrays(); delete[] m_item.log_clusters; + if (m_item.item.bidiLevel) + delete[] m_item.string; } void reset() @@ -624,6 +637,22 @@ private: m_offsetX += m_pixelWidth; } + void mirrorCharacters(UChar* destination, const UChar* source, int length) const + { + int position = 0; + bool error = false; + // Iterate characters in source and mirror character if needed. + while (position < length) { + UChar32 character; + int nextPosition = position; + U16_NEXT(source, nextPosition, length, character); + character = u_charMirror(character); + U16_APPEND(destination, position, length, character, error); + ASSERT(!error); + position = nextPosition; + } + } + const Font* const m_font; HB_ShaperItem m_item; uint16_t* m_glyphs16; // A vector of 16-bit glyph ids. diff --git a/WebCore/platform/graphics/android/LayerAndroid.cpp b/WebCore/platform/graphics/android/LayerAndroid.cpp index b80171e..86400c2 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.cpp +++ b/WebCore/platform/graphics/android/LayerAndroid.cpp @@ -111,6 +111,27 @@ LayerAndroid::LayerAndroid(const LayerAndroid& layer) : SkLayer(layer), gDebugLayerAndroidInstances++; } +LayerAndroid::LayerAndroid(SkPicture* picture) : SkLayer(), + m_isRootLayer(true), + m_haveClip(false), + m_doRotation(false), + m_isFixed(false), + m_recordingPicture(picture), + m_foregroundPicture(0), + m_contentsImage(0), + m_extra(0), + m_uniqueId(-1) +{ + m_angleTransform = 0; + m_translation.set(0, 0); + m_scale.set(1, 1); + m_backgroundColor = 0; + m_foregroundClip.setEmpty(); + m_foregroundLocation.set(0, 0); + SkSafeRef(m_recordingPicture); + gDebugLayerAndroidInstances++; +} + LayerAndroid::~LayerAndroid() { removeChildren(); diff --git a/WebCore/platform/graphics/android/LayerAndroid.h b/WebCore/platform/graphics/android/LayerAndroid.h index 2c11958..b74a8c8 100644 --- a/WebCore/platform/graphics/android/LayerAndroid.h +++ b/WebCore/platform/graphics/android/LayerAndroid.h @@ -77,6 +77,7 @@ class LayerAndroid : public SkLayer { public: LayerAndroid(bool isRootLayer); LayerAndroid(const LayerAndroid& layer); + LayerAndroid(SkPicture*); virtual ~LayerAndroid(); static int instancesCount(); 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; } |