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

Commit 194f3759 authored by Seigo Nonaka's avatar Seigo Nonaka Committed by Android (Google) Code Review
Browse files

Merge "Follow Minikin's signature changes."

parents a955c9df c7064146
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -63,27 +63,27 @@ static jlong FontFamily_create(jlong builderPtr) {
        return 0;
    }
    NativeFamilyBuilder* builder = reinterpret_cast<NativeFamilyBuilder*>(builderPtr);
    minikin::FontFamily* family = new minikin::FontFamily(
            builder->langId, builder->variant, std::move(builder->fonts));
    FontFamilyWrapper* family = new FontFamilyWrapper(
            std::make_shared<minikin::FontFamily>(
                    builder->langId, builder->variant, std::move(builder->fonts)));
    delete builder;
    return reinterpret_cast<jlong>(family);
}

static void FontFamily_abort(jlong builderPtr) {
    NativeFamilyBuilder* builder = reinterpret_cast<NativeFamilyBuilder*>(builderPtr);
    minikin::Font::clearElementsWithLock(&builder->fonts);
    delete builder;
}

static void FontFamily_unref(jlong familyPtr) {
    minikin::FontFamily* fontFamily = reinterpret_cast<minikin::FontFamily*>(familyPtr);
    fontFamily->Unref();
    FontFamilyWrapper* family = reinterpret_cast<FontFamilyWrapper*>(familyPtr);
    delete family;
}

static void addSkTypeface(jlong builderPtr, sk_sp<SkTypeface> face, const void* fontData,
        size_t fontSize, int ttcIndex, jint givenWeight, jboolean givenItalic) {
    minikin::MinikinFont* minikinFont =
            new MinikinFontSkia(std::move(face), fontData, fontSize, ttcIndex,
    std::shared_ptr<minikin::MinikinFont> minikinFont =
            std::make_shared<MinikinFontSkia>(std::move(face), fontData, fontSize, ttcIndex,
                    std::vector<minikin::FontVariation>());
    NativeFamilyBuilder* builder = reinterpret_cast<NativeFamilyBuilder*>(builderPtr);
    int weight = givenWeight / 100;
@@ -96,8 +96,8 @@ static void addSkTypeface(jlong builderPtr, sk_sp<SkTypeface> face, const void*
        }
    }

    builder->fonts.push_back(minikin::Font(minikinFont, minikin::FontStyle(weight, italic)));
    minikinFont->Unref();
    builder->fonts.push_back(minikin::Font(
            std::move(minikinFont), minikin::FontStyle(weight, italic)));
}

static void release_global_ref(const void* /*data*/, void* context) {
@@ -208,13 +208,12 @@ static jboolean FontFamily_addFontWeightStyle(JNIEnv* env, jobject clazz, jlong
        ALOGE("addFont failed to create font, invalid request");
        return false;
    }
    minikin::MinikinFont* minikinFont =
            new MinikinFontSkia(std::move(face), fontPtr, fontSize, ttcIndex,
    std::shared_ptr<minikin::MinikinFont> minikinFont =
            std::make_shared<MinikinFontSkia>(std::move(face), fontPtr, fontSize, ttcIndex,
                    std::vector<minikin::FontVariation>());
    NativeFamilyBuilder* builder = reinterpret_cast<NativeFamilyBuilder*>(builderPtr);
    builder->fonts.push_back(minikin::Font(minikinFont,
    builder->fonts.push_back(minikin::Font(std::move(minikinFont),
            minikin::FontStyle(weight / 100, isItalic)));
    minikinFont->Unref();
    return true;
}

+10 −0
Original line number Diff line number Diff line
@@ -18,9 +18,19 @@
#define _ANDROID_GRAPHICS_FONT_UTILS_H_

#include <jni.h>
#include <memory>

namespace minikin {
class FontFamily;
}  // namespace minikin

namespace android {

struct FontFamilyWrapper {
  FontFamilyWrapper(std::shared_ptr<minikin::FontFamily>&& family) : family(family) {}
  std::shared_ptr<minikin::FontFamily> family;
};

// Utility wrapper for java.util.List
class ListHelper {
public:
+8 −9
Original line number Diff line number Diff line
@@ -300,8 +300,8 @@ namespace PaintGlue {

    static void getTextPath(JNIEnv* env, Paint* paint, Typeface* typeface, const jchar* text,
            jint count, jint bidiFlags, jfloat x, jfloat y, SkPath* path) {
        minikin::Layout layout;
        MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, text, 0, count, count);
        minikin::Layout layout = MinikinUtils::doLayout(
                paint, bidiFlags, typeface, text, 0, count, count);
        size_t nGlyphs = layout.nGlyphs();
        uint16_t* glyphs = new uint16_t[nGlyphs];
        SkPoint* pos = new SkPoint[nGlyphs];
@@ -344,8 +344,8 @@ namespace PaintGlue {
        SkRect  r;
        SkIRect ir;

        minikin::Layout layout;
        MinikinUtils::doLayout(&layout, &paint, bidiFlags, typeface, text, 0, count, count);
        minikin::Layout layout = MinikinUtils::doLayout(
                &paint, bidiFlags, typeface, text, 0, count, count);
        minikin::MinikinRect rect;
        layout.getBounds(&rect);
        r.fLeft = rect.mLeft;
@@ -459,9 +459,8 @@ namespace PaintGlue {
            nChars++;
            prevCp = cp;
        }
        minikin::Layout layout;
        MinikinUtils::doLayout(&layout, paint, bidiFlags, typeface, str.get(), 0, str.size(),
                str.size());
        minikin::Layout layout = MinikinUtils::doLayout(
                paint, bidiFlags, typeface, str.get(), 0, str.size(), str.size());
        size_t nGlyphs = countNonSpaceGlyphs(layout);
        if (nGlyphs != 1 && nChars > 1) {
            // multiple-character input, and was not a ligature
@@ -480,8 +479,8 @@ namespace PaintGlue {
            // since ZZ is reserved for unknown or invalid territory.
            // U+1F1FF (REGIONAL INDICATOR SYMBOL LETTER Z) is \uD83C\uDDFF in UTF16.
            static const jchar ZZ_FLAG_STR[] = { 0xD83C, 0xDDFF, 0xD83C, 0xDDFF };
            minikin::Layout zzLayout;
            MinikinUtils::doLayout(&zzLayout, paint, bidiFlags, typeface, ZZ_FLAG_STR, 0, 4, 4);
            minikin::Layout zzLayout = MinikinUtils::doLayout(
                    paint, bidiFlags, typeface, ZZ_FLAG_STR, 0, 4, 4);
            if (zzLayout.nGlyphs() != 1 || layoutContainsNotdef(zzLayout)) {
                // The font collection doesn't have a glyph for unknown flag. Just return true.
                return true;
+6 −7
Original line number Diff line number Diff line
@@ -67,9 +67,7 @@ static jlong Typeface_createWeightAlias(JNIEnv* env, jobject, jlong familyHandle

static void Typeface_unref(JNIEnv* env, jobject obj, jlong faceHandle) {
    Typeface* face = reinterpret_cast<Typeface*>(faceHandle);
    if (face != NULL) {
        face->unref();
    }
    delete face;
}

static jint Typeface_getStyle(JNIEnv* env, jobject obj, jlong faceHandle) {
@@ -79,12 +77,13 @@ static jint Typeface_getStyle(JNIEnv* env, jobject obj, jlong faceHandle) {

static jlong Typeface_createFromArray(JNIEnv *env, jobject, jlongArray familyArray) {
    ScopedLongArrayRO families(env, familyArray);
    std::vector<minikin::FontFamily*> familyVec;
    std::vector<std::shared_ptr<minikin::FontFamily>> familyVec;
    familyVec.reserve(families.size());
    for (size_t i = 0; i < families.size(); i++) {
        minikin::FontFamily* family = reinterpret_cast<minikin::FontFamily*>(families[i]);
        familyVec.push_back(family);
        FontFamilyWrapper* family = reinterpret_cast<FontFamilyWrapper*>(families[i]);
        familyVec.emplace_back(family->family);
    }
    return reinterpret_cast<jlong>(Typeface::createFromFamilies(familyVec));
    return reinterpret_cast<jlong>(Typeface::createFromFamilies(std::move(familyVec)));
}

static void Typeface_setDefault(JNIEnv *env, jobject, jlong faceHandle) {
+4 −3
Original line number Diff line number Diff line
@@ -159,11 +159,12 @@ static jfloat nAddStyleRun(JNIEnv* env, jclass, jlong nativePtr,
    minikin::LineBreaker* b = reinterpret_cast<minikin::LineBreaker*>(nativePtr);
    Paint* paint = reinterpret_cast<Paint*>(nativePaint);
    Typeface* typeface = reinterpret_cast<Typeface*>(nativeTypeface);
    minikin::FontCollection *font;
    minikin::MinikinPaint minikinPaint;
    minikin::FontStyle style = MinikinUtils::prepareMinikinPaint(&minikinPaint, &font, paint,
    Typeface* resolvedTypeface = Typeface::resolveDefault(typeface);
    minikin::FontStyle style = MinikinUtils::prepareMinikinPaint(&minikinPaint, paint,
            typeface);
    return b->addStyleRun(&minikinPaint, font, style, start, end, isRtl);
    return b->addStyleRun(&minikinPaint, resolvedTypeface->fFontCollection, style, start, end,
            isRtl);
}

// Accept width measurements for the run, passed in from Java
Loading