[XeTeX] XeTeX, fontspec, OTF, and fontdimens

Khaled Hosny khaledhosny at eglug.org
Sun Feb 20 19:17:34 CET 2011


On Sun, Feb 20, 2011 at 10:38:28AM -0600, mskala at ansuz.sooke.bc.ca wrote:
> On Sun, 20 Feb 2011, Khaled Hosny wrote:
> > I lost track of what the original issue is, so I tried testing your
> > example with a little modification (removing default font feature and
> > using different font), and all monspaced fonts I tried are giving me,
> > guess what, monospaced results. Now I'm more confused.
> 
> In September of last year I had the issue that my inter-sentence spaces
> were wrong, with a commercial monospace font used at only one size.  I
> asked on this list and was told about the WordSpace option to fontspec,
> which also led me to discover the PunctuationSpace option.  That thread
> starts here:
>    http://tug.org/mailman/htdig/xetex/2010-September/018463.html
> 
> After that I made a general practice of using WordSpace and
> PunctuationSpace when using monospace fonts.  The new problem arose when,
> in a different project, I wanted to also scale the fonts with the LaTeX
> size commands.  So I wrote something like this:
> 
> \fontspec[WordSpace={1,0,0},PunctuationSpace=3]{FontName}
> 
> small text
> 
> \Large
> large text
> 
> and I found that the space in "large text" was too small - it was the
> same size as the space in "small text," not having scaled when the font
> scaled.
> 
> Everything subsequent to that flows from attempting to get that scenario
> to work without breaking other things.  The workaround of not using
> WordSpace allows the space to scale properly, but then it becomes
> stretchable.  Things that could remove the stretchability seem like they
> must be repeated for every size change.  And so on.
> 
> And it's less than perfect that I have to do any special configuration at
> all.  Non-stretchable word space equal to the fixed width of the font, and
> extra punctuation space of either zero or also equal to the fixed width of
> the font, are the only things that make sense as defaults for monospace
> fonts.  (Yes, it's easy to imagine someone could want something else, like
> double-justification of monospace, but that's not a sensible *default*.)
> If XeTeX can get monospace right by default for older fonts like CMTT but
> not for OpenType fonts, then XeTeX isn't as compatible with OpenType as I
> wish it could be.
> 
> My immediate problem is solved.  I can live with the workaround of using
> the everysel package to add code at every font selection to reset the
> stretchability and shrinkability to zero.  However, I think fontspec
> should be changed to remember the WordSpace settings as multipliers rather
> than as lengths, and to recalculate the multiplication at every size
> change.  That would allow my original code to work as intended; it would
> also be consistent with the current documentation of fontspec, which says
> the WordSpace settings are multipliers applied to the default widths,
> implying that the results of the multiplication change when the default
> widths change; and it would allow for others with more complicated
> requirements than mine to get what they want in a clean way (for instance,
> typesetting documents that contain monospace fonts but aren't ENTIRELY
> written with monospace fonts).
> 
> The same "remember the multiplier instead of the result of multiplication"
> should apply to PunctuationSpace as well.

OK, this sounds like a fontspec bug to me, can you file a bug against
fontspec (else I'll try to do myself).

> A more speculative wishlist item would be that the XeTeX engine should
> recognize when a font is monospace, and set the default fontdimens in that
> case to stretchability and shrinkability zero, extra space equal to word
> space.  A bitter argument exists about whether a sentence space in a
> monospace setting should be equal to one or two word spaces (I prefer
> two), but I don't think anybody would seriously claim that it should
> default to a non-integer number of word spaces; nonetheless 1.333 is the
> current default.  However, recognizing monospace fonts would require the
> XeTeX engine to be *able* to recognize monospace fonts, which seems to be
> a harder problem than it ought to be; and it could also break existing
> documents that rely on the existing, broken, default widths.

Interestingly, fontforge can recognise monowidth fonts and luaotfload
(or rather the code adapted from ConTeXt) makes use of it and sets the
respective fontdimens to zero, so may be it is not that hard after all.

OK, checking FF code, there is an isFixedPitch entry in 'post' and 'CFF'
tables that should be non-zero in monospaced fonts, so we just need
someone to come with a patch to make use of that :)

Regards,
 Khaled

-- 
 Khaled Hosny
 Egyptian


More information about the XeTeX mailing list