Difference between revisions of "Palatino Linotype under MKIV"

From Wiki
Jump to navigation Jump to search
(New page: This page shows you how to use most of the typographical features of the Palatino Linotype font shipped with Windows XP under ConTeXt / LuaTeX a.k.a. MKIV, and particularly how to get the ...)
 
(Splitting ligatures and miscellaneous into separate sections. Updating image.)
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This page shows you how to use most of the typographical features of the Palatino Linotype font shipped with 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.
+
This page shows you how to use most of the typographical features of the Palatino Linotype font shipped with MS Windows.
  
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 requires LuaTeX 0.77.0+ which simplifies the font setup significantly.
 
 
The following code has been tested with ConTeXt 2010.06.23 / LuaTeX 0.60.1 on Win XP. ([[User:Schickele|Schickele]] 16:02, 30 June 2010 (UTC))
 
  
 
== Example file ==
 
== 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>
 
<texcode>
\startluacode
+
% specifying ancient greek pattern ensures proper hyphenation of greek text
function palapatch (data,filename)
+
\setuplanguage[en][patterns={en,agr}]
    if data.version == "1.40" then
+
\mainlanguage[en]
        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["^pala"] = palapatch
 
\stopluacode
 
 
 
\definefontfeature[palatinolt-default][script=latn,kern=yes,liga=yes,trep=yes,tlig=yes,protrusion=quality]
 
\definefontfeature[palatinolt-smcp][script=latn,kern=yes,liga=yes,trep=yes,tlig=yes,protrusion=quality,smcp=yes,onum=yes]
 
