Skip to content

Instantly share code, notes, and snippets.

@hmenke
Created September 10, 2018 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmenke/b8a1e7c47b92b8cf8778efa7d3eef315 to your computer and use it in GitHub Desktop.
Save hmenke/b8a1e7c47b92b8cf8778efa7d3eef315 to your computer and use it in GitHub Desktop.
Quality protrusion vectors in LuaTeX
\documentclass{article}
\usepackage{fontspec}
\usepackage{luacode}
\usepackage{xcolor}
\begin{luacode*}
local byte = string.byte
fonts.expansions.setups['quality'] = {
stretch = 2, shrink = 2, step = .5, factor = 1,
[byte('A')] = 0.5, [byte('B')] = 0.7, [byte('C')] = 0.7, [byte('D')] = 0.5, [byte('E')] = 0.7,
[byte('F')] = 0.7, [byte('G')] = 0.5, [byte('H')] = 0.7, [byte('K')] = 0.7, [byte('M')] = 0.7,
[byte('N')] = 0.7, [byte('O')] = 0.5, [byte('P')] = 0.7, [byte('Q')] = 0.5, [byte('R')] = 0.7,
[byte('S')] = 0.7, [byte('U')] = 0.7, [byte('W')] = 0.7, [byte('Z')] = 0.7,
[byte('a')] = 0.7, [byte('b')] = 0.7, [byte('c')] = 0.7, [byte('d')] = 0.7, [byte('e')] = 0.7,
[byte('g')] = 0.7, [byte('h')] = 0.7, [byte('k')] = 0.7, [byte('m')] = 0.7, [byte('n')] = 0.7,
[byte('o')] = 0.7, [byte('p')] = 0.7, [byte('q')] = 0.7, [byte('s')] = 0.7, [byte('u')] = 0.7,
[byte('w')] = 0.7, [byte('z')] = 0.7,
[byte('2')] = 0.7, [byte('3')] = 0.7, [byte('6')] = 0.7, [byte('8')] = 0.7, [byte('9')] = 0.7,
}
fonts.protrusions.setups['quality'] = {
factor = 1, left = 1, right = 1,
[0x002C] = { 0, 1 }, -- comma
[0x002E] = { 0, 1 }, -- period
[0x003A] = { 0, 1 }, -- colon
[0x003B] = { 0, 1 }, -- semicolon
[0x002D] = { 0, 1 }, -- hyphen
[0x00AD] = { 0, 1 }, -- also hyphen
[0x2013] = { 0, 0.50 }, -- endash
[0x2014] = { 0, 0.33 }, -- emdash
[0x3001] = { 0, 1 }, -- ideographic comma 、
[0x3002] = { 0, 1 }, -- ideographic full stop 。
[0x060C] = { 0, 1 }, -- arabic comma ،
[0x061B] = { 0, 1 }, -- arabic semicolon ؛
[0x06D4] = { 0, 1 }, -- arabic full stop ۔
[0x003F] = { 0, 0.20 }, -- ?
[0x00BF] = { 0.20, 0 }, -- ¿
[0x0021] = { 0, 0.20 }, -- !
[0x00A1] = { 0.20, 0, }, -- ¡
[0x0028] = { 0.05, 0 }, -- (
[0x0029] = { 0, 0.05 }, -- )
[0x005B] = { 0.05, 0 }, -- [
[0x005D] = { 0, 0.05 }, -- ]
[0x002C] = { 0, 0.70 }, -- comma
[0x002E] = { 0, 0.70 }, -- period
[0x003A] = { 0, 0.50 }, -- colon
[0x003B] = { 0, 0.50 }, -- semicolon
[0x002D] = { 0, 0.70 }, -- hyphen
[0x00AD] = { 0, 0.70 }, -- also hyphen
[0x2013] = { 0, 0.30 }, -- endash
[0x2014] = { 0, 0.20 }, -- emdash
[0x060C] = { 0, 0.70 }, -- arabic comma
[0x061B] = { 0, 0.50 }, -- arabic semicolon
[0x06D4] = { 0, 0.70 }, -- arabic full stop
[0x061F] = { 0, 0.20 }, -- ؟
-- todo: left and right quotes: .5 double, .7 single
[0x2039] = { 0.70, 0.70 }, -- left single guillemet ‹
[0x203A] = { 0.70, 0.70 }, -- right single guillemet ›
[0x00AB] = { 0.50, 0.50 }, -- left guillemet «
[0x00BB] = { 0.50, 0.50 }, -- right guillemet »
[0x2018] = { 0.70, 0.70 }, -- left single quotation mark ‘
[0x2019] = { 0, 0.70 }, -- right single quotation mark ’
[0x201A] = { 0.70, 0 }, -- single low-9 quotation mark ,
[0x201B] = { 0.70, 0 }, -- single high-reversed-9 quotation mark ‛
[0x201C] = { 0.50, 0.50 }, -- left double quotation mark “
[0x201D] = { 0, 0.50 }, -- right double quotation mark ”
[0x201E] = { 0.50, 0 }, -- double low-9 quotation mark „
[0x201F] = { 0.50, 0 }, -- double high-reversed-9 quotation mark ‟
[byte("A")] = { .05, .05 },
[byte("F")] = { 0, .05 },
[byte("J")] = { .05, 0 },
[byte("K")] = { 0, .05 },
[byte("L")] = { 0, .05 },
[byte("T")] = { .05, .05 },
[byte("V")] = { .05, .05 },
[byte("W")] = { .05, .05 },
[byte("X")] = { .05, .05 },
[byte("Y")] = { .05, .05 },
[byte("k")] = { 0, .05 },
[byte("r")] = { 0, .05 },
[byte("t")] = { 0, .05 },
[byte("v")] = { .05, .05 },
[byte("w")] = { .05, .05 },
[byte("x")] = { .05, .05 },
[byte("y")] = { .05, .05 },
}
\end{luacode*}
\protrudechars=2
%\adjustspacing=2
\newfontfamily\none{Latin Modern Roman}[Color=gray]
\newfontfamily\default{Latin Modern Roman}[RawFeature={protrusion=default},Color=red]
\newfontfamily\quality{Latin Modern Roman}[RawFeature={protrusion=quality},Color=blue]
\begin{document}
\fboxsep=0pt
\fboxrule=.1pt
\setbox0=\vbox{\none\input tufte\par}
\setbox1=\vbox{\default\input tufte\par}
\setbox2=\vbox{\quality\input tufte\par}
``default'' over ``none'':
\fbox{\ooalign{\copy0\cr\hidewidth\copy1\hidewidth\cr}}
``quality'' over ``none'':
\fbox{\ooalign{\copy0\cr\hidewidth\copy2\hidewidth\cr}}
``quality'' over ``default'':
\fbox{\ooalign{\copy1\cr\hidewidth\copy2\hidewidth\cr}}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment