Mobile development – A simple Unicode Character Map

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 what glyphs are supported and which 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 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 se I have copied ARIALUNI.TTF form my desktop PC into the \Windows\Fonts dir of the device and can use the font in CharmapCF.

What can also see here is that the table is zoomed in. You can use the Options menu to zoom the table in or out.

Here you 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 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 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.

Source code is at code.googl.com/p/win-mobile-code

Executable as with release 58 is here: [Download not found]

Leave a Reply