On Thu, 6 Jul 2023 at 08:04, Max Chernoff
Hi Luigi,
I've attached a series of font-related patches.
Patch 1:
Even if you set "tounicode = 1" at the top level of a font, "tounicode = <something>" for each character, and run "pdf.setgentounicode(1)", LuaTeX will only write out a /ToUnicode entry if the document uses "\pdfextension glyphtounicode" somewhere.
A minimal(-ish) example:
% \pdfextension glyphtounicode{fake!}{0000}
\newcount\fontid \directlua{ local height = tex.sp("8bp") local width = tex.sp("36bp")
pdf.setgentounicode(1)
local inner = font.define { name = "fake-font-inner", parameters = {}, properties = {}, encodingbytes = 0, psname = "none", tounicode = 1, characters = { [1] = { width = width, height = height, depth = 0, tounicode = { 0x1f986 }, } } }
tex.count.fontid = font.define { name = "fake-font-virtual", parameters = {}, properties = {}, characters = { [string.byte"x"] = { width = width, height = height, depth = 0, commands = { { "slot", 1, 1 } }
} }, type = "virtual", fonts = {{ id = inner }}, }
callback.register( "provide_charproc_data", function (mode, font_id, slot) if mode == 2 then return pdf.immediateobj("stream", "36 0 d0 0 0 36 8 re f"), 36 elseif mode == 3 then return 1 / 10 end end ) }
x{\setfontid\fontid x}x
\bye
You would expect that copying the black box would give you a duck, but this only happens if the first line is uncommented. The first patch should fix this.
(sorry for the long delay) Iiuc, the problem is that in this case glyph_unicode_tree is NULL ( \pdfextension glyphtounicode{fake!}{0000} create a new glyph_unicode_tree if is the case, by mean of def_tounicode). So perhaps it's better if we export a new function glyph_unicode_new(void) at the lua level that allocate ,if the case, a new glyph_unicode_tree, leaving do_write_tounicode as is now. -- luigi