0

I'm trying to use an Icon Font inside a Xamarin application. It is actually quite straight forward and i got the font to work. However it works fine with using Unicode to reference the symols, like this:

Label iconLabel = new Label
{
   Text = "\u0078"
};

But i discovered that only a few symbols of this font have a unicode assigned, the other symbols only have a name. That icon font is usually supposed to be used in html where these symbols can be referenced by the name.

If i try to do this in C#: Text = "arrow_down" it won't work, as it only displays the plain text.

Is there a way this could work with the names of the symbols or maybe a way to automatically add unicodes to every symbol in this font?

Elias Johannes
  • 694
  • 2
  • 7
  • 26
  • *"only a few symbols of this font have a unicode assigned, the other symbols only have a name"* - what do you mean? What are those few symbols lucky enough to get unicode and those who only got a name? What is name? Are you talking about [HTML](https://www.w3schools.com/charsets/ref_utf_misc_symbols.asp) (maybe [this one](https://stackoverflow.com/q/2701192/1997232) is better)? – Sinatr Jul 15 '20 at 12:39
  • To output `↓` you have to use [\u2193](https://dotnetfiddle.net/FzNBZq) (refer to [this handy table](https://en.wikipedia.org/wiki/Arrow_%28symbol%29#Arrows_in_Unicode)) – Sinatr Jul 15 '20 at 12:46
  • @Sinatr The `arrow_down` was just an example. To demonstrate best what i mean, [here](https://github.com/framework7io/framework7-icons/tree/master/fonts) is the font i'm talking about. I'm using [this](https://fontdrop.info/) tool to inspect the font and most of the symbols/icons say "unicode: none", so i don't know how i could reference these specific symbols. – Elias Johannes Jul 15 '20 at 12:55
  • Never made a font myself, no idea what is `unicode:none`. To display a character from custom font you have to load this font and then render string. It's still not clear what you want. You can't pass character name into font. C# supports certain escape sequences (`\u` is one of them to specify unicode), but there is nothing like `\arrow_down`, this is why I asked you about html. Your example `Text = "arrow_down"` will never be a single character. Who will be specifying that `"arrow_down"`? A user of application? You can use placeholders and replace those with actual unicode characters. – Sinatr Jul 15 '20 at 13:06
  • Basically all i want to do is access every symbol of this font, but only a few symbols have a unicode reference or at least i can't find a way to get the other unicode symbols. – Elias Johannes Jul 15 '20 at 13:15
  • *"access every symbol of this font"* - see [this question](https://stackoverflow.com/q/1439551/1997232). I still don't understand what is "unicode reference", just use unicode to have character (symbol you want) drawn. – Sinatr Jul 15 '20 at 13:34
  • The "don't have unicode" is not clear. Note: various symbols do not have proper Unicode code point, but they requires combining characters, and some symbols are usually show in fonts as ligature (although Unicode may include also ligature code points, such ligature should not be used). Every Unicode Code point has own character name (but not the combined symbols), and ligatures depends on font, script and language. Things are complex, for this reason you should use the correct terminology, or we may interpret your question in a very different way. Examples, images, and part of code helps. – Giacomo Catenazzi Jul 15 '20 at 13:59
  • @GiacomoCatenazzi I'm sorry my terminology about fonts and unicodes are pretty limited to be honest. If you refere to [this](https://fontdrop.info/) tool and scroll down a little bit and hover over symbols you'll see the unicode of the symbol. If you scroll all the way down on the example font you'll find symbols that say "unicode: none". Now let's assume i want to reference one of these symbols from this font in my c# code, how would i do that? I hope this example makes sense. – Elias Johannes Jul 15 '20 at 14:13
  • To me, they just seems characters than in Unicode you will use 2 code points. "Bad fonts" will just construct an accent over the previous one. "Good fonts" try to combine accents in a pleasing manner. Note: if you look the "glyph" field, you see the two unicodes characters used to "build" such glyph. Note: Unicode is explicitly not about glyphs. -- ah, I noticed that there are few cases without uniXXXX_uni_YYYY. In such case you have no luck. Some accent's glyphs depend on language: (same semantic, but one will design it differently, on same font). – Giacomo Catenazzi Jul 15 '20 at 14:20
  • and BTW you choose a website for/of font designers. This is Unicode complexity squared. – Giacomo Catenazzi Jul 15 '20 at 14:25
  • @GiacomoCatenazzi With no luck - do you mean i "randomly" need to find out what the unicode could be then? My font example (the one above) has about 95% of those. Is there no way to find these out? – Elias Johannes Jul 15 '20 at 14:31
  • This go far from my knowledge. Font files should have some tables: unicode sequence (not just a code point, possibly with some status and language) -> glyphs. [You just need the inverse way, right?] But I do not know the font formats (and there are different formats). – Giacomo Catenazzi Jul 15 '20 at 14:38
  • The format would be true type (.ttf). Maybe there is some tool that can generate these tables. Unfortunately the Font Book on macOS won't be able to copy the symbols without the unicode aswell... – Elias Johannes Jul 15 '20 at 14:51

1 Answers1

0

I ended up using the fantastic tool fontello and uploaded the open source icon font, selected all the symbols from it and downloaded it again - which generated new unicodes for every single symbol and i got it to work like a charm now. (Additionally fontello generates a great spreadsheet showing every code for every symbol).

In the end i guess this is the smartest way to work around this - if you need to access symbols from a font via unicode but the font isn't laid-out for this, use a tool like fontello to generate your own.

Elias Johannes
  • 694
  • 2
  • 7
  • 26