Search Unity

Does/How/Will unity support surrogate pair?

Discussion in 'Scripting' started by geniusz, Nov 21, 2014.

  1. geniusz

    geniusz

    Joined:
    Nov 21, 2014
    Posts:
    38
    I found the unicode of some emoji characters on Android/iOS are larger than 0xFFFF (eg: U+1F40C).
    But the method "Font.GetCharacterInfo" can get info only from one char parameter.
    So is there a way to get these emoji characters info in unity?
     
  2. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,539
    So it's the mono framework you're going to want to research for specifics on. Not unity specifically. Becuase unity uses the mono framework.

    Now if you're dealing with text that has characters with a value larger than 0xFFFF, that means you're dealing with UTF-32 encoding. The 'string' and 'char' types in .net/mono are UTF-16 in size, which is why 0xFFFF is the largest value supported.

    You can deal with the text data by keeping it in a byte array or something like that and directly manipulate it there.

    http://msdn.microsoft.com/en-us/library/system.text.encoding.utf32(v=vs.110).aspx

    You could even write a special string type around this if you wanted. Or you might be able to even find an implementation out there.
     
  3. geniusz

    geniusz

    Joined:
    Nov 21, 2014
    Posts:
    38
    I think my title confuses the problem.
    The problem is the first parameter of the method "Font.GetCharacterInfo" require the type "char".
    So I can't get the glyph from the font, if the unicode is larger than 0xFFFF.
     
  4. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,539
    Aw, well in that case, you're probably S*** out of luck.
     
  5. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Just added support in TextMesh Pro for UTF-32. The built-in Font Asset Creator now supports generating font assets with UTF-32. You can then access those characters by using the "\U" with 4 hex pairs. See the example below.

    upload_2015-9-1_0-45-43.png

    Note: This example also show the use of the <font> tag which will be available in the next release of TextMesh Pro. Since the font asset that I generated only includes icons (like that fish), I used the <font> tag to access another font so I could type text.