%% This is part of OpTeX project, see http://petr.olsak.net/optex \_codedecl \fontfam {Fonts selection system <2020-03-18>} % preloaded in format \_doc ----------------------------- The \`\initunifonts` initializes extended `\font` primitive (to be able to load Unicode fonts). Unfortunately, this part of \OpTeX/ depends on \LaTeX/ lua codes `ltluatex.lua` and `luaotfload-main.lua`. And this code need to be declared a control sequence `\e@alloc@attribute@count` by `\countdef` primitive. Moreover, the `\initunifont` switches with the \^`\_doresizefont` macro to OTF mode which is represented by the macro \`\_doresizeunifont`. This mode includes a fallback to TFM mode if \^`\_fontnamegen` is not defined. Finally, the `\initunifnt` sets itself to relax because we need not to do this work twice. \_cod ----------------------------- \_def\_initunifonts {% \_ea\_newcount \_csname e@alloc@attribute@count\_endcsname \_global \_csname e@alloc@attribute@count\_endcsname=-1 \_directlua{% require("ltluatex") require('luaotfload-main') local _void = luaotfload.main () }% \_gdef\_rfskipatX ##1" ##2\_relax{"##1"}% \_global\_let \_doresizefont=\_doresizeunifont \_gdef\_tryloadtt {\_fontdef\_tentt{\def\_fontnamegen{[lmmono10-regular]}\_rm}}% \_global\_let \_initunifonts=\_relax % we need not to do this work twice \_global\_let \initunifonts=\_relax } \_gdef\_doresizeunifont #1{\_logfont{#1}% \_ifx\_fontnamegen\_undefined \_doresizetfmfont#1\_else \_font#1={\_fontnamegen} \_sizespec \_relax \_setwsp#1\_relax \_fi } \_public \initunifonts ; \_doc ----------------------------- The \`\_famdecl` `[] \ {} {} {} {}`\nl `{} {\def`\^`\_fontnamegen``{}}` runs \^`\initunifonts`, then checks if `\` is defined. If it is true, then closes the file by `\endinput`. Else it defines `\` and saves it to the \`\_mainfamcommand` macro because the \`\_initfontfamily` needs it. The \`\_currfamily` is set to the `` because the following \^`\moddef` commands need to be in the right font family context. The `\_currfamily` is set to the `` by the `\` too, because `\` must set the right faily context. The font family context is given by the current `\_currfamily` value and by the actual meaning of the \^`\_fontnamegen` macro. \_cod ----------------------------- \_def\_famdecl [#1]#2#3#4#5#6#7#8{% \_initunifonts \_uniaccents \_ifx #2\_undefined \_isfont{#7}\_iffalse \_opwarning{Family [#1] skipped, font "#7" not found}\_ea\_ea\_ea\_endinput \_else \_edef\_currfamily {\_csstring #2}% \_def\_mainfamcommand{#2}\_def\_mathfaminfo{#6}% \_protected\_edef#2{\_def\_noexpand\_currfamily{\_csstring #2}\_unexpanded{#8\_resetmod}}% \_wterm {FONT: [#1] -- \string#2 \_detokenize{(#3)^^J mods:{#4} vars:{#5} math:{#6}}}% \_fi \_else \_ea #2\_ea\_endinput \_fi } \_def\_initfontfamily{% \_mainfamcommand \_reloading \_rm } \_doc ----------------------------- \`\_regoptsizes` ` ? ` prepares data for using by the \`\_optname` `` macro. The data are saved to the `\_oz:` macro. When the `\_optname` is expanded then the data are scanned by the macro \`\_optnameA` `? `\code{<}`` in the loop.\nl \`\_optfontalias` `{ is undeclared in current family" and nothing happens. But you can declare the same variant selector by \^`\famvardef` macro in the context of new family. Then the same command will be do different work depending on the current font family. Suppose that the selected font family provides the font modifier `\medium` for mediate weight of fonts but supports only basic variant selectors `\rm`, `\bf`, `\it`, and `\bi`. Then you can declare: \begtt \famvardef \mr {\medium\rm} \famvardef \mi {\medium\it} \endtt Now, you can use six independent variant selectors `\rm`, `\bf`, `\it`, `\bi`, `\mr` and `\mi` in the selected font family. A `\` can be written before `` in the `\famvardef` parameter. Then the `\` is declared in the current family but it can use fonts from another family represented by the `\`. When you are mixing fonts from more families then you probably run into problem with incompatible ex-heights. This problem can be solved using \^`\setfontsize` and \^`\famvardef` macros: \begtt \fontfam[Heros] \fontfam[Termes] \def\exhcorr{\setfontsize{mag.88}} \famvardef\rmsans{\Heros\exhcorr\rm} \famvardef\itsans{\Heros\exhcorr\rm} Compare ex-height of Termes \rmsans with Heros \rm and Termes. \endtt There exists analogical declarator `\moddef` for declaration family dependent font modifiers. It is described in detail the section~\ref[fontfamfiles]. \secc Modifying font features %---------------------------- Each OTF font provides \"font features". You can list these font features by `otfinfo -f font.otf`. For example LinLibertine fonts provide `frac` font feature. If it is active then fractions like 1/2 are printed in a special form. The font features are part of the font context data. The macro \^`\setff` `{}` acts like family independent font modifier and prepares a new . You must use a variant selector in order to reinitialize the font with the new font feature. For example \^`\setff``{+frac}\rm` or \^`\setff``{+frac}`\^`\currvar`. You can declare a new variant selector too: \begtt \fontfam[LinLibertine] \famvardef \fraclig {\setff{+frac}\currvar} Compare 1/2 or 1/10 \fraclig to 1/2 or 1/10. \endtt If the used font does not supports given font feature then font is realoaded without warning nor error, silently. The font feature is not activated. The `onum` font feature (old style digits) is connected to `\caps` macro for Caps+SmallCaps variant in \OpTeX/ font family files. So you need not to create a new modifier, just use `{\caps`\^`\currvar`` 012345}`. \secc Special font modifiers %--------------------------- Despite the font modifiers declared in the font family file (and dependent on the font family), we have following font modifiers (independent of font family): \begtt \catcode`\<=13 \setfontsize{} % sets the font size \setff{} % adds the font feature \setfontcolor{} % sets font color \setletterspace{} % sets letter spacing \setwordspace{} % modifies word spacing \endtt The \^`\setfontsize` command is described in the section \ref[setfontsize]. The \^`\setff` command was described in previous subsection. \^`\setfontcolor` `{}` specifies the color and the opacity of the text. The parameter should be in hexadecimal format of four bytes ``, for example `FF0080FF` means full red, zero green, half blue and full opacity. You can use names `red`, `green`, `blue`, `yellow`, `cyan`, `magenta`, `white`, `grey`, `lgrey` (without backslash) instead of the hexadecimal specification. The empty parameter `` means default black color. That colors of fonts are implemented using \LuaTeX/ internal font feature. This is different approach than using colors in section \ref[colors]. \^`\setletterspace` `{}` specifies letter spacing of the font. The `` is decimal number without unit. The unit is supposed as 1/100 of the font size. I.e. `2.5` means 0.25 pt when the font is at 10 pt size. The empty parameter `` means no letter spacing which is default. \^`\setwordspace` `{}` scales the default inter word space (defined in the font) and its stretching and shrinking parameters by given `` factor. For example `\setwordspace{2.5}` multiplies inter word space by 2.5. If you need another font transformations, you can use `\setff` with following font features provided by Lua\TeX/: \begtt \setff{embolden=1.5}\rm % font is bolder because outline has nonzero width \setff{slant=0.2}\rm % font is slanted by a linear transformation \setff{extend=1.2}\rm % font is extended by a linear transformation. \endtt Use font transformations mentioned above and \^`\setletterspace`, \^`\setwordspace` with care. The best setting of these values is default setting in every font, of course. If you really needs to set a different letter spacing then it is strongly recommended to add `\setff{-liga}` in order to disable ligatures. And setting a positive letter spacing probably needs to scale inter word spacing too. All mentioned font modifiers (with the exception of `\setfontsize`) work only with Unicode fonts loaded by \^`\fontfam`. \secc[fontfamfiles] How to create the font family file %------------------------------------------------------ \printdoctail f-heros.opm \printdoctail f-lmfonts.opm \secc How to register the font family in the Font Selection System %--------------------------------------------------------------- \printdoctail fams-ini.opm \endinput 2020-04-18 \_tryloadfamslocal introduced \_fontdecl -> \_famdecl with different concept 2020-03-18 released