Changes

Jump to navigation Jump to search
Removing dotlessi fix, simplifying the font setup.
This page shows you how to use most of the typographical features of the Palatino Linotype font shipped with MS Windows XP under ConTeXt / LuaTeX a.k.a. MKIV, and particularly how to get the small cap "i" issue patched. All credits for the <tt>lua</tt> patch and the detailed explanations go to Taco Hoekwater.
Note that the Palatino version (5.00) provided by Windows Vista and Windows 7 differs from the Windows XP one (version 1.40).  The following code has been tested with ConTeXt 20102013.0612.23 20 / LuaTeX 0.6077.1 0 on Win XPWindows 7. It takes advantage of recent fixes which simplified the font setup significantly. ([[User:Schickele|Schickele]] 16:02, 30 June 2010 (UTC))
== Example file ==
The following example file should give you a ready-to-use solution to take advantage of the typographical possibilities of Palatino Linotype under ConTeXt / MKIV. Of course, the four Palatino font shapes, called <tt>pala.ttf</tt>, <tt>palai.ttf</tt>, <tt>palab.ttf</tt> and <tt>palabi.ttf</tt>, must be installed on your computer. On a normal XP machine, they are stored in the system font folder (<tt>C:\Windows\Fonts</tt>).
 
<texcode>
\startluacodefunction palapatch (data,filename) if data.version == "1.40" then logs.report("load otf", "patching smallcaps i") data.glyphsdefinefontfamily[0x92palatino].lookups["ss_latn_l_14_s"][1rm].specification.variant="a.scturkish" data.glyphs[0x492Palatino Linotype].name = "a.scturkish" endend fonts.otf.enhancers.patches["^pala"] features= palapatch\stopluacode \definefontfeature[palatinolt-{default][script=latn,kern=yes,liga=yes,trep=yes,tlig=yes,protrusion=quality}]% by default all \definefontfeature[palatinolt-smcp][script=latn,kern=yes,liga=yes,trep=yes,tlig=yes,protrusion=quality,smcp=yes,onum=yes]it \definefontfeature[palatinolt-sups][mode=node,script=latn,kern=yes,liga=yes,trep=yes,tlig=yes,protrusion=quality,sups=yes] bf \starttypescript[serif][palatinolt][name]bi \usetypescript[serif][fallback]oldstyle styles are ready to use as well as ligatures\definefontsynonym[Serif][file:pala.ttf][features=palatinolt-default]% but superscript requires extra settings\definefontsynonymdefinefontfeature[SerifBold][filef:palab.ttfsuperscript][featuressups=palatinolt-defaultyes]% an extra \definefontsynonym[SerifItalic][file:palai.ttf][features=palatinolt-default]sup macro is defined for our convenience\definefontsynonymdefine[SerifBoldItalic][file:palabi.ttf][features=palatinolt-default1]\definefontsynonym[SerifCaps][file:pala.ttf][features=palatinolt-smcp]sup{\definefontsynonymfeature[SerifSlanted+][filef:pala.ttf][features=palatinolt-sups]\stoptypescript \definetypeface[PalatinoLinotype][rm][serif][palatinolt][defaultsuperscript]#1}
\setupbodyfont[PalatinoLinotypepalatino]% global protrusion and expansion settings - it is not inherited in custom paragraph definitions\setupbodyfontenvironmentsetupalign[hz, hanging]% default][em=italic]'verystrict' tolerance settings produces unwrapped greek text\setuppagenumberingsetuptolerance[location=strict]\enableprotruding
\defineparagraphs[TwoColumns][n=2,align={hz, hanging}]\setupparagraphs[TwoColumns][1][width=52pt,style=\emitalic,align=left]
\starttext
\startTwoColumns
Italic\TwoColumns
{\emit\getbuffer[Plato]}
\stopTwoColumns
\startTwoColumns
Small caps\TwoColumns
{\scsmallcaps\getbuffer[Plato]}
\stopTwoColumns
\stopTwoColumns
Old style ffl figures \& superior characters: 567890 / {\sc bi\oldstyle 567890} --- 1{\sl sup 1} o{\sl sup o} re{\sl sup re}
\stoptext
[[Image:Palatino_linotype_under_mkiv.png]]
 
In this example, the <cmd>sl</cmd> command gives superior characters. Protrusion is enabled, but not expansion (hz). This first lines (<cmd>startluacode</cmd> ... <cmd>stopluacode</cmd>) are the patch written by Taco to get the small cap dottless "i" work properly under LuaTeX. Without patch, activating the small cap lookup (<tt>smcp=yes</tt>) leads to dotted small cap "i" characters. The following section explains how the patch works.
 