\definefontfeature[palatinolt-sups][mode=node,script=latn,kern=yes,liga=yes,trep=yes,tlig=yes,protrusion=quality,sups=yes]
 
  
\starttypescript[serif][palatinolt][name]
+
\definefontfamily[palatino][rm][Palatino Linotype][features={default, quality}]
\usetypescript[serif][fallback]
+
% by default all \it \bf \bi \smallcaps \oldstyle styles are ready to use as well as ligatures
\definefontsynonym[Serif][file:pala.ttf][features=palatinolt-default]
+
% but superscript requires extra settings
\definefontsynonym[SerifBold][file:palab.ttf][features=palatinolt-default]
+
\definefontfeature[f:superscript][sups=yes]
\definefontsynonym[SerifItalic][file:palai.ttf][features=palatinolt-default]
+
% an extra \sup macro is defined for our convenience
\definefontsynonym[SerifBoldItalic][file:palabi.ttf][features=palatinolt-default]
+
\define[1]\sup{\feature[+][f:superscript]#1}
\definefontsynonym[SerifCaps][file:pala.ttf][features=palatinolt-smcp]
 
\definefontsynonym[SerifSlanted][file:pala.ttf][features=palatinolt-sups]
 
\stoptypescript
 
  
\definetypeface[PalatinoLinotype][rm][serif][palatinolt][default]
+
\setupbodyfont[palatino]
 +
% global protrusion and expansion settings - it is not inherited in custom paragraph definitions
 +
\setupalign[hz, hanging]
  
\setupbodyfont[PalatinoLinotype]
+
\defineparagraphs[TwoColumns][n=2, align={hz, hanging}]
\setupbodyfontenvironment[default][em=italic]
+
\setupparagraphs[TwoColumns][1][width=100pt, style=italic, align=left]
\setuppagenumbering[location=]
 
\enableprotruding
 
 
 
\defineparagraphs[TwoColumns][n=2,align=hanging]
 
\setupparagraphs[TwoColumns][1][width=52pt,style=\em,align=left]
 
  
 
\starttext
 
\starttext
Line 60: Line 38:
 
\startTwoColumns
 
\startTwoColumns
 
Italic\TwoColumns
 
Italic\TwoColumns
{\em\getbuffer[Plato]}
+
{\it\getbuffer[Plato]}
 
\stopTwoColumns
 
\stopTwoColumns
  
Line 75: Line 53:
 
\startTwoColumns
 
\startTwoColumns
 
Small caps\TwoColumns
 
Small caps\TwoColumns
{\sc\getbuffer[Plato]}
+
{\smallcaps\getbuffer[Plato]}
 
\stopTwoColumns
 
\stopTwoColumns
  
 
\startTwoColumns
 
\startTwoColumns
Old greek\TwoColumns
+
Ancient greek\TwoColumns
 
Ὅτι μὲν ὑμεῖς, ὦ ἄνδρες Ἀθηναῖοι,  
 
Ὅτι μὲν ὑμεῖς, ὦ ἄνδρες Ἀθηναῖοι,  
 
πεπόνθατε ὑπὸ τῶν ἐμῶν κατηγόρων,  
 
πεπόνθατε ὑπὸ τῶν ἐμῶν κατηγόρων,  
Line 85: Line 63:
 
αὐτῶν ὀλίγου ἐμαυτοῦ ἐπελαθόμην,  
 
αὐτῶν ὀλίγου ἐμαυτοῦ ἐπελαθόμην,  
 
οὕτω πιθανῶς ἔλεγον.  
 
οὕτω πιθανῶς ἔλεγον.  
 +
\stopTwoColumns
  
 +
\startTwoColumns
 +
Ligatures\TwoColumns
 +
Jeff, the office at the first floor is offline.
 
\stopTwoColumns
 
\stopTwoColumns
  
Old style figures \& superior characters: 567890 / {\sc 567890} --- 1{\sl 1} o{\sl o} re{\sl re}
+
\startTwoColumns
 +
Miscellaneous\TwoColumns
 +
Old style figures 1234567890/{\oldstyle 1234567890}.\par
 +
Superior characters 1{\sup 1} o{\sup o} re{\sup re}.
 +
\stopTwoColumns
  
 
\stoptext
 
\stoptext
 
</texcode>
 
</texcode>
  
[[Image:Palatino_linotype_under_mkiv.png]]
+
[[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>
 

Revision as of 19:16, 1 April 2016

This page shows you how to use most of the typographical features of the Palatino Linotype font shipped with MS Windows.

The following code requires LuaTeX 0.77.0+ which simplifies the font setup significantly.

Example file

% specifying ancient greek pattern ensures proper hyphenation of greek text
\setuplanguage[en][patterns={en,agr}]
\mainlanguage[en]

\definefontfamily[palatino][rm][Palatino Linotype][features={default, quality}]
% by default all \it \bf \bi \smallcaps \oldstyle styles are ready to use as well as ligatures
% but superscript requires extra settings
\definefontfeature[f:superscript][sups=yes]
% an extra \sup macro is defined for our convenience
\define[1]\sup{\feature[+][f:superscript]#1}

\setupbodyfont[palatino]
% global protrusion and expansion settings - it is not inherited in custom paragraph definitions
\setupalign[hz, hanging]

\defineparagraphs[TwoColumns][n=2, align={hz, hanging}]
\setupparagraphs[TwoColumns][1][width=100pt, style=italic, align=left]

\starttext

\startbuffer[Plato]
How you, O Athenians, have been affected by my accusers, I cannot tell;
but I know that they almost made me forget who I was--so persuasively
did they speak; and yet they have hardly uttered a word of truth.
\stopbuffer

\startTwoColumns
Roman\TwoColumns
\getbuffer[Plato]
\stopTwoColumns

\startTwoColumns
Italic\TwoColumns
{\it\getbuffer[Plato]}
\stopTwoColumns

\startTwoColumns
Bold\TwoColumns
{\bf\getbuffer[Plato]}
\stopTwoColumns

\startTwoColumns
Bold italic\TwoColumns
{\bi\getbuffer[Plato]}
\stopTwoColumns

\startTwoColumns
Small caps\TwoColumns
{\smallcaps\getbuffer[Plato]}
\stopTwoColumns

\startTwoColumns
Ancient greek\TwoColumns
Ὅτι μὲν ὑμεῖς, ὦ ἄνδρες Ἀθηναῖοι, 
πεπόνθατε ὑπὸ τῶν ἐμῶν κατηγόρων, 
οὐκ οἶδα· ἐγὼ δ' οὖν καὶ αὐτὸς ὑπ' 
αὐτῶν ὀλίγου ἐμαυτοῦ ἐπελαθόμην, 
οὕτω πιθανῶς ἔλεγον. 
\stopTwoColumns

\startTwoColumns
Ligatures\TwoColumns
Jeff, the office at the first floor is offline.
\stopTwoColumns

\startTwoColumns
Miscellaneous\TwoColumns
Old style figures 1234567890/{\oldstyle 1234567890}.\par
Superior characters 1{\sup 1} o{\sup o} re{\sup re}.
\stopTwoColumns

\stoptext

palatino linotype under mkiv.png