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
diff --git a/core/jni/android/graphics/MinikinUtils.cpp b/core/jni/android/graphics/MinikinUtils.cpp
index 7dabf6b..8139c24 100644
--- a/core/jni/android/graphics/MinikinUtils.cpp
+++ b/core/jni/android/graphics/MinikinUtils.cpp
@@ -47,6 +47,7 @@
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 83021e9..a92a9ac 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -453,6 +453,16 @@
}
}
+ static jint getHyphenEdit(JNIEnv* env, jobject clazz, jlong paintHandle, jint hyphen) {
+ Paint* paint = reinterpret_cast<Paint*>(paintHandle);
+ return paint->getHyphenEdit();
+ }
+
+ static void setHyphenEdit(JNIEnv* env, jobject clazz, jlong paintHandle, jint hyphen) {
+ Paint* paint = reinterpret_cast<Paint*>(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 @@
{"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 fa539f5..1f82836 100644
--- a/core/jni/android/graphics/Paint.h
+++ b/core/jni/android/graphics/Paint.h
@@ -69,11 +69,20 @@
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 fac669b..da85018 100644
--- a/core/jni/android/graphics/PaintImpl.cpp
+++ b/core/jni/android/graphics/PaintImpl.cpp
@@ -28,7 +28,8 @@
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 @@
mFontFeatureSettings = other.mFontFeatureSettings;
mTextLocale = other.mTextLocale;
mFontVariant = other.mFontVariant;
+ mHyphenEdit = other.mHyphenEdit;
return *this;
}
@@ -48,7 +50,8 @@
&& 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 0656b2e..1da198c 100644
--- a/graphics/java/android/graphics/Paint.java
+++ b/graphics/java/android/graphics/Paint.java
@@ -1331,6 +1331,29 @@
}
/**
+ * 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 @@
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);
}