[XeTeX] XeTeX, fontspec, OTF, and fontdimens

Khaled Hosny khaledhosny at eglug.org
Sun Feb 20 21:21:31 CET 2011


On Sun, Feb 20, 2011 at 01:42:28PM -0600, mskala at ansuz.sooke.bc.ca wrote:
> On Sun, 20 Feb 2011, Khaled Hosny wrote:
> > OK, this sounds like a fontspec bug to me, can you file a bug against
> > fontspec (else I'll try to do myself).
> 
> Okay, I'll file one.
> 
> > 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 :)
> 
> I can't find a way to edit that flag in FontForge; it appears that
> FontForge sets it behind the scenes when saving a font if and only if all
> glyphs in the font have exactly the same width.
> 
> Fonts like mine are not really monospace in that sense - the basic Latin
> glyphs are one width, the CJK characters are twice that width, and there
> exist combining characters that are zero width.  Other widths might even
> be possible too, when we get into the more esoteric CJK features such as
> vertical forms and one-third-width characters.  Such a font might be
> better described as grid-spaced than mono-spaced.
> 
> Thus, I don't think FontForge would flag the fonts as monospace, and I
> found some comments on the Web suggesting that indeed it shouldn't; some
> rasterizers will break if the monospace flag is set and the font doesn't
> have absolutely every glyph the same width.
> 
> So I think that although it might be nice to make XeTeX read that flag, it
> would also be good if there were a clean way to tell XeTeX and/or fontspec
> to treat a font as monospace for the purposes of the fontdimen defaults,
> regardless of the state of the flag.

OK, the inevitable luatex post (I've been resisting for long :p):

\documentclass{article}
\usepackage{fontspec}

\directlua{
 local function monospace(tfmdata, value)
     if value then
         tfmdata.parameters.space_stretch = 0
         tfmdata.parameters.space_shrink  = 0
         tfmdata.parameters.extra_space   = 0
     end
 end
 table.insert(fonts.triggers,"monospace")
 fonts.initializers.base.otf.monospace = monospace
 fonts.initializers.node.otf.monospace = monospace
}

\setmainfont[RawFeature={monospace=yes}]{Free Serif}

\begin{document}
\noindent
x x x\\
xxxxx\\
x x x\\
xxxxx

Interword space:  \the\fontdimen2\font.

\Large
\noindent
x x x\\
xxxxx\\
x x x\\
xxxxx

Interword space:  \the\fontdimen2\font.
\end{document}

Can you try with your font and see if it heps?

Regards,
 Khaled

-- 
 Khaled Hosny
 Egyptian


More information about the XeTeX mailing list