Add wordSpacing parameter to Paint
Adds the ability to control word spacing from Java, wiring up the plumbing to the corresponding change that adds it at the Minikin level. Bug: 31707212 Test: ran graphicstests Change-Id: I568186aca961d51ee5231cb0331f882b7b005e90
This commit is contained in:
@@ -915,6 +915,16 @@ namespace PaintGlue {
|
||||
paint->setLetterSpacing(letterSpacing);
|
||||
}
|
||||
|
||||
static jfloat getWordSpacing(jlong paintHandle) {
|
||||
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
|
||||
return paint->getWordSpacing();
|
||||
}
|
||||
|
||||
static void setWordSpacing(jlong paintHandle, jfloat wordSpacing) {
|
||||
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
|
||||
paint->setWordSpacing(wordSpacing);
|
||||
}
|
||||
|
||||
static jint getHyphenEdit(jlong paintHandle, jint hyphen) {
|
||||
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
|
||||
return paint->getHyphenEdit();
|
||||
@@ -1043,6 +1053,8 @@ static const JNINativeMethod methods[] = {
|
||||
{"nSetTextSkewX","(JF)V", (void*) PaintGlue::setTextSkewX},
|
||||
{"nGetLetterSpacing","(J)F", (void*) PaintGlue::getLetterSpacing},
|
||||
{"nSetLetterSpacing","(JF)V", (void*) PaintGlue::setLetterSpacing},
|
||||
{"nGetWordSpacing","(J)F", (void*) PaintGlue::getWordSpacing},
|
||||
{"nSetWordSpacing","(JF)V", (void*) PaintGlue::setWordSpacing},
|
||||
{"nGetHyphenEdit", "(J)I", (void*) PaintGlue::getHyphenEdit},
|
||||
{"nSetHyphenEdit", "(JI)V", (void*) PaintGlue::setHyphenEdit},
|
||||
{"nAscent","(JJ)F", (void*) PaintGlue::ascent},
|
||||
|
||||
@@ -1441,6 +1441,28 @@ public class Paint {
|
||||
nSetLetterSpacing(mNativePaint, letterSpacing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the paint's word-spacing for text. The default value is 0.
|
||||
*
|
||||
* @return the paint's word-spacing for drawing text.
|
||||
* @hide
|
||||
*/
|
||||
public float getWordSpacing() {
|
||||
return nGetWordSpacing(mNativePaint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the paint's word-spacing for text. The default value is 0.
|
||||
* The value is in pixels (note the units are not the same as for
|
||||
* letter-spacing).
|
||||
*
|
||||
* @param wordSpacing set the paint's word-spacing for drawing text.
|
||||
* @hide
|
||||
*/
|
||||
public void setWordSpacing(float wordSpacing) {
|
||||
nSetWordSpacing(mNativePaint, wordSpacing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the font feature settings. The format is the same as the CSS
|
||||
* font-feature-settings attribute:
|
||||
@@ -2711,6 +2733,10 @@ public class Paint {
|
||||
@CriticalNative
|
||||
private static native void nSetLetterSpacing(long paintPtr, float letterSpacing);
|
||||
@CriticalNative
|
||||
private static native float nGetWordSpacing(long paintPtr);
|
||||
@CriticalNative
|
||||
private static native void nSetWordSpacing(long paintPtr, float wordSpacing);
|
||||
@CriticalNative
|
||||
private static native int nGetHyphenEdit(long paintPtr);
|
||||
@CriticalNative
|
||||
private static native void nSetHyphenEdit(long paintPtr, int hyphen);
|
||||
|
||||
@@ -218,4 +218,13 @@ public class PaintTest extends AndroidTestCase {
|
||||
assertEquals(width, p.measureText(bidiText), 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void testSetGetWordSpacing() {
|
||||
Paint p = new Paint();
|
||||
assertEquals(0.0f, p.getWordSpacing()); // The default value should be 0.
|
||||
p.setWordSpacing(1.0f);
|
||||
assertEquals(1.0f, p.getWordSpacing());
|
||||
p.setWordSpacing(-2.0f);
|
||||
assertEquals(-2.0f, p.getWordSpacing());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ minikin::FontStyle MinikinUtils::prepareMinikinPaint(minikin::MinikinPaint* mini
|
||||
minikinPaint->scaleX = paint->getTextScaleX();
|
||||
minikinPaint->skewX = paint->getTextSkewX();
|
||||
minikinPaint->letterSpacing = paint->getLetterSpacing();
|
||||
minikinPaint->wordSpacing = paint->getWordSpacing();
|
||||
minikinPaint->paintFlags = MinikinFontSkia::packPaintFlags(paint);
|
||||
minikinPaint->fontFeatureSettings = paint->getFontFeatureSettings();
|
||||
minikinPaint->hyphenEdit = minikin::HyphenEdit(paint->getHyphenEdit());
|
||||
|
||||
@@ -48,6 +48,14 @@ public:
|
||||
return mLetterSpacing;
|
||||
}
|
||||
|
||||
void setWordSpacing(float wordSpacing) {
|
||||
mWordSpacing = wordSpacing;
|
||||
}
|
||||
|
||||
float getWordSpacing() const {
|
||||
return mWordSpacing;
|
||||
}
|
||||
|
||||
void setFontFeatureSettings(const std::string& fontFeatureSettings) {
|
||||
mFontFeatureSettings = fontFeatureSettings;
|
||||
}
|
||||
@@ -82,6 +90,7 @@ public:
|
||||
|
||||
private:
|
||||
float mLetterSpacing = 0;
|
||||
float mWordSpacing = 0;
|
||||
std::string mFontFeatureSettings;
|
||||
uint32_t mMinikinLangListId;
|
||||
minikin::FontVariant mFontVariant;
|
||||
|
||||
@@ -19,18 +19,19 @@
|
||||
namespace android {
|
||||
|
||||
Paint::Paint() :
|
||||
SkPaint(), mLetterSpacing(0), mFontFeatureSettings(), mMinikinLangListId(0),
|
||||
mFontVariant(minikin::VARIANT_DEFAULT) {
|
||||
SkPaint(), mLetterSpacing(0), mWordSpacing(0), mFontFeatureSettings(),
|
||||
mMinikinLangListId(0), mFontVariant(minikin::VARIANT_DEFAULT) {
|
||||
}
|
||||
|
||||
Paint::Paint(const Paint& paint) : SkPaint(paint),
|
||||
mLetterSpacing(paint.mLetterSpacing), mFontFeatureSettings(paint.mFontFeatureSettings),
|
||||
mLetterSpacing(paint.mLetterSpacing), mWordSpacing(paint.mWordSpacing),
|
||||
mFontFeatureSettings(paint.mFontFeatureSettings),
|
||||
mMinikinLangListId(paint.mMinikinLangListId), mFontVariant(paint.mFontVariant),
|
||||
mHyphenEdit(paint.mHyphenEdit) {
|
||||
}
|
||||
|
||||
Paint::Paint(const SkPaint& paint) : SkPaint(paint),
|
||||
mLetterSpacing(0), mFontFeatureSettings(), mMinikinLangListId(0),
|
||||
mLetterSpacing(0), mWordSpacing(0), mFontFeatureSettings(), mMinikinLangListId(0),
|
||||
mFontVariant(minikin::VARIANT_DEFAULT) {
|
||||
}
|
||||
|
||||
@@ -40,6 +41,7 @@ Paint::~Paint() {
|
||||
Paint& Paint::operator=(const Paint& other) {
|
||||
SkPaint::operator=(other);
|
||||
mLetterSpacing = other.mLetterSpacing;
|
||||
mWordSpacing = other.mWordSpacing;
|
||||
mFontFeatureSettings = other.mFontFeatureSettings;
|
||||
mMinikinLangListId = other.mMinikinLangListId;
|
||||
mFontVariant = other.mFontVariant;
|
||||
@@ -50,6 +52,7 @@ Paint& Paint::operator=(const Paint& other) {
|
||||
bool operator==(const Paint& a, const Paint& b) {
|
||||
return static_cast<const SkPaint&>(a) == static_cast<const SkPaint&>(b)
|
||||
&& a.mLetterSpacing == b.mLetterSpacing
|
||||
&& a.mWordSpacing == b.mWordSpacing
|
||||
&& a.mFontFeatureSettings == b.mFontFeatureSettings
|
||||
&& a.mMinikinLangListId == b.mMinikinLangListId
|
||||
&& a.mFontVariant == b.mFontVariant
|
||||
|
||||
Reference in New Issue
Block a user