summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2014-09-04 00:16:27 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-09-04 00:16:27 +0000
commit9f00aaec705f667fc62710c5b1cd2cb8d005e1d5 (patch)
treebb260551ba0f363ad5e12940feaf9f5c304e8b67
parentdf0178d7d22efabe922f5c1f90a100d2b740ebf4 (diff)
parent6740536e3927d25bf5c2567e5f6e8c175973cbb7 (diff)
downloadandroid_frameworks_minikin-9f00aaec705f667fc62710c5b1cd2cb8d005e1d5.tar.gz
android_frameworks_minikin-9f00aaec705f667fc62710c5b1cd2cb8d005e1d5.tar.bz2
android_frameworks_minikin-9f00aaec705f667fc62710c5b1cd2cb8d005e1d5.zip
am 6740536e: Snap advance widths to integers
* commit '6740536e3927d25bf5c2567e5f6e8c175973cbb7': Snap advance widths to integers
-rw-r--r--include/minikin/MinikinFont.h6
-rw-r--r--libs/minikin/Layout.cpp26
2 files changed, 24 insertions, 8 deletions
diff --git a/include/minikin/MinikinFont.h b/include/minikin/MinikinFont.h
index 9b25f92..3f07589 100644
--- a/include/minikin/MinikinFont.h
+++ b/include/minikin/MinikinFont.h
@@ -49,6 +49,12 @@ struct MinikinPaint {
std::string fontFeatureSettings;
};
+// Only a few flags affect layout, but those that do should have values
+// consistent with Android's paint flags.
+enum MinikinPaintFlags {
+ LinearTextFlag = 0x40,
+};
+
struct MinikinRect {
float mLeft, mTop, mRight, mBottom;
bool isEmpty() const {
diff --git a/libs/minikin/Layout.cpp b/libs/minikin/Layout.cpp
index cfca18e..5ad3bfc 100644
--- a/libs/minikin/Layout.cpp
+++ b/libs/minikin/Layout.cpp
@@ -670,7 +670,14 @@ 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 letterSpaceHalf = letterSpace * .5;
+ 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;
@@ -715,8 +722,8 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t
hb_glyph_position_t* positions = hb_buffer_get_glyph_positions(buffer, NULL);
if (numGlyphs)
{
- mAdvances[info[0].cluster - start] += letterSpaceHalf;
- x += letterSpaceHalf;
+ mAdvances[info[0].cluster - start] += letterSpaceHalfLeft;
+ x += letterSpaceHalfLeft;
}
for (unsigned int i = 0; i < numGlyphs; i++) {
#ifdef VERBOSE
@@ -724,9 +731,9 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t
": " << HBFixedToFloat(positions[i].x_advance) << "; " << positions[i].x_offset << ", " << positions[i].y_offset << std::endl;
#endif
if (i > 0 && info[i - 1].cluster != info[i].cluster) {
- mAdvances[info[i - 1].cluster - start] += letterSpaceHalf;
- mAdvances[info[i].cluster - start] += letterSpaceHalf;
- x += letterSpaceHalf;
+ mAdvances[info[i - 1].cluster - start] += letterSpaceHalfRight;
+ mAdvances[info[i].cluster - start] += letterSpaceHalfLeft;
+ x += letterSpace;
}
hb_codepoint_t glyph_ix = info[i].codepoint;
@@ -736,6 +743,9 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t
LayoutGlyph glyph = {font_ix, glyph_ix, x + xoff, y + yoff};
mGlyphs.push_back(glyph);
float xAdvance = HBFixedToFloat(positions[i].x_advance);
+ if ((ctx->paint.paintFlags & LinearTextFlag) == 0) {
+ xAdvance = roundf(xAdvance);
+ }
MinikinRect glyphBounds;
ctx->paint.font->GetBounds(&glyphBounds, glyph_ix, ctx->paint);
glyphBounds.offset(x + xoff, y + yoff);
@@ -745,8 +755,8 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t
}
if (numGlyphs)
{
- mAdvances[info[numGlyphs - 1].cluster - start] += letterSpaceHalf;
- x += letterSpaceHalf;
+ mAdvances[info[numGlyphs - 1].cluster - start] += letterSpaceHalfRight;
+ x += letterSpaceHalfRight;
}
}
}