29.05.2014 Views

The history of luaTEX 2006–2009 / v 0.50 - Pragma ADE

The history of luaTEX 2006–2009 / v 0.50 - Pragma ADE

The history of luaTEX 2006–2009 / v 0.50 - Pragma ADE

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

While implementing the Lua side <strong>of</strong> the loader we took a similar approach as the afm<br />

reader and cached intermediate tables as well as keep track <strong>of</strong> font names (in addition<br />

to lenames). In order to be able to quickly determine the (internal) font name <strong>of</strong> an<br />

OpenType font, special loader functions are provided.<br />

<strong>The</strong> size is kind <strong>of</strong> special, because we can have specications like<br />

at 10pt<br />

at 3ex<br />

at \dimexpr\bodyfontsize+1pt\relax<br />

This means that we need to handle that on the TEX side and pass the calculated value to<br />

the callback.<br />

Virtual fonts have a rather special nature. <strong>The</strong>y permit you to dene variations <strong>of</strong> fonts<br />

using other fonts and special (dvi related) operators. However, from the perspective <strong>of</strong><br />

TEX itself they don't exist at all. When you create a virtual font you also end up with a<br />

tfm le and TEX only needs this le, which dened characters in terms <strong>of</strong> a width, height,<br />

depth and italic correction as well as associates characters with kerning pairs and ligatures.<br />

TEX leaves it to the backend to deal the actual glyphs and therefore the backend<br />

will be confronted by the internals <strong>of</strong> a virtual font. Because pdfTEX and therefore LuaTEX<br />

has the backend built in, it is capable <strong>of</strong> handling virtual fonts information.<br />

In LuaTEX you can build your own virtual font and this will suit us well. It permits us for<br />

instance to complete fonts that lack certain characters (glyphs) and thereby let us get rid<br />

<strong>of</strong> ugly macro based fallback trickery. Although in ConTEXt we will provide a high level<br />

interface, we will give you a taste <strong>of</strong> Lua here.<br />

callback.register("define_font", function(name,size)<br />

if name == "demo" then<br />

local f = font.read_tfm('texnansi-lmr10',size)<br />

if f then<br />

local capscale, digscale = 0.85, 0.75<br />

f.name, f.type = name, 'virtual'<br />

f.fonts = {<br />

{ name="texnansi-lmr10" , size=size },<br />

{ name="texnansi-lmss10", size=size*capscale },<br />

{ name="texnansi-lmtt10", size=size*digscale }<br />

}<br />

for k,v in pairs(f.characters) do<br />

local chr = utf.char(k)<br />

if chr:find("[A-Z]") then<br />

v.width = capscale*v.width<br />

v.commands = {<br />

A fresh look at fonts 37

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

Saved successfully!

Ooh no, something went wrong!