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
This commit is contained in:
Raph Levien
2015-03-09 14:42:14 -07:00
parent e4bb8c9fb7
commit 210a189e22
5 changed files with 53 additions and 3 deletions

View File

@@ -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);
}

View File

@@ -453,6 +453,16 @@ public:
}
}
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 @@ 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},

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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);
}