[Fontinst] fontinst fontdsize variance?

Lars Hellström Lars.Hellstrom at residenset.net
Thu Feb 4 17:41:10 CET 2016


Getting ready to call it day, but since I have a modification which lets 
fontinst preserve all the designsize digits, I thought I should give you a 
chance to try it. Attached is the patch against the fontinst sources; you 
still need to docstrip after applying.

I have tested it with


\input fontinst.sty
\installfonts
    \installfont{cmr17t1}{cmr17,newlatin}{t1} {T1}{cmr17}{m}{n}{17}
\endinstallfonts
\bye


The resulting cmr17t1.vpl claims designsize 17.28, but references the base 
font cmr17 with (FONTDSIZE R 17.279999), just like vptovf wants it to.

I'd like to apply some additional optimisations however, to reduce the 
number of tokens spent storing these long digit sequences. To be continued 
some other day...


Lars Hellström
diff --git a/source/fibasics.dtx b/source/fibasics.dtx
index eb8bc1b..2809350 100644
--- a/source/fibasics.dtx
+++ b/source/fibasics.dtx
@@ -65,7 +65,7 @@
 %   stuff any earlier than this.  Note that |\fontinstversion| is not
 %   just used for indentification but also in |\needsfontinstversion|.
 %    \begin{macrocode}
-%<pkg|doc>\def\fontinstversion{1.933}
+%<pkg|doc>\def\fontinstversion{1.935}
 %    \end{macrocode}
 % \end{macro}
 %
