summaryrefslogtreecommitdiff
path: root/macros/luatex/optex/pdfuni-string.opm
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-02-13 03:00:51 +0000
committerNorbert Preining <norbert@preining.info>2020-02-13 03:00:51 +0000
commit8379012d545fd6a59fae8842d97d14ec0c2b27d7 (patch)
tree740889c25a2f4eb83c4433954ec856b568728575 /macros/luatex/optex/pdfuni-string.opm
parent2dbfa6c67f1c50ff228326c6ec6cccfdecb61735 (diff)
CTAN sync 202002130300
Diffstat (limited to 'macros/luatex/optex/pdfuni-string.opm')
-rw-r--r--macros/luatex/optex/pdfuni-string.opm63
1 files changed, 63 insertions, 0 deletions
diff --git a/macros/luatex/optex/pdfuni-string.opm b/macros/luatex/optex/pdfuni-string.opm
new file mode 100644
index 0000000000..d9732472f2
--- /dev/null
+++ b/macros/luatex/optex/pdfuni-string.opm
@@ -0,0 +1,63 @@
+%% This is part of OpTeX project, see http://petr.olsak.net/optex
+
+\_codedecl \pdfunidef {PDFunicode strings for outlines <2019-05-21>}
+
+\_edef\_octalprint#1#2{\_noexpand\_directlua{% #1=character-code #2=character
+ if ('#2'>='A' and '#2'<='Z') or ('#2'>='a' and '#2'<='z') then
+ tex.print(string.format('000\_pcent s',"#2"))
+ else
+ tex.print(string.format('\_pcent 03o\_nbb\_pcent03o',#1/256,#1\_pcent256))
+ end
+}}
+\_def\_pdfunidef#1#2{%
+ \_begingroup
+ \_catcode`\\=12 \_let\\=\_nbackslash
+ \_ea\_def\_ea#1\_ea{\_detokenize\_ea{#2}}%
+ \_ea\_replstring\_ea#1\_ea{\\}{\_pdfunidefA}%
+ \_edef#1{#1 ^}\_replstring#1{ ^}{}% \TeX /u -> \TeX/u
+ \_replstring#1{ }{{ }}% text text -> text{ }text
+ \_edef\_out{\\376\\377}%
+ \_ea\_pdfunidefB#1^% text -> \_out in octal
+ \_ea
+ \_endgroup
+ \_ea\_def\_ea#1\_ea{\_out}
+}
+\_def\_pdfunidefA #1 #2{\\#1\_ifx/#2/\_else\_space \_ea#2\_fi}
+\_def\_pdfunidefB#1{%
+ \_ifx^#1\_else
+ \_tmpnum=`#1
+ \_ea\_ifx\_nbackslash#1\_pdfunidefC{#1#1}\_else\_pdfunidefC{#1}\_fi
+ \_ea\_pdfunidefB \_fi
+}
+\_def\_pdfunidefC #1{\_edef\_out{\_out \\\_ea\_octalprint\_ea{\_the\_tmpnum}{#1}}}
+
+\public \pdfunidef ;
+
+\_endcode % --------------------------------
+
+There are only two encodings for PDF strings (used in PDFoutlines, PDFinfo
+etc.). First one is PDFDocEncoding which is one-byte encoding, but most
+Czech or Slovak characters are missing here.
+
+The second encoding is PDFunicode encoding wich is implemented in this file.
+This encoding is TeX-dicomfortable, because it looks like
+
+\376\377\000C\000v\000i\001\015\000e\000n\000\355\000\040\000j\000e\000\040
+\000z\000\341\000t\001\033\001\176
+
+This example is real encoding of the string "Cvičení je zátěž". You can see
+that this is UTF-16 encoding (two bytes per character) with two starting
+bytes FEFF. Moreover, each byte is encoded by three octal digits preceded by
+backslash. The only exception is the visible ASCII character encoding: such
+a character is encoded by its real byte preceded by \000.
+
+The pdfuni.tex macro implements the command
+
+\pdfunidef\macro{string}
+
+We implemented the octal string printing of one character using \directlua.
+The input string is preprocessed: detokenized, converted `\word /` to
+`\word/` (used in logos) preprocessed spaces using \replstring and then the
+\_pdfunidefB is repeated on each character. It calls the `\directlua` chunk
+to print octal numbers.
+