diff options
| -rw-r--r-- | luaotfload-auxiliary.lua | 38 | ||||
| -rw-r--r-- | tests/pln-aux-4.tex | 40 | 
2 files changed, 78 insertions, 0 deletions
| diff --git a/luaotfload-auxiliary.lua b/luaotfload-auxiliary.lua index a5f22dd..f7886be 100644 --- a/luaotfload-auxiliary.lua +++ b/luaotfload-auxiliary.lua @@ -174,6 +174,44 @@ end  aux.do_if_glyph_else = do_if_glyph_else +--- this one is approximately “name_to_slot” from the microtype +--- package + +--- string -> (int | false) +local codepoint_of_name = function (glyphname) +  local fontdata = identifiers[font.current()] +  if fontdata then +    local unicode = fontdata.resources.unicodes[glyphname] +    if unicode and type(unicode) == "number" then +      return unicode +    else +      return unicode[1] --- again, does that even happen? +    end +  end +  return false +end + +aux.codepoint_of_name = codepoint_of_name + +--- inverse of above + +local indices + +--- int -> (string | false) +local name_of_codepoint = function (codepoint) +  if not indices then --- this will load the glyph list +    local unicodes = fonts.encodings.agl.unicodes +    indices = table.swapped(unicodes) +  end +  local glyphname = indices[codepoint] +  if glyphname then +    return glyphname +  end +  return false +end + +aux.name_of_codepoint = name_of_codepoint +  -----------------------------------------------------------------------  ---                 features / scripts / languages  ----------------------------------------------------------------------- diff --git a/tests/pln-aux-4.tex b/tests/pln-aux-4.tex new file mode 100644 index 0000000..b025561 --- /dev/null +++ b/tests/pln-aux-4.tex @@ -0,0 +1,40 @@ +\input luaotfload.sty + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% unicode character mappings +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\font\ptserifregular = file:PTF55F.ttf \ptserifregular + +%% here we map the function luaotfload.aux.name_of_codepoint +%% on a short text, printing a list of letters, their codepoints +%% and names (as specified in the Adobe Glyph List). + +\directlua{ +  local aux = luaotfload.aux +  local cbk = function (str) +    if string.match(str, "^EOF") then +      luatexbase.remove_from_callback("process_input_buffer", "weird") +      return [[the end!]] +    end +    local res = { } +    for chr in string.utfcharacters(str) do +      local val = unicode.utf8.byte(chr) +      local line = chr .. " <> " .. tostring(val) +      line = line .. " <> " .. (aux.name_of_codepoint(val) or "") +      res[\string#res+1] = line +    end +    return table.concat(res, [[\endgraf]]) +  end + +  luatexbase.add_to_callback("process_input_buffer", cbk, "weird") +} + +Я узнал что у меня +Есть огромная семья +И тропинка и лесок +В поле каждый колосок + +EOF + +\bye | 
