1
\$\begingroup\$

I'm trying to draw currency symbols in an Arial Spritefont. According to this site, the font contains these symbols. I've included the Unicode character region for these symbols in the Content Processor SpriteFont file, like so:

<CharacterRegions>
  <CharacterRegion>
    <Start>&#32;</Start>
    <End>&#126;</End>
  </CharacterRegion>
  <CharacterRegion>
    <!-- Currency symbols -->
    <Start>&#8352;</Start>
    <End>&#8378;</End>
  </CharacterRegion>
</CharacterRegions>

However, whenever I try to draw a € (Euro) symbol, I get this exception:

Text contains characters that cannot be resolved by this SpriteFont

Inspecting the SpriteFont in the IDE at that breakpoint shows the € symbol is in there. I'm at a loss at what could be wrong. Why is this exception thrown?

\$\endgroup\$
4
  • \$\begingroup\$ Related (potential duplicate?) gamedev.stackexchange.com/questions/56058/… \$\endgroup\$
    – user1430
    Commented Apr 28, 2014 at 17:42
  • \$\begingroup\$ If you look at the asker's answer, the problem is unrelated. They simply forgot to switch to the correct font, I've already checked for this. \$\endgroup\$
    – Appeltaart
    Commented Apr 28, 2014 at 17:56
  • \$\begingroup\$ Yeah; just checking, it's the only other 'character not supported' question I recall seeing here in a while. \$\endgroup\$
    – user1430
    Commented Apr 28, 2014 at 18:07
  • \$\begingroup\$ Have you tried some unicode values from other encoding schemes? The euro symbol is one that varies between between Microsoft and Other. en.wikipedia.org/wiki/Western_Latin_character_sets_(computing) \$\endgroup\$ Commented Apr 28, 2014 at 18:10

2 Answers 2

1
\$\begingroup\$

The best way to handle this is to take advantage of the characters collection SpriteFont.Characters and see if it contains the character. Any character that returns false will result in an error when rendered using the sprite font.

For example the below is what I use to filter out non usable characters from my textboxes.

if (!Font.Characters.Contains(character) && character != '\r' && character != '\n') { return; }
\$\endgroup\$
1
\$\begingroup\$

The problem wasn't in the € sign, but another char embedded in the string.

This char was added by the NSNumberformatter (I'm using Xamarin), which is A0 or 160. As my font only went from 32 through 126, and 8352 through 8378, this obviously wouldn't work.

As such, the following code solved the problem, and the string is properly drawn now.

using System.Text;

if (priceString.Contains((char)160)) { priceString = priceString.Replace(((char)160).ToString(), ""); }

The reason I thought the problem was in the € was because it would work for the $ sign - in truth, the formatter didn't add the non-breaking space in that currency format.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .