[Dev-luatex] Unicode in \pdfinfo
Jonathan Sauer
Jonathan.Sauer at silverstroke.com
Tue Jul 1 10:00:17 CEST 2008
Hello,
> \pdfinfo doesn't seem to support Unicode, when I compile the
> attached example with luatex I get symbols like هصة
> instead of the proper (Arabic) Unicode strings.
> Shouldn't luatex default to Unicode here too?
The following function takes a LuaTeX (UTF-8) string and converts it
to UTF-16 with BOM and writes it to TeX (note that it requires
a recent beta of LuaTeX, cf. my mail to this list on 8th April 2008):
function convertPDFstring(s)
-- UTF-16 BOM
sprint(char(0x110000 + 254))
sprint(char(0x110000 + 255))
-- The string
for c in string.utfvalues(s) do
if c < 0x10000 then
sprint(char(0x110000 + c / 256))
sprint(char(0x110000 + c % 256))
else
c = c - 0x10000
local c1 = c / 1024 + 0xD800
local c2 = c % 1024 + 0xDC00
sprint(char(0x110000 + c1 / 256))
sprint(char(0x110000 + c1 % 256))
sprint(char(0x110000 + c2 / 256))
sprint(char(0x110000 + c2 % 256))
end
end
end
Usage (to set the title of the document):
\pdfinfo{/Title(\directlua0{convertPDFstring('my title')})}
Jonathan
More information about the dev-luatex
mailing list