Forum Samples, Tips and Tricks

Proper typographical ligatures

kmmv
prince-text-replace makes it easy to apply proper typographical ligatures to your PDFs, assuming your fonts support them:

* {
    prince-text-replace: "ff" "\fb00" "fi" "\fb01" "fl" "\fb02" "ffi" "\fb03" "ffl" "\fb04" "ft" "\fb05" "ij" "\133" "IJ" "\132";
}


This replaces the "ff" "fi" "fl" "ffi" "ffl" "ft" and "ij" ligatures. Note that most common fonts do not have all ligatures, although the first five are common, the latter two are not. The higher quality professional fonts generally include them, and may include many other ligatures ("Th" "MB" "e.g." "i.e" "f.e" "etc" etc).

These may make moving from LaTeX to Prince a bit easier.
mikeday
That's a neat trick! A good workaround until we support ligatures automatically in Prince. :)
carl johnson
Note to future readers:

U+FB05 ſt is NOT a ligature for f and t. It is a ligature for t plus "long s" the weird letter that looks like an f that was used for s inside of words until the 19th century. See its wikipedia entry for more info, but suffice it to say, you don't want to replace ft with ſt in your documents.

Also, the 3 character substitutions need to be specified before the 2 character substitutions in order to have an effect on the text. Here is what I use:

    body { 
        font-size: 12pt; 
        font-family: "Palatino Linotype", serif;
        prince-text-replace: "ffi" "\fb03" "ffl" "\fb04" "fi" "\fb01" "fl" "\fb02" "ff" "\fb00" "ij" "\133" "IJ" "\132"; 
    }
    h1, h2, h3, h4, {
        font-family: Helvetica, sans-serif;
        font-weight: bold;
        prince-text-replace: "fi" "\fb01" "fl" "\fb02" "ij" "\133" "IJ" "\132";
    }
mikeday
We have now released the first beta for Prince 7.0, which supports automatic ligatures found in OpenType fonts.
Infarinato
mikeday wrote:
We have now released the first beta for Prince 7.0, which supports automatic ligatures found in OpenType fonts.

I’m using Prince 8.0 beta 1 and —I think— OpenType fonts (say, Georgia), but am not getting the common ligatures applied. Not even explicitly setting
font-variant: prince-opentype(liga);
would work for me. :(

Only explicit text replace seems to work:
prince-text-replace: "ffi" "\fb03" "ffl" "\fb04" "fi" "\fb01" "fl" "\fb02" "ff" "\fb00";
:?

Any suggestions?

Many thanks.
mikeday
Georgia does not seem to have any OpenType information, eg. a GSUB table needed for ligature substitutions. The DejaVu fonts on Linux do, and the newer Microsoft fonts on Windows Vista do.
StoneCypher
How does one check for whether a given font has such information? Does Candara?

John Haugeland is http://fullof.bs/

mikeday
Candara does, as do the other "C" fonts that come with Vista. I think that old classics like Times New Roman have also been updated to include OpenType information at some point, but the Microsoft Core Fonts package that people use on non-Windows platforms have not.
_savage
Great to see this feature, I should poke around these forums more often :-)

To ask StoneCypher's question again: how do I know whether a given font supports ligatures or not? Manual inspection of the above mentioned substitutions?

(Edit: It seems the Palatino I use at the moment doesn't have that support: the font-variant had no effect, and explicit substitutions rendered with a different font. Gah.)

Edited by _savage

mikeday
I'm not sure what is the best way to check if a font supports ligatures, besides opening it in a font editor, or producing a PDF and carefully examining the output. :)

We could get Prince to check if the font has the OpenType GSUB table when you run --scanfonts, but this would not guarantee that it contains ligature substitutions. And even if it does have ligature substitutions, you might want to know exactly which ligatures it supports.

Is the Palatino font an OpenType font? If it came with MacOS X, it may use the Apple Advanced Typography (AAT) layout features instead of OpenType GSUB/GPOS tables, which is why Prince isn't picking up the ligatures.
_savage
I just checked: there are two fonts installed on my Mac (as per Font Book). One is the "Palatino" which apparently is a TrueType font v3.8 but I can't find its actual .ttf file? It's supposed to be in /Library/Fonts/ but there is only an empty file.

The other one is "Palatino Linotype" which I think Microsoft Office installed, and that's a OpenType TrueType font v5, with a .ttf file accessible.

When I set my
@font-face {
  font-family: serif;
  src: local("Palatino Linotype");
}

to either one of them, words like "effect" or "find" don't seem to have ligatures. Ah well, I'll leave it enabled in my stylesheet for future reference and different fonts.

Just for laughs and giggles, which font do you know for sure supports ligatures, so that I can take a look? Just curious... :)
mikeday
The empty font file is a MacOS X font where the data is stored in the resource fork, not the data fork, making it invisible to traditional Unix tools. This is the historical legacy of MacOS dating back to the '80s; doesn't make much sense now, but we still have to deal with it. :)

