-
Notifications
You must be signed in to change notification settings - Fork 2
Fonts
There are several types of fonts available in libHaru.
Type of Font | Description |
---|---|
Base14 Font | The built-in font of PDF. Can be used for all viewer applications. |
Type1 Font | A font format used by PostScript. |
TrueType Font | Widely used outline font format. |
CID Font | Font format for multi-byte characters. Developed by Adobe. |
The application needs to invoke HPDF_GetFont() to get font handle.
Except for base14-fonts, one of the following functions must be used to load the font before invoking HPDF_GetFont():
- HPDF_LoadType1FontFromFile()
- HPDF_LoadTTFontFromFile()
- HPDF_LoadTTFontFromFile2()
- HPDF_UseCNSFonts()
- HPDF_UseCNTFonts()
- HPDF_UseJPFonts()
- HPDF_UseKRFonts()
Base14 fonts are built into PDF and all viewer applications can display these fonts. An application can get a base14 font handle any time by invoking HPDF_GetFont(). PDF files which use base14 fonts are smaller than those which use other type of fonts. Moreover, PDF processing is faster because there is no need to load external fonts. However, base14 fonts are only able to display the latin1 character set. To use other character sets, an application must use other fonts.
Built-in base14 fonts
- Courier
- Courier-Bold
- Courier-Oblique
- Courier-BoldOblique
- Helvetica
- Helvetica-Bold
- Helvetica-Oblique
- Helvetica-BoldOblique
- Times-Roman
- Times-Bold
- Times-Italic
- Times-BoldItalic
- Symbol
- ZapfDingbats
Type1 is a format of outline fonts developed by Adobe. An AFM file is necessary to use an external Type1 font on Haru. When an application uses an external Type1 font, an application has to invoke HPDF_LoadType1FontFromFile() before invoking HPDF_GetFont(). The return value of HPDF_LoadType1FontFromFile() is used as font-name parameter of HPDF_GetFont(). If a PFA/PFB file is specified at invoking HPDF_LoadType1FontFromFile(), the glyf data of the font is embedded to the PDF file. Otherwise, only metrics data in AFM file is embedded.
font_name = HPDF_LoadType1FontFromFile (pdf, "a010013l.afm", "a010013l.pfb"); hfont = HPDF_GetFont (pdf, font_name, "CP1250"); HPDF_Page_SetFontAndSize (page, hfont, 10.5);
libHaru can use TrueType fonts. There are two types of TrueType fonts. The first format, with ".ttf" extension, contains only one font-data in the file. HPDF_LoadTTFontFromFile() loads this type of font. The second format, with ".ttc" extension, contains multiple font-data in the file. HPDF_LoadTTFontFromFile2() loads this type of font. HPDF_LoadTTFontFromFile2() has a parameter which is used to specify the index of the font to load. If the parameter "embedding" is set to HPDF_TRUE when invoking HPDF_LoadTTFontFromFile() or HPDF_LoadTTFontFromFile2(), the subset of a font is embedded into a PDF file. If not, only the marix data is stored into a PDF file. In this case a viewer application may use an alternative font if it cannot find font.
font_name = HPDF_LoadTTFontFromFile (pdf, "/usr/local/fonts/arial.ttf", HPDF_TRUE); hfont = HPDF_GetFont (pdf, font_name, "CP1250"); HPDF_Page_SetFontAndSize (page, hfont, 10.5);
NOTE - Haru can use only TrueType fonts which have Unicode cmap and the following tables. "OS/2", "cmap", "cvt ", "fpgm", "glyf", "head", "hhea", "hmtx", "loca", "maxp", "name", "post", "prep".
CIDFont is a font for multi byte character developed by Adobe. Two simplified Chinese fonts, one traditional Chinese fonts, four Japanese fonts, and four Korean fonts are available on Haru. An application have to invoke the following functions once before using CID fonts.
Function Name | Description |
---|---|
HPDF_UseCNSFonts() | It makes simplified Chinese fonts(SimSun, SimHei) to become available. |
HPDF_UseCNTFonts() | It makes traditional Chinese fonts(MingLiU) to become available. |
HPDF_UseJPFonts() | It makes Japanese fonts(MS-Mincyo, MS-Gothic, MS-PMincyo, MS-PGothic) to become available. |
HPDF_UseKRFonts() | It makes Korean fonts (Batang, Dotum, BatangChe, DotumChe) to become available. |
HPDF_UseJPFonts (pdf); HPDF_UseJPEncodings (pdf); hfont = HPDF_GetFont (pdf, "MS-Mincyo", "90ms-RKSJ-H"); HPDF_Page_SetFontAndSize (page, hfont, 10.5);