[XeTeX] Detect, whether a font contains a certain character

Jonathan Kew jfkthame at googlemail.com
Tue Nov 29 08:40:13 CET 2011


On 28 Nov 2011, at 08:06, Heiko Oberdiek wrote:

> \catcode`\{=1
> \catcode`\}=2
> \catcode`\^=7
> \showboxdepth=10000
> \showboxbreadth=10000
> \tracingonline=1
> \font\rm=cmr10\relax
> \rm
> \setbox0=\hbox{\kern1pt^^^^018e}
> \showbox0
> \csname @@end\endcsname\end
> 
> And where is the inserted ".notdef" glyph?

There won't be one with cmr10: that's a TFM font, so missing chars get dropped, just like in standard TeX. But if \rm is a native truetype/opentype font, it'll be there:

\catcode`\{=1
\catcode`\}=2
\catcode`\^=7
\showboxdepth=10000
\showboxbreadth=10000
\scrollmode
\tracingonline=1
\font\rm="Trebuchet MS"
\rm
\setbox0=\hbox{\kern1pt^^^^018e}
\showbox0
\showthe\wd0
\end

-->

This is XeTeX, Version 3.1415926-2.3-0.9997.5 (TeX Live 2011)
 restricted \write18 enabled.
entering extended mode
(./x.tex
Missing character: There is no Ǝ in font Trebuchet MS!
> \box0=
\hbox(5.45789+0.0)x6.0
.\kern 1.0
.\rm Ǝ

! OK.
l.11 \showbox0
              
> 6.0pt.
l.12 \showthe\wd0
                 
 )

Which tells us that the width of .notdef in Trebuchet MS is 5pt, but tells us nothing (from within the document - the "Missing character" message tells us externally, of course) about the presence or absence of U+018E in this font.

> 
>>> the problem is rather that a existing glyph can have width zero
>>> (not likely in your case) and that there is a warning in the .log file.
>>> See my examples.
>> 
>> Assuming the OP is interested in "native" truetype/opentype fonts, not .tfm-based fonts, \XeTeXcharglyph is the simple answer.
> 
> In case of \ifnum\XeTeXfonttype>0 there is a better test.
> 
> Or what do you suggest for a general test of glyph existence?

For native Unicode fonts, as I said, use \XeTeXcharglyph. For TFM fonts, I don't think the question is particularly interesting or worthwhile. TFM fonts do not have a standard encoding, so querying them for a particular "character code" is meaningless - you have to know the encoding of the font you're using in order to do anything useful with it, in which case you should already know what characters it supports.

JK




More information about the XeTeX mailing list