Hi, Hans:

On Tue, May 12, 2009 at 11:22 PM, Hans Hagen <pra...@wxs.nl> wrote:
> \setupbodyfont[myzhfont] \dorecurse{10000}{{hello
> {\switchtobodyfont[myzhfont] 你好}}\par}
> so it's probably also an operating system issue (caching files in mem, disk 
> access etc)

After debugging for half an hour in the morning, finally I know why
this is so slow on both XeTeX and pdfTeX.
This problem is not an operating system issue, But a ConTeXt "feature".

in font-mkii, you use the following to define a actual font
(\definefontlocal and \definefontglobal):
  {\expandafter\xdef\csname#1\endcsname  % ! ! ! ! not needed in luatex ! ! ! !
     {\noexpand\csname#1:\endcsname
      \noexpand\reactivatefont{\somefontname}{\fontfile}}%

For example, in the previous example, it will define a lot of fonts,
like \*myzhfont12ptmmexrm*: , is defined as
\reactivatefont{cmex10}{lmex10}. When define that font, a macro
\*myzhfont12ptmmexrm* is defined to select the \*myzhfont12ptmmexrm* :
font.
\*myzhfont12ptmmexrm* =\csname *myzhfont12ptmmexrm* :\endcsname
\reactivefont{cmex10}{lmex10}
TeX then expand your reactivatefont macros to lmex10 at 12.0pt. So the
\*myzhfont12ptmmexrm*: font will assigned to lmex10 at 12.0pt. This is
quite right for definition.

However, after switching the font, the problems occurs:
it tries to call \*myzhfont12ptmmexrm* macro. the macro then expands to
\csname *myzhfont12ptmmexrm* :\endcsname \reactivefont{cmex10}{lmex10}
then to
\*myzhfont12ptmmexrm* :\reactivefont{cmex10}{lmex10}
and here TeX tries to do the following thing:
TeX select the font \*myzhfont12ptmmexrm*:, which is lmex10 at 12pt,
then *changing* into that font environment in order to *typeset*
\reactivefont.  it then expand the macro of reacitve font, but found
nothing to typeset...

what's worse, this will occur on every real fonts in the definition.
So in fact TeX will switching dozens of fonts into the *current* font
for a "\switchtobodyfont" call, in order to typeset nothing. And
that's why ConTeXt is so slow on typeface changing.

The solution to this bug (or feature?) is quite easy, just use \font
to define the \*myzhfont12ptmmexrm*: font, but pay attention not to
switch the current font to \*myzhfont12ptmmexrm*: . Since it is quite
slow to switch to dozens of font for one \switchtobodyfont call even
in Knuth TeX.




Yue Wang









> so it's probably also an operating system issue (caching files in mem, disk
> access etc)
>
> -----------------------------------------------------------------
>                                          Hans Hagen | PRAGMA ADE
>              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
>                                             | 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://tex.aanhet.net
> archive  : https://foundry.supelec.fr/projects/contextrev/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
>
___________________________________________________________________________________
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to