From fbf06cfeaa65ed3e3cee8275c892ae5b7c90e667 Mon Sep 17 00:00:00 2001
From: Dohyun Kim <nomosnomos@gmail.com>
Date: Mon, 29 Jun 2015 02:04:25 +0900
Subject: compatible-with-beamer revisited

---
 src/luaotfload-colors.lua | 18 ++++++++++++++----
 src/luaotfload.sty        | 20 --------------------
 2 files changed, 14 insertions(+), 24 deletions(-)

(limited to 'src')

diff --git a/src/luaotfload-colors.lua b/src/luaotfload-colors.lua
index ff4dc13..8035210 100644
--- a/src/luaotfload-colors.lua
+++ b/src/luaotfload-colors.lua
@@ -40,10 +40,9 @@ local setattribute          = nodedirect.set_attribute
 
 local texset                = tex.set
 local texget                = tex.get
-local texsettoks            = tex.settoks
-local texgettoks            = tex.gettoks
 
 local stringformat          = string.format
+local concat                = table.concat
 
 local otffeatures           = fonts.constructors.newfeatures("otf")
 local identifiers           = fonts.hashes.identifiers
@@ -311,6 +310,9 @@ node_colorize = function (head, current_color)
     return head, current_color
 end
 
+local pgf_extgs = { }
+luaotfload.pgf_extgs = pgf_extgs
+
 --- node -> node
 local color_handler = function (head)
     head = todirect(head)
@@ -324,7 +326,7 @@ local color_handler = function (head)
         local no_extgs = not tpr:find("/ExtGState<<.*>>")
         local pgf_loaded = no_extgs and luaotfload.pgf_loaded
         if pgf_loaded then
-            tpr = texgettoks(pgf_loaded) -- see luaotfload.sty
+            tpr = concat(pgf_extgs)
         end
 
         local t   = ""
@@ -336,7 +338,7 @@ local color_handler = function (head)
         end
         if t ~= "" then
             if pgf_loaded then
