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

Commit 3b5c7a1

Browse files
zandersobdero
andauthored
[CP] [Impeller] Retain embolden/skew font properties when rendering text g… (#39424)
* [Impeller] Retain embolden/skew font properties when rendering text glyphs (#39378) * [Impeller] Make text appear less emboldened (#39383) --------- Co-authored-by: Brandon DeRosier <bdero@google.com>
1 parent 341b8c0 commit 3b5c7a1

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

impeller/typographer/backends/skia/text_frame_skia.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ static Font ToFont(const SkTextBlobRunIterator& run, Scalar scale) {
2727
Font::Metrics metrics;
2828
metrics.scale = scale;
2929
metrics.point_size = font.getSize();
30+
metrics.embolden = font.isEmbolden();
31+
metrics.skewX = font.getSkewX();
32+
metrics.scaleX = font.getScaleX();
3033

3134
return Font{std::move(typeface), metrics};
3235
}

impeller/typographer/backends/skia/text_render_context_skia.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,17 +272,23 @@ static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas,
272272
return nullptr;
273273
}
274274

275-
atlas.IterateGlyphs([canvas](const FontGlyphPair& font_glyph,
276-
const Rect& location) -> bool {
275+
bool has_color = atlas.GetType() == GlyphAtlas::Type::kColorBitmap;
276+
277+
atlas.IterateGlyphs([canvas, has_color](const FontGlyphPair& font_glyph,
278+
const Rect& location) -> bool {
277279
const auto& metrics = font_glyph.font.GetMetrics();
278280
const auto position = SkPoint::Make(location.origin.x / metrics.scale,
279281
location.origin.y / metrics.scale);
280282
SkGlyphID glyph_id = font_glyph.glyph.index;
281283

282284
SkFont sk_font(
283285
TypefaceSkia::Cast(*font_glyph.font.GetTypeface()).GetSkiaTypeface(),
284-
metrics.point_size);
285-
auto glyph_color = SK_ColorWHITE;
286+
metrics.point_size, metrics.scaleX, metrics.skewX);
287+
sk_font.setEdging(SkFont::Edging::kAntiAlias);
288+
sk_font.setHinting(SkFontHinting::kSlight);
289+
sk_font.setEmbolden(metrics.embolden);
290+
291+
auto glyph_color = has_color ? SK_ColorWHITE : SK_ColorBLACK;
286292

287293
SkPaint glyph_paint;
288294
glyph_paint.setColor(glyph_color);

impeller/typographer/font.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "impeller/base/comparable.h"
1212
#include "impeller/typographer/glyph.h"
1313
#include "impeller/typographer/typeface.h"
14+
#include "include/core/SkFont.h"
1415

1516
namespace impeller {
1617

@@ -38,9 +39,13 @@ class Font : public Comparable<Font> {
3839
/// The point size of the font.
3940
///
4041
Scalar point_size = 12.0f;
42+
bool embolden = false;
43+
Scalar skewX = 0.0f;
44+
Scalar scaleX = 1.0f;
4145

4246
constexpr bool operator==(const Metrics& o) const {
43-
return scale == o.scale && point_size == o.point_size;
47+
return scale == o.scale && point_size == o.point_size &&
48+
embolden == o.embolden && skewX == o.skewX && scaleX == o.scaleX;
4449
}
4550
};
4651

0 commit comments

Comments
 (0)