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

Commit 2763fb72 authored by Ben Wagner's avatar Ben Wagner
Browse files

Use own enum instead of SkTypeface::Style.

The current use of SkTypeface::Style and the naming of
Typeface::fSkiaStyle are misleading. Neither is used to actually
interact with Skia (which no longer uses the type in its API). Instead,
this type and field are used to track the values which will be exposed
through the jni layer which match the Android SDK values for the
constants on the android.graphics.Typeface type.

This change allows Skia to hide and eventually remove SkTypeface::Style,
as this is the last known external user. Additionally this allows
Android an easier path when updating the Typeface API in the future.

Test: refactoring CL. Existing unit tests still pass.
Change-Id: Ic820105a5b0d98727586fdc4a9a1c45e8ad40ff3
parent 34e83d28
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -30,14 +30,14 @@ using namespace android;

static jlong Typeface_createFromTypeface(JNIEnv* env, jobject, jlong familyHandle, jint style) {
    Typeface* family = reinterpret_cast<Typeface*>(familyHandle);
    Typeface* face = Typeface::createRelative(family, (SkTypeface::Style)style);
    Typeface* face = Typeface::createRelative(family, (Typeface::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 = Typeface::createRelative(family, (SkTypeface::Style)(style ^ SkTypeface::kItalic));
        face = Typeface::createRelative(family, (Typeface::Style)(style ^ Typeface::kItalic));
    }
    for (int i = 0; NULL == face && i < 4; i++) {
        face = Typeface::createRelative(family, (SkTypeface::Style)i);
        face = Typeface::createRelative(family, (Typeface::Style)i);
    }
    return reinterpret_cast<jlong>(face);
}
@@ -78,7 +78,7 @@ static void Typeface_unref(JNIEnv* env, jobject obj, jlong faceHandle) {

static jint Typeface_getStyle(JNIEnv* env, jobject obj, jlong faceHandle) {
    Typeface* face = reinterpret_cast<Typeface*>(faceHandle);
    return face->fSkiaStyle;
    return face->fAPIStyle;
}

static jint Typeface_getWeight(JNIEnv* env, jobject obj, jlong faceHandle) {
+14 −14
Original line number Diff line number Diff line
@@ -34,12 +34,12 @@

namespace android {

static SkTypeface::Style computeSkiaStyle(int weight, bool italic) {
static Typeface::Style computeAPIStyle(int weight, bool italic) {
    // This bold detection comes from SkTypeface.h
    if (weight >= SkFontStyle::kSemiBold_Weight) {
        return italic ? SkTypeface::kBoldItalic : SkTypeface::kBold;
        return italic ? Typeface::kBoldItalic : Typeface::kBold;
    } else {
        return italic ? SkTypeface::kItalic : SkTypeface::kNormal;
        return italic ? Typeface::kItalic : Typeface::kNormal;
    }
}

@@ -50,12 +50,12 @@ static minikin::FontStyle computeMinikinStyle(int weight, bool italic) {
}

// Resolve the relative weight from the baseWeight and target style.
static minikin::FontStyle computeRelativeStyle(int baseWeight, SkTypeface::Style relativeStyle) {
static minikin::FontStyle computeRelativeStyle(int baseWeight, Typeface::Style relativeStyle) {
    int weight = baseWeight;
    if ((relativeStyle & SkTypeface::kBold) != 0) {
    if ((relativeStyle & Typeface::kBold) != 0) {
        weight += 300;
    }
    bool italic = (relativeStyle & SkTypeface::kItalic) != 0;
    bool italic = (relativeStyle & Typeface::kItalic) != 0;
    return computeMinikinStyle(weight, italic);
}

@@ -66,13 +66,13 @@ const Typeface* Typeface::resolveDefault(const Typeface* src) {
    return src == nullptr ? gDefaultTypeface : src;
}

Typeface* Typeface::createRelative(Typeface* src, SkTypeface::Style style) {
Typeface* Typeface::createRelative(Typeface* src, Typeface::Style style) {
    const Typeface* resolvedFace = Typeface::resolveDefault(src);
    Typeface* result = new Typeface;
    if (result != nullptr) {
        result->fFontCollection = resolvedFace->fFontCollection;
        result->fBaseWeight = resolvedFace->fBaseWeight;
        result->fSkiaStyle = style;
        result->fAPIStyle = style;
        result->fStyle = computeRelativeStyle(result->fBaseWeight, style);
    }
    return result;
@@ -84,7 +84,7 @@ Typeface* Typeface::createAbsolute(Typeface* base, int weight, bool italic) {
    if (result != nullptr) {
        result->fFontCollection = resolvedFace->fFontCollection;
        result->fBaseWeight = resolvedFace->fBaseWeight;
        result->fSkiaStyle = computeSkiaStyle(weight, italic);
        result->fAPIStyle = computeAPIStyle(weight, italic);
        result->fStyle = computeMinikinStyle(weight, italic);
    }
    return result;
@@ -105,7 +105,7 @@ Typeface* Typeface::createFromTypefaceWithVariation(Typeface* src,
        // Do not update styles.
        // TODO: We may want to update base weight if the 'wght' is specified.
        result->fBaseWeight = resolvedFace->fBaseWeight;
        result->fSkiaStyle = resolvedFace->fSkiaStyle;
        result->fAPIStyle = resolvedFace->fAPIStyle;
        result->fStyle = resolvedFace->fStyle;
    }
    return result;
@@ -117,8 +117,8 @@ Typeface* Typeface::createWithDifferentBaseWeight(Typeface* src, int weight) {
    if (result != nullptr) {
        result->fFontCollection = resolvedFace->fFontCollection;
        result->fBaseWeight = weight;
        result->fSkiaStyle = resolvedFace->fSkiaStyle;
        result->fStyle = computeRelativeStyle(weight, result->fSkiaStyle);
        result->fAPIStyle = resolvedFace->fAPIStyle;
        result->fStyle = computeRelativeStyle(weight, result->fAPIStyle);
    }
    return result;
}
@@ -161,7 +161,7 @@ Typeface* Typeface::createFromFamilies(
    }

    result->fBaseWeight = weight;
    result->fSkiaStyle = computeSkiaStyle(weight, italic);
    result->fAPIStyle = computeAPIStyle(weight, italic);
    result->fStyle = computeMinikinStyle(weight, italic);
    return result;
}
@@ -191,7 +191,7 @@ void Typeface::setRobotoTypefaceForTest() {

    Typeface* hwTypeface = new Typeface();
    hwTypeface->fFontCollection = collection;
    hwTypeface->fSkiaStyle = SkTypeface::kNormal;
    hwTypeface->fAPIStyle = Typeface::kNormal;
    hwTypeface->fBaseWeight = SkFontStyle::kNormal_Weight;
    hwTypeface->fStyle = minikin::FontStyle(4 /* weight */, false /* italic */);

+9 −3
Original line number Diff line number Diff line
@@ -38,8 +38,14 @@ struct ANDROID_API Typeface {
    // resolved style actually used for rendering
    minikin::FontStyle fStyle;

    // style used for constructing and querying Typeface objects
    SkTypeface::Style fSkiaStyle;
    // style used in the API
    enum Style : uint8_t {
        kNormal = 0,
        kBold   = 0x01,
        kItalic = 0x02,
        kBoldItalic = 0x03
    };
    Style fAPIStyle;

    static const Typeface* resolveDefault(const Typeface* src);

@@ -68,7 +74,7 @@ struct ANDROID_API Typeface {
    //
    //   Typeface* black = createAbsolute(base, 900, false);  // Rendered with a weight of 900.
    static Typeface* createWithDifferentBaseWeight(Typeface* src, int baseweight);
    static Typeface* createRelative(Typeface* src, SkTypeface::Style desiredStyle);
    static Typeface* createRelative(Typeface* src, Style desiredStyle);
    static Typeface* createAbsolute(Typeface* base, int weight, bool italic);

    static Typeface* createFromTypefaceWithVariation(Typeface* src,
+66 −66
Original line number Diff line number Diff line
@@ -84,159 +84,159 @@ TEST(TypefaceTest, createWithDifferentBaseWeight) {
    std::unique_ptr<Typeface> bold(Typeface::createWithDifferentBaseWeight(nullptr, 700));
    EXPECT_EQ(7, bold->fStyle.getWeight());
    EXPECT_FALSE(bold->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kNormal, bold->fSkiaStyle);
    EXPECT_EQ(Typeface::kNormal, bold->fAPIStyle);

    std::unique_ptr<Typeface> light(Typeface::createWithDifferentBaseWeight(nullptr, 300));
    EXPECT_EQ(3, light->fStyle.getWeight());
    EXPECT_FALSE(light->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kNormal, light->fSkiaStyle);
    EXPECT_EQ(Typeface::kNormal, light->fAPIStyle);
}

TEST(TypefaceTest, createRelativeTest_fromRegular) {
    // In Java, Typeface.create(Typeface.DEFAULT, Typeface.NORMAL);
    std::unique_ptr<Typeface> normal(Typeface::createRelative(nullptr, SkTypeface::kNormal));
    std::unique_ptr<Typeface> normal(Typeface::createRelative(nullptr, Typeface::kNormal));
    EXPECT_EQ(4, normal->fStyle.getWeight());
    EXPECT_FALSE(normal->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kNormal, normal->fSkiaStyle);
    EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle);

    // In Java, Typeface.create(Typeface.DEFAULT, Typeface.BOLD);
    std::unique_ptr<Typeface> bold(Typeface::createRelative(nullptr, SkTypeface::kBold));
    std::unique_ptr<Typeface> bold(Typeface::createRelative(nullptr, Typeface::kBold));
    EXPECT_EQ(7, bold->fStyle.getWeight());
    EXPECT_FALSE(bold->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBold, bold->fSkiaStyle);
    EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);

    // In Java, Typeface.create(Typeface.DEFAULT, Typeface.ITALIC);
    std::unique_ptr<Typeface> italic(Typeface::createRelative(nullptr, SkTypeface::kItalic));
    std::unique_ptr<Typeface> italic(Typeface::createRelative(nullptr, Typeface::kItalic));
    EXPECT_EQ(4, italic->fStyle.getWeight());
    EXPECT_TRUE(italic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kItalic, italic->fSkiaStyle);
    EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);

    // In Java, Typeface.create(Typeface.DEFAULT, Typeface.BOLD_ITALIC);
    std::unique_ptr<Typeface> boldItalic(
            Typeface::createRelative(nullptr, SkTypeface::kBoldItalic));
            Typeface::createRelative(nullptr, Typeface::kBoldItalic));
    EXPECT_EQ(7, boldItalic->fStyle.getWeight());
    EXPECT_TRUE(boldItalic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBoldItalic, boldItalic->fSkiaStyle);
    EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle);
}

TEST(TypefaceTest, createRelativeTest_BoldBase) {
    std::unique_ptr<Typeface> base(Typeface::createWithDifferentBaseWeight(nullptr, 700));

    // In Java, Typeface.create(Typeface.create("sans-serif-bold"), Typeface.NORMAL);
    std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), SkTypeface::kNormal));
    std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal));
    EXPECT_EQ(7, normal->fStyle.getWeight());
    EXPECT_FALSE(normal->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kNormal, normal->fSkiaStyle);
    EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle);

    // In Java, Typeface.create(Typeface.create("sans-serif-bold"), Typeface.BOLD);
    std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), SkTypeface::kBold));
    std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold));
    EXPECT_EQ(10, bold->fStyle.getWeight());
    EXPECT_FALSE(bold->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBold, bold->fSkiaStyle);
    EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);

    // In Java, Typeface.create(Typeface.create("sans-serif-bold"), Typeface.ITALIC);
    std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), SkTypeface::kItalic));
    std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic));
    EXPECT_EQ(7, italic->fStyle.getWeight());
    EXPECT_TRUE(italic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kItalic, italic->fSkiaStyle);
    EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);

    // In Java, Typeface.create(Typeface.create("sans-serif-bold"), Typeface.BOLD_ITALIC);
    std::unique_ptr<Typeface>
            boldItalic(Typeface::createRelative(base.get(), SkTypeface::kBoldItalic));
            boldItalic(Typeface::createRelative(base.get(), Typeface::kBoldItalic));
    EXPECT_EQ(10, boldItalic->fStyle.getWeight());
    EXPECT_TRUE(boldItalic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBoldItalic, boldItalic->fSkiaStyle);
    EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle);
}

