summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/draftwatermark/draftwatermark-2x.sty
blob: 7c7124ce19467eb484ca26809b84a1dafa9c3693 (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
%%
%% This is file `draftwatermark-2x.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% draftwatermark.dtx  (with options: `draftwatermark-2x')
%% 
%%   IMPORTANT NOTICE:
%% 
%% Copyright 2006, 2020
%% Sergio Callegari <sergio.callegari@gmail.com>
%% 
%% ------------------------------------------------
%% This file is part of the draftwatermark package,
%% a contribution to the LaTeX2e system.
%% ------------------------------------------------
%% 
%% This program consists of the files listed in the README.md file included
%% in the package.
%% 
%% Any modified versions of this file must be renamed with new filenames
%% distinct from draftwatermark-2x.sty.
%% 
%% For distribution of the original source see the terms for copying and
%% modification in the file draftwatermark.dtx.
%% 
%% This generated file may be distributed as long as the original source files,
%% as listed above, are part of the same distribution. (The sources need not
%% necessarily be in the same archive or directory.)
%% 
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{draftwatermark}%
  [2020/12/06 2.3 Put a gray textual watermark on document pages]

\RequirePackage{kvoptions}
\RequirePackage{everypage}[2007/06/20]
\RequirePackage{graphicx}
\RequirePackage{color}

\SetupKeyvalOptions{family=draftwatermark, prefix=draftwatermark@}

\DeclareBoolOption[false]{firstpageonly}
\define@key{draftwatermark}{firstpage}[true]{%
  \csname draftwatermark@firstpageonly#1\endcsname}
\DeclareBoolOption[true]{stamp}
\DeclareComplementaryOption{nostamp}{stamp}
\DeclareComplementaryOption{final}{stamp}
\DeclareStringOption[45]{angle}
\DeclareStringOption[1]{scale}
\DeclareStringOption[DRAFT]{text}
\DeclareStringOption[0.5\paperwidth]{hpos}
\DeclareStringOption[0.5\paperheight]{vpos}
\DeclareStringOption[0.25\paperwidth]{fontsize}
\DeclareStringOption[gray]{colormodel}
\DeclareStringOption[0.8]{colorspec}
\DeclareStringOption[c]{hanchor}
\DeclareStringOption[m]{vanchor}
\DeclareStringOption[c]{alignment}
\DeclareStringOption[\DraftwatermarkStdMark]{markcmd}
\define@key{draftwatermark}{pos}{%
  \draftwatermark@processpos #1\@nil}
\define@key{draftwatermark}{anchor}{%
  \draftwatermark@processanchor{#1}}
\define@key{draftwatermark}{color}{%
  \draftwatermark@processcolor #1\@nil}

\def\draftwatermark@processpos#1,#2\@nil{%
  \def\draftwatermark@hpos{#1}%
  \def\draftwatermark@vpos{#2}}

\def\draftwatermark@processanchor#1{%
  \def\draftwatermark@tempa{#1}
  \@onelevel@sanitize \draftwatermark@tempa
  \expandafter \@tfor \expandafter \draftwatermark@tempb
    \expandafter :\expandafter =\draftwatermark@tempa
    \do
    {%
      \if \draftwatermark@tempb l%
        \def \draftwatermark@hanchor{l}%
      \else \if \draftwatermark@tempb c%
        \def \draftwatermark@hanchor{c}%
      \else \if \draftwatermark@tempb r%
        \def \draftwatermark@hanchor{r}%
      \else \if \draftwatermark@tempb t%
        \def \draftwatermark@vanchor{t}%
      \else \if \draftwatermark@tempb m%
        \def \draftwatermark@vanchor{m}%
      \else \if \draftwatermark@tempb b%
        \def \draftwatermark@vanchor{b}
      \else
        \PackageError{draftwatermark}{%
          Illegal anchor directive `\draftwatermark@tempb'}%
          {Directive has been ingnored.}%
      \fi\fi\fi\fi\fi\fi
    }}

\def\draftwatermark@processcolor{%
  \@ifnextchar[
    \draftwatermark@processcolor@ii\draftwatermark@processcolor@i}

\def\draftwatermark@processcolor@i#1\@nil{%
  \def\draftwatermark@colormodel{}%
  \def\draftwatermark@colorspec{#1}}

\def\draftwatermark@processcolor@ii[#1]#2\@nil{%
  \def\draftwatermark@colormodel{#1}%
  \def\draftwatermark@colorspec{#2}}

\ProcessKeyvalOptions*
\DisableKeyvalOption{draftwatermark}{firstpageonly}
\DisableKeyvalOption{draftwatermark}{firstpage}

\newcommand\DraftwatermarkOptions[1]{\setkeys{draftwatermark}{#1}}

\newcommand\SetWatermarkAngle[1]{\DraftwatermarkOptions{angle=#1}}
\newcommand\SetWatermarkFontSize[1]{\DraftwatermarkOptions{fontsize=#1}}
\newcommand\SetWatermarkScale[1]{\DraftwatermarkOptions{scale=#1}}
\newcommand\SetWatermarkHorCenter[1]{%
  \DraftwatermarkOptions{hpos=#1, hanchor=c}}
\newcommand\SetWatermarkVerCenter[1]{%
  \DraftwatermarkOptions{vpos=#1, vanchor=m}}
\newcommand\SetWatermarkText[1]{\DraftwatermarkOptions{text={#1}}}
\newcommand\SetWatermarkColor[2][]{%
  \DraftwatermarkOptions{colormodel=#1, colorspec=#2}}
\newcommand\SetWatermarkLightness[1]{%
  \DraftwatermarkOptions{colormodel=gray, colorspec=#1}}

\newcommand\DraftwatermarkStdMark{%
  \rotatebox{\draftwatermark@angle}{%
    \scalebox{\draftwatermark@scale}{%
      \begingroup
      \ifx\draftwatermark@colormodel\@empty
        \color{\draftwatermark@colorspec}%
      \else
        \color[\draftwatermark@colormodel]{\draftwatermark@colorspec}%
      \fi
      \setlength{\@tempdima}{\draftwatermark@fontsize}%
      \fontsize{\@tempdima}{1.2\@tempdima}\selectfont
      \shortstack[\draftwatermark@alignment]{\draftwatermark@text}%
      \endgroup}}}

\newcommand\draftwatermark@printwm[1]{%
  \sbox\@tempboxa{#1}%
  \setlength{\@tempdima}{\draftwatermark@hpos}%
  \setlength{\@tempdimb}{\draftwatermark@vpos}%
  \edef \draftwatermark@tempa{\draftwatermark@hanchor}%
  \@onelevel@sanitize \draftwatermark@tempa
  \expandafter\def\expandafter\draftwatermark@tempb
    \expandafter{\expandafter\@car \draftwatermark@tempa\@nil}%
  \if \draftwatermark@tempb r%
    \addtolength\@tempdima{-\wd\@tempboxa}%
  \else\if \draftwatermark@tempb c%
    \addtolength\@tempdima{-0.5\wd\@tempboxa}%
  \else\if \draftwatermark@tempb l%
    \relax
  \else
    \PackageError{draftwatermark}{%
      Illegal anchor directive `\draftwatermark@tempb'}%
        {Anchoring to left side.}%
  \fi\fi\fi
  \edef \draftwatermark@tempa{\draftwatermark@vanchor}%
  \@onelevel@sanitize \draftwatermark@tempa
  \expandafter\def\expandafter\draftwatermark@tempb
    \expandafter{\expandafter\@car \draftwatermark@tempa\@nil}%
  \if \draftwatermark@tempb b%
    \addtolength\@tempdimb{-\ht\@tempboxa}%
    \addtolength\@tempdimb{-\dp\@tempboxa}%
  \else\if \draftwatermark@tempb m%
    \addtolength\@tempdimb{-0.5\ht\@tempboxa}%
    \addtolength\@tempdimb{-0.5\dp\@tempboxa}%
  \else\if \draftwatermark@tempb t%
    \relax
  \else
    \PackageError{draftwatermark}{%
      Illegal anchor directive `\draftwatermark@tempb'}%
        {Anchoring to top side.}%
  \fi\fi\fi
  \vbox to 0pt {%
      \vspace*{-1in}%
      \vspace*{\@tempdimb}%
      \hbox to 0pt {%
        \hspace*{-1in}%
        \hspace*{\@tempdima}%
        \usebox\@tempboxa
        \hss}%
      \vss}}

\newcommand\draftwatermark@print[1]{%
  \ifdraftwatermark@stamp
    \draftwatermark@printwm{#1}%
  \fi}
\ifdraftwatermark@firstpageonly
  \AddThispageHook{\draftwatermark@print{\draftwatermark@markcmd}}
\else
  \AddEverypageHook{\draftwatermark@print{\draftwatermark@markcmd}}
\fi
\endinput
%%
%% End of file `draftwatermark-2x.sty'.