[latex3-commits] [git/LaTeX3-latex3-pdfresources] reworking-annot: variant for transparency, using new stacks (677bc5b)

Ulrike Fischer fischer at troubleshooting-tex.de
Mon Dec 28 00:15:32 CET 2020


Repository : https://github.com/latex3/pdfresources
On branch  : reworking-annot
Link       : https://github.com/latex3/pdfresources/commit/677bc5bf44e0a96deb9795a8c625447f2ec73bfe

>---------------------------------------------------------------

commit 677bc5bf44e0a96deb9795a8c625447f2ec73bfe
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Sat Dec 12 15:17:53 2020 +0100

    variant for transparency, using new stacks


>---------------------------------------------------------------

677bc5bf44e0a96deb9795a8c625447f2ec73bfe
 build.lua                                          |   1 +
 .../{new-transparent.sty => new-transparent2.sty}  | 134 ++++++++++-----------
 2 files changed, 62 insertions(+), 73 deletions(-)

diff --git a/build.lua b/build.lua
index e3624ed..e695743 100644
--- a/build.lua
+++ b/build.lua
@@ -12,6 +12,7 @@ sourcefiles =  {"*.dtx","*.ins",
                 "hgeneric-experimental.def",
                 "tmpl3shipout.sty",
                 "newpackages/new-transparent.sty",
+                "newpackages/new-transparent2.sty",
                 "newpackages/new-bookmark.sty",
                 "newpackages/bkm-generic.def",
                 "newpackages/new-attachfile.sty",
diff --git a/newpackages/new-transparent.sty b/newpackages/new-transparent2.sty
similarity index 53%
copy from newpackages/new-transparent.sty
copy to newpackages/new-transparent2.sty
index 1207b7f..a65fdc2 100644
--- a/newpackages/new-transparent.sty
+++ b/newpackages/new-transparent2.sty
@@ -1,14 +1,12 @@
 %%
-%% This is file `new-transparent.sty',
+%% This is file `new-transparent2.sty',
 %% base on transparent sty from Heiko Oberdiek
 %%
 \NeedsTeXFormat{LaTeX2e}[2020/10/01]
-\ProvidesExplPackage{new-transparent}%
-  {2020-09-06}{v1.42}{Transparency with color stacks (based on transparent from Heiko Oberdiek)}%
-%pdftex + luatex in pdf mode
-\sys_if_output_pdf:T
-  {
-    \bool_lazy_and:nnF
+\ProvidesExplPackage{new-transparent2}%
+  {2020-12-10}{v0.1}{Transparency with color stacks (based on transparent from Heiko Oberdiek)}%
+%not really needed for dvips, but lets keep it for now ...
+\bool_lazy_and:nnF
       {\cs_if_exist_p:N \pdfmanagement_add:nnn }
       { \pdfmanagement_if_active_p: }
       {
@@ -19,87 +17,77 @@
          }
         \endinput
       }
-   }
-\sys_if_engine_pdftex:T
-  {
-    \let\TRP at pdfcolorstackinit\tex_pdfcolorstackinit:D
-    \let\TRP at pdfcolorstack\tex_pdfcolorstack:D
-  }
-
-\sys_if_engine_luatex:T
-  {
-    \def\TRP at pdfcolorstackinit           {\pdffeedback~colorstackinit}
-    \protected\def\TRP at pdfcolorstack     {\pdfextension~colorstack}
-  }
-
-\sys_if_output_pdf:T
-  {
-    %initialize opacity 1
-    \pdfmanagement_add:nnn{Page/Resources/ExtGState}{TRP1}{<</ca~1/CA~1>>}
-    %
-    \cs_new_protected:Npn \__transparent_use:n #1
+% Open question: do we need also fill and stroke opacity?
+% And if yes, should it also use a stack?
+
+\fp_new:N\l__color_backend_opacity_fp
+\cs_if_free:NTF \__kernel_color_stack_init:Nnn
+  { %dvips
+    % only minimal support (doesn't work over page breaks, and no stack, simply
+    % resets to 1 after the group
+    \cs_new_protected:Npn \__color_backend_opacity_set:n #1
       {
-        \tl_if_exist:cF { c__transparent_TRP#1_tl }
-          {
-            \pdfmanagement_add:nnn{Page/Resources/ExtGState}{TRP#1}{<</ca~#1/CA~#1>>}
-            \tl_const:cn { c__transparent_TRP#1_tl }{ /TRP#1~gs }
-          }
+        \fp_set:Nn\l__color_backend_opacity_fp { min(max(0,#1),1)}
+        \__kernel_backend_postscript:x {\fp_use:N\l__color_backend_opacity_fp\c_space_tl~.setstrokeconstantalpha}
+        \__kernel_backend_postscript:x {\fp_use:N\l__color_backend_opacity_fp\c_space_tl~.setfillconstantalpha}
+        \group_insert_after:N \__color_backend_opacity_reset:
       }
-    \xdef\TRP at colorstack{%
-         \TRP at pdfcolorstackinit~page~direct{/TRP1~gs}}
-    \NewDocumentCommand{\transparent} { m }
+    \cs_new_protected:Npn \__color_backend_opacity_reset:
       {
-        \exp_args:Nx\__transparent_use:n { \fp_eval:n{ min(max(0,#1),1)}}
-        \tl_set:Nx  \transparent at current { \fp_eval:n{ min(max(0,#1),1)}}
-        \transparent at set
+        \__kernel_backend_postscript:n {1~.setstrokeconstantalpha}
+        \__kernel_backend_postscript:n {1~.setfillconstantalpha}
       }
-
-    \def\transparent at current{/TRP1~gs}
-    \def\transparent at set
+  }
+  { %others
+    \__kernel_color_stack_init:Nnn \g_tmpa_int {page~direct}{/l3opa1~gs}
+    % hm, actually only needed if used ...
+    \pdfmanagement_add:nnn{Page/Resources/ExtGState}{l3opa1}{<</ca~1/CA~1>>}
+    \int_const:Nn \c__color_backend_opacity_stack_int { \int_use:N \g_tmpa_int }
+    \cs_new_protected:Npn \__color_backend_opacity_set:n #1
       {
-        \TRP at pdfcolorstack\TRP at colorstack~push~
+        %decide later, if we should test that the opacity has already been set ...
+        \fp_set:Nn\l__color_backend_opacity_fp { min(max(0,#1),1)}
+        \exp_args:Nxx
+        \pdfmanagement_add:nnn
+          {Page/Resources/ExtGState}
+          {l3opa\fp_use:N \l__color_backend_opacity_fp}
           {
-            \tl_use:c { c__transparent_TRP\transparent at current _tl }
+            <<
+              /ca~\fp_use:N \l__color_backend_opacity_fp
+              /CA~\fp_use:N \l__color_backend_opacity_fp
+            >>
           }
-            \aftergroup\transparent at reset
-      }
-
-    \def\transparent at reset{\TRP at pdfcolorstack\TRP at colorstack~pop\relax}
-
-  }
-
-%xetex, dvipdfmx
-\str_case_e:nnT {\g__sys_backend_tl}
- {
-   {xetex}{}
-   {dvipdfmx}{}
- }
- {
-   \PackageInfo{new-transparent}{xetex~and~dvipdfmx~need~dvipdfmx~newer~than~20200901}{}
-   \NewDocumentCommand{\transparent} { m }
-      {
-       \transparent at set{#1}
+        \exp_args:Nee \__kernel_color_stack_push:nn
+         {
+           \int_use:N \c__color_backend_opacity_stack_int
+         }
+         {
+           /l3opa\fp_use:N\l__color_backend_opacity_fp~\c_space_tl~gs
+         }
+       \group_insert_after:N \__color_backend_opacity_reset:
       }
-   \def\transparent at set #1
+    \cs_new_protected:Npn \__color_backend_opacity_reset:
       {
-        \special{pdf:bxgstate~<</CA~#1/ca~#1>>}
-        \aftergroup\transparent at reset
-      }
-
-    \def\transparent at reset{\special{pdf:exgstate}}
- }
+        \exp_args:Ne
+        \__kernel_color_stack_pop:n
+          {
+            \int_use:N \c__color_backend_opacity_stack_int
+          }
+       }
+    }
 
-%warning for dvips currently missing
-% but it should at least not error
-\ProvideDocumentCommand\transparent { m }{}
+\NewDocumentCommand{\transparent} { m }
+  {
+    \__color_backend_opacity_set:n { #1 }
+  }
 
 \NewDocumentCommand{\texttransparent}{m m}
   {
-   \protect\leavevmode
-   \begingroup
+   \mode_leave_vertical:
+   \group_begin:
      \transparent{#1}
      #2
-   \endgroup
+   \group_end:
   }
 
 





More information about the latex3-commits mailing list.