TEST(TypefaceTest, createRelativeTest_LightBase) {
    std::unique_ptr<Typeface> base(Typeface::createWithDifferentBaseWeight(nullptr, 300));

    // In Java, Typeface.create(Typeface.create("sans-serif-light"), Typeface.NORMAL);
    std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), SkTypeface::kNormal));
    std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal));
    EXPECT_EQ(3, normal->fStyle.getWeight());
    EXPECT_FALSE(normal->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kNormal, normal->fSkiaStyle);
    EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle);

    // In Java, Typeface.create(Typeface.create("sans-serif-light"), Typeface.BOLD);
    std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), SkTypeface::kBold));
    std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold));
    EXPECT_EQ(6, bold->fStyle.getWeight());
    EXPECT_FALSE(bold->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBold, bold->fSkiaStyle);
    EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);

    // In Java, Typeface.create(Typeface.create("sans-serif-light"), Typeface.ITLIC);
    std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), SkTypeface::kItalic));
    std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic));
    EXPECT_EQ(3, italic->fStyle.getWeight());
    EXPECT_TRUE(italic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kItalic, italic->fSkiaStyle);
    EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);

    // In Java, Typeface.create(Typeface.create("sans-serif-light"), Typeface.BOLD_ITALIC);
    std::unique_ptr<Typeface>
            boldItalic(Typeface::createRelative(base.get(), SkTypeface::kBoldItalic));
            boldItalic(Typeface::createRelative(base.get(), Typeface::kBoldItalic));
    EXPECT_EQ(6, boldItalic->fStyle.getWeight());
    EXPECT_TRUE(boldItalic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBoldItalic, boldItalic->fSkiaStyle);
    EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle);
}

