Codechange: Use structured bindings when iterating font_mapping.
This commit is contained in:
committed by
Peter Nelson
parent
c78e309b16
commit
59680867c3
@@ -157,8 +157,8 @@ static CTRunDelegateCallbacks _sprite_font_callback = {
|
||||
if (length == 0) return nullptr;
|
||||
|
||||
/* Can't layout our in-built sprite fonts. */
|
||||
for (const auto &i : font_mapping) {
|
||||
if (i.second->fc->IsBuiltInFont()) return nullptr;
|
||||
for (const auto &[position, font] : font_mapping) {
|
||||
if (font->fc->IsBuiltInFont()) return nullptr;
|
||||
}
|
||||
|
||||
/* Make attributed string with embedded font information. */
|
||||
@@ -174,35 +174,35 @@ static CTRunDelegateCallbacks _sprite_font_callback = {
|
||||
/* Apply font and colour ranges to our string. This is important to make sure
|
||||
* that we get proper glyph boundaries on style changes. */
|
||||
int last = 0;
|
||||
for (const auto &i : font_mapping) {
|
||||
if (i.first - last == 0) continue;
|
||||
for (const auto &[position, font] : font_mapping) {
|
||||
if (position - last == 0) continue;
|
||||
|
||||
CTFontRef font = (CTFontRef)i.second->fc->GetOSHandle();
|
||||
if (font == nullptr) {
|
||||
if (!_font_cache[i.second->fc->GetSize()]) {
|
||||
CTFontRef font_handle = static_cast<CTFontRef>(font->fc->GetOSHandle());
|
||||
if (font_handle == nullptr) {
|
||||
if (!_font_cache[font->fc->GetSize()]) {
|
||||
/* Cache font information. */
|
||||
CFAutoRelease<CFStringRef> font_name(CFStringCreateWithCString(kCFAllocatorDefault, i.second->fc->GetFontName().c_str(), kCFStringEncodingUTF8));
|
||||
_font_cache[i.second->fc->GetSize()].reset(CTFontCreateWithName(font_name.get(), i.second->fc->GetFontSize(), nullptr));
|
||||
CFAutoRelease<CFStringRef> font_name(CFStringCreateWithCString(kCFAllocatorDefault, font->fc->GetFontName().c_str(), kCFStringEncodingUTF8));
|
||||
_font_cache[font->fc->GetSize()].reset(CTFontCreateWithName(font_name.get(), font->fc->GetFontSize(), nullptr));
|
||||
}
|
||||
font = _font_cache[i.second->fc->GetSize()].get();
|
||||
font_handle = _font_cache[font->fc->GetSize()].get();
|
||||
}
|
||||
CFAttributedStringSetAttribute(str.get(), CFRangeMake(last, i.first - last), kCTFontAttributeName, font);
|
||||
CFAttributedStringSetAttribute(str.get(), CFRangeMake(last, position - last), kCTFontAttributeName, font_handle);
|
||||
|
||||
CGColorRef color = CGColorCreateGenericGray((uint8_t)i.second->colour / 255.0f, 1.0f); // We don't care about the real colours, just that they are different.
|
||||
CFAttributedStringSetAttribute(str.get(), CFRangeMake(last, i.first - last), kCTForegroundColorAttributeName, color);
|
||||
CGColorRef color = CGColorCreateGenericGray((uint8_t)font->colour / 255.0f, 1.0f); // We don't care about the real colours, just that they are different.
|
||||
CFAttributedStringSetAttribute(str.get(), CFRangeMake(last, position - last), kCTForegroundColorAttributeName, color);
|
||||
CGColorRelease(color);
|
||||
|
||||
/* Install a size callback for our special private-use sprite glyphs in case the font does not provide them. */
|
||||
for (ssize_t c = last; c < i.first; c++) {
|
||||
if (buff[c] >= SCC_SPRITE_START && buff[c] <= SCC_SPRITE_END && i.second->fc->MapCharToGlyph(buff[c], false) == 0) {
|
||||
CFAutoRelease<CTRunDelegateRef> del(CTRunDelegateCreate(&_sprite_font_callback, (void *)(size_t)(buff[c] | (i.second->fc->GetSize() << 24))));
|
||||
for (ssize_t c = last; c < position; c++) {
|
||||
if (buff[c] >= SCC_SPRITE_START && buff[c] <= SCC_SPRITE_END && font->fc->MapCharToGlyph(buff[c], false) == 0) {
|
||||
CFAutoRelease<CTRunDelegateRef> del(CTRunDelegateCreate(&_sprite_font_callback, (void *)(size_t)(buff[c] | (font->fc->GetSize() << 24))));
|
||||
/* According to the offical documentation, if a run delegate is used, the char should always be 0xFFFC. */
|
||||
CFAttributedStringReplaceString(str.get(), CFRangeMake(c, 1), replacment_str.get());
|
||||
CFAttributedStringSetAttribute(str.get(), CFRangeMake(c, 1), kCTRunDelegateAttributeName, del.get());
|
||||
}
|
||||
}
|
||||
|
||||
last = i.first;
|
||||
last = position;
|
||||
}
|
||||
CFAttributedStringEndEditing(str.get());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user