[Impeller] Use ascent/descent rather than deprecated top/bottom for glyph bounds (flutter/engine#35960)

This commit is contained in:
Brandon DeRosier 2022-09-06 23:57:31 -07:00 committed by GitHub
parent 380692b661
commit faa5bea1b9
3 changed files with 19 additions and 14 deletions

View File

@ -138,7 +138,9 @@ bool TextContents::Render(const ContentContext& renderer,
Point{font.GetMetrics().min_extent.x, font.GetMetrics().ascent};
vtx.glyph_size = Point{static_cast<Scalar>(glyph_size.width),
static_cast<Scalar>(glyph_size.height)};
vtx.atlas_position = atlas_glyph_pos->origin;
vtx.atlas_position =
atlas_glyph_pos->origin + Point{1 / atlas_glyph_pos->size.width,
1 / atlas_glyph_pos->size.height};
vtx.atlas_glyph_size =
Point{atlas_glyph_pos->size.width, atlas_glyph_pos->size.height};
vertex_builder.AppendVertex(std::move(vtx));

View File

@ -23,8 +23,8 @@ static Font ToFont(const SkFont& font, Scalar scale) {
metrics.point_size = font.getSize();
metrics.ascent = sk_metrics.fAscent;
metrics.descent = sk_metrics.fDescent;
metrics.min_extent = {sk_metrics.fXMin, sk_metrics.fTop};
metrics.max_extent = {sk_metrics.fXMax, sk_metrics.fBottom};
metrics.min_extent = {sk_metrics.fXMin, sk_metrics.fAscent};
metrics.max_extent = {sk_metrics.fXMax, sk_metrics.fDescent};
return Font{std::move(typeface), std::move(metrics)};
}

View File

@ -122,13 +122,14 @@ static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas,
atlas.IterateGlyphs([canvas](const FontGlyphPair& font_glyph,
const Rect& location) -> bool {
const auto position = SkPoint::Make(location.origin.x, location.origin.y);
const auto position =
SkPoint::Make(location.origin.x / font_glyph.font.GetMetrics().scale,
location.origin.y / font_glyph.font.GetMetrics().scale);
SkGlyphID glyph_id = font_glyph.glyph.index;
SkFont sk_font(
TypefaceSkia::Cast(*font_glyph.font.GetTypeface()).GetSkiaTypeface(),
font_glyph.font.GetMetrics().point_size *
font_glyph.font.GetMetrics().scale);
font_glyph.font.GetMetrics().point_size);
const auto& metrics = font_glyph.font.GetMetrics();
@ -136,14 +137,16 @@ static std::shared_ptr<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas,
SkPaint glyph_paint;
glyph_paint.setColor(glyph_color);
canvas->drawGlyphs(
1u, // count
&glyph_id, // glyphs
&position, // positions
SkPoint::Make(-metrics.min_extent.x * metrics.scale,
-metrics.ascent * metrics.scale), // origin
sk_font, // font
glyph_paint // paint
canvas->resetMatrix();
canvas->scale(font_glyph.font.GetMetrics().scale,
font_glyph.font.GetMetrics().scale);
canvas->drawGlyphs(1u, // count
&glyph_id, // glyphs
&position, // positions
SkPoint::Make(-metrics.min_extent.x,
-metrics.ascent), // origin
sk_font, // font
glyph_paint // paint
);
return true;
});