| 74 | } |
| 75 | |
| 76 | int32 Font::GetKerning(Char first, Char second) const |
| 77 | { |
| 78 | int32 kerning = 0; |
| 79 | const uint32 key = (uint32)first << 16 | second; |
| 80 | if (_hasKerning && !_kerningTable.TryGet(key, kerning)) |
| 81 | { |
| 82 | // This thread race condition may happen in editor but in game we usually do all stuff with fonts on main thread (chars caching) |
| 83 | ScopeLock lock(_asset->Locker); |
| 84 | |
| 85 | // Handle situation when more than one thread wants to get the same character |
| 86 | if (!_kerningTable.TryGet(key, kerning)) |
| 87 | { |
| 88 | const FT_Face face = _asset->GetFTFace(); |
| 89 | ASSERT(face); |
| 90 | |
| 91 | FlushFaceSize(); |
| 92 | |
| 93 | FT_Vector vec; |
| 94 | const FT_UInt firstIndex = FT_Get_Char_Index(face, first); |
| 95 | const FT_UInt secondIndex = FT_Get_Char_Index(face, second); |
| 96 | FT_Get_Kerning(face, firstIndex, secondIndex, FT_KERNING_DEFAULT, &vec); |
| 97 | kerning = vec.x >> 6; |
| 98 | |
| 99 | _kerningTable.Add(key, kerning); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | return kerning; |
| 104 | } |
| 105 | |
| 106 | void Font::CacheText(const StringView& text) |
| 107 | { |
no test coverage detected