SelectCharmap & SetCharmap Not Working?
When creating a new Face, SharpFont/FreeType defaults to the Unicode CharMap as expected. For fonts that don't have a Unicode CharMap (like symbol fonts such as the standard Wingdings), the CharMap is set to null as expected.
However, when I try setting the CharMap with either SelectCharmap or SetCharmap to another CharMap that's in the CharMaps array, it doesn't take. No exceptions are generated, but the Charmap remains null.
Perhaps I'm just missing something, Here's the code that's not's working for symbol fonts:
fontFace = new Face(lib, Path.Combine(FontDir.Text, FontName.Text));
if (fontFace.CharMap == null)
{
fontFace.SelectCharmap(SharpFont.Encoding.MicrosoftSymbol);
foreach (CharMap charMap in fontFace.CharMaps)
{
if(charMap.PlatformId == SharpFont.TrueType.PlatformId.Microsoft)
{
fontFace.SetCharmap(charMap);
break;
}
}
}
I expect SelectCharmap or SetCharmap to set the CharMap appropriately, but neither do.
Subsequent calls to GetCharIndex return 0, which is what I'd expect for a null CharMap.
Is there another step I need to do before attempting to set the CharMap or another way to accomplish this? Or this is just not working in SharpFont?
There's a chance this is SharpFont's fault. If you have a chance to test it in C/C++ with FreeType2 that would help narrow down the issue. I probably won't have time to try to reproduce this until at least next weekend.
It is probably a SharpFont issue. I tried with microsoft's symbol.ttf with the above c# snipplet, the charmap selection/set didn't stick.
selecting/set charmap with freetype's python binding does stick, on the same font.
Here is the whole interactive python session:
$ python
Python 2.7.11 (default, Mar 31 2016, 20:46:51)
[GCC 5.3.1 20151207 (Red Hat 5.3.1-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import freetype
>>> face = freetype.Face("w7fonts/symbol.ttf")
>>> face.charmap
<freetype.Charmap object at 0x7efbecbb98d0>
>>> face.charmap.platform_id
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/freetype/__init__.py", line 492, in <lambda>
platform_id = property( lambda self: self._FT_Charmap.contents.platform_id,
ValueError: NULL pointer access
>>> face.charmaps
[<freetype.Charmap object at 0x7efbe9292610>, <freetype.Charmap object at 0x7efbe9292690>]
>>> face.set_charmap(face.charmaps[1])
>>> face.charmap.platform_id
3
>>> face.set_charmap(face.charmaps[0])
>>> face.charmap.platform_id
1
>>> from freetype.raw import *
>>> FT_ENCODINGS['FT_ENCODING_MS_SYMBOL']
1937337698
>>> face.select_charmap(FT_ENCODINGS['FT_ENCODING_MS_SYMBOL'])
>>> face.charmap.platform_id
3
>>> face.set_charmap(face.charmaps[0])
>>> face.charmap.platform_id
1
>>> face.select_charmap(FT_ENCODINGS['FT_ENCODING_MS_SYMBOL'])
>>> face.charmap.platform_id
3
>>>
Thanks, very useful information! I'll use it to narrow down the issue when I get a chance to look at this bug in closer detail!
I think MS's powershell offers something similar, mono's csharp can be run interactively - so did 'csharp -lib:'where' -r:SharpFont' and have an interactive csharp-like session with essentially the same thing I did in the python session. (in reality I was adapting the later python session to do what I did in csharp shell earlier).