[cairo] [PATCH] Use Type2 CID fonts instead of Type42 fonts in PDF backend

Adrian Johnson ajohnson at redneon.com
Mon Jan 22 04:25:29 PST 2007

Eugeniy Meshcheryakov wrote:
> Hello,
> With attached patch cairo PDF backend outputs Type2 CID fonts for
> truetype, instead of Type42 fonts. This has advantage that most of
> truetype fonts will not be fragmented. This can make some documents
> significantly more compact: all structures that were dublicated in
> multiple Type42 fonts (cvt, fpgm, prep, some glyphs referenced from
> other glyphs, maybe other tables) will now be included only once.

This is a good feature to include. It also avoids frequent font subset
switching when using more than 256 glyphs from the one font.

The change to cairo-pdf-surface to emit TrueType CID fonts looks good.
However the changes to support creating 65536 glyph subsets will break
existing functionality. There are two problems here.

The first problem is the addition of code to cairo-ft-font.c to test
for a truetype font.

> +    scaled_font->base.cid = FT_IS_SFNT(face);

This code is FreeType specific and doesn't support other font backends
such as win32. It breaks when using OpenType fonts which are also sfnt

The second problem is that having decided that a font is TrueType, a
65536 glyph subset is created. However _cairo_truetype_subset_init() can
fail even when the font is TrueType. The next two font subsetters that
will be tried - Type 1 fallback and Type 3 will be unable to handle
the 65356 glyph subsets.

I suggest the following solution.

Modify cairo-scaled-font-subsets.c to create a CID (max 65536 glyphs)
subset for each font. ie each CID subset contains the glyphs from all
scaled fonts of the same face merged together. Non CID (max 256 glyphs)
subsets for each scaled font will also be created (as is currently the
case). A mapping from each CID subset to all non CID subsets of the same
font face is created.

In addition to the support for TrueType CID fonts in the patch, add CID
support for Type1 and OpenType fonts. The PDF backend will, for each CID
subset, try each of the CID enabled subsetters until a font is
successfully generated.

Where a CID subset fails with all of the above subsetters, a Type 3
bitmap font will be emitted for each non CID subset with the same font
face as the failed CID subset. The Type 3 outline font code can be
removed. The 256 glyph scaled font subsets are required for Type3 as PDF
does not support CID Type 3 fonts and a separate bitmap font needs to be
embedded for each scale used.

There would also need to be a flag added to cairo_scaled_font_subsets.c
that is set by the Type 3 font code to indicate to
_cairo_scaled_font_subsets_map_glyph() when the non CID subsets are used.

This solution has the advantage of using CID fonts where possible and
eliminating the problem of re-embedding each font at every size used.

More information about the cairo mailing list