Changeset - r28453:68a15f36b252
[Not reviewed]
master
0 1 0
Michael Lutz - 12 months ago 2023-12-16 01:30:12
michi@icosahedron.de
Fix: [OSX] Spurious log message when a sprite glyph was layouted.
1 file changed with 7 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/os/macosx/string_osx.cpp
Show inline comments
 
@@ -165,12 +165,15 @@ static CTRunDelegateCallbacks _sprite_fo
 
	CFAutoRelease<CFMutableAttributedStringRef> str(CFAttributedStringCreateMutable(kCFAllocatorDefault, 0));
 
	CFAttributedStringBeginEditing(str.get());
 

	
 
	CFAutoRelease<CFStringRef> base(CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, buff, length, kCFAllocatorNull));
 
	CFAttributedStringReplaceString(str.get(), CFRangeMake(0, 0), base.get());
 

	
 
	const UniChar replacment_char = 0xFFFC;
 
	CFAutoRelease<CFStringRef> replacment_str(CFStringCreateWithCharacters(kCFAllocatorDefault, &replacment_char, 1));
 

	
 
	/* 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 : fontMapping) {
 
		if (i.first - last == 0) continue;
 

	
 
@@ -190,12 +193,14 @@ static CTRunDelegateCallbacks _sprite_fo
 
		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))));
 
				/* 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;
 
	}
 
@@ -239,13 +244,14 @@ CoreTextParagraphLayout::CoreTextVisualR
 

	
 
	/* Convert glyph array to our data type. At the same time, substitute
 
	 * the proper glyphs for our private sprite glyphs. */
 
	CGGlyph gl[this->glyphs.size()];
 
	CTRunGetGlyphs(run, CFRangeMake(0, 0), gl);
 
	for (size_t i = 0; i < this->glyphs.size(); i++) {
 
		if (buff[this->glyph_to_char[i]] >= SCC_SPRITE_START && buff[this->glyph_to_char[i]] <= SCC_SPRITE_END && gl[i] == 0) {
 
		if (buff[this->glyph_to_char[i]] >= SCC_SPRITE_START && buff[this->glyph_to_char[i]] <= SCC_SPRITE_END && (gl[i] == 0 || gl[i] == 3)) {
 
			/* A glyph of 0 indidicates not found, while apparently 3 is what char 0xFFFC maps to. */
 
			this->glyphs[i] = font->fc->MapCharToGlyph(buff[this->glyph_to_char[i]]);
 
			this->positions[i * 2 + 0] = pts[i].x;
 
			this->positions[i * 2 + 1] = (font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(font->fc->GetSize()))) / 2; // Align sprite font to centre
 
		} else {
 
			this->glyphs[i] = gl[i];
 
			this->positions[i * 2 + 0] = pts[i].x;
0 comments (0 inline, 0 general)