How to use Wingdings symbol font with libharu?

332 views
Skip to first unread message

sume

unread,
May 12, 2009, 8:57:14 AM5/12/09
to libHaru
This is a step-by-step description for making libharu pdf library to
capable
using Wingdings (or other) symbol font (try it, please check it -
correct it,
enjoy it!):

1. Download the libharu source code package. You have to edit the
source, and
recompile/rebuild the library!!!
2. Download the fonttools.exe from Microsoft website (if you are a
nonWin user,
please find a machine with MSWindows, sorry...):
http://www.microsoft.com/typography/tools/tools.aspx
3. Unpack the ttfdump.exe from fonttools.exe
4. Ttfdump is a console program without GUI, so start Command Prompt!
(Start->Run: cmd.exe, click OK)
5. Run the ttfdump:
C:\temp> ttfdump.exe c:\windows\fonts\wingding.ttf > wingding.txt
6. Open the file wingding.txt in a text editor.
7. First, find "cmap". (Skip the Offset Table entry, find next.)
8. Skip Subtable 1., find Subtable 2.
9. In Subtable 2. platform id: 3, specific id: 0, format: 4
10. Scroll down, find "Which means".
11. This is the character mapping table in the font file:
Char F020 -> Index 3
Char F021 -> Index 4
...
Char F0FF -> Index 225
12. The Wingding font has a special character encoding (you can see in
a font
selection dialog in Win): Symbol.
13. In the table F0xx (xx = [20..FF]) are the unicode character codes
for glyfs.
14. Find "post" from the begining. (Skip the Offset Table entry, find
next.)
15. In this table you can find a name for every glyf in the font:
Glyf 3 -> space
Glyf 4 -> pencil
...
Glyf 225 -> windowslogo
16. Let's join the tables (Index will be the key!):
Char F020 -> Index 3 -> Glyf 3 -> space
Char F021 -> Index 4 -> Glyf 4 -> pencil
...
Char F0FF -> Index 225 -> Glyf 225 -> windowslogo
17. Use this steps for getting info from other symbol font files in
the future.
18. Are you ready? We didn't do anything yet... Let's go!
19. Open the src\hpdf_encoder.c source file in a text editor.
20. Find the HPDF_UNICODE_GRYPH_NAME_MAP array. This is a large array,
containing
unicode - name pairs.
21. This array is ordered by the unicode field, so find 0x266b -
musicalnotebdl and
0xF6BE - dotlessj entries.
22. Insert lines into the source (be careful, keep the ordering
sequence!):
{0x266b, "musicalnotebdl"},
// begin wingding unicodes and names
{0xF020, "space"},
{0xF021, "pencil"},
... <- insert all (or any) character codes and names
{0xF0FF, "windowslogo"},
// end wingding unicodes and names
{0xF6BE, "dotlessj"},
23. Find the HPDF_BUILTIN_ENCODINGS array.
24. At the end of the array (but before HPDF_BASE_ENCODING_EOF),
create a new entry:
{
HPDF_ENCODING_SYMBOL,
HPDF_BASE_ENCODING_WIN_ANSI,
HPDF_UNICODE_MAP_SYMBOL
},
25. Find the HPDF_UNICODE_MAP_KOI8_R array.
26. After HPDF_UNICODE_MAP_KOI8_R insert a new array (you have to
write all 224 values!):
static const HPDF_UNICODE HPDF_UNICODE_MAP_SYMBOL[] = {
0xF020, 0xF021, ... , 0xF0FF
};
27. Save and close the hpdf_encoder.c file.
28. Open the include\hpdf_encoder.h file in a text editor.
29. In the predefined font encodings section create a new entry:
#define HPDF_ENCODING_SYMBOL "SYMBOL"
30. Save and close the hpdf_encoder.h file.
31. Open the src\hpdf_fontdef_tt.c file in a text editor.
32. Find "MS-Unicode-CMAP" text. First occurence is in a comment.
33. The next line is:
if (platformID == 3 && encodingID == 1 && format == 4) {
34. Wingdings has 3-0-4 codes (see 9.), so we need modify this
condition.
35. Change the line to:
if (platformID == 3 && (encodingID == 0 || encodingID == 1) &&
format == 4) {
32. Save and close the hpdf_fontdef_tt.c file.
33. Rebuild the library. (e.g.: make -f srcipt\Makefile.msvc)
34. Done.

******************************************************************************
Using the library from C language:

HPDF_Doc doc;
HPDF_Page page;
HPDF_Font font;
const char *fontname;

... init, create the doc, pages, etc.
fontname = HPDF_LoadTTFontFromFile(doc, "c:\\windows\\fonts\
\wingding.ttf", HPDF_TRUE);
if (fontname != NULL)
font = HPDF_GetFont(doc, fontname, "SYMBOL");
HPDF_Page_SetFontAndSize(page, font, 12); // 12 point height
HPDF_Page_TextOut(page, x, y, "["); // this is a yinyang
}

******************************************************************************
Main problem: Dump to txt other symbol fonts, e.g. webdings. You can
see the same unicode
range (0xf020-0xf0ff) for different names! The
HPDF_UNICODE_GRYPH_NAME_MAP array depends
on the font name! Currently this is not supported by libharu, so you
can use only ONE
embbed symbol font!

bye
SA
Reply all
Reply to author
Forward
0 new messages