package vg
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=ccd0d0f61cdbdb3420b5f4d747fe6e6b95e487738f70163a6e26396b1eeb9a42118306bc9c2c9afc9256171d57f81fbdf08ec558625eb5d723230aa0e9564fb6
doc/vg.pdf/Vgr_pdf/index.html
Module Vgr_pdfSource
PDF renderer.
Renders a sequence of renderables as a multi-page PDF 1.7 document. Each renderable defines a page of the document.
Bug reports. PDF being an insane standard, rendering abilities of PDF readers vary wildly. No rendering bug report for this renderer will be considered if it cannot be reproduced in the latest Adobe Acrobat Reader.
Font resolution
Font resolution happens during the rendering of Vg.I.cut_glyphs images through the font callback given to the PDF rendering target. See Text rendering for more details.
The type for OpenType fonts.
otf_font bytes is an OpenType font from the OpenType byte serialization bytes.
The type for font resolution results. Any case different from `Otf ends up using the PDF standard fonts. See Text rendering for details.
font is the default font resolver. Given a Vg.font f it performs the following resolutions according to value of f.Font.name:
"Helvetica", returns`Sans"Times", returns`Serif"Courier", returns`Fixed- Any other, returns
`Sans
See Text rendering for understanding what this entails.
PDF render targets
val target :
?font:(Vg.font -> font) ->
?xmp:string ->
unit ->
Vg.Vgr.dst_stored Vg.Vgr.targettarget font xmp () is a PDF render target for rendering to the stored destination given to Vg.Vgr.create.
fontis the font resolver, defaults tofont, see Text rendering for details. Note thatfontresults are cached by the renderer.xmpis an optional UTF-8 encoded XML XMP metadata packet describing the PDF document (see ISO 16684-1 or the equivalent Adobe spec.). The convenience functionVg.Vgr.xmpcan be used to generate a packet.
Multiple image. Multiple image render is supported. Each image defines a page of the resulting PDF file.
Text rendering
Text rendering depends on the way fonts are resolved by the function specified in the rendering target. Given a glyph cut:
Vg.I.cut_glyphs ~text ~blocks ~advances font glyphs
First, if the optional text and blocks arguments are specified, they are always used to map the rendered glyphs to text for PDF text extraction. Then the following happens according to the resolution of the font argument by the render target:
`Otf otf, the values inglyphsare glyph indexes of the OpenType fontotf. Ifadvancesis specified these vectors are used to position the glyphs (e.g. you need to use this to perform kerning), otherwise the font's glyph advances, as found inotf, are used.`Helvetica, uses one of the standard PDF font Helvetica, Helvetica-Bold, Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique according tofont'sVg.Font.slantandVg.Font.weight. The values inglyphsare glyph indexes representing the corresponding Unicode character (e.g. glyph index0x20is the glyph for characterU+0020). The font supports glyph indexes for all the characters listed in the in the second column of this document which is all the Basic Latin block, the Latin-1 Supplement block without its control characters and some additional characters (those at rows 0x80-0x9F in that document). If a glyph index is not supported it is replaced by0. Ifadvancesis specified these vectors are used to position the glyphs, otherwise the internal font's glyphs advances are used.`Times, same as`Helveticabut uses one of the standard PDF font Times-Roman, Times-Bold, Times-Italic or Times-BoldItalic.`Courier, same as`Helveticabut uses one of the standard PDF font Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique.`Sansis the same as`Helveticaexceptadvancesandglyphsare ignored. Instead the UTF-8 stringtextis used to generate a correspondingglyphslist, mapping supported characters as mentioned above to their corresponding glyph. Unsupported characters are mapped to glyph 0.`Serifsame as`Sansbut uses the same fonts as`Times.`Fixedsame as`Sansbut uses the same fonts as`Courier.
So what should be used ? In general clients should use a font resolution mechanism independent from Vg in order to get an OpenType font otf for font. Using this otf font is should compute, using again a mechanism independent from Vg, a glyph layout resulting in advances and glyphs to use with Vg.I.cut_glyphs and finally resolve font in the target with `Otf otf. This means that font resolution should:
- Use
`Otf otfwhenever it is guaranteed that the glyph indexes inglyphsactually correspond to the glyph indexes ofotf. - Use
`Sans,`Serifor`Fixedwhenever its is unable to resolvefontto an appropriateotf, this may not result in the expected rendering but still at least show (the latin) part of the text. - Use
`Helvetica,`Timesor`Courierto perform glyph layout using PDF's standard fonts without having to embed the fonts in the PDF (the font metrics can be downloaded here). PDFs without embedded fonts are however not recommended.
Render warnings and limitations
The following render warnings are reported.
`Unsupported_cut (`O o, i), outline area cuts can be performed only on (possibly transformed)Vg.I.const,Vg.I.axial,Vg.I.radialimages.`Unsupported_glyph_cut (`O o, i), outline area glyph cuts can be performed only on (possibly transformed)Vg.I.const,Vg.I.axial,Vg.I.radialimages.
The following limitations should be taken into account:
Streams in the PDF files are currently uncompressed and fonts are embedded without subsetting which may result in large file sizes. This will be lifted in future versions of the library. Meanwhile if you need to reduce the size of generated PDFs you can pass them through cpdf or ghostscript.
> cpdf -compress -o output.pdf input.pdf > gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf input.pdf