380 TRACE_EVENT0(
"impeller", __FUNCTION__);
385 std::shared_ptr<GlyphAtlas> last_atlas = atlas_context->GetGlyphAtlas();
387 if (font_glyph_map.empty()) {
395 std::vector<FontGlyphPair> new_glyphs;
396 for (
const auto& font_value : font_glyph_map) {
397 const ScaledFont& scaled_font = font_value.first;
398 const FontGlyphAtlas* font_glyph_atlas =
399 last_atlas->GetFontGlyphAtlas(scaled_font.font, scaled_font.scale);
400 if (font_glyph_atlas) {
401 for (
const Glyph& glyph : font_value.second) {
402 if (!font_glyph_atlas->FindGlyphBounds(glyph)) {
403 new_glyphs.emplace_back(scaled_font, glyph);
407 for (
const Glyph& glyph : font_value.second) {
408 new_glyphs.emplace_back(scaled_font, glyph);
412 if (last_atlas->GetType() == type && new_glyphs.size() == 0) {
421 std::vector<Rect> glyph_positions;
422 if (last_atlas->GetType() == type &&
424 atlas_context->GetAtlasSize(),
425 atlas_context->GetRectPacker())) {
433 for (
size_t i = 0, count = glyph_positions.size(); i < count; i++) {
434 last_atlas->AddTypefaceGlyphPosition(new_glyphs[i], glyph_positions[i]);
441 auto bitmap = atlas_context_stb.GetBitmap();
459 std::vector<FontGlyphPair> font_glyph_pairs;
460 font_glyph_pairs.reserve(std::accumulate(
461 font_glyph_map.begin(), font_glyph_map.end(), 0,
462 [](
const int a,
const auto&
b) { return a + b.second.size(); }));
463 for (
const auto& font_value : font_glyph_map) {
464 const ScaledFont& scaled_font = font_value.first;
465 for (
const Glyph& glyph : font_value.second) {
466 font_glyph_pairs.push_back({scaled_font, glyph});
469 auto glyph_atlas = std::make_shared<GlyphAtlas>(type);
475 context.GetResourceAllocator()->GetMaxTextureSizeSupported()
478 atlas_context->UpdateGlyphAtlas(glyph_atlas, atlas_size);
479 if (atlas_size.IsEmpty()) {
489 if (glyph_positions.size() != font_glyph_pairs.size()) {
498 for (
auto it = font_glyph_pairs.begin(); it != font_glyph_pairs.end();
500 glyph_atlas->AddTypefaceGlyphPosition(*it, glyph_positions[i]);
511 atlas_context_stb.UpdateBitmap(bitmap);
519 format = context.GetCapabilities()->GetDefaultGlyphAtlasFormat();
523 ? context.GetCapabilities()->GetDefaultGlyphAtlasFormat()
536 glyph_atlas->SetTexture(std::move(texture));