3.6 Font
Right PDF SDK provides APIs that enable users to determine the font style, width, bounding box, and the way to order font value, and also to count and embed fonts into a PDF document. Note that ZSFont_Create needs to be called in advance to allow APIs to work, and use ZSFont_Release to end the entire action. Here are some common APIs for font setting listed in Table 3.7. For a complete list of APIs, please refer to ZSFont.h.
Table 3.7
|
API Name |
Description |
1 |
ZSFont_Create |
Create a font with the given attributes. |
2 |
ZSFont_Release |
Release a font object. |
3 |
ZSFont_IsBold |
Detect whether a font object is bold or not. |
4 |
ZSFont_GetAscent |
Get an ascent value of a font. |
5 |
ZSFont_GetDescent |
Get a descent value of a font. |
6 |
ZSFont_GetCharBBox |
Get a specific character bounding box of a font. |
7 |
ZSFont_GetCharWidth |
Get a specific character width of a font. |
8 |
ZSFont_IsEmbedded |
Check whether a font is embedded in a PDF document. |
9 |
ZSFont_GetDict |
Get the dictionary of a font in a PDF document. |
10 |
ZSFont_NumFonts |
Count all the PDF fonts in the document, which enumerates all the font resources for pages, annots, and AcroForm. |
11 |
ZSFont_EmbedFont |
Embed a font into a PDF document. |
This is an example of getting an ascent/ descent value of a font and the width of a certain character.
Example: Get an ascent/descent value of a font and the width of the character “A”
ZSFont font;
ZSFont_Create(&fontname, ZS_FONTSTYLE_FIXEDPITCH, 0, ZS_CHARSET_CHINESEBIGS, &font);
ZSFont_GetAscent(font, &ascent);
ZSFont_GetDescent(font, &descent);
ZSFont_GetCharWidth(font, ‘A’, &width);
ZSDoc_EmbedFont(doc, font);
ZSFont_Release(font);
|