@@ -1922,8 +1922,67 @@
    \catcode`\t=12
    \gdef\lose_measure#1pt{#1}
 }
+%    \end{macrocode}
+% \end{macro}
+% 
+% \begin{macro}{\store_length_without_measure}
+%   This macro has the syntax
+%   \begin{quote}
+%     |\store_length_without_measure|\marg{command}\marg{dimen}
+%   \end{quote}
+%   and it is \emph{almost} the same as doing
+%   \begin{quote}
+%     |\a_dimen = |\meta{dimen}\\
+%     |\edef|\meta{command}|{\expandafter\lose_measure \the\a_dimen}|
+%   \end{quote}
+%   i.e., it defines the \meta{command} to be a macro which expands 
+%   to the \meta{factor} such that \meta{factor}|pt| is |\ifdim| 
+%   equal to the given \meta{dimen}. But if the \meta{dimen} is 
+%   already specified with a unit of |pt|, then \meta{command} is 
+%   directly defined to be the digits in front of that.
+%   \changes{1.935}{2016/02/04}{Macro added. (LH)}
+%    \begin{macrocode}
+\def\store_length_without_measure#1#2{
+   \begingroup
+      \a_dimen = #2\x_relax
+   \expandafter\endgroup \expandafter\store_length_without_measure_i
+      \expandafter{ \the\a_dimen } #2 \first_of_two pt \second_of_two
+      \store_length_without_measure_i{\edef#1}
+   
+}
+\def\store_length_without_measure_i 
+   #1#2pt #3 #4\store_length_without_measure_i#5
+{
+   #5{#3{#2}{\lose_measure #1}}
+}
 %</pkg>
 %    \end{macrocode}
+%   The idea of |\store_length_without_measure_i| is that if the 
+%   \meta{dimen} ends with |pt| then |#3| will be |\first_of_two| and 
+%   the replacement text of the |\edef| in |#5| expands to what comes 
+%   in front of that |pt|. Otherwise |#3| will be |\second_of_two| 
+%   and the |\lose_measure| construction gets expanded.
+%   
+%   Now \emph{why} would anyone want to do that in such a roundabout 
+%   way? Because \package{VPtoVF} requires that font design sizes 
+%   (which are very vague numbers to begin with) are specified at a 
+%   \emph{higher}(!!) precision than \TeX\ dimen arithmetic provides, 
+%   so we cannot rely on that for design sizes. This is no big 
+%   problem, since the design size is in practice just a magical 
+%   number that \package{fontinst} has to copy from base font to 
+%   virtual font---no arithmetic is ever required---but because these 
+%   were traditionally treated as dimens there are public interfaces 
+%   around where the raw number has to carry a |pt| suffix. 
+%   |\store_length_without_measure| exists to lose that |pt| suffix 
+%   without losing the required magic number precision. And it seeks 
+%   to do something sensible in the weird but in principle supported 
+%   case that a design size is not given in |pt|.
+%   
+%   Note also that the catcodes for |p| and |t| here are correct. In 
+%   |\lose_measure| these tokens are generated by |\the| and thus of 
+%   category other, but for |\store_length_without_measure| the 
+%   normal case is that they come from normal tokenisation of text in 
+%   a file and therefore should be letters.
 % \end{macro}
 % 
 % 
diff --git a/source/ficonv.dtx b/source/ficonv.dtx
index 4281142..c0e6cb8 100644
--- a/source/ficonv.dtx
+++ b/source/ficonv.dtx
@@ -1143,6 +1143,18 @@
 % \end{macro}
 %
 % 
+% \begin{macro}{\raw_font_designsize}
+%   This macro stores the designsize value of the font. This is 
+%   specified once in the PL file, but will be copied to every 
+%   |\setrawglyph| command generated. The value is a sequence of 
+%   digits followed by |pt|, so it may be used as a dimen, but in 
+%   many cases VPtoVF requests higher precision than a dimen register 
+%   would provide, so we need to preserve the full sequence of 
+%   decimals.
+%   \changes{1.935}{2016/02/04}{Introduced macro, replacing 
+%     \cs{a_dimen} as storage for this information. (LH)}
+% \end{macro}
+% 
 % \begin{macro}{\pl_to_mtx}
 %   \changes{1.911}{1999/11/19}{\cs{edef}ing \cs{raw_font_name}. (LH)}
 %   The |\pl_to_mtx| macro contains all code that was common to 
@@ -1159,6 +1171,7 @@
 %    \begin{macrocode}
 \def\pl_to_mtx#1#2#3#4{
    \edef\raw_font_name{#1}
+   \def\raw_font_designsize{10pt}
    \open_out{\temp_prefix#2.mtx}
    \out_line{\percent_char~Filename:~#2.mtx}
    \out_line{\percent_char~Created~by:~tex~\jobname}
@@ -1365,10 +1378,15 @@
 %   the corresponding base font.
 %    \begin{macrocode}
 \def\DESIGNSIZE~#1~#2~{
-   \a_dimen=#2pt
-   \out_line{\string\setdim{designsize}{\the\a_dimen}}
+   \def\raw_font_designsize{#2pt}
+   \out_line{\string\setdim{designsize}{\raw_font_designsize}}
 }
 %    \end{macrocode}
+%   Technically, it seems legal to write the designsize in e.g.~octal 
+%   or hexadecomal instead, but since apparently noone had been mad 
+%   enough to do so during the first two decades of 
+%   \package{fontinst}'s existence, it's nothing we need to worry 
+%   about.
 % \end{PLproperty}
 % 
 % \begin{PLproperty}{DESIGNUNITS}
@@ -1702,7 +1720,7 @@
          \out_line{\string\setrawglyph
             {\csname~name-\the\a_count\endcsname}
             {\raw_font_name}
-            {\the\a_dimen}
+            {\raw_font_designsize}
             {\the\a_count}
             {\the\b_count}
             {\the\c_count}
@@ -1752,8 +1770,6 @@
    \out_line{}
    \out_line{(COMMENT~THIS~FILE~CAN~THEN~BE~DELETED.)}
    \out_line{}
-   \out_line{(DESIGNSIZE~R~10.0)}
-   \out_line{}
    \let\setglyph=\iffalse
    \let\endsetglyph=\fi
    \let\setkern=\gobble_three
@@ -1768,13 +1784,21 @@
 % \end{macro}
 %
 % \begin{macro}{\first_pl_raw_glyph}
-%   The |\first_pl_raw_glyph| writes the \texttt{DESIGNUNITS} property 
-%   for the font when the first |\setscaledrawglyph| is encountered. 
-%   This is to undo the scaling that has already been applied to the 
-%   metrics, so that the metrics will match the actual font.
+%   The |\first_pl_raw_glyph| writes the \texttt{DESIGNSIZE} and 
+%   \texttt{DESIGNUNITS} properties for the font when the first 
+%   |\setscaledrawglyph| is encountered; the proper values aren't 
+%   known before that. The value for the \texttt{DESIGNUNITS} serves 
+%   to undo the scaling that has already been applied to the metrics, 
+%   so that the metrics will match the actual font.
+%   \changes{1.935}{2016/02/04}{Emitting \texttt{DESIGNSIZE} here 
+%     instead. Previously it was hardwired to 10.0, which could be 
+%     incorrect. (LH)}
 %    \begin{macrocode}
 \def\first_pl_raw_glyph#1#2#3#4{
+   \store_length_without_measure\a_macro{#3}
+   \out_line{(DESIGNSIZE~R~\a_macro)}
    \out_line{(DESIGNUNITS~R~\make_factor{#4})}
+   \out_line{}
    \let\setscaledrawglyph=\pl_raw_glyph
    \pl_raw_glyph{#1}{#2}{#3}{#4}
 }
diff --git a/source/fimain.dtx b/source/fimain.dtx
index 106f62a..5d2c723 100644
--- a/source/fimain.dtx
+++ b/source/fimain.dtx
@@ -1746,6 +1746,7 @@
 % 
 % \begin{macro}{\saved_scale}
 % \begin{macro}{\saved_mapfont}
+%   \changes{1.935}{2016/02/04}{Changed syntax to not include a unit. (LH)}
 % \begin{macro}{\saved_raw}
 % \begin{macro}{\saved_rule}
 % \begin{macro}{\saved_special}
@@ -1770,6 +1771,9 @@
 %     |\saved_push|\\
 %     |\saved_pop|
 %   \end{isyntax}
+%   
+%   \textbf{Note.} Before v\,1.935, the \meta{designsize} used to 
+%   include a unit, but now it is just the raw \meta{factor}.
 %    \begin{macrocode}
 \let\saved_scale\x_relax
 \let\saved_mapfont\x_relax
@@ -1987,6 +1991,7 @@
 %    \begin{macrocode}
 \def\setscaledrawglyph#1#2#3#4#5#6#7#8#9{
    \if_undefined{g-\glyph_name_modifier{#1}}\then
+      \store_length_without_measure\b_macro{#3}
       \eval_expr{#4}
       \ifnum \result=\one_thousand
          \let\a_macro\identity_one
@@ -2012,13 +2017,7 @@
          {\the\c_count}
          {\the\d_count}
          {\a_macro{\saved_raw{#2}{\the\result}{#1}}}
-         {\a_macro{
-            \ifdim #3=10\p@
-               \saved_mapfont_tenpt{#2}
-            \else
-               \saved_mapfont{#2}{#3}
-            \fi
-         }}
+         {\a_macro{\saved_mapfont{#2}{\b_macro}}}
       }
    \fi
 }
@@ -3121,13 +3120,12 @@
 %      \cs{mathchardef}s. (LH)}
 %    \begin{macrocode}
 \def\vpl_mapfont#1#2{
-   \a_dimen=#2
    \if_undefined{\the\mapfont_scaling-#1}\then
       \global\x_cs\mathchardef{\the\mapfont_scaling-#1}=\font_count
       \x_cs\xdef{f-\the\font_count}{\the\mapfont_scaling-#1}
       \out_line{(MAPFONT~\vpl_int\font_count\space
          (FONTNAME~#1)~
-         (FONTDSIZE~\vpl_real\a_dimen)~
+         (FONTDSIZE~R~#2)~
          (FONTAT~\vpl_real\mapfont_scaling))}
       \record_usage{#1}
       \global\advance\font_count by 1


More information about the fontinst mailing list