TEST(TypefaceTest, createRelativeTest_fromBoldStyled) {
    std::unique_ptr<Typeface> base(Typeface::createRelative(nullptr, SkTypeface::kBold));
    std::unique_ptr<Typeface> base(Typeface::createRelative(nullptr, Typeface::kBold));

    // In Java, Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD), Typeface.NORMAL);
    std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), SkTypeface::kNormal));
    std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal));
    EXPECT_EQ(4, normal->fStyle.getWeight());
    EXPECT_FALSE(normal->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kNormal, normal->fSkiaStyle);
    EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle);

    // In Java Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD), Typeface.BOLD);
    std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), SkTypeface::kBold));
    std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold));
    EXPECT_EQ(7, bold->fStyle.getWeight());
    EXPECT_FALSE(bold->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBold, bold->fSkiaStyle);
    EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);

    // In Java, Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD), Typeface.ITALIC);
    std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), SkTypeface::kItalic));
    std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic));
    EXPECT_EQ(4, normal->fStyle.getWeight());
    EXPECT_TRUE(italic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kItalic, italic->fSkiaStyle);
    EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);

    // In Java,
    // Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD), Typeface.BOLD_ITALIC);
    std::unique_ptr<Typeface>
            boldItalic(Typeface::createRelative(base.get(), SkTypeface::kBoldItalic));
            boldItalic(Typeface::createRelative(base.get(), Typeface::kBoldItalic));
    EXPECT_EQ(7, boldItalic->fStyle.getWeight());
    EXPECT_TRUE(boldItalic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBoldItalic, boldItalic->fSkiaStyle);
    EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle);
}

