374 {
377 return nullptr;
378 }
380 std::shared_ptr<GlyphAtlas> last_atlas = atlas_context->GetGlyphAtlas();
381
382 if (font_glyph_map.empty()) {
383 return last_atlas;
384 }
385
386
387
388
389
390 std::vector<FontGlyphPair> new_glyphs;
391 for (const auto& font_value : font_glyph_map) {
392 const ScaledFont& scaled_font = font_value.first;
393 const FontGlyphAtlas* font_glyph_atlas =
394 last_atlas->GetFontGlyphAtlas(scaled_font.font, scaled_font.scale);
395 if (font_glyph_atlas) {
396 for (
const Glyph& glyph : font_value.second) {
397 if (!font_glyph_atlas->FindGlyphBounds(glyph)) {
398 new_glyphs.emplace_back(scaled_font, glyph);
399 }
400 }
401 } else {
402 for (
const Glyph& glyph : font_value.second) {
403 new_glyphs.emplace_back(scaled_font, glyph);
404 }
405 }
406 }
407 if (last_atlas->GetType() ==
type && new_glyphs.size() == 0) {
408 return last_atlas;
409 }
410
411
412
413
414
415
416 std::vector<Rect> glyph_positions;
417 if (last_atlas->GetType() ==
type &&
419 atlas_context->GetAtlasSize(),
420 atlas_context->GetRectPacker())) {
421
422
423
424
425
426
427
428 for (
size_t i = 0,
count = glyph_positions.size(); i <
count; i++) {
429 last_atlas->AddTypefaceGlyphPosition(new_glyphs[i], glyph_positions[i]);
430 }
431
432
433
434
435
436 auto bitmap = atlas_context_stb.GetBitmap();
438 return nullptr;
439 }
440
441
442
443
445 return nullptr;
446 }
447 return last_atlas;
448 }
449
450
451
452
453
454 std::vector<FontGlyphPair> font_glyph_pairs;
455 font_glyph_pairs.reserve(std::accumulate(
456 font_glyph_map.begin(), font_glyph_map.end(), 0,
457 [](
const int a,
const auto&
b) { return a + b.second.size(); }));
458 for (const auto& font_value : font_glyph_map) {
459 const ScaledFont& scaled_font = font_value.first;
460 for (
const Glyph& glyph : font_value.second) {
461 font_glyph_pairs.push_back({scaled_font, glyph});
462 }
463 }
464 auto glyph_atlas = std::make_shared<GlyphAtlas>(
type);
466 font_glyph_pairs,
467 glyph_positions,
468 atlas_context,
470 context.GetResourceAllocator()->GetMaxTextureSizeSupported()
471 );
472
473 atlas_context->UpdateGlyphAtlas(glyph_atlas, atlas_size);
474 if (atlas_size.IsEmpty()) {
475 return nullptr;
476 }
477
478
479
480
481
482
483
484 if (glyph_positions.size() != font_glyph_pairs.size()) {
485 return nullptr;
486 }
487
488
489
490
491 {
492 size_t i = 0;
493 for (auto it = font_glyph_pairs.begin(); it != font_glyph_pairs.end();
494 ++i, ++it) {
495 glyph_atlas->AddTypefaceGlyphPosition(*it, glyph_positions[i]);
496 }
497 }
498
499
500
501
504 return nullptr;
505 }
506 atlas_context_stb.UpdateBitmap(
bitmap);
507
508
509
510
514 format = context.GetCapabilities()->GetDefaultGlyphAtlasFormat();
515 break;
518 ? context.GetCapabilities()->GetDefaultGlyphAtlasFormat()
520 break;
521 }
525 return nullptr;
526 }
527
528
529
530
531 glyph_atlas->SetTexture(std::move(
texture));
532
533 return glyph_atlas;
534}
static GlyphAtlasContextSTB & Cast(GlyphAtlasContext &base)
virtual bool IsValid() const
uint32_t uint32_t * format
static std::shared_ptr< Texture > UploadGlyphTextureAtlas(const std::shared_ptr< Allocator > &allocator, std::shared_ptr< SkBitmap > bitmap, const ISize &atlas_size, PixelFormat format)
static std::shared_ptr< SkBitmap > CreateAtlasBitmap(const GlyphAtlas &atlas, const ISize &atlas_size)
static ISize OptimumAtlasSizeForFontGlyphPairs(const std::vector< FontGlyphPair > &pairs, std::vector< Rect > &glyph_positions, const std::shared_ptr< GlyphAtlasContext > &atlas_context, GlyphAtlas::Type type, const ISize &max_texture_size)
static bool UpdateGlyphTextureAtlas(std::shared_ptr< SkBitmap > bitmap, const std::shared_ptr< Texture > &texture)
static bool UpdateAtlasBitmap(const GlyphAtlas &atlas, const std::shared_ptr< SkBitmap > &bitmap, const std::vector< FontGlyphPair > &new_pairs)
static bool CanAppendToExistingAtlas(const std::shared_ptr< GlyphAtlas > &atlas, const std::vector< FontGlyphPair > &extra_pairs, std::vector< Rect > &glyph_positions, ISize atlas_size, const std::shared_ptr< RectanglePacker > &rect_packer)
#define TRACE_EVENT0(category_group, name)
#define DISABLE_COLOR_FONT_SUPPORT