diff options
author | Dianne Hackborn <hackbod@google.com> | 2011-08-12 18:59:39 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2011-08-12 18:59:39 -0700 |
commit | f43fa5746ee5b81a6e386d36594094d079ac8160 (patch) | |
tree | bf26f4fde8e7610722f6c75944b713c18d115064 | |
parent | 7c0d8472d003334fafd14f7c1e7d95dbd213088b (diff) | |
download | frameworks_base-f43fa5746ee5b81a6e386d36594094d079ac8160.zip frameworks_base-f43fa5746ee5b81a6e386d36594094d079ac8160.tar.gz frameworks_base-f43fa5746ee5b81a6e386d36594094d079ac8160.tar.bz2 |
Turn off hinting by default for higher density displays.
Also adds an API for apps to control whether hinting is used.
Change-Id: I1a06b06255fbb8d0f02a8ce48c2cd60019088ed3
-rw-r--r-- | api/current.txt | 4 | ||||
-rw-r--r-- | core/jni/android/graphics/Paint.cpp | 20 | ||||
-rw-r--r-- | graphics/java/android/graphics/Paint.java | 27 |
3 files changed, 49 insertions, 2 deletions
diff --git a/api/current.txt b/api/current.txt index fee4df6..ed46f45 100644 --- a/api/current.txt +++ b/api/current.txt @@ -8216,6 +8216,7 @@ package android.graphics { method public int getFontMetricsInt(android.graphics.Paint.FontMetricsInt); method public android.graphics.Paint.FontMetricsInt getFontMetricsInt(); method public float getFontSpacing(); + method public int getHinting(); method public android.graphics.MaskFilter getMaskFilter(); method public android.graphics.PathEffect getPathEffect(); method public android.graphics.Rasterizer getRasterizer(); @@ -8262,6 +8263,7 @@ package android.graphics { method public void setFakeBoldText(boolean); method public void setFilterBitmap(boolean); method public void setFlags(int); + method public void setHinting(int); method public void setLinearText(boolean); method public android.graphics.MaskFilter setMaskFilter(android.graphics.MaskFilter); method public android.graphics.PathEffect setPathEffect(android.graphics.PathEffect); @@ -8287,6 +8289,8 @@ package android.graphics { field public static final int DITHER_FLAG = 4; // 0x4 field public static final int FAKE_BOLD_TEXT_FLAG = 32; // 0x20 field public static final int FILTER_BITMAP_FLAG = 2; // 0x2 + field public static final int HINTING_OFF = 0; // 0x0 + field public static final int HINTING_ON = 1; // 0x1 field public static final int LINEAR_TEXT_FLAG = 64; // 0x40 field public static final int STRIKE_THRU_TEXT_FLAG = 16; // 0x10 field public static final int SUBPIXEL_TEXT_FLAG = 128; // 0x80 diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index 98d7fce..423eff4 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -15,6 +15,10 @@ ** limitations under the License. */ +#define LOG_TAG "Paint" + +#include <utils/Log.h> + #include "jni.h" #include "GraphicsJNI.h" #include <android_runtime/AndroidRuntime.h> @@ -50,8 +54,6 @@ static jclass gFontMetricsInt_class; static JMetricsID gFontMetricsInt_fieldID; static void defaultSettingsForAndroid(SkPaint* paint) { - // looks best we decided - paint->setHinting(SkPaint::kSlight_Hinting); // utf16 is required for java paint->setTextEncoding(SkPaint::kUTF16_TextEncoding); } @@ -96,6 +98,18 @@ public: GraphicsJNI::getNativePaint(env, paint)->setFlags(flags); } + static jint getHinting(JNIEnv* env, jobject paint) { + NPE_CHECK_RETURN_ZERO(env, paint); + return GraphicsJNI::getNativePaint(env, paint)->getHinting() + == SkPaint::kNo_Hinting ? 0 : 1; + } + + static void setHinting(JNIEnv* env, jobject paint, jint mode) { + NPE_CHECK_RETURN_VOID(env, paint); + GraphicsJNI::getNativePaint(env, paint)->setHinting( + mode == 0 ? SkPaint::kNo_Hinting : SkPaint::kSlight_Hinting); + } + static void setAntiAlias(JNIEnv* env, jobject paint, jboolean aa) { NPE_CHECK_RETURN_VOID(env, paint); GraphicsJNI::getNativePaint(env, paint)->setAntiAlias(aa); @@ -833,6 +847,8 @@ static JNINativeMethod methods[] = { {"native_set","(II)V", (void*) SkPaintGlue::assign}, {"getFlags","()I", (void*) SkPaintGlue::getFlags}, {"setFlags","(I)V", (void*) SkPaintGlue::setFlags}, + {"getHinting","()I", (void*) SkPaintGlue::getHinting}, + {"setHinting","(I)V", (void*) SkPaintGlue::setHinting}, {"setAntiAlias","(Z)V", (void*) SkPaintGlue::setAntiAlias}, {"setSubpixelText","(Z)V", (void*) SkPaintGlue::setSubpixelText}, {"setLinearText","(Z)V", (void*) SkPaintGlue::setLinearText}, diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java index 828bafd..cde997e 100644 --- a/graphics/java/android/graphics/Paint.java +++ b/graphics/java/android/graphics/Paint.java @@ -20,6 +20,7 @@ import android.text.GraphicsOperations; import android.text.SpannableString; import android.text.SpannedString; import android.text.TextUtils; +import android.util.DisplayMetrics; /** * The Paint class holds the style and color information about how to draw @@ -106,6 +107,16 @@ public class Paint { static final int DEFAULT_PAINT_FLAGS = DEV_KERN_TEXT_FLAG; /** + * Option for {@link #setHinting}: disable hinting. + */ + public static final int HINTING_OFF = 0x0; + + /** + * Option for {@link #setHinting}: enable hinting. + */ + public static final int HINTING_ON = 0x1; + + /** * Bidi flag to set LTR paragraph direction. * * @hide @@ -333,6 +344,8 @@ public class Paint { public Paint(int flags) { mNativePaint = native_init(); setFlags(flags | DEFAULT_PAINT_FLAGS); + setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV + ? HINTING_OFF : HINTING_ON); mCompatScaling = mInvCompatScaling = 1; } @@ -367,6 +380,8 @@ public class Paint { public void reset() { native_reset(mNativePaint); setFlags(DEFAULT_PAINT_FLAGS); + setHinting(DisplayMetrics.DENSITY_DEVICE >= DisplayMetrics.DENSITY_TV + ? HINTING_OFF : HINTING_ON); mHasCompatScaling = false; mCompatScaling = mInvCompatScaling = 1; mBidiFlags = BIDI_DEFAULT_LTR; @@ -446,6 +461,18 @@ public class Paint { public native void setFlags(int flags); /** + * Return the paint's hinting mode. Returns either + * {@link #HINTING_OFF} or {@link #HINTING_ON}. + */ + public native int getHinting(); + + /** + * Set the paint's hinting mode. May be either + * {@link #HINTING_OFF} or {@link #HINTING_ON}. + */ + public native void setHinting(int mode); + + /** * Helper for getFlags(), returning true if ANTI_ALIAS_FLAG bit is set * AntiAliasing smooths out the edges of what is being drawn, but is has * no impact on the interior of the shape. See setDither() and |