Merge "Use enum class for FontVariation and update MinikinUtils"

This commit is contained in:
TreeHugger Robot
2017-11-08 02:21:56 +00:00
committed by Android (Google) Code Review
11 changed files with 222 additions and 205 deletions

View File

@@ -36,6 +36,7 @@
#include <hwui/Typeface.h>
#include <utils/FatVector.h>
#include <minikin/FontFamily.h>
#include <minikin/LocaleList.h>
#include <memory>
@@ -43,9 +44,10 @@ namespace android {
struct NativeFamilyBuilder {
NativeFamilyBuilder(uint32_t langId, int variant)
: langId(langId), variant(variant), allowUnsupportedFont(false) {}
: langId(langId), variant(static_cast<minikin::FontVariant>(variant)),
allowUnsupportedFont(false) {}
uint32_t langId;
int variant;
minikin::FontVariant variant;
bool allowUnsupportedFont;
std::vector<minikin::Font> fonts;
std::vector<minikin::FontVariation> axes;
@@ -55,10 +57,9 @@ static jlong FontFamily_initBuilder(JNIEnv* env, jobject clazz, jstring langs, j
NativeFamilyBuilder* builder;
if (langs != nullptr) {
ScopedUtfChars str(env, langs);
builder = new NativeFamilyBuilder(
minikin::FontStyle::registerLocaleList(str.c_str()), variant);
builder = new NativeFamilyBuilder(minikin::registerLocaleList(str.c_str()), variant);
} else {
builder = new NativeFamilyBuilder(minikin::FontStyle::registerLocaleList(""), variant);
builder = new NativeFamilyBuilder(minikin::registerLocaleList(""), variant);
}
return reinterpret_cast<jlong>(builder);
}
@@ -121,14 +122,14 @@ static bool addSkTypeface(NativeFamilyBuilder* builder, sk_sp<SkData>&& data, in
std::make_shared<MinikinFontSkia>(std::move(face), fontPtr, fontSize, ttcIndex,
builder->axes);
int weight = givenWeight / 100;
int weight = givenWeight;
bool italic = givenItalic == 1;
if (givenWeight == RESOLVE_BY_FONT_TABLE || givenItalic == RESOLVE_BY_FONT_TABLE) {
int os2Weight;
bool os2Italic;
if (!minikin::FontFamily::analyzeStyle(minikinFont, &os2Weight, &os2Italic)) {
ALOGE("analyzeStyle failed. Using default style");
os2Weight = 4;
os2Weight = 400;
os2Italic = false;
}
if (givenWeight == RESOLVE_BY_FONT_TABLE) {
@@ -139,7 +140,8 @@ static bool addSkTypeface(NativeFamilyBuilder* builder, sk_sp<SkData>&& data, in
}
}
builder->fonts.push_back(minikin::Font(minikinFont, minikin::FontStyle(weight, italic)));
builder->fonts.push_back(minikin::Font(minikinFont,
minikin::FontStyle(weight, static_cast<minikin::FontSlant>(italic))));
builder->axes.clear();
return true;
}

View File

@@ -41,6 +41,7 @@
#include <hwui/Paint.h>
#include <hwui/Typeface.h>
#include <minikin/GraphemeBreak.h>
#include <minikin/LocaleList.h>
#include <minikin/Measurement.h>
#include <unicode/utf16.h>
@@ -546,9 +547,9 @@ namespace PaintGlue {
static jint setTextLocales(JNIEnv* env, jobject clazz, jlong objHandle, jstring locales) {
Paint* obj = reinterpret_cast<Paint*>(objHandle);
ScopedUtfChars localesChars(env, locales);
jint minikinLangListId = minikin::FontStyle::registerLocaleList(localesChars.c_str());
obj->setMinikinLangListId(minikinLangListId);
return minikinLangListId;
jint minikinLocaleListId = minikin::registerLocaleList(localesChars.c_str());
obj->setMinikinLocaleListId(minikinLocaleListId);
return minikinLocaleListId;
}
static void setFontFeatureSettings(JNIEnv* env, jobject clazz, jlong paintHandle, jstring settings) {
@@ -580,7 +581,7 @@ namespace PaintGlue {
// restore the original settings.
paint->setTextSkewX(saveSkewX);
paint->setFakeBoldText(savefakeBold);
if (paint->getFontVariant() == minikin::VARIANT_ELEGANT) {
if (paint->getFontVariant() == minikin::FontVariant::ELEGANT) {
SkScalar size = paint->getTextSize();
metrics->fTop = -size * kElegantTop / 2048;
metrics->fBottom = -size * kElegantBottom / 2048;
@@ -871,20 +872,20 @@ namespace PaintGlue {
obj->setTextAlign(align);
}
static void setTextLocalesByMinikinLangListId(jlong objHandle,
jint minikinLangListId) {
static void setTextLocalesByMinikinLocaleListId(jlong objHandle,
jint minikinLocaleListId) {
Paint* obj = reinterpret_cast<Paint*>(objHandle);
obj->setMinikinLangListId(minikinLangListId);
obj->setMinikinLocaleListId(minikinLocaleListId);
}
static jboolean isElegantTextHeight(jlong paintHandle) {
Paint* obj = reinterpret_cast<Paint*>(paintHandle);
return obj->getFontVariant() == minikin::VARIANT_ELEGANT;
return obj->getFontVariant() == minikin::FontVariant::ELEGANT;
}
static void setElegantTextHeight(jlong paintHandle, jboolean aa) {
Paint* obj = reinterpret_cast<Paint*>(paintHandle);
obj->setFontVariant(aa ? minikin::VARIANT_ELEGANT : minikin::VARIANT_DEFAULT);
obj->setFontVariant(aa ? minikin::FontVariant::ELEGANT : minikin::FontVariant::DEFAULT);
}
static jfloat getTextSize(jlong paintHandle) {
@@ -1080,8 +1081,8 @@ static const JNINativeMethod methods[] = {
{"nSetTypeface","(JJ)V", (void*) PaintGlue::setTypeface},
{"nGetTextAlign","(J)I", (void*) PaintGlue::getTextAlign},
{"nSetTextAlign","(JI)V", (void*) PaintGlue::setTextAlign},
{"nSetTextLocalesByMinikinLangListId","(JI)V",
(void*) PaintGlue::setTextLocalesByMinikinLangListId},
{"nSetTextLocalesByMinikinLocaleListId","(JI)V",
(void*) PaintGlue::setTextLocalesByMinikinLocaleListId},
{"nIsElegantTextHeight","(J)Z", (void*) PaintGlue::isElegantTextHeight},
{"nSetElegantTextHeight","(JZ)V", (void*) PaintGlue::setElegantTextHeight},
{"nGetTextSize","(J)F", (void*) PaintGlue::getTextSize},

View File

@@ -83,7 +83,7 @@ static jint Typeface_getStyle(JNIEnv* env, jobject obj, jlong faceHandle) {
static jint Typeface_getWeight(JNIEnv* env, jobject obj, jlong faceHandle) {
Typeface* face = reinterpret_cast<Typeface*>(faceHandle);
return face->fStyle.getWeight() * 100;
return face->fStyle.weight;
}
static jlong Typeface_createFromArray(JNIEnv *env, jobject, jlongArray familyArray,

View File

@@ -126,19 +126,17 @@ class Run {
class StyleRun : public Run {
public:
StyleRun(int32_t start, int32_t end, minikin::MinikinPaint&& paint,
std::shared_ptr<minikin::FontCollection>&& collection,
minikin::FontStyle&& style, bool isRtl)
std::shared_ptr<minikin::FontCollection>&& collection, bool isRtl)
: Run(start, end), mPaint(std::move(paint)), mCollection(std::move(collection)),
mStyle(std::move(style)), mIsRtl(isRtl) {}
mIsRtl(isRtl) {}
void addTo(minikin::LineBreaker* lineBreaker) override {
lineBreaker->addStyleRun(&mPaint, mCollection, mStyle, mStart, mEnd, mIsRtl);
lineBreaker->addStyleRun(&mPaint, mCollection, mStart, mEnd, mIsRtl);
}
private:
minikin::MinikinPaint mPaint;
std::shared_ptr<minikin::FontCollection> mCollection;
minikin::FontStyle mStyle;
const bool mIsRtl;
};
@@ -167,10 +165,9 @@ class StaticLayoutNative {
mRightPaddings(std::move(rightPaddings)) {}
void addStyleRun(int32_t start, int32_t end, minikin::MinikinPaint&& paint,
std::shared_ptr<minikin::FontCollection> collection,
minikin::FontStyle&& style, bool isRtl) {
std::shared_ptr<minikin::FontCollection> collection, bool isRtl) {
mRuns.emplace_back(std::make_unique<StyleRun>(
start, end, std::move(paint), std::move(collection), std::move(style), isRtl));
start, end, std::move(paint), std::move(collection), isRtl));
}
void addReplacementRun(int32_t start, int32_t end, float width, uint32_t localeListId) {
@@ -323,15 +320,9 @@ static jint nComputeLineBreaks(JNIEnv* env, jclass, jlong nativePtr,
static void nAddStyleRun(jlong nativePtr, jlong nativePaint, jint start, jint end, jboolean isRtl) {
StaticLayoutNative* builder = toNative(nativePtr);
Paint* paint = reinterpret_cast<Paint*>(nativePaint);
const Typeface* typeface = paint->getAndroidTypeface();
minikin::MinikinPaint minikinPaint;
const Typeface* resolvedTypeface = Typeface::resolveDefault(typeface);
minikin::FontStyle style = MinikinUtils::prepareMinikinPaint(&minikinPaint, paint,
typeface);
builder->addStyleRun(
start, end, std::move(minikinPaint), resolvedTypeface->fFontCollection, std::move(style),
isRtl);
const Typeface* typeface = Typeface::resolveDefault(paint->getAndroidTypeface());
minikin::MinikinPaint minikinPaint = MinikinUtils::prepareMinikinPaint(paint, typeface);
builder->addStyleRun(start, end, std::move(minikinPaint), typeface->fFontCollection, isRtl);
}
// CriticalNative
@@ -339,7 +330,7 @@ static void nAddReplacementRun(jlong nativePtr, jlong nativePaint, jint start, j
jfloat width) {
StaticLayoutNative* builder = toNative(nativePtr);
Paint* paint = reinterpret_cast<Paint*>(nativePaint);
builder->addReplacementRun(start, end, width, paint->getMinikinLangListId());
builder->addReplacementRun(start, end, width, paint->getMinikinLocaleListId());
}
static const JNINativeMethod gMethods[] = {

View File

@@ -88,7 +88,7 @@ public class Paint {
* A map from a string representation of the LocaleList to Minikin's language list ID.
*/
@GuardedBy("sCacheLock")
private static final HashMap<String, Integer> sMinikinLangListIdCache = new HashMap<>();
private static final HashMap<String, Integer> sMinikinLocaleListIdCache = new HashMap<>();
/**
* @hide
@@ -1445,16 +1445,16 @@ public class Paint {
private void syncTextLocalesWithMinikin() {
final String languageTags = mLocales.toLanguageTags();
final Integer minikinLangListId;
final Integer minikinLocaleListId;
synchronized (sCacheLock) {
minikinLangListId = sMinikinLangListIdCache.get(languageTags);
if (minikinLangListId == null) {
minikinLocaleListId = sMinikinLocaleListIdCache.get(languageTags);
if (minikinLocaleListId == null) {
final int newID = nSetTextLocales(mNativePaint, languageTags);
sMinikinLangListIdCache.put(languageTags, newID);
sMinikinLocaleListIdCache.put(languageTags, newID);
return;
}
}
nSetTextLocalesByMinikinLangListId(mNativePaint, minikinLangListId.intValue());
nSetTextLocalesByMinikinLocaleListId(mNativePaint, minikinLocaleListId.intValue());
}
/**
@@ -2918,8 +2918,8 @@ public class Paint {
@CriticalNative
private static native void nSetTextAlign(long paintPtr, int align);
@CriticalNative
private static native void nSetTextLocalesByMinikinLangListId(long paintPtr,
int mMinikinLangListId);
private static native void nSetTextLocalesByMinikinLocaleListId(long paintPtr,
int mMinikinLocaleListId);
@CriticalNative
private static native void nSetShadowLayer(long paintPtr,
float radius, float dx, float dy, int color);

View File

@@ -26,39 +26,38 @@
namespace android {
minikin::FontStyle MinikinUtils::prepareMinikinPaint(minikin::MinikinPaint* minikinPaint,
const Paint* paint, const Typeface* typeface) {
minikin::MinikinPaint MinikinUtils::prepareMinikinPaint(const Paint* paint,
const Typeface* typeface) {
const Typeface* resolvedFace = Typeface::resolveDefault(typeface);
minikin::FontStyle resolved = resolvedFace->fStyle;
/* Prepare minikin FontStyle */
minikin::FontVariant minikinVariant = (paint->getFontVariant() == minikin::VARIANT_ELEGANT)
? minikin::VARIANT_ELEGANT
: minikin::VARIANT_COMPACT;
const uint32_t langListId = paint->getMinikinLangListId();
minikin::FontStyle minikinStyle(langListId, minikinVariant, resolved.getWeight(),
resolved.getItalic());
const minikin::FontVariant minikinVariant =
(paint->getFontVariant() == minikin::FontVariant::ELEGANT)
? minikin::FontVariant::ELEGANT
: minikin::FontVariant::COMPACT;
minikin::MinikinPaint minikinPaint;
/* Prepare minikin Paint */
minikinPaint->size =
minikinPaint.size =
paint->isLinearText() ? paint->getTextSize() : static_cast<int>(paint->getTextSize());
minikinPaint->scaleX = paint->getTextScaleX();
minikinPaint->skewX = paint->getTextSkewX();
minikinPaint->letterSpacing = paint->getLetterSpacing();
minikinPaint->wordSpacing = paint->getWordSpacing();
minikinPaint->paintFlags = MinikinFontSkia::packPaintFlags(paint);
minikinPaint->fontFeatureSettings = paint->getFontFeatureSettings();
minikinPaint->hyphenEdit = minikin::HyphenEdit(paint->getHyphenEdit());
return minikinStyle;
minikinPaint.scaleX = paint->getTextScaleX();
minikinPaint.skewX = paint->getTextSkewX();
minikinPaint.letterSpacing = paint->getLetterSpacing();
minikinPaint.wordSpacing = paint->getWordSpacing();
minikinPaint.paintFlags = MinikinFontSkia::packPaintFlags(paint);
minikinPaint.localeListId = paint->getMinikinLocaleListId();
minikinPaint.fontStyle = minikin::FontStyle(minikinVariant, resolved.weight, resolved.slant);
minikinPaint.fontFeatureSettings = paint->getFontFeatureSettings();
minikinPaint.hyphenEdit = minikin::HyphenEdit(paint->getHyphenEdit());
return minikinPaint;
}
minikin::Layout MinikinUtils::doLayout(const Paint* paint, minikin::Bidi bidiFlags,
const Typeface* typeface, const uint16_t* buf, size_t start,
size_t count, size_t bufSize) {
minikin::MinikinPaint minikinPaint;
minikin::FontStyle minikinStyle = prepareMinikinPaint(&minikinPaint, paint, typeface);
minikin::MinikinPaint minikinPaint = prepareMinikinPaint(paint, typeface);
minikin::Layout layout;
layout.doLayout(buf, start, count, bufSize, bidiFlags, minikinStyle, minikinPaint,
layout.doLayout(buf, start, count, bufSize, bidiFlags, minikinPaint,
Typeface::resolveDefault(typeface)->fFontCollection);
return layout;
}
@@ -66,11 +65,10 @@ minikin::Layout MinikinUtils::doLayout(const Paint* paint, minikin::Bidi bidiFla
float MinikinUtils::measureText(const Paint* paint, minikin::Bidi bidiFlags,
const Typeface* typeface, const uint16_t* buf, size_t start,
size_t count, size_t bufSize, float* advances) {
minikin::MinikinPaint minikinPaint;
minikin::FontStyle minikinStyle = prepareMinikinPaint(&minikinPaint, paint, typeface);
minikin::MinikinPaint minikinPaint = prepareMinikinPaint(paint, typeface);
const Typeface* resolvedTypeface = Typeface::resolveDefault(typeface);
return minikin::Layout::measureText(buf, start, count, bufSize, bidiFlags, minikinStyle,
minikinPaint, resolvedTypeface->fFontCollection, advances,
return minikin::Layout::measureText(buf, start, count, bufSize, bidiFlags, minikinPaint,
resolvedTypeface->fFontCollection, advances,
nullptr /* extent */, nullptr /* overhangs */);
}
@@ -109,4 +107,4 @@ float MinikinUtils::hOffsetForTextAlign(Paint* paint, const minikin::Layout& lay
SkPathMeasure measure(path, false);
return align * (layout.getAdvance() - measure.getLength());
}
}
} // namespace android

View File

@@ -34,9 +34,8 @@ namespace android {
class MinikinUtils {
public:
ANDROID_API static minikin::FontStyle prepareMinikinPaint(minikin::MinikinPaint* minikinPaint,
const Paint* paint,
const Typeface* typeface);
ANDROID_API static minikin::MinikinPaint prepareMinikinPaint(const Paint* paint,
const Typeface* typeface);
ANDROID_API static minikin::Layout doLayout(const Paint* paint, minikin::Bidi bidiFlags,
const Typeface* typeface, const uint16_t* buf,

View File

@@ -67,11 +67,11 @@ public:
std::string getFontFeatureSettings() const { return mFontFeatureSettings; }
void setMinikinLangListId(uint32_t minikinLangListId) {
mMinikinLangListId = minikinLangListId;
void setMinikinLocaleListId(uint32_t minikinLocaleListId) {
mMinikinLocaleListId = minikinLocaleListId;
}
uint32_t getMinikinLangListId() const { return mMinikinLangListId; }
uint32_t getMinikinLocaleListId() const { return mMinikinLocaleListId; }
void setFontVariant(minikin::FontVariant variant) { mFontVariant = variant; }
@@ -89,12 +89,13 @@ private:
float mLetterSpacing = 0;
float mWordSpacing = 0;
std::string mFontFeatureSettings;
uint32_t mMinikinLangListId;
uint32_t mMinikinLocaleListId;
minikin::FontVariant mFontVariant;
uint32_t mHyphenEdit = 0;
// The native Typeface object has the same lifetime of the Java Typeface object. The Java Paint
// object holds a strong reference to the Java Typeface object. Thus, following pointer can
// never be a dangling pointer. Note that nullptr is valid: it means the default typeface.
// The native Typeface object has the same lifetime of the Java Typeface
// object. The Java Paint object holds a strong reference to the Java Typeface
// object. Thus, following pointer can never be a dangling pointer. Note that
// nullptr is valid: it means the default typeface.
const Typeface* mTypeface = nullptr;
};

View File

@@ -23,15 +23,15 @@ Paint::Paint()
, mLetterSpacing(0)
, mWordSpacing(0)
, mFontFeatureSettings()
, mMinikinLangListId(0)
, mFontVariant(minikin::VARIANT_DEFAULT) {}
, mMinikinLocaleListId(0)
, mFontVariant(minikin::FontVariant::DEFAULT) {}
Paint::Paint(const Paint& paint)
: SkPaint(paint)
, mLetterSpacing(paint.mLetterSpacing)
, mWordSpacing(paint.mWordSpacing)
, mFontFeatureSettings(paint.mFontFeatureSettings)
, mMinikinLangListId(paint.mMinikinLangListId)
, mMinikinLocaleListId(paint.mMinikinLocaleListId)
, mFontVariant(paint.mFontVariant)
, mHyphenEdit(paint.mHyphenEdit)
, mTypeface(paint.mTypeface) {}
@@ -41,8 +41,8 @@ Paint::Paint(const SkPaint& paint)
, mLetterSpacing(0)
, mWordSpacing(0)
, mFontFeatureSettings()
, mMinikinLangListId(0)
, mFontVariant(minikin::VARIANT_DEFAULT) {}
, mMinikinLocaleListId(0)
, mFontVariant(minikin::FontVariant::DEFAULT) {}
Paint::~Paint() {}
@@ -51,7 +51,7 @@ Paint& Paint::operator=(const Paint& other) {
mLetterSpacing = other.mLetterSpacing;
mWordSpacing = other.mWordSpacing;
mFontFeatureSettings = other.mFontFeatureSettings;
mMinikinLangListId = other.mMinikinLangListId;
mMinikinLocaleListId = other.mMinikinLocaleListId;
mFontVariant = other.mFontVariant;
mHyphenEdit = other.mHyphenEdit;
mTypeface = other.mTypeface;
@@ -62,7 +62,7 @@ bool operator==(const Paint& a, const Paint& b) {
return static_cast<const SkPaint&>(a) == static_cast<const SkPaint&>(b) &&
a.mLetterSpacing == b.mLetterSpacing && a.mWordSpacing == b.mWordSpacing &&
a.mFontFeatureSettings == b.mFontFeatureSettings &&
a.mMinikinLangListId == b.mMinikinLangListId && a.mFontVariant == b.mFontVariant &&
a.mMinikinLocaleListId == b.mMinikinLocaleListId && a.mFontVariant == b.mFontVariant &&
a.mHyphenEdit == b.mHyphenEdit && a.mTypeface == b.mTypeface;
}
}
} // namespace android

View File

@@ -44,9 +44,8 @@ static Typeface::Style computeAPIStyle(int weight, bool italic) {
}
static minikin::FontStyle computeMinikinStyle(int weight, bool italic) {
// TODO: Better to use raw base weight value for font selection instead of dividing by 100.
const int minikinWeight = uirenderer::MathUtils::clamp((weight + 50) / 100, 1, 10);
return minikin::FontStyle(minikinWeight, italic);
return minikin::FontStyle(uirenderer::MathUtils::clamp(weight, 1, 1000),
static_cast<minikin::FontSlant>(italic));
}
// Resolve the relative weight from the baseWeight and target style.
@@ -192,8 +191,8 @@ void Typeface::setRobotoTypefaceForTest() {
hwTypeface->fFontCollection = collection;
hwTypeface->fAPIStyle = Typeface::kNormal;
hwTypeface->fBaseWeight = SkFontStyle::kNormal_Weight;
hwTypeface->fStyle = minikin::FontStyle(4 /* weight */, false /* italic */);
hwTypeface->fStyle = minikin::FontStyle();
Typeface::setDefault(hwTypeface);
}
}
} // namespace android

View File

@@ -81,127 +81,139 @@ TEST(TypefaceTest, resolveDefault_and_setDefaultTest) {
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(700, bold->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, bold->fStyle.slant);
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(300, light->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, light->fStyle.slant);
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, Typeface::kNormal));
EXPECT_EQ(4, normal->fStyle.getWeight());
EXPECT_FALSE(normal->fStyle.getItalic());
EXPECT_EQ(400, normal->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, normal->fStyle.slant);
EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle);
// In Java, Typeface.create(Typeface.DEFAULT, Typeface.BOLD);
std::unique_ptr<Typeface> bold(Typeface::createRelative(nullptr, Typeface::kBold));
EXPECT_EQ(7, bold->fStyle.getWeight());
EXPECT_FALSE(bold->fStyle.getItalic());
EXPECT_EQ(700, bold->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, bold->fStyle.slant);
EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);
// In Java, Typeface.create(Typeface.DEFAULT, Typeface.ITALIC);
std::unique_ptr<Typeface> italic(Typeface::createRelative(nullptr, Typeface::kItalic));
EXPECT_EQ(4, italic->fStyle.getWeight());
EXPECT_TRUE(italic->fStyle.getItalic());
EXPECT_EQ(400, italic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, italic->fStyle.slant);
EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);
// In Java, Typeface.create(Typeface.DEFAULT, Typeface.BOLD_ITALIC);
std::unique_ptr<Typeface> boldItalic(Typeface::createRelative(nullptr, Typeface::kBoldItalic));
EXPECT_EQ(7, boldItalic->fStyle.getWeight());
EXPECT_TRUE(boldItalic->fStyle.getItalic());
EXPECT_EQ(700, boldItalic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, boldItalic->fStyle.slant);
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);
// In Java, Typeface.create(Typeface.create("sans-serif-bold"),
// Typeface.NORMAL);
std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal));
EXPECT_EQ(7, normal->fStyle.getWeight());
EXPECT_FALSE(normal->fStyle.getItalic());
EXPECT_EQ(700, normal->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, normal->fStyle.slant);
EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle);
// In Java, Typeface.create(Typeface.create("sans-serif-bold"), Typeface.BOLD);
// In Java, Typeface.create(Typeface.create("sans-serif-bold"),
// Typeface.BOLD);
std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold));
EXPECT_EQ(10, bold->fStyle.getWeight());
EXPECT_FALSE(bold->fStyle.getItalic());
EXPECT_EQ(1000, bold->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, bold->fStyle.slant);
EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);
// In Java, Typeface.create(Typeface.create("sans-serif-bold"), Typeface.ITALIC);
// In Java, Typeface.create(Typeface.create("sans-serif-bold"),
// Typeface.ITALIC);
std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic));
EXPECT_EQ(7, italic->fStyle.getWeight());
EXPECT_TRUE(italic->fStyle.getItalic());
EXPECT_EQ(700, italic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, italic->fStyle.slant);
EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);
// In Java, Typeface.create(Typeface.create("sans-serif-bold"), Typeface.BOLD_ITALIC);
// In Java, Typeface.create(Typeface.create("sans-serif-bold"),
// Typeface.BOLD_ITALIC);
std::unique_ptr<Typeface> boldItalic(
Typeface::createRelative(base.get(), Typeface::kBoldItalic));
EXPECT_EQ(10, boldItalic->fStyle.getWeight());
EXPECT_TRUE(boldItalic->fStyle.getItalic());
EXPECT_EQ(1000, boldItalic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, boldItalic->fStyle.slant);
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);
// In Java, Typeface.create(Typeface.create("sans-serif-light"),
// Typeface.NORMAL);
std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal));
EXPECT_EQ(3, normal->fStyle.getWeight());
EXPECT_FALSE(normal->fStyle.getItalic());
EXPECT_EQ(300, normal->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, normal->fStyle.slant);
EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle);
// In Java, Typeface.create(Typeface.create("sans-serif-light"), Typeface.BOLD);
// In Java, Typeface.create(Typeface.create("sans-serif-light"),
// Typeface.BOLD);
std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold));
EXPECT_EQ(6, bold->fStyle.getWeight());
EXPECT_FALSE(bold->fStyle.getItalic());
EXPECT_EQ(600, bold->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, bold->fStyle.slant);
EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);
// In Java, Typeface.create(Typeface.create("sans-serif-light"), Typeface.ITLIC);
// In Java, Typeface.create(Typeface.create("sans-serif-light"),
// Typeface.ITLIC);
std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic));
EXPECT_EQ(3, italic->fStyle.getWeight());
EXPECT_TRUE(italic->fStyle.getItalic());
EXPECT_EQ(300, italic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, italic->fStyle.slant);
EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);
// In Java, Typeface.create(Typeface.create("sans-serif-light"), Typeface.BOLD_ITALIC);
// In Java, Typeface.create(Typeface.create("sans-serif-light"),
// Typeface.BOLD_ITALIC);
std::unique_ptr<Typeface> boldItalic(
Typeface::createRelative(base.get(), Typeface::kBoldItalic));
EXPECT_EQ(6, boldItalic->fStyle.getWeight());
EXPECT_TRUE(boldItalic->fStyle.getItalic());
EXPECT_EQ(600, boldItalic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, boldItalic->fStyle.slant);
EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle);
}
TEST(TypefaceTest, createRelativeTest_fromBoldStyled) {
std::unique_ptr<Typeface> base(Typeface::createRelative(nullptr, Typeface::kBold));
// In Java, Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD), Typeface.NORMAL);
// In Java, Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD),
// Typeface.NORMAL);
std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal));
EXPECT_EQ(4, normal->fStyle.getWeight());
EXPECT_FALSE(normal->fStyle.getItalic());
EXPECT_EQ(400, normal->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, normal->fStyle.slant);
EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle);
// In Java Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD), Typeface.BOLD);
// In Java Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD),
// Typeface.BOLD);
std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold));
EXPECT_EQ(7, bold->fStyle.getWeight());
EXPECT_FALSE(bold->fStyle.getItalic());
EXPECT_EQ(700, bold->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, bold->fStyle.slant);
EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);
// In Java, Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD), Typeface.ITALIC);
// In Java, Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD),
// Typeface.ITALIC);
std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic));
EXPECT_EQ(4, normal->fStyle.getWeight());
EXPECT_TRUE(italic->fStyle.getItalic());
EXPECT_EQ(400, normal->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, italic->fStyle.slant);
EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);
// In Java,
// Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD), Typeface.BOLD_ITALIC);
// Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.BOLD),
// Typeface.BOLD_ITALIC);
std::unique_ptr<Typeface> boldItalic(
Typeface::createRelative(base.get(), Typeface::kBoldItalic));
EXPECT_EQ(7, boldItalic->fStyle.getWeight());
EXPECT_TRUE(boldItalic->fStyle.getItalic());
EXPECT_EQ(700, boldItalic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, boldItalic->fStyle.slant);
EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle);
}
@@ -209,31 +221,35 @@ TEST(TypefaceTest, createRelativeTest_fromItalicStyled) {
std::unique_ptr<Typeface> base(Typeface::createRelative(nullptr, Typeface::kItalic));
// In Java,
// Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC), Typeface.NORMAL);
// Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC),
// Typeface.NORMAL);
std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal));
EXPECT_EQ(4, normal->fStyle.getWeight());
EXPECT_FALSE(normal->fStyle.getItalic());
EXPECT_EQ(400, normal->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, normal->fStyle.slant);
EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle);
// In Java, Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC), Typeface.BOLD);
// In Java, Typeface.create(Typeface.create(Typeface.DEFAULT,
// Typeface.ITALIC), Typeface.BOLD);
std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold));
EXPECT_EQ(7, bold->fStyle.getWeight());
EXPECT_FALSE(bold->fStyle.getItalic());
EXPECT_EQ(700, bold->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, bold->fStyle.slant);
EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);
// In Java,
// Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC), Typeface.ITALIC);
// Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC),
// Typeface.ITALIC);
std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic));
EXPECT_EQ(4, italic->fStyle.getWeight());
EXPECT_TRUE(italic->fStyle.getItalic());
EXPECT_EQ(400, italic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, italic->fStyle.slant);
EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);
// In Java,
// Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC), Typeface.BOLD_ITALIC);
// Typeface.create(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC),
// Typeface.BOLD_ITALIC);
std::unique_ptr<Typeface> boldItalic(
Typeface::createRelative(base.get(), Typeface::kBoldItalic));
EXPECT_EQ(7, boldItalic->fStyle.getWeight());
EXPECT_TRUE(boldItalic->fStyle.getItalic());
EXPECT_EQ(700, boldItalic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, boldItalic->fStyle.slant);
EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle);
}
@@ -245,8 +261,8 @@ TEST(TypefaceTest, createRelativeTest_fromSpecifiedStyled) {
// .setWeight(700).setItalic(false).build();
// Typeface.create(typeface, Typeface.NORMAL);
std::unique_ptr<Typeface> normal(Typeface::createRelative(base.get(), Typeface::kNormal));
EXPECT_EQ(4, normal->fStyle.getWeight());
EXPECT_FALSE(normal->fStyle.getItalic());
EXPECT_EQ(400, normal->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, normal->fStyle.slant);
EXPECT_EQ(Typeface::kNormal, normal->fAPIStyle);
// In Java,
@@ -254,8 +270,8 @@ TEST(TypefaceTest, createRelativeTest_fromSpecifiedStyled) {
// .setWeight(700).setItalic(false).build();
// Typeface.create(typeface, Typeface.BOLD);
std::unique_ptr<Typeface> bold(Typeface::createRelative(base.get(), Typeface::kBold));
EXPECT_EQ(7, bold->fStyle.getWeight());
EXPECT_FALSE(bold->fStyle.getItalic());
EXPECT_EQ(700, bold->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, bold->fStyle.slant);
EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);
// In Java,
@@ -263,8 +279,8 @@ TEST(TypefaceTest, createRelativeTest_fromSpecifiedStyled) {
// .setWeight(700).setItalic(false).build();
// Typeface.create(typeface, Typeface.ITALIC);
std::unique_ptr<Typeface> italic(Typeface::createRelative(base.get(), Typeface::kItalic));
EXPECT_EQ(4, italic->fStyle.getWeight());
EXPECT_TRUE(italic->fStyle.getItalic());
EXPECT_EQ(400, italic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, italic->fStyle.slant);
EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);
// In Java,
@@ -273,89 +289,99 @@ TEST(TypefaceTest, createRelativeTest_fromSpecifiedStyled) {
// Typeface.create(typeface, Typeface.BOLD_ITALIC);
std::unique_ptr<Typeface> boldItalic(
Typeface::createRelative(base.get(), Typeface::kBoldItalic));
EXPECT_EQ(7, boldItalic->fStyle.getWeight());
EXPECT_TRUE(boldItalic->fStyle.getItalic());
EXPECT_EQ(700, boldItalic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, boldItalic->fStyle.slant);
EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle);
}
TEST(TypefaceTest, createAbsolute) {
// In Java,
// new Typeface.Builder(invalid).setFallback("sans-serif").setWeight(400).setItalic(false)
// new
// Typeface.Builder(invalid).setFallback("sans-serif").setWeight(400).setItalic(false)
// .build();
std::unique_ptr<Typeface> regular(Typeface::createAbsolute(nullptr, 400, false));
EXPECT_EQ(4, regular->fStyle.getWeight());
EXPECT_FALSE(regular->fStyle.getItalic());
EXPECT_EQ(400, regular->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, regular->fStyle.slant);
EXPECT_EQ(Typeface::kNormal, regular->fAPIStyle);
// In Java,
// new Typeface.Builder(invalid).setFallback("sans-serif").setWeight(700).setItalic(false)
// new
// Typeface.Builder(invalid).setFallback("sans-serif").setWeight(700).setItalic(false)
// .build();
std::unique_ptr<Typeface> bold(Typeface::createAbsolute(nullptr, 700, false));
EXPECT_EQ(7, bold->fStyle.getWeight());
EXPECT_FALSE(bold->fStyle.getItalic());
EXPECT_EQ(700, bold->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, bold->fStyle.slant);
EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);
// In Java,
// new Typeface.Builder(invalid).setFallback("sans-serif").setWeight(400).setItalic(true)
// new
// Typeface.Builder(invalid).setFallback("sans-serif").setWeight(400).setItalic(true)
// .build();
std::unique_ptr<Typeface> italic(Typeface::createAbsolute(nullptr, 400, true));
EXPECT_EQ(4, italic->fStyle.getWeight());
EXPECT_TRUE(italic->fStyle.getItalic());
EXPECT_EQ(400, italic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, italic->fStyle.slant);
EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);
// In Java,
// new Typeface.Builder(invalid).setFallback("sans-serif").setWeight(700).setItalic(true)
// new
// Typeface.Builder(invalid).setFallback("sans-serif").setWeight(700).setItalic(true)
// .build();
std::unique_ptr<Typeface> boldItalic(Typeface::createAbsolute(nullptr, 700, true));
EXPECT_EQ(7, boldItalic->fStyle.getWeight());
EXPECT_TRUE(boldItalic->fStyle.getItalic());
EXPECT_EQ(700, boldItalic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, boldItalic->fStyle.slant);
EXPECT_EQ(Typeface::kBoldItalic, boldItalic->fAPIStyle);
// In Java,
// new Typeface.Builder(invalid).setFallback("sans-serif").setWeight(1100).setItalic(true)
// new
// Typeface.Builder(invalid).setFallback("sans-serif").setWeight(1100).setItalic(true)
// .build();
std::unique_ptr<Typeface> over1000(Typeface::createAbsolute(nullptr, 1100, false));
EXPECT_EQ(10, over1000->fStyle.getWeight());
EXPECT_FALSE(over1000->fStyle.getItalic());
EXPECT_EQ(1000, over1000->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, over1000->fStyle.slant);
EXPECT_EQ(Typeface::kBold, over1000->fAPIStyle);
}
TEST(TypefaceTest, createFromFamilies_Single) {
// In Java, new Typeface.Builder("Roboto-Regular.ttf").setWeight(400).setItalic(false).build();
// In Java, new
// Typeface.Builder("Roboto-Regular.ttf").setWeight(400).setItalic(false).build();
std::unique_ptr<Typeface> regular(
Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoRegular), 400, false));
EXPECT_EQ(4, regular->fStyle.getWeight());
EXPECT_FALSE(regular->fStyle.getItalic());
EXPECT_EQ(400, regular->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, regular->fStyle.slant);
EXPECT_EQ(Typeface::kNormal, regular->fAPIStyle);
// In Java, new Typeface.Builder("Roboto-Bold.ttf").setWeight(700).setItalic(false).build();
// 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(700, bold->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, bold->fStyle.slant);
EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);
// In Java, new Typeface.Builder("Roboto-Italic.ttf").setWeight(400).setItalic(true).build();
// 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(400, italic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, italic->fStyle.slant);
EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);
// In Java,
// new Typeface.Builder("Roboto-BoldItalic.ttf").setWeight(700).setItalic(true).build();
// new
// Typeface.Builder("Roboto-BoldItalic.ttf").setWeight(700).setItalic(true).build();
std::unique_ptr<Typeface> boldItalic(
Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoBoldItalic), 700, true));
EXPECT_EQ(7, boldItalic->fStyle.getWeight());
EXPECT_TRUE(boldItalic->fStyle.getItalic());
EXPECT_EQ(700, boldItalic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, boldItalic->fStyle.slant);
EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);
// In Java,
// new Typeface.Builder("Roboto-BoldItalic.ttf").setWeight(1100).setItalic(false).build();
// new
// Typeface.Builder("Roboto-BoldItalic.ttf").setWeight(1100).setItalic(false).build();
std::unique_ptr<Typeface> over1000(
Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoBold), 1100, false));
EXPECT_EQ(10, over1000->fStyle.getWeight());
EXPECT_FALSE(over1000->fStyle.getItalic());
EXPECT_EQ(1000, over1000->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, over1000->fStyle.slant);
EXPECT_EQ(Typeface::kBold, over1000->fAPIStyle);
}
@@ -363,30 +389,30 @@ TEST(TypefaceTest, createFromFamilies_Single_resolveByTable) {
// In Java, new Typeface.Builder("Roboto-Regular.ttf").build();
std::unique_ptr<Typeface> regular(Typeface::createFromFamilies(
makeSingleFamlyVector(kRobotoRegular), RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE));
EXPECT_EQ(4, regular->fStyle.getWeight());
EXPECT_FALSE(regular->fStyle.getItalic());
EXPECT_EQ(400, regular->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, regular->fStyle.slant);
EXPECT_EQ(Typeface::kNormal, regular->fAPIStyle);
// In Java, new Typeface.Builder("Roboto-Bold.ttf").build();
std::unique_ptr<Typeface> bold(Typeface::createFromFamilies(
makeSingleFamlyVector(kRobotoBold), RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE));
EXPECT_EQ(7, bold->fStyle.getWeight());
EXPECT_FALSE(bold->fStyle.getItalic());
EXPECT_EQ(700, bold->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, bold->fStyle.slant);
EXPECT_EQ(Typeface::kBold, bold->fAPIStyle);
// In Java, new Typeface.Builder("Roboto-Italic.ttf").build();
std::unique_ptr<Typeface> italic(Typeface::createFromFamilies(
makeSingleFamlyVector(kRobotoItalic), RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE));
EXPECT_EQ(4, italic->fStyle.getWeight());
EXPECT_TRUE(italic->fStyle.getItalic());
EXPECT_EQ(400, italic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, italic->fStyle.slant);
EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);
// In Java, new Typeface.Builder("Roboto-BoldItalic.ttf").build();
std::unique_ptr<Typeface> boldItalic(
Typeface::createFromFamilies(makeSingleFamlyVector(kRobotoBoldItalic),
RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE));
EXPECT_EQ(7, boldItalic->fStyle.getWeight());
EXPECT_TRUE(boldItalic->fStyle.getItalic());
EXPECT_EQ(700, boldItalic->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::ITALIC, boldItalic->fStyle.slant);
EXPECT_EQ(Typeface::kItalic, italic->fAPIStyle);
}
@@ -396,8 +422,8 @@ TEST(TypefaceTest, createFromFamilies_Family) {
buildFamily(kRobotoBoldItalic)};
std::unique_ptr<Typeface> typeface(Typeface::createFromFamilies(
std::move(families), RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE));
EXPECT_EQ(4, typeface->fStyle.getWeight());
EXPECT_FALSE(typeface->fStyle.getItalic());
EXPECT_EQ(400, typeface->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, typeface->fStyle.slant);
}
TEST(TypefaceTest, createFromFamilies_Family_withoutRegular) {
@@ -405,8 +431,8 @@ TEST(TypefaceTest, createFromFamilies_Family_withoutRegular) {
buildFamily(kRobotoBold), buildFamily(kRobotoItalic), buildFamily(kRobotoBoldItalic)};
std::unique_ptr<Typeface> typeface(Typeface::createFromFamilies(
std::move(families), RESOLVE_BY_FONT_TABLE, RESOLVE_BY_FONT_TABLE));
EXPECT_EQ(7, typeface->fStyle.getWeight());
EXPECT_FALSE(typeface->fStyle.getItalic());
EXPECT_EQ(700, typeface->fStyle.weight);
EXPECT_EQ(minikin::FontSlant::UPRIGHT, typeface->fStyle.slant);
}
} // namespace