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

Commit 910ba90

Browse files
committed
[Impeller] Make text appear less emboldened
1 parent 868234d commit 910ba90

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

impeller/typographer/backends/skia/text_frame_skia.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static Font ToFont(const SkTextBlobRunIterator& run, Scalar scale) {
2929
metrics.point_size = font.getSize();
3030
metrics.embolden = font.isEmbolden();
3131
metrics.skewX = font.getSkewX();
32+
metrics.scaleX = font.getScaleX();
3233

3334
return Font{std::move(typeface), metrics};
3435
}

impeller/typographer/backends/skia/text_render_context_skia.cc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,21 +287,21 @@ static void ConvertBitmapToSignedDistanceField(uint8_t* pixels,
287287

288288
static void DrawGlyph(SkCanvas* canvas,
289289
const FontGlyphPair& font_glyph,
290-
const Rect& location) {
290+
const Rect& location,
291+
bool has_color) {
291292
const auto& metrics = font_glyph.font.GetMetrics();
292293
const auto position = SkPoint::Make(location.origin.x / metrics.scale,
293294
location.origin.y / metrics.scale);
294295
SkGlyphID glyph_id = font_glyph.glyph.index;
295296

296297
SkFont sk_font(
297298
TypefaceSkia::Cast(*font_glyph.font.GetTypeface()).GetSkiaTypeface(),
298-
metrics.point_size);
299+
metrics.point_size, metrics.scaleX, metrics.skewX);
299300
sk_font.setEdging(SkFont::Edging::kAntiAlias);
300301
sk_font.setHinting(SkFontHinting::kSlight);
301302
sk_font.setEmbolden(metrics.embolden);
302-
sk_font.setSkewX(metrics.skewX);
303303

304-
auto glyph_color = SK_ColorWHITE;
304+
auto glyph_color = has_color ? SK_ColorWHITE : SK_ColorBLACK;
305305

306306
SkPaint glyph_paint;
307307
glyph_paint.setColor(glyph_color);
@@ -333,12 +333,14 @@ static bool UpdateAtlasBitmap(const GlyphAtlas& atlas,
333333
return false;
334334
}
335335

336+
bool has_color = atlas.GetType() == GlyphAtlas::Type::kColorBitmap;
337+
336338
for (const auto& pair : new_pairs) {
337339
auto pos = atlas.FindFontGlyphPosition(pair);
338340
if (!pos.has_value()) {
339341
continue;
340342
}
341-
DrawGlyph(canvas, pair, pos.value());
343+
DrawGlyph(canvas, pair, pos.value(), has_color);
342344
}
343345
return true;
344346
}
@@ -373,11 +375,13 @@ static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas,
373375
return nullptr;
374376
}
375377

376-
atlas.IterateGlyphs(
377-
[canvas](const FontGlyphPair& font_glyph, const Rect& location) -> bool {
378-
DrawGlyph(canvas, font_glyph, location);
379-
return true;
380-
});
378+
bool has_color = atlas.GetType() == GlyphAtlas::Type::kColorBitmap;
379+
380+
atlas.IterateGlyphs([canvas, has_color](const FontGlyphPair& font_glyph,
381+
const Rect& location) -> bool {
382+
DrawGlyph(canvas, font_glyph, location, has_color);
383+
return true;
384+
});
381385

382386
return bitmap;
383387
}

impeller/typographer/font.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ class Font : public Comparable<Font> {
4141
Scalar point_size = 12.0f;
4242
bool embolden = false;
4343
Scalar skewX = 0.0f;
44+
Scalar scaleX = 1.0f;
4445

4546
constexpr bool operator==(const Metrics& o) const {
4647
return scale == o.scale && point_size == o.point_size &&
47-
embolden == o.embolden && skewX == o.skewX;
48+
embolden == o.embolden && skewX == o.skewX && scaleX == o.scaleX;
4849
}
4950
};
5051

0 commit comments

Comments
 (0)