The Windows Vista fonts have ligatures, that's Calibri, Candara, Cambria, all the fonts whose names begin with C. The Microsoft Core Fonts don't support ligatures, so that's Times New Roman, Arial, Georgia, etc. Although updated versions of these fonts shipped with more recent versions of Windows or Office may have extended OpenType support.

If you browse Adobe TypeKit or Google Web Fonts you will find many modern fonts that have extensive support for OpenType features, including ligatures. On Linux the free DejaVu font family also has good OpenType support, as do many of the SIL fonts such as Gentium.
_savage
I think this thread here is a better continuation for this discussion, because it's turning ligature now.

With this in my CSS
body {
  prince-text-replace: "ffi" "\fb03" "fi" "\fb01" "ffl" "\fb04" "fl" "\fb02" "ff" "\fb00" /* "???" "\fb05" */ "st" "\fb06"; /* order is important! */
  font-variant: prince-opentype(onum, liga);
}
I noticed that some ligatures ("fi" in "first," for example) are applied, while other's aren't ("ffi" in "efficient"). It makes no difference whether I delete the prince-text-replace or not; I would have expected that the text replace would at least take care of those ligatures that have Unicode code points for latin ligatures (see here).

The font I am using is a ttf file of the Pona typeface. It does offer several ligatures, as can be seen from the specimen sheet. If I understand our conversation correctly, then the reason why ligatures like "ffi" don't show in the PDF are because they are not exported/declared by the font as such?
mikeday
The font has to support the ligature code points if you want to use the text-replace method. But if it doesn't, you should be getting question marks in the output and warnings in the Prince log. You can always try text-replacing it to something else like "HELLO" to check it is actually applying.

In general though, using the OpenType feature should be nicer. Perhaps the font does not declare "ffi" as a default ligature (although that would be surprising?) or perhaps Prince is not applying it for some other reason.

If you want I can take a look at the font file, or you can try loading it in an OpenType editor and seeing what features it defines.
_savage
Thank you for the elaboration, Mike, I'll remove the manual text replace from the stylesheet then.

After your hint I went off to read up on OpenType features here and here, and now it makes more sense what you’re saying. Looking at the feature list of ligatures (just installed FontForge) defined by the Pona font, it seems to provide "ff" and "ffi" and other ligatures. Oddly, in "efficient" the "fi" ligature works but not the "ffi;" could there be an ordering problem in the substitution order within the font's features?

To try this further, I used a small test file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <style>
@font-face {
  font-family: ponafont;
  font-style: normal;
  font-weight: 300;
  src: local("Pona Light");
}
p {
  font-family: ponafont;
  font-variant: prince-opentype(liga);
}
    </style>
  </head>
  <body>
    <p>fi fl ff fb ffb fh ffh ffi fj ffj fk ffk fl</p>
  </body>
</html>

which produced the attached princelig.jpg. Compared to the specimen sheet of the Pona font, it seems that some ligatures are missing.

How would I find out if this is on the Prince side or the font side?
  1. ponalig.jpg15.2 kB
    Ligatures defined by Pona specimen sheet
  2. princelig.jpg16.2 kB
    Ligatures by Prince w/ Pona font

Edited by _savage

mikeday
Interesting. Could you email me (mikeday@yeslogic.com) the ttf file? It would be good to confirm that Prince is doing the right thing here. :)
mikeday
It seems that the "liga" feature in the Pona font only covers f+i and f+l ligatures. All the rest are accessed via the "dlig" feature, which is not applied by default.

If you want the additional ligatures like f+f and f+f+i you need to apply dlig before liga, like this:
font-variant: prince-opentype(dlig, liga)
_savage
That seems to have worked, thanks Mike! :)