Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2836c472 authored by Raph Levien's avatar Raph Levien Committed by Android (Google) Code Review
Browse files

Merge "Start of Minikin integration"

parents fe4c1e22 1a73f732
Loading
Loading
Loading
Loading
+14 −12
Original line number Diff line number Diff line
@@ -1127,14 +1127,15 @@ class GLES20Canvas extends HardwareCanvas {

        int modifiers = setupModifiers(paint);
        try {
            nDrawText(mRenderer, text, index, count, x, y, paint.mBidiFlags, paint.mNativePaint);
            nDrawText(mRenderer, text, index, count, x, y, paint.mBidiFlags, paint.mNativePaint,
                paint.mNativeTypeface);
        } finally {
            if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers);
        }
    }
    
    private static native void nDrawText(long renderer, char[] text, int index, int count,
            float x, float y, int bidiFlags, long paint);
            float x, float y, int bidiFlags, long paint, long typeface);

    @Override
    public void drawText(CharSequence text, int start, int end, float x, float y, Paint paint) {
@@ -1143,7 +1144,7 @@ class GLES20Canvas extends HardwareCanvas {
            if (text instanceof String || text instanceof SpannedString ||
                    text instanceof SpannableString) {
                nDrawText(mRenderer, text.toString(), start, end, x, y, paint.mBidiFlags,
                        paint.mNativePaint);
                        paint.mNativePaint, paint.mNativeTypeface);
            } else if (text instanceof GraphicsOperations) {
                ((GraphicsOperations) text).drawText(this, start, end, x, y,
                                                         paint);
@@ -1151,7 +1152,7 @@ class GLES20Canvas extends HardwareCanvas {
                char[] buf = TemporaryBuffer.obtain(end - start);
                TextUtils.getChars(text, start, end, buf, 0);
                nDrawText(mRenderer, buf, 0, end - start, x, y,
                        paint.mBidiFlags, paint.mNativePaint);
                        paint.mBidiFlags, paint.mNativePaint, paint.mNativeTypeface);
                TemporaryBuffer.recycle(buf);
            }
        } finally {
@@ -1167,21 +1168,22 @@ class GLES20Canvas extends HardwareCanvas {

        int modifiers = setupModifiers(paint);
        try {
            nDrawText(mRenderer, text, start, end, x, y, paint.mBidiFlags, paint.mNativePaint);
            nDrawText(mRenderer, text, start, end, x, y, paint.mBidiFlags, paint.mNativePaint,
                paint.mNativeTypeface);
        } finally {
            if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers);
        }
    }

    private static native void nDrawText(long renderer, String text, int start, int end,
            float x, float y, int bidiFlags, long paint);
            float x, float y, int bidiFlags, long paint, long typeface);

    @Override
    public void drawText(String text, float x, float y, Paint paint) {
        int modifiers = setupModifiers(paint);
        try {
            nDrawText(mRenderer, text, 0, text.length(), x, y, paint.mBidiFlags,
                    paint.mNativePaint);
                    paint.mNativePaint, paint.mNativeTypeface);
        } finally {
            if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers);
        }
