Why is a glyph drawn that is not part of the font?

Assume the following code snippet:


  UIFont* systemFont = [UIFont systemFontOfSize:20.0];
  
  NSDictionary<NSAttributedStringKey,id>* attributes = [NSDictionary dictionaryWithObject:systemFont forKey:NSFontAttributeName];
  
  [@"" drawAtPoint:CGPointMake(100.0,100.0) withAttributes:attributes];

When checking the system font if the glyph (smiley) does exist the result is NO. But the glyph is correctly drawn. Why? 😕


The smiley exists only in font "Apple Color Emoji".

Replies

Do you show all the code ?


I do not understand how an empty string should draw as some charecter, smiley or not.

Hi,


sorry, it seems to be that the smiley got lost during the copy & paste operation. Here again with smiley:

UIFont* systemFont = [UIFont systemFontOfSize:20.0];
NSDictionary* attributes = [NSDictionary dictionaryWithObject:systemFont forKey:NSFontAttrib
uteName];
 [@"

🙂

" drawAtPoint:CGPointMake(100.0,100.0) withAttributes:attributes];


Sorry for the format but it seems to be that the editor is not really able to handle the smileys....

When the character is not found in the characterset, it is drawn as is. That works for smileys or for any other character that is not in system font. It works so with plain text as well as with attributed.


And it is drawn at the specified size.


In fact, I find it a very good behavior: it avoids leaving you with missing characters or with characters substituted by the unknown character.

If you need to skip the characters that are not in system font, you can always filter the String to test of existence in systemFont.

Hi,


but what kind of logic is behind finding the character in another font? I mean which font is used when the character does not exist in the system font?


BTW: I rather find this behaviour odd. I understand that for most people it is the easiest solution but it leads to unpredictable behaviour with respect to the chosen font.