Mobile Development – A Simple Unicode Character Map
A charmap tool like we have on Windows Desktop PCs
- The source code is available at code.googl.com/p/win-mobile-code
- Executable as with release 58 is available here: CharmapCF r58 executable - (Hits: 0, size: 9.13 KB)
Recently, I needed to know which chars (glyphs) are supported by a Windows Mobile font. I looked around for a charmap tool like we have on Windows Desktop PCs, and was unable to find one. So I started this little tool: CharmapCF
.
As you can see, you get a simple charmap
and can verify which glyphs are supported and which are not (square rectangle).
CharmapCF
supports only UCS-2, UTF-16 as used by Microsoft’s Encoding.Unicode
class. So it also only supports the Unicode Basic Multilanguage Plane (BMP).
When you click on a glyph, you will get the Unicode codepoint displayed in the title and the char
is placed in the small text box in the upper right. Using the [c] button, you copy the Unicode char to the clipboard and paste it in another app.
In the above screenshot, you can see that I have copied ARIALUNI.TTF from my desktop PC into the \Windows\Fonts dir of the device and can use the font in CharmapCF
.
What can also be seen here is that the table is zoomed in. You can use the Options menu to zoom the table in or out.
Here you can see that Tahoma does only support some of the glyphs.
Above is simply a Wingdings glyphs char.
There is nothing special in the code. Maybe you will find the font enumeration code useful:
/// <summary>
///
/// </summary>
/// <param name="lpelfe">IntPtr LOGFONT structure that contains
/// information about the logical attributes of the font</param>
/// <param name="lpntme">structure that contains information about
/// the physical attributes of the font, if the font is a TrueType font. If the font
/// is not a TrueType font, this parameter points to a TEXTMETRIC structure</param>
/// <param name="FontType">[in] DWORD that specifies the type of the font:
/// DEVICE_FONTTYPE
/// RASTER_FONTTYPE
/// TRUETYPE_FONTTYPE</param>
/// <param name="lParam">Pointer to the application-defined
// data passed by the EnumFontFamilies function</param>
/// <returns>Nonzero continues enumeration. Zero stops enumeration</returns>
private int EnumFontFamiliesExProc(IntPtr lpelfe, IntPtr lpntme,
EnumFontsType FontType, int lParam)
{
LOGFONT logFont = (LOGFONT)Marshal.PtrToStructure(lpelfe, typeof(LOGFONT));
if (logFont.lfWeight == lfWeightType.FW_REGULAR && logFont.lfItalic==0)
{
//we dont like duplicate names
if(!fontNames.Contains(logFont.lfFaceName))
fontNames.Add(logFont.lfFaceName);
System.Diagnostics.Debug.WriteLine(logFont.lfFaceName);
}
// Non-zero return continues enumerating
return 1;
}
private void buildList(){
// Need an HDC to pass to EnumFontFamilies
IntPtr hwnd = GetDesktopWindow();
IntPtr hdc = GetDC(hwnd);
LOGFONT logFont = new LOGFONT();
enumFontDelegate = new EnumFontDelegate(EnumFontFamiliesExProc);
fpEnumProc = Marshal.GetFunctionPointerForDelegate(enumFontDelegate);
EnumFontFamilies(hdc, null, fpEnumProc, IntPtr.Zero);
// We got a list of the major families. Copy the list,
// then clear it so we can go back and grab all the individual fonts.
List<string> fontFamilies = new List<string>();
fontFamilies.AddRange(fontNames);
fontNames.Clear();
foreach(string fontFamily in fontFamilies)
{
EnumFontFamilies(hdc, fontFamily, fpEnumProc, IntPtr.Zero);
}
ReleaseDC(hdc);
foreach(string s in fontNames)
{
//listBox1.Items.Add(s);
}
}
One interesting behavior of the Windows font system is shown when you select the Font “Fantasie
” from the fonts listbox
. You will see Windows chooses another font for you (see label on right of the listbox
showing the active font).
The rest of the code implements some drawing routines. I have used a class based on Panel
, so I can easily move and resize the charmap
.