[Dev-luatex] Unicode in \pdfinfo

Jonathan Sauer Jonathan.Sauer at silverstroke.com
Wed Jul 2 09:55:33 CEST 2008


Hello, 

> Not to forget: Some characters inside (...) need to be 
> escaped (`\', unmatched `(' and `)', line ends, ...)

Of course (although according to the PDF spec, line ends need not be
escaped):


local char =	unicode.utf8.char
local write =	tex.write

function convertPDFstring(s)
	-- UTF-16 BOM
	write(char(0x110000 + 254, 0x110000 + 255))
	
	-- The string
	for c in string.utfvalues(s) do
		-- Escape (, ) and \. Since the string is read before it
is decoded,
		-- do not encode the escape sequence as UTF-16, but only
escape the
		-- second byte of the UTF-16 byte pair
		if c == 40 then
			write(char(0x110000, 0x110000 + 92, 0x110000 +
40))
		elseif c == 41 then
			write(char(0x110000, 0x110000 + 92, 0x110000 +
41))
		elseif c == 92 then
			write(char(0x110000, 0x110000 + 92, 0x110000 +
92))
		elseif c < 0x10000 then
			write(char(0x110000 + c / 256, 0x110000 + c %
256))
		else
			c = c - 0x10000
			local c1 = c / 1024 + 0xD800
			local c2 = c % 1024 + 0xDC00
			write(char(	0x110000 + c1 / 256,
						0x110000 + c1 % 256,
						0x110000 + c2 / 256,
						0x110000 + c2 % 256))
		end
	end
end


Jonathan



More information about the dev-luatex mailing list