Bad Characters in Custom Font

When I create a custom font and specify a filter in the resources file to limit the memory size, I can't include these four characters: & " < >

In the following code, the & causes a compile error. Is there a way to "escape" the charcter to get it accepted? \& does not work. Same with " < and >

<resources>
<font id="dcb35" filename="fonts/dcb35.fnt" antialias="true" filter="0123456789&" />
</resources>

  • As a work around, what you can do is don't use a filter, but when you export the font in bmfont, only export the characters you need.

  • The resources file you describe is XML, so it is subject to the restrictions and requirements of an XML file. The characters ", &, ', <,  and > are special in XML, and they require special handling.

    You can either specify these characters using their entity reference, or as a Unicode code point. Here are the entity reference and Unicode code point numbers for those special characters:

    | Character | Code Point (dec) | Entity Reference |
    +-----------+------------------+------------------+
    | "         | U+0022 (34)      | quot             |
    | &         | U+0026 (38)      | amp              |
    | '         | U+0027 (39)      | apos             |
    | <         | U+003C (60)      | lt               |
    | >         | U+003E (62)      | gt               |

    To write a one of these reserved entities in XML, use one of these formats:

    &{entity_ref};
    &#{decimal_code_point};
    &#x{hexadecimal_code_point};

    Due to the way that this forum software works, I'm having trouble showing what you'd need to write, so the below examples have additional whitespace inserted following the ampersand (&) character. You will need to remove these whitespaces. Any of these should work for what you are trying to do.

    // using entity reference
    filter="0123456789& apos;"
    
    // using unicode code point (decimal)
    filter="0123456789& #38"
    
    // using unicode code point (hexadecimal)
    filter="0123456789&# x26"
    
    

  • Thank you! That worked, of course. Interestingly, AMP passes thru fine and doesn't require special handling. Wonder if that indicates a bug in the XML parser?

  • > Interestingly, AMP passes thru fine and doesn't require special handling.

    I'm not sure what you are saying. Could you provide more detail?

  • sorry it wasn’t clear. I meant in my filter I don’t need to do any special handling for one of the “special” characters: APOS. I mistakenly said AMP but meant APOS. Just found that interesting because your original reply suggested XML expects APOS to require special handling. No biggie.

  • Ahh. There may be some cases where it is okay to use the character itself. I don't have a great deal of experience with these parts of XML.