Clean up and rename TypefaceImpl
bug:25865834
Change-Id: I77e8a627163e040a5c25865054a8a936052af367
diff --git a/core/jni/android/graphics/FontFamily.cpp b/core/jni/android/graphics/FontFamily.cpp
index a24af29..6dc251c 100644
--- a/core/jni/android/graphics/FontFamily.cpp
+++ b/core/jni/android/graphics/FontFamily.cpp
@@ -32,7 +32,7 @@
#include "Utils.h"
#include <hwui/MinikinSkia.h>
-#include <hwui/TypefaceImpl.h>
+#include <hwui/Typeface.h>
#include <minikin/FontFamily.h>
#include <memory>
diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h
index 8108e0a..5baa8f8 100644
--- a/core/jni/android/graphics/GraphicsJNI.h
+++ b/core/jni/android/graphics/GraphicsJNI.h
@@ -19,7 +19,7 @@
namespace android {
class Paint;
-struct TypefaceImpl;
+struct Typeface;
}
class GraphicsJNI {
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index d222a4b..27d8fed 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -40,7 +40,7 @@
#include <hwui/MinikinSkia.h>
#include <hwui/MinikinUtils.h>
#include <hwui/Paint.h>
-#include <hwui/TypefaceImpl.h>
+#include <hwui/Typeface.h>
#include <minikin/GraphemeBreak.h>
#include <minikin/Measurement.h>
#include <unicode/utf16.h>
@@ -402,8 +402,8 @@
const int kElegantDescent = -500;
const int kElegantLeading = 0;
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
- typeface = TypefaceImpl_resolveDefault(typeface);
+ Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
+ typeface = Typeface::resolveDefault(typeface);
FakedFont baseFont = typeface->fFontCollection->baseFontFaked(typeface->fStyle);
float saveSkewX = paint->getTextSkewX();
bool savefakeBold = paint->isFakeBoldText();
@@ -474,7 +474,7 @@
return descent - ascent + leading;
}
- static jfloat doTextAdvances(JNIEnv *env, Paint *paint, TypefaceImpl* typeface,
+ static jfloat doTextAdvances(JNIEnv *env, Paint *paint, Typeface* typeface,
const jchar *text, jint start, jint count, jint contextCount, jint bidiFlags,
jfloatArray advances, jint advancesIndex) {
NPE_CHECK_RETURN_ZERO(env, text);
@@ -510,7 +510,7 @@
jcharArray text, jint index, jint count, jint contextIndex, jint contextCount,
jint bidiFlags, jfloatArray advances, jint advancesIndex) {
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
+ Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
jchar* textArray = env->GetCharArrayElements(text, NULL);
jfloat result = doTextAdvances(env, paint, typeface, textArray + contextIndex,
index - contextIndex, count, contextCount, bidiFlags, advances, advancesIndex);
@@ -523,7 +523,7 @@
jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint bidiFlags,
jfloatArray advances, jint advancesIndex) {
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
+ Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
const jchar* textArray = env->GetStringChars(text, NULL);
jfloat result = doTextAdvances(env, paint, typeface, textArray + contextStart,
start - contextStart, end - start, contextEnd - contextStart, bidiFlags,
@@ -590,7 +590,7 @@
SkPath tmpPath;
};
- static void getTextPath(JNIEnv* env, Paint* paint, TypefaceImpl* typeface, const jchar* text,
+ static void getTextPath(JNIEnv* env, Paint* paint, Typeface* typeface, const jchar* text,
jint count, jint bidiFlags, jfloat x, jfloat y, SkPath* path) {
Layout layout;
MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count);
@@ -613,7 +613,7 @@
jlong typefaceHandle, jint bidiFlags,
jcharArray text, jint index, jint count, jfloat x, jfloat y, jlong pathHandle) {
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
+ Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
const jchar* textArray = env->GetCharArrayElements(text, NULL);
getTextPath(env, paint, typeface, textArray + index, count, bidiFlags, x, y, path);
@@ -624,7 +624,7 @@
jlong typefaceHandle, jint bidiFlags,
jstring text, jint start, jint end, jfloat x, jfloat y, jlong pathHandle) {
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
+ Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
SkPath* path = reinterpret_cast<SkPath*>(pathHandle);
const jchar* textArray = env->GetStringChars(text, NULL);
getTextPath(env, paint, typeface, textArray + start, end - start, bidiFlags, x, y, path);
@@ -648,7 +648,7 @@
return paint->getLooper() && paint->getLooper()->asABlurShadow(NULL);
}
- static int breakText(JNIEnv* env, const Paint& paint, TypefaceImpl* typeface, const jchar text[],
+ static int breakText(JNIEnv* env, const Paint& paint, Typeface* typeface, const jchar text[],
int count, float maxWidth, jint bidiFlags, jfloatArray jmeasured,
const bool forwardScan) {
size_t measuredCount = 0;
@@ -685,7 +685,7 @@
NPE_CHECK_RETURN_ZERO(env, jtext);
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
+ Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
bool forwardTextDirection;
if (count < 0) {
@@ -714,7 +714,7 @@
NPE_CHECK_RETURN_ZERO(env, jtext);
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
+ Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
int count = env->GetStringLength(jtext);
const jchar* text = env->GetStringChars(jtext, NULL);
@@ -724,7 +724,7 @@
}
static void doTextBounds(JNIEnv* env, const jchar* text, int count, jobject bounds,
- const Paint& paint, TypefaceImpl* typeface, jint bidiFlags) {
+ const Paint& paint, Typeface* typeface, jint bidiFlags) {
SkRect r;
SkIRect ir;
@@ -743,7 +743,7 @@
static void getStringBounds(JNIEnv* env, jobject, jlong paintHandle, jlong typefaceHandle,
jstring text, jint start, jint end, jint bidiFlags, jobject bounds) {
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
+ Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
const jchar* textArray = env->GetStringChars(text, NULL);
doTextBounds(env, textArray + start, end - start, bounds, *paint, typeface, bidiFlags);
env->ReleaseStringChars(text, textArray);
@@ -752,7 +752,7 @@
static void getCharArrayBounds(JNIEnv* env, jobject, jlong paintHandle, jlong typefaceHandle,
jcharArray text, jint index, jint count, jint bidiFlags, jobject bounds) {
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
+ Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
const jchar* textArray = env->GetCharArrayElements(text, NULL);
doTextBounds(env, textArray + index, count, bounds, *paint, typeface, bidiFlags);
env->ReleaseCharArrayElements(text, const_cast<jchar*>(textArray),
@@ -771,7 +771,7 @@
static jboolean hasGlyph(JNIEnv *env, jclass, jlong paintHandle, jlong typefaceHandle,
jint bidiFlags, jstring string) {
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
+ Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
ScopedStringChars str(env, string);
/* Start by rejecting unsupported base code point and variation selector pairs. */
@@ -820,7 +820,7 @@
return nGlyphs > 0 && !layoutContainsNotdef(layout);
}
- static jfloat doRunAdvance(const Paint* paint, TypefaceImpl* typeface, const jchar buf[],
+ static jfloat doRunAdvance(const Paint* paint, Typeface* typeface, const jchar buf[],
jint start, jint count, jint bufSize, jboolean isRtl, jint offset) {
int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR;
if (offset == count) {
@@ -837,7 +837,7 @@
jlong typefaceHandle, jcharArray text, jint start, jint end, jint contextStart,
jint contextEnd, jboolean isRtl, jint offset) {
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
+ Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
jchar* textArray = (jchar*) env->GetPrimitiveArrayCritical(text, NULL);
jfloat result = doRunAdvance(paint, typeface, textArray + contextStart,
start - contextStart, end - start, contextEnd - contextStart, isRtl,
@@ -846,7 +846,7 @@
return result;
}
- static jint doOffsetForAdvance(const Paint* paint, TypefaceImpl* typeface, const jchar buf[],
+ static jint doOffsetForAdvance(const Paint* paint, Typeface* typeface, const jchar buf[],
jint start, jint count, jint bufSize, jboolean isRtl, jfloat advance) {
int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR;
std::unique_ptr<float[]> advancesArray(new float[count]);
@@ -859,7 +859,7 @@
jlong typefaceHandle, jcharArray text, jint start, jint end, jint contextStart,
jint contextEnd, jboolean isRtl, jfloat advance) {
const Paint* paint = reinterpret_cast<Paint*>(paintHandle);
- TypefaceImpl* typeface = reinterpret_cast<TypefaceImpl*>(typefaceHandle);
+ Typeface* typeface = reinterpret_cast<Typeface*>(typefaceHandle);
jchar* textArray = (jchar*) env->GetPrimitiveArrayCritical(text, NULL);
jint result = doOffsetForAdvance(paint, typeface, textArray + contextStart,
start - contextStart, end - start, contextEnd - contextStart, isRtl, advance);
diff --git a/core/jni/android/graphics/Typeface.cpp b/core/jni/android/graphics/Typeface.cpp
index 8e2572c..9a53cad 100644
--- a/core/jni/android/graphics/Typeface.cpp
+++ b/core/jni/android/graphics/Typeface.cpp
@@ -22,38 +22,40 @@
#include "SkTypeface.h"
#include <android_runtime/android_util_AssetManager.h>
#include <androidfw/AssetManager.h>
-#include <hwui/TypefaceImpl.h>
+#include <hwui/Typeface.h>
using namespace android;
static jlong Typeface_createFromTypeface(JNIEnv* env, jobject, jlong familyHandle, jint style) {
- TypefaceImpl* family = reinterpret_cast<TypefaceImpl*>(familyHandle);
- TypefaceImpl* face = TypefaceImpl_createFromTypeface(family, (SkTypeface::Style)style);
+ Typeface* family = reinterpret_cast<Typeface*>(familyHandle);
+ Typeface* face = Typeface::createFromTypeface(family, (SkTypeface::Style)style);
// TODO: the following logic shouldn't be necessary, the above should always succeed.
// Try to find the closest matching font, using the standard heuristic
if (NULL == face) {
- face = TypefaceImpl_createFromTypeface(family, (SkTypeface::Style)(style ^ SkTypeface::kItalic));
+ face = Typeface::createFromTypeface(family, (SkTypeface::Style)(style ^ SkTypeface::kItalic));
}
for (int i = 0; NULL == face && i < 4; i++) {
- face = TypefaceImpl_createFromTypeface(family, (SkTypeface::Style)i);
+ face = Typeface::createFromTypeface(family, (SkTypeface::Style)i);
}
return reinterpret_cast<jlong>(face);
}
static jlong Typeface_createWeightAlias(JNIEnv* env, jobject, jlong familyHandle, jint weight) {
- TypefaceImpl* family = reinterpret_cast<TypefaceImpl*>(familyHandle);
- TypefaceImpl* face = TypefaceImpl_createWeightAlias(family, weight);
+ Typeface* family = reinterpret_cast<Typeface*>(familyHandle);
+ Typeface* face = Typeface::createWeightAlias(family, weight);
return reinterpret_cast<jlong>(face);
}
static void Typeface_unref(JNIEnv* env, jobject obj, jlong faceHandle) {
- TypefaceImpl* face = reinterpret_cast<TypefaceImpl*>(faceHandle);
- TypefaceImpl_unref(face);
+ Typeface* face = reinterpret_cast<Typeface*>(faceHandle);
+ if (face != NULL) {
+ face->unref();
+ }
}
static jint Typeface_getStyle(JNIEnv* env, jobject obj, jlong faceHandle) {
- TypefaceImpl* face = reinterpret_cast<TypefaceImpl*>(faceHandle);
- return TypefaceImpl_getStyle(face);
+ Typeface* face = reinterpret_cast<Typeface*>(faceHandle);
+ return face->fSkiaStyle;
}
static jlong Typeface_createFromArray(JNIEnv *env, jobject, jlongArray familyArray) {
@@ -63,12 +65,12 @@
FontFamily* family = reinterpret_cast<FontFamily*>(families[i]);
familyVec.push_back(family);
}
- return reinterpret_cast<jlong>(TypefaceImpl_createFromFamilies(familyVec));
+ return reinterpret_cast<jlong>(Typeface::createFromFamilies(familyVec));
}
static void Typeface_setDefault(JNIEnv *env, jobject, jlong faceHandle) {
- TypefaceImpl* face = reinterpret_cast<TypefaceImpl*>(faceHandle);
- return TypefaceImpl_setDefault(face);
+ Typeface* face = reinterpret_cast<Typeface*>(faceHandle);
+ return Typeface::setDefault(face);
}
///////////////////////////////////////////////////////////////////////////////