TEST(TypefaceTest, createRelativeTest_fromItalicStyled) {
    std::unique_ptr<Typeface> base(Typeface::createRelative(nullptr, SkTypeface::kItalic));
    std::unique_ptr<Typeface> base(Typeface::createRelative(nullptr, Typeface::kItalic));

    // In Java,
    // Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC), Typeface.NORMAL);
    std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), SkTypeface::kNormal));
    std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal));
    EXPECT_EQ(4, normal->fStyle.getWeight());
    EXPECT_FALSE(normal->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kNormal, normal->fSkiaStyle);
    EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle);

    // In Java, Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC), Typeface.BOLD);
    std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), SkTypeface::kBold));
    std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold));
    EXPECT_EQ(7, bold->fStyle.getWeight());
    EXPECT_FALSE(bold->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBold, bold->fSkiaStyle);
    EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);

    // In Java,
    // Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC), Typeface.ITALIC);
    std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), SkTypeface::kItalic));
    std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic));
    EXPECT_EQ(4, italic->fStyle.getWeight());
    EXPECT_TRUE(italic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kItalic, italic->fSkiaStyle);
    EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);

    // In Java,
    // Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC), Typeface.BOLD_ITALIC);
    std::unique_ptr<Typeface>
            boldItalic(Typeface::createRelative(base.get(), SkTypeface::kBoldItalic));
            boldItalic(Typeface::createRelative(base.get(), Typeface::kBoldItalic));
    EXPECT_EQ(7, boldItalic->fStyle.getWeight());
    EXPECT_TRUE(boldItalic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBoldItalic, boldItalic->fSkiaStyle);
    EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle);
}

