summaryrefslogtreecommitdiff
path: root/macros/luatex/optex/fonts-resize.opm
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/optex/fonts-resize.opm')
-rw-r--r--macros/luatex/optex/fonts-resize.opm351
1 files changed, 238 insertions, 113 deletions
diff --git a/macros/luatex/optex/fonts-resize.opm b/macros/luatex/optex/fonts-resize.opm
index dbc5974852..6c5ef27fb1 100644
--- a/macros/luatex/optex/fonts-resize.opm
+++ b/macros/luatex/optex/fonts-resize.opm
@@ -1,8 +1,53 @@
%% This is part of OpTeX project, see http://petr.olsak.net/optex
-\_codedecl \setfontsize {Font resizing macros <2020-03-17>} % preloaded in format
+\_codedecl \setfontsize {Font resizing macros <2020-04-17>} % preloaded in format
-%% resizefont variant-name \fontswitch, for example \resizefont{bf}\_tenbf
+ \_doc -----------------------------
+ The \`\setfontsize` `{<sizespec>}` saves the `<sizespec>` to the \`\_sizespec` macro.
+ The \`\_optsize` value is calculated from the `<sizespec>`.
+ If the `<sizepec>` is in the `mag<number>` format then the contents of
+ the `\_sizespec` macro is re-calculated to the `at<dimen>` format using
+ previous `\_optsize` value.
+ \par \goodbreak
+ \_cod -----------------------------
+
+\_newdimen \_optsize \_optsize=10pt
+\_newdimen \_defaultoptsize \_defaultoptsize=10pt
+\_newdimen\_lastmagsize
+
+\_def\_setfontsize #1{%
+ \_edef\_sizespec{#1}%
+ \_ea \_setoptsize \_sizespec\_relax
+ \_reloading
+}
+\_def\_setoptsize {\_isnextchar a{\_setoptsizeA}
+ {\_isnextchar m{\_setoptsizeC}{\_setoptsizeB}}}
+\_def\_setoptsizeA at#1\_relax{\_optsize=#1\_relax\_lastmagsize=\_optsize} % at<dimen>
+\_def\_setoptsizeB scaled#1\_relax{\_optsize=\_defaultoptsize\_relax} % scaled<scalenum>
+\_def\_setoptsizeC mag#1\_relax{%
+ \_ifdim\_lastmagsize>0pt \_optsize=\_lastmagsize \_else \_optsize=\_pdffontsize\_font \_fi
+ \_optsize=#1\_optsize
+ \_lastmagsize=\_optsize
+ \_edef\_sizespec{at\_the\_optsize}%
+}
+\_public \setfontsize \defaultoptsize ;
+
+ \_doc -----------------------------
+ \`\_resizefont` `{<variant-name>}\<font switch>`,
+ for example `\resizefont{bf}\_tenbf` resizes the font given by the
+ variant. The variant `XX` have its font switch `\_tenXX`.
+ The \`\_doresizefont``\fontswitch` is used. It works in
+ TFM mode (\`\_doresizetfmfont`) or OTF mode (\^`\_doresizeunifont`).
+ In both modes, it does
+ \begtt \catcode`\<=13
+ \_font \_tenXX = <fontname> \_sizespec
+ \endtt
+ The `<fontname>` is generated by the `\fontname` \TeX/ primitive where
+ \`\_rfontskipat` removes the `at<dimen>` part of the `\_fontname` output.
+ The `<fontname>` is generated differently in OTF mode, see
+ \^`\_doresizeunifont` macro.\nl
+ The \`\_whatresize` is defined as `<variant-name>`.
+ \_cod -----------------------------
\_def\_resizefont#1#2{%
\_edef\_whatresize{#1}%
@@ -22,40 +67,111 @@
\_def\_rfskipatX #1" #2\_relax{"\_whichtfm{#1}"}
\_def\_rfskipatN #1 #2\_relax{\_whichtfm{#1}}
-%% \setfontsize{at<size>} or \setfontsize{scaled<size>}
+ \_doc -----------------------------
+ \`\fontdef` `<font switch>{<modifiers><variant selector>}`
+ opens group, runs `<modifiers><variant selector>` (i.e.\ it runs `#2` parameter).
+ The font switch `#1` saved in the \`\_fontselector` macro is re-declared
+ because the variant selector runs the \^`\_resizefont`. Now, we need to
+ keep the current meaning of the font switch `#1` but we must leave the
+ opened group. This is done by the \`\_keepmeaning` macro.
+ \nl
+ \`\fontlet` `<font switch A> <font switch B> <size spec>` does
+ \begtt \catcode`\<=13
+ \font <font switch A> = <fontname> <sizespec>
+ \endtt
+ The `<fontname>` is extracted using the primitive command `\_fontname <font switch B>`.
+ \_cod -----------------------------
-\_newdimen \_optsize \_optsize=10pt
-\_newdimen \_defaultoptsize \_defaultoptsize=10pt
+\_def \_fontdef #1#2{\_begingroup
+ \_ifx\_fontselector\_undefined \_def\_fontselector{#1}\_fi
+ \_reloading #2%
+ \_ea \_keepmeaning \_fontselector \_endgroup
+}
+\_def\_fontlet#1#2{\_ifx #2=\_ea\_fontlet \_ea#1\_else
+ \_ea\_font\_ea#1\_ea\_rfontskipat\_fontname#2 \_relax\_space \_fi
+}
+\_def \_keepmeaning #1#2{\_global\_let\_keepmeaningdata=#1%
+ #2\_let#1=\_keepmeaningdata \_global\_let\_keepmeaningdata=\_undefined
+}
+\_public \fontdef \fontlet ;
+
+ \_doc -----------------------------
+ \`\newcurrfontsize` `<size spec>` sets current font size to the `<size spec>`
+ It is implemented by \^`\fontlet`.
+ The font switch of the current font is extracted by `\_the\_font`.
+ We must re-create the control sequence `\_the\_font` because
+ its original meaning is set to \"inaccessible" by \TeX/ when `\font`
+ primitive is started.
+ \nl
+ \`\resizethefont` is implemented by `\newcurrfontsize` using data from
+ the \^`\_sizespec` macro.
+ \_cod -----------------------------
-\_def\_setfontsize #1{%
- \_edef\_sizespec{#1}%
- \_ea \_setoptsize \_sizespec\_relax
- \_reloading
+\_def \_newcurrfontsize #1{% \newcurrfontsize{at25pt}
+ \_edef\_tmp{\_ea\_csstring \_the\_font}%
+ \_ea \_fontlet \_csname \_tmp\_ea\_endcsname \_the\_font \_space #1\_relax
+ \_csname \_tmp\_endcsname
}
+\_protected\_def \_resizethefont{\_newcurrfontsize\_sizespec}
+
+ \_public \newcurrfontsize \resizethefont ;
+
+ \_doc -----------------------------
+ The variant selector is defined by `\protected\def\XX{\_tryloadXX \_tenXX}`
+ The `\_tryloadXX` can be in `\_relax` state if no font modifiers were
+ declared. But normally it does \^`\_resizefont``{XX}\tenXX`. This meaning
+ is activated by the \`\_reloading` macro.
+ \_cod -----------------------------
+
\_def\_reloading{\_loadf{rm}\_tenrm \_loadf{bf}\_tenbf
\_loadf{it}\_tenit \_loadf{bi}\_tenbi
}
\_def\_loadf#1#2{\sdef{_tryload#1}{\_ifmmode \_else \_resizefont{#1}#2\_fi}}
\_def\_tryloadtt{\_resizefont{tt}\_tentt}
-\_def\_setoptsize {\_isnextchar a{\_setoptsizeA}
- {\_isnextchar m{\_setoptsizeC}{\_setoptsizeB}}}
-\_def\_setoptsizeA at#1\_relax{\_optsize=#1\_relax\_lastmagsize=\_optsize} % at<dimen>
-\_def\_setoptsizeB scaled#1\_relax{\_optsize=\_defaultoptsize\_relax} % scaled<scalenum>
-\_def\_setoptsizeC mag#1\_relax{%
- \_ifdim\_lastmagsize>0pt \_optsize=\_lastmagsize \_else \_optsize=\_pdffontsize\_font \_fi
- \_optsize=#1\_optsize
- \_lastmagsize=\_optsize
- \_edef\_sizespec{at\_the\_optsize}}
-
-\_newdimen\_lastmagsize
-
-\_setfontsize{at10pt} % default size
\_let\_tryloadrm=\_relax
\_let\_tryloadbf=\_relax
\_let\_tryloadit=\_relax
\_let\_tryloadbi=\_relax
+ \_doc ----------------------------
+ The font selection system allows to use \`\currvar`
+ instead explicitly specified variant selector. The current variant
+ is extracted from `\the\font` output which could be `\_tenXX` control
+ sequence. Then `\currvar` expands to `\_rm` or `\_it` etc.
+ \_cod ----------------------------
+
+\_protected \_def \_currvar{\_cs{_currvar:\_ea \_csstring \_the\_font}}
+\_sdef{_currvar:_tenrm}{\_rm}
+\_sdef{_currvar:_tenbf}{\_bf}
+\_sdef{_currvar:_tenit}{\_it}
+\_sdef{_currvar:_tenbi}{\_bi}
+\_sdef{_currvar:_tentt}{\_tt}
+\_public \currvar ;
+
+ \_doc -----------------------------
+ The \`\_regtfm` `<font id> <optical size data>`
+ saves the <optical size data> concerned to `<font id>`.
+ The `<optical size data>` is in the form as show below in the code where
+ `\regtfm` is used.
+ \nl
+ The \`\_wichtfm` `<fontname>` expands to the `<fontname>` or to the corrected
+ `<fontname>` read from the `<optical size data>`. It is used in the
+ \^`\_rfontskipat` macro and it is used in \^`\fontlet` macro.
+ It means that each `<fontname>` generated by the `\fontname` primitive in the
+ `\fontlet` macro is processed by the `\_whichtfm`. The real `<fontname>` or
+ corrected `<fontname>` (depending on the optical data does not exist or exist)
+ is the output of the expansion before `\font` primitive takes this output
+ as its parameter.
+
+ The implementation detail: The `\_<font id>:reg` is defined as the
+ `<optical size data>` and all control sequences `\_<fontname>:reg`
+ from this data line has the same meaning because of the
+ \`\_reversetfm` macro. The `\_whichtfm` expands this data line and apply
+ \`\_dowhichtfm`. This macro select the right result from the data line
+ by testing with the current `\_optsize` value.
+ \_cod -----------------------------
+
\_def\_regtfm #1 0 #2 *{\_ea\_def \_csname _#1:reg\_endcsname{#2 16380 \_relax}%
\_def\_tmpa{#1}\_reversetfm #2 * %
}
@@ -78,41 +194,9 @@
}
\_def\_ignoretfm #1\_relax{}
-% \fontdef \new {\<modifiers>\<var-selector>}
-\_def \_fontdef #1#2{\_begingroup
- \_ifx\_fontselector\_undefined \_def\_fontselector{#1}\_fi
- \_reloading #2%
- \_ea \_keepmeaning \_fontselector \_endgroup
-}
-\_def\_fontlet#1#2{\_ifx #2=\_ea\_fontlet \_ea#1\_else
- \_ea\_font\_ea#1\_ea\_rfontskipat\_fontname#2 \_relax\_space \_fi
-}
-\_def \_keepmeaning #1#2{\_global\_let\_keepmeaningdata=#1%
- #2\_let#1=\_keepmeaningdata \_global\_let\_keepmeaningdata=\_undefined
-}
-\_protected \_def \_currvar{\_cs{_currvar:\_ea \_csstring \_the\_font}}
-\_sdef{_currvar:_tenrm}{\_rm}
-\_sdef{_currvar:_tenbf}{\_bf}
-\_sdef{_currvar:_tenit}{\_it}
-\_sdef{_currvar:_tenbi}{\_bi}
-\_sdef{_currvar:_tentt}{\_tt}
-
-\_def \_newcurrfontsize #1{% \newcurrfontsize{at25pt}
- \_edef\_tmp{\_ea\_csstring \_the\_font}%
- \_ea \_fontlet \_csname \_tmp\_ea\_endcsname \_the\_font \_space #1\_relax
- \_csname \_tmp\_endcsname
-}
-
-\_def \_rmfixed {% used in default \footline
- {\_ifdim\_mainfosize=0pt \_mainfosize=10pt \_fi
- \_fontdef\_rmfixed{\_setfontsize{at\mainfosize}\_resetmod\_rm}%
- \_global\_let\_rmfixed=\_rmfixed} % next use will be font switch only
- \_rmfixed
-}
-\_let \rmfixed = \_tenrm % user can redefine it
-
-
-%% Optical sizes data for preloaded Latin Modern fonts:
+ \_doc -----------------------------
+ Optical sizes data for preloaded 8bit Latin Modern fonts:
+ \_cod -----------------------------
\_regtfm lmr 0 ec-lmr5 5.5 ec-lmr6 6.5 ec-lmr7 7.5 ec-lmr8 8.5 ec-lmr9 9.5
ec-lmr10 11.1 ec-lmr12 15 ec-lmr17 *
@@ -121,64 +205,109 @@
\_regtfm lmri 0 ec-lmri7 7.5 ec-lmri8 8.5 ec-lmri9 9.5 ec-lmri10 11.1 ec-lmri12 *
\_regtfm lmtt 0 ec-lmtt10 11.1 ec-lmtt12 *
-\_public
- \setfontsize \newcurrfontsize \fontdef \fontlet \currvar \defaultoptsize ;
+\_setfontsize {at10pt} % default font size
\_endcode %---------------------------------------------------
-This code is inspired from csfontsm.tex file.
-\sec Scaling fonts to diferent sizes in text mode (low-level macros)
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\sec[setfontsize] Scaling fonts in text mode (low-level macros)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+The \^`\setfontsize` `{<size spec>}`
+saves the information about `<size spec>`. This information is taken into
+account when a variant selector (for example `\rm`, `\bf`, `\it`, `\bi`)
+or `\resizethefont` is used. The `<size spec>` can be:
+\begitems
+* `at<dimen>`, for example `\setfontsize{at12pt}`. It gives the desired font size directly.
+* `scaled<scale factor>`, for example `\setfontsize{scaled1200}`. The font is
+ scaled in respect to its native size (which is typically 10\,pt). It
+ behaves like `\font\... scaled<number>`.
+* `mag<decimal number>`, for example `\setfontsize{mag1.2}`. The font is
+ scaled in respect to the current size of the fonts given by the previous
+ \^`\setfontsize` command.
+\enditems
+The initialization value in \OpTeX/ is given by `\setfontsize{at10pt}`.
-There are four basic font-variant selectors `\rm`, `\bf`, `\it`, `\bi`.
-Once a font family is loaded (for example fonts decalred in the format in
-the `fonts-preloaded.opm` or loaded by `\fontfam`) then you can resize these
-fonts using `\setfontsize{<sizespec>}`, for example `\setfontsize{at12pt}`
-or `\setfontsize{scaled1300}`. Note that the word `at` or `scaled` must be
-present here. This command itself does not rescaling, this is done at the
-first moment you use next `\rm`, `\bf`, `\it` or `\bi` selectors.
-Example. Assume that we are printing at 10pt and we use:
+The \^`\resizethefont` resizes the current font to the size given by previous
+\^`\setfontsize`. For example
\begtt
- \setfontsize{at15pt} ...still at 10pt... \rm ...now the text is at15pt...
- \bf bold is at 15pt too ...
+ Here is 10 pt text,
+\setfontsize{at12pt} 10 pt text here unchanged...
+\resizethefont and 12 pt text is here.
\endtt
+%
+The \^`\setfontsize` command acts like {\em font modifier}. It means that it
+saves information about fonts but does not change the font actually until
+variant selector or \^`\resizethefont` is used.
-More meaningful is to use first variant selector immediatelly after
-`\setfontsize` command. There is a special "variant selector" `\currvar`
-which reloads the font from current variant, for example
+The following example demonstrates the `mag` format of \^`\setfontsize`
+parameter. It is only a curious example probably not used in practical
+typography.
\begtt
- \it italics at10pt \setfontsize{at7pt}\currvar italics at 7pt.
+\def\smaller{\setfontsize{mag.9}\resizethefont}
+Text \smaller text \smaller text \smaller text.
\endtt
-If you are using font families by `\fontfam` then you can use more "font
-modifiers". The `\setfontsize` command is only one of such font modifier. All font
-modifiers does not actual change of fonts but first usage of a variant selector
-takes this setting. See `fonts-select.opm` for more information about it.
+If you load a font directly by `\font` primitive and you want to
+create a size-dependent selector for such font then you can use
+\^`\resizethefont`:
+
+\begtt
+\font\tencomfortaa=Comfortaa-Regular-T1 at10pt
+\def\comfortaa{\tencomfortaa\resizethefont}
-You can declare `\<newfont>` which behaves as natural font switch declared
-by `\font`:
+\comfortaa Here is 10 pt text
+\setfontsize{at12pt}
+\comfortaa Here is 12 pt text
+\endtt
+%
+The example above uses the 8\,bit `tfm` font. You can use Unicode font too, of
+course. The \^`\fontfam` macro initializes the extended `\font` primitive
+features for \LuaTeX/. If you didn't use this command, you must to initialize
+these features by `\initunifonts` command, for example:
\begtt
- \fontdef \<newfont> {<modifiers> \<variant-selector>}
+\initunifonts
+\font\tencyklop=[cyklop-regular] at10pt % the font cyklop-regular.otf is loaded
+\def\cyklop{\tencyklop\resizethefont}
+
+\cyklop Here is 10 pt text
+\setfontsize{at12pt}
+\cyklop Here is 12 pt text
+\endtt
+
+\secc[fontdef] The \code{\\fontdef} declarator
+
+You can declare `\<newfont>` by the \^`\fontdef` command.
+
+\begtt \catcode`\<=13
+ \fontdef \<newfont> {<font modifiers> \<variant-selector>}
example:
\fontdef \bigfont {\setfontsize{at15pt}\bf}
\endtt
-
-This command runs `<modifiers> \<variant-selector>` in a group and sets the
+%
+This command runs `<font modifiers> \<variant-selector>` in a group and sets the
resulting current font as `\<newfont>`.
-The parameter of the `\fontdef` macro needs to be finalized by one of the
-four standard variant selectors (or `\currvar`).
+The resulting `\<newfont>` declared by \^`\fontdef` is \"fixed font switch"
+independent of \^`\setfontsize` and other font modifiers. More exactly, it is
+fixed font switch when it is used but it can depend on the current font
+modifiers and font family and given font modifiers when it is declared.
-We have another command for scaling: `\fontlet` which is able to resize
-arbitrary font. The font must be presented by \<fontswhitch>, i.e. by
-`\_tenrm`, `\_tenbf` etc. or arbitrary font switch you declared it by
-`\font` primitive or `\fontdef` macro. The usage is:
+The parameter of the \^`\fontdef` macro must be exactly finished by the
+variant selector. More information about font modifiers
+and variant selectors are in the section~\ref[fontsystem].
-\begtt
+\secc[fontlet] The \code{\\fontlet} declarator
+
+We have another command for scaling: \^`\fontlet` which is able to resize
+arbitrary font given by its font switch.
+This font switch was declared it by the
+`\font` primitive or the `\fontdef` macro.
+
+\begtt \catcode`\<=13
\fontlet \<newfont> = \<fontswitch> <sizespec>
example:
\fontlet \bigfont = \_tenbf at15pt
@@ -189,36 +318,32 @@ was used. The advantage of `\fontdef` macro will be more clear when you load
font families by `\fontfam` and you are using more font modifiers declared
in such families.
-The `\newcurrfontsize{<sizespec>}` resizes immediatelly current font.
-No others fonts are resized.
-
-The parameter of `\setfontsize` should be in the format `at<dimen>` or
-`scaled<scalenum>` or `mag<coefficient>`. The first two are know from
-classical \TeX/. The third sets new font size to <coefficient> multiplied by
-current font size (declared by at<dimen> or mag<coefficient>). For example
-if we have do `\setfontsize{at12pt}` and next we write
-`\setfontsize{mag1.5}\rm` then the current font size is `at19pt`. You can
-define a funny macro `\bigger`:
-
-\begtt
- \def\bigger {\setfontsize{mag1.3}\currvar}
- text \bigger text \bigger text \bigger text...
-\endtt
+Summary: you can declare font switches:
+\begitems
+* by the `\font` primitive if you know the font file,
+* by the \^`\fontlet` command if you know the font switch and the size, or
+* by the \^`\fontdef` command if you know the variant and modifiers.
+\enditems
\secc Optical sizes
There are font families with more font files where almost the same font is
implemented in various design sizes: `cmr5`, `cmr6`, `cmr7`, `cmr8`, `cmr9`,
-`cmr10`, `cmr12`, `cmr17` for example. This feature is called "optical
+`cmr10`, `cmr12`, `cmr17` for example. This feature is called \"optical
sizes". \OpTeX/ chooses a font with an optical size closest to desired size
-specified by `\setfontsize`, when `at<dimen>` or `mag<coefficient>` is used.
-When `scaled<scalenum>` is used then optical size is choosen using the value
+specified by the \^`\setfontsize`, when `at<dimen>` or `mag<coefficient>` is used.
+When `scaled<scale factor>` is used then optical size is chosen using the value
of the `\defaultoptsize` register and such font is scaled by the specified
-<scalenum>. There is `\defaultoptsize=10pt` by default.
+`<scale factor>`. There is `\defaultoptsize=10pt` by default.
+Font collections with optical sizes must be registered by the
+\^`\_regtfm` for `tfm` files or \^`\_regoptsizes` for Unicode fonts.
+\OpTeX/ registers 8bit Latin Moder fonts in the format (`fonts-resize.opm` file)
+and OTF Latin Modern fonts in the `f-lmfonts.opm` file.
\secc Implementation notes
-... to do ...
-
+\_endinput
+2020-04-17 \resizethefont introduced
+2020-03-17 released