321 {
324 return nullptr;
325 }
327 std::shared_ptr<GlyphAtlas> last_atlas = atlas_context->GetGlyphAtlas();
328
329 if (font_glyph_map.empty()) {
330 return last_atlas;
331 }
332
333
334
335
336
337 std::vector<FontGlyphPair> new_glyphs;
338 for (const auto& font_value : font_glyph_map) {
339 const ScaledFont& scaled_font = font_value.first;
340 const FontGlyphAtlas* font_glyph_atlas =
341 last_atlas->GetFontGlyphAtlas(scaled_font.font, scaled_font.scale);
342 if (font_glyph_atlas) {
343 for (
const Glyph& glyph : font_value.second) {
344 if (!font_glyph_atlas->FindGlyphBounds(glyph)) {
345 new_glyphs.emplace_back(scaled_font, glyph);
346 }
347 }
348 } else {
349 for (
const Glyph& glyph : font_value.second) {
350 new_glyphs.emplace_back(scaled_font, glyph);
351 }
352 }
353 }
354 if (last_atlas->GetType() ==
type && new_glyphs.size() == 0) {
355 return last_atlas;
356 }
357
358
359
360
361
362
363 std::vector<Rect> glyph_positions;
364 if (last_atlas->GetType() ==
type &&
366 atlas_context->GetAtlasSize(),
367 atlas_context->GetRectPacker())) {
368
369
370
371
372
373
374
375 for (
size_t i = 0,
count = glyph_positions.size(); i <
count; i++) {
376 last_atlas->AddTypefaceGlyphPosition(new_glyphs[i], glyph_positions[i]);
377 }
378
379
380
381
382 auto bitmap = atlas_context_skia.GetBitmap();
384 return nullptr;
385 }
386
387
388
389
391 return nullptr;
392 }
393 return last_atlas;
394 }
395
396
397
398
399
400 std::vector<FontGlyphPair> font_glyph_pairs;
401 font_glyph_pairs.reserve(std::accumulate(
402 font_glyph_map.begin(), font_glyph_map.end(), 0,
403 [](
const int a,
const auto&
b) { return a + b.second.size(); }));
404 for (const auto& font_value : font_glyph_map) {
405 const ScaledFont& scaled_font = font_value.first;
406 for (
const Glyph& glyph : font_value.second) {
407 font_glyph_pairs.push_back({scaled_font, glyph});
408 }
409 }
410 auto glyph_atlas = std::make_shared<GlyphAtlas>(
type);
412 font_glyph_pairs,
413 glyph_positions,
414 atlas_context,
416 context.GetResourceAllocator()->GetMaxTextureSizeSupported()
417 );
418
419 atlas_context->UpdateGlyphAtlas(glyph_atlas, atlas_size);
420 if (atlas_size.IsEmpty()) {
421 return nullptr;
422 }
423
424
425
426
427
428
429 if (glyph_positions.size() != font_glyph_pairs.size()) {
430 return nullptr;
431 }
432
433
434
435
436 {
437 size_t i = 0;
438 for (auto it = font_glyph_pairs.begin(); it != font_glyph_pairs.end();
439 ++i, ++it) {
440 glyph_atlas->AddTypefaceGlyphPosition(*it, glyph_positions[i]);
441 }
442 }
443
444
445
446
449 return nullptr;
450 }
451 atlas_context_skia.UpdateBitmap(
bitmap);
452
453
454
455
459 format = context.GetCapabilities()->GetDefaultGlyphAtlasFormat();
460 break;
463 break;
464 }
468 return nullptr;
469 }
470
471
472
473
474 glyph_atlas->SetTexture(std::move(
texture));
475
476 return glyph_atlas;
477}
static GlyphAtlasContextSkia & 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)