TEST(TypefaceTest, createRelativeTest_fromSpecifiedStyled) {
@@ -246,38 +246,38 @@ TEST(TypefaceTest, createRelativeTest_fromSpecifiedStyled) {
    // Typeface typeface = new Typeface.Builder(invalid).setFallback("sans-serif")
    //     .setWeight(700).setItalic(false).build();
    // Typeface.create(typeface, Typeface.NORMAL);
    std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), SkTypeface::kNormal));
    std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal));
    EXPECT_EQ(4, normal->fStyle.getWeight());
    EXPECT_FALSE(normal->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kNormal, normal->fSkiaStyle);
    EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle);

    // In Java,
    // Typeface typeface = new Typeface.Builder(invalid).setFallback("sans-serif")
    //     .setWeight(700).setItalic(false).build();
    // Typeface.create(typeface, Typeface.BOLD);
    std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), SkTypeface::kBold));
    std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold));
    EXPECT_EQ(7, bold->fStyle.getWeight());
    EXPECT_FALSE(bold->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBold, bold->fSkiaStyle);
    EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);

    // In Java,
    // Typeface typeface = new Typeface.Builder(invalid).setFallback("sans-serif")
    //     .setWeight(700).setItalic(false).build();
    // Typeface.create(typeface, Typeface.ITALIC);
    std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), SkTypeface::kItalic));
    std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic));
    EXPECT_EQ(4, italic->fStyle.getWeight());
    EXPECT_TRUE(italic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kItalic, italic->fSkiaStyle);
    EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);

    // In Java,
    // Typeface typeface = new Typeface.Builder(invalid).setFallback("sans-serif")
    //     .setWeight(700).setItalic(false).build();
    // Typeface.create(typeface, Typeface.BOLD_ITALIC);
    std::unique_ptr<Typeface>
            boldItalic(Typeface::createRelative(base.get(), SkTypeface::kBoldItalic));
            boldItalic(Typeface::createRelative(base.get(), Typeface::kBoldItalic));
    EXPECT_EQ(7, boldItalic->fStyle.getWeight());
    EXPECT_TRUE(boldItalic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBoldItalic, boldItalic->fSkiaStyle);
    EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle);
}

TEST(TypefaceTest, createAbsolute) {
@@ -287,7 +287,7 @@ TEST(TypefaceTest, createAbsolute) {
    std::unique_ptr<Typeface> regular(Typeface::createAbsolute(nullptr, 400, false));
    EXPECT_EQ(4, regular->fStyle.getWeight());
    EXPECT_FALSE(regular->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kNormal, regular->fSkiaStyle);
    EXPECT_EQ(Typeface::kNormal, regular->fAPIStyle);

    // In Java,
    // new Typeface.Builder(invalid).setFallback("sans-serif").setWeight(700).setItalic(false)
@@ -295,7 +295,7 @@ TEST(TypefaceTest, createAbsolute) {
    std::unique_ptr<Typeface> bold(Typeface::createAbsolute(nullptr, 700, false));
    EXPECT_EQ(7, bold->fStyle.getWeight());
    EXPECT_FALSE(bold->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBold, bold->fSkiaStyle);
    EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);

    // In Java,
    // new Typeface.Builder(invalid).setFallback("sans-serif").setWeight(400).setItalic(true)
@@ -303,7 +303,7 @@ TEST(TypefaceTest, createAbsolute) {
    std::unique_ptr<Typeface> italic(Typeface::createAbsolute(nullptr, 400, true));
    EXPECT_EQ(4, italic->fStyle.getWeight());
    EXPECT_TRUE(italic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kItalic, italic->fSkiaStyle);
    EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);

    // In Java,
    // new Typeface.Builder(invalid).setFallback("sans-serif").setWeight(700).setItalic(true)
@@ -311,7 +311,7 @@ TEST(TypefaceTest, createAbsolute) {
    std::unique_ptr<Typeface> boldItalic(Typeface::createAbsolute(nullptr, 700, true));
    EXPECT_EQ(7, boldItalic->fStyle.getWeight());
    EXPECT_TRUE(boldItalic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBoldItalic, boldItalic->fSkiaStyle);
    EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle);

    // In Java,
    // new Typeface.Builder(invalid).setFallback("sans-serif").setWeight(1100).setItalic(true)
@@ -319,7 +319,7 @@ TEST(TypefaceTest, createAbsolute) {
    std::unique_ptr<Typeface> over1000(Typeface::createAbsolute(nullptr, 1100, false));
    EXPECT_EQ(10, over1000->fStyle.getWeight());
    EXPECT_FALSE(over1000->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBold, over1000->fSkiaStyle);
    EXPECT_EQ(Typeface::kBold, over1000->fAPIStyle);
}

TEST(TypefaceTest, createFromFamilies_Single) {
@@ -328,21 +328,21 @@ TEST(TypefaceTest, createFromFamilies_Single) {
            Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoRegular), 400, false));
    EXPECT_EQ(4, regular->fStyle.getWeight());
    EXPECT_FALSE(regular->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kNormal, regular->fSkiaStyle);
    EXPECT_EQ(Typeface::kNormal, regular->fAPIStyle);

    // In Java, new Typeface.Builder("Roboto-Bold.ttf").setWeight(700).setItalic(false).build();
    std::unique_ptr<Typeface> bold(
            Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoBold), 700, false));
    EXPECT_EQ(7, bold->fStyle.getWeight());
    EXPECT_FALSE(bold->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBold, bold->fSkiaStyle);
    EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);

    // In Java, new Typeface.Builder("Roboto-Italic.ttf").setWeight(400).setItalic(true).build();
    std::unique_ptr<Typeface> italic(
            Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoItalic), 400, true));
    EXPECT_EQ(4, italic->fStyle.getWeight());
    EXPECT_TRUE(italic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kItalic, italic->fSkiaStyle);
    EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);

    // In Java,
    // new Typeface.Builder("Roboto-BoldItalic.ttf").setWeight(700).setItalic(true).build();
