6

I'm trying to access a glyph, but it's only mentioned in the "Basic Latin and Latin 1" set for a font. The glyph has no name or unicode ID, but it does have a glyph ID or GID. fontspec doesn't mention possibilities for using this glyph. Neither does Adobe in the adobe feature file syntax: http://www.adobe.com/devnet/opentype/afdko/topic_feature_file_syntax.html#2.f

I'd still like to be able to access a glyph through its ID, since it's the only way I can access it (I think).

My specific case requires to access the glyph ID 554 from Stevens Titling Pro Sable Brush. I will only post this font if it's strictly necessary, since I don't like to distribute these fonts to the wide world.

I posted an MWE containing another (free) font. This is not the font I intend to use, but perhaps a starting point to try and access glyphs manually.

\documentclass{article}

\usepackage{fontspec}
\setmainfont{EB Garamond}

\parindent=0pt
\begin{document}

Some text int EB Garamond. How can I access glyph 123 now?

\end{document}
1010011010
  • 6,357
  • 2
    What's the ID of the glyph? – egreg Nov 10 '14 at 23:58
  • Surely "Basic Latin and Latin 1" is entirely covered by unicode? Can something be in these ranges and not have a unicode ID? – cfr Nov 11 '14 at 00:24
  • @egreg The glyph is not from EB Garamond. This probably led to confusion. The glyph ID is 554 (as taken from Adobe InDesign), but neither FontForge nor FontExplorer Pro can confirm this (they both show an undefined glyph for this ID). The font furthermore isn't made by Adobe which may or may not contribute to this situation. – 1010011010 Nov 11 '14 at 08:51
  • 1
    And how are we supposed to help if you hide all information? If you use XeLaTeX, then \XeTeXglyph554\relax could be the answer. I'm downvoting this question, hoping it will be improved. – egreg Nov 11 '14 at 08:56
  • @cfr This may clarify your questions: http://i.imgur.com/R7ysuPZ.png – 1010011010 Nov 11 '14 at 08:58
  • @egreg Sorry. I've left the question as broad as possible to put off the necessity of actually posting the font, which I've received exceedingly hostile remarks for previously. Your \XeTeXglyph554\relax was already the answer! – 1010011010 Nov 11 '14 at 09:04
  • I was not referring to posting the font, but to improve the information in the question. Downvote retracted, of course. Good answer, too! – egreg Nov 11 '14 at 10:42

2 Answers2

13

The method for accessing a specific glyph using fontspec depends on the engine used.

With XeTeX, an implementation is \XeTeXglyph554\relax (Thanks egreg).

An example document, using the inaccessible glyph with ID 554 from Stevens Titling Pro, Sable Brush, is shown below:

http://i.imgur.com/ALUoPcg.png?1

\documentclass{article}
\usepackage{fontspec}
\setmainfont{StevensTitlPro-SableBrush.otf}
\begin{document}
\XeTeXglyph554\relax
\end{document}

In LuaTeX, there appears to be no pre-defined high level command to access a glyph by its (OpenType) glyph number. However, one can create a Lua-based function to provide this access method.

Some example implementation for accessing the same glyph:

http://i.imgur.com/ALUoPcg.png?1

\documentclass{article}
\usepackage{fontspec}
\usepackage{luacode}  % provides 'luacode'  environment
\setmainfont{StevensTitlPro-SableBrush.otf}

\begin{luacode}
function LuaTeXglyph(charNo)
  local fontNo=font.current()
  local f=font.getfont(fontNo)
  local i
  local v
  local found=false
  for i,v in pairs(f.characters) do
   if v.index == charNo
   then
      tex.print( '\\char '..i..' ' )
      found=true
      break
    end
  end
  if not found
  then
    tex.error( 'font has no glyph '..charNo )
  end
end
\end{luacode}

\newcommand*{\LuaTeXglyph}[1]{%
  \directlua{LuaTeXglyph(#1)}
}

\begin{document}
\LuaTeXglyph{554}
\end{document}
Mico
  • 506,678
1010011010
  • 6,357
  • Very nice! This is a really useful posting, as I've noticed that there are quite a few Opentype fonts and font families that feature glyphs that are neither UTF8-encoded nor feature an Opentype-style "handle". – Mico Nov 11 '14 at 09:42
  • I've taken the liberty of editing your write-up on the Lua-side of things. I hope you don't mind. – Mico Nov 11 '14 at 09:42
9

This is just an alternative to the above luatex solution of looping over the font table. Instead, we may also use the information from the raw font (with fontloader), where the glyphs are still accessible on the top level, and translate the internal glyph name into a char code via luaotfload's function slot_of_name:

\documentclass{article}
\usepackage{fontspec,luacode}
\setmainfont{EB Garamond 12}
\begin{luacode}
function luatexglyph(glyph)
  local f  = fonts.hashes.identifiers[font.current()]
  local ff = fontloader.open(f.filename)
  local g  = ff.glyphs[glyph]
  local n  = luaotfload.aux.slot_of_name(font.current(),g.name)
  if n then
    tex.sprint('\\char' ..n.. ' ');
  else
    tex.error('font has no glyph '.. glyph)
  end
  fontloader.close(ff)
end
\end{luacode}
\def\LuaTeXglyph#1{\directlua{luatexglyph "#1"}}
\begin{document}
\LuaTeXglyph{1875}
\LuaTeXglyph{1895}
\LuaTeXglyph{1897}
\end{document}

Th

Robert
  • 14,181
  • 1
  • 52
  • 77