Merge "Support for scaleX and skewX in Minikin" into lmp-preview-dev
diff --git a/core/jni/android/graphics/MinikinSkia.cpp b/core/jni/android/graphics/MinikinSkia.cpp
index 243fa10..2b96f1b 100644
--- a/core/jni/android/graphics/MinikinSkia.cpp
+++ b/core/jni/android/graphics/MinikinSkia.cpp
@@ -46,8 +46,10 @@
static void MinikinFontSkia_SetSkiaPaint(SkTypeface* typeface, SkPaint* skPaint, const MinikinPaint& paint) {
skPaint->setTypeface(typeface);
skPaint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
- // TODO: set more paint parameters from Minikin
skPaint->setTextSize(paint.size);
+ skPaint->setTextScaleX(paint.scaleX);
+ skPaint->setTextSkewX(paint.skewX);
+ MinikinFontSkia::unpackPaintFlags(skPaint, paint.paintFlags);
}
float MinikinFontSkia::GetHorizontalAdvance(uint32_t glyph_id,
@@ -96,4 +98,21 @@
return mTypeface->uniqueID();
}
+uint32_t MinikinFontSkia::packPaintFlags(const SkPaint* paint) {
+ uint32_t flags = paint->getFlags();
+ SkPaint::Hinting hinting = paint->getHinting();
+ // select only flags that might affect text layout
+ flags &= (SkPaint::kAntiAlias_Flag | SkPaint::kFakeBoldText_Flag | SkPaint::kLinearText_Flag |
+ SkPaint::kSubpixelText_Flag | SkPaint::kDevKernText_Flag |
+ SkPaint::kEmbeddedBitmapText_Flag | SkPaint::kAutoHinting_Flag |
+ SkPaint::kVerticalText_Flag);
+ flags |= (hinting << 16);
+ return flags;
+}
+
+void MinikinFontSkia::unpackPaintFlags(SkPaint* paint, uint32_t paintFlags) {
+ paint->setFlags(paintFlags & SkPaint::kAllFlags);
+ paint->setHinting(static_cast<SkPaint::Hinting>(paintFlags >> 16));
+}
+
}
diff --git a/core/jni/android/graphics/MinikinSkia.h b/core/jni/android/graphics/MinikinSkia.h
index 1cc2c51..0452c57 100644
--- a/core/jni/android/graphics/MinikinSkia.h
+++ b/core/jni/android/graphics/MinikinSkia.h
@@ -38,6 +38,8 @@
SkTypeface *GetSkTypeface();
+ static uint32_t packPaintFlags(const SkPaint* paint);
+ static void unpackPaintFlags(SkPaint* paint, uint32_t paintFlags);
private:
SkTypeface *mTypeface;
};
diff --git a/core/jni/android/graphics/MinikinUtils.cpp b/core/jni/android/graphics/MinikinUtils.cpp
index a88b747..146bc3d 100644
--- a/core/jni/android/graphics/MinikinUtils.cpp
+++ b/core/jni/android/graphics/MinikinUtils.cpp
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+#define LOG_TAG "Minikin"
+#include <cutils/log.h>
+
#include "SkPaint.h"
#include "minikin/Layout.h"
#include "TypefaceImpl.h"
@@ -23,23 +26,37 @@
namespace android {
+// Do an sprintf starting at offset n, abort on overflow
+static int snprintfcat(char* buf, int off, int size, const char* format, ...) {
+ va_list args;
+ va_start(args, format);
+ int n = vsnprintf(buf + off, size - off, format, args);
+ LOG_ALWAYS_FATAL_IF(n >= size - off, "String overflow in setting layout properties");
+ va_end(args);
+ return off + n;
+}
+
void MinikinUtils::SetLayoutProperties(Layout* layout, const SkPaint* paint, int flags,
TypefaceImpl* typeface) {
TypefaceImpl* resolvedFace = TypefaceImpl_resolveDefault(typeface);
layout->setFontCollection(resolvedFace->fFontCollection);
FontStyle style = resolvedFace->fStyle;
char css[256];
- int off = snprintf(css, sizeof(css),
- "font-size: %d; font-weight: %d; font-style: %s; -minikin-bidi: %d;",
+ int off = snprintfcat(css, 0, sizeof(css),
+ "font-size: %d; font-scale-x: %f; font-skew-x: %f; -paint-flags: %d;"
+ " font-weight: %d; font-style: %s; -minikin-bidi: %d;",
(int)paint->getTextSize(),
+ paint->getTextScaleX(),
+ paint->getTextSkewX(),
+ MinikinFontSkia::packPaintFlags(paint),
style.getWeight() * 100,
style.getItalic() ? "italic" : "normal",
flags);
SkString langString = paint->getPaintOptionsAndroid().getLanguage().getTag();
- off += snprintf(css + off, sizeof(css) - off, " lang: %s;", langString.c_str());
+ off = snprintfcat(css, off, sizeof(css), " lang: %s;", langString.c_str());
SkPaintOptionsAndroid::FontVariant var = paint->getPaintOptionsAndroid().getFontVariant();
const char* varstr = var == SkPaintOptionsAndroid::kElegant_Variant ? "elegant" : "compact";
- off += snprintf(css + off, sizeof(css) - off, " -minikin-variant: %s;", varstr);
+ off = snprintfcat(css, off, sizeof(css), " -minikin-variant: %s;", varstr);
layout->setProperties(css);
}
diff --git a/core/jni/android/graphics/MinikinUtils.h b/core/jni/android/graphics/MinikinUtils.h
index 997d6e3..3996c82 100644
--- a/core/jni/android/graphics/MinikinUtils.h
+++ b/core/jni/android/graphics/MinikinUtils.h
@@ -26,10 +26,14 @@
namespace android {
+class Layout;
+class TypefaceImpl;
+
class MinikinUtils {
public:
static void SetLayoutProperties(Layout* layout, const SkPaint* paint, int flags,
TypefaceImpl* face);
+
static float xOffsetForTextAlign(SkPaint* paint, const Layout& layout);
// f is a functor of type void f(SkTypeface *, size_t start, size_t end);
diff --git a/core/jni/android/graphics/TypefaceImpl.cpp b/core/jni/android/graphics/TypefaceImpl.cpp
index 786d19c..27df7cf 100644
--- a/core/jni/android/graphics/TypefaceImpl.cpp
+++ b/core/jni/android/graphics/TypefaceImpl.cpp
@@ -32,6 +32,7 @@
#include <minikin/FontCollection.h>
#include <minikin/FontFamily.h>
#include <minikin/Layout.h>
+#include "SkPaint.h"
#include "MinikinSkia.h"
#endif