summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2015-06-26 11:15:17 -0700
committerRaph Levien <raph@google.com>2015-06-26 11:15:17 -0700
commite8721b2d293ba1a0e5d92a066aa9aa15807357cc (patch)
tree2ec90ae675558c1372dfd5936632384dbcc89619
parenta6f8bf6f530f80b00a7cc64605667dd1d75a971c (diff)
downloadandroid_frameworks_minikin-e8721b2d293ba1a0e5d92a066aa9aa15807357cc.tar.gz
android_frameworks_minikin-e8721b2d293ba1a0e5d92a066aa9aa15807357cc.tar.bz2
android_frameworks_minikin-e8721b2d293ba1a0e5d92a066aa9aa15807357cc.zip
Disable letterspacing for connected scripts
The appearance of letterspacing with scripts with cursive connections is poor, so we simply disable letterspacing for those scripts. There may be some cases where some form of letterspacing is desirable, but this gives the highest likelihood that the final result will be good without requiring additional work from clients. Bug: 21935803 Change-Id: Ie25266249ac3a2605aa89ef5132e8edbe3a06d35
-rw-r--r--libs/minikin/Layout.cpp47
1 files changed, 38 insertions, 9 deletions
diff --git a/libs/minikin/Layout.cpp b/libs/minikin/Layout.cpp
index 17ce596..0c8c4ca 100644
--- a/libs/minikin/Layout.cpp
+++ b/libs/minikin/Layout.cpp
@@ -514,6 +514,29 @@ static size_t getNextWordBreak(const uint16_t* chars, size_t offset, size_t len)
return len;
}
+/**
+ * Disable certain scripts (mostly those with cursive connection) from having letterspacing
+ * applied. See https://github.com/behdad/harfbuzz/issues/64 for more details.
+ */
+static bool isScriptOkForLetterspacing(hb_script_t script) {
+ return !(
+ script == HB_SCRIPT_ARABIC ||
+ script == HB_SCRIPT_NKO ||
+ script == HB_SCRIPT_PSALTER_PAHLAVI ||
+ script == HB_SCRIPT_MANDAIC ||
+ script == HB_SCRIPT_MONGOLIAN ||
+ script == HB_SCRIPT_PHAGS_PA ||
+ script == HB_SCRIPT_DEVANAGARI ||
+ script == HB_SCRIPT_BENGALI ||
+ script == HB_SCRIPT_GURMUKHI ||
+ script == HB_SCRIPT_MODI ||
+ script == HB_SCRIPT_SHARADA ||
+ script == HB_SCRIPT_SYLOTI_NAGRI ||
+ script == HB_SCRIPT_TIRHUTA ||
+ script == HB_SCRIPT_OGHAM
+ );
+}
+
void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize,
int bidiFlags, const FontStyle &style, const MinikinPaint &paint) {
AutoMutex _l(gMinikinLock);
@@ -678,15 +701,6 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t
double size = ctx->paint.size;
double scaleX = ctx->paint.scaleX;
- double letterSpace = ctx->paint.letterSpacing * size * scaleX;
- double letterSpaceHalfLeft;
- if ((ctx->paint.paintFlags & LinearTextFlag) == 0) {
- letterSpace = round(letterSpace);
- letterSpaceHalfLeft = floor(letterSpace * 0.5);
- } else {
- letterSpaceHalfLeft = letterSpace * 0.5;
- }
- double letterSpaceHalfRight = letterSpace - letterSpaceHalfLeft;
float x = mAdvance;
float y = 0;
@@ -716,6 +730,21 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t
srunend = srunstart;
hb_script_t script = getScriptRun(buf + start, run.end, &srunend);
+ double letterSpace = 0.0;
+ double letterSpaceHalfLeft = 0.0;
+ double letterSpaceHalfRight = 0.0;
+
+ if (ctx->paint.letterSpacing != 0.0 && isScriptOkForLetterspacing(script)) {
+ letterSpace = ctx->paint.letterSpacing * size * scaleX;
+ if ((ctx->paint.paintFlags & LinearTextFlag) == 0) {
+ letterSpace = round(letterSpace);
+ letterSpaceHalfLeft = floor(letterSpace * 0.5);
+ } else {
+ letterSpaceHalfLeft = letterSpace * 0.5;
+ }
+ letterSpaceHalfRight = letterSpace - letterSpaceHalfLeft;
+ }
+
hb_buffer_clear_contents(buffer);
hb_buffer_set_script(buffer, script);
hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR);