[Impeller] Make text appear less emboldened (flutter/engine#39383)

This commit is contained in:
Brandon DeRosier
2023-02-03 22:34:09 -08:00
committed by GitHub
parent 146694ca7b
commit 54686edb5d
3 changed files with 17 additions and 11 deletions

View File

@@ -29,6 +29,7 @@ static Font ToFont(const SkTextBlobRunIterator& run, Scalar scale) {
metrics.point_size = font.getSize();
metrics.embolden = font.isEmbolden();
metrics.skewX = font.getSkewX();
metrics.scaleX = font.getScaleX();
return Font{std::move(typeface), metrics};
}

View File

@@ -287,7 +287,8 @@ static void ConvertBitmapToSignedDistanceField(uint8_t* pixels,
static void DrawGlyph(SkCanvas* canvas,
const FontGlyphPair& font_glyph,
const Rect& location) {
const Rect& location,
bool has_color) {
const auto& metrics = font_glyph.font.GetMetrics();
const auto position = SkPoint::Make(location.origin.x / metrics.scale,
location.origin.y / metrics.scale);
@@ -295,13 +296,12 @@ static void DrawGlyph(SkCanvas* canvas,
SkFont sk_font(
TypefaceSkia::Cast(*font_glyph.font.GetTypeface()).GetSkiaTypeface(),
metrics.point_size);
metrics.point_size, metrics.scaleX, metrics.skewX);
sk_font.setEdging(SkFont::Edging::kAntiAlias);
sk_font.setHinting(SkFontHinting::kSlight);
sk_font.setEmbolden(metrics.embolden);
sk_font.setSkewX(metrics.skewX);
auto glyph_color = SK_ColorWHITE;
auto glyph_color = has_color ? SK_ColorWHITE : SK_ColorBLACK;
SkPaint glyph_paint;
glyph_paint.setColor(glyph_color);
@@ -333,12 +333,14 @@ static bool UpdateAtlasBitmap(const GlyphAtlas& atlas,
return false;
}
bool has_color = atlas.GetType() == GlyphAtlas::Type::kColorBitmap;
for (const auto& pair : new_pairs) {
auto pos = atlas.FindFontGlyphPosition(pair);
if (!pos.has_value()) {
continue;
}
DrawGlyph(canvas, pair, pos.value());
DrawGlyph(canvas, pair, pos.value(), has_color);
}
return true;
}
@@ -373,11 +375,13 @@ static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas,
return nullptr;
}
atlas.IterateGlyphs(
[canvas](const FontGlyphPair& font_glyph, const Rect& location) -> bool {
DrawGlyph(canvas, font_glyph, location);
return true;
});
bool has_color = atlas.GetType() == GlyphAtlas::Type::kColorBitmap;
atlas.IterateGlyphs([canvas, has_color](const FontGlyphPair& font_glyph,
const Rect& location) -> bool {
DrawGlyph(canvas, font_glyph, location, has_color);
return true;
});
return bitmap;
}

View File

@@ -41,10 +41,11 @@ class Font : public Comparable<Font> {
Scalar point_size = 12.0f;
bool embolden = false;
Scalar skewX = 0.0f;
Scalar scaleX = 1.0f;
constexpr bool operator==(const Metrics& o) const {
return scale == o.scale && point_size == o.point_size &&
embolden == o.embolden && skewX == o.skewX;
embolden == o.embolden && skewX == o.skewX && scaleX == o.scaleX;
}
};