15.07.2013 Views

luatexref-t.pdf.

luatexref-t.pdf.

luatexref-t.pdf.

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.

• if it is positive, it specifies an ‘at size' in scaled points.<br />

• if it is negative, its absolute value represents a ‘scaled' setting relative to the designsize of the font.<br />

The id is the internal number assigned to the font.<br />

The internal structure of the font table that is to be returned is explained in chapter 7. That table is<br />

saved internally, so you can put extra fields in the table for your later Lua code to use.<br />

Setting this callback to false is pointless as it will prevent font loading completely but will nevertheless<br />

generate errors.<br />

4.2 The e<strong>pdf</strong> library<br />

The e<strong>pdf</strong> library provides Lua bindings to many <strong>pdf</strong> access functions that are defined by the poppler<br />

<strong>pdf</strong> viewer library (written in C++ by Kristian Høgsberg, based on x<strong>pdf</strong> by Derek Noonburg). Within<br />

LuaTEX (and <strong>pdf</strong>TEX), x<strong>pdf</strong> functionality is being used since long time to embed <strong>pdf</strong> files. The e<strong>pdf</strong><br />

library shall allow to scrutinize an external <strong>pdf</strong> file. It gives access to its document structure, e. g.,<br />

catalog, cross-reference table, individual pages, objects, annotations, info, and metadata.<br />

The e<strong>pdf</strong> library is still in alpha state: <strong>pdf</strong> access is currently read-only (it's not yet possible to alter<br />

a <strong>pdf</strong> file or to assemble it from scratch), and many function bindings are still missing.<br />

For a start, a <strong>pdf</strong> file is opened by e<strong>pdf</strong>.open() with file name, e. g.:<br />

doc = e<strong>pdf</strong>.open("foo.<strong>pdf</strong>")<br />

This normally returns a PDFDoc userdata variable; but if the file could not be opened successfully,<br />

instead of a fatal error just the value nil is returned.<br />

All Lua functions in the e<strong>pdf</strong> library are named after the poppler functions listed in the poppler header<br />

files for the various classes, e. g., files PDFDoc.h, Dict.h, and Array.h. These files can be found<br />

in the poppler subdirectory within the LuaTEX sources. Which functions are already implemented in<br />

the e<strong>pdf</strong> library can be found in the LuaTEX source file le<strong>pdf</strong>lib.cc. For using the e<strong>pdf</strong> library,<br />

knowledge of the <strong>pdf</strong> file architecture is indispensable.<br />

There are many different userdata types defined by the e<strong>pdf</strong> library, currently these are Annot,<br />

AnnotBorder, AnnotBorderStyle, Annots, Array, Catalog, EmbFile, Dict, GString,<br />

LinkDest, Object, ObjectStream, Page, PDFDoc, PDFRectangle, Ref, Stream, XRef, and<br />

XRefEntry.<br />

All these userdata names and the Lua access functions closely resemble the classes naming from the<br />

poppler header files, including the choice of mixed upper and lower case letters. The Lua function calls<br />

use object-oriented syntax, e. g., the following calls return the Page object for page 1:<br />

pageref = doc:getCatalog():getPageRef(1)<br />

pageobj = doc:getXRef():fetch(pageref.num, pageref.gen)<br />

But writing such chained calls is risky, as an intermediate function may return nil on error; therefore<br />

between function calls there should be Lua type checks (e. g., against nil) done. If a non-object item<br />

44<br />

LuaTEX Lua Libraries

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

Saved successfully!

Ooh no, something went wrong!