Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
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
3 changes: 3 additions & 0 deletions impeller/typographer/backends/skia/text_frame_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ static Font ToFont(const SkTextBlobRunIterator& run, Scalar scale) {
Font::Metrics metrics;
metrics.scale = 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
14 changes: 10 additions & 4 deletions impeller/typographer/backends/skia/text_render_context_skia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,23 @@ static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas,
return nullptr;
}

atlas.IterateGlyphs([canvas](const FontGlyphPair& font_glyph,
const Rect& location) -> bool {
bool has_color = atlas.GetType() == GlyphAtlas::Type::kColorBitmap;

atlas.IterateGlyphs([canvas, has_color](const FontGlyphPair& font_glyph,
const Rect& location) -> bool {
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);
auto glyph_color = SK_ColorWHITE;
metrics.point_size, metrics.scaleX, metrics.skewX);
sk_font.setEdging(SkFont::Edging::kAntiAlias);
sk_font.setHinting(SkFontHinting::kSlight);
sk_font.setEmbolden(metrics.embolden);

auto glyph_color = has_color ? SK_ColorWHITE : SK_ColorBLACK;

SkPaint glyph_paint;
glyph_paint.setColor(glyph_color);
Expand Down
7 changes: 6 additions & 1 deletion impeller/typographer/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "impeller/base/comparable.h"
#include "impeller/typographer/glyph.h"
#include "impeller/typographer/typeface.h"
#include "include/core/SkFont.h"

namespace impeller {

Expand Down Expand Up @@ -38,9 +39,13 @@ class Font : public Comparable<Font> {
/// The point size of the 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;
return scale == o.scale && point_size == o.point_size &&
embolden == o.embolden && skewX == o.skewX && scaleX == o.scaleX;
}
};

Expand Down