summaryrefslogtreecommitdiff
path: root/texmf-dist/source/latex/opacity-pro/opacity-pro.dtx
blob: f40f0c1a84838ae9d1004176b727b2b29c72e909 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
% \iffalse
%<*copyright>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% opacity-pro.sty package,                             %%
%% Copyright (C) 2008--2018                             %%
%%   dpstory@acrotex.net                                %%
%%                                                      %%
%% This program can redistributed and/or modified under %%
%% the terms of the LaTeX Project Public License        %%
%% Distributed from CTAN archives in directory          %%
%% macros/latex/base/lppl.txt; either version 1.2 of    %%
%% tje License, or (at your option) any later version.  %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%</copyright>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{opacity-pro}
%<package> [2018/05/13 v1.1 Provides support for transparency (dps)]
%<*driver>
\documentclass{ltxdoc}
\usepackage[colorlinks,hyperindex=false]{hyperref}
\pdfstringdefDisableCommands{\let\\\textbackslash}%
\def\CMD#1{\textbackslash{#1}}\def\EXCL{!}
\let\opt\texttt \let\app\textsf \let\pkg\textsf \let\env\texttt
\OnlyDescription  % comment out for implementation details
\EnableCrossrefs
\CodelineIndex
\RecordChanges
\bgroup\ttfamily
\gdef\brpr#1{\char123\relax#1\char125\relax}\egroup
\let\darg\brpr
\let\env\texttt
\let\opt\texttt
\let\app\textsf
\def\visispace{\symbol{32}}
\def\ameta#1{\ensuremath{\langle\textit{\texttt{#1}}\rangle}}
\def\meta#1{\textsl{\texttt{#1}}}
\def\SUB#1{\ensuremath{{}_{\mbox{\scriptsize\ttfamily#1}}}}
\InputIfFileExists{aebdocfmt.def}{\PackageInfo{opacity-pro}{Inputting aebdocfmt.def}}
    {\def\IndexOpt{\DescribeMacro}\def\IndexKey{\DescribeMacro}\let\setupFullwidth\relax
     \PackageInfo{opacity-pro}{aebdocfmt.def cannot be found}}
