2

I'm using Brill-Roman.otffont and with luatex I don't know how to access smallcaps glyphs from virtual fontloader.to_table returned table glyphs. There is no such index and I have no idea how to get that glyphs data. In Brill-Roman.lua there is such glyph (smallcaps D):

  [983164]={
   ["boundingbox"]=804,
   ["index"]=1146,
   ["name"]="D.c2sc",
   ["unicode"]=68,
   ["width"]=559,
  },

NWE

\documentclass{article}
\usepackage{luacode}
\usepackage{fontspec}
\setmainfont[
  Extension=.otf,
  UprightFont=*-Roman,
  UprightFeatures={
    SizeFeatures={
      { Size={9-},
          SmallCapsFeatures={Letters=UppercaseSmallCaps,LetterSpace=5.0},
          WordSpace={1,1.5,0.6}
      }
    }
  }
]{Brill}

\begin{luacode*}

local function get_real_char(font_idx, glyph_idx)
    local real_font = font.getfont(font_idx)
    local myfont = fontloader.open(real_font.filename)
    if myfont then
        metrics = fontloader.to_table(myfont)
        print ("IS_IT?", metrics.glyphs[glyph_idx])
        fontloader.close(myfont)
    end    
end

function print_glyph(h)
    for n in node.traverse(h) do
      if n.id == node.id("glyph") then
        print ("GLYPH:", n.char, n.font)
        get_real_char(n.font, n.char)
      elseif n.id == node.id("hlist") or n.id == node.id("vlist") then
        print_glyph(n.head)
      end
    end
  return h  
end  
luatexbase.add_to_callback("pre_output_filter", print_glyph, "print glyph")            
\end{luacode*}

\begin{document}
\textsc{Data} font
\end{document}

And here is the output:

This is LuaTeX, Version 1.07.0 (TeX Live 2018/W32TeX)  
  (format=lualatex 2018.6.5)  10 JUL 2018 09:43
....
GLYPH:     983164  30
IS_IT?  nil
GLYPH:  983574  30
IS_IT?  nil
GLYPH:  983593  30
IS_IT?  nil
GLYPH:  983574  30
IS_IT?  nil
GLYPH:  102     29
IS_IT?  table: 09814140
GLYPH:  111     29
IS_IT?  table: 0D4A73B8
GLYPH:  110     29
IS_IT?  table: 0E93DCF8
GLYPH:  116     29
IS_IT?  table: 106CDC88

I printed out all the table returned by fontloader and there was nothing with 983164, but there was a lot info with name D.c2sc. It seems it is already remaped to some lookup tables. I don't see any possibilities to attache files here so I can't add that font.
Question how to get n.char data (e.g. "name", "unicode") if it is not in fontloader returned virtual font table.

  • The documentation of luatex says that with the fontloader library "the font is automatically re-encoded, so that the metrics table for TrueType and OpenType fonts is using Unicode for the character indices". This imho means that you need to access the glyph by unicode index. Be aware that the fontloader library is not the luaotfload fontloader and I also don't think that luaotfload uses it. – Ulrike Fischer Jul 10 '18 at 9:56
5

The table has to be indexed with the character index from the OTF file, not with the unicode codepoint. You can access the codepoint using the LuaTeX font table: Your real_font table contains a character hash indexed by the glyph indices used by LuaTeX and stored in the glyph nodes. In there, every character table has a index field which gives the index in the font file. This index has to be used for accessing the fontloader table. You might want to avoid to_table, the table gets very big.

Most information is also available in the LuaTeX font table directly, so you shouldn't need fontloader to begin with. Like Ulrike Fischer mentioned in a comment, the fontloader library is not normally used for anything, especially not by the luaotfload fontloader.

\documentclass{article}
\usepackage{luacode}
\usepackage{fontspec}
\setmainfont[
  Extension=.ttf,
  UprightFont=*-Roman,
  UprightFeatures={
    SizeFeatures={
      { Size={9-},
          SmallCapsFeatures={Letters=UppercaseSmallCaps,LetterSpace=5.0},
          WordSpace={1,1.5,0.6}
      }
    }
  }
]{Brill}

\begin{luacode*}

local function get_real_char(font_idx, glyph_idx)
    local real_font = font.getfont(font_idx)
    local myfont = fontloader.open(real_font.filename)
    if myfont then
        print ("Name: ", myfont.glyphs[real_font.characters[glyph_idx].index].name)
        fontloader.close(myfont)
    end    
    print ("Unicode without fontloader: ", real_font.characters[glyph_idx].unicode)
end

function print_glyph(h)
    for n in node.traverse(h) do
      if n.id == node.id("glyph") then
        print ("GLYPH:", n.char, n.font)
        get_real_char(n.font, n.char)
      elseif n.id == node.id("hlist") or n.id == node.id("vlist") then
        print_glyph(n.head)
      end
    end
  return h  
end  
luatexbase.add_to_callback("pre_output_filter", print_glyph, "print glyph")            
\end{luacode*}

\begin{document}
\textsc{Data} font
\end{document}
| improve this answer | |
  • Marcel, nice answer! I needed to_table to get character information frompfb files when luatex uses tfm files. I just don't need it for modern fonts. – Linuxss Jul 11 '18 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.