== LuaTeX glyph renaming patch from Taco Hoekwater ==
''This section explains how the patch used in the above example file works. Both patch and explanations have been written by Taco Hoekwater. His original answer, including an attached test file, can be found [[http://www.mail-archive.com/ntg-context@ntg.nl/msg47311.html here]].''
 
To fix the [wrong small cap dotted i] problem nicely, we have to rename one of
the two glyphs.
 
This could be done in an external editor, but as this is a system font,
that may not be wise or even possible. Luckily, context allows to do
this using a patching system that is active during initial font loading
time (when the cache is generated).
 
In the following, we will be patching the generated cache file before
it is saved (by putting some lua code at the beginning of your test
file). Remember that you have to delete the generated cache
files after each iteration. In my case, they were <tt>/opt/tex/texmf-
cache/luatex-cache/context/c24894930eb65eadf7b71f1e305ff518/fonts/otf/pala.tm*</tt>.
If you forget to do this step in between runs,
nothing will change in the output!
 
The existing font patches are in font-pat.lua, and from that file it is
possible to deduce that something like this is the correct program
structure, theoretically:
 
<texcode>
\startluacode
function palapatch (data,filename)
-- to be filled in
end
fonts.otf.enhancers.patches["^pala"] = palapatch
\stopluacode
</texcode>
 
The two arguments to the patch function are the data table from the
luafontloader and the font file name, respectively. The function
should patch the data table to our liking and does not have to return
anything.
 
In order to have a good look at the data, the first thing to do is to
dump the data to a file. Put this code at the top of your test file,
delete the data cache files, and run:
 
<texcode>
\startluacode
function palapatch (data,filename)
io.savedata(filename .. '.lua', table.serialize(data))
end
 
fonts.otf.enhancers.patches["^pala"] = palapatch
\stopluacode
 
\definefontfeature [...]
</texcode>
 
Afterwards, open <tt>pala.ttf.lua</tt> (or <tt>pala.TTF.lua</tt>. not sure how this works
out on an actual XP install) in an editor for browsing.
 
Looking at the lua code in <tt>pala.ttf.lua</tt>, you will see that there
is a pretty large sub-array called '<tt>glyphs</tt>', which happens to be
indexed by glyph id. There are two entries in that sub-array called
'<tt>i.sc</tt>' and we will want to change the second of those to '<tt>i.scturkish</tt>'
(the one at <tt>0x492</tt>, the number we discovered above).
 
Change the lua code to the code below, save your test file, delete the
data cache again, and rerun.
 
<texcode>
\startluacode
function palapatch (data,filename)
data.glyphs[0x492].name = "a.scturkish"
end
 
fonts.otf.enhancers.patches["^pala"] = palapatch
\stopluacode
</texcode>
 
That's one problem fixed. If you look at the test's pdf, it will now
have dotless i's in the smallcaps. But now we have broken the
turkish smallcaps code (it will now also use the first <tt>i.sc</tt>, which is
wrong) so it is nice to fix that as well. Some searching back and forth
through the <tt>pala.ttf.lua</tt> code reveals that there are two lookups that
use <tt>i.sc</tt>: <tt>ss_latn_l_13_s</tt> (for normal latin) and <tt>ss_latn_l_14_s</tt> (for
turkish). These lookups are part of the glyph definition of 'i' which
lives at <tt>0x92</tt> (I found that number in the earlier font dump, but you
could also count the entries in <tt>pala.ttf.lua</tt>, if you are bored or like
counting stuff).
 
Named lookups are small arrays (you can deduce that from the double
braces in <tt>pala.ttf.lua</tt>), so the needed patch is:
 
<texcode>
data.glyphs[0x92].lookups["ss_latn_l_14_s"][1].specification.variant="a.scturkish"
</texcode>
 
And that will fix the turkish lookup. Now, I want to make sure we
only run this code for palatino version 1.40 (it should be obvious
why), and it is nice to do a terminal message as well. (note: testing
for just the font version ignores the fact that different vendors may
use the same font name for different fonts, but that is a complication
that I think can be ignored in this particular case).
 
The end result is:
 
<texcode>
\startluacode
function palapatch (data,filename)
if data.version == "1.40" then
logs.report("load otf", "patching smallcaps i")
data.glyphs[0x92].lookups["ss_latn_l_14_s"][1].specification.variant="a.scturkish"
data.glyphs[0x492].name = "a.scturkish"
end
end
 
fonts.otf.enhancers.patches["^palatino"] = palapatch
\stopluacode
</texcode>

Navigation menu