@@ -1235,14 +1237,14 @@ class GLES20Canvas extends HardwareCanvas {
        int modifiers = setupModifiers(paint);
        try {
            nDrawTextRun(mRenderer, text, index, count, contextIndex, contextCount, x, y, dir,
                    paint.mNativePaint);
                    paint.mNativePaint, paint.mNativeTypeface);
        } finally {
            if (modifiers != MODIFIER_NONE) nResetModifiers(mRenderer, modifiers);
        }
    }

    private static native void nDrawTextRun(long renderer, char[] text, int index, int count,
            int contextIndex, int contextCount, float x, float y, int dir, long nativePaint);
            int contextIndex, int contextCount, float x, float y, int dir, long nativePaint, long nativeTypeface);

    @Override
    public void drawTextRun(CharSequence text, int start, int end, int contextStart, int contextEnd,
@@ -1257,7 +1259,7 @@ class GLES20Canvas extends HardwareCanvas {
            if (text instanceof String || text instanceof SpannedString ||
                    text instanceof SpannableString) {
                nDrawTextRun(mRenderer, text.toString(), start, end, contextStart,
                        contextEnd, x, y, flags, paint.mNativePaint);
                        contextEnd, x, y, flags, paint.mNativePaint, paint.mNativeTypeface);
            } else if (text instanceof GraphicsOperations) {
                ((GraphicsOperations) text).drawTextRun(this, start, end,
                        contextStart, contextEnd, x, y, flags, paint);
@@ -1267,7 +1269,7 @@ class GLES20Canvas extends HardwareCanvas {
                char[] buf = TemporaryBuffer.obtain(contextLen);
                TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
                nDrawTextRun(mRenderer, buf, start - contextStart, len, 0, contextLen,
                        x, y, flags, paint.mNativePaint);
                        x, y, flags, paint.mNativePaint, paint.mNativeTypeface);
                TemporaryBuffer.recycle(buf);
            }
        } finally {
@@ -1276,7 +1278,7 @@ class GLES20Canvas extends HardwareCanvas {
    }

    private static native void nDrawTextRun(long renderer, String text, int start, int end,
            int contextStart, int contextEnd, float x, float y, int flags, long nativePaint);
            int contextStart, int contextEnd, float x, float y, int flags, long nativePaint, long nativeTypeface);

    @Override
    public void drawVertices(VertexMode mode, int vertexCount, float[] verts, int vertOffset,
+3 −1
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ LOCAL_SRC_FILES:= \
	android/graphics/CanvasProperty.cpp \
	android/graphics/ColorFilter.cpp \
	android/graphics/DrawFilter.cpp \
	android/graphics/FontFamily.cpp \
	android/graphics/CreateJavaOutputStreamAdaptor.cpp \
	android/graphics/Graphics.cpp \
	android/graphics/HarfBuzzNGFaceSkia.cpp \
@@ -231,7 +232,8 @@ ifeq ($(USE_MINIKIN), true)
	LOCAL_CFLAGS += -DUSE_MINIKIN
	LOCAL_C_INCLUDES += frameworks/minikin/include \
		external/freetype/include
	LOCAL_SRC_FILES += 	android/graphics/MinikinSkia.cpp
	LOCAL_SRC_FILES += 	android/graphics/MinikinSkia.cpp \
		android/graphics/MinikinUtils.cpp
# note: the freetype include is spurious; minikin itself probably
# shouldn't depend on it
	LOCAL_SHARED_LIBRARIES += libminikin libstlport
+2 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ extern int register_android_graphics_Canvas(JNIEnv* env);
extern int register_android_graphics_CanvasProperty(JNIEnv* env);
extern int register_android_graphics_ColorFilter(JNIEnv* env);
extern int register_android_graphics_DrawFilter(JNIEnv* env);
extern int register_android_graphics_FontFamily(JNIEnv* env);
extern int register_android_graphics_Matrix(JNIEnv* env);
extern int register_android_graphics_Paint(JNIEnv* env);
extern int register_android_graphics_Path(JNIEnv* env);
@@ -1236,6 +1237,7 @@ static const RegJNIRec gRegJNI[] = {
    REG_JNI(register_android_graphics_CanvasProperty),
    REG_JNI(register_android_graphics_ColorFilter),
    REG_JNI(register_android_graphics_DrawFilter),
    REG_JNI(register_android_graphics_FontFamily),
    REG_JNI(register_android_graphics_Interpolator),
    REG_JNI(register_android_graphics_LayerRasterizer),
    REG_JNI(register_android_graphics_MaskFilter),
+3 −10
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#ifdef USE_MINIKIN
#include <minikin/Layout.h>
#include "MinikinSkia.h"
#include "MinikinUtils.h"
#endif

#include "TextLayout.h"
@@ -865,15 +866,7 @@ public:

#ifdef USE_MINIKIN
        Layout layout;
        TypefaceImpl* resolvedFace = TypefaceImpl_resolveDefault(typeface);
        layout.setFontCollection(resolvedFace->fFontCollection);
        FontStyle style = resolvedFace->fStyle;
        char css[256];
        sprintf(css, "font-size: %d; font-weight: %d; font-style: %s",
            (int)paint->getTextSize(),
            style.getWeight() * 100,
            style.getItalic() ? "italic" : "normal");
        layout.setProperties(css);
        MinikinUtils::SetLayoutProperties(&layout, paint, typeface);
        layout.doLayout(textArray + start, count);
        drawGlyphsToSkia(canvas, paint, &layout, x, y);
#else
+75 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "Minikin"

#include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h>

#include "SkTypeface.h"
#include "GraphicsJNI.h"
#include <ScopedPrimitiveArray.h>
#include <ScopedUtfChars.h>

#ifdef USE_MINIKIN
#include <minikin/FontFamily.h>
#include "MinikinSkia.h"
#endif

namespace android {

static jlong FontFamily_create(JNIEnv* env, jobject clazz) {
#ifdef USE_MINIKIN
    return (jlong)new FontFamily();
#else
    return 0;
#endif
}

static void FontFamily_destroy(JNIEnv* env, jobject clazz, jlong ptr) {
    // TODO: work out lifetime issues
}

static jboolean FontFamily_addFont(JNIEnv* env, jobject clazz, jlong familyPtr, jstring path) {
#ifdef USE_MINIKIN
    NPE_CHECK_RETURN_ZERO(env, path);
    ScopedUtfChars str(env, path);
    ALOGD("addFont %s", str.c_str());
    SkTypeface* face = SkTypeface::CreateFromFile(str.c_str());
    MinikinFont* minikinFont = new MinikinFontSkia(face);
    FontFamily* fontFamily = (FontFamily*)familyPtr;
    return fontFamily->addFont(minikinFont);
#else
    return false;
#endif
}

///////////////////////////////////////////////////////////////////////////////

static JNINativeMethod gFontFamilyMethods[] = {
    { "nCreateFamily",            "()J", (void*)FontFamily_create },
    { "nDestroyFamily",           "(J)V", (void*)FontFamily_destroy },
    { "nAddFont",                 "(JLjava/lang/String;)Z", (void*)FontFamily_addFont },
};

int register_android_graphics_FontFamily(JNIEnv* env)
{
    return android::AndroidRuntime::registerNativeMethods(env,
        "android/graphics/FontFamily",
        gFontFamilyMethods, NELEM(gFontFamilyMethods));
}

}
Loading