bug-texinfo
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LuaTeX PDF outline Unicode strings support


From: Masamichi HOSODA
Subject: LuaTeX PDF outline Unicode strings support
Date: Tue, 16 Feb 2016 01:31:00 +0900 (JST)

Hello,

I've made LuaTeX (both 0.80 and 0.85+)
PDF outline Unicode strings support patch.

ChangeLog

2016-02-XX  Masamichi Hosoda  <address@hidden>

        * doc/texinfo.tex: Add LuaTeX PDF outline Unicode strings support.
        (UTF16oct): New Lua function.
        (\pdfexcapestring): New macro.
        (\dopdfoutline): Add Unicode support for LuaTeX.
--- texinfo.tex.org     2016-02-16 00:58:09.264846200 +0900
+++ texinfo.tex 2016-02-16 01:07:59.672069100 +0900
@@ -1106,6 +1106,35 @@
 
 \ifx\luatexversion\thisisundefined
 \else
+  % Escape PDF strings UTF-8 to UTF-16
+  \begingroup
+    \catcode`\%=12
+    \directlua{
+      function UTF16oct(str)
+        tex.sprint(string.char(0x5c) .. '376' .. string.char(0x5c) .. '377')
+        for c in string.utfvalues(str) do
+          if c < 0x10000 then
+            tex.sprint(
+              string.format(string.char(0x5c) .. string.char(0x25) .. '03o' ..
+                            string.char(0x5c) .. string.char(0x25) .. '03o',
+                            (c / 256), (c % 256)))
+          else
+            c = c - 0x10000
+            local c_hi = c / 1024 + 0xd800
+            local c_lo = c % 1024 + 0xdc00
+            tex.sprint(
+              string.format(string.char(0x5c) .. string.char(0x25) .. '03o' ..
+                            string.char(0x5c) .. string.char(0x25) .. '03o' ..
+                            string.char(0x5c) .. string.char(0x25) .. '03o' ..
+                            string.char(0x5c) .. string.char(0x25) .. '03o',
+                            (c_hi / 256), (c_hi % 256),
+                            (c_lo / 256), (c_lo % 256)))
+          end
+        end
+      end
+    }
+  \endgroup
+  \def\pdfescapestring#1{\directlua{UTF16oct('\luaescapestring{#1}')}}
   \ifnum\luatexversion>84
     % For LuaTeX >= 0.85
     \def\pdfdest{\pdfextension dest}
@@ -1312,18 +1341,23 @@
     % page number.  We could generate a destination for the section
     % text in the case where a section has no node, but it doesn't
     % seem worth the trouble, since most documents are normally structured.
-    \edef\pdfoutlinedest{#3}%
-    \ifx\pdfoutlinedest\empty
-      \def\pdfoutlinedest{#4}%
-    \else
-      \txiescapepdf\pdfoutlinedest
-    \fi
-    %
-    % Also escape PDF chars in the display string.
-    \edef\pdfoutlinetext{#1}%
-    \txiescapepdf\pdfoutlinetext
-    %
-    \pdfoutline goto name{\pdfmkpgn{\pdfoutlinedest}}#2{\pdfoutlinetext}%
+    {
+      \ifx\luatexversion\thisisundefined \else
+        \turnoffactive % LuaTeX can use Unicode strings for PDF
+      \fi
+      \edef\pdfoutlinedest{#3}%
+      \ifx\pdfoutlinedest\empty
+        \def\pdfoutlinedest{#4}%
+      \else
+        \txiescapepdf\pdfoutlinedest
+      \fi
+      %
+      % Also escape PDF chars in the display string.
+      \edef\pdfoutlinetext{#1}%
+      \txiescapepdf\pdfoutlinetext
+      %
+      \pdfoutline goto name{\pdfmkpgn{\pdfoutlinedest}}#2{\pdfoutlinetext}%
+    }
   }
   %
   \def\pdfmakeoutlines{%

reply via email to

[Prev in Thread] Current Thread [Next in Thread]