17.05.2014 Views

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5.4 Loading Fonts<br />

5.4.1 Selecting an Encoding for Text Fonts<br />

Fonts can be loaded explicitly with the load_font( ) function or implicitly by supplying<br />

the fontname and encoding options to certain functions such as add/create_textflow( ) or<br />

fill_textblock( ). Regardless of the method used for loading a font, a suitable encoding<br />

must be specified. The encoding determines<br />

> in which text formats <strong>PDFlib</strong> expects the supplied text;<br />

> which glyphs in a font can be used;<br />

> how text on the page and the glyph data in the font will be stored in the PDF output<br />

document.<br />

<strong>PDFlib</strong>’s text handling is based on the Unicode standard 1 , almost identical to ISO 10646.<br />

Since most modern development environments support the Unicode standard our goal<br />

is to make it as easy as possible to use Unicode strings for creating PDF output. However,<br />

developers who don’t work with Unicode are not required to switch their application<br />

to Unicode since legacy encodings can be used as well.<br />

The choice of encoding depends on the font, the available text data, and some programming<br />

aspects. In the remainder of this section we will provide an overview of the<br />

different classes of encodings as an aid for selecting a suitable encoding.<br />

Unicode encoding. With encoding=unicode you can pass Unicode strings to <strong>PDFlib</strong>. This<br />

encoding is supported for all font formats. Depending on the language binding in use,<br />

the Unicode string data type provided by the programming language (e.g. Java) can be<br />

used, or byte arrays containing Unicode in one of the UTF-8, UTF-16, or UTF-32 formats<br />

with little- or big-endian byte ordering (e.g. C).<br />

With encoding=unicode all glyphs in a font can be addressed; complex script shaping<br />

and OpenType layout features are supported. <strong>PDFlib</strong> checks whether the font contains a<br />

glyph for a requested Unicode value. If no glyph is available, a substitute glyph can be<br />

pulled from the same or another font (see Section 5.4.6, »Fallback Fonts«, page 139).<br />

Some font types in PDF (Type 1, Type 3, and OpenType fonts based on glyph names)<br />

support only single-byte text. However, <strong>PDFlib</strong> takes care of this situation to make sure<br />

that more than 255 different characters can be used even for these font types.<br />

The disadvantage of encoding=unicode is that text in traditional single- or multi-byte<br />

encodings (except ISO 8859-1) cannot be used.<br />

Single-byte encodings. 8-bit encodings (also called single-byte encodings) map each<br />

byte in a text string to a single character, and are thus limited to 255 different characters<br />

at a time (the value 0 is not available). This type of encoding is supported for all font formats.<br />

<strong>PDFlib</strong> checks whether the font contains glyphs which match the selected encoding.<br />

If a minimum number of usable glyphs is not reached, <strong>PDFlib</strong> will log a warning<br />

message. If no usable glyph at all for the selected encoding is available in the font, font<br />

loading will fail with the message font doesn’t support encoding. <strong>PDFlib</strong> checks whether<br />

the font contains a glyph for a requested input value. If no glyph is available, a substitute<br />

glyph can be pulled from the same or another font (see Section 5.4.6, »Fallback<br />

Fonts«, page 139).<br />

1. See www.unicode.org<br />

5.4 Loading Fonts 127

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!