| 35 | } |
| 36 | |
| 37 | void Font::GetCharacter(Char c, FontCharacterEntry& result, bool enableFallback) |
| 38 | { |
| 39 | // Try to get the character or cache it if cannot be found |
| 40 | if (!_characters.TryGet(c, result)) |
| 41 | { |
| 42 | // This thread race condition may happen in editor but in game we usually do all stuff with fonts on main thread (chars caching) |
| 43 | ScopeLock lock(_asset->Locker); |
| 44 | |
| 45 | // Handle situation when more than one thread wants to get the same character |
| 46 | if (_characters.TryGet(c, result)) |
| 47 | return; |
| 48 | |
| 49 | // Try to use fallback font if character is missing |
| 50 | if (enableFallback && !_asset->ContainsChar(c)) |
| 51 | { |
| 52 | for (int32 fallbackIndex = 0; fallbackIndex < FallbackFonts.Count(); fallbackIndex++) |
| 53 | { |
| 54 | FontAsset* fallbackFont = FallbackFonts.Get()[fallbackIndex].Get(); |
| 55 | if (fallbackFont && _asset->GetOptions().RasterMode == FontRasterMode::MSDF) |
| 56 | { |
| 57 | fallbackFont = fallbackFont->GetMSDF(); |
| 58 | } |
| 59 | if (fallbackFont && fallbackFont->ContainsChar(c)) |
| 60 | { |
| 61 | fallbackFont->CreateFont(GetSize())->GetCharacter(c, result, enableFallback); |
| 62 | return; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // Create character cache |
| 68 | FontManager::AddNewEntry(this, c, result); |
| 69 | ASSERT(result.Font); |
| 70 | |
| 71 | // Add to the dictionary |
| 72 | _characters.Add(c, result); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | int32 Font::GetKerning(Char first, Char second) const |
| 77 | { |
no test coverage detected