[cairo] Cairo PDFs - vector or raster?

Behdad Esfahbod behdad.esfahbod at gmail.com
Fri May 8 13:13:11 PDT 2015


On 15-04-26 10:34 PM, C. Thomas Stover wrote:
> On Sat, 25 Apr 2015 15:28:37 +0930, Adrian Johnson wrote:
> 
>> Cairo PDF and PS output uses embedded fonts for drawing text. The
>> embedded fonts are subsetted to remove unused glyphs while being careful
>> to preserve font hinting. The encoding used depends on the output format
>> and the characters used.
>>
>> For PDF, glyphs that map to characters in the PDF WinAnsiEncoding are
>> placed in an 8-bit font with that encoding. Other glyphs are placed in a
>> 16-bit font with a custom encoding (the glyphs ids are assigned
>> sequentially starting from 1). A ToUnicode map and optionally ActualText
>> is embedded to allow extracting the unicode characters for the glyphs.
>> Cairo user fonts are embedded using Type 3 fonts.
>>
>> Most of the font subsetting code is shared by PS and PDF. The PS
>> embedded fonts are the same as PDF with a couple of exceptions:
>>
>> - PS does not have a builting WinAnsiEncoding. Instead we create a
>> custom 8-bit font with the same encoding.
>>
>> - While it is possible to create PS composite fonts with a 16-bit
>> encoding, we use only 8-bits fonts. Multiple 8-bit fonts are used to
>> contain all glyphs that don't map the WinAnsi encoding.
> 
> Thanks so much for your answer! That explains so much. Maybe you can 
> comment on these.
> 
> 1. Is the font rendering logic deterministic / predictable enough, such 
> that given a font, one could compute the sizes of rendered text with 
> enough confidence that the same result would be yielded from PS / PDF 
> viewers, printer drivers, and printer firmware? I would imagine the 
> answer is probably something like "usually". Is it just font metrics + 
> kerning tables + ligatures substitutions, or are there more variables?

The kerning, ligatures, etc happen before PDF generation.  PDF records the
exactly glyph indices and locations to show them.


> 2. Are the font metrics needed for the above rendering computations read 
> from font files, hard coded tables, font "metrics" files, or combinations?
> 
> 3. Some sources talk about a set of core fonts that some versions of PS 
> and PDF support are guaranteed to have, yet those particular fonts have 
> limited character code point coverages. Are these fonts ever used in 
> cairo?

Definitely limited charset.  Don't remember if cairo uses them.  Guess not.


> 4. How much of this is done by cairo vs pango? Does pango do the size 
> computations and cairo do the composite font file creations?


Yes.  Pango does layout, cairo does font subsetting and embedding (including
composite fonts).



More information about the cairo mailing list