From 36dadcfc7e063ca60dc22dbb4517832326d26c30 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 7 Feb 2018 18:38:58 +0000 Subject: [PATCH] Revert "Use new minikin::Font constructor" This causes a regression for some characters This reverts commit ab40df9e6979c955f89a06a358385ecec361c9d9. Bug: 73054061 Change-Id: Icf1f9d2b89b75031aabb47507135e45a21bc5363 --- core/jni/android/graphics/FontFamily.cpp | 28 +++++++++++++++++------- core/jni/android/graphics/Paint.cpp | 2 +- libs/hwui/hwui/Typeface.cpp | 6 ++--- libs/hwui/tests/unit/TypefaceTests.cpp | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/core/jni/android/graphics/FontFamily.cpp b/core/jni/android/graphics/FontFamily.cpp index 48aef4a8b320b..937b3ffb9d606 100644 --- a/core/jni/android/graphics/FontFamily.cpp +++ b/core/jni/android/graphics/FontFamily.cpp @@ -90,7 +90,7 @@ static void FontFamily_unref(jlong familyPtr) { } static bool addSkTypeface(NativeFamilyBuilder* builder, sk_sp&& data, int ttcIndex, - jint weight, jint italic) { + jint givenWeight, jint givenItalic) { uirenderer::FatVector skiaAxes; for (const auto& axis : builder->axes) { skiaAxes.emplace_back(SkFontArguments::Axis{axis.axisTag, axis.value}); @@ -114,15 +114,27 @@ static bool addSkTypeface(NativeFamilyBuilder* builder, sk_sp&& data, in std::shared_ptr minikinFont = std::make_shared(std::move(face), fontPtr, fontSize, ttcIndex, builder->axes); - minikin::Font::Builder fontBuilder(minikinFont); - if (weight != RESOLVE_BY_FONT_TABLE) { - fontBuilder.setWeight(weight); + 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 = 400; + os2Italic = false; + } + if (givenWeight == RESOLVE_BY_FONT_TABLE) { + weight = os2Weight; + } + if (givenItalic == RESOLVE_BY_FONT_TABLE) { + italic = os2Italic; + } } - if (italic != RESOLVE_BY_FONT_TABLE) { - fontBuilder.setSlant(static_cast(italic != 0)); - } - builder->fonts.push_back(fontBuilder.build()); + + builder->fonts.push_back(minikin::Font(minikinFont, + minikin::FontStyle(weight, static_cast(italic)))); builder->axes.clear(); return true; } diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp index 482d028a67f35..115d0d5a608b2 100644 --- a/core/jni/android/graphics/Paint.cpp +++ b/core/jni/android/graphics/Paint.cpp @@ -576,7 +576,7 @@ namespace PaintGlue { minikin::FakedFont baseFont = typeface->fFontCollection->baseFontFaked(typeface->fStyle); float saveSkewX = paint->getTextSkewX(); bool savefakeBold = paint->isFakeBoldText(); - MinikinFontSkia::populateSkPaint(paint, baseFont.font->typeface().get(), baseFont.fakery); + MinikinFontSkia::populateSkPaint(paint, baseFont.font, baseFont.fakery); SkScalar spacing = paint->getFontMetrics(metrics); // The populateSkPaint call may have changed fake bold / text skew // because we want to measure with those effects applied, so now diff --git a/libs/hwui/hwui/Typeface.cpp b/libs/hwui/hwui/Typeface.cpp index dca9ef5559a62..091b5267881d6 100644 --- a/libs/hwui/hwui/Typeface.cpp +++ b/libs/hwui/hwui/Typeface.cpp @@ -132,8 +132,8 @@ Typeface* Typeface::createFromFamilies(std::vectorgetClosestMatch(defaultStyle).font->typeface().get(); + const minikin::MinikinFont* mf = + families.empty() ? nullptr : families[0]->getClosestMatch(defaultStyle).font; if (mf != nullptr) { SkTypeface* skTypeface = reinterpret_cast(mf)->GetSkTypeface(); const SkFontStyle& style = skTypeface->fontStyle(); @@ -183,7 +183,7 @@ void Typeface::setRobotoTypefaceForTest() { std::shared_ptr font = std::make_shared( std::move(typeface), data, st.st_size, 0, std::vector()); std::vector fonts; - fonts.push_back(minikin::Font::Builder(font).build()); + fonts.push_back(minikin::Font(std::move(font), minikin::FontStyle())); std::shared_ptr collection = std::make_shared( std::make_shared(std::move(fonts))); diff --git a/libs/hwui/tests/unit/TypefaceTests.cpp b/libs/hwui/tests/unit/TypefaceTests.cpp index e424a266bf725..2232c25de3456 100644 --- a/libs/hwui/tests/unit/TypefaceTests.cpp +++ b/libs/hwui/tests/unit/TypefaceTests.cpp @@ -57,7 +57,7 @@ std::shared_ptr buildFamily(const char* fileName) { std::shared_ptr font = std::make_shared( std::move(typeface), data, st.st_size, 0, std::vector()); std::vector fonts; - fonts.push_back(minikin::Font::Builder(font).build()); + fonts.push_back(minikin::Font(std::move(font), minikin::FontStyle())); return std::make_shared(std::move(fonts)); }