summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <phg42.2a@gmail.com>2014-03-21 08:11:00 +0100
committerPhilipp Gesang <phg42.2a@gmail.com>2014-03-21 08:11:00 +0100
commitd5d47a03f73afd6b1743636b20f4064b0643ba20 (patch)
tree7b7beace788147993e07676a84d92b79467e0d6f
parente27ccb9092cd4f95c8572c9115f50f88a2d42d9e (diff)
parent95cdecde2d3415604cd8194eacd11544fe985aeb (diff)
downloadluaotfload-d5d47a03f73afd6b1743636b20f4064b0643ba20.tar.gz
Merge pull request #207 from phi-gamma/texlive2014
separate the collecting of font files from the scanning pass
-rw-r--r--.gitignore19
-rw-r--r--doc/luaotfload-context.tex38
-rw-r--r--doc/luaotfload-latex.tex124
-rw-r--r--doc/luaotfload-main.tex329
-rw-r--r--src/luaotfload-database.lua294
5 files changed, 463 insertions, 341 deletions
diff --git a/.gitignore b/.gitignore
index 850a861..d9cba93 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,5 +39,22 @@ tests/*.ovf
tests/*.sty
tests/luaotfload*
-# temporary directory
+# temporary directories
+build/*
+testing/*
+tests/*
tmp/*
+
+# tex side-effects
+doc/*.aux
+doc/*.log
+doc/*.out
+doc/*.pdf
+doc/*.tmp
+doc/*.toc
+doc/*.tuc
+doc/*.vimout
+
+# valgrind log
+src/*.log
+
diff --git a/doc/luaotfload-context.tex b/doc/luaotfload-context.tex
index aeca7cb..6c8d4b2 100644
--- a/doc/luaotfload-context.tex
+++ b/doc/luaotfload-context.tex
@@ -83,8 +83,8 @@
\definefontfeature [monospace] [liga=no,tlig=no,onum=no]
\definefontfamily [mainface] [serif] [Linux Libertine O] [features=default]
-%\definefontfamily [mainface] [serif] [Liberation Serif] [feature=default]
-%\definefontfamily [mainface] [sans] [Iwona] [feature=default]
+%definefontfamily [mainface] [serif] [Liberation Serif] [feature=default]
+%definefontfamily [mainface] [sans] [Iwona] [feature=default]
\definefontfamily [mainface] [sans] [Iwona Medium] [
feature=default,
it=file:IwonaMedium-Italic.otf,
@@ -128,7 +128,9 @@
\definetype [luafunction] [style=typing:luafunction]
\setuptyping [style=ttx]
-\definebodyfontenvironment [8pt]
+\definebodyfontenvironment [8pt]
+\definebodyfontenvironment [10pt]
+\definebodyfontenvironment [12pt]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% headings
@@ -196,7 +198,26 @@
%% Context offers both \type{…} and \type<<…>>, but not an unbalanced
%% one that we could map directly onto Latex’s \verb|…|.
-\definetype [inlinecode] [style=emphasis:nonproportional]
+\definetype [inlinecode_indeed] [style=emphasis:nonproportional]
+
+%% The listings macros don’t seem to handle backslashes and braces
+%% well. We emulate this behavior by handling the escaping in Lua.
+
+\startluacode
+ local lpeg = require "lpeg"
+ local Cs, P, S = lpeg.Cs, lpeg.P, lpeg.S
+ local lpegmatch = lpeg.match
+ local unescape_char = S[[\letterbackslash\letterleftbrace\letterrightbrace]]
+ local backslash = P[[\letterbackslash]]
+ local unescape = Cs (((backslash / "" * unescape_char) + 1)^0)
+ commands.unescape_things = function (str)
+ context.type (lpegmatch (unescape, str))
+ end
+\stopluacode
+
+\unexpanded \def \inlinecode #content{%
+ \ctxcommand {unescape_things \!!bs \detokenize {#content}\!!es}%
+}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% codelistings
@@ -209,6 +230,7 @@
\unexpanded \def \endlisting {\typebuffer [listing]}
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% enumerations and lists
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -308,7 +330,13 @@
%% special elements
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\def \meta #1{<{\italic #1}>}
+\definefont [lmromantenregular] [file:lmroman10-regular.otf*default]
+
+\def \meta #1{%
+ {\lmromantenregular<}%
+ {\italic #1}%
+ {\lmromantenregular>}%
+}
\def \beginabstractcontent {%
\grabbufferdatadirect{abstractcontent}{beginabstractcontent}{endabstractcontent}%
diff --git a/doc/luaotfload-latex.tex b/doc/luaotfload-latex.tex
index 3045c26..409adcf 100644
--- a/doc/luaotfload-latex.tex
+++ b/doc/luaotfload-latex.tex
@@ -79,26 +79,64 @@
\newcommand\CONTEXT {Con\TeX t\xspace}
\newcommand\OpenType {\identifier{Open\kern-.25ex Type}\xspace}
-\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}
+%% \groupedcommand, with some omissions taken from syst-aux.mkiv
+\let \handlegroupnormalbefore \relax
+\let \handlegroupnormalafter \relax
+
+\protected \def \handlegroupnormal #1#2{%
+ \bgroup % 1
+ \def \handlegroupbefore {#1}%
+ \def \handlegroupafter {#2}%
+ \afterassignment \handlegroupnormalbefore
+ \let \next =
+}
+
+\def \handlegroupnormalbefore {%
+ \bgroup % 2
+ \handlegroupbefore
+ \bgroup % 3
+ \aftergroup \handlegroupnormalafter%
+}
+
+\def \handlegroupnormalafter {%
+ \handlegroupafter
+ \egroup % 3
+ \egroup % 2
+}
+
+\let \groupedcommand \handlegroupnormal %% only the two arg version
+
+\def \definehighlight [#1][#2]{%
+ \ifcsname #1\endcsname\else
+ \expandafter\def\csname #1\endcsname{%
+ \leavevmode
+ \groupedcommand {#2}\empty%
+ }
+ \fi%
+}
+
+%% old, simplistic definition: obsolete now that we have
+%% \groupedcommand
+%\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}
\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
+\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
-\definehighlight [Largefont][\Large] %% font size
-\definehighlight [smallcaps][\sc] %% font feature
-\definehighlight [proportional][\tt] %% font switch
+\definehighlight [Largefont][\Large] %% font size
+\definehighlight [smallcaps][\sc] %% font feature
+\definehighlight [nonproportional][\tt] %% font switch
\newcommand*\email[1]{\href{mailto:#1}{#1}}
@@ -170,6 +208,7 @@
\usepackage {listings}
\lstset {
basicstyle=\ttfamily,
+ escapechar=Ö,
}
\def \inlinecode #1{%
@@ -245,8 +284,10 @@
\def \first {####1}%
#2
}
- \let \beginaltitem \altitem
- \let \endaltitem \relax
+ \let \beginnormalitem \item
+ \let \endnormalitem \relax
+ \let \beginaltitem \altitem
+ \let \endaltitem \relax
}
\expandafter \def \csname end#1\endcsname {%
@@ -280,6 +321,9 @@
%% special elements
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\let \beginfrontmatter \relax
+\let \endfrontmatter \relax
+
\def \beginabstractcontent {\begin {abstract}}
\def \endabstractcontent {\end {abstract}}
@@ -288,7 +332,9 @@
\let \setdocumentauthor \author
\let \typesetdocumenttitle \maketitle
-\let \typesetcontent \tableofcontent
+\AtBeginDocument {%% seriously?
+ \let \typesetcontent \tableofcontents%
+}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% floats
@@ -315,34 +361,22 @@
}
%% figures, e.g. the file graph
-\def \beginfigurefloat #1#2{%% #1:label #2:caption
- \begingroup
- \begin {figure} [b]
- \edef \figurelabel {#1}%
- \caption {#2}%
-}
-
-\def \endfigurefloat {%
- \label \figurelabel
- \end {figure}
- \endgroup
+\def \figurefloat #1#2#3{%% #1:label #2:caption #3:file
+ \begin {figure} [b]
+ \caption {#2}%
+ \includegraphics[width=\textwidth]{#3}%
+ \label {#1}
+ \end {figure}
}
%% tables
-
-\def \begintablefloat #1#2{%% #1:label #2:caption
- \begingroup
- \begin {table} [t]
- \hrule
- \edef \floatlabel {#1}%
- \caption {#2}%
-}
-
-\def \endtablefloat {%
- \label \floatlabel
- \hrule
- \end {table}
- \endgroup
+\def \tablefloat #1#2{%% #1:label #2:caption
+ \begin {table} [t]
+ \hrule
+ \caption {#2}%
+ \label {#1}
+ \hrule
+ \end {table}
}
@@ -402,6 +436,8 @@
\makeatother
+\newif \ifcontextmkiv \contextmkivfalse
+
\begin {document}
\input {luaotfload-main.tex}
\end {document}
diff --git a/doc/luaotfload-main.tex b/doc/luaotfload-main.tex
index 0e74aa9..5b033c0 100644
--- a/doc/luaotfload-main.tex
+++ b/doc/luaotfload-main.tex
@@ -1,16 +1,3 @@
-%\beginsection {foo}
- %bar baz
-%\endsection
-
-%\begindescriptions
-
- %\beginaltitem {mode} foo
- %%\identifier{luaotfload} has two \OpenType processing
- %%\emphasis{modes}:
-%\enddescriptions
-
-%\endinput
-
%% Copyright (C) 2009-2014
%%
%% by Elie Roux <elie.roux@telecom-bretagne.eu>
@@ -42,21 +29,25 @@
%% ----------------------------------------------------------------------------
%%
-\setdocumenttitle {The \identifier{luaotfload} package}
-\setdocumentdate {2014/**/** v2.5}
-\setdocumentauthor {Elie Roux · Khaled Hosny · Philipp Gesang\\
- Home: \hyperlink {https://github.com/lualatex/luaotfload}\\
- Support: \email {lualatex-dev@tug.org}}
+\beginfrontmatter
-\typesetdocumenttitle
+ \setdocumenttitle {The \identifier{luaotfload} package}
+ \setdocumentdate {2014/**/** v2.5}
+ \setdocumentauthor {Elie Roux · Khaled Hosny · Philipp Gesang\\
+ Home: \hyperlink {https://github.com/lualatex/luaotfload}\\
+ Support: \email {lualatex-dev@tug.org}}
-\beginabstractcontent
- This package is an adaptation of the \CONTEXT font loading system.
- It allows for loading \OpenType fonts with an extended syntax and adds
- support for a variety of font features.
-\endabstractcontent
+ \typesetdocumenttitle
-\tableofcontents
+ \beginabstractcontent
+ This package is an adaptation of the \CONTEXT font loading system.
+ It allows for loading \OpenType fonts with an extended syntax and adds
+ support for a variety of font features.
+ \endabstractcontent
+
+\endfrontmatter
+
+\typesetcontent
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\beginsection {Introduction}
@@ -140,10 +131,10 @@ in the task and willingness to respond to our suggestions.
\identifier{luaotfload} supports an extended font request syntax:
\beginnarrower
- \inlinecode{\\font\\foo=\{}%
- \meta{prefix}\inlinecode{:}%
- \meta{font name}\inlinecode{:}%
- \meta{font features}\inlinecode{\}}%
+ \nonproportional{\string\font\string\foo\space= \string{}%
+ \meta{prefix}\nonproportional{:}%
+ \meta{font name}\nonproportional{:}%
+ \meta{font features}\nonproportional{\string}}%
\meta{\TEX font features}
\endnarrower
@@ -165,18 +156,18 @@ for a more formal description see figure \ref{font-syntax}.
In addition to the font style modifiers
(\emphasis{slash-notation}) given above, there
are others that are recognized but will be silently
- ignored: {\ttfamily aat},
- {\ttfamily icu}, and
- {\ttfamily gr}.
+ ignored: \nonproportional{aat},
+ \nonproportional{icu}, and
+ \nonproportional{gr}.
The special terminals are:
- {\sc feature\textunderscore id} for a valid font
+ \smallcaps {feature\textunderscore id} for a valid font
feature name and
- {\sc feature\textunderscore value} for the corresponding
+ \smallcaps {feature\textunderscore value} for the corresponding
value.
- {\sc tfmname} is the name of a \abbrev{tfm} file.
- {\sc digit} again refers to bytes 48--57, and
- {\sc all\textunderscore characters} to all byte values.
- {\sc csname} and {\sc dimension} are the \TEX concepts.}
+ \smallcaps {tfmname} is the name of a \abbrev{tfm} file.
+ \smallcaps {digit} again refers to bytes 48--57, and
+ \smallcaps {all\textunderscore characters} to all byte values.
+ \smallcaps {csname} and \smallcaps {dimension} are the \TEX concepts.}
%
<definition> ::= `\\font', {\sc csname}, `=', <font request>, [ <size> ] ;
@@ -223,7 +214,11 @@ In \identifier{luaotfload}, the canonical syntax for font requests
requires a \emphasis{prefix}:
%
\beginnarrower
- \inlinecode{\\font\\fontname=}\meta{prefix}\inlinecode{:}\meta{fontname}\dots
+ \nonproportional{\string\font\string\fontname\space= }%
+ \meta{prefix}%
+ \nonproportional{:}%
+ \meta{fontname}%
+ \dots
\endnarrower
%
where \meta{prefix} is either \inlinecode{file:} or \inlinecode {name:}.\footnote{%
@@ -318,7 +313,9 @@ There are again two modes: bracketed and unbracketed.
A bracketed request looks as follows.
\beginnarrower
- \inlinecode{\\font\\fontname=[}\meta{path to file}\inlinecode{]}
+ \nonproportional{\string\font\string\fontname\space = [}%
+ \meta{/path/to/file}%
+ \nonproportional{]}
\endnarrower
\noindent
@@ -329,7 +326,9 @@ Naturally, path-less file names are equally valid and processed the
same way as an ordinary \inlinecode {file:} lookup.
\beginnarrower
- \inlinecode{\\font\\fontname=}\meta{font name} \dots
+ \nonproportional{\string\font\string\fontname\space= }%
+ \meta{font name}
+ \dots
\endnarrower
Unbracketed (or, for lack of a better word: \emphasis{anonymous})
@@ -347,7 +346,11 @@ Furthermore, \identifier{luaotfload} supports the slashed (shorthand)
font style notation from \XETEX.
\beginnarrower
- \inlinecode{\\font\\fontname=}\meta{font name}\inlinecode{/}\meta{modifier}\dots
+ \nonproportional{\string\font\string\fontname\space= }%
+ \meta{font name}%
+ \nonproportional{/}%
+ \meta{modifier}
+ \dots
\endnarrower
\noindent
@@ -470,11 +473,14 @@ which is equivalent to these full names:
general scheme for font requests:
\beginnarrower
- \inlinecode{\\font\\foo=\{}%
- \meta{prefix}\inlinecode{:}%
- \meta{font name}\inlinecode{:}%
- \meta{font features}\inlinecode{\}}%
- \meta{\TEX font features}
+ \nonproportional{\string\font\string\foo\space= "}%
+ \meta{prefix}%
+ \nonproportional{:}%
+ \meta{font name}%
+ \nonproportional{:}%
+ \meta{font features}%
+ \meta{\TEX font features}%
+ \nonproportional{"}
\endnarrower
\noindent
@@ -680,6 +686,12 @@ obviously, \inlinecode{random}.
user.
\endaltitem
+\ifcontextmkiv
+ \startbuffer [printvectors]
+ \directlua{inspect(fonts.protrusions.setups.default)
+ inspect(fonts.expansions.setups.default)}
+ \stopbuffer
+\fi
\beginaltitem {protrusion \& expansion}
These keys control microtypographic features of the font,
@@ -694,10 +706,14 @@ obviously, \inlinecode{random}.
%
Alternatively and with loss of information, you can dump
those tables into your terminal by issuing
- \beginlisting
-\directlua{inspect(fonts.protrusions.setups.default)
- inspect(fonts.expansions.setups.default)}
- \endlisting
+ \unless \ifcontextmkiv
+ \beginlisting
+ \directlua{inspect(fonts.protrusions.setups.default)
+ inspect(fonts.expansions.setups.default)}
+ \endlisting
+ \else
+ \typebuffer [printvectors]
+ \fi
at some point after loading \fileent{luaotfload.sty}.
}
%
@@ -740,13 +756,28 @@ Currently (2014) there are three of them:
\beginaltitem {tlig}
Applies legacy \TEX ligatures:
- \begintabulate [rlrl]
- \beginrow `` \newcell \inlinecode {``} \newcell '' \newcell \inlinecode {''} \endrow
- \beginrow ` \newcell \inlinecode {`} \newcell ' \newcell \inlinecode {'} \endrow
- \beginrow " \newcell \inlinecode {"} \newcell -- \newcell \inlinecode {--} \endrow
- \beginrow --- \newcell \inlinecode {---} \newcell !` \newcell \inlinecode {!`} \endrow
- \beginrow ?` \newcell \inlinecode {?`} \newcell \newcell \endrow
- \endtabulate
+ \unless \ifcontextmkiv
+ \begintabulate [rlrl]
+ \beginrow `` \newcell \inlinecode {``} \newcell '' \newcell \inlinecode {''} \endrow
+ \beginrow ` \newcell \inlinecode {`} \newcell ' \newcell \inlinecode {'} \endrow
+ \beginrow " \newcell \inlinecode {"} \newcell -- \newcell \inlinecode {--} \endrow
+ \beginrow --- \newcell \inlinecode {---} \newcell !` \newcell \inlinecode {!`} \endrow
+ \beginrow ?` \newcell \inlinecode {?`} \newcell \newcell \endrow
+ \endtabulate
+ \else
+ %% XXX find a way to wrap these in the tabulate environment
+ \startframed [frame=off,width=broad,align=middle]
+ \startframed [frame=off,width=\dimexpr(\textwidth/2)]
+ \startxtable [align=middle]
+ \startxrow \startxcell `` \stopxcell \startxcell \inlinecode {``} \stopxcell \startxcell '' \stopxcell \startxcell \inlinecode {''} \stopxcell \stopxrow
+ \startxrow \startxcell ` \stopxcell \startxcell \inlinecode {`} \stopxcell \startxcell ' \stopxcell \startxcell \inlinecode {'} \stopxcell \stopxrow
+ \startxrow \startxcell " \stopxcell \startxcell \inlinecode {"} \stopxcell \startxcell -- \stopxcell \startxcell \inlinecode {--} \stopxcell \stopxrow
+ \startxrow \startxcell --- \stopxcell \startxcell \inlinecode {---} \stopxcell \startxcell !` \stopxcell \startxcell \inlinecode {!`} \stopxcell \stopxrow
+ \startxrow \startxcell ?` \stopxcell \startxcell \inlinecode {?`} \stopxcell \startxcell \stopxcell \startxcell \stopxcell \stopxrow
+ \stopxtable
+ \stopframed
+ \stopframed
+ \fi
\footnote{%
These contain the feature set \inlinecode {trep} of earlier
@@ -873,26 +904,41 @@ Other paths can be specified by setting the environment variable
If it is non-empty, then search will be extended to the included
directories.
-\begintablefloat {table-searchpaths}
+\tablefloat {table-searchpaths}
{List of paths searched for each supported operating system.}
- \begincentered
- \begintabulate [lp{.5\textwidth}]
- \beginrow
- Windows \newcell \inlinecode {\% WINDIR\%\\ Fonts}
- \endrow
- \beginrow
- Linux \newcell \fileent{/usr/local/etc/fonts/fonts.conf} and\hfill\break
- \fileent{/etc/fonts/fonts.conf}
- \endrow
- \beginrow
- Mac \newcell \fileent{\textasciitilde/Library/Fonts},\break
- \fileent{/Library/Fonts},\break
- \fileent{/System/Library/Fonts}, and\hfill\break
- \fileent{/Network/Library/Fonts}
- \endrow
- \endtabulate
- \endcentered
-\endtablefloat
+ {%
+ \unless \ifcontextmkiv
+ \begincentered
+ \begintabulate [lp{.5\textwidth}]
+ \beginrow
+ Windows \newcell \inlinecode {\% WINDIR\%\\ Fonts}
+ \endrow
+ \beginrow
+ Linux \newcell \fileent{/usr/local/etc/fonts/fonts.conf} and\hfill\break
+ \fileent{/etc/fonts/fonts.conf}
+ \endrow
+ \beginrow
+ Mac \newcell \fileent{\textasciitilde/Library/Fonts},\break
+ \fileent{/Library/Fonts},\break
+ \fileent{/System/Library/Fonts}, and\hfill\break
+ \fileent{/Network/Library/Fonts}
+ \endrow
+ \endtabulate
+ \endcentered
+ \else
+ \setuplocalinterlinespace [14pt]
+ \starttabulate [|l|p(.5\textwidth)|]
+ \NC Windows \NC \inlinecode {\% WINDIR\%\\ Fonts} \NC \NR
+ \NC Linux \NC \fileent{/usr/local/etc/fonts/fonts.conf} and\crlf
+ \fileent{/etc/fonts/fonts.conf} \NC \NR
+ \NC
+ Mac \NC \fileent{\textasciitilde/Library/Fonts},\crlf
+ \fileent{/Library/Fonts},\break
+ \fileent{/System/Library/Fonts}, and\crlf
+ \fileent{/Network/Library/Fonts} \NC \NR
+ \stoptabulate
+ \fi%
+ }
\endsubsection
@@ -1016,7 +1062,7 @@ An example with explicit paths:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\identifier{luaotfload} relies on code originally written by Hans
-Hagen for the \hyperlink[\identifier\CONTEXT]{http://wiki.contextgarden.net}
+Hagen for the \hyperlink[\identifier{\CONTEXT}]{http://wiki.contextgarden.net}
format.
%
It integrates the font loader as distributed in
@@ -1067,64 +1113,70 @@ It houses several \LUA files that can be classed in three
categories.
\begindefinitions
- \normalitem \emphasis{\LUA utility libraries}, a subset
- of what is provided by the \identifier{lualibs}
- package.
-
- \begindoublecolumns
- \begindefinitions
- \beginaltitem {l-lua.lua} \endaltitem
- \beginaltitem {l-lpeg.lua} \endaltitem
- \beginaltitem {l-function.lua} \endaltitem
- \beginaltitem {l-string.lua} \endaltitem
- \beginaltitem {l-table.lua} \endaltitem
- \beginaltitem {l-io.lua} \endaltitem
- \beginaltitem {l-file.lua} \endaltitem
- \beginaltitem {l-boolean.lua} \endaltitem
- \beginaltitem {l-math.lua} \endaltitem
- \beginaltitem {util-str.lua} \endaltitem
- \enddefinitions
- \enddoublecolumns
-
- \normalitem The \emphasis{font loader} itself.
- These files have been written for
- \LUATEX-Fonts and they are distributed along
- with \identifier{luaotfload}.
- \begindoublecolumns
- \begindefinitions
- \beginaltitem{luatex-basics-gen.lua} \endaltitem
- \beginaltitem{luatex-basics-nod.lua} \endaltitem
- \beginaltitem{luatex-fonts-enc.lua} \endaltitem
- \beginaltitem{luatex-fonts-syn.lua} \endaltitem
- \beginaltitem{luatex-fonts-tfm.lua} \endaltitem
- \beginaltitem{luatex-fonts-chr.lua} \endaltitem
- \beginaltitem{luatex-fonts-lua.lua} \endaltitem
- \beginaltitem{luatex-fonts-inj.lua} \endaltitem
- \beginaltitem{luatex-fonts-otn.lua} \endaltitem
- \beginaltitem{luatex-fonts-def.lua} \endaltitem
- \beginaltitem{luatex-fonts-ext.lua} \endaltitem
- \beginaltitem{luatex-fonts-cbk.lua} \endaltitem
- \enddefinitions
- \enddoublecolumns
-
- \normalitem Code related to \emphasis{font handling and
- node processing}, taken directly from
- \CONTEXT.
- \begindoublecolumns
- \begindefinitions
- \beginaltitem{data-con.lua} \endaltitem
- \beginaltitem{font-ini.lua} \endaltitem
- \beginaltitem{font-con.lua} \endaltitem
- \beginaltitem{font-cid.lua} \endaltitem
- \beginaltitem{font-map.lua} \endaltitem
- \beginaltitem{font-oti.lua} \endaltitem
- \beginaltitem{font-otf.lua} \endaltitem
- \beginaltitem{font-otb.lua} \endaltitem
- \beginaltitem{font-ota.lua} \endaltitem
- \beginaltitem{font-def.lua} \endaltitem
- \beginaltitem{font-otp.lua} \endaltitem
- \enddefinitions
- \enddoublecolumns
+ \beginnormalitem
+ \emphasis{\LUA utility libraries}, a subset
+ of what is provided by the \identifier{lualibs}
+ package.
+
+ \begindoublecolumns
+ \begindefinitions
+ \beginaltitem {l-lua.lua} \endaltitem
+ \beginaltitem {l-lpeg.lua} \endaltitem
+ \beginaltitem {l-function.lua} \endaltitem
+ \beginaltitem {l-string.lua} \endaltitem
+ \beginaltitem {l-table.lua} \endaltitem
+ \beginaltitem {l-io.lua} \endaltitem
+ \beginaltitem {l-file.lua} \endaltitem
+ \beginaltitem {l-boolean.lua} \endaltitem
+ \beginaltitem {l-math.lua} \endaltitem
+ \beginaltitem {util-str.lua} \endaltitem
+ \enddefinitions
+ \enddoublecolumns
+ \endnormalitem
+
+ \beginnormalitem
+ The \emphasis{font loader} itself.
+ These files have been written for
+ \LUATEX-Fonts and they are distributed along
+ with \identifier{luaotfload}.
+ \begindoublecolumns
+ \begindefinitions
+ \beginaltitem{luatex-basics-gen.lua} \endaltitem
+ \beginaltitem{luatex-basics-nod.lua} \endaltitem
+ \beginaltitem{luatex-fonts-enc.lua} \endaltitem
+ \beginaltitem{luatex-fonts-syn.lua} \endaltitem
+ \beginaltitem{luatex-fonts-tfm.lua} \endaltitem
+ \beginaltitem{luatex-fonts-chr.lua} \endaltitem
+ \beginaltitem{luatex-fonts-lua.lua} \endaltitem
+ \beginaltitem{luatex-fonts-inj.lua} \endaltitem
+ \beginaltitem{luatex-fonts-otn.lua} \endaltitem
+ \beginaltitem{luatex-fonts-def.lua} \endaltitem
+ \beginaltitem{luatex-fonts-ext.lua} \endaltitem
+ \beginaltitem{luatex-fonts-cbk.lua} \endaltitem
+ \enddefinitions
+ \enddoublecolumns
+ \endnormalitem
+
+ \beginnormalitem
+ Code related to \emphasis{font handling and
+ node processing}, taken directly from
+ \CONTEXT.
+ \begindoublecolumns
+ \begindefinitions
+ \beginaltitem{data-con.lua} \endaltitem
+ \beginaltitem{font-ini.lua} \endaltitem
+ \beginaltitem{font-con.lua} \endaltitem
+ \beginaltitem{font-cid.lua} \endaltitem
+ \beginaltitem{font-map.lua} \endaltitem
+ \beginaltitem{font-oti.lua} \endaltitem
+ \beginaltitem{font-otf.lua} \endaltitem
+ \beginaltitem{font-otb.lua} \endaltitem
+ \beginaltitem{font-ota.lua} \endaltitem
+ \beginaltitem{font-def.lua} \endaltitem
+ \beginaltitem{font-otp.lua} \endaltitem
+ \enddefinitions
+ \enddoublecolumns
+ \endnormalitem
\enddefinitions
Note that if \identifier{luaotfload} cannot locate the
@@ -1184,11 +1236,10 @@ files not contained in the merge. Some of these have no equivalent in
\endaltitem
\endfilelist
-\beginfigurefloat
+\figurefloat
{file-graph}
{Schematic of the files in \identifier{Luaotfload}}
- \includegraphics[width=\textwidth]{filegraph.pdf}
-\endfigurefloat
+ {filegraph.pdf}
\endsection
diff --git a/src/luaotfload-database.lua b/src/luaotfload-database.lua
index 54738df..17cb4fd 100644
--- a/src/luaotfload-database.lua
+++ b/src/luaotfload-database.lua
@@ -560,7 +560,6 @@ local update_names
--- state of the database
local fonts_reloaded = false
-local fonts_read = 0
--- limit output when approximate font matching (luaotfload-tool -F)
local fuzzy_limit = 1 --- display closest only
@@ -2189,73 +2188,44 @@ local truncate_string = function (str, restrict)
return str
end
---[[doc--
- scan_dir() scans a directory and populates the list of fonts
- with all the fonts it finds.
+--[[doc--
- · dirname : name of the directory to scan
- · currentnames : current font db object
- · targetnames : font db object to fill
- · dry_run : don’t touch anything
+ collect_font_filenames_dir -- Traverse the directory root at
+ ``dirname`` looking for font files. Returns a list of {*filename*;
+ *location*} pairs.
--doc]]--
---- string -> dbobj -> dbobj -> bool -> bool -> (int * int)
-
-local scan_dir = function (dirname, currentnames, targetnames,
- dry_run, location)
+--- string -> string -> string * string list
+local collect_font_filenames_dir = function (dirname, location)
if lpegmatch (p_blacklist, dirname) then
report ("both", 4, "db",
"Skipping blacklisted directory %s.", dirname)
--- ignore
- return 0, 0
+ return { }
end
local found = find_font_files (dirname, location ~= "texmf" and location ~= "local")
if not found then
report ("both", 4, "db",
"No such directory: %q; skipping.", dirname)
- return 0, 0
+ return { }
end
- report ("both", 4, "db", "Scanning directory %s.", dirname)
- local n_new = 0 --- total of fonts collected
- local n_found = #found
- local max_fonts = luaotfloadconfig.max_fonts
-
- report ("both", 4, "db", "%d font files detected.", n_found)
- for j=1, n_found do
- if max_fonts and fonts_read >= max_fonts then
- break
- end
+ local nfound = #found
+ local files = { }
+ report ("both", 4, "db",
+ "%d font files detected in %s.",
+ nfound, dirname)
+ for j = 1, nfound do
local fullname = found[j]
- fullname = path_normalize(fullname)
- local new
-
- if dry_run == true then
- local truncated = truncate_string (fullname, 43)
- report ("log", 2, "db",
- "Would have been loading %s.", fullname)
- report_status ("term", "db",
- "Would have been loading %s", truncated)
- else
- local truncated = truncate_string (fullname, 32)
- report ("log", 2, "db", "Loading font %s.", fullname)
- report_status ("term", "db", "Loading font %s", truncated)
- local new = read_font_names (fullname, currentnames,
- targetnames, texmf)
- if new == true then
- fonts_read = fonts_read + 1
- n_new = n_new + 1
- end
- end
+ files[#files + 1] = { path_normalize (fullname), location }
end
- report ("both", 4, "db", "Done. %d fonts indexed in %q.",
- n_found, dirname)
- return n_found, n_new
+ return files
end
+
--- string list -> string list
local filter_out_pwd = function (dirs)
local result = { }
@@ -2275,28 +2245,28 @@ local path_separator = ostype == "windows" and ";" or ":"
--[[doc--
- scan_texmf_fonts() scans all fonts in the texmf tree through the
- kpathsea variables OPENTYPEFONTS and TTFONTS of texmf.cnf.
+ collect_font_filenames_texmf -- Scan texmf tree for font files
+ relying on the kpathsea variables $OPENTYPEFONTS and $TTFONTS of
+ texmf.cnf.
The current working directory comes as “.” (texlive) or absolute
path (miktex) and will always be filtered out.
---doc]]--
+ Returns a list of { *filename*; *location* } pairs.
---- dbobj -> dbobj -> bool? -> (int * int)
+--doc]]--
-local scan_texmf_fonts = function (currentnames, targetnames, dry_run)
+--- unit -> string * string list
+local collect_font_filenames_texmf = function ()
- local n_scanned, n_new, fontdirs = 0, 0
local osfontdir = kpseexpand_path "$OSFONTDIR"
if stringis_empty (osfontdir) then
- report ("info", 1, "db", "Scanning TEXMF fonts...")
+ report ("info", 1, "db", "Scanning TEXMF for fonts...")
else
- report ("info", 1, "db", "Scanning TEXMF and OS fonts...")
+ report ("info", 1, "db", "Scanning TEXMF and $OSFONTDIR for fonts...")
if log.get_loglevel () > 3 then
local osdirs = filesplitpath (osfontdir)
- report ("info", 0, "db",
- "$OSFONTDIR has %d entries:", #osdirs)
+ report ("info", 0, "db", "$OSFONTDIR has %d entries:", #osdirs)
for i = 1, #osdirs do
report ("info", 0, "db", "[%d] %s", i, osdirs[i])
end
@@ -2307,24 +2277,22 @@ local scan_texmf_fonts = function (currentnames, targetnames, dry_run)
fontdirs = fontdirs .. path_separator .. kpseexpand_path "$TTFONTS"
fontdirs = fontdirs .. path_separator .. kpseexpand_path "$T1FONTS"
- if not stringis_empty (fontdirs) then
- local tasks = filter_out_pwd (filesplitpath (fontdirs))
- report ("info", 3, "db",
- "Initiating scan of %d directories.", #tasks)
- report_status_start (2, 4)
- for _, d in next, tasks do
- local found, new = scan_dir (d, currentnames, targetnames,
- dry_run, "texmf")
- n_scanned = n_scanned + found
- n_new = n_new + new
- end
- report_status_stop ("term", "db", "Scanned %d files, %d new.", n_scanned, n_new)
+ if stringis_empty (fontdirs) then
+ return { }
end
- return n_scanned, n_new
+ local tasks = filter_out_pwd (filesplitpath (fontdirs))
+ report ("info", 3, "db",
+ "Initiating scan of %d directories.", #tasks)
+
+ local files = { }
+ for _, dir in next, tasks do
+ files = tableappend (files, collect_font_filenames_dir (dir, "texmf"))
+ end
+ report ("term", 3, "db", "Collected %d files.", #files)
+ return files
end
---- TODO stuff those paths into some writable table
--- unit -> string list
local function get_os_dirs ()
if os.name == 'macosx' then
@@ -2350,38 +2318,75 @@ end
--[[doc--
- scan_os_fonts() scans the OS fonts through
- - fontconfig for Unix (reads the fonts.conf file[s] and scans the
- directories)
- - a static set of directories for Windows and MacOSX
+ retrieve_namedata -- Scan the list of collected fonts and populate
+ the list of namedata.
- **NB**: If $OSFONTDIR is nonempty, as it appears to be by default
- on Windows setups, the system fonts will have already been
- processed while scanning the TEXMF. Thus, this function is
- never called.
+ · dirname : name of the directory to scan
+ · currentnames : current font db object
+ · targetnames : font db object to fill
+ · dry_run : don’t touch anything
+
+ Returns the number of fonts that were actually added to the index.
--doc]]--
---- dbobj -> dbobj -> bool? -> (int * int)
-local scan_os_fonts = function (currentnames,
- targetnames,
- dry_run)
+--- string * string list -> dbobj -> dbobj -> bool? -> int
+local retrieve_namedata = function (files, currentnames, targetnames, dry_run)
+
+ local nfiles = #files
+ local nnew = 0
+ local max_fonts = luaotfloadconfig.max_fonts or 2^51
+
+ report ("info", 1, "db", "Scanning %d collected font files ...", nfiles)
+
+ local bylocation = { texmf = { 0, 0 }
+ , ["local"] = { 0, 0 }
+ , system = { 0, 0 }
+ }
+ report_status_start (2, 4)
+ for i = 1, (nfiles < max_fonts) and nfiles or max_fonts do
+ local fullname, location = unpack (files[i])
+ local count = bylocation[location]
+ count[1] = count[1] + 1
+ if dry_run == true then
+ local truncated = truncate_string (fullname, 43)
+ report ("log", 2, "db", "Would have been loading %s.", fullname)
+ report_status ("term", "db", "Would have been loading %s", truncated)
+ --- skip the read_font_names part
+ else
+ local truncated = truncate_string (fullname, 32)
+ report ("log", 2, "db", "Loading font %s.", fullname)
+ report_status ("term", "db", "Loading font %s", truncated)
+ local new = read_font_names (fullname, currentnames,
+ targetnames, location)
+ if new == true then
+ nnew = nnew + 1
+ count[2] = count[2] + 1
+ end
+ end
+ end
+ report_status_stop ("term", "db", "Scanned %d files, %d new.", nfiles, nnew)
+ for location, count in next, bylocation do
+ report ("term", 4, "db", " * %s: %d files, %d new",
+ location, count[1], count[2])
+ end
+ return nnew
+end
+
+--- unit -> string * string list
+local collect_font_filenames_system = function ()
local n_scanned, n_new = 0, 0
- report ("info", 1, "db", "Scanning OS fonts...")
+ report ("info", 1, "db", "Scanning system fonts...")
report ("info", 2, "db",
"Searching in static system directories...")
- report_status_start (2, 4)
- for _, d in next, get_os_dirs () do
- local found, new = scan_dir (d, currentnames,
- targetnames, dry_run)
- n_scanned = n_scanned + found
- n_new = n_new + new
+ local files = { }
+ for _, dir in next, get_os_dirs () do
+ tableappend (files, collect_font_filenames_dir (dir, "system"))
end
- report_status_stop ("term", "db", "Scanned %d files, %d new.", n_scanned, n_new)
-
- return n_scanned, n_new
+ report ("term", 3, "db", "Collected %d files.", #files)
+ return files
end
--- unit -> bool
@@ -2393,29 +2398,32 @@ end
--[[doc--
- scan_local_fonts() -- Scan font files in $PWD (during a TeX run)
- and add them to the database.
+ collect_font_filenames_local -- Scan $PWD (during a TeX run)
+ for font files.
+
+ Side effect: This sets the “local” flag in the subtable “meta” to
+ prevent the merged table from being saved to disk.
- This sets the “local” flag in the subtable “meta” to prevent the
- merged table from being saved to disk.
-
TODO the local tree could be cached in $PWD.
--doc]]--
-local scan_local_fonts = function (currentnames,
- targetnames,
- dry_run)
- local n_scanned, n_new = 0, 0
- local pwd = lfscurrentdir ()
- report ("both", 1, "db", "Scanning fonts in $PWD (%q) ...", pwd)
+--- unit -> string * string list
+local collect_font_filenames_local = function ()
+ local pwd = lfscurrentdir ()
+ report ("both", 1, "db", "Scanning for fonts in $PWD (%q) ...", pwd)
- n_scanned, n_new = scan_dir (pwd, currentnames, targetnames, false, "local")
- if n_new > 0 then
+ local files = collect_font_filenames_dir (pwd, "local")
+ local nfiles = #files
+ if nfiles > 0 then
targetnames.meta["local"] = true --- prevent saving to disk
+ report ("term", 1, "db", "Found %d files.", pwd)
+ else
+ report ("term", 1, "db",
+ "Couldn’t find a thing here. What a waste.", pwd)
end
-
- return n_scanned, n_new
+ report ("term", 3, "db", "Collected %d files.", #files)
+ return files
end
--- dbobj -> dbobj -> int * int
@@ -2912,35 +2920,18 @@ order_design_sizes = function (families)
return families
end
-local retrieve_namedata = function (currentnames,
- targetnames,
- dry_run,
- n_rawnames,
- n_newnames)
-
- local rawnames, new = scan_texmf_fonts (currentnames,
- targetnames,
- dry_run)
-
- n_rawnames = n_rawnames + rawnames
- n_newnames = n_newnames + new
-
- rawnames, new = scan_os_fonts (currentnames, targetnames, dry_run)
-
- n_rawnames = n_rawnames + rawnames
- n_newnames = n_newnames + new
-
- if luaotfloadconfig.scan_local == true then
- rawnames, new = scan_local_fonts (currentnames, targetnames, dry_run)
-
- n_rawnames = n_rawnames + rawnames
- n_newnames = n_newnames + new
+--- dbobj -> dbobj -> int -> int -> string * bool list
+local collect_font_filenames = function ()
+ ---
+ local filenames = { }
+ tableappend (filenames, collect_font_filenames_texmf ())
+ tableappend (filenames, collect_font_filenames_system ())
+ if luaotfloadconfig.scan_local == true then
+ tableappend (filenames, collect_font_filenames_local ())
end
-
- return n_rawnames, n_newnames
+ return filenames
end
-
--- dbobj -> stats
local collect_statistics = function (mappings)
@@ -3113,7 +3104,6 @@ end
--- dbobj? -> bool? -> bool? -> dbobj
update_names = function (currentnames, force, dry_run)
local targetnames
- local n_raw, n_new = 0, 0
if luaotfloadconfig.update_live == false then
report ("info", 2, "db",
@@ -3132,9 +3122,6 @@ update_names = function (currentnames, force, dry_run)
report("both", 1, "db", "Updating the font names database"
.. (force and " forcefully." or "."))
- --- pass 1 get raw data: read font files (normal case) or reuse
- --- information present in index
-
if luaotfloadconfig.skip_read == true then
--- the difference to a “dry run” is that we don’t search
--- for font files entirely. we also ignore the “force”
@@ -3161,17 +3148,22 @@ update_names = function (currentnames, force, dry_run)
read_blacklist ()
- n_raw, n_new = retrieve_namedata (currentnames,
- targetnames,
- dry_run,
- 0,
- 0)
+ --- pass 1: Collect the names of all fonts we are going to process.
+ local font_filenames = collect_font_filenames ()
+
+ --- pass 2: read font files (normal case) or reuse information
+ --- present in index
+
+ n_new = retrieve_namedata (font_filenames,
+ currentnames,
+ targetnames,
+ dry_run)
report ("info", 3, "db",
- "Scanned %d font files; %d new entries.",
- n_raw, n_new)
+ "Found %d font files; %d new entries.",
+ #font_filenames, n_new)
end
- --- pass 2 (optional): collect some stats about the raw font info
+ --- pass 3 (optional): collect some stats about the raw font info
if luaotfloadconfig.statistics == true then
targetnames.meta.statistics = collect_statistics
(targetnames.mappings)
@@ -3181,17 +3173,17 @@ update_names = function (currentnames, force, dry_run)
--- non-texmf entries are redirected there and the mapping
--- needs to be 100% consistent
- --- pass 3: build filename table
+ --- pass 4: build filename table
targetnames.files = generate_filedata (targetnames.mappings)
- --- pass 4: build family lookup table
+ --- pass 5: build family lookup table
targetnames.families = collect_families (targetnames.mappings)
- --- pass 5: arrange style and size info
+ --- pass 6: arrange style and size info
targetnames.families = group_modifiers (targetnames.mappings,
targetnames.families)
- --- pass 6: order design size tables
+ --- pass 7: order design size tables
targetnames.families = order_design_sizes (targetnames.families)
@@ -3454,7 +3446,6 @@ end
--- export functionality to the namespace “fonts.names”
-----------------------------------------------------------------------
-names.scan_dir = scan_dir
names.set_font_filter = set_font_filter
names.flush_lookup_cache = flush_lookup_cache
names.save_lookups = save_lookups
@@ -3468,7 +3459,6 @@ names.read_blacklist = read_blacklist
names.sanitize_fontname = sanitize_fontname
names.getfilename = resolve_fullpath
names.set_location_precedence = set_location_precedence
-names.scan_local_fonts = scan_local_fonts
--- font cache
names.purge_cache = purge_cache