From 210a189e226d5ce64f760d557efc6570409c8147 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 9 Mar 2015 14:42:14 -0700 Subject: [PATCH] Add HyphenEdit support to Paint This adds HyphenEdit on the C++ and also to Java via JNI. HyphenEdit is a Minikin feature for adding hyphens to text without having to edit the string on the client side. Change-Id: Icfb228407c1d11a716d055f813da7507acb38fbf --- core/jni/android/graphics/MinikinUtils.cpp | 1 + core/jni/android/graphics/Paint.cpp | 12 +++++++++++ core/jni/android/graphics/Paint.h | 11 +++++++++- core/jni/android/graphics/PaintImpl.cpp | 7 ++++-- graphics/java/android/graphics/Paint.java | 25 ++++++++++++++++++++++ 5 files changed, 53 insertions(+), 3 deletions(-) diff --git a/core/jni/android/graphics/MinikinUtils.cpp b/core/jni/android/graphics/MinikinUtils.cpp index 7dabf6bcd42a5..8139c24cd88ac 100644 --- a/core/jni/android/graphics/MinikinUtils.cpp +++ b/core/jni/android/graphics/MinikinUtils.cpp @@ -47,6 +47,7 @@ void MinikinUtils::doLayout(Layout* layout, const Paint* paint, int bidiFlags, T minikinPaint.letterSpacing = paint->getLetterSpacing(); minikinPaint.paintFlags = MinikinFontSkia::packPaintFlags(paint); minikinPaint.fontFeatureSettings = paint->getFontFeatureSettings(); + minikinPaint.hyphenEdit = HyphenEdit(paint->getHyphenEdit()); layout->doLayout(buf, start, count, bufSize, bidiFlags, minikinStyle, minikinPaint); } diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index 83021e938268a..a92a9ac74ec85 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -453,6 +453,16 @@ public: } } + static jint getHyphenEdit(JNIEnv* env, jobject clazz, jlong paintHandle, jint hyphen) { + Paint* paint = reinterpret_cast(paintHandle); + return paint->getHyphenEdit(); + } + + static void setHyphenEdit(JNIEnv* env, jobject clazz, jlong paintHandle, jint hyphen) { + Paint* paint = reinterpret_cast(paintHandle); + paint->setHyphenEdit((uint32_t)hyphen); + } + static SkScalar getMetricsInternal(JNIEnv* env, jobject jpaint, Paint::FontMetrics *metrics) { const int kElegantTop = 2500; const int kElegantBottom = -1000; @@ -1009,6 +1019,8 @@ static JNINativeMethod methods[] = { {"native_getLetterSpacing","!(J)F", (void*) PaintGlue::getLetterSpacing}, {"native_setLetterSpacing","!(JF)V", (void*) PaintGlue::setLetterSpacing}, {"native_setFontFeatureSettings","(JLjava/lang/String;)V", (void*) PaintGlue::setFontFeatureSettings}, + {"native_getHyphenEdit", "!(J)I", (void*) PaintGlue::getHyphenEdit}, + {"native_setHyphenEdit", "!(JI)V", (void*) PaintGlue::setHyphenEdit}, {"ascent","!()F", (void*) PaintGlue::ascent}, {"descent","!()F", (void*) PaintGlue::descent}, diff --git a/core/jni/android/graphics/Paint.h b/core/jni/android/graphics/Paint.h index fa539f5b84529..1f82836d72bb6 100644 --- a/core/jni/android/graphics/Paint.h +++ b/core/jni/android/graphics/Paint.h @@ -69,11 +69,20 @@ public: return mFontVariant; } + void setHyphenEdit(uint32_t hyphen) { + mHyphenEdit = hyphen; + } + + uint32_t getHyphenEdit() const { + return mHyphenEdit; + } + private: - float mLetterSpacing; + float mLetterSpacing = 0; std::string mFontFeatureSettings; std::string mTextLocale; FontVariant mFontVariant; + uint32_t mHyphenEdit = 0; }; } // namespace android diff --git a/core/jni/android/graphics/PaintImpl.cpp b/core/jni/android/graphics/PaintImpl.cpp index fac669ba8d086..da85018b1b715 100644 --- a/core/jni/android/graphics/PaintImpl.cpp +++ b/core/jni/android/graphics/PaintImpl.cpp @@ -28,7 +28,8 @@ Paint::Paint() : SkPaint(), Paint::Paint(const Paint& paint) : SkPaint(paint), mLetterSpacing(paint.mLetterSpacing), mFontFeatureSettings(paint.mFontFeatureSettings), - mTextLocale(paint.mTextLocale), mFontVariant(paint.mFontVariant) { + mTextLocale(paint.mTextLocale), mFontVariant(paint.mFontVariant), + mHyphenEdit(paint.mHyphenEdit) { } Paint::~Paint() { @@ -40,6 +41,7 @@ Paint& Paint::operator=(const Paint& other) { mFontFeatureSettings = other.mFontFeatureSettings; mTextLocale = other.mTextLocale; mFontVariant = other.mFontVariant; + mHyphenEdit = other.mHyphenEdit; return *this; } @@ -48,7 +50,8 @@ bool operator==(const Paint& a, const Paint& b) { && a.mLetterSpacing == b.mLetterSpacing && a.mFontFeatureSettings == b.mFontFeatureSettings && a.mTextLocale == b.mTextLocale - && a.mFontVariant == b.mFontVariant; + && a.mFontVariant == b.mFontVariant + && a.mHyphenEdit == b.mHyphenEdit; } } diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index 0656b2e42bcd0..1da198cfc5692 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -1330,6 +1330,29 @@ public class Paint { native_setFontFeatureSettings(mNativePaint, settings); } + /** + * Get the current value of hyphen edit. + * + * @return the current hyphen edit value + * + * @hide + */ + public int getHyphenEdit() { + return native_getHyphenEdit(mNativePaint); + } + + /** + * Set a hyphen edit on the paint (causes a hyphen to be added to text when + * measured or drawn). + * + * @param hyphen 0 for no edit, 1 for adding a hyphen (other values in future) + * + * @hide + */ + public void setHyphenEdit(int hyphen) { + native_setHyphenEdit(mNativePaint, hyphen); + } + /** * Return the distance above (negative) the baseline (ascent) based on the * current typeface and text size. @@ -2309,4 +2332,6 @@ public class Paint { float letterSpacing); private static native void native_setFontFeatureSettings(long native_object, String settings); + private static native int native_getHyphenEdit(long native_object); + private static native void native_setHyphenEdit(long native_object, int hyphen); }