Hi,

I finally decided to start an experiment that I had on my todo list for a while: dynamically scaling fonts. Below is an example of usage (plus some comment). In that example some 2*200 different font sizes are used which in mkiv demands 400 font definitions. This costs time and memory. The example below runs (on my old laptop) in less than 2 seconds and only uses two instances. I bet that our CJK users will love it.

I post it because:

(1) I need to discuss the impact with Wolfgang ... how do we integrate this. We can for instance define some sizes (\tfa \tfb ...) differently.

(2) I want to see if average performance improves on huge documents with many fonts / sizes (that is for Massimiliano to test).

(3) Are there side effects? It does work for math (rather neat trickery) but maybe we need an additional configration for that.

(4) I considered several variants but for now use a low level \glyphscale command that takes a number (in goodl old tex tradition a scale of 1.0 is entered as 1000).

(5) The implementation can be improved a bit (performance wise). There is a bit more overhead involved but usually I can compensate that.

(6) It will not be backported to MKIV so one can only test in LMTX. it's a bit of a mix between engine and context features.

(7) There can be bugs (unforseen side effects, or typos in the somewhat quick patches in the source).

Consider it an experiment, but so far I'm rather satisfied,

Hans



%%%% EXAMPLE %%%%

\setuplayout[middle]

\setupbodyfont[pagella,10pt]

\setupalign[verytolerant,stretch]

\setupwhitespace[big]

\starttext

\startbuffer
\definescaledfont[bfe][scale=2000,style=bf]

\setuphead[chapter][style=\bfe]

\dostepwiserecurse {10} {2020} {10} {
    \title{Here we go #1!}
    \start
    \glyphscale#1\relax
    \setupinterlinespace
    \samplefile{ward}%
    \bf
    \samplefile{ward}
    \par
    \stop
    \page
}
\stopbuffer

\getbuffer

\title{Scaled fonts}

Although \CONTEXT\ is quite efficient with fonts there is always room for
improvement. However, after years of finetuning the font mechanisms there was not
that much room left. This made me think of a different approach to scaling.
Nowadays fonts seldom come in design sizes. Also, in \CONTEXT\ \MKIV\ and
therefore \LMTX\ we always had so called dynamic features: apply additional
features locally, although that comes with a small penalty in performance, it saves additional font instances. It is a good approach for the occasional small
stretch of glyphs, like small capped logos and such.

We now can also do dynamic font scaling, which means that we don't need to define a new font instance when the same feature set is used. Or course in addition to
this features one can still use the dynamic features. This means that for
instance chapter titling can use the bodyfont instance and just apply additional scaling. Although for a normal run the number of loaded fonts is normally small, and the number of instances also isn't that impressive it can happen in a large document that you end up with a few dozen. That number can now be reduced to half
a dozen.

Of course there can be side effects, whcich is why it's currently tagged as
experimental. There is also a small performance hit because we now need to track it but that is gained back because we load less fonts and have less glyph runs.
It even works in math, although there some different trickery is needed.

\typebuffer

\stoptext







-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to