@@ -62,21 +62,19 @@ static bool PairsFitInAtlasOfSize(const FontGlyphPair::Vector& pairs,
62
62
glyph_positions.reserve (pairs.size ());
63
63
64
64
for (const auto & pair : pairs) {
65
- auto glyph_size = pair.font .GetGlyphSize ();
66
- if (!glyph_size.has_value ()) {
67
- continue ;
68
- }
65
+ const auto glyph_size =
66
+ ISize::Ceil (pair.font .GetMetrics ().GetBoundingBox ().size );
69
67
SkIPoint16 location_in_atlas;
70
- if (!rect_packer->addRect (glyph_size-> width , //
71
- glyph_size-> height , //
72
- &location_in_atlas //
68
+ if (!rect_packer->addRect (glyph_size. width , //
69
+ glyph_size. height , //
70
+ &location_in_atlas //
73
71
)) {
74
72
return false ;
75
73
}
76
74
glyph_positions.emplace_back (Rect::MakeXYWH (location_in_atlas.x (), //
77
75
location_in_atlas.y (), //
78
- glyph_size-> width , //
79
- glyph_size-> height //
76
+ glyph_size. width , //
77
+ glyph_size. height //
80
78
));
81
79
}
82
80
@@ -122,22 +120,46 @@ static std::optional<SkBitmap> CreateAtlasBitmap(const GlyphAtlas& atlas,
122
120
const Rect & location) -> bool {
123
121
const auto position = SkPoint::Make (location.origin .x , location.origin .y );
124
122
SkGlyphID glyph_id = font_glyph.glyph .index ;
125
- SkFont font (
123
+
124
+ SkFont sk_font (
126
125
TypefaceSkia::Cast (*font_glyph.font .GetTypeface ()).GetSkiaTypeface (),
127
126
font_glyph.font .GetMetrics ().point_size );
128
127
129
- SkFontMetrics metrics;
130
- font.getMetrics (&metrics);
128
+ const auto & metrics = font_glyph.font .GetMetrics ();
129
+
130
+ auto glyph_color = SK_ColorWHITE;
131
+
132
+ #if 0
133
+ {
134
+ glyph_color = SkColorSetARGB(255, //
135
+ std::rand() % 255, //
136
+ std::rand() % 255, //
137
+ std::rand() % 255 //
138
+ );
139
+ SkPaint debug_paint;
140
+ debug_paint.setARGB(255 / 4, //
141
+ std::rand() % 255, //
142
+ std::rand() % 255, //
143
+ std::rand() % 255 //
144
+ );
145
+ canvas->drawRect(SkRect::MakeXYWH(location.origin.x, //
146
+ location.origin.y, //
147
+ location.size.width, //
148
+ location.size.height //
149
+ ),
150
+ debug_paint);
151
+ }
152
+ #endif
131
153
132
154
SkPaint glyph_paint;
133
- glyph_paint.setColor (SK_ColorWHITE );
155
+ glyph_paint.setColor (glyph_color );
134
156
canvas->drawGlyphs (1u , // count
135
157
&glyph_id, // glyphs
136
158
&position, // positions
137
- SkPoint::Make (0.0 ,
138
- -metrics.fAscent ), // origin
139
- font, // font
140
- glyph_paint // paint
159
+ SkPoint::Make (-metrics. min_extent . x ,
160
+ -metrics.ascent ), // origin
161
+ sk_font, // font
162
+ glyph_paint // paint
141
163
);
142
164
return true ;
143
165
});
0 commit comments