@@ -350,7 +350,7 @@ TEST(TypefaceTest, createFromFamilies_Single) {
            Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoBoldItalic), 700, true));
    EXPECT_EQ(7, boldItalic->fStyle.getWeight());
    EXPECT_TRUE(boldItalic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kItalic, italic->fSkiaStyle);
    EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);

    // In Java,
    // new Typeface.Builder("Roboto-BoldItalic.ttf").setWeight(1100).setItalic(false).build();
@@ -358,7 +358,7 @@ TEST(TypefaceTest, createFromFamilies_Single) {
            Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoBold), 1100, false));
    EXPECT_EQ(10, over1000->fStyle.getWeight());
    EXPECT_FALSE(over1000->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBold, over1000->fSkiaStyle);
    EXPECT_EQ(Typeface::kBold, over1000->fAPIStyle);
}

TEST(TypefaceTest, createFromFamilies_Single_resolveByTable) {
@@ -368,7 +368,7 @@ TEST(TypefaceTest, createFromFamilies_Single_resolveByTable) {
                    RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE));
    EXPECT_EQ(4, regular->fStyle.getWeight());
    EXPECT_FALSE(regular->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kNormal, regular->fSkiaStyle);
    EXPECT_EQ(Typeface::kNormal, regular->fAPIStyle);

    // In Java, new Typeface.Builder("Roboto-Bold.ttf").build();
    std::unique_ptr<Typeface> bold(
@@ -376,7 +376,7 @@ TEST(TypefaceTest, createFromFamilies_Single_resolveByTable) {
                    RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE));
    EXPECT_EQ(7, bold->fStyle.getWeight());
    EXPECT_FALSE(bold->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kBold, bold->fSkiaStyle);
    EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);

    // In Java, new Typeface.Builder("Roboto-Italic.ttf").build();
    std::unique_ptr<Typeface> italic(
@@ -384,7 +384,7 @@ TEST(TypefaceTest, createFromFamilies_Single_resolveByTable) {
                    RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE));
    EXPECT_EQ(4, italic->fStyle.getWeight());
    EXPECT_TRUE(italic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kItalic, italic->fSkiaStyle);
    EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);

    // In Java, new Typeface.Builder("Roboto-BoldItalic.ttf").build();
    std::unique_ptr<Typeface> boldItalic(
@@ -392,7 +392,7 @@ TEST(TypefaceTest, createFromFamilies_Single_resolveByTable) {
                    RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE));
    EXPECT_EQ(7, boldItalic->fStyle.getWeight());
    EXPECT_TRUE(boldItalic->fStyle.getItalic());
    EXPECT_EQ(SkTypeface::kItalic, italic->fSkiaStyle);
    EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);
}

TEST(TypefaceTest, createFromFamilies_Family) {