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.

Specifying the initial font subset. Font subsets contain outline descriptions for all<br />

glyphs used in the document. This means that the generated font subsets will vary<br />

among documents since a different set of characters (and therefore glyphs) is generally<br />

used in each document. Different font subsets can be problematic when merging many<br />

small documents with embedded font subsets to a larger document: the embedded subsets<br />

cannot be removed since they are all different.<br />

For this scenario <strong>PDFlib</strong> allows you to specify the initial contents of a font subset<br />

with the initialsubset option of load_font( ). While <strong>PDFlib</strong> starts with an empty subset by<br />

default and adds glyphs as required by the generated text output, the initialsubset option<br />

can be used to specify a non-empty subset. For example, if you know that only Latin-1<br />

text output will be generated and the font contains many more glyphs, you can<br />

specify the first Unicode block as initial subset:<br />

initialsubset={U+0020-U+00FF}<br />

This means that the glyphs for all Unicode characters in the specified range will be included<br />

in the subset. If this range has been selected so that it covers all text in the generated<br />

documents, the generated font subsets will be identical in all documents. As a result,<br />

when combining such documents later to a single PDF the identical font subsets<br />

can be removed with the optimize option of begin_document( ).<br />

Type 3 font subsetting. Type 3 fonts must be defined and therefore embedded before<br />

they can be used in a document (because the glyph widths are required). On the other<br />

hand, subsetting is only possible after creating all pages (since the glyphs used in the<br />

document must be known to determine the proper subset). In order to avoid this conflict,<br />

<strong>PDFlib</strong> supports widths-only Type 3 fonts. If you need subsetting for a Type 3 font<br />

you must define the font in two passes:<br />

> The first pass with the widthsonly option of begin_font( ) must be done before using<br />

the font. It defines only the font and glyph metrics (widths); the font matrix in<br />

begin_font( ) as well as wx and the glyph bounding box in begin_glyph( )) must be supplied<br />

and must accurately describe the actual glyph metrics. Only begin_glyph( ) and<br />

end_glyph( ) are required for each glyph, but not any other calls for defining the actual<br />

glyph shape. If other functions are called between start and end of a glyph description,<br />

they will not have any effect on the PDF output, and will not raise any exception.<br />

> The second pass must be done after creating all text in this font, and defines the actual<br />

glyph outlines or bitmaps. Font and glyph metrics will be ignored since they are<br />

already known from the first pass. After the last page has been created, <strong>PDFlib</strong> also<br />

knows which glyphs have been used in the document, and will only embed the required<br />

glyph descriptions to construct the font subset.<br />

The same set of glyphs must be provided in pass 1 and pass 2. A Type 3 font with subsetting<br />

can only be loaded once with load_font( ).<br />

Cookbook A full code sample can be found in the Cookbook topic fonts/type3_subsetting.<br />

144 Chapter 5: Font Handling (Edition for <strong>COM</strong>, .<strong>NET</strong>, and REALbasic)

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

Saved successfully!

Ooh no, something went wrong!