diff options
author | Raph Levien <raph@google.com> | 2014-05-12 15:10:30 -0700 |
---|---|---|
committer | Raph Levien <raph@google.com> | 2014-05-14 15:56:05 -0700 |
commit | d231a4b0b1d482c7ae7717b048112e1fe5d0f5a9 (patch) | |
tree | ca496d1b5dde30fc435c61b5d0ae4741a68695e9 /libs/minikin | |
parent | 0a689bb956183beebe7d59fccb226a82680f265a (diff) | |
download | android_frameworks_minikin-d231a4b0b1d482c7ae7717b048112e1fe5d0f5a9.tar.gz android_frameworks_minikin-d231a4b0b1d482c7ae7717b048112e1fe5d0f5a9.tar.bz2 android_frameworks_minikin-d231a4b0b1d482c7ae7717b048112e1fe5d0f5a9.zip |
Initial BiDi support
This patch contains a very basic implementation of BiDi. It respects the
BiDi flags passed in as an explicit parameter (through the
"-minikin-bidi" pseudo-CSS property), but doesn't yet do its own BiDi
run detection. It also takes some shortcuts (marked as TODO) that are
based on reasonable assumptions of the current font stack, but not
universally valid.
Even with these shortcomings, it seems to display RTL text from TextView
correctly.
Change-Id: I223433923c4eb06f90c0327e86bfbe0aff71d4f5
Diffstat (limited to 'libs/minikin')
-rw-r--r-- | libs/minikin/CssParse.cpp | 1 | ||||
-rw-r--r-- | libs/minikin/Layout.cpp | 13 |
2 files changed, 12 insertions, 2 deletions
diff --git a/libs/minikin/CssParse.cpp b/libs/minikin/CssParse.cpp index d4de23b..5bb6949 100644 --- a/libs/minikin/CssParse.cpp +++ b/libs/minikin/CssParse.cpp @@ -41,6 +41,7 @@ CssTag parseTag(const string str, size_t off, size_t len) { if (strEqC(str, off, len, "font-style")) return fontStyle; } else if (c == '-') { if (strEqC(str, off, len, "-minikin-hinting")) return minikinHinting; + if (strEqC(str, off, len, "-minikin-bidi")) return minikinBidi; } return unknown; } diff --git a/libs/minikin/Layout.cpp b/libs/minikin/Layout.cpp index 08365b3..3a0be6a 100644 --- a/libs/minikin/Layout.cpp +++ b/libs/minikin/Layout.cpp @@ -19,10 +19,12 @@ #include <string> #include <vector> +#include <algorithm> #include <fstream> #include <iostream> // for debugging #include <stdio.h> // ditto +#include <unicode/ubidi.h> #include <hb-icu.h> #include "MinikinInternal.h" @@ -91,7 +93,6 @@ void Layout::init() { } void Layout::setFontCollection(const FontCollection *collection) { - ALOGD("setFontCollection(%p)", collection); mCollection = collection; } @@ -290,6 +291,11 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { MinikinPaint paint; double size = mProps.value(fontSize).getFloatValue(); paint.size = size; + int bidiFlags = mProps.hasTag(minikinBidi) ? mProps.value(minikinBidi).getIntValue() : 0; + bool isRtl = (bidiFlags & 1) != 0; // TODO: do real bidi algo + if (isRtl) { + std::reverse(items.begin(), items.end()); + } mGlyphs.clear(); mFaces.clear(); @@ -315,6 +321,9 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { hb_font_set_ppem(hbFont, size, size); hb_font_set_scale(hbFont, HBFloatToFixed(size), HBFloatToFixed(size)); + // TODO: if there are multiple scripts within a font in an RTL run, + // we need to reorder those runs. This is unlikely with our current + // font stack, but should be done for correctness. ssize_t srunend; for (ssize_t srunstart = run.start; srunstart < run.end; srunstart = srunend) { srunend = srunstart; @@ -322,7 +331,7 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { hb_buffer_reset(buffer); hb_buffer_set_script(buffer, script); - hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); + hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR); hb_buffer_add_utf16(buffer, buf, nchars, srunstart, srunend - srunstart); hb_shape(hbFont, buffer, NULL, 0); unsigned int numGlyphs; |