diff --git a/core/jni/android/graphics/FontFamily.cpp b/core/jni/android/graphics/FontFamily.cpp index a24af29ea8f2c..6dc251c87e5e3 100644 --- a/core/jni/android/graphics/FontFamily.cpp +++ b/core/jni/android/graphics/FontFamily.cpp @@ -32,7 +32,7 @@ #include "Utils.h" #include -#include +#include #include #include diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h index 8108e0a08e908..5baa8f8740c2c 100644 --- a/core/jni/android/graphics/GraphicsJNI.h +++ b/core/jni/android/graphics/GraphicsJNI.h @@ -19,7 +19,7 @@ class SkCanvas; 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 d222a4b4771e5..27d8fed51e8af 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include #include @@ -402,8 +402,8 @@ namespace PaintGlue { const int kElegantDescent = -500; const int kElegantLeading = 0; Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); - typeface = TypefaceImpl_resolveDefault(typeface); + Typeface* typeface = reinterpret_cast(typefaceHandle); + typeface = Typeface::resolveDefault(typeface); FakedFont baseFont = typeface->fFontCollection->baseFontFaked(typeface->fStyle); float saveSkewX = paint->getTextSkewX(); bool savefakeBold = paint->isFakeBoldText(); @@ -474,7 +474,7 @@ namespace PaintGlue { 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 @@ namespace PaintGlue { jcharArray text, jint index, jint count, jint contextIndex, jint contextCount, jint bidiFlags, jfloatArray advances, jint advancesIndex) { Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(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 @@ namespace PaintGlue { jstring text, jint start, jint end, jint contextStart, jint contextEnd, jint bidiFlags, jfloatArray advances, jint advancesIndex) { Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(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 @@ namespace PaintGlue { 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 @@ namespace PaintGlue { jlong typefaceHandle, jint bidiFlags, jcharArray text, jint index, jint count, jfloat x, jfloat y, jlong pathHandle) { Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(typefaceHandle); SkPath* path = reinterpret_cast(pathHandle); const jchar* textArray = env->GetCharArrayElements(text, NULL); getTextPath(env, paint, typeface, textArray + index, count, bidiFlags, x, y, path); @@ -624,7 +624,7 @@ namespace PaintGlue { jlong typefaceHandle, jint bidiFlags, jstring text, jint start, jint end, jfloat x, jfloat y, jlong pathHandle) { Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(typefaceHandle); SkPath* path = reinterpret_cast(pathHandle); const jchar* textArray = env->GetStringChars(text, NULL); getTextPath(env, paint, typeface, textArray + start, end - start, bidiFlags, x, y, path); @@ -648,7 +648,7 @@ namespace PaintGlue { 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 @@ namespace PaintGlue { NPE_CHECK_RETURN_ZERO(env, jtext); Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(typefaceHandle); bool forwardTextDirection; if (count < 0) { @@ -714,7 +714,7 @@ namespace PaintGlue { NPE_CHECK_RETURN_ZERO(env, jtext); Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(typefaceHandle); int count = env->GetStringLength(jtext); const jchar* text = env->GetStringChars(jtext, NULL); @@ -724,7 +724,7 @@ namespace PaintGlue { } 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 @@ namespace PaintGlue { 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(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(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 @@ namespace PaintGlue { 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(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(typefaceHandle); const jchar* textArray = env->GetCharArrayElements(text, NULL); doTextBounds(env, textArray + index, count, bounds, *paint, typeface, bidiFlags); env->ReleaseCharArrayElements(text, const_cast(textArray), @@ -771,7 +771,7 @@ namespace PaintGlue { static jboolean hasGlyph(JNIEnv *env, jclass, jlong paintHandle, jlong typefaceHandle, jint bidiFlags, jstring string) { const Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(typefaceHandle); ScopedStringChars str(env, string); /* Start by rejecting unsupported base code point and variation selector pairs. */ @@ -820,7 +820,7 @@ namespace PaintGlue { 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 @@ namespace PaintGlue { jlong typefaceHandle, jcharArray text, jint start, jint end, jint contextStart, jint contextEnd, jboolean isRtl, jint offset) { const Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(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 @@ namespace PaintGlue { 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 advancesArray(new float[count]); @@ -859,7 +859,7 @@ namespace PaintGlue { jlong typefaceHandle, jcharArray text, jint start, jint end, jint contextStart, jint contextEnd, jboolean isRtl, jfloat advance) { const Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(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 8e2572c9b6b90..9a53cadf355b7 100644 --- a/core/jni/android/graphics/Typeface.cpp +++ b/core/jni/android/graphics/Typeface.cpp @@ -22,38 +22,40 @@ #include "SkTypeface.h" #include #include -#include +#include using namespace android; static jlong Typeface_createFromTypeface(JNIEnv* env, jobject, jlong familyHandle, jint style) { - TypefaceImpl* family = reinterpret_cast(familyHandle); - TypefaceImpl* face = TypefaceImpl_createFromTypeface(family, (SkTypeface::Style)style); + Typeface* family = reinterpret_cast(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(face); } static jlong Typeface_createWeightAlias(JNIEnv* env, jobject, jlong familyHandle, jint weight) { - TypefaceImpl* family = reinterpret_cast(familyHandle); - TypefaceImpl* face = TypefaceImpl_createWeightAlias(family, weight); + Typeface* family = reinterpret_cast(familyHandle); + Typeface* face = Typeface::createWeightAlias(family, weight); return reinterpret_cast(face); } static void Typeface_unref(JNIEnv* env, jobject obj, jlong faceHandle) { - TypefaceImpl* face = reinterpret_cast(faceHandle); - TypefaceImpl_unref(face); + Typeface* face = reinterpret_cast(faceHandle); + if (face != NULL) { + face->unref(); + } } static jint Typeface_getStyle(JNIEnv* env, jobject obj, jlong faceHandle) { - TypefaceImpl* face = reinterpret_cast(faceHandle); - return TypefaceImpl_getStyle(face); + Typeface* face = reinterpret_cast(faceHandle); + return face->fSkiaStyle; } static jlong Typeface_createFromArray(JNIEnv *env, jobject, jlongArray familyArray) { @@ -63,12 +65,12 @@ static jlong Typeface_createFromArray(JNIEnv *env, jobject, jlongArray familyArr FontFamily* family = reinterpret_cast(families[i]); familyVec.push_back(family); } - return reinterpret_cast(TypefaceImpl_createFromFamilies(familyVec)); + return reinterpret_cast(Typeface::createFromFamilies(familyVec)); } static void Typeface_setDefault(JNIEnv *env, jobject, jlong faceHandle) { - TypefaceImpl* face = reinterpret_cast(faceHandle); - return TypefaceImpl_setDefault(face); + Typeface* face = reinterpret_cast(faceHandle); + return Typeface::setDefault(face); } /////////////////////////////////////////////////////////////////////////////// diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp index 094f3c53d045b..ded4daca07073 100644 --- a/core/jni/android_graphics_Canvas.cpp +++ b/core/jni/android_graphics_Canvas.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include "Bitmap.h" @@ -478,7 +478,7 @@ static void drawTextChars(JNIEnv* env, jobject, jlong canvasHandle, jcharArray t jint index, jint count, jfloat x, jfloat y, jint bidiFlags, jlong paintHandle, jlong typefaceHandle) { Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(typefaceHandle); jchar* jchars = env->GetCharArrayElements(text, NULL); get_canvas(canvasHandle)->drawText(jchars + index, 0, count, count, x, y, bidiFlags, *paint, typeface); @@ -489,7 +489,7 @@ static void drawTextString(JNIEnv* env, jobject, jlong canvasHandle, jstring tex jint start, jint end, jfloat x, jfloat y, jint bidiFlags, jlong paintHandle, jlong typefaceHandle) { Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(typefaceHandle); const int count = end - start; const jchar* jchars = env->GetStringChars(text, NULL); get_canvas(canvasHandle)->drawText(jchars + start, 0, count, count, x, y, @@ -501,7 +501,7 @@ static void drawTextRunChars(JNIEnv* env, jobject, jlong canvasHandle, jcharArra jint count, jint contextIndex, jint contextCount, jfloat x, jfloat y, jboolean isRtl, jlong paintHandle, jlong typefaceHandle) { Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(typefaceHandle); const int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; jchar* jchars = env->GetCharArrayElements(text, NULL); @@ -515,7 +515,7 @@ static void drawTextRunString(JNIEnv* env, jobject obj, jlong canvasHandle, jstr jfloat x, jfloat y, jboolean isRtl, jlong paintHandle, jlong typefaceHandle) { Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(typefaceHandle); int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; jint count = end - start; @@ -532,7 +532,7 @@ static void drawTextOnPathChars(JNIEnv* env, jobject, jlong canvasHandle, jcharA jlong typefaceHandle) { SkPath* path = reinterpret_cast(pathHandle); Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(typefaceHandle); jchar* jchars = env->GetCharArrayElements(text, NULL); @@ -547,7 +547,7 @@ static void drawTextOnPathString(JNIEnv* env, jobject, jlong canvasHandle, jstri jint bidiFlags, jlong paintHandle, jlong typefaceHandle) { SkPath* path = reinterpret_cast(pathHandle); Paint* paint = reinterpret_cast(paintHandle); - TypefaceImpl* typeface = reinterpret_cast(typefaceHandle); + Typeface* typeface = reinterpret_cast(typefaceHandle); const jchar* jchars = env->GetStringChars(text, NULL); int count = env->GetStringLength(text); diff --git a/core/jni/android_text_StaticLayout.cpp b/core/jni/android_text_StaticLayout.cpp index fddcfa8461347..13e4f1a59fd8d 100644 --- a/core/jni/android_text_StaticLayout.cpp +++ b/core/jni/android_text_StaticLayout.cpp @@ -156,7 +156,7 @@ static jfloat nAddStyleRun(JNIEnv* env, jclass, jlong nativePtr, jlong nativePaint, jlong nativeTypeface, jint start, jint end, jboolean isRtl) { LineBreaker* b = reinterpret_cast(nativePtr); Paint* paint = reinterpret_cast(nativePaint); - TypefaceImpl* typeface = reinterpret_cast(nativeTypeface); + Typeface* typeface = reinterpret_cast(nativeTypeface); FontCollection *font; MinikinPaint minikinPaint; FontStyle style = MinikinUtils::prepareMinikinPaint(&minikinPaint, &font, paint, typeface); diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk index c7dc154ba8228..7b297bdf01e99 100644 --- a/libs/hwui/Android.mk +++ b/libs/hwui/Android.mk @@ -16,7 +16,7 @@ hwui_src_files := \ hwui/MinikinSkia.cpp \ hwui/MinikinUtils.cpp \ hwui/PaintImpl.cpp \ - hwui/TypefaceImpl.cpp \ + hwui/Typeface.cpp \ renderstate/Blend.cpp \ renderstate/MeshState.cpp \ renderstate/OffscreenBufferPool.cpp \ diff --git a/libs/hwui/hwui/Canvas.cpp b/libs/hwui/hwui/Canvas.cpp index 04e3af6da7d98..8c3eea35e783f 100644 --- a/libs/hwui/hwui/Canvas.cpp +++ b/libs/hwui/hwui/Canvas.cpp @@ -20,7 +20,7 @@ #include "RecordingCanvas.h" #include "MinikinUtils.h" #include "Paint.h" -#include "TypefaceImpl.h" +#include "Typeface.h" #include @@ -147,7 +147,7 @@ private: }; void Canvas::drawText(const uint16_t* text, int start, int count, int contextCount, - float x, float y, int bidiFlags, const Paint& origPaint, TypefaceImpl* typeface) { + float x, float y, int bidiFlags, const Paint& origPaint, Typeface* typeface) { // minikin may modify the original paint Paint paint(origPaint); @@ -202,7 +202,7 @@ private: }; void Canvas::drawTextOnPath(const uint16_t* text, int count, int bidiFlags, const SkPath& path, - float hOffset, float vOffset, const Paint& paint, TypefaceImpl* typeface) { + float hOffset, float vOffset, const Paint& paint, Typeface* typeface) { Paint paintCopy(paint); Layout layout; MinikinUtils::doLayout(&layout, &paintCopy, bidiFlags, typeface, text, 0, count, count); diff --git a/libs/hwui/hwui/Canvas.h b/libs/hwui/hwui/Canvas.h index d5f7053479eee..dc669f0b526a0 100644 --- a/libs/hwui/hwui/Canvas.h +++ b/libs/hwui/hwui/Canvas.h @@ -60,7 +60,7 @@ class Tree; typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot; class Paint; -struct TypefaceImpl; +struct Typeface; class ANDROID_API Canvas { public: @@ -237,10 +237,10 @@ public: * and delegating the final draw to virtual drawGlyphs method. */ void drawText(const uint16_t* text, int start, int count, int contextCount, - float x, float y, int bidiFlags, const Paint& origPaint, TypefaceImpl* typeface); + float x, float y, int bidiFlags, const Paint& origPaint, Typeface* typeface); void drawTextOnPath(const uint16_t* text, int count, int bidiFlags, const SkPath& path, - float hOffset, float vOffset, const Paint& paint, TypefaceImpl* typeface); + float hOffset, float vOffset, const Paint& paint, Typeface* typeface); protected: void drawTextDecorations(float x, float y, float length, const SkPaint& paint); diff --git a/libs/hwui/hwui/MinikinUtils.cpp b/libs/hwui/hwui/MinikinUtils.cpp index f4feee2dd7d98..67b775d983569 100644 --- a/libs/hwui/hwui/MinikinUtils.cpp +++ b/libs/hwui/hwui/MinikinUtils.cpp @@ -17,7 +17,7 @@ #include "Paint.h" #include "SkPathMeasure.h" -#include "TypefaceImpl.h" +#include "Typeface.h" #include #include @@ -25,8 +25,8 @@ namespace android { FontStyle MinikinUtils::prepareMinikinPaint(MinikinPaint* minikinPaint, FontCollection** pFont, - const Paint* paint, TypefaceImpl* typeface) { - const TypefaceImpl* resolvedFace = TypefaceImpl_resolveDefault(typeface); + const Paint* paint, Typeface* typeface) { + const Typeface* resolvedFace = Typeface::resolveDefault(typeface); *pFont = resolvedFace->fFontCollection; FontStyle resolved = resolvedFace->fStyle; @@ -51,7 +51,7 @@ FontStyle MinikinUtils::prepareMinikinPaint(MinikinPaint* minikinPaint, FontColl } void MinikinUtils::doLayout(Layout* layout, const Paint* paint, int bidiFlags, - TypefaceImpl* typeface, const uint16_t* buf, size_t start, size_t count, + Typeface* typeface, const uint16_t* buf, size_t start, size_t count, size_t bufSize) { FontCollection *font; MinikinPaint minikinPaint; @@ -60,7 +60,7 @@ void MinikinUtils::doLayout(Layout* layout, const Paint* paint, int bidiFlags, layout->doLayout(buf, start, count, bufSize, bidiFlags, minikinStyle, minikinPaint); } -float MinikinUtils::measureText(const Paint* paint, int bidiFlags, TypefaceImpl* typeface, +float MinikinUtils::measureText(const Paint* paint, int bidiFlags, Typeface* typeface, const uint16_t* buf, size_t start, size_t count, size_t bufSize, float *advances) { FontCollection *font; MinikinPaint minikinPaint; @@ -69,8 +69,8 @@ float MinikinUtils::measureText(const Paint* paint, int bidiFlags, TypefaceImpl* font, advances); } -bool MinikinUtils::hasVariationSelector(TypefaceImpl* typeface, uint32_t codepoint, uint32_t vs) { - const TypefaceImpl* resolvedFace = TypefaceImpl_resolveDefault(typeface); +bool MinikinUtils::hasVariationSelector(Typeface* typeface, uint32_t codepoint, uint32_t vs) { + const Typeface* resolvedFace = Typeface::resolveDefault(typeface); return resolvedFace->fFontCollection->hasVariationSelector(codepoint, vs); } diff --git a/libs/hwui/hwui/MinikinUtils.h b/libs/hwui/hwui/MinikinUtils.h index 4a49581c47519..cfaa961ac1fcf 100644 --- a/libs/hwui/hwui/MinikinUtils.h +++ b/libs/hwui/hwui/MinikinUtils.h @@ -28,23 +28,23 @@ #include #include "Paint.h" #include "MinikinSkia.h" -#include "TypefaceImpl.h" +#include "Typeface.h" namespace android { class MinikinUtils { public: ANDROID_API static FontStyle prepareMinikinPaint(MinikinPaint* minikinPaint, FontCollection** pFont, - const Paint* paint, TypefaceImpl* typeface); + const Paint* paint, Typeface* typeface); ANDROID_API static void doLayout(Layout* layout, const Paint* paint, int bidiFlags, - TypefaceImpl* typeface, const uint16_t* buf, size_t start, size_t count, + Typeface* typeface, const uint16_t* buf, size_t start, size_t count, size_t bufSize); - ANDROID_API static float measureText(const Paint* paint, int bidiFlags, TypefaceImpl* typeface, + ANDROID_API static float measureText(const Paint* paint, int bidiFlags, Typeface* typeface, const uint16_t* buf, size_t start, size_t count, size_t bufSize, float *advances); - ANDROID_API static bool hasVariationSelector(TypefaceImpl* typeface, uint32_t codepoint, uint32_t vs); + ANDROID_API static bool hasVariationSelector(Typeface* typeface, uint32_t codepoint, uint32_t vs); ANDROID_API static float xOffsetForTextAlign(Paint* paint, const Layout& layout); diff --git a/libs/hwui/hwui/TypefaceImpl.cpp b/libs/hwui/hwui/Typeface.cpp similarity index 82% rename from libs/hwui/hwui/TypefaceImpl.cpp rename to libs/hwui/hwui/Typeface.cpp index f14381b346c07..fa8ad5d6ce32c 100644 --- a/libs/hwui/hwui/TypefaceImpl.cpp +++ b/libs/hwui/hwui/Typeface.cpp @@ -20,7 +20,7 @@ * being, that choice is hidden under the USE_MINIKIN compile-time flag. */ -#include "TypefaceImpl.h" +#include "Typeface.h" #include "MinikinSkia.h" #include "SkTypeface.h" @@ -34,7 +34,7 @@ namespace android { // Resolve the 1..9 weight based on base weight and bold flag -static void resolveStyle(TypefaceImpl* typeface) { +static void resolveStyle(Typeface* typeface) { int weight = typeface->fBaseWeight / 100; if (typeface->fSkiaStyle & SkTypeface::kBold) { weight += 3; @@ -46,7 +46,7 @@ static void resolveStyle(TypefaceImpl* typeface) { typeface->fStyle = FontStyle(weight, italic); } -TypefaceImpl* gDefaultTypeface = NULL; +Typeface* gDefaultTypeface = NULL; pthread_once_t gDefaultTypefaceOnce = PTHREAD_ONCE_INIT; // This installs a default typeface (from a hardcoded path) that allows @@ -85,7 +85,7 @@ static void getDefaultTypefaceOnce() { if (gDefaultTypeface == NULL) { // We expect the client to set a default typeface, but provide a // default so we can make progress before that happens. - gDefaultTypeface = new TypefaceImpl; + gDefaultTypeface = new Typeface; gDefaultTypeface->fFontCollection = makeFontCollection(); gDefaultTypeface->fSkiaStyle = SkTypeface::kNormal; gDefaultTypeface->fBaseWeight = 400; @@ -93,7 +93,7 @@ static void getDefaultTypefaceOnce() { } } -TypefaceImpl* TypefaceImpl_resolveDefault(TypefaceImpl* src) { +Typeface* Typeface::resolveDefault(Typeface* src) { if (src == NULL) { pthread_once(&gDefaultTypefaceOnce, getDefaultTypefaceOnce); return gDefaultTypeface; @@ -102,9 +102,9 @@ TypefaceImpl* TypefaceImpl_resolveDefault(TypefaceImpl* src) { } } -TypefaceImpl* TypefaceImpl_createFromTypeface(TypefaceImpl* src, SkTypeface::Style style) { - TypefaceImpl* resolvedFace = TypefaceImpl_resolveDefault(src); - TypefaceImpl* result = new TypefaceImpl; +Typeface* Typeface::createFromTypeface(Typeface* src, SkTypeface::Style style) { + Typeface* resolvedFace = Typeface::resolveDefault(src); + Typeface* result = new Typeface; if (result != 0) { result->fFontCollection = resolvedFace->fFontCollection; result->fFontCollection->Ref(); @@ -115,9 +115,9 @@ TypefaceImpl* TypefaceImpl_createFromTypeface(TypefaceImpl* src, SkTypeface::Sty return result; } -TypefaceImpl* TypefaceImpl_createWeightAlias(TypefaceImpl* src, int weight) { - TypefaceImpl* resolvedFace = TypefaceImpl_resolveDefault(src); - TypefaceImpl* result = new TypefaceImpl; +Typeface* Typeface::createWeightAlias(Typeface* src, int weight) { + Typeface* resolvedFace = Typeface::resolveDefault(src); + Typeface* result = new Typeface; if (result != 0) { result->fFontCollection = resolvedFace->fFontCollection; result->fFontCollection->Ref(); @@ -128,8 +128,8 @@ TypefaceImpl* TypefaceImpl_createWeightAlias(TypefaceImpl* src, int weight) { return result; } -TypefaceImpl* TypefaceImpl_createFromFamilies(const std::vector& families) { - TypefaceImpl* result = new TypefaceImpl; +Typeface* Typeface::createFromFamilies(const std::vector& families) { + Typeface* result = new Typeface; result->fFontCollection = new FontCollection(families); if (families.empty()) { ALOGW("createFromFamilies creating empty collection"); @@ -152,18 +152,12 @@ TypefaceImpl* TypefaceImpl_createFromFamilies(const std::vector& fa return result; } -void TypefaceImpl_unref(TypefaceImpl* face) { - if (face != NULL) { - face->fFontCollection->Unref(); - } - delete face; +void Typeface::unref() { + fFontCollection->Unref(); + delete this; } -int TypefaceImpl_getStyle(TypefaceImpl* face) { - return face->fSkiaStyle; -} - -void TypefaceImpl_setDefault(TypefaceImpl* face) { +void Typeface::setDefault(Typeface* face) { gDefaultTypeface = face; } diff --git a/libs/hwui/hwui/TypefaceImpl.h b/libs/hwui/hwui/Typeface.h similarity index 55% rename from libs/hwui/hwui/TypefaceImpl.h rename to libs/hwui/hwui/Typeface.h index 01f1e83f95729..8862e5a5a9115 100644 --- a/libs/hwui/hwui/TypefaceImpl.h +++ b/libs/hwui/hwui/Typeface.h @@ -26,7 +26,7 @@ namespace android { -struct ANDROID_API TypefaceImpl { +struct ANDROID_API Typeface { FontCollection *fFontCollection; // style used for constructing and querying Typeface objects @@ -36,28 +36,20 @@ struct ANDROID_API TypefaceImpl { // resolved style actually used for rendering FontStyle fStyle; + + void unref(); + + static Typeface* resolveDefault(Typeface* src); + + static Typeface* createFromTypeface(Typeface* src, SkTypeface::Style style); + + static Typeface* createWeightAlias(Typeface* src, int baseweight); + + static Typeface* createFromFamilies(const std::vector& families); + + static void setDefault(Typeface* face); }; -// Note: it would be cleaner if the following functions were member -// functions (static or otherwise) of the TypefaceImpl class. However, -// that can't be easily accommodated in the case where TypefaceImpl -// is just a pointer to SkTypeface, in the non-USE_MINIKIN case. -// TODO: when #ifdef USE_MINIKIN is removed, move to member functions. - -ANDROID_API TypefaceImpl* TypefaceImpl_resolveDefault(TypefaceImpl* src); - -ANDROID_API TypefaceImpl* TypefaceImpl_createFromTypeface(TypefaceImpl* src, SkTypeface::Style style); - -ANDROID_API TypefaceImpl* TypefaceImpl_createWeightAlias(TypefaceImpl* src, int baseweight); - -ANDROID_API TypefaceImpl* TypefaceImpl_createFromFamilies(const std::vector& families); - -ANDROID_API void TypefaceImpl_unref(TypefaceImpl* face); - -ANDROID_API int TypefaceImpl_getStyle(TypefaceImpl* face); - -ANDROID_API void TypefaceImpl_setDefault(TypefaceImpl* face); - } #endif // _ANDROID_GRAPHICS_TYPEFACE_IMPL_H_