diff options
author | claireho <chinglanho@gmail.com> | 2010-07-26 16:48:56 -0700 |
---|---|---|
committer | claireho <chinglanho@gmail.com> | 2010-07-26 17:10:24 -0700 |
commit | abb274d1eae5637eee465c5618aac1266d8ce695 (patch) | |
tree | 2f176bcedee4e121c854a0c21c673fe1fb3a35ca | |
parent | 9b79df2264b8a55f37c294de5b365203680c0773 (diff) | |
download | external_webkit-abb274d1eae5637eee465c5618aac1266d8ce695.zip external_webkit-abb274d1eae5637eee465c5618aac1266d8ce695.tar.gz external_webkit-abb274d1eae5637eee465c5618aac1266d8ce695.tar.bz2 |
Bug 2811402:Fixed parenthesis are not mirrored correctly in bidi layout.
Ported the webkit fixes from http://trac.webkit.org/changeset/62965.
Harfbuzz does not do mirroring, so we iterate each character
in the string and mirror it if needed before passing the
string to harfbuzz for shaping.
Change-Id: Ifee1035f96e4e82a5a2641b57dd839cec3427b59
-rw-r--r-- | WebCore/platform/graphics/android/FontAndroid.cpp | 33 |
1 files changed, 31 insertions, 2 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. |