\begin{document}
  \GetFileInfo{opacity-pro.sty}
  \title{\texorpdfstring{\protect\pkg{opacity-pro}\\}{opacity-pro: }as suggested by J\"{u}rgen Gilg}
  \author{D. P. Story\\
    Email: \texttt{dpstory@acrotex.net}}
  \date{processed \today}
  \maketitle
  \tableofcontents
  \DocInput{opacity-pro.dtx}
\IfFileExists{\jobname.ind}{\newpage\setupFullwidth\par\PrintIndex}{\paragraph*{Index} The index goes here. Execute\\[3pt]\null\qquad
    \texttt{makeindex -s gind.ist -o opacity-pro.ind opacity-pro.idx}\\[3pt]
    on the command line and recompile \texttt{opacity-pro.dtx}.}
\IfFileExists{\jobname.gls}{\PrintChanges}{\paragraph*{Change History} The list of changes goes here. Execute\\[3pt]\null\qquad
    \texttt{makeindex -s gglo.ist -o opacity-pro.gls opacity-pro.glo}\\[3pt]
    on the command line and recompile \texttt{opacity-pro.dtx}.}
\end{document}
%</driver>
% \fi
% \MakeShortVerb{|}
% \InputIfFileExists{aebdonotindex.def}{\PackageInfo{opacity-pro}{Inputting aebdonotindex.def}}
%    {\PackageInfo{opacity-pro}{cannot find aebdonotindex.def}}
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
% This is a short package that provides one command and one
% environment: \cs{settransparency} and \texttt{settransparency}.
% They are used to set the opacity and blend of an object. The reader
% interested in transparency should read Chapter 7 of the \textsl{PDF
% Reference, Sixth Edition} for Version 1.7. The techniques used in
% this package were derived from the \textsl{pdfmark Reference}
% (Adobe Acrobat 8.0 SDK), pages 38--43.
%
% As the suffix ``\texttt{pro}'' might suggest, this package is for
% those who use distiller version 6.0 or greater to produce PDFs. The
% \textsf{opacity-pro} uses distiller with the \textsf{Adobe PDF
% Settings} set to process the transparency operator. For your
% convenience, the \textsf{Adobe PDF Settings} file
% \texttt{Standard\_transparency.joboptions} is included in the
% distribution. Place this file wherever distiller looks for the
% \texttt{.joboptions} files.\footnote{Go to \texttt{Settings > Edit
% Adobe PDF Settings ...} in the Distiller application window, then
% click the \texttt{SaveAs} button. A \textsf{Save Adobe PDF Settings
% As} dialog box opens, and you can then see where Distiller likes to
% save its \texttt{.joboptions} file. Copy the provided
% \texttt{.joboptions} to the folder and restart Distiller, the
% \texttt{Standard\_transparency} should now be visible in the drop
% down \textsf{Default Settings} list.}
%
% The package doesn't really require other packages, but normally, it
% is used with the color or the graphicx packages. It does require
% that a .dvi to .ps converter be used that recognizes the special
% \verb!\special{ps: ...}!.  This includes, of course,
% \textsf{dvips}.
% %
% \section{Package Options}
%
%    \begin{macrocode}
\DeclareOption{dvips}{\def\op@driver{0}}
\DeclareOption{dvipsone}{\def\op@driver{1}}
\def\op@driver{0}
\@ifundefined{l@tex@@@@driver}{\ExecuteOptions{dvips}}
  {\ExecuteOptions{dvipsone}}
\ProcessOptions
%    \end{macrocode}
% \section{Some documentation}
% There is a command and an environment version for setting
% transparency. Use the environment when the content contains
% verbatim text, for example; otherwise, the content is taken in as one of the
% parameters. The syntax of these two are,
%\begin{flushleft}\ttfamily
%\qquad\string\settransparency*[\ameta{BM\,}]\darg{\ameta{ca}}\darg{\ameta{CA}}[\ameta{PDFKVs}]\darg{\ameta{content}}\\[6pt]
%\qquad\string\begin\darg{settransparency}[\ameta{BM\,}]\darg{\ameta{ca}}\darg{\ameta{CA}}[\ameta{PDFKVs}]\\
% \qquad\quad\ameta{contents}\\
%\qquad\string\end\darg{settransparency}\\[3pt]
%\qquad\string\begin\darg{settransparency*}[\ameta{BM\,}]\darg{\ameta{ca}}\darg{\ameta{CA}}[\ameta{PDFKVs}]\\
% \qquad\quad\ameta{contents}\\
%\qquad\string\end\darg{settransparency*}
%\end{flushleft}
%The parameters are
%\begin{quote}
%\begin{enumerate}
% \item[\texttt*] (optional) If present, the PDF entries \textbf{ca} and \textbf{CA}
%     are set as \texttt{/ca \ameta{ca}} and \texttt{/CA \ameta{CA}};
%     otherwise, the algorithm for setting the \textbf{ca} and \textbf{CA}
%     entries into the PDF is used. The algorithm is described in the
%     paragraph \textbf{\nameref{algorithm}} below.
% \item[\ameta{BM\,}:] Current blend mode. Names recognized are \texttt{Normal}, \texttt{Multiply},
% \texttt{Screen}, \texttt{Overlay}, \texttt{Darken},
% \texttt{Lighten}, \texttt{ColorDodge}, \texttt{ColorBurn},
% \texttt{HardLight}, \texttt{SoftLight}, \texttt{Difference},
% \texttt{Exclusion}, \texttt{Hue}, \texttt{Color}, \texttt{Saturation}  and
% \texttt{Luminosity}. See the accompanying file \texttt{blend\-modes.tex} for a description
%                      of each.
% \item[\ameta{ca}:] Current alpha constant, specifying the constant
%      shape or constant opacity value to be used for \emph{non-stroking operations}.
%      A number between 0 and 1, inclusive. Default is 1.0.
% \item[\ameta{CA}:] Current stroking alpha constant, specifying the constant
%      shape or constant opacity value to be used for \emph{stroking operations}.
%      A number between 0 and 1, inclusive. Default is 1.0.
% \item[\ameta{PDFKVs}]  (optional) These pairs can be inserted using the optional
%    fourth parameter (see page 38 of the \textsl{pdfmark Reference, Version
%    8.0}, for a listing of these other key-value pairs).
% \item[\ameta{contents}]  The target object, this can be text, pictures, color boxes, and so on.
% \ameta{contents} is either the fifth argument of the command version, or the contents of the environment
% version.
%\end{enumerate}
%\end{quote}
% In the environment case, the last parameter
% is optional, so {\LaTeX} will be looking for a left brace `\texttt{[}', if the contents
% of the environment begin with a command, that command will get expanded while {\LaTeX} looks for
% a left brace; if this is a potential problem. As a workaround, simply put an empty optional argument `\texttt{[]}'
% to make {\LaTeX} happy.
%
% \section{The main code}
% Below you will find the code for this package.
%    \begin{macrocode}
\let\op@YES=y \let\op@NO=n \def\op@mark{[\space}%]
\def\settransparency@env{settransparency}
\def\settransparency@envs{settransparency*}
\let\op@isEnv\op@NO
\let\op@isStar\op@NO
%    \end{macrocode}
%    \begin{macro}{\settransparency}
%    The command sets transparency for its fifth argument \ameta{contents}
%    \begin{environment}{settransparency}
%    When the content to be operated on is large, or contains verbatim text, use
%    the environment version.
%    \begin{environment}{settransparency*}
%    When the star-option is present for the command, or the \env{settransparency*} environment is used,
%    the algorithm (\textbf{\nameref{algorithm}}) is bypassed.
%    \begin{macrocode}
\newenvironment{settransparency}{%
  \@ifstar{\let\op@isStar\op@YES\settransparency@next}
  {\let\op@isStar\op@NO\settransparency@next}%
}{\special{ps:grestore}}
\newenvironment{settransparency*}{\let\op@isStar\op@YES
  \settransparency@next}{\endsettransparency}
\newcommand{\settransparency@next}[3][Normal]{%
  \@ifnextchar[%]
    {\settransparencyi{#1}{#2}{#3}}%
    {\settransparencyi{#1}{#2}{#3}[]}}%
\long\def\settransparencyi#1#2#3[#4]{%
    \ifx\@currenvir\settransparency@env
      \let\op@next\settransparencyii@env\else
    \ifx\@currenvir\settransparency@envs
      \let\op@next\settransparencyii@env\else
    \let\op@next\settransparencyii\fi\fi\op@next{#1}{#2}{#3}{#4}%
}
\def\settransparencyii#1#2#3#4#5{\op@ck@defs{#2}{#3}\leavevmode
    \special{ps:gsave \op@mark\op@ca\op@CA/BM/#1#4/SetTransparency
    pdfmark}#5\special{ps:grestore}%
}
\def\settransparencyii@env#1#2#3#4{\op@ck@defs{#2}{#3}\leavevmode
    \special{ps:gsave \op@mark\op@ca\op@CA/BM/#1#4/SetTransparency
    pdfmark}%
}
%    \end{macrocode}
%\paragraph*{Algorithm for assigning \textbf{ca} and \textbf{CA} entries}\label{algorithm}
% Recall that $\mbox{\texttt{ca}} = \mbox{filling}$ (non-stroking) and $\mbox{\texttt{CA}} = \mbox{stroking}$. The \app{dvipsone} strokes some paths that
% \app{dvips} fills. If the star-option is not taken, as a workaround, we always assure that $\mbox{\texttt{ca}} = \mbox{\texttt{CA}}$,
% provided the \app{dvips} driver is used.
%    \begin{macrocode}
\def\op@ck@defs#1#2{\def\op@argi{#1}\def\op@argii{#2}%
  \ifx\op@argii\@empty
  \let\op@CA\@empty\else\def\op@CA{/CA #2}\fi
  \ifx\op@argi\@empty\let\op@ca\@empty
  \else\def\op@ca{/ca #1}%
%    \end{macrocode}
%     If the star-option is taken, we skip this part; otherwise, we apply the algorithm
%     only if the driver is \app{dvips}.
%    \begin{macrocode}
    \ifx\op@isStar\op@NO
      \if\op@driver0\relax
        \ifx\op@argii\@empty\else
        \def\op@ca{/ca #2}\fi
      \fi
    \fi
  \fi
}
%    \end{macrocode}
%    \end{environment}
%    \end{environment}
%    \end{macro}
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%  \Finale
\endinput

\def\op@ck@defs#1#2{\def\op@argi{#1}\def\op@argii{#2}%
    \ifx\op@argii\@empty
    \let\op@CA\@empty\else\def\op@CA{/CA #2}\fi
    \ifx\op@argi\@empty\let\op@ca\@empty
    \else\def\op@ca{/ca #1}\fi
}


\def\op@ck@defs#1#2{\def\op@argi{#1}\def\op@argii{#2}%
  \def\op@ca{\@empty}\def\op@CA{\@empty}%
    \ifx\op@argii\@empty
    \else
      \def\op@CA{/CA #2}%
    \fi
    \if\op@driver0\relax
      \ifx\op@argi\@empty
        \edef\op@ca{\noexpand\def\noexpand\op@ca{\op@CA}}%
        \lowercase\expandafter{\op@ca}% ca = CA
      \else
        % ca nonempty
        \ifx\op@argii\@empty
          \def\op@ca{/ca #1}%
          \def\op@CA{/CA #1}% CA = ca
        \else % CA nonempty
          % in this case, we set ca = CA, even though
          % there is a value for ca
          \def\op@ca{/ca #2}% ca = CA
        \fi
      \fi
    \else
      \def\op@ca{/ca #1}%
    \fi
}

\def\op@ck@defs#1#2{\def\op@argi{#1}\def\op@argii{#2}%
  \ifx\op@argii\@empty
    \let\op@CA\@empty\else
    \def\op@CA{/CA #2}\fi
  \ifx\op@argi\@empty
    \let\op@ca\@empty\else
    \def\op@ca{/ca #1}\fi
}
\def\op@ck@defs#1#2{%
    \def\op@argii{#2}\ifx\op@argii\@empty
    \let\op@CA\@empty\else\def\op@CA{/CA #2}\fi
    \def\op@argi{#1}%
    \ifx\op@argi\@empty\let\op@ca\op@CA\else
      \if\op@driver0\relax
        \ifx\op@argii\@empty\else
        \def\op@ca{/ca #2}\fi
      \else
        \def\op@ca{/ca #1}\fi
    \fi
}