summaryrefslogtreecommitdiff
path: root/luaotfload.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'luaotfload.dtx')
-rw-r--r--luaotfload.dtx1423
1 files changed, 991 insertions, 432 deletions
diff --git a/luaotfload.dtx b/luaotfload.dtx
index 3538075..818dbd9 100644
--- a/luaotfload.dtx
+++ b/luaotfload.dtx
@@ -1,6 +1,6 @@
% \iffalse meta-comment
%
-% Copyright (C) 2009-2011 by Elie Roux <elie.roux@telecom-bretagne.eu>
+% Copyright (C) 2009-2013 by Elie Roux <elie.roux@telecom-bretagne.eu>
% and Khaled Hosny <khaledhosny@eglug.org>
% (Support: <lualatex-dev@tug.org>.)
%
@@ -14,7 +14,7 @@
% tex luaotfload.dtx
%
% Documentation:
-% pdflatex luaotfload.dtx
+% lualatex luaotfload.dtx
%
% The class ltxdoc loads the configuration file ltxdoc.cfg
% if available. Here you can specify further options, e.g.
@@ -36,7 +36,7 @@
\input docstrip.tex
\Msg{************************************************************************}
\Msg{* Installation}
-\Msg{* Package: luaotfload v2.0 OpenType layout system}
+\Msg{* Package: luaotfload v2.2 OpenType layout system}
\Msg{************************************************************************}
\keepsilent
@@ -47,7 +47,7 @@
\preamble
This is a generated file.
-Copyright (C) 2009-2011 by by Elie Roux <elie.roux@telecom-bretagne.eu>
+Copyright (C) 2009-2013 by by Elie Roux <elie.roux@telecom-bretagne.eu>
and Khaled Hosny <khaledhosny@eglug.org>
(Support: <lualatex-dev@tug.org>.)
@@ -61,13 +61,12 @@ and the derived files
\let\MetaPrefix\DoubleperCent
-
\generate{%
- \usedir{tex/luatex/luaodfload}%
+ \usedir{tex/luatex/luaotfload}%
\file{luaotfload.sty}{\from{luaotfload.dtx}{package}}%
}
-% The following hacks are to generate a lua file with lua comments starting by
+% The following hacks are to generate a lua file with lua comments starting with
% -- instead of %%
\def\MetaPrefix{-- }
@@ -104,35 +103,57 @@ and the derived files
%<*driver>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{luaotfload.drv}%
- [2011/10/06 v2.0 OpenType layout system]%
+ [2013/04/16 v2.2 OpenType layout system]%
\documentclass{ltxdoc}
-\usepackage{metalogo,multicol,mdwlist,fancyvrb,xcolor,xspace}
+\usepackage{metalogo,multicol,mdwlist,fancyvrb,xspace}
+\usepackage[x11names]{xcolor}
+%
+\def\primarycolor{DodgerBlue4} %%-> rgb 16 78 139 | #104e8b
+\def\secondarycolor{Goldenrod4} %%-> rgb 139 105 200 | #8b6914
+%
\usepackage[
- bookmarks=true,
- colorlinks=true,
- linkcolor=niceblue,
-% urlcolor=niceblue,
- citecolor=niceblue,
- pdftitle={The luaotfload package},
- pdfsubject={OpenType layout system for Plain TeX and LaTeX},
- pdfauthor={Elie Roux & Khaled Hosny},
+ bookmarks=true,
+ colorlinks=true,
+ linkcolor=\primarycolor,
+ urlcolor=\secondarycolor,
+ citecolor=\primarycolor,
+ pdftitle={The luaotfload package},
+ pdfsubject={OpenType layout system for Plain TeX and LaTeX},
+ pdfauthor={Elie Roux & Khaled Hosny},
pdfkeywords={luatex, lualatex, unicode, opentype}
- ]{hyperref}
-
+]{hyperref}
\usepackage{fontspec}
-\usepackage{unicode-math}
-\setmainfont[Ligatures=TeX]{Linux Libertine O}
-\setsansfont[Ligatures=TeX]{Linux Biolinum O}
-\setmathfont{XITS Math}
+%usepackage{unicode-math}%% broken
+\setmainfont[Numbers=OldStyle,Ligatures=TeX]{Linux Libertine O}
+\setmonofont[Ligatures=TeX,Scale=MatchLowercase]{Liberation Mono}
+%setsansfont[Ligatures=TeX]{Linux Biolinum O}
+\setsansfont[Ligatures=TeX,Scale=MatchLowercase]{Iwona Medium}
+%setmathfont{XITS Math}
+
+\newcommand\TEX {\TeX\xspace}
+\newcommand\LUA {Lua\xspace}
+\newcommand\PDFTEX {pdf\TeX\xspace}
+\newcommand\LUATEX {Lua\TeX\xspace}
+\newcommand\XETEX {\XeTeX\xspace}
+\newcommand\LATEX {\LaTeX\xspace}
+\newcommand\CONTEXT{Con\TeX t\xspace}
-\definecolor{niceblue}{rgb}{0.4,0.6,1.000}
+\def\definehighlight[#1][#2]%
+ {\ifcsname #1\endcsname\else
+ \expandafter\def\csname #1\endcsname%
+ {\bgroup#2\csname #1_indeed\endcsname}
+ \expandafter\def\csname #1_indeed\endcsname##1%
+ {##1\egroup}%
+ \fi}
-\newcommand\tex {\TeX\xspace}
-\newcommand\pdftex {PDF\TeX\xspace}
-\newcommand\luatex {Lua\TeX\xspace}
-\newcommand\xetex {\XeTeX\xspace}
-\newcommand\latex {\LaTeX\xspace}
-\newcommand\context{Con\TeX t\xspace}
+\def\restoreunderscore{\catcode`\_=12\relax}
+
+\definehighlight [fileent][\ttfamily\restoreunderscore] %% files, dirs
+\definehighlight [texmacro][\sffamily\itshape\textbackslash] %% cs
+\definehighlight[luafunction][\sffamily\itshape\restoreunderscore] %% lua identifiers
+\definehighlight [identifier][\sffamily] %% names
+\definehighlight [abbrev][\rmfamily\scshape] %% acronyms
+\definehighlight [emphasis][\rmfamily\slshape] %% level 1 emph
\newcommand*\email[1]{\href{mailto:#1}{#1}}
@@ -163,76 +184,102 @@ and the derived files
%
% \GetFileInfo{luaotfload.drv}
%
-% \title{The \textsf{luaotfload} package}
-% \date{2011/10/06 v2.0}
+% \title{The \identifier{luaotfload} package}
+% \date{2013/04/16 v2.2}
% \author{Elie Roux and Khaled Hosny\\
% Support: \email{lualatex-dev@tug.org}}
%
% \maketitle
%
% \begin{abstract}
-% This package is an adaptation of the \context font loading system, providing
-% the ability to load \textsf{OpenType} fonts with extended font loading syntax
-% supporting a large selection of OpenType font features.
+% This package is an adaptation of the \CONTEXT font loading system, providing
+% the ability to load \identifier{OpenType} fonts with extended font loading syntax
+% supporting a large selection of \identifier{OpenType} font features.
% \end{abstract}
%
% \tableofcontents
%
% \section{Introduction}
%
-% Font management and installation has always been painful with \tex. A lot of
-% files are needed for one font (tfm, pfb, map, fd, vf), and as \tex is 8-bit
-% each font is limited to 256 characters. But the font world has evolved since
-% \tex, and new font technologies have appeared, most notably the so called
-% \emph{smart font} technologies like \textsf{OpenType} fonts. These fonts can
-% contain a lot of characters, and additional functionalities like ligatures,
-% old-style numbers, small capitals, etc., and support more complex writing
-% systems like Arabic and Indic\footnote{Unfortunately, \textsf{luaotfload}
-% doesn't support Indic scripts right now.} scripts. They are widely deployed
-% and available for all modern operating systems and are becoming the de facto
-% standard fonts for advanced text layout. Until now the only way to use them
-% directly in the \tex world was by using them with \xetex.
-%
-% Unlike \xetex, \luatex does not provide direct support for using these fonts
-% by default, but it provides a way to hook Lua code in some points of the \tex
-% processing; for instance, we can improve the font loading system, and text
-% procession, which what this package is about.
+% Font management and installation has always been painful with \TEX. A lot of
+% files are needed for one font (\abbrev{tfm}, \abbrev{pfb}, \abbrev{map},
+% \abbrev{fd}, \abbrev{vf}), and as \TEX is 8-bit each font is limited to 256
+% characters.
+% But the font world has evolved since the original
+% \TEX, and new typographic systems have appeared, most notably the so
+% called \emphasis{smart font} technologies like \identifier{OpenType}
+% (\abbrev{otf}) fonts.
+% These fonts can contain a lot of characters and additional
+% functionality like ligatures, old-style numbers, small capitals,
+% etc., and support more complex writing systems like Arabic and
+% Indic\footnote{%
+% Unfortunately, \identifier{luaotfload} doesn't support Indic
+% scripts right now.
+% Assistance in implementing the prerequisites is greatly
+% appreciated.
+% }
+% scripts.
+% \identifier{OpenType} fonts are widely deployed and available for all
+% modern operating systems.
+% As of 2013 they have become the de facto standard for advanced text
+% layout.
+% However, until recently the only way to use them directly in the \TEX
+% world was with the \XETEX engine.
+%
+% Unlike \XETEX, \LUATEX has no built-in support for
+% \identifier{OpenType} or other technologies.
+% Instead, it provides hooks for executing Lua during the \TEX run
+% that allow implementing extensions for loading fonts and manipulating
+% how input text is processed without modifying the underlying engine.
%
% \section{Loading fonts}
%
-% \textsf{luaotfload} supports an extended font loading syntax which looks
-% like:
+% \identifier{luaotfload} supports an extended font loading syntax:
%
% \begin{center}
-% |\font\foo={|\meta{prefix}|:|\meta{font name}|:|\meta{font features}|}| \meta{\tex font features}
+% |\font\foo={|%
+% \meta{prefix}|:|%
+% \meta{font name}|:|%
+% \meta{font features}|}|%
+% \meta{\TEX font features}
% \end{center}
%
% \noindent
-% The curly brackets are optional and are used for escaping spaces in font
-% names (double quotes can also used for the same purpose).
+% The curly brackets are optional and escape the spaces in the enclosed
+% font name (alternatively, double quotes serve the same purpose).
+% The individual parts of the syntax are:
%
% \paragraph{Prefix}
%
-% The \meta{prefix} can be either |file:| or |name:|, which specify whether to
-% use a select the font from its filename or font name, respectively. If no
-% prefix is specified |name:| is assumed.
-%
-% For compatibility with \xetex, surrounding the \meta{font name} with square
-% brackets is synonymous to using the |file:| prefix.
-%
-% Accessing fonts by fontname allows loading system installed fonts as well as
-% \textsc{texmf} ones, and requires a font names database; see
+% The \meta{prefix} is either |file:| or |name:|.
+% It determines whether font loader should interpret the request as a
+% file name or font name, respectively, which again influences how it
+% will attempt to locate the font.
+% The prefix can be omitted, in which case |name:| is assumed.
+%
+%% \iffalse%% how am i supposed to friggin comment stuff in a dtx???
+%% TODO
+%% it would appear that the next paragraph is incorrect; I get
+%% name: lookups regardless unless the font file is actually
+%% in CWD
+%% \fi
+%% For compatibility with \XETEX, surrounding the \meta{font name} with
+%% square brackets is synonymous to using the |file:| prefix.
+%
+% Accessing fonts by fontname allows loading system installed fonts as
+% well as \fileent{texmf} ones, and requires a font names database; see
% Section~\ref{sec:fontdb} for more information.
%
% \paragraph{Font name}
%
-% The \meta{font name} can be either a font filename or actual font name based
-% on the \meta{prefix} as mentioned above.
+% The \meta{font name} can be either a font filename or actual font
+% name based on the \meta{prefix} as mentioned above.
%
-% Fonts loaded by filename may either include their absolute path in the
-% filesystem or consist of just the filename with a path. If no path is
-% specified then \textsf{kpathsea} is used to locate the font (which will
-% typically be in the \textsc{texmf} tree or the current directory).
+% Fonts loaded by filename may either include their absolute path in
+% the filesystem or consist of just the filename without a path. If no
+% path is specified, then \identifier{kpathsea} is used to locate the
+% font (which will typically be in the \fileent{texmf} tree or the
+% current directory).
%
% For example,
% \begin{quote}
@@ -247,527 +294,1039 @@ and the derived files
% \paragraph{Font features}
%
% \meta{font features} is semicolon-separated list of feature
-% tags\footnote{\url{http://www.microsoft.com/typography/otspec/featurelist.htm}}
-% and font options. Font features are prepended with a |+| to turn them on and
-% a |-| to turn them off, alternatively you can pass |true| or |false| value to
-% the feature:
+% tags\footnote{%
+% Cf. \url{http://www.microsoft.com/typography/otspec/featurelist.htm}.
+% }
+% and font options.
+% Prepending a font feature with a |+|-sign enables it, while
+% a |-| disables it. For instance, the request
%
% |\font\test=Latin Modern Roman:+clig;-kern|
%
-% \noindent or:
+% \noindent activates contextual ligatures (|clig|) and disables
+% kerning (|kern|).
+% Alternatively the options |true| or |false| can be passed to
+% the feature in a key/value expression.
+% The following request has the same meaning as the last one:
%
% |\font\test=Latin Modern Roman:clig=true;kern=false|
%
-% \noindent For alternate substation features you can pass the index of the
-% variant you want (starting from 1) or |random| to randomly select a variant
-% each time an affected glyph is shown, e.g.:
+% \noindent
+% Furthermore, this second syntax is required if a font feature
+% accepts options besides its activation state.
+% For example, \emphasis{stylistic alternates} (|salt|) provide a set
+% of variants to given glyphs.
+% These can be selected either explicitly by supplying the variant
+% index (starting from 1), or randomly by setting the value to,
+% obviously, |random|:
%
% |\font\test=Latin Modern Roman:salt=1|
%
-% \noindent Known font options include:
+% \noindent Other font options include:
%
% \begin{description}
+%
% \item [mode] \hfill \\
-% \textsf{luaotfload} has two OpenType processing modes; |base| and |node|.
-% |base| mode works by mapping OpenType features to traditional \tex ligature
-% and kerning mechanisms, thus supporting only non-contextual substitutions and
-% kerning pairs, but is slightly faster. |node| works by direct processing of
-% the node list at Lua end and have more wide support of OpenType features but
-% can be slow especially with complex fonts and can't be used in math mode.
-%
-% By default |node| mode is used, and you have to manually force |base| mode
-% when needed e.g. for math fonts.
-%
-% \item [script] \hfill \\
-% OpenType script
-% string,\footnote{\url{http://www.microsoft.com/typography/otspec/scripttags.htm}}
-% default value is |dflt|. Some fonts don't assign features to the |dflt|
-% script, in which case the script need to be set explicitly.
+% \identifier{luaotfload} has two \identifier{OpenType} processing
+% \emphasis{modes}:
+% \identifier{base} and \identifier{node}.
+%
+% \identifier{base} mode works by mapping \identifier{OpenType}
+% features to traditional \TEX ligature and kerning mechanisms,
+% thus supporting only non-contextual substitutions and kerning
+% pairs, but is the slightly faster variant.
+% \identifier{node} mode works by processing \TEX’s internal
+% node list directly at the \LUA end and supports
+% a wider range of \identifier{OpenType} features.
+% The downside is that the intricate operations required for
+% \identifier{node} mode may slow down typesetting especially
+% with complex fonts and it does not work in math mode.
+%
+% By default \identifier{luaotfload} is in \identifier{node}
+% mode, and \identifier{base} mode has to be requested where needed,
+% e.~g. for math fonts.
+%
+% \item [script] \ref{script-tag} \hfill \\
+% An \identifier{OpenType} script tag;\footnote{%
+% See \url{http://www.microsoft.com/typography/otspec/scripttags.htm}
+% for a list of valid values.
+% For scripts derived from the Latin alphabet the value
+% |latn| is good choice.
+% }
+% the default value is |dlft|.
+% Some fonts do not assign features to the |dflt| script, in
+% which case the script needs to be set explicitly.
%
% \item [language] \hfill \\
-% OpenType language
-% string,\footnote{\url{http://www.microsoft.com/typography/otspec/languagetags.htm}}
-% default value is |latn|.
+% An \identifier{OpenType} language system identifier,\footnote{%
+% Cf. \url{http://www.microsoft.com/typography/otspec/languagetags.htm}.
+% }
+% defaulting to |dflt|.
%
% \item [featurefile] \hfill \\
-% a comma-separated list of feature files to be applied to the font. Feature
-% files are textual representation of OpenType tables and can be used to extend
-% OpenType features of the font on fly. Features defined in a feature file,
-% after being applied to the font, can be enabled/disabled like any other
-% feature. The syntax is documented in Adobe's OpenType Feature File
-% Specification.\footnote{\url{http://www.adobe.com/devnet/opentype/afdko/topic_feature_file_syntax.html}}
-%
-% For example, to set a |tkrn| feature from |mykern.fea| file:
-%
-% |\font\test=Latin Modern Roman:featurefile=mykern.fea;+tkrn|
+% A comma-separated list of feature files to be applied to the
+% font.
+% Feature files contain a textual representation of
+% \identifier{OpenType} tables and extend the features of a font
+% on fly.
+% After they are applied to a font, features defined in a
+% feature file can be enabled or disabled just like any
+% other font feature.
+% The syntax is documented in \identifier{Adobe}’s
+% \identifier{OpenType} Feature File Specification.\footnote{%
+% Cf. \url{http://www.adobe.com/devnet/opentype/afdko/topic_feature_file_syntax.html}.
+% }
+%
+% For a demonstration of how to set a |tkrn| feature consult
+% the file |tkrn.fea| that is part of \identifier{luaotfload}.
+% It can be read and applied as follows:
+%
+% |\font\test=Latin Modern Roman:featurefile=tkrn.fea;+tkrn|
%
% \item [color] \hfill \\
-% font color, defined as a triplet of two-digit hexadecimal RGB values, with
-% optionally another value for the transparency (where |00| is completely
-% transparent and |FF| is opaque.)
+% A font color, defined as a triplet of two-digit hexadecimal
+% \abbrev{rgb} values, with an optional fourth value for
+% transparency
+% (where |00| is completely transparent and |FF| is opaque).
%
-% For example, to set text in semitransparent red:
+% For example, in order to set text in semitransparent red:
%
-% |\font\test=Latin Modern Roman:color=FF0000BB|
+% |\font\test=Latin Modern Roman:color=FF0000BB|
%
% \item [protrusion \& expansion] \hfill \\
-% Both keys control microtypographic features of the font, namely glyph
-% protrusion and expansion. The value of the key is the name of predefined Lua
-% tables of protrusion and expansion values; see the end of |otfl-fonts-ext.lua|
-% file for an example of such tables. The only predefined value is |default|.
+% These keys both control microtypographic features of the font,
+% namely \emphasis{character protrusion} and \emphasis{font
+% expansion}.
+% They accept names of predefined \LUA tables that contain
+% values for the respective features.\footnote{%
+% For examples of the table layout please refer to the
+% section of the file \fileent{otfl-fonts-ext.lua} where the
+% default values are defined.
+% Alternatively and with loss of information, you can dump
+% those tables into your terminal by issuing
+% \begin{verbatim}
+% \directlua{inspect(fonts.protrusions.setups.default)
+% inspect(fonts.expansions.setups.default)}
+% \end{verbatim}
+% at some point after loading \fileent{luaotfload.sty}.
+% }
+% For both, only the set \identifier{default} is predefined.
+%
+% For example, to enable default protrusion\footnote{%
+% You also need to set
+% \verb|pdfprotrudechars=2| and
+% \verb|pdfadjustspacing=2|
+% to activate protrusion and expansion, respectively.
+% See the
+% \href{http://mirrors.ctan.org/systems/pdftex/manual/pdftex-a.pdf}%
+% {\PDFTEX manual}
+% for details.
+% }:
+%
+% |\font\test=Latin Modern Roman:protrusion=default|
+% \end{description}
%
-% For example, to enable default protrusion:\footnote{You also need to set
-% |\pdfprotrudechars2 \pdfadjustspacing2| to activate protrusion and expansion,
-% respectively. See \pdftex manual for details.}
+% \paragraph{Non-standard font features}
+% \identifier{luaotfload} add a number of features that are not defined
+% in the original \identifier{OpenType} specification, most of them
+% aiming at emulating the behavior familiar from other \TEX engines.
+% Currently (2013) there are three of them:
%
-% |\font\test=Latin Modern Roman:protrusion=default|
-% \end{description}
+% \begin{description}
+%
+% \item [anum]
+% Substitutes the glyphs in the \abbrev{ascii} number range
+% with their counterparts from eastern Arabic or Persian,
+% depending on the value of \identifier{language}.
+%
+% \item [tlig]
+% Applies legacy \TEX ligatures:
+% |``|, |''|, |`|, |'|, |"|, |--|, |---|, |!`| and |?`|.%
+% \footnote{%
+% These contain the feature set \verb|trep| of earlier
+% versions of \identifier{luaotfload}.
%
-% \subparagraph{Non-standard font features}
-% \textsf{luaotfload} defines some additional font feature not defined in
-% OpenType, currently three features are defined:
+% Note to \XETEX users: this is the equivalent of the
+% assignment \verb|mapping=text-tex| using \XETEX's input
+% remapping feature.
+% }
%
-% \begin{itemize*}
-% \item |anum|: replaces European numbers with eastern Arabic numbers or
-% Persian numbers, depending on the value of |language|.
-% \item |tlig|: applies legacy \tex ligatures: |``|, |''|, |`|, |'|, |"|, |--|,
-% |---|, |!`| and |?`|.\footnote{For \xetex users: this is the equivalent of
-% writing |mapping=text-tex| using \xetex's input remapping feature.}
-% \end{itemize*}
+% \item [itlc]
+% Computes italic correction values (active by default).
+%
+% \end{description}
%
%
%
% \section{Font names database}
% \label{sec:fontdb}
%
-% As introduced in the previous section, \textsf{luaotfload} uses a database to
-% keep track of fonts available to \luatex. Using this database, fonts can be
-% loaded by font name as well as filename.
-%
-% When \textsf{luaotfload} is asked to load a font by font name, it will check
-% if font names database exists and load it, or generate a new database if non
-% exists. This is all done automatically without user intervention. When the
-% asked font is missing from the database, it will attempt to update the
-% database and try to find the font again, so that the user can install new
-% fonts without worrying about manually updating the database.
-%
-% However, it is sometimes desirable to update the database manually, so
-% \textsf{luaotfload} provides a |mkluatexfontdb| utility to manually update
-% the database. |mkluatexfontdb| is a lua script that can be either run
-% directly or as an argument to |texlua|, depending on your system.\footnote{On
-% MS Windows it can be run either by calling the wrapper application
-% |mkluatexfontdb.exe| or with |texlua.exe mkluatexfontdb.lua|.}
-%
-% The first time the database is generated may take quite some time to process
-% every font on your computer. This is particularly noticeable if it occurs
-% during a typesetting run. Subsequent runs to update the database will be
-% quite fast, however.
-%
-% \textsf{luaotfload} will parse standard places for fonts in your system to
-% build the font database. On Linux, it will read |fontconfig| configuration
-% files to find the font locations; on Windows and Mac~OS~X, it will search in
-% the standard font locations, |%WINDIR%\Fonts| in Windows and
-% |~/Library/Fonts|, |/Library/Fonts|, |/System/Library/Fonts|, and
-% |/Network/Library/Fonts| in Mac~OS~X.
-%
-% If you do not wish the standard font locations be searched by default but
-% would rather specify the exact locations in which to find your fonts, set the
-% |OSFONTDIR| environment variable instead. When this variable is set, only the
-% specified directories will be searched.
-%
-% |mkluatexfontdb.lua --help| provides a brief summary of the functionality of
-% the script and includes some advanced options that we have not mentioned
-% here.
+% As mentioned above, \identifier{luaotfload} keeps track of which
+% fonts are available to \LUATEX by means of a \emphasis{database}.
+% This allows loading not only by explicit filenames but also by the
+% proper names contained in the metadata which is often more accessible
+% to humans.\footnote{%
+% The tool \href{http://www.lcdf.org/type/}{\fileent{otfinfo}} (comes
+% with \TEX Live), when invoked on a font file with the \verb|-o|
+% option, lists the variety of name fields defined for it.
+% }
%
-% \subsection{Blacklisting fonts}
+% When \identifier{luaotfload} is asked to load a font by font name, it
+% will check if the database exists and load it or else generate a
+% fresh one.
+% Should it then fail to locate the font, an update to the database is
+% performed in case the font has been added to the system only
+% recently. As soon as the database is updated, the resolver will try
+% and look up the font again, all without user intervention.
+% The goal is for \identifier{luaotfload} to act in the background and
+% behave as unobtrusively as possible, while providing a convenient
+% interface to the fonts installed on the system.
+%
+% \subsection[mkluatexfontdb.lua]%
+% {\fileent{mkluatexfontdb.lua}\footnote{%
+% The script may be named just \fileent{mkluatexfontdb} in your
+% distribution.
+% }}
+%
+% However, it can be desirable at times to do some of these steps
+% manually.
+% To this end, \identifier{luaotfload} comes with the utility
+% \fileent{mkluatexfontdb} that offers an interface to the database
+% functionality.
+% Being a \LUA script, there are two ways to run it:
+% either make it executable (\verb|chmod +x| on unixoid systems) or
+% pass it as an argument to \fileent{texlua}.\footnote{%
+% Tests by the maintainer show only marginal performance gain by
+% running with Luigi Scarso’s
+% \href{https://foundry.supelec.fr/projects/luajittex/}%
+% {\LUA jit\TEX},
+% which is probably due to the fact that most of the time is spent
+% on file system operations.
+%
+% \emphasis{Note}:
+% On \abbrev{MS} \identifier{Windows} systems, the script can be run
+% either by calling the wrapper application
+% \fileent{mkluatexfontdb.exe} or as
+% \verb|texlua.exe mkluatexfontdb.lua|.
+% }
+% Invoke it from the command line with the \verb|--force| switch to
+% initiate a complete rebuild of the database.
+%
+% \begin{verbatim}
+% mkluatexfontdb --force
+% \end{verbatim}
%
-% Some fonts are problematic in \luatex, if you found that your document takes
-% too long to compile, or eats all the free memory, you can find the culprit
-% file by running |mkluatexfontdb| utility with |-v| option to see which font
-% file it is stuck with. You can then instruct \textsf{luaotfload} to ignore
-% this font by adding it to the blacklist configuration file.
-%
-% Simply, create a file named |otfl-blacklist.cnf| and added the to be
-% blacklisted files, one per line. Then put the file some where \textsf{kpse}
-% can find. You can either use the base name or the full path. Any thing after
-% a |%| sign is ignored. \textsf{luaotfload} reads all files named named
-% |otfl-blacklist.cnf|, so you can add your own fonts to the global blacklist
-% by creating a local file |otfl-blacklist.cnf| with the entries you need. You
-% can also remove a font from this blacklist by prepending the name with a dash
-% (|-|).
+% Generating the database for the first time may take a while since it
+% inspects every font file on your computer.
+% This is particularly noticeable if it occurs during a typesetting run.
+% In any case, subsequent updates to the database will be quite fast.
+%
+% \subsection{Search Paths}
+%
+% \identifier{luaotfload} scans those directories where fonts are
+% expected to be located on a given system.
+% On a Linux machine it follows the paths listed in the
+% \identifier{Fontconfig} configuration files;
+% consult \verb|man 5 fonts.conf| for further information.
+% On \identifier{Windows} systems, the standard location is
+% \verb|Windows\Fonts|,
+% while \identifier{Mac OS~X} requires a multitude of paths to
+% be examined.
+% The complete list is is given in table \ref{table-searchpaths}.
+% Other paths can be specified by setting the environment variable
+% \verb+OSFONTDIR+.
+% If it is non-empty, then search will be limited to the included
+% directories.
+%
+% \begin{table}[t]
+% \hrule
+% \caption{List of paths searched for each supported operating
+% system.}
+% \renewcommand{\arraystretch}{1.2}
+% \begin{center}
+% \begin{tabular}{lp{.5\textwidth}}
+% Windows & \verb|%WINDIR%\Fonts|
+% \\
+% Linux & \fileent{/usr/local/etc/fonts/fonts.conf} and\hfill\break
+% \fileent{/etc/fonts/fonts.conf"}
+% \\
+% Mac & \fileent{~/Library/Fonts},\break
+% \fileent{/Library/Fonts},\break
+% \fileent{/System/Library/Fonts}, and\hfill\break
+% \fileent{/Network/Library/Fonts}
+% \\
+% \end{tabular}
+% \end{center}
+% \label{table-searchpaths}
+% \hrule
+% \end{table}
+%
+% \subsection{Querying from outside}
+%
+% \fileent{mkluatexfontdb.lua} also provides rudimentary means of
+% accessing the font database.
+% If the option \verb|--find=name| is given, the script will try and search
+% the fonts indexed by \identifier{luaotfload} for a matching name.
+% For instance, the invocation
%
% \begin{verbatim}
-% % example otf-blacklist.cnf
-% /Library/Fonts/GillSans.ttc % luaotfload ignores this font
-% -/Library/Fonts/Optima.ttc % it is usable again, even if it
-% % is blacklisted somewhere else
+% mkluatexfontdb.lua --find="Iwona Regular"
% \end{verbatim}
%
-% \section{Used \context files}
+% will verify if “Iwona Regular” is found in the database and can be
+% readily requested in a document.
%
-% This package is a wrapper for several files taken from the \context macro
-% package. The philosophy is to let \context do all the implementation and
-% update these files from time to time. So we try not to modify the files taken
-% from \context as far as possible, but we changed their names to prevent name
-% clashes.
+% If you are unsure about the actual font name, then you can add the
+% \verb|-F| switch to the command line to enable approximate matching.
+% Suppose you cannot precisely remember if the variant of
+% \identifier{Iwona} you are looking for was “Bright” or “Light”.
+% The query
%
-% The \context files are renamed by adding the prefix |otfl-| to them (|otfl|
-% as |OTF L|oad). The files are:
+% \begin{verbatim}
+% mkluatexfontdb.lua -F --find="Iwona Bright"
+% \end{verbatim}
%
-% \begin{multicols}{3}
-% \begin{itemize*}
-% \item |data-con.lua|
-% \item |font-cid.lua|
-% \item |font-con.lua|
-% \item |font-def.lua|
-% \item |font-ini.lua|
-% \item |font-map.lua|
-% \item |font-ota.lua|
-% \item |font-otb.lua|
-% \item |font-otc.lua|
-% \item |font-otf.lua|
-% \item |font-oti.lua|
-% \item |font-otn.lua|
-% \item |node-inj.lua|
-% \item |luatex-fonts-cbk.lua|
-% \item |luatex-fonts-enc.lua|
-% \item |luatex-fonts-ext.lua|
-% \item |luatex-fonts-lua.lua|
-% \item |luatex-fonts-tfm.lua|
-% \item |luatex-basics-gen.lua|
-% \item |luatex-basics-nod.lua|
-% \item |font-age.lua|\footnote{Not renamed as it is loaded directly from
-% |fonts-enc.lua|.}
-% \end{itemize*}
-% \end{multicols}
+% will tell you that indeed the latter name is correct.
+%
+% \verb|mkluatexfontdb.lua --help| will list the available command line
+% switches, including some that will not be discussed in detail here.
+%
+% \subsection{Blacklisting fonts}
+% \label{font-blacklist}
+%
+% Some fonts are problematic in general, or just in \LUATEX.
+% If you find that compiling your document takes far too long or eats
+% away all your system’s memory, you can track down the culprit by
+% running \verb|mkluatexfontdb -v| to increase verbosity.
+% Take a note of the \emphasis{filename} of the font that database
+% creation fails with and append it to the file
+% \fileent{otfl-blacklist.cnf}.
+%
+% A blacklist file is a list of font filenames, one per line.
+% Specifying the full path where the file is located is optional, the
+% plain filename should suffice.
+% File extensions (\fileent{.otf}, \fileent{.ttf}, etc.) may be omitted.
+% Anything after a percent (|%|) character until the end of the line
+% is ignored, so use this to add comments.
+% Place this file to some location where the \identifier{kpse}
+% library can find it, e.~g.
+% \fileent{texmf-local/tex/luatex/luaotfload} if you are running
+% \identifier{\TEX Live},\footnote{%
+% You may have to run \verb|mktexlsr| if you created a new file in
+% your \fileent{texmf} tree.
+% }
+% or just leave it in the working directory of your document.
+% \identifier{luaotfload} reads all files named
+% \fileent{otfl-blacklist.cnf} it finds, so the fonts in
+% \fileent{./otfl-blacklist.cnf} extend the global blacklist.
+%
+% Furthermore, a filename prepended with a dash character (|-|) is
+% removed from the blacklist, causing it to be temporarily whitelisted
+% without modifying the global file.
+% An example with explicit paths:
+%
+% \begin{verbatim}
+% % example otf-blacklist.cnf
+% /Library/Fonts/GillSans.ttc % Luaotfload ignores this font.
+% -/Library/Fonts/Optima.ttc % This one is usable again, even if
+% % blacklisted somewhere else.
+% \end{verbatim}
%
-% The following files have been written for this package:
-% \begin{itemize*}
-% \item |otfl-font-clr.lua|
-% \item |otfl-font-nms.lua|
-% \item |otfl-luat-ovr.lua|
-% \item |otfl-font-ltx.lua|\footnote{A heavily modified version of
-% |luatex-fonts-def.lua|.}
-% \end{itemize*}
+% \section{Files from \CONTEXT and \LUATEX-Fonts}
+%
+% This package relies on code originally written by Hans
+% Hagen\footnote{%
+% The creator of the \href{http://wiki.contextgarden.net}{\CONTEXT}
+% format.
+% }
+% for and tested with \CONTEXT.
+% \identifier{luaotfload} integrates the font loader as distributed in
+% the \identifier{\LUATEX-Fonts} package.
+% The original \LUA source files have been combined using the
+% \fileent{mtx-package} script into a single, self-contained blob.
+% In this form the font loader has no further dependencies\footnote{%
+% It covers, however, to some extent the functionality of the
+% \identifier{lualibs} package.
+% }
+% and requires only minor adaptions to integrate into
+% \identifier{luaotfload}.
+% The guiding principle is to let \CONTEXT/\LUATEX-Fonts take care of
+% the implementation, and update the imported code from time to time.
+% As maintainers, we aim at importing files from upstream essentially
+% \emphasis{unmodified}, except for renaming the files to prevent name
+% clashes.
+% This job has been greatly alleviated since the advent of
+% \LUATEX-Fonts, prior to which the individual dependencies had to be
+% manually spotted and extracted from the \CONTEXT source code in a
+% complicated and error-prone fashion.
+%
+% Below is a commented list of the files distributed with
+% \identifier{luaotfload} in one way or the other.
+% See figure \ref{file-graph} on page \pageref{file-graph} for a
+% graphical representation of the dependencies.
+% From \LUATEX-Fonts the following files have been imported:
+%
+% \begin{itemize}
+% \let\normalitem=\item
+% \def\fileitem#1#2{%
+% \normalitem{\fileent{#1}}%
+% \hfill
+% (as \fileent{\itshape#2})%
+% \break
+% }
+% \def\incitem#1{%
+% \normalitem{\fileent{#1}}
+% }
+% \fileitem{luatex-fonts.lua}{otfl-fonts.lua}
+% The wrapper that loads the font loader code.
+%
+% \fileitem{luatex-fonts-merged.lua}{otfl-fonts-merged.lua}
+% The font loader package.
+% It is generated by \fileent{mtx-package}, a \LUA
+% source code merging tool developed by Hans
+% Hagen.\footnote{%
+% \fileent{mtx-package} is
+% \href
+% {http://repo.or.cz/w/context.git/blob_plain/refs/heads/origin:/scripts/context/lua/mtx-package.lua}
+% {part of \CONTEXT}
+% and requires \fileent{mtxrun}.
+% Run
+% \verb|mtxrun --script package --help|
+% to display further information.
+% For the actual merging code see the file
+% \fileent{util-mrg.lua} that is part of \CONTEXT.
+% }
+%
+% Included are several Lua files that can be classed in three
+% categories.
+% \begin{itemize}
+% \normalitem \emphasis{\LUA utility libraries}, a subset
+% of what is provided by the \identifier{lualibs}
+% package.
+%
+% \begin{multicols}{2}
+% \begin{itemize}
+% \incitem{l-lua.lua} \incitem{l-lpeg.lua}
+% \incitem{l-function.lua} \incitem{l-string.lua}
+% \incitem{l-table.lua} \incitem{l-io.lua}
+% \incitem{l-file.lua} \incitem{l-boolean.lua}
+% \incitem{l-math.lua} \incitem{util-str.lua}
+% \end{itemize}
+% \end{multicols}
+%
+% \normalitem The \emphasis{Font Loader} itself.
+% These files have been written for
+% \LUATEX-Fonts and are distributed along with
+% \identifier{luaotfload}.
+% \begin{multicols}{2}
+% \begin{itemize}
+% \incitem{luatex-basics-gen.lua}
+% \incitem{luatex-basics-nod.lua}
+% \incitem{luatex-fonts-enc.lua}
+% \incitem{luatex-fonts-syn.lua}
+% \incitem{luatex-fonts-tfm.lua}
+% \incitem{luatex-fonts-chr.lua}
+% \incitem{luatex-fonts-lua.lua}
+% \incitem{luatex-fonts-def.lua}
+% \incitem{luatex-fonts-ext.lua}
+% \incitem{luatex-fonts-cbk.lua}
+% \end{itemize}
+% \end{multicols}
+%
+% \normalitem Code related to \emphasis{font handling and
+% node processing}, taken directly from
+% \CONTEXT.
+% \begin{multicols}{2}
+% \begin{itemize}
+% \incitem{data-con.lua} \incitem{font-ini.lua}
+% \incitem{font-con.lua} \incitem{font-cid.lua}
+% \incitem{font-map.lua} \incitem{font-oti.lua}
+% \incitem{font-otf.lua} \incitem{font-otb.lua}
+% \incitem{node-inj.lua} \incitem{font-ota.lua}
+% \incitem{font-otn.lua} \incitem{font-def.lua}
+% \end{itemize}
+% \end{multicols}
+% \end{itemize}
+%
+% \end{itemize}
+%
+% In addition to these, \identifier{luaotfload} requires a number of
+% files not contained in the merge. Some of these have no equivalent in
+% \LUATEX-Fonts or \CONTEXT, some were taken unmodified from the
+% latter.
+%
+% \begin{itemize}
+% \let\normalitem=\item
+% \def\ouritem#1{%
+% \normalitem{\fileent{#1}}%
+% \space--\hskip1em
+% }
+% \ouritem {otfl-font-otc.lua} \fileent{font-otc} from \CONTEXT;
+% font feature handling.
+% \ouritem {otfl-lib-dir.lua} \fileent{l-dir} from \CONTEXT;
+% contains functionality required
+% by \fileent{otfl-font-nms.lua}.
+% \ouritem {otfl-luat-ovr.lua} overrides for the \CONTEXT logging
+% functionality.
+% \ouritem {otfl-font-pfb.lua} registers the \identifier{OpenType}
+% font reader as handler for
+% Postscript fonts.
+% \ouritem {otfl-font-nms.lua} font database.
+% \ouritem {otfl-font-clr.lua} color handling.
+% \ouritem {otfl-font-ltx.lua} font feature handling.
+% \ouritem {otfl-features.lua} definitions of the \verb|anum| and
+% \verb|tlig| features.
+% \end{itemize}
+%
+% \begin{figure}[b]
+% \caption{Schematic of the Files in \identifier{Luaotfload}}
+% \includegraphics[width=\textheight,angle=90]{filegraph.pdf}
+% \label{file-graph}
+% \end{figure}
%
% \section{Troubleshooting}
%
% If you encounter problems with some fonts, please first update to the latest
-% version of this package before reporting a bug, as this package is under
-% active development.
+% version of this package before reporting a bug, as
+% \identifier{luaotfload} is under active development and still a
+% moving target.
+% Errors during database generation can be traced by increasing
+% verbosity levels and redirecting log output to \fileent{stdout}:
%
-% A very common problem is the lack of features for some OpenType fonts even
-% when specified. It can be related to the fact that some fonts do not provide
-% features for the |dflt| script, which is the default one in this package, so
-% you may have to specify the script in the command line, for example:
+% \begin{verbatim}
+% mkluatexfontdb.lua -F -vvv --log=stdout
+% \end{verbatim}
%
-% |\font\test=file:MyFont.otf:script=latn;+liga;|
+% If this fails, the font last printed to the terminal is likely to be
+% the culprit.
+% Please specify it when reporting a bug, and blacklist it for the time
+% being (see above, page \pageref{font-blacklist}).
+%
+% A common problem is the lack of features for some
+% \identifier{OpenType} fonts even when specified.
+% This can be related to the fact that some fonts do not provide
+% features for the |dflt| script (see above on page
+% \pageref{script-tag}),
+% which is the default one in this package.
+% If this happens, assigning a script when the font is defined should
+% fix it.
+% For example with the |latn| script:
%
-% \part{\texttt{luaotfload.lua}}
+% \begin{verbatim}
+% \font\test=file:MyFont.otf:script=latn;+liga;
+% \end{verbatim}
+%
+% \part{\fileent{luaotfload.lua}}
%
% \iffalse
%<*lua>
% \fi
-%
-% \section{Initializations}
-%
% \begin{macrocode}
module("luaotfload", package.seeall)
-% \end{macrocode}
-%
-% \begin{macrocode}
+
luaotfload.module = {
name = "luaotfload",
- version = 2.0,
- date = "2011/10/06",
+ version = 2.2,
+ date = "2013/04/15",
description = "OpenType layout system.",
author = "Elie Roux & Hans Hagen",
copyright = "Elie Roux",
license = "CC0"
}
+
+local luatexbase = luatexbase
+
+local type, next = type, next
+local stringfind = string.find
+local stringsub = string.sub
+local stringmatch = string.match
+local find_file = kpse.find_file
+
+local add_to_callback, create_callback =
+ luatexbase.add_to_callback, luatexbase.create_callback
+local reset_callback, call_callback =
+ luatexbase.reset_callback, luatexbase.call_callback
+
+local dummy_function = function () end
+
% \end{macrocode}
%
+% No final decision has been made on how to handle font definition. At
+% the moment, there are three candidates: The \identifier{generic}
+% callback as hard-coded in the font loader, the \identifier{old}
+% wrapper, and a simplified version of the latter (\identifier{patch})
+% that does nothing besides applying font patches.
+%
% \begin{macrocode}
-local error, warning, info, log = luatexbase.provides_module(luaotfload.module)
+luaotfload.font_definer = "patch" --- | “generic” | “old”
+
+local error, warning, info, log =
+ luatexbase.provides_module(luaotfload.module)
+
% \end{macrocode}
%
-% The minimal required \luatex version.
+% This is a necessary initalization in order not to rebuild an existing
+% font.
+% Maybe 600 should be replaced by \texmacro{pdfpkresolution} %% (why?)
+% or \luafunction{texconfig.pk_dpi} (and it should be replaced
+% dynamically), but we don't have access (yet) to the
+% \identifier{texconfig} table, so we let it be 600.
+% Anyway, it does still work fine even if \texmacro{pdfpkresolution} is
+% changed.
%
% \begin{macrocode}
-local luatex_version = 70
+
+kpse.init_prog("", 600, "/")
+
% \end{macrocode}
%
+% We set the minimum version requirement for \LUATEX to v0.74, as it was
+% the first version to include version 5.2 of the \LUA interpreter.
+%
% \begin{macrocode}
+
+local luatex_version = 74
+
if tex.luatexversion < luatex_version then
warning("LuaTeX v%.2f is old, v%.2f is recommended.",
tex.luatexversion/100,
luatex_version /100)
end
+
% \end{macrocode}
%
-% Some required functions missing from \textsf{lualibs} package.
+% \subsection{Module loading}
+%
+% We load the files imported from \CONTEXT with this function.
+% It automatically prepends the prefix \fileent{otfl-} to its argument,
+% so we can refer to the files with their actual \CONTEXT name.
%
% \begin{macrocode}
-function table.reversed(t)
- if t then
- local tt, tn = { }, #t
- if tn > 0 then
- local ttn = 0
- for i=tn,1,-1 do
- ttn = ttn + 1
- tt[ttn] = t[i]
- end
- end
- return tt
+
+local fl_prefix = "otfl" -- “luatex” for luatex-plain
+local loadmodule = function (name)
+ local tofind = fl_prefix .."-"..name
+ local found = find_file(tofind,"tex")
+ if found then
+ log("loading file %s.", found)
+ dofile(found)
+ else
+ error("file %s not found.", tofind)
end
end
+
% \end{macrocode}
%
+% Virtual fonts are resolved via a callback.
+% \luafunction{find_vf_file} derives the name of the virtual font file
+% from the filename.
+% (NB: \CONTEXT handles this likewise in \fileent{font-vf.lua}.)
+%
% \begin{macrocode}
-function table.derive(parent)
- local child = { }
- if parent then
- setmetatable(child,{ __index = parent })
+local Cs, P, lpegmatch = lpeg.Cs, lpeg.P, lpeg.match
+
+local p_dot, p_slash = P".", P"/"
+local p_suffix = (p_dot * (1 - p_dot - p_slash)^1 * P(-1)) / ""
+local p_removesuffix = Cs((p_suffix + 1)^1)
+
+local find_vf_file = function (name)
+ local fullname = find_file(name, "ovf")
+ if not fullname then
+ --fullname = find_file(file.removesuffix(name), "ovf")
+ fullname = find_file(lpegmatch(p_removesuffix, name), "ovf")
+ end
+ if fullname then
+ log("loading virtual font file %s.", fullname)
end
- return child
+ return fullname
end
+
+--[[-- keep --]]
+--- from Hans (all merged):
+
+--- file name modified include name
+--- × basics-gen.lua t luat-basics-gen
+--- × font-def -> fonts-def t luatex-font-def (there’s also the normal font-def!)
+--- × fonts-enc f luatex-font-enc
+--- × fonts-ext t luatex-fonts-ext
+--- × fonts-lua f luatex-fonts-lua
+--- fonts-tfm f luatex-fonts-tfm
+--- × fonts-cbk f luatex-fonts-lua
+
+--- from Hans (unmerged):
+--- font-otc.lua -> otfl-font-otc.lua
+
+--- from luaotfload:
+--- otfl-luat-ovr.lua -- override some luat-dum functions
+--- otfl-font-clr.lua
+--- otfl-font-ltx.lua
+--- otfl-font-nms.lua
+--- otfl-font-pfb.lua -- ?
+
+--[[-- new --]]
+--- basics-nod (merged as fonts-nod !)
+--- fonts-demo-vf-1.lua
+--- fonts-syn (merged)
+
+--[[-- merged, to be dropped --]]
+--- otfl-data-con.lua
+--- otfl-font-cid.lua
+--- otfl-font-con.lua
+--- otfl-font-ini.lua
+--- otfl-font-ota.lua
+--- otfl-font-otb.lua
+--- otfl-font-otf.lua
+--- otfl-font-oti.lua
+--- otfl-font-otn.lua
+
% \end{macrocode}
%
+%
+% \subsection{Preparing the Font Loader}
+% We treat the fontloader as a black box so behavior is consistent
+% between formats.
+% The wrapper file is \fileent{otfl-fonts.lua} which we imported from
+% \href{http://standalone.contextgarden.net/current/context/experimental/tex/generic/context/luatex/}{\LUATEX-Plain}.
+% It has roughly two purposes:
+%
+% \begin{enumerate}
+%
+% \item insert the functionality required for fontloader; and
+%
+% \item put it in place via the respective callbacks.
+%
+% \end{enumerate}
+%
+% How the first step is executed depends on the presence on the
+% \emphasis{merged font loader code}.
+% In \identifier{luaotfload} this is contained in the file
+% \fileent{otfl-fonts-merged.lua}.
+% If this file cannot be found, the original libraries from \CONTEXT of
+% which the merged code was composed are loaded instead.
+%
+% Hans provides two global tables to control the font loader:
+%
+% \begin{itemize}
+% \item \luafunction{generic_context}:
+% encapsulation mechanism, callback functions
+% \item \luafunction{non generic_context}:
+% customized code insertion
+% \end{itemize}
+%
+% With \luafunction{non_generic_context} we can tailor the font loader
+% insertion to our file naming habits (key \luafunction{load_before}).
+% Additionally, \luafunction{skip_loading} can be unset to force loading
+% of the original libraries as though the merged code was absent.
+% Another key, \luafunction{load_after} is called at the time when the
+% font loader is actually inserted.
+% In combination with the option \luafunction{no_callbacks_yet} in
+% \luafunction{generic_context}, we can insert our own,
+% \identifier{luatexbase}-style callback handling here.
+%
% \begin{macrocode}
-function string.quoted(str)
- return string.format("%q",str)
-end
+if not _G. generic_context then _G. generic_context = { } end
+if not _G.non_generic_context then _G.non_generic_context = { } end
+
+local generic_context = generic_context
+local non_generic_context =non_generic_context
+
+generic_context.no_callbacks_yet = true
+
+_G.non_generic_context = { luatex_fonts = {
+ load_before = "otfl-fonts-merged.lua",
+ -- load_after = nil, --- TODO, this is meant for callbacks
+ skip_loading = true,
+}}
+
% \end{macrocode}
%
-% \section{Module loading}
+% The imported font loader will call \luafunction{callback.register} once
+% while reading \fileent{font-def.lua}.
+% This is unavoidable unless we modify the imported files, but harmless
+% if we make it call a dummy instead.
%
% \begin{macrocode}
-require('otfl-basics-gen.lua')
-require('otfl-luat-ovr.lua') -- overrides some otfl-basics-gen.lua functions
-require('otfl-data-con.lua')
-require('otfl-basics-nod.lua')
+
+local trapped_register = callback.register
+callback.register = dummy_function
+
% \end{macrocode}
%
-% By default \context takes some private attributes for internal use. To
-% avoide attribute clashes with other packages, we override the function
-% that allocates new attributes, making it a wraper around
-% |luatexbase.new_attribute()|. We also prefix attributes with |otfl@| to
-% avoid possiple name clashes.
+% Now that things are sorted out we can finally load the fontloader.
%
% \begin{macrocode}
-function attributes.private(name)
- local attr = "otfl@" .. name
- local number = luatexbase.attributes[attr]
- if not number then
- number = luatexbase.new_attribute(attr)
+
+loadmodule"fonts.lua"
+
+% \end{macrocode}
+%
+% By default, the fontloader requires a number of \emphasis{private
+% attributes} for internal use.
+% These must be kept consistent with the attribute handling methods as
+% provided by \identifier{luatexbase}.
+% Our strategy is to override the function that allocates new attributes
+% before we initialize the font loader, making it a wrapper around
+% \luafunction{luatexbase.new_attribute}.\footnote{%
+% Many thanks, again, to Hans Hagen for making this part
+% configurable!
+% }
+% The attribute identifiers are prefixed “\fileent{otfl@}” to
+% avoid name clashes.
+%
+% \begin{macrocode}
+
+do
+ local new_attribute = luatexbase.new_attribute
+ local the_attributes = luatexbase.attributes
+
+ _G.attributes = _G.attributes or { }
+
+ _G.attributes.private = function (name)
+ local attr = "otfl@" .. name
+ local number = the_attributes[attr]
+ if not number then
+ number = new_attribute(attr)
+ end
+ return number
end
- return number
end
+
% \end{macrocode}
%
+%
+% \subsection{Callbacks}
+%
+% After the fontloader is ready we can restore the callback trap from
+% \identifier{luatexbase}.
+%
% \begin{macrocode}
-require('otfl-font-ini.lua')
-require('otfl-font-con.lua')
-require('otfl-fonts-enc.lua')
-require('otfl-font-cid.lua')
-require('otfl-font-map.lua')
-require('otfl-font-nms.lua')
-require('otfl-fonts-tfm.lua')
-require('otfl-font-oti.lua')
-require('otfl-font-otf.lua')
-require('otfl-font-pfb.lua')
-require('otfl-font-otb.lua')
-require('otfl-node-inj.lua')
-require('otfl-font-otn.lua')
-require('otfl-font-ota.lua')
-require('otfl-font-otc.lua')
-require('otfl-fonts-lua.lua')
-require('otfl-font-def.lua')
-require('otfl-font-ltx.lua')
-require('otfl-fonts-ext.lua')
-require('otfl-fonts-cbk.lua')
-require('otfl-font-clr.lua')
+
+callback.register = trapped_register
+
% \end{macrocode}
%
-% Here we override some defaults set in \context code.
+% We do our own callback handling with the means provided by luatexbase.
+%
+% Note: \luafunction{pre_linebreak_filter} and \luafunction{hpack_filter}
+% are coupled in \CONTEXT in the concept of \emphasis{node processor}.
%
% \begin{macrocode}
-fonts.mode = "node"
-caches.compilemethod = "both"
+
+add_to_callback("pre_linebreak_filter",
+ generic_context.callback_pre_linebreak_filter,
+ "luaotfload.node_processor",
+ 1)
+add_to_callback("hpack_filter",
+ generic_context.callback_hpack_filter,
+ "luaotfload.node_processor",
+ 1)
+add_to_callback("find_vf_file",
+ find_vf_file, "luaotfload.find_vf_file")
+
+loadmodule"font-otc.lua" -- TODO check what we can drop from otfl-features
+loadmodule"lib-dir.lua" -- required by font-nms
+loadmodule"luat-ovr.lua"
+
+if fonts and fonts.readers.tfm then
+ --------------------------------------------------------------------
+ --- OFM; read this first
+ --------------------------------------------------------------------
+ --- I can’t quite make out whether this is still relevant
+ --- as those ofm fonts always fail, even in the 2011 version
+ --- (mktexpk: don't know how to create bitmap font for omarabb.ofm)
+ --- the font loader appears to read ofm like tfm so if this
+ --- hack was supposed achieve that, we should excise it anyways
+ fonts.readers.ofm = fonts.readers.tfm
+ fonts.handlers.ofm = fonts.handlers.tfm --- empty anyways
+ fonts.formats.ofm = fonts.formats.tfm --- “type1”
+ --- fonts.readers.sequence[#fonts.readers.sequence+1] = "ofm"
+ --------------------------------------------------------------------
+end
+
% \end{macrocode}
%
-% Now overriding the \context's definition of |tlig| and |trep| features,
-% using code points instead of glyph names to make it font independent.
+%
+% Now we load the modules written for \identifier{luaotfload}.
%
% \begin{macrocode}
-local everywhere = { ["*"] = { ["*"] = true } }
-
-local tlig = {
- {
- type = "substitution",
- features = everywhere,
- data = {
- [0x0022] = 0x201D, -- quotedblright
- [0x0027] = 0x2019, -- quoteleft
- [0x0060] = 0x2018, -- quoteright
- },
- flags = { },
- },
- {
- type = "ligature",
- features = everywhere,
- data = {
- [0x2013] = {0x002D, 0x002D}, -- endash
- [0x2014] = {0x002D, 0x002D, 0x002D}, -- emdash
- [0x201C] = {0x2018, 0x2018}, -- quotedblleft
- [0x201D] = {0x2019, 0x2019}, -- quotedblright
- [0x201E] = {0x002C, 0x002C}, -- quotedblbase
- [0x00A1] = {0x0021, 0x2018}, -- exclamdown
- [0x00BF] = {0x003F, 0x2018}, -- questiondown
- },
- flags = { },
- },
- {
- type = "ligature",
- features = everywhere,
- data = {
- [0x201C] = {0x0060, 0x0060}, -- quotedblleft
- [0x201D] = {0x0027, 0x0027}, -- quotedblright
- [0x00A1] = {0x0021, 0x0060}, -- exclamdown
- [0x00BF] = {0x003F, 0x0060}, -- questiondown
- },
- flags = { },
- },
-}
+loadmodule"font-pfb.lua" --- new in 2.0, added 2011
+loadmodule"font-nms.lua"
+loadmodule"font-clr.lua"
+loadmodule"font-ltx.lua" --- new in 2.0, added 2011
-fonts.handlers.otf.addfeature("tlig", tlig)
-fonts.handlers.otf.addfeature("trep", { }) -- empty, all in tlig now
% \end{macrocode}
%
-% And overriding the \context's definition of |anum|.
+%
+% We create a callback for patching fonts on the fly, to be used by other
+% packages.
+% It initially contains the empty function that we are going to override
+% below.
%
% \begin{macrocode}
-local anum_arabic = {
- [0x0030] = 0x0660,
- [0x0031] = 0x0661,
- [0x0032] = 0x0662,
- [0x0033] = 0x0663,
- [0x0034] = 0x0664,
- [0x0035] = 0x0665,
- [0x0036] = 0x0666,
- [0x0037] = 0x0667,
- [0x0038] = 0x0668,
- [0x0039] = 0x0669,
-}
-local anum_persian = {
- [0x0030] = 0x06F0,
- [0x0031] = 0x06F1,
- [0x0032] = 0x06F2,
- [0x0033] = 0x06F3,
- [0x0034] = 0x06F4,
- [0x0035] = 0x06F5,
- [0x0036] = 0x06F6,
- [0x0037] = 0x06F7,
- [0x0038] = 0x06F8,
- [0x0039] = 0x06F9,
-}
+create_callback("luaotfload.patch_font", "simple", dummy_function)
-local function valid(data)
- local features = data.resources.features
- if features then
- for k, v in next, features do
- for k, v in next, v do
- if v.arab then
- return true
+% \end{macrocode}
+%
+%
+% This is a wrapper for the imported font loader.
+% As of 2013, everything it does appear to be redundand, so we won’t use
+% it unless somebody points out a cogent reason.
+% Nevertheless, it has been adapted to work with the current structure of
+% font data objects and will stay here for reference / until breakage is
+% reported.
+%
+% \emphasis{TODO}
+% This one also enables patching fonts.
+% The current fontloader apparently comes with a dedicated mechanism for
+% that already: enhancers.
+% How those work remains to be figured out.
+%
+% \begin{macrocode}
+local define_font_wrapper = function (...)
+ --- we use “tfmdata” (not “fontdata”) for consistency with the
+ --- font loader
+ local tfmdata = fonts.definers.read(...)
+ if type(tfmdata) == "table" and tfmdata.shared then
+ local metadata = tfmdata.shared.rawdata.metadata
+ local mathdata = metadata.math --- do all fonts have this field?
+ if mathdata then
+ local mathconstants = { } --- why new hash, not modify in place?
+ local units_per_em = metadata.units_per_em
+ local size = tfmdata.size
+ for k,v in next, mathdata do
+ --- afaics this is alread taken care of by
+ --- definers.read
+ if stringfind(k, "Percent") then
+ -- keep percent values as is
+ print(k,v)
+ mathconstants[k] = v
+ else
+ mathconstants[k] = v / units_per_em * size
end
end
+ --- for \overwithdelims
+ --- done by definers.read as well
+ mathconstants.FractionDelimiterSize = 1.01 * size
+ --- fontloader has 2.4 × size
+ mathconstants.FractionDelimiterDisplayStyleSize = 2.39 * size
+ tfmdata.MathConstants = mathconstants
end
+ call_callback("luaotfload.patch_font", tfmdata)
end
+ return tfmdata
end
-local anum_specification = {
- {
- type = "substitution",
- features = { arab = { far = true, urd = true, snd = true } },
- data = anum_persian,
- flags = { },
- valid = valid,
- },
- {
- type = "substitution",
- features = { arab = { ["*"] = true } },
- data = anum_arabic,
- flags = { },
- valid = valid,
- },
-}
-
-fonts.handlers.otf.addfeature("anum",anum_specification)
% \end{macrocode}
%
-% we provide a callback for patching fonts on the fly, to be used by other
-% packages.
%
-% \begin{macrocode}
-luatexbase.create_callback("luaotfload.patch_font", "simple", function() end)
-% \end{macrocode}
+% \subsection{\CONTEXT override}
+%
+% We provide a simplified version of the original font definition
+% callback.
%
% \begin{macrocode}
-local function deffont(...)
- local fontdata = fonts.definers.read(...)
- if type(fontdata) == "table" then
- luatexbase.call_callback("luaotfload.patch_font", fontdata)
+
+local read_font_file = fonts.definers.read
+local patch_defined_font = function (...)
+ local tfmdata = read_font_file(...)-- spec -> size -> id -> tmfdata
+ if type(tfmdata) == "table" then
+ call_callback("luaotfload.patch_font", tfmdata)
end
- return fontdata
+ return tfmdata
end
+
+caches.compilemethod = "both"
+
+reset_callback("define_font")
+
% \end{macrocode}
%
% Finally we register the callbacks
%
% \begin{macrocode}
-local handler = nodes.simple_font_handler
-luatexbase.reset_callback("define_font")
-luatexbase.add_to_callback("pre_linebreak_filter", handler, "luaotfload")
-luatexbase.add_to_callback("hpack_filter", handler, "luaotfload")
-luatexbase.add_to_callback("define_font", deffont, "luaotfload")
+
+if luaotfload.font_definer == "old" then
+ add_to_callback("define_font",
+ define_font_wrapper,
+ "luaotfload.define_font",
+ 1)
+elseif luaotfload.font_definer == "generic" then
+ add_to_callback("define_font",
+ generic_context.callback_define_font,
+ "luaotfload.define_font",
+ 1)
+elseif luaotfload.font_definer == "patch" then
+ add_to_callback("define_font",
+ patch_defined_font,
+ "luaotfload.define_font",
+ 1)
+end
+
+--[[todo--
+--- The manual promises coercion of the file: lookup if
+--- the asked name is enclosed in brackets.
+--- A couple things make me doubt that this is the case:
+---
+--- 1) there doesn’t appear to be code for these cases
+--- 2) the brackets remain part of the file name
+--- 3) we still get calls to names.resolve which
+--- ignores the “lookup” field of the spec it gets
+---
+--- For this reason here is some code that a) coerces
+--- file: lookups in these cases and b) strips the brackets
+--- from the file name. As we *still* get name: lookups even
+--- though this code is active I’ll just leave it here
+--- for reference, ineffective as it is.
+do
+ local getspecification, makespecification =
+ fonts.definers.getspecification, fonts.definers.makespecification
+
+ local analyze = function (specification, size)
+ local lookup, name, sub, method, detail = getspecification(specification or "")
+ local filename = stringmatch(name, "^%[(.*)%]$")
+ if filename then
+ lookup = "file" --> coerce file:
+ name = filename --> remove brackets
+ end
+ return makespecification(specification, lookup, name, sub, method, detail, size)
+ end
+ fonts.definers.analyze = analyze
+end
+--]]--
+
+loadmodule"features.lua"
+
+-- vim:tw=71:sw=4:ts=4:expandtab
+
% \end{macrocode}
%
% \iffalse
%</lua>
% \fi
%
-% \part{\texttt{luaotfload.sty}}
+% \part{\fileent{luaotfload.sty}}
%
% \iffalse
%<*package>
% \fi
%
-% Classical Plain+\latex package initialization.
+% Classical Plain+\LATEX package initialization.
%
% \begin{macrocode}
\csname ifluaotfloadloaded\endcsname
\let\ifluaotfloadloaded\endinput
-% \end{macrocode}
-%
-% \begin{macrocode}
\bgroup\expandafter\expandafter\expandafter\egroup
\expandafter\ifx\csname ProvidesPackage\endcsname\relax
\input luatexbase.sty
\else
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luaotfload}%
- [2011/10/06 v2.0 OpenType layout system]
+ [2013/04/16 v2.2 OpenType layout system]
\RequirePackage{luatexbase}
\fi
-% \end{macrocode}
-%
-% \begin{macrocode}
-\RequireLuaModule{lualibs}
-% \end{macrocode}
-%
-% \begin{macrocode}
\RequireLuaModule{luaotfload}
+\endinput
% \end{macrocode}
% \iffalse
%</package>