-                texsettoks("global", pgf_loaded, tpr..t)
+                pgf_extgs[#pgf_extgs+1] = t
             else
                 if no_extgs then
                     tpr = tpr .. "/ExtGState<<>>"
@@ -377,5 +379,13 @@ add_color_callback = function ( )
     end
 end
 
+tex.sprint("\\count255=\\catcode`@ \\catcode`@=11 ",
+    "\\ifdefined\\AtBeginDocument\\else\\def\\AtBeginDocument#1{#1}\\fi",
+    "\\AtBeginDocument{\\ifdefined\\pgfutil@everybye",
+    "\\directlua{luaotfload.pgf_loaded=true}\\begingroup",
+    "\\toks@{\\pgf@sys@addpdfresource@extgs@plain{\\directlua{tex.sprint(luaotfload.pgf_extgs)}}}",
+    "\\edef\\x{\\endgroup\\noexpand\\pgfutil@everybye{\\the\\toks@\\the\\pgfutil@everybye}}\\x",
+    "\\fi}\\catcode`@=\\count255 ")
+
 -- vim:tw=71:sw=4:ts=4:expandtab
 
diff --git a/src/luaotfload.sty b/src/luaotfload.sty
index 34f9a87..c9c9864 100644
--- a/src/luaotfload.sty
+++ b/src/luaotfload.sty
@@ -46,23 +46,3 @@
 \fi
 \RequireLuaModule{luaotfload-main}
 
-% for compatibility with beamer class, which loads pgf package.
-\ifcsname selectfont\endcsname
-  \AtBeginDocument{\@ifpackageloaded{pgfsys}{
-    \csname newtoks\endcsname\pgf@sys@pgf@resource@list@extgs@toks
-    \directlua{luaotfload.pgf_loaded=\the\allocationnumber}
-    \def\pgf@sys@pgf@resource@list@extgs{\the\pgf@sys@pgf@resource@list@extgs@toks}
-    \def\pgf@sys@addpdfresource@extgs@plain#1{\global\pgf@sys@pgf@resource@list@extgs@toks
-      \expandafter{\the\pgf@sys@pgf@resource@list@extgs@toks #1}}
-  }{}}
-\endinput\fi
-% under plain tex, tikz (pgf) should be loaded before luaotfload.
-\ifcsname pgf@sys@pgf@resource@list@extgs\endcsname\else\endinput\fi
-\count255=\the\catcode`@\relax
-\catcode`@=11\relax
-\newtoks\pgf@sys@pgf@resource@list@extgs@toks
-\directlua{luaotfload.pgf_loaded=\the\allocationnumber}
-\def\pgf@sys@pgf@resource@list@extgs{\the\pgf@sys@pgf@resource@list@extgs@toks}
-\def\pgf@sys@addpdfresource@extgs@plain#1{\global\pgf@sys@pgf@resource@list@extgs@toks
-  \expandafter{\the\pgf@sys@pgf@resource@list@extgs@toks #1}}
-\catcode`@=\the\count255\relax
-- 
cgit v1.2.3


From a3609f5cd2e3e7ec844adab7f7220f02599e4743 Mon Sep 17 00:00:00 2001
From: Dohyun Kim <nomosnomos@gmail.com>
Date: Mon, 29 Jun 2015 02:04:25 +0900
Subject: compatible-with-beamer revisited

---
 src/luaotfload-colors.lua | 18 ++++++++++++++----
 src/luaotfload.sty        | 20 --------------------
 2 files changed, 14 insertions(+), 24 deletions(-)

(limited to 'src')

diff --git a/src/luaotfload-colors.lua b/src/luaotfload-colors.lua
index ff4dc13..8035210 100644
--- a/src/luaotfload-colors.lua
+++ b/src/luaotfload-colors.lua
@@ -40,10 +40,9 @@ local setattribute          = nodedirect.set_attribute
 
 local texset                = tex.set
 local texget                = tex.get
-local texsettoks            = tex.settoks
-local texgettoks            = tex.gettoks
 
 local stringformat          = string.format
+local concat                = table.concat
 
 local otffeatures           = fonts.constructors.newfeatures("otf")
 local identifiers           = fonts.hashes.identifiers
@@ -311,6 +310,9 @@ node_colorize = function (head, current_color)
     return head, current_color
 end
 
+local pgf_extgs = { }
+luaotfload.pgf_extgs = pgf_extgs
+
 --- node -> node
 local color_handler = function (head)
     head = todirect(head)
@@ -324,7 +326,7 @@ local color_handler = function (head)
         local no_extgs = not tpr:find("/ExtGState<<.*>>")
         local pgf_loaded = no_extgs and luaotfload.pgf_loaded
         if pgf_loaded then
-            tpr = texgettoks(pgf_loaded) -- see luaotfload.sty
+            tpr = concat(pgf_extgs)
         end
 
         local t   = ""
@@ -336,7 +338,7 @@ local color_handler = function (head)
         end
         if t ~= "" then
             if pgf_loaded then
-                texsettoks("global", pgf_loaded, tpr..t)
+                pgf_extgs[#pgf_extgs+1] = t
             else
                 if no_extgs then
                     tpr = tpr .. "/ExtGState<<>>"
@@ -377,5 +379,13 @@ add_color_callback = function ( )
     end
 end
 
+tex.sprint("\\count255=\\catcode`@ \\catcode`@=11 ",
+    "\\ifdefined\\AtBeginDocument\\else\\def\\AtBeginDocument#1{#1}\\fi",
+    "\\AtBeginDocument{\\ifdefined\\pgfutil@everybye",
+    "\\directlua{luaotfload.pgf_loaded=true}\\begingroup",
+    "\\toks@{\\pgf@sys@addpdfresource@extgs@plain{\\directlua{tex.sprint(luaotfload.pgf_extgs)}}}",
+    "\\edef\\x{\\endgroup\\noexpand\\pgfutil@everybye{\\the\\toks@\\the\\pgfutil@everybye}}\\x",
+    "\\fi}\\catcode`@=\\count255 ")
+
 -- vim:tw=71:sw=4:ts=4:expandtab
 
diff --git a/src/luaotfload.sty b/src/luaotfload.sty
index 34f9a87..c9c9864 100644
--- a/src/luaotfload.sty
+++ b/src/luaotfload.sty
@@ -46,23 +46,3 @@
 \fi
 \RequireLuaModule{luaotfload-main}
 
-% for compatibility with beamer class, which loads pgf package.
-\ifcsname selectfont\endcsname
-  \AtBeginDocument{\@ifpackageloaded{pgfsys}{
-    \csname newtoks\endcsname\pgf@sys@pgf@resource@list@extgs@toks
-    \directlua{luaotfload.pgf_loaded=\the\allocationnumber}
-    \def\pgf@sys@pgf@resource@list@extgs{\the\pgf@sys@pgf@resource@list@extgs@toks}
-    \def\pgf@sys@addpdfresource@extgs@plain#1{\global\pgf@sys@pgf@resource@list@extgs@toks
-      \expandafter{\the\pgf@sys@pgf@resource@list@extgs@toks #1}}
-  }{}}
-\endinput\fi
-% under plain tex, tikz (pgf) should be loaded before luaotfload.
-\ifcsname pgf@sys@pgf@resource@list@extgs\endcsname\else\endinput\fi
-\count255=\the\catcode`@\relax
-\catcode`@=11\relax
-\newtoks\pgf@sys@pgf@resource@list@extgs@toks
-\directlua{luaotfload.pgf_loaded=\the\allocationnumber}
-\def\pgf@sys@pgf@resource@list@extgs{\the\pgf@sys@pgf@resource@list@extgs@toks}
-\def\pgf@sys@addpdfresource@extgs@plain#1{\global\pgf@sys@pgf@resource@list@extgs@toks
-  \expandafter{\the\pgf@sys@pgf@resource@list@extgs@toks #1}}
-\catcode`@=\the\count255\relax
-- 
cgit v1.2.3


From 6e87573031e27cc0741f3f42c65b6ae8cbeae9fd Mon Sep 17 00:00:00 2001
From: Dohyun Kim <nomosnomos@gmail.com>
Date: Thu, 30 Jul 2015 00:06:54 +0900
Subject: remove unnecessary line

---
 src/luaotfload-colors.lua | 1 -
 1 file changed, 1 deletion(-)

(limited to 'src')

diff --git a/src/luaotfload-colors.lua b/src/luaotfload-colors.lua
index 19903d8..89884b6 100644
--- a/src/luaotfload-colors.lua
+++ b/src/luaotfload-colors.lua
@@ -44,7 +44,6 @@ local texsettoks            = tex.settoks
 local texgettoks            = tex.gettoks
 
 local stringformat          = string.format
-local concat                = table.concat
 
 local otffeatures           = fonts.constructors.newfeatures("otf")
 local identifiers           = fonts.hashes.identifiers
-- 
cgit v1.2.3