Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Make dark text appear less emboldened #39383

Merged
merged 1 commit into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions impeller/typographer/backends/skia/text_frame_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand Down
24 changes: 14 additions & 10 deletions impeller/typographer/backends/skia/text_render_context_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,21 +287,21 @@ 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);
SkGlyphID glyph_id = font_glyph.glyph.index;

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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion impeller/typographer/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand Down