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

Commit 5d446ec5 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Stop supporting broken font fallback"

parents 4d41f291 fcd2af9c
Loading
Loading
Loading
Loading
+5 −13
Original line number Diff line number Diff line
@@ -44,11 +44,9 @@ namespace android {

struct NativeFamilyBuilder {
    NativeFamilyBuilder(uint32_t langId, int variant)
        : langId(langId), variant(static_cast<minikin::FontFamily::Variant>(variant)),
          allowUnsupportedFont(false) {}
        : langId(langId), variant(static_cast<minikin::FontFamily::Variant>(variant)) {}
    uint32_t langId;
    minikin::FontFamily::Variant variant;
    bool allowUnsupportedFont;
    std::vector<minikin::Font> fonts;
    std::vector<minikin::FontVariation> axes;
};
@@ -70,22 +68,17 @@ static jlong FontFamily_create(jlong builderPtr) {
    }
    std::unique_ptr<NativeFamilyBuilder> builder(
            reinterpret_cast<NativeFamilyBuilder*>(builderPtr));
    if (builder->fonts.empty()) {
        return 0;
    }
    std::shared_ptr<minikin::FontFamily> family = std::make_shared<minikin::FontFamily>(
            builder->langId, builder->variant, std::move(builder->fonts));
    if (family->getCoverage().length() == 0 && !builder->allowUnsupportedFont) {
    if (family->getCoverage().length() == 0) {
        return 0;
    }
    return reinterpret_cast<jlong>(new FontFamilyWrapper(std::move(family)));
}

static void FontFamily_allowUnsupportedFont(jlong builderPtr) {
    if (builderPtr == 0) {
        return;
    }
    NativeFamilyBuilder* builder = reinterpret_cast<NativeFamilyBuilder*>(builderPtr);
    builder->allowUnsupportedFont = true;
}

static void FontFamily_abort(jlong builderPtr) {
    NativeFamilyBuilder* builder = reinterpret_cast<NativeFamilyBuilder*>(builderPtr);
    delete builder;
@@ -270,7 +263,6 @@ static void FontFamily_addAxisValue(jlong builderPtr, jint tag, jfloat value) {
static const JNINativeMethod gFontFamilyMethods[] = {
    { "nInitBuilder",          "(Ljava/lang/String;I)J", (void*)FontFamily_initBuilder },
    { "nCreateFamily",         "(J)J", (void*)FontFamily_create },
    { "nAllowUnsupportedFont", "(J)V", (void*)FontFamily_allowUnsupportedFont },
    { "nAbort",                "(J)V", (void*)FontFamily_abort },
    { "nUnrefFamily",          "(J)V", (void*)FontFamily_unref },
    { "nAddFont",              "(JLjava/nio/ByteBuffer;III)Z", (void*)FontFamily_addFont },
+0 −22
Original line number Diff line number Diff line
@@ -160,25 +160,6 @@ public class FontFamily {
                isItalic);
    }

    /**
     * Allow creating unsupported FontFamily.
     *
     * For compatibility reasons, we still need to create a FontFamily object even if Minikin failed
     * to find any usable 'cmap' table for some reasons, e.g. broken 'cmap' table, no 'cmap' table
     * encoded with Unicode code points, etc. Without calling this method, the freeze() method will
     * return null if Minikin fails to find any usable 'cmap' table. By calling this method, the
     * freeze() won't fail and will create an empty FontFamily. This empty FontFamily is placed at
     * the top of the fallback chain but is never used. if we don't create this empty FontFamily
     * and put it at top, bad things (performance regressions, unexpected glyph selection) will
     * happen.
     */
    public void allowUnsupportedFont() {
        if (mBuilderPtr == 0) {
            throw new IllegalStateException("Unable to allow unsupported font.");
        }
        nAllowUnsupportedFont(mBuilderPtr);
    }

    // TODO: Remove once internal user stop using private API.
    private static boolean nAddFont(long builderPtr, ByteBuffer font, int ttcIndex) {
        return nAddFont(builderPtr, font, ttcIndex, -1, -1);
@@ -189,9 +170,6 @@ public class FontFamily {
    @CriticalNative
    private static native long nCreateFamily(long mBuilderPtr);

    @CriticalNative
    private static native void nAllowUnsupportedFont(long builderPtr);

    @CriticalNative
    private static native void nAbort(long mBuilderPtr);

+6 −12
Original line number Diff line number Diff line
@@ -818,12 +818,9 @@ public class Typeface {
            if (fontFamily.addFontFromAssetManager(mgr, path, 0, true /* isAsset */,
                    0 /* ttc index */, RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE,
                    null /* axes */)) {
                // Due to backward compatibility, even if the font is not supported by our font
                // stack, we need to place the empty font at the first place. The typeface with
                // empty font behaves different from default typeface especially in fallback
                // font selection.
                fontFamily.allowUnsupportedFont();
                fontFamily.freeze();
                if (!fontFamily.freeze()) {
                    return Typeface.DEFAULT;
                }
                final FontFamily[] families = { fontFamily };
                typeface = createFromFamiliesWithDefault(families, DEFAULT_FAMILY,
                        RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE);
@@ -870,12 +867,9 @@ public class Typeface {
        final FontFamily fontFamily = new FontFamily();
        if (fontFamily.addFont(path, 0 /* ttcIndex */, null /* axes */,
                  RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE)) {
            // Due to backward compatibility, even if the font is not supported by our font
            // stack, we need to place the empty font at the first place. The typeface with
            // empty font behaves different from default typeface especially in fallback font
            // selection.
            fontFamily.allowUnsupportedFont();
            fontFamily.freeze();
            if (!fontFamily.freeze()) {
                return Typeface.DEFAULT;
            }
            FontFamily[] families = { fontFamily };
            return createFromFamiliesWithDefault(families, DEFAULT_FAMILY,
                    RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE);