summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/xwatermark
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2011-08-13 22:21:51 +0000
committerKarl Berry <karl@freefriends.org>2011-08-13 22:21:51 +0000
commit0afc4b11d95956fe6518f5c1cf78adef9d2370f9 (patch)
tree7ddd661e934dee4619a89d5d72cffafa188aff38 /Master/texmf-dist/tex/latex/xwatermark
parent6896e1abedec5194e9a456ce8d6c630999e4ed0f (diff)
xwatermark (12aug11)
git-svn-id: svn://tug.org/texlive/trunk@23545 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/xwatermark')
-rw-r--r--Master/texmf-dist/tex/latex/xwatermark/xwatermark.sty2508
1 files changed, 2124 insertions, 384 deletions
diff --git a/Master/texmf-dist/tex/latex/xwatermark/xwatermark.sty b/Master/texmf-dist/tex/latex/xwatermark/xwatermark.sty
index 61b875faeb7..81ceb5b120f 100644
--- a/Master/texmf-dist/tex/latex/xwatermark/xwatermark.sty
+++ b/Master/texmf-dist/tex/latex/xwatermark/xwatermark.sty
@@ -1,5 +1,5 @@
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
-% This is file 'xwatermark.sty', version 1.4. %
+% This is file 'xwatermark.sty', version 1.5.1, July 2011. %
% %
% This package puts user-specified watermarks (graphics and arbitrary %
% texts) on select pages of documents. See package documentation %
@@ -19,425 +19,2165 @@
% implied warranties of merchantability and fitness for a particular %
% purpose. %
% %
-% Copyright (c) 2010 Ahmed Musa (a.musa@rocketmail.com). %
+% Copyright (c) 2009-2011 Ahmed Musa (amusa22@gmail.com). %
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
-\begingroup
-\catcode064 11% @
-\catcode123 01% {
-\catcode125 02% }
-\def\x{\endgroup
- \edef\xwm@RestoreCodeAtEnd{%
- \catcode035 \the\catcode035% #
- \catcode064 \the\catcode064% @
- \catcode123 \the\catcode123% {
- \catcode125 \the\catcode125% }
- \catcode061 \the\catcode061% =
- }%
-}
-\x
-\@makeother{\=}%
-\catcode035=06% #
-\catcode064=11% @
-\catcode123=01% {
-\catcode125=02% }
-\def\xwm@EnsureCode#1#2{%
- \edef\xwm@RestoreCodeAtEnd{%
- \xwm@RestoreCodeAtEnd
- \catcode#1=\the\catcode#1\relax
- }%
- \catcode#1=#2\relax
-}
-\AtEndOfPackage{\xwm@RestoreCodeAtEnd}
-\xwm@EnsureCode{010}{12}% ^^J
-\xwm@EnsureCode{033}{12}% !
-\xwm@EnsureCode{039}{12}% '
-\xwm@EnsureCode{040}{12}% (
-\xwm@EnsureCode{041}{12}% )
-\xwm@EnsureCode{042}{12}% *
-\xwm@EnsureCode{044}{12}% ,
-\xwm@EnsureCode{045}{12}% -
-\xwm@EnsureCode{046}{12}% .
-\xwm@EnsureCode{047}{12}% /
-\xwm@EnsureCode{058}{12}% :
-\xwm@EnsureCode{060}{12}% <
-\xwm@EnsureCode{062}{12}% >
-\xwm@EnsureCode{094}{07}% ^ (superscript)
-\xwm@EnsureCode{096}{12}% `
-\xwm@EnsureCode{254}{12}% ^^fe
-\xwm@EnsureCode{255}{12}% ^^ff
-\xwm@EnsureCode{126}{13}% ~ (active)
-\def\readRCS$#1 #2 #3 #4 #5 #6 #7 #8 ${%
- \def\filedate{#4}%
- \def\fileversion{v#3}%
- \def\filetime{#5}%
- \def\fileauthor{#6\space#7}%
-}
-\def\filedesc{%
- Puts user-specified watermarks on select document pages (\fileauthor)}
-\readRCS
-$Id: xwatermark.sty,v 1.4 2010/01/10 09:00:00 Ahmed Musa Exp $
-\ProvidesPackage{xwatermark}[\filedate\space\fileversion\space\filedesc]
+
+\@ifpackageloaded{catoptions}{}{\RequirePackage{catoptions}[2011/07/30]}
+\UseNormalCatcodes
+\StyleFilePurpose{Puts select watermarks on select pages}
+\StyleFileRCSInfo
+$Id: xwatermark.sty,v 1.5.1 2011/07/30 09:00:00 Ahmed Musa Exp $
+\ProvidesPackage{xwatermark}[\StyleFileInfo]
\NeedsTeXFormat{LaTeX2e}[1996/12/01]
-\@ifpackageloaded{etoolbox}{}{\RequirePackage{etoolbox}[2009/08/06]}
-\@ifpackageloaded{ltxnew}{}{\RequirePackage{ltxnew}[2009/07/22]}
-\newrobustcmd\xwm@info[1]{\PackageInfo{xwatermark}{#1\@gobble}}
-\newrobustcmd\xwm@warn[1]{\PackageWarningNoLine{xwatermark}{#1}}
-\newrobustcmd\xwm@err[1]{\PackageError{xwatermark}{#1}{\@ehc}}
-\new\def\xwm@car#1#2\@nil{#1}
-\new\def\xwm@testarg#1{%
- \begingroup
- \escapechar=92\relax
- \edef\tmp@a{\expandafter\xwm@car\string#1\@nil}%
- \if\tmp@a\@backslashchar
- \aftergroup\@firstoftwo
- \else
- \aftergroup\@secondoftwo
+\SetStyleFileMessages[xwm@]{info}{warn}{err}
+\robust@def*\xwm@@err#1#2#3{\xwm@err{#1}{#2}\@gobble}
+\cptloadpackages{%
+ fix-cm||2006/03/24;
+ picture||2008/11/26;
+ graphicx||1999/02/16;
+ atbegshi||2008/07/31;
+ fancyhdr;
+ atveryend||2010/03/24;
+ ltxkeys||2011/01/01;
+ framed||2007/10/04
+}
+\AtEndOfPackage{\AtBeginDocument{%
+ \ifcsndefTF{ver@hyperref.sty}{}{\usepackage{hyperref}}%
+}}
+\newletcs\xwm@nil\relax
+\AtBeginShipoutInit
+\newvariables{box}[xwm@box]{a,b}\relax
+\newvariables{count}[xwm@]{cnta}\relax
+\newvariables{if}[xwm@]{pdf,swa,swb,foregrd,wall}[false]
+\newvariables{write}[xwm@]{wrt}\relax
+\robust@def*\AtShipoutAlwaysUpperLeft#1{%
+ \AtBeginShipout{\AtBeginShipoutUpperLeft{#1}}%
+}
+\newletcs\stripallbr\stripallouterbraces
+\newletcs\stripallbrincs\stripallouterbracesincs
+\new@def*\xwmremoveleadparsers#1#2{%
+ \s@expandarg\ifbracedTF{#2}{%
+ \unexpanded\expandafter{#2}%
+ }{%
+ \unexpanded\expandafter{\romannumeral
+ \expandafter\xwm@removeleadparsers#2\batchmode{#1}}%
+ }%
+}
+\new@def*\xwm@removeleadparsers#1#2\batchmode#3{%
+ \ifcondTF\if\string#3\string#1\fi{%
+ \xwm@removeleadparsers#2\batchmode{#3}%
+ }{%
+ 0 #1#2%
+ }%
+}
+\robust@def*\xwm@ifxcolorloaded{%
+ \ifcsndefTF{ver@xcolor.sty}\@iden{%
+ \xwm@err{'xcolor' package not loaded}\@ehc
+ }%
+}
+\robust@def*\xwmdefinecolor{%
+ \xwm@ifxcolorloaded{%
+ \let\reserved@e\definecolor
+ \cpt@testopt\xwm@definecolor{}%
+ }%
+}
+\robust@def*\xwmcolorlet{%
+ \xwm@ifxcolorloaded{%
+ \let\reserved@e\colorlet
+ \cpt@testopt\xwm@definecolor{}%
+ }%
+}
+\robust@def*\xwm@definecolor[#1]#2{%
+ \@ifundefinedcolor{#2}{%
+ \reserved@e[#1]{#2}%
+ }{%
+ \xwm@err{Color name '#2' already defined}\@ehc
+ }%
+}
+\robust@def*\xwmdefinecolorset{\cpt@testopt\xwm@definecolorset{x}}
+\robust@def*\xwm@definecolorset[#1]{%
+ \cpt@testpnopt{\xwm@d@finecolorset{#1}}{1}%
+}
+\robust@def*\xwm@d@finecolorset#1(#2)#3{%
+ \xwm@ifxcolorloaded{%
+ \begingroup
+ \emptifycsset{\xwm@tempb,\xwm@tempc,\xwm@tempd,\xwm@tempe}%
+ \def\xwm@tempa##1,##2,##3,##4,##5\@nil{%
+ \ifx\noboundary##4\noboundary
+ \xwm@err{Incomplete color format in
+ \string\xwmdefinecolorset}\@ehc
+ \else
+ \def\reserved@a{##1}%
+ \fi
+ }%
+ \cpt@stfalse\cpt@csvnormalize[;]{#3}%
+ \def\do##1;{%
+ \ifnot@nil{##1}{%
+ \xwm@tempa##1,,,,\@nil
+ \xifinsetTF{,\reserved@a,}{,\xwm@tempd,}{%
+ \edef\xwm@tempe{\cptliststack,\xwm@tempe\reserved@a}%
+ }{%
+ \edef\xwm@tempd{\cptliststack,\xwm@tempd\reserved@a}%
+ \@ifundefinedcolor{#1\reserved@a#2}{%
+ \edef\xwm@tempb{\cptliststack;\xwm@tempb##1}%
+ }{%
+ \edef\xwm@tempc{\cptliststack;\xwm@tempc#1\reserved@a#2}%
+ }%
+ }%
+ \do
+ }%
+ }%
+ \expandafter\do\normalized@list;\@nil;%
+ \ifcsemptyTF\xwm@tempe{}{%
+ \xwm@err{Color names '\expandcsonce\xwm@tempe' multiply
+ \MsgBrk submitted to \string\xwmdefinecolorset}\@ehc
+ }%
+ \ifcsemptyTF\xwm@tempc{}{%
+ \xwm@err{Color names '\expandcsonce\xwm@tempc' already in use}\@ehc
+ }%
+ \ifcsemptyTF\xwm@tempb{}{%
+ \cptexpandarg{\xglobal\definecolorset{rgb}{#1}{#2}}
+ {\expandcsonce\xwm@tempb}%
+ }%
+ \endgroup
+ }%
+}
+\DefSuffixChecker\xwm@suffixcheck{*}{'}
+\robust@def*\xwmifitemsinTF{%
+ \cpt@swatrue\cpt@testopt\xwm@itemsin\@ne
+}
+\robust@def*\xwmifitemsinFT{%
+ \cpt@swafalse\cpt@testopt\xwm@itemsin\@ne
+}
+\robust@def\xwm@itemsin[#1]#2#3{%
+ \ifnum\numexpr#1<\@ne
+ \xwm@err{Invalid number '\the#1'\relax\MsgBrk
+ for command \string\xwmifitemsinTF}\@ehc
\fi
+ \lowercase{%
+ \edef\xwm@tempa{\unexpanded{#2}}%
+ \edef\xwm@tempb{\unexpanded{#3}}%
+ }%
+ \cpt@sttrue\cpt@csvnormalize[,]\xwm@tempb
+ \chardef\xwm@nritems\z@pt
+ \def\xwm@items{}%
+ \def\csv@do##1{%
+ \xifinsetFT{,\detokenize{##1}}{,\cptoxdetok\xwm@tempb}{}{%
+ \cptaddtolist[,]\xwm@items{##1}%
+ \pushnumber\xwm@nritems
+ \ifnum\xwm@nritems>\numexpr#1-1\relax
+ \loopbreak
+ \fi
+ }%
+ }%
+ \csv@@parse*[,]\xwm@tempa
+ \csname
+ @\ifnum\xwm@nritems>\numexpr#1-1\relax
+ \ifcpt@swa first\else second\fi
+ \else
+ \ifcpt@swa second\else first\fi
+ \fi
+ oftwo\endcsname
+}
+\robust@def*\x@xwmifitemsinTF{%
+ \cpt@swatrue\cpt@testopt\xwm@xitemsin{1}%
+}
+\robust@def\xwm@xitemsin[#1]#2#3{%
+ \cptexpandtwoargs{\xwm@itemsin[#1]}{#2}{#3}%
+}
+\robust@def*\xwm@hyphenpagerange#1#2#3{%
+ \xifinsetTF{\detokenize{\xwmgetpagenumber}}{\cptoxdetok{#1}}{%
+ \xwm@swbtrue
+ }{%
+ \xifinsetTF{\detokenize{\lastdocpage}}{\cptoxdetok{#1}}{%
+ \xwm@swbtrue
+ }{%
+ \xwm@swbfalse
+ }%
+ }%
+ \protected@edef#2{#1}\def#3{}%
+ \begingroup
+ \catcode`\-=12\relax
+ \cptscantokens#2%
+ \postgroupdef#2\endgroup
+ \oifinsetTF{-}{#2}{%
+ \expandafter\xwm@splitpagerange#2\xwm@nil{#2}{#3}%
+ }{%
+ \ifblankTF{#1}{%
+ \xwm@err{Empty page range for watermark:
+ ^^J'\expandcsonce\currentmark'.^^J}\@ehc
+ }{%
+ \protected@edef#3{#1}%
+ }%
+ }%
+}
+\robust@def*\xwm@splitpagerange#1-#2\xwm@nil#3#4{%
+ \def#3{#1}\def#4{#2}%
+ \ifinsetTF{-}{#2}{%
+ \xwm@err{Too many hyphens in page range '#1-#2'
+ \MsgBrk of watermark:^^J'\expandcsonce\currentmark'}\@ehc
+ }{%
+ \ifblankTF{#1}{%
+ \xwm@warn{No start-page in page-range of watermark:
+ ^^J'\expandcsonce\currentmark'.^^JI have used the
+ default start-page '\xwm@defaultfirstpage'
+ instead}%
+ \def#3{\xwm@defaultfirstpage}%
+ \xwm@swafalse
+ }{%
+ \xwm@swatrue
+ }%
+ \ifblankTF{#2}{%
+ \xwm@warn{No end-page for page-range
+ of watermark:^^J'\expandcsonce\currentmark'
+ ^^JI have used the default end-page
+ '\xwm@defaultlastpage' instead}%
+ \def#4{\xwm@defaultlastpage}%
+ \xwm@swafalse
+ }{%
+ \xwm@swatrue
+ }%
+ \ifxwm@swa
+ \ifnum\numexpr#1=\numexpr#2\relax\else
+ \ifnum\numexpr#1<\numexpr#2\relax\else
+ \ifxwm@swb\else
+ \xwm@err{Watermark start-page '#1' is greater
+ than end-page '#2'}\@ehc
+ \fi
+ \fi
+ \fi
+ \fi
+ }%
+}
+\let\xwm@papercenter\relax
+\ifdefTF\pdfoutput{%
+ \ifnum\pdfoutput<\@ne\xwm@pdffalse\else\xwm@pdftrue\fi
+}{%
+ \xwm@pdffalse
+}
+\new@def*\xwm@allowedcoordunits{%
+ em,ex,in,pt,pc,cm,mm,dd,cc,nd,nc,bp,sp,\paperwidth,%
+ \paperheight,\textwidth,\textheight,\hsize,\vsize,%
+ \columnwidth,\linewidth
+}
+\robust@def*\xwm@checkcoordunit#1{%
+ \oifinset@sp@TF,{#1}{\xwm@allowedcoordunits}{}{%
+ \xwm@err{Invalid coordinate unit '#1'}{%
+ Allowed coordinate units are:
+ ^^J||\xwm@allowedcoordunits||^^J}%
+ }%
+}
+\robust@def*\xwm@defaultunits#1#2{%
+ \begingroup
+ \@defaultunits\@tempdima\dimexpr#1\p@\relax\@nnil
+ \edefpass#2{\endgroup\def\noexpand#2{\the\@tempdima}}%
+}
+\robust@def*\xwm@getposition#1#2#3{%
+ \begingroup
+ \@defaultunits\@tempdima\dimexpr#1#3\p@\relax\@nnil
+ \csn@xdef{\cptremovescape#1@a}{%
+ \the\dimexpr0.5\paperwidth+\@tempdima\relax
+ }%
+ \@defaultunits\@tempdima\dimexpr#2#3\p@\relax\@nnil
+ \csn@xdef{\cptremovescape#2@a}{%
+ \the\dimexpr-0.5\paperheight+\@tempdima\relax
+ }%
\endgroup
}
-\newrobustcmd*\xwm@numdef[2]{%
- \xwm@testarg{#1}{}{\xwm@err{Unacceptable argument '#1' for number}}
- \ifstrempty{#2}{\xwm@err{Empty argument for counter}}{}
- \ifundef{#1}{\new\count#1\relax #1=\numexpr#2\relax}{#1=\numexpr#2\relax}
-}
-\newrobustcmd*\xwm@dimdef[2]{%
- \xwm@testarg{#1}{}{\xwm@err{Unacceptable argument '#1' for dimension}}
- \ifstrempty{#2}{\xwm@err{Empty argument for dimension}}{}
- \ifundef{#1}{\new\dimen#1\relax #1=\dimexpr#2\relax}{#1=\dimexpr#2\relax}
-}
-\new\long\def\xwm@afterfi#1\fi{\fi#1}
-\new\long\def\xwm@afterelsefi#1\else#2\fi{\fi#1}
-\new\let\xwm@pagestart\@empty
-\new\let\xwm@pageend\@empty
-\new\def\xwm@pagerange#1{%
- \renew\def\xwm@pagestart{#1}%
- \renew\def\xwm@pageend{}%
- \xwm@pagerange@ifhyphen#1-\@nil{%
- \ifx\xwm@pagestart\@empty
- \xwm@afterelsefi\xwm@err{Empty page range passed to package}%
+\cptrobustify{%
+ \fbox,\framebox,\makebox,\rotatebox,\scalebox,\raisebox
+}
+\new@def*\xwm@relax{\relax}
+\robust@def*\xwm@settextalign#1{%
+ \ifmacroTF{#1}{}{\cpt@notcserr{#1}}%
+ \begingroup
+ \cptexpandmacro{#1}\xwm@tempa
+ \cptexpandargonce{\endgroup\stripallbr}\xwm@tempa#1%
+ \ltxkeys@trimspacesincs{#1}%
+ \cptexpandsecond{\def\reserved@a##1}{#1}##2##3\xwm@nil{%
+ \ifx\noboundary##3\noboundary
+ \cpt@err{Invalid value '#1' for textalign}\@ehc
\else
- \xwm@afterfi
- \xwm@err{Only page \xwm@pagestart\space was passed as page range}%
+ \def#1{##2}%
\fi
+ }%
+ \cptexpandsecond{\reserved@a
+ center{center},\centering{center},right{flushright},
+ \flushright{flushright},\raggedleft{flushright},
+ left{flushleft},\flushleft{flushleft},\raggedright{flushleft},
+ justified{xwm@relax},\relax{xwm@relax},xwm@relax{xwm@relax}%
+ }{#1}{\xwm@nil}\xwm@nil
+}
+\robust@def*\xwm@getalign#1{%
+ \ifmacroTF{#1}{%
+ \csn@edef{xwm@\expandafter\@gobblethree\string#1}{%
+ \xifstrcmpTF{#1}{\relax}{relax}{#1}%
+ }%
}{%
- \xwm@pagerange@split#1\@nil
+ \cpt@notcserr{#1}%
}%
}
-\new\def\xwm@pagerange@split#1-#2\@nil{%
- \renew\def\xwm@pagestart{#1}%
- \renew\def\xwm@pageend{#2}%
- \xwm@pagerange@ifhyphen#2-\@nil{%
- \ifx\xwm@pagestart\@empty
- \expandafter\xwm@err{No starting page for page range}%
- \else
- \ifx\xwm@pageend\@empty
- \xwm@afterelsefi
- \xwm@err{No ending page for page range}%
- \else
- \xwm@afterfi
- \xwm@info{Page range:\space\xwm@pagestart\space to \xwm@pageend}%
+\robust@def*\xwm@setboxalign#1{%
+ \ifmacroTF{#1}{}{\cpt@notcserr{#1}}%
+ \begingroup
+ \toks@{}%
+ \cptexpandarg\lowercase{\def\noexpand\reserved@a{#1}}%
+ \def\xwm@tempa{}\def\xwm@tempb{}%
+ \def\xwm@resa##1-{%
+ \ifstrcmpTF{##1}{\xwm@nil}{}{%
+ \ifinsetTF{,##1,}{,top,left,right,bottom,center,%
+ justified,}{%
+ \edef\xwm@tempa{\cptliststack,\xwm@tempa##1}%
+ }{%
+ \ifinsetTF{,##1,}{,l,r,b,t,c,s,}{%
+ \edef\xwm@tempb{\xwm@tempb##1}%
+ }{%
+ \toks@\expandafter{\the\toks@##1}%
+ }%
+ }%
+ \xwm@resa
+ }%
+ }%
+ \expandafter\xwm@resa\reserved@a-\xwm@nil-%
+ \s@expandarg\ifnullTF{\the\toks@}{}{%
+ \xwm@err{'boxalign' has invalid or inconsistent
+ \MsgBrk values '#1'}\@ehc
+ }%
+ \ifcsnullTF\xwm@tempa{}{%
+ \ifcsnullTF\xwm@tempb{}{%
+ \xwm@err{Invalid values '#1' for 'boxalign':
+ \MsgBrk possibly a mixture of styles}\@ehc
+ }%
+ }%
+ \def\xwm@tempc{}%
+ \ifcsnullTF\xwm@tempa{}{%
+ \def\xwm@resa##1##2##3\xwm@nil##4{%
+ \ifblankTF{##3}{}{%
+ \ifinsetFT{,##1,}{,##4,}{}{%
+ \xifinsetTF{##2}{\xwm@tempc}{}{%
+ \edef\xwm@tempc{\xwm@tempc##2}%
+ }%
+ }%
+ \xwm@resa##3\xwm@nil{##4}%
+ }%
+ }%
+ \cptexpandarg
+ {\xwm@resa{center}{c}{justified}{s}{left}{l}{right}{r}%
+ {top}{t}{bottom}{b}\xwm@mil\xwm@mil\xwm@nil}\xwm@tempa
+ }%
+ \ifcsnullTF\xwm@tempb{}{%
+ \def\siso@do##1{%
+ \ifinsetFT{,##1,}{,l,r,b,t,c,s,}{}{%
+ \xifinsetTF{##1}{\xwm@tempc}{}{%
+ \edef\xwm@tempc{\xwm@tempc##1}%
+ }%
+ }%
+ }%
+ \simpleexpandarg\siso@@loop\xwm@tempb
+ }%
+ \ifcsnullTF\xwm@tempc{%
+ \xifblankTF{#1}{%
+ \def\xwm@tempc{s}%
+ }{%
+ \xwm@err{Invalid entries '#1' for 'boxalign'}\@ehc
+ }%
+ }{%
+ \begingroup
+ \cpt@cnta\z@pt
+ \def\siso@do##1{\advance\cpt@cnta\@ne}%
+ \s@expandarg\siso@@loop\xwm@tempc
+ \ifnum\cpt@cnta>2\relax
+ \xwm@err{More than two entries '#1' for 'boxalign'}\@ehc
+ \fi
+ \endgroup
+ }%
+ \let#1=\xwm@tempc
+ \postgroupdef#1\endgroup
+}
+\robust@def*\xwm@notenddocerr{%
+ \xwm@err{Wrong location of \noexpand\enddocument command}\@ehc
+}
+\robust@def*\AfterEndOfDocument{\grightaddtocs\xwm@afterenddoc}
+\new@def*\xwm@afterenddoc{}
+\robust@def*\AfterLastPageOfDocument{%
+ \grightaddtocs\xwm@afterlastpage
+}
+\new@def*\xwm@afterlastpage{}
+\AtEndDocument{%
+ \let\xwm@aft@renddoc\AtVeryEnd@AtVeryEndDocumentHook
+ \def\AtVeryEnd@AtVeryEndDocumentHook{%
+ \let\AfterEndOfDocument\@firstofone
+ \xwm@afterenddoc\xwm@aft@renddoc
+ \let\AfterEndOfDocument\xwm@notenddocerr
+ \undefcs\xwm@afterenddoc
+ \undefcs\xwm@aft@renddoc
+ }%
+ \let\xwm@afterl@stpage\AtVeryEnd@AfterLastShipoutHook
+ \def\AtVeryEnd@AfterLastShipoutHook{%
+ \let\AfterLastPageOfDocument\@firstofone
+ \xwm@afterlastpage\xwm@afterl@stpage
+ \let\AfterLastPageOfDocument\xwm@notenddocerr
+ \undefcs\xwm@afterlastpage
+ \undefcs\xwm@afterl@stpage
+ }%
+ \let\xwm@n@wlabel\xwm@testdef
+}
+\robust@def*\xwm@newlabel{\xwm@n@wlabel{xwmr}}
+\robust@def*\xwm@n@wlabel#1#2#3{%
+ \begingroup
+ \ifcsndefFT{#1@#2}{}{%
+ \gdef\xwm@multiplelabels{%
+ \@ltx@warn{There were multiply-defined labels}%
+ }%
+ \@ltx@warn{Label '#2' multiply defined}%
+ }%
+ \csn@gdef{#1@#2}{#3}%
+ \endgroup
+}
+\let\xwm@multiplelabels\relax
+\BeforeStartOfDocument{%
+ \global\let\xwm@multiplelabels\relax
+}
+\robust@def*\xwm@testdef#1#2#3{%
+ \begingroup
+ \def\xwm@tempa{#3}%
+ \aftercsname\ifxTF{#1@#2}\xwm@tempa
+ {\global\xwm@swafalse}{\global\xwm@swatrue}%
+ \endgroup
+}
+\AfterLastPageOfDocument{%
+ \if@filesw
+ \begingroup
+ \advance\c@page\m@one
+ \xwmlabel{xwmlastpage}%
+ \endgroup
+ \fi
+ \immediate\closeout\xwm@wrt
+ \InputIfFileExists{\jobname.xwm}{}{}%
+ \if@filesw
+ \ifx\xwm@multiplelabels\relax
+ \ifxwm@swa
+ \@ltx@warn{Label(s) may have changed.
+ Rerun to get cross-references right}%
\fi
+ \else
+ \xwm@multiplelabels
\fi
+ \fi
+}
+\new@def*\xwm@labelcarr#1#2#3\xwm@nil{\ifblankTF{#3}{}{#2}}
+\new@def*\xwmgetpagenumber#1{%
+ \ifcsndefTF{xwmr@#1}{%
+ \cptsevenxp\xwm@labelcarr
+ \usename{xwmr@#1}\xwm@defaultfirstpage\xwm@nil
}{%
- \xwm@err{Too many hyphens in page range}%
+ \xwm@defaultfirstpage
}%
}
-\new\def\xwm@pagerange@ifhyphen#1-#2\@nil{%
- \ifstrempty{#2}{\@firstoftwo}{\@secondoftwo}%
+\new@def*\lastdocpage{\xwmgetpagenumber{xwmlastpage}}
+\robust@def*\xwmlabel#1{%
+ \@bsphack
+ \begingroup
+ \@onelevel@sanitize\@currentlabelname
+ \edef\@currentlabelname{%
+ \expandafter\strip@period\@currentlabelname\relax.\relax\@@@
+ }%
+ \immediate\write\@auxout{%
+ \string\newlabel{#1}{{\@currentlabel}{\thepage}%
+ {\@currentlabelname}{\@currentHref}{}}%
+ }%
+ \immediate\write\xwm@wrt{%
+ \string\xwm@newlabel{#1}{{\@currentlabel}{\thepage}%
+ {\@currentlabelname}{\@currentHref}{}}%
+ }%
+ \endgroup
+ \@esphack
}
-\@ifpackageloaded{fix-cm}{}{\RequirePackage{fix-cm}[2006/03/24]}
-\@ifpackageloaded{graphicx}{}{\RequirePackage{graphicx}[1999/02/16]}
-\@ifpackageloaded{xkeyval}{}{\RequirePackage{xkeyval}[2008/08/13]}
-\@ifpackageloaded{atbegshi}{}{\RequirePackage{atbegshi}[2008/07/31]}
-\@ifpackageloaded{picture}{}{\RequirePackage{picture}[2008/11/26]}
-\@ifpackageloaded{xcolor}{%
- \xwm@info{You have loaded 'xcolor' package\MessageBreak
- with options that possibly differ\MessageBreak
- from those used in 'xwatermark' package}
-}{%
- \RequirePackage[table,hyperref]{xcolor}[2007/01/21]
- \xwm@info{'xcolor' package loaded with\MessageBreak
- options 'table', 'hyperref'}
-}
-\@ifpackageloaded{xifthen}{}{\RequirePackage{xifthen}[2009/04/17]}
-\@ifpackageloaded{boxedminipage}{}{\RequirePackage{boxedminipage}}
-\@ifpackageloaded{keyreader}{}{\RequirePackage{keyreader}[2010/01/01]}
-\krsetup{parser=;,macroprefix=xwm@,keyprefix=XWM,keyfamily=xwatermark}
-\xwm@dimdef{\xwm@xcoord@a}{\z@}
-\xwm@dimdef{\xwm@ycoord@a}{\z@}
-\xwm@numdef{\xwm@minmark}{\z@}
-\xwm@numdef{\xwm@c@printmark}{\z@}
-\new\let\xwm@papercenter\relax
-\providetoggle{pdf}
-\ifundef\pdfoutput{}{\unless\ifnum\pdfoutput<1\toggletrue{pdf}\fi}
-\define@boolkey[XWM]{xwatermark}[xwm@]{printwatermark}[true]{%
- \ifxwm@printwatermark\xwm@minmark=\@ne\fi}
-\define@boolkeys[XWM]{xwatermark}[xwm@bool@]{onepageonly,%
- prange,tmark,pmark,showcenter}[true]
-\define@boolkey[XWM]{xwatermark}[xwm@]{firstpage}[true]{%
- \ifxwm@firstpage\xwm@minmark=1\fi}
-\define@boolkey[XWM]{xwatermark}[xwm@]{allpages}[true]{%
- \ifxwm@allpages\xwm@minmark=1\fi}
-\define@boolkey[XWM]{xwatermark}[xwm@]{oddpages}[true]{%
- \ifxwm@oddpages\xwm@minmark=1\fi}
-\define@boolkey[XWM]{xwatermark}[xwm@]{evenpages}[true]{%
- \ifxwm@evenpages\xwm@minmark=1\fi}
-\define@boolkey[XWM]{xwatermark}[xwm@]{dgeometry}[true]{%
- \AtEndPreamble{%
- \ifxwm@dgeometry
- \ifcsdef{geometry}{%
- \geometry{pass}%
- \xwm@info{I've detected that you've loaded the\MessageBreak
- 'geometry' package. To avoid scale changes by\MessageBreak
- 'geometry', I have disabled its features.\MessageBreak
- You should set your watermarks before using\MessageBreak
- 'geometry'}}{}%
+\InputIfFileExists{\jobname.xwm}{}{}
+\if@filesw
+ \immediate\openout\xwm@wrt=\jobname.xwm
+ \immediate\write\xwm@wrt{\relax}
+\fi
+\robust@def*\DeclareWatermarkParser#1{%
+ \begingroup
+ \stripallbr{#1}\xwm@tempa
+ \xdef\xwm@watermarkparser{\cptoxdetok\xwm@tempa}%
+ \endgroup
+}
+\DeclareWatermarkParser{;}
+\robust@def*\xwm@put{\leavevmode\put}
+\new@edef*\xwm@defaultfileext{\ifxwm@pdf pdf\else eps\fi}
+\new@def*\xwm@picfilesread{}
+\robust@def*\xwm@fileextfn#1#2{%
+ \ifcsndefFT{#2picfile}{}{%
+ \def\xwm@tempb##1##2{%
+ \xwm@warn{Default file extension '##1'\MsgBrk
+ substituted for invalid '#1' in\MsgBrk
+ ##2 mode. I'll later confirm the\MsgBrk
+ existence of \usename{#2picfile}.##1%
+ }%
+ }%
+ \ifcsnnullTF{#2picfile}{%
+ \csn@edef{#2picfileext}{}%
+ }{%
+ \xifinsetTF{,\usename{#2picfile},}{,\xwm@picfilesread,}{%
+ \xwm@swbfalse
+ }{%
+ \xwm@swbtrue
+ \cptgxaddtolist*\xwm@picfilesread{\usename{#2picfile}}%
+ }%
+ \aftercsname\stripallbrincs{#2picfileext}%
+ \if@boolTF{xwm@pdf}{%
+ \xifinsetTF{,\usename{#2picfileext},}{,pdf,png,jpeg,jpg,mps,}{}{%
+ \csn@def{#2picfileext}{pdf}%
+ \ifxwm@swb\xwm@tempb{pdf}{pdf}\fi
+ }%
+ }{%
+ \xifinsetTF{,\usename{#2picfileext},}{,eps,ps,}{}{%
+ \csn@def{#2picfileext}{eps}%
+ \ifxwm@swb\xwm@tempb{eps}{dvi}\fi
+ }%
+ }%
+ }%
+ }%
+}
+\ltxkeys@boolkey[XWM]{main}[xwm@]{disablegeometry}[true]{%
+ \BeforeStartOfDocument{%
+ \ifxwm@disablegeometry
+ \ifdefFT\geometry{}{%
+ \geometry{pass}%
+ \xwm@info{On your request (ie, 'disablegeometry=true')
+ \MsgBrk I have disabled the features of the
+ \MsgBrk 'geometry' package}%
+ }%
\fi
}%
}
-\define@choicekey*+[XWM]{xwatermark}{align}[\val\nr]%
-{center,right,left,justified}[center]{%
- \ifcase\nr\relax
- \def\xwm@align{\centering}%
- \or
- \def\xwm@align{\flushright}%
- \or
- \def\xwm@align{\flushleft}%
- \or
- \let\xwm@align\relax
+\new@def*\xwm@gr@phicsoptions{}
+\robust@def*\GraphicsOptions#1{\gdef\xwm@gr@phicsoptions{#1}}
+\ltxkeys@definekeys*[XWM]<main>[xwm@]{%
+ disable-geometry=true/\setmnkey{disablegeometry};
+ printwatermark=true;
+ print-watermark=true/\setmnkey{printwatermark};
+ allownesting=true;
+ showpagecenter=true/\if@boolTF{xwm@showpagecenter}
+ {\wmk@showpagecentertrue\wlp@showpagecentertrue}{};
+ show-page-center=true/\setmnkey{showpagecenter};
+ showpapercenter=true/\setmnkey{showpagecenter};
+ usedummymarks=true;
+ use-dummy-marks=true/\setmnkey{usedummymarks};
+ defaultfirstpage=1;
+ default-first-page=1/\setmnkey{defaultfirstpage};
+ defaultlastpage=\xwmgetpagenumber{xwmlastpage};
+ default-last-page=\xwmgetpagenumber{xwmlastpage}/
+ \setmnkey{defaultlastpage};
+ frontpagestyle=empty;
+ front-page-style=empty/\setmnkey{frontpagestyle};
+ watermarkparser={;}/\DeclareWatermarkParser{#1};
+ watermark-parser={;}/\setmnkey{watermarkparser};
+ resetpaperorigin=true/\ifxwm@resetpaperorigin\pdfhorigin\z@pt
+ \pdfvorigin\z@pt\hoffset\z@pt\voffset\z@pt\fi;
+ reset-paper-origin=true/\setmnkey{resetpaperorigin};
+}
+\ltxkeys@biboolkeys+[XWM]{main}[xwm@]{draft,final}[true]
+ {}{}{\ltxkeys@keyvalerr}
+\makeoption@keys[XWM]{main}
+\BeforeStartOfDocument{%
+ \ifxwm@printwatermark
+ \cptreplaceoneelement\XWM@main@initial@keyvals
+ {printwatermark=false}{printwatermark=true}%
\fi
-}{%
- \xwm@err{Inadmissible value '\string#1' for align}%
-}
-\define@cmdkey[XWM]{xwatermark}[xwm@]{page}[1]{%
- \xwm@bool@onepageonlytrue\xwm@minmark=\@ne
-}
-\define@key[XWM]{xwatermark}{pages}[1-1]{%
- \xwm@bool@prangetrue
- \xwm@pagerange{#1}\xwm@minmark=\@ne
-}
-\iftoggle{pdf}{\new\def\xwm@picfilex{pdf}}{\new\def\xwm@picfilex{eps}}
-\define@cmdkey[XWM]{xwatermark}[xwm@]{picfile}[]{%
- \ifstrempty{#1}{\xwm@bool@pmarkfalse}{%
- \xwm@bool@pmarktrue\xwm@minmark=\@ne
- }%
-}
-\define@cmdkey[XWM]{xwatermark}[xwm@]{textmark}[DRAFT]{%
- \ifstrempty{#1}{\xwm@bool@tmarkfalse}{\xwm@bool@tmarktrue}%
-}
-\define@cmdkey[XWM]{xwatermark}[xwm@]{picfilex}[eps]{%
- \ifthenelse{\equal{\xwm@picfilex}{pdf}\OR\equal{\xwm@picfilex}{png}
- \OR\equal{\xwm@picfilex}{jpeg}\OR\equal{\xwm@picfilex}{eps}}{}{%
- \xwm@err{File extension \xwm@picfilex\space inadmissible}}
- \iftoggle{pdf}{%
- \ifthenelse{\isempty{\xwm@picfilex}\OR\equal{\xwm@picfilex}{eps}}%
- {\def\xwm@picfilex{pdf}}{}%
- }{%
- \ifthenelse{\isempty{\xwm@picfilex}\OR\equal{\xwm@picfilex}{pdf}%
- \OR\equal{\xwm@picfilex}{png}\OR\equal{\xwm@picfilex}{jpeg}}%
- {\def\xwm@picfilex{eps}}{}%
- }%
-}
-\define@keylist{2,color,gray!25,;2,fontfamily,bch,;2,angle,45,;
- 2,scale,1,;2,coordunit,mm,;2,fontsize,5cm,;2,fontseries,b,;
- 2,height,\paperwidth,;2,width,\paperheight,;2,xcoord,\z@,;
- 2,ycoord,\z@,;2,picscale,1,;2,picbb,0 0 100 100,}
-\presetkeys[XWM]{xwatermark}{tmark,angle,scale,color,
- textmark,fontfamily,fontsize,fontseries,coordunit,
- align,height,width,xcoord,ycoord,picscale,picbb}{}
-\DeclareOptionX*{\xwm@warn{Unknown option '\CurrentOption' ignored}}
-\ExecuteOptionsX[XWM]<xwatermark>{printwatermark}
-\ProcessOptionsX*[XWM]<xwatermark>\relax
-\newrobustcmd\watermarksetup[1]{\setkeys[XWM]{xwatermark}{#1}}
-\AtBeginDocument{%
- \xwm@disable@keys[XWM]{xwatermark}{printwatermark,dgeometry}%
-}
-\new\def\xwm@coords{\begingroup%
- \protected@edef\@tempa{\endgroup%
- \xwm@dimdef{\xwm@xcoord@a}{0.5\paperwidth+
- \number\xwm@xcoord\xwm@coordunit}%
- \xwm@dimdef{\xwm@ycoord@a}{-0.5\paperheight+
- \number\xwm@ycoord\xwm@coordunit}%
- }\@tempa
-}
-\unless\ifxwm@printwatermark
- \xwm@info{printwatermark=false: no watermark printed}
-\fi
-\newcommand\xwm@papercenter{%
- \color{red}%
- \put(0,-0.5\paperheight){\line(1,0){\paperwidth}}%
- \put(0.5\paperwidth,0){\line(0,-1){\paperheight}}%
- \put(0.5\paperwidth,-0.5\paperheight){\circle{10}}%
- \normalcolor
}
-\newcommand\xwm@insert@textmark@a{%
- \leavevmode\removelastskip\noindent%
- \makebox(0,0){\rotatebox[origin=c]{\xwm@angle}{\scalebox{\xwm@scale}{%
- \parbox[c][\xwm@height][c]{\xwm@width}{%
- \color{\xwm@color}%
- \fontfamily{\xwm@fontfamily}\fontseries{\xwm@fontseries}%
- \fontsize{\xwm@fontsize}{1.2\xwm@fontsize}\selectfont
- \xwm@align\xwm@textmark
- }}}}%
- \removelastskip\normalcolor
-}
-\newcommand\xwm@insert@picmark@a{%
- \xwm@align
- \makebox(0,0){\rotatebox{\xwm@angle}{\xwm@insertpic}}%
-}
-\newcommand\xwm@insert@textmark@b{%
- \put(\xwm@xcoord@a,\xwm@ycoord@a){\xwm@insert@textmark@a}%
-}
-\newcommand\xwm@insert@picmark@b{%
- \put(\xwm@xcoord@a,\xwm@ycoord@a){\xwm@insert@picmark@a}%
-}
-\newcommand\xwm@insert@mark@a{%
- \xwm@coords
- \ifxwm@bool@tmark\xwm@insert@textmark@b\fi
- \ifxwm@bool@pmark\xwm@insert@picmark@b\fi
- \ifxwm@bool@showcenter\xwm@papercenter\fi
-}%
-\newcommand\xwm@insertmark{%
- \ifnum\xwm@minmark=\@ne
- \ifxwm@allpages
- \xwm@insert@mark@a
- \else\ifxwm@firstpage
- \ifnum\c@page=\@ne\xwm@insert@mark@a\fi
- \else\ifxwm@oddpages
- \ifodd\c@page\xwm@insert@mark@a\fi
- \else\ifxwm@evenpages
- \unless\ifodd\c@page\xwm@insert@mark@a\fi
- \else\ifxwm@bool@onepageonly
- \ifnum\c@page=\number\xwm@page\xwm@insert@mark@a\fi
- \else\ifxwm@bool@prange
- \ifthenelse{\(\c@page=\xwm@pagestart\OR\c@page=\xwm@pageend\)
- \OR\(\c@page>\xwm@pagestart\AND\c@page<\xwm@pageend\)}{%
- \xwm@insert@mark@a}{}%
- \else\ifxwm@printwatermark
- \ifnum\c@page=\@ne
- \xwm@bool@tmarktrue\xwm@bool@pmarkfalse
- \xwm@dimdef{\xwm@xcoord@a}{0.5\paperwidth}%
- \xwm@dimdef{\xwm@ycoord@a}{-0.5\paperheight}%
- \xwm@insert@mark@a
- \xwm@info{Draftmark printed on page 1 only:\MessageBreak
- You've specified no pages for watermark}%
- \fi
- \fi\fi\fi\fi\fi\fi\fi
+\robust@def*\xwm@defcommonkeys#1{%
+ \begingroup
+ \endlinechar\m@one
+ \expandafter\endgroup\xwm@defc@mmonkeys{#1}%
+}
+\robust@def*\xwm@defc@mmonkeys#1#2{%
+ \csn@def{#1@commonkeys}##1{#2}%
+ \AtEndOfPackage{\letcsntocs{#1@commonkeys}\relax}%
+}
+\xwm@defcommonkeys{xwm-1}{%
+ minmark=true;
+ onepageonly=true;
+ prange=true;
+ tmark=true;
+ pmark=true;
+ graphicsoptions={}/
+ \ifbracedTF{##1}{%
+ \aftercsname{\stripallbr{##1}}{#1graphicsoptions}
+ }{
+ \cpt@err{Values of key 'graphicsoptions' not braced}\@ehc
+ };
+ GraphicsOptions=/
+ \ifdocstartedTF{%
+ \xwm@err{\noexpand\GraphicsOptions
+ is a command, not a key.\MsgBrk
+ Maybe you meant 'graphicsoptions'}\@ehc
+ }{};
+ picontoptext=true;
+ picture-on-top-text=true/\setmnkey{picontoptext};
+ pic-on-top-text=true/\setmnkey{picontoptext};
+ textontoppic=true/\setmnkey{picontoptext}[false];
+ text-on-top-picture=true/\setmnkey{picontoptext}[false];
+ text-on-top-pic=true/\setmnkey{picontoptext}[false];
+ draftboxcolor=blue;
+ draft-box-color=blue/\setmnkey{draftboxcolor};
+ textcolor=gray!25;
+ text-color=gray!25/\setmnkey{textcolor};
+ color=gray!25/\setmnkey{textcolor};
+ textangle=0;
+ text-angle=0/\setmnkey{textangle};
+ angle=0/\setmnkey{textangle};
+ textscale=1;
+ text-scale=1/\setmnkey{textscale};
+ scale=1/\setmnkey{textscale};
+ textalign=center/\aftercsname\xwm@settextalign{#1textalign};
+ text-align=center/\setmnkey{textalign};
+ align=center/\setmnkey{textalign};
+ showpagecenter=true/\ifboolTF{#1showpagecenter}{%
+ \usename{#1showpagecentertrue}}{\usename{#1showpagecenterfalse}};
+ show-page-center=true/\setmnkey{showpagecenter};
+ showpapercenter=true/\setmnkey{showpagecenter};
+ fontsize=1cm/\aftercsname{\xwm@defaultunits{##1}}{#1fontsize};
+ font-size=1cm/\setmnkey{fontsize};
+ fontseries=b;
+ font-series=b/\setmnkey{fontseries};
+ fontfamily=bch;
+ font-family=bch/\setmnkey{fontfamily};
+ \needvalue{picfile}=/\aftercsname\stripallbrincs{#1picfile}
+ \ifcsnnullTF{#1picfile}{\usename{#1pmarkfalse}}{\usename{#1pmarktrue}
+ \usename{#1minmarktrue}};
+ \needvalue{picture-file}=/\setmnkey{picfile};
+ picfileext=\xwm@defaultfileext/\xwm@fileextfn{##1}{#1};
+ pic-file-ext=\xwm@defaultfileext/\setmnkey{picfileext};
+ picangle=0;
+ picture-angle=0/\setmnkey{picangle};
+ picscale=1;
+ picture-scale=1/\setmnkey{picscale};
+ picbb=0 0 100 100;
+ picture-bb=0 0 100 100/\setmnkey{picbb};
+ pic-bounding-box=0 0 100 100/\setmnkey{picbb};
+ picxpos=\z@pt;
+ picture-xpos=0/\setmnkey{picxpos};
+ picture-x-position=0/\setmnkey{picxpos};
+ picypos=\z@pt;
+ picture-ypos=0/\setmnkey{picypos};
+ picture-y-position=0/\setmnkey{picypos};
+ mark=DRAFT/\setmnkey{textmark};
+ textmark=DRAFT/
+ \aftercsname\stripallbrincs{#1textmark}
+ \ifcsnnullTF{#1textmark}{%
+ \usename{#1tmarkfalse}
+ }{
+ \usename{#1tmarktrue}
+ }
+ \letcstocsn\currentmark{#1textmark};
+ text-mark=DRAFT/\setmnkey{textmark};
+ firstpage=true/\if@boolFT{#1firstpage}{}{\usename{#1minmarktrue}};
+ first-page=true/\setmnkey{firstpage};
+ allpages=true/\if@boolFT{#1allpages}{}{\usename{#1minmarktrue}};
+ oddpages=true/\if@boolFT{#1oddpages}{}{\usename{#1minmarktrue}};
+ evenpages=true/\if@boolFT{#1evenpages}{}{\usename{#1minmarktrue}};
+ page=1/
+ \ifinsetTF{-}{##1}{%
+ \xwm@err{I found '-' in '##1' for key 'page',
+ \MsgBrk but 'page' doesn't take page-range}\@ehc
+ }{
+ \ifnum\numexpr##1=\z@pt\else\usename{#1onepageonlytrue}
+ \usename{#1minmarktrue}\fi
+ };
+ pages=1-1/
+ \aftercsname\stripallbrincs{#1pages}
+ \aftercsname\cptstrcmp{#1pages}{0-0}{}{%
+ \usename{#1prangetrue}\usename{#1minmarktrue}
+ }
+ \cptexpandsecond\xwm@hyphenpagerange{\cptmakecs{#1pages}
+ \cptmakecs{#1pagestart}\cptmakecs{#1pageend}};
+ pagex={1}/
+ \ifbracedTF{##1}{}{%
+ \xwm@err{Value of key 'pagex' must be braced}\@ehc
+ };
+ boxalign=/\ifblankTF{##1}{}
+ {\aftercsname\xwm@setboxalign{#1boxalign}};
+ box-align=/\setmnkey{boxalign};
+}
+\robust@def*\xwm@adddefkeys{%
+ \begingroup
+ \endlinechar\m@one
+ \cpt@testopt\xwm@addd@fkeys{}%
+}
+\robust@def\xwm@addd@fkeys[#1]#2#3#4#5{%
+ \def\xwm@tempa{\endgroup#4}%
+ \expandafter\expandafter\expandafter\xwm@tempa
+ \expandafter\expandafter\expandafter
+ {\csname#2@commonkeys\endcsname{#3}#1#5}%
+}
+\xwm@adddefkeys[;]{xwm-1}{wmk@}
+ {\ltxkeys@definekeys*[XWM]<watermark>[wmk@]}{%
+ textwidth=\paperheight;
+ text-width=\paperheight/\setmnkey{textwidth};
+ width=\paperheight/\setmnkey{textwidth};
+ textheight=\paperwidth;
+ text-height=\paperwidth/\setmnkey{textheight};
+ height=\paperwidth/\setmnkey{textheight};
+ \needvalue{picheight}=;
+ pic-height=/\setmnkey{picheight};
+ picture-height=/\setmnkey{picheight};
+ \needvalue{picwidth}=;
+ picture-width=/\setmnkey{picwidth};
+ textxpos=0;
+ text-xpos=0/\setmnkey{textxpos};
+ text-x-position=0/\setmnkey{textxpos};
+ xpos=0/\setmnkey{textxpos};
+ textypos=0;
+ text-ypos=0/\setmnkey{textypos};
+ text-y-position=0/\setmnkey{textypos};
+ ypos=0/\setmnkey{textypos};
+ coordunit=mm/\xwm@checkcoordunit{#1};
+ coord-unit=mm/\setmnkey{coordunit};
+ position-unit=mm/\setmnkey{coordunit};
+}
+\makeoption@keys*[XWM]{watermark}
+\xwm@adddefkeys[;]{xwm-1}{wlp@}
+ {\ltxkeys@definekeys*[XWM]<wallpaper>[wlp@]}{%
+ textheight=\wlp@tileysize;
+ text-height=\wlp@tileysize/\setmnkey{textheight};
+ textwidth=\wlp@tilexsize;
+ text-width=\wlp@tilexsize/\setmnkey{textwidth};
+ picheight=\wlp@tileysize;
+ picture-height=\wlp@tileysize/\setmnkey{picheight};
+ picwidth=\wlp@tilexsize;
+ picture-width=\wlp@tilexsize/\setmnkey{picwidth};
+ tilexsize=.25\paperwidth;
+ tile-xsize=.25/\setmnkey{tilexsize};
+ tileysize=.25\paperheight;
+ tile-ysize=.25/\setmnkey{tileysize};
+ wpxoffset=\z@pt;
+ wallpaper-xoffset=\z@pt/\setmnkey{wpxoffset};
+ wpyoffset=\z@pt;
+ wallpaper-yoffset=\z@pt/\setmnkey{wpyoffset};
+ tilexoffset=\z@pt;
+ tile-xoffset=\z@pt/\setmnkey{tilexoffset};
+ tileyoffset=\z@pt;
+ tile-yoffset=\z@pt/\setmnkey{tileyoffset};
+ tileno=4;
+ tilenumber=4/\setmnkey{tileno};
+ tile-number=4/\setmnkey{tileno};
+ number-of-tiles=4/\setmnkey{tileno};
+ squaretiles=true;
+ square-tiles=true/\setmnkey{squaretiles};
+}
+\makeoption@keys*[XWM]{wallpaper}
+\ltxkeys@definekeys*[XWM]<fancypagenos>[pgn@]{%
+ textalign=center/\xwm@settextalign\pgn@textalign;
+ text-align=center/\setmnkey{textalign};
+ align=center/\setmnkey{textalign};
+ boxalign=/\ifblankTF{#1}{}{\xwm@setboxalign\pgn@boxalign};
+ box-align=center/\setmnkey{boxalign};
+ textangle=0;
+ text-angle=0/\setmnkey{textangle};
+ angle=0/\setmnkey{textangle};
+ picangle=0;
+ picture-angle=0/\setmnkey{picangle};
+ textwidth=.25\textwidth;
+ text-width=.25/\setmnkey{textwidth};
+ width=.25\hsize/\setmnkey{textwidth};
+ textheight=.25\textheight;
+ text-height=.25/\setmnkey{textheight};
+ height=.25\vsize/\setmnkey{textheight};
+ textxpos=\z@pt;
+ x-position=0/\setmnkey{textxpos};
+ xpos=\z@pt/\setmnkey{textxpos};
+ textypos=\z@pt;
+ y-position=0/\setmnkey{textypos};
+ ypos=\z@pt/\setmnkey{textypos};
+ textcolor=blue;
+ text-color=blue/\setmnkey{textcolor};
+ color=blue/\setmnkey{textcolor};
+ textscale=2.5;
+ text-scale=2.5/\setmnkey{textscale};
+ scale=2.5/\setmnkey{textscale};
+ coordunit=mm/\xwm@checkcoordunit{#1};
+ coord-unit=mm/\setmnkey{coordunit};
+ position-unit=mm/\setmnkey{coordunit};
+ fontfamily=bch;
+ font-family=bch/\setmnkey{fontfamily};
+ fontseries=m;
+ font-series=m/\setmnkey{fontseries};
+ format=\fbox;
+ fontsize=12\p@/\xwm@defaultunits{#1}\pgn@fontsize;
+ font-size=12/\setmnkey{fontsize};
+ cfoot;
+ center-footer=/\setmnkey{cfoot};
+ footer-center=/\setmnkey{cfoot};
+ rfoot;
+ right-footer=/\setmnkey{rfoot};
+ footer-right=/\setmnkey{rfoot};
+ lfoot;
+ left-footer=/\setmnkey{lfoot};
+ footer-left=/\setmnkey{lfoot};
+ chead;
+ center-header=/\setmnkey{chead};
+ header-center=/\setmnkey{chead};
+ rhead;
+ right-header=/\setmnkey{rhead};
+ header-right=/\setmnkey{rhead};
+ lhead;
+ left-header=/\setmnkey{lhead};
+ header-left=/\setmnkey{lhead};
+ headruleH=.4\p@;
+ headrule-height=.4\p@/\setmnkey{headruleH};
+ headruleD=.4\p@;
+ head-rule-depth=.4\p@/\setmnkey{headruleD};
+ headruleW=\headwidth;
+ headrule-width=\headwidth/\setmnkey{headruleW};
+ headruleS=2\p@;
+ head-rule-sep=2\p@/\setmnkey{headruleS};
+ head-rule-separation=2\p@/\setmnkey{headruleS};
+ headruleC=blue;
+ headrule-color=blue/\setmnkey{headruleC};
+ footruleH=.4\p@;
+ foot-rule-height=.4\p@/\setmnkey{footruleH};
+ footruleD=.4\p@;
+ footrule-depth=.4\p@/\setmnkey{footruleD};
+ footruleW=\headwidth;
+ footrule-width=\headwidth/\setmnkey{footruleW};
+ footruleS=2\p@;
+ footrule-sep=2\p@/\setmnkey{footruleS};
+ footrule-separation=2\p@/\setmnkey{footruleS};
+ footruleC=cyan;
+ footrule-color=blue/\setmnkey{footruleC};
+ hfoffsetL=.5;
+ hfoffset-left=.5/\setmnkey{hfoffsetL};
+ hfoffsetR=.5;
+ hfoffset-right=.5/\setmnkey{hfoffsetR};
+ style=\thepage;
+ printstyle=\thepage/\setmnkey{style};
+ print-style=\thepage/\setmnkey{style};
+ sendtoback=true;
+ send-to-back=true/\setmnkey{sendtoback};
+}
+\makeoption@keys*[XWM]{fancypagenos}
+\ltxkeys@definekeys*[XWM]<fancypagenos>[pgn@]{%
+ showpagenos=true/\ifpgn@showpagenos\global\pgn@showpagenostrue\fi;
+ show-page-numbers=true/\setmnkey{showpagenos};
+ show-pagenos=true/\setmnkey{showpagenos};
+ show-pageno=true/\setmnkey{showpagenos};
+ showonpageone=true;
+ show-on-page-1=true/\setmnkey{showonpageone};
+ show-on-page-one=true/\setmnkey{showonpageone};
+ showheadrule=true;
+ show-headrule=true/\setmnkey{showheadrule};
+ showfootrule=true;
+ show-footrule=true/\setmnkey{showfootrule};
+}
+\BeforeStartOfDocument{%
+ \ifpgn@showpagenos
+ \cptreplaceoneelement\XWM@fancypagenos@initial@keyvals
+ {showpagenos=false}{showpagenos=true}%
\fi
}
-\ifxwm@printwatermark
- \AtBeginShipout{\AtBeginShipoutUpperLeft{\xwm@insertmark}}%
- \xwm@info{Option 'printwatermark=true': watermark printed}%
-\fi
-\krsetup{keyfamily=minipage,macroprefix=mp@}%
-\define@keylist{2,width,\paperwidth,;2,textcolor,black,;
- 2,framecolor,white,;2,framesep,3pt,;2,framerule,0.4pt,;
- 2,text,No text passed.,}%
-\define@key[XWM]{minipage}{align}[center]{%
+\robust@def*\PrintWatermark{\global\xwm@printwatermarktrue}
+\ltxkeys@declareoption*{%
+ \ltxkeys@getpvalnopad
+ \xwm@warn{Unknown option '\CurrentKey' with
+ value '\InnocentVal' ignored}%
+}
+\ltxkeys@executeoptions[XWM]<main>{%
+ printwatermark=true,disablegeometry=false
+}\relax
+\ltxkeys@processoptions*[XWM]<main,watermark,wallpaper,%
+ fancypagenos>\relax
+\new@def*\xwm@samplemarkkeys{%
+ firstpage,lastpage,allpages,oddpages,evenpages,
+ picscale,picture-scale,
+ picfile,picture-file,
+ picfileext,pic-file-ext,
+ picangle,picture-angle,
+ picbb,picture-bb,pic-bounding-box,
+ picxpos,picture-xpos,picture-x-position,
+ picypos,picture-ypos,picture-y-position,
+ showpagecenter,show-page-center,
+ picontoptext,picture-on-top-text,pic-on-top-text,
+ textontoppic,text-on-top-picture,text-on-top-pic=true,
+ pic-height,picture-height,
+ picwidth,picture-width,
+ squaretiles,square-tiles,
+ tilexsize,tile-xsize,
+ tileysize,tile-ysize,
+ wpxoffset,wallpaper-xoffset,
+ wpyoffset,wallpaper-yoffset,
+ tilexoffset,tile-xoffset,
+ tileyoffset,tile-yoffset,
+ tileno,tilenumber,tile-number,number-of-tiles
+}
+\new@def*\xwm@pagespecifiers{%
+ page=,pages=,pagex=,firstpage,lastpage,allpages,%
+ oddpages,evenpages%
+}
+\robust@def*\xwm@decidedetok#1{%
+ \ifsingletokenTF{#1}{%
+ \ifmacroTF{#1}{%
+ \let\xwm@detok\cptoxdetok
+ }{%
+ \let\xwm@detok\detokenize
+ }%
+ }{%
+ \let\xwm@detok\detokenize
+ }%
+}
+\robust@def*\xwm@decidexp#1{%
+ \ifsingletokenTF{#1}{%
+ \ifmacroTF{#1}{%
+ \let\xwm@xp\expandcsonce
+ }{%
+ \let\xwm@xp\unexpanded
+ }%
+ }{%
+ \let\xwm@xp\unexpanded
+ }%
+}
+\robust@def*\newwatermark#1{%
+ \xwm@wallfalse
+ \ifstrcmpTF{#1}\dummywatermark{%
+ \xwm@err{'\string\dummywatermark' in front of
+ \string\newwatermark}{First comment out or
+ remove '\string\dummywatermark'.}%
+ }{%
+ \def\xwm@forelist{\xwm@forewmklist}%
+ \def\xwm@backlist{\xwm@backwmklist}%
+ \xwm@suffixcheck\xwm@newwatermark{#1}%
+ }%
+}
+\robust@def*\xnewwatermark{%
+ \cpt@teststpm{\cpt@testopt\cpt@xnewwatermark{}}%
+}
+\robust@def*\xwm@ltxcmds{%
+ \centering,\flushright,\flushleft,\raggedright,%
+ \raggedleft,\fbox,\framebox,\makebox,\rotatebox,%
+ \scalebox,\raisebox,\color,\textcolor,\usecsn,%
+ \newcommand,\lastdocpage
+}
+\robust@def*\xwm@relaxltxcmds{%
+ \def\ltxkeys@do##1{\let##1=\relax}%
+ \ltxkeys@csvparse*\xwm@ltxcmds
+}
+\robust@def*\cpt@xnewwatermark[#1]#2{%
+ \begingroup
+ \xwm@relaxltxcmds
+ \cptexpanded{%
+ \endgroup
+ \newwatermark\ifcpt@st*\fi\ifcpt@pm'\fi
+ [\expandcstwice{#1}]{\expandcstwice{#2}}%
+ }%
+}
+\robust@def*\newwallpaper#1{%
+ \xwm@walltrue
+ \ifstrcmpTF{#1}\dummywallpaper{%
+ \xwm@err
+ {'\string\dummywallpaper' in front of \string\newwallpaper}%
+ {First comment out or remove '\string\dummywallpaper'.}%
+ }{%
+ \def\xwm@forelist{\xwm@forewalllist}%
+ \def\xwm@backlist{\xwm@backwalllist}%
+ \xwm@suffixcheck\xwm@newwatermark{#1}%
+ }%
+}
+\robust@def*\xnewwallpaper{%
+ \cpt@teststpm{\cpt@testopt\cpt@xnewwallpaper{}}%
+}
+\robust@def*\cpt@xnewwallpaper[#1]#2{%
\begingroup
- \edef\x{\endgroup\noexpand\XKV@cc*+[\noexpand\val\noexpand\nr]{#1}%
- {center,right,left,justified}{}{}}%
- \x
- \ifcase\nr\relax
- \def\mp@align{\centering}%
- \or
- \def\mp@align{\flushright}%
- \or
- \def\mp@align{\flushleft}%
- \or
- \let\mp@align\relax
+ \xwm@relaxltxcmds
+ \cptexpanded{%
+ \endgroup
+ \newwallpaper\ifcpt@st*\fi\ifcpt@pm'\fi
+ [\expandcstwice{#1}]{\expandcstwice{#2}}%
+ }%
+}
+\robust@def*\xwm@newwatermark{%
+ \def\siso@do##1{\catcode`##1\string=12}%
+ \cpt@teststpm{%
+ \let\ifxwm@foregrd\ifcpt@st
+ \cpt@testopt{%
+ \begingroup
+ \expandafter\siso@@loop\expandafter
+ {\xwm@watermarkparser,;|-=!'"*}%
+ \expandafter\endgroup\xwm@n@wwatermark
+ }{}%
+ }%
+}
+\robust@def\xwm@n@wwatermark[#1]#2{%
+ \if@boolTF{cpt@pm}{}{\xwm@n@ww@termark{#1}{#2}}%
+}
+\robust@def\xwm@n@ww@termark#1#2{%
+ \xwm@decidexp{#1}%
+ \edef\xwm@currattrib{\xwm@xp{#1}}%
+ \cpt@sttrue\cpt@kvnormalize[,]\xwm@currattrib
+ \xwm@decidexp{#2}%
+ \edef\xwm@currmark{\xwm@xp{#2}}%
+ \xwm@decidedetok{#2}%
+ \xwm@swafalse
+ \xifinsetTF{\detokenize{\newwatermark}}{\xwm@detok{#2}}{%
+ \xwm@swatrue
+ }{%
+ \xifinsetTF{\detokenize{\newwallpaper}}{\xwm@detok{#2}}{%
+ \xwm@swatrue
+ }{}%
+ }%
+ \ifxwm@swa
+ \ifxwm@allownesting\else
+ \xwm@err{Nested '\string\newwatermark' or
+ '\string\newwallpaper'\MsgBrk
+ while option 'allownesting' is false}\@ehc
+ \fi
+ \fi
+ \if@boolTF{xwm@wall}{}{%
+ \xwmifitemsinFT[1]{%
+ squaretiles,square-tiles,tilexsize,tile-xsize,%
+ tileysize,tile-ysize,wpxoffset,wallpaper-xoffset,%
+ wpyoffset,wallpaper-yoffset,tilexoffset,tile-xoffset,%
+ tileyoffset,tile-yoffset,tileno,tilenumber,%
+ tile-number,number-of-tiles%
+ }{#1}{}{%
+ \xwm@@err{'\xwm@items' not admissible for
+ \MsgBrk non-wallpaper watermarks}\@ehc
+ }%
+ }%
+ \if@boolTF{xwm@allownesting}{}{%
+ \cpt@choicefdfalse
+ \def\csv@do##1{%
+ \xifinsetFT{,\detokenize{##1}}{,\xwm@detok{#2}}{}{%
+ \def\xwm@tempa{##1}%
+ \cpt@choicefdtrue\loopbreak
+ }%
+ }%
+ \csv@@parse*[,]\xwm@samplemarkkeys
+ \ifcpt@choicefd
+ \xwm@err{Illegal location of '\xwm@tempa'.
+ \MsgBrk The following keys are not allowed in
+ \MsgBrk mandatory/second argument of
+ \MsgBrk '\string\newwatermark' or '\string\newwallpaper':
+ ^^J||\xwm@samplemarkkeys||}\@ehc
+ \fi
+ }%
+ \xifinsetFT\xwm@watermarkparser{\xwm@detok{#2}}{}{%
+ \xwm@err{Watermark parser '\xwm@watermarkparser' appears in
+ the following watermark.\MsgBrk Enclose your token
+ '\xwm@watermarkparser' in braces:^^J||\unexpanded{#2}||}\@ehc
+ }%
+ \x@xwmifitemsinTF[1]\xwm@pagespecifiers{\expandcsonce\xwm@currattrib}{%
+ \x@xwmifitemsinTF[2]\xwm@pagespecifiers{\expandcsonce\xwm@currattrib}{%
+ \xwm@err{Too many page specifiers '\xwm@items' for watermark:
+ ^^J||\expandcsonce\xwm@currattrib||}{%
+ Only one page specifier is allowed in watermark.}%
+ }{}%
+ }{%
+ \xwm@err{No page specifier for watermark:
+ ^^J||\expandcsonce\xwm@currmark||}\@ehc
+ }%
+ \ifcsnullTF\xwm@currattrib{%
+ \ifcsnullTF\xwm@currmark{}{%
+ \xwm@@err{No attributes for watermark:
+ ^^J||\expandcsonce\xwm@currmark||}\@ehc
+ }%
+ }{%
+ \xwm@makecurrmark
+ }%
+ \edef\reserved@a{%
+ \ifxwm@foregrd\expandcsonce\xwm@forelist\else
+ \expandcsonce\xwm@backlist\fi
+ }%
+ \expandafter\edef\reserved@a{%
+ \expandafter\ifdefTF\reserved@a{\expandcstwice\reserved@a}{}%
+ \expandcsonce\currentmark
+ }%
+ \undefcs\xwm@xp\undefcs\xwm@detok
+}
+\robust@def*\xwm@twopagespecerr{%
+ \ifxwm@swa
+ \xwm@err{Two page specifiers in watermark attributes:
+ ^^J||\cptoxdetok{\xwm@currattrib}||}\@ehc
\else
- \xwm@err{Inadmissible value '\string#1' for minipage's align}%
+ \xwm@swatrue
\fi
-}%
-\presetkeys[XWM]{minipage}{align,width,textcolor,text,framesep,
- framerule,framecolor}{}%
-\long\def\xwminipage#1{%
- \setkeys[XWM]{minipage}{#1}%
- \begingroup%
- \fboxsep=\mp@framesep\fboxrule=\mp@framerule%
- \removelastskip
- \color{\mp@framecolor}%
- \noindent
- \begin{boxedminipage}{\mp@width}%
- \mp@align\textcolor{\mp@textcolor}{\mp@text}%
- \end{boxedminipage}%
- \removelastskip
- \endgroup
-}%
-\krsetup{keyfamily=colorbox,macroprefix=cb@}
-\CKVS{align}{center,right,left,justified}
-\define@keylist{2,width,\textwidth,;2,textcolor,black,;
- 2,fillcolor,yellow!55,;2,framecolor,white,;
- 2,text,No text passed.,;2,framesep,3\p@,;2,framerule,0.4\p@,;
- 4,align,center,\protected@edef\cb@align{\val}}
-\presetkeys[XWM]{colorbox}{align=center,width,fillcolor,textcolor,text,
- framesep,framerule,framecolor}{}
-\newcommand\xwcolorbox[1]{%
- \setkeys[XWM]{colorbox}{#1}%
- \color{\cb@framecolor}%
- \removelastskip\noindent%
- \colorbox{\cb@fillcolor}{%
- \xwminipage{framesep=\cb@framesep,framerule=\cb@framerule,
- framecolor=\cb@framecolor,align=\cb@align,width=\cb@width,
- text=\cb@text,textcolor=\cb@textcolor
- }%
- }%
- \removelastskip\normalcolor%
-}%
-\newcommand\ywcolorbox[1]{%
- \setkeys[XWM]{colorbox}{#1}%
- \color{\cb@framecolor}%
- \begin{center}%
- \makebox[\z@][c]{%
- \colorbox{\cb@fillcolor}{%
- \xwminipage{framesep=\cb@framesep,framerule=\cb@framerule,
- framecolor=\cb@framecolor,align=\cb@align,width=\cb@width,
- text=\cb@text,textcolor=\cb@textcolor
+}
+\robust@def*\xwm@addcurrmark#1{%
+ \begingroup
+ \xifinsetTF{,\detokenize{textmark}}{,\cptoxdetok\xwm@currattrib}{%
+ \@tempswafalse
+ \ifxTF\xwm@currmark\@empty{}{%
+ \xwm@err{Duplicate nonempty 'textmark'}\@ehc
+ }%
+ }{%
+ \@tempswatrue
+ }%
+ \edef\xwm@tempb{%
+ page=\number#1,\expandcsonce\xwm@currattrib,%
+ \if@tempswa textmark={\expandcsonce\xwm@currmark}\fi
+ }%
+ \ifcsemptyTF\xwm@tempb{}{\xwm@normdoublecomma\xwm@tempb}%
+ \edef\currentmark{%
+ \expandcsonce\currentmark{\number#1}{\expandcsonce\xwm@tempb}%
+ }%
+ \postgroupdef\currentmark\endgroup
+}
+\robust@def*\xwm@getpagespec#1{%
+ \ifinsetTF{,#1,}{,page,pages,pagex,}{%
+ \def\xwm@tempa##1#1=##2,##3\xwm@nil{%
+ \ifblankTF{##2}{%
+ \xwm@warn{Key 'page/pages' has blank value;
+ \MsgBrk '1' used instead}\@ehc
+ \def\xwm@currpage{1}%
+ }{%
+ \ifstrcmpTF{#1}{pages}{%
+ \ifinsetTF{,}{##2}{%
+ \xwm@err{Key 'pages' doesn't accept comma-separated
+ \MsgBrk page numbers: use a hyphen}\@ehc
+ }{}%
+ }{%
+ \ifstrcmpTF{#1}{pagex}{%
+ \ifinsetTF{-}{##2}{%
+ \xwm@err{Key 'pagex' doesn't accept hyphen-separated
+ \MsgBrk page numbers: use commas}\@ehc
+ }{}%
+ }{}%
+ }%
+ \def\xwm@currpage{##2}%
+ }%
+ \edef\xwm@currattrib{\unexpanded{##1,##3}}%
+ }%
+ \expandafter\xwm@tempa\xwm@currattrib,\xwm@nil
+ }{%
+ \def\xwm@tempa##1#1,##2\xwm@nil{%
+ \edef\xwm@currattrib{\unexpanded{##1,##2}}%
+ }%
+ \expandafter\xwm@tempa\xwm@currattrib,\xwm@nil
+ }%
+}
+\robust@def*\xwm@ifpagespec#1{%
+ \cptexpandtwoargs\cpt@in
+ {,\detokenize{#1}}{,\cptoxdetok\xwm@currattrib}%
+ \if@boolTF{cpt@in}\@iden\@gobble
+}
+\robust@def*\xwm@normdoublecomma#1{%
+ \def\xwm@tempa##1,,##2\xwm@@nil{%
+ \ifblankTF{##2}
+ {\edef#1{\unexpanded{##1}}}
+ {\xwm@tempa##1,##2\xwm@@nil}%
+ }%
+ \expandafter\xwm@tempa#1,,\xwm@@nil
+}
+\robust@def*\xwm@makecurrmark{%
+ \edef\xwm@rsvda{\lastdocpage}%
+ \def\currentmark{}%
+ \xwm@swafalse
+ \xwm@ifpagespec{page=}{%
+ \xwm@twopagespecerr
+ \xwm@getpagespec{page}%
+ \xwm@addcurrmark\xwm@currpage
+ }%
+ \xwm@ifpagespec{pages=}{%
+ \xwm@twopagespecerr
+ \xwm@getpagespec{pages}%
+ \xwm@hyphenpagerange\xwm@currpage\xwm@pagestart\xwm@pageend
+ \xwm@cnta\numexpr\xwm@pagestart\relax
+ \cptloop
+ \xwm@addcurrmark\xwm@cnta
+ \advance\xwm@cnta by1
+ \ifnum\xwm@cnta<\numexpr\xwm@pageend+1\relax
+ \repeat
+ }%
+ \xwm@ifpagespec{pagex=}{%
+ \xwm@twopagespecerr
+ \xwm@getpagespec{pagex}%
+ \def\ltxkeys@do##1{\xwm@addcurrmark{##1}}%
+ \ltxkeys@csvparse*\xwm@currpage
+ }%
+ \xwm@ifpagespec{firstpage}{%
+ \xwm@twopagespecerr
+ \xwm@getpagespec{firstpage}%
+ \xwm@addcurrmark{1}%
+ }%
+ \xwm@ifpagespec{lastpage}{%
+ \xwm@twopagespecerr
+ \xwm@getpagespec{lastpage}%
+ \xwm@addcurrmark\xwm@rsvda
+ }%
+ \xwm@ifpagespec{evenpages}{%
+ \xwm@twopagespecerr
+ \xwm@getpagespec{evenpages}%
+ \xwm@cnta\@ne
+ \cptloop
+ \ifodd\xwm@cnta\else
+ \xwm@addcurrmark\xwm@cnta
+ \fi
+ \advance\xwm@cnta by1
+ \ifnum\xwm@cnta<\numexpr\xwm@rsvda+1\relax
+ \repeat
+ }%
+ \xwm@ifpagespec{oddpages}{%
+ \xwm@twopagespecerr
+ \xwm@getpagespec{oddpages}%
+ \xwm@cnta\z@
+ \cptloop
+ \ifodd\xwm@cnta
+ \xwm@addcurrmark\xwm@cnta
+ \fi
+ \advance\xwm@cnta by1
+ \ifnum\xwm@cnta<\numexpr\xwm@rsvda+1\relax
+ \repeat
+ }%
+ \ifxwm@swa\else
+ \xwm@err{No page specifier in watermark attributes:
+ ^^J||\cptoxdetok\xwm@currattrib||}\@ehc
+ \fi
+}
+\robust@def*\dummywatermark#1{%
+ \ifstrcmpTF{#1}\newwatermark{%
+ \xwm@err
+ {'\string\newwatermark' in front of \string\dummywatermark}%
+ {First comment out or remove '\string\newwatermark'.}%
+ }{%
+ \if@boolTF{xwm@usedummymarks}\newwatermark\xwm@dummywatermark
+ #1%
+ }%
+}
+\robust@def*\dummywallpaper#1{%
+ \ifstrcmpTF{#1}\newwallpaper{%
+ \xwm@err
+ {'\string\newwallpaper' in front of \string\dummywallpaper}%
+ {First comment out or remove '\string\newwallpaper'.}%
+ }{%
+ \if@boolTF{xwm@usedummymarks}\newwallpaper\xwm@dummywatermark
+ #1%
+ }%
+}
+\robust@def*\xwm@dummywatermark{%
+ \cpt@teststpm{\cpt@testopt\xwm@d@mmywatermark{}}%
+}
+\robust@def*\xwm@d@mmywatermark[#1]#2{}
+\robust@def*\UseDummyWatermarks{\global\xwm@usedummymarkstrue}
+\robust@def*\DiscardDummyWatermarks{\global\xwm@usedummymarksfalse}
+\DiscardDummyWatermarks
+\robust@def*\DiscardAllWatermarks{%
+ \global\let\newwatermark\dummywatermark
+ \global\xwm@usedummymarksfalse
+}
+\robust@def*\xwm@putbothmarks{%
+ \ifdefFT\xwm@watermarklist{}\xwm@textpicmark@a
+ \ifdefFT\xwm@wallpaperlist{}\xwm@wallpaper@a
+}
+\chardef\xwm@nowatermark\z@pt
+\AtBeginShipout{%
+ \endlinechar13\catcode13=5
+ \catcode`\ =10
+ \catcode`\\\z@pt
+ \catcode`\{\@ne
+ \catcode`\}\tw@
+ \if@boolTF{xwm@printwatermark}{%
+ \let\xwm@watermarklist\xwm@backwmklist
+ \let\xwm@wallpaperlist\xwm@backwalllist
+ \AtBeginShipoutUpperLeft{%
+ \xwm@foregrdfalse
+ \xwm@putbothmarks
+ }%
+ \let\xwm@watermarklist\xwm@forewmklist
+ \let\xwm@wallpaperlist\xwm@forewalllist
+ \AtBeginShipoutUpperLeftForeground{%
+ \xwm@foregrdtrue
+ \xwm@putbothmarks
+ }%
+ }{%
+ \ifnum\xwm@nowatermark<\@ne
+ \pushnumber\xwm@nowatermark
+ \xwm@info{'printwatermark=false': no watermark printed}%
+ \fi
+ }%
+}
+\robust@def*\xwm@perpagestate{%
+ page=0,
+ pagex={0},
+ pages=0-0,
+ minmark=false,
+ onepageonly=false,
+ prange=false,
+ tmark=false,
+ pmark=false,
+ firstpage=false,
+ allpages=false,
+ oddpages=false,
+ evenpages=false,
+ showpagecenter=false,
+ textmark=DRAFT,
+ textalign=center,
+ boxalign=,
+ textcolor=gray!55,
+ fontfamily=bch,
+ textangle=0,
+ picangle=0,
+ fontsize=1cm,
+ fontseries=b,
+ textscale=1,
+ picscale=1,
+ picheight=,
+ picwidth=,
+ picbb=0 0 100 100,
+ picfileext,
+ picontoptext=false,
+ graphicsoptions={},
+}
+\robust@edef*\xwm@perpagewmkstate{%
+ \expandcsonce\xwm@perpagestate,
+ \unexpanded{%
+ height=\paperwidth,
+ width=\paperheight,
+ textxpos=0,
+ textypos=0,
+ picxpos=\z@pt,
+ picypos=\z@pt,
+ coordunit=mm
+ }%
+}
+\robust@edef*\xwm@perpagewallstate{%
+ \expandcsonce\xwm@perpagestate,
+ \unexpanded{%
+ tilexsize=.5\paperwidth,
+ tileysize=.5\paperheight,
+ wpxoffset=\z@pt,
+ wpyoffset=\z@pt,
+ textmark=,
+ picfile=,
+ tilexoffset=\z@pt,
+ tileyoffset=\z@pt,
+ tileno=4,
+ squaretiles=false
+ }%
+}
+\robust@def*\xwm@textpicmark@a{%
+ \ifcsnullTF\xwm@watermarklist{%
+ \if@boolTF{xwm@foregrd}{}{%
+ \if@boolFT{xwm@printwatermark}{}{%
+ \if@boolTF{xwm@draft}{%
+ \if@boolTF{wmk@showpagecenter}{}{%
+ \ifnumcmpFT\c@page=\@ne{}{%
+ \cptexpandargonce{\ltxkeys@setkeys[XWM]{watermark}}%
+ \xwm@perpagewmkstate
+ \wmk@tmarktrue\wmk@pmarkfalse
+ \cptdimdef\wmk@textxpos@a{0.5\paperwidth}%
+ \cptdimdef\wmk@textypos@a{-0.5\paperheight}%
+ \xwm@textpicmark@c
+ \xwm@info{'printwatermark' and 'draft' are 'true'
+ \MsgBrk but no watermark(s): watermark
+ \MsgBrk printed on page 1 only}%
+ }%
+ }%
+ }{%
+ \ifnum\c@page=\@ne
+ \xwm@info{'printwatermark=true' and 'draft=false'
+ \MsgBrk but no watermark(s)}%
+ \fi
+ }%
+ }%
+ }%
+ }{%
+ \xwm@processmarks\xwm@watermarklist{%
+ \xwm@setwatermarkkeys{watermark}{wmk}{##2}%
+ \if@boolFT{wmk@minmark}{}\xwm@textpicmark@c
+ }%
+ }%
+}
+\robust@def*\xwm@wallpaper@a{%
+ \ifcsnullTF\xwm@wallpaperlist{}{%
+ \xwm@processmarks\xwm@wallpaperlist{%
+ \xwm@setwatermarkkeys{wallpaper}{wall}{##2}%
+ \if@boolFT{wlp@minmark}{}\xwm@wallpaper@c
+ }%
+ }%
+}
+\robust@def*\xwm@setwatermarkkeys#1#2#3{%
+ \ltxkeys@getkeynames{#3}%
+ \cptexpandsecond{%
+ \ltxkeys@setkeys[XWM]{#1}%
+ }{%
+ [\ltxkeys@keynames]{\expandcsnonce{xwm@perpage#2state}}%
+ }%
+ \edef\currentmark{\unexpanded{#3}}%
+ \ifblankTF{#3}{}{\ltxkeys@setkeys[XWM]{#1}{#3}}%
+}
+\robust@def*\xwm@processmarks#1#2{%
+ \def\xwm@pr@cessmarks##1##2{%
+ \ifstrcmpTF{##1}{.}{}{%
+ \ifnumcmpTF##1=\c@page{#2}{%
+ \edef#1{\expandcsonce#1\unexpanded{{##1}{##2}}}%
}%
+ \xwm@pr@cessmarks
}%
}%
- \end{center}%
- \removelastskip\normalcolor
-}%
-\new\def\xwm@insertpic{\begingroup
- \protected@edef\@tempa{\endgroup%
- \iftoggle{pdf}{%
- \noexpand\IfFileExists{\xwm@picfile.\xwm@picfilex}{%
- \noexpand\includegraphics[viewport=\xwm@picbb,scale=\xwm@picscale]%
- {\xwm@picfile.\xwm@picfilex}%
- }{\xwm@err{No file \xwm@picfile.\xwm@picfilex\space or wrong path}}%
+ \cptexpandsecondonce{\def#1{}\xwm@pr@cessmarks}{#1}{.}{}%
+}
+\ltxkeys@disablekeys*[XWM]{main}{printwatermark,disablegeometry}
+\BeforeStartOfDocument{%
+ \unless\ifxwm@printwatermark
+ \xwm@info{*** printwatermark=false: no watermark printed}%
+ \fi
+}
+\newcommand\xwm@papercenter{%
+ \color{red}\noindent
+ \xwm@put(0,-0.5\paperheight){\line(1,0){\paperwidth}}%
+ \xwm@put(0.5\paperwidth,0){\line(0,-1){\paperheight}}%
+ \xwm@put(0.5\paperwidth,-0.5\paperheight){\circle{10}}%
+ \normalcolor
+}
+\robust@def*\xwm@textbox#1{%
+ \begingroup
+ \let\nxp\noexpand
+ \let\mcs\cptmakecs
+ \edef\xwm@curralign{\expandcsnonce{#1@textalign}}%
+ \cptexpanded{\endgroup
+ \xwm@put(\mcs{#1@textxpos@a},\mcs{#1@textypos@a}){%
+ \quitvmode\nxp\@killglue\noindent
+ \cptexpandsecond{\nxp\makebox(0,0)}{[\mcs{#1@boxalign}]}{%
+ \nxp\rotatebox[origin=c]{\mcs{#1@textangle}}{%
+ \nxp\scalebox{\mcs{#1@textscale}}{%
+ \nxp\parbox[c][\mcs{#1@textheight}]%
+ [c]\mcs{#1@textwidth}{%
+ \nxp\color{\mcs{#1@textcolor}}%
+ % First convert \fontsize to scaled points:
+ \cptdimdef\mcs{#1@fontsize@a}{\mcs{#1@fontsize}}%
+ \cptdimdef\mcs{#1@fontsize@a}%
+ {1.5\p@*\mcs{#1@fontsize@a}}%
+ \nxp\fontfamily\mcs{#1@fontfamily}%
+ \nxp\fontseries\mcs{#1@fontseries}%
+ \nxp\fontsize\mcs{#1@fontsize}\mcs{#1@fontsize@a}%
+ \nxp\selectfont
+ \noexpand\begin{\xwm@curralign}%
+ \mcs{#1@textmark}%
+ \noexpand\end{\xwm@curralign}%
+ }%
+ }%
+ }%
+ }%
+ }%
+ }%
+ \@killglue\normalcolor
+}
+\robust@def*\xwm@getpicsize#1{%
+ \ifcsnnullTF{#1@picwidth}{%
+ \ifcsnnullTF{#1@picheight}{%
+ \edef\pic@size{scale=\cptmakecs{#1@picscale}}%
}{%
- \noexpand\IfFileExists{\xwm@picfile.\xwm@picfilex}{%
- \noexpand\includegraphics[bb=\xwm@picbb,scale=\xwm@picscale]%
- {\xwm@picfile.\xwm@picfilex}%
- }{\xwm@err{No file \xwm@picfile.\xwm@picfilex\space or wrong path}}%
- }%
- }\@tempa%
-}%
-\newrobustcmd\xwm@dis@ble@keys[1]{%
- \XKV@checksanitizeb{#1}\xwm@tempa
- \XKV@for@o\xwm@tempa\xwm@tempa{%
- \XKV@ifundefined{\XKV@header\xwm@tempa}{%
- \xwm@warn{Key '\xwm@tempa' undefined: can't be disabled}%
+ \xwm@err{You have supplied picture height
+ but not width}\@ehc
+ }%
+ }{%
+ \ifcsnnullTF{#1@picheight}{%
+ \xwm@err{You have supplied picture width
+ but not height}\@ehc
}{%
- \edef\xwm@tempb{%
- \noexpand\xwm@err{Key '\xwm@tempa' has been disabled.\MessageBreak
- You can't set or reset it at this late stage.\MessageBreak
- You should have set it earlier in the\MessageBreak
- \string\documentclass\space or \string\usepackage}%
+ \edef\pic@size{width=\cptmakecs{#1@picwidth},%
+ height=\cptmakecs{#1@picheight}}%
+ }%
+ }%
+}
+\newcommand*\xwm@picmark{%
+ \xwm@findpicfile\wmk@picfile\wmk@picfileext
+ \xwm@getpicsize{wmk}%
+ \cptpassexpanded{%
+ \setbox\xwm@boxa=\hbox{%
+ \noexpand\includegraphics[\ifxwm@pdf viewport\else
+ bb\fi=\wmk@picbb,\pic@size,clip,\wmk@graphicsoptions,
+ \xwm@gr@phicsoptions]{\xwm@filefound}}%
+ }%
+ \xwm@makedraftbox
+ \xwm@put(\wmk@picxpos@a,\wmk@picypos@a){%
+ \rotatebox[origin=c]\wmk@picangle{%
+ \cptexpandsecond{\makebox(0,0)}{[\wmk@boxalign]{%
+ \if@boolTF{xwm@draft}
+ {\xwm@draftbox{wmk}}{\copy\xwm@boxa}%
+ }%
+ }%
+ }}%
+}
+\robust@def*\xwm@makedraftbox{%
+ \fboxsep\p@\fboxrule.4\p@
+ \cptdimdef\xwm@tempa{(\ht\xwm@boxa+\dp\xwm@boxa
+ -2\fboxsep-2\fboxrule)/2}%
+ \cptdimdef\xwm@tempb{\wd\xwm@boxa-2\fboxsep-2\fboxrule}%
+ \setbox\@tempboxa\hbox{\color@begingroup
+ \ttfamily\color{red}\Large (draft mode)\color@endgroup}%
+ \setbox\xwm@boxb=\hb@xt@\xwm@tempb{%
+ \xwmstrut\xwm@tempa\z@pt
+ \hb@xt@\xwm@tempb{\hss\unhbox\@tempboxa\hss}%
+ \xwmstrut\z@pt\xwm@tempa
+ }%
+}
+\robust@def*\xwm@draftbox#1{%
+ \begingroup
+ \color{\usename{#1@draftboxcolor}}\fbox{\copy\xwm@boxb}%
+ \endgroup
+}
+\newcommand*\xwm@textpicmark@c{%
+ \xwm@getposition\wmk@textxpos\wmk@textypos\wmk@coordunit
+ \xwm@getposition\wmk@picxpos\wmk@picypos\wmk@coordunit
+ \if@boolTF{wmk@picontoptext}{%
+ \if@boolFT{wmk@tmark}{}{\xwm@textbox{wmk}}%
+ \if@boolFT{wmk@pmark}{}\xwm@picmark
+ }{%
+ \if@boolFT{wmk@pmark}{}\xwm@picmark
+ \if@boolFT{wmk@tmark}{}{\xwm@textbox{wmk}}%
+ }%
+ \if@boolFT{wmk@showpagecenter}{}\xwm@papercenter
+}
+\AtBeginDocument{%
+ \ifdefTF\Ginput@path{%
+ \xdef\xwm@inputpath{\Ginput@path\xwm@inputpath}%
+ \ifxTF\Ginput@path\input@path{}{%
+ \ifdefFT\input@path{}{%
+ \xdef\xwm@inputpath{\input@path\xwm@inputpath}%
}%
- \XKV@ifundefined{\XKV@header\xwm@tempa @default}{%
- \edef\xwm@tempc{\noexpand\XKV@define@key{\xwm@tempa}}%
+ }%
+ }{%
+ \ifdefFT\input@path{}{%
+ \xdef\xwm@inputpath{\input@path\xwm@inputpath}%
+ }%
+ }%
+}
+\new@def*\xwm@inputpath{}
+\robust@def*\watermarkpaths{%
+ \cpt@testst{\cpt@testopt\xwm@w@termarkpaths{}}%
+}
+\robust@def*\xwm@w@termarkpaths[#1]{%
+ \cpt@testpnopt{\xwm@w@term@rkpaths#1}{}
+}
+\robust@def*\xwm@w@term@rkpaths#1(#2)#3{%
+ \cpt@useemptytrue
+ \def\xwm@tempa{#3}%
+ \if@boolTF{cpt@st}{%
+ \ifbracedTF{#3}{\stripallbr{#3}\xwm@tempa}{}%
+ \def\csv@do##1{%
+ \ifbracedTF{##1}{%
+ \stripallbr{##1}\xwm@tempa
+ }{%
+ \def\xwm@tempa{##1}%
+ }%
+ \cptexpandarg{\grightaddtocs\xwm@inputpath}{{#1\xwm@tempa#2}}%
+ }%
+ \csv@@parse*[,]\xwm@tempa
+ }{%
+ \xifinsetFT{,}{\cptoxdetok\xwm@tempa}{}{%
+ \xwm@err{Input path '#3' contains comma:
+ \MsgBrk Commas can appear only in the argument
+ \MsgBrk of star (*) variant of \string\watermarkpaths}\@ehc
+ }%
+ \def\tsv@do##1{%
+ \ifbracedTF{##1}{%
+ \cptexpandarg{\grightaddtocs\xwm@inputpath}{{#1\@iden##1#2}}%
}{%
- \edef\xwm@tempc{\noexpand\XKV@define@key{\xwm@tempa}[]}%
+ \xwm@err{Input path '##1' needs outer braces}\@ehc
}%
- \expandafter\xwm@tempc\expandafter{\xwm@tempb}%
}%
+ \tsv@@parse*\xwm@tempa
}%
-}%
-\newrobustcmd\xwm@disable@keys{\XKV@testoptb\xwm@dis@ble@keys}%
+}
+\newletcs\watermarkpath=\watermarkpaths
+\new@def*\xwmifeofTF#1{\ifcondTF\ifeof#1\fi}
+\robust@def*\pdfiffileexistsTF#1{%
+ \cptifcondFT\if\pdffilesize{#1}\relax\fi
+}
+\robust@def*\xwmiffileexistsTF#1{%
+ \openin\@inputcheck#1\@space
+ \xwmifeofTF\@inputcheck{%
+ \ifcsnullTF\xwm@inputpath{%
+ \@secondoftwo
+ }{%
+ \xwm@iffileonpath{#1}%
+ }%
+ }{%
+ \closein\@inputcheck
+ \edef\xwm@filefound{#1}%
+ \@firstoftwo
+ }%
+}
+\robust@def*\xwmiffileexistsFT#1{%
+ \xwmiffileexistsTF{#1}\@secondoftwo\@firstoftwo
+}
+\robust@def*\xwm@iffileonpath#1{%
+ \let\xwm@pathfound\@empty
+ \cpt@choicefdfalse
+ \def\tsv@do##1{%
+ \stripallbr{##1}\xwm@tempa
+ \openin\@inputcheck\xwm@tempa#1\@space
+ \xwmifeofTF\@inputcheck{}{%
+ \let\xwm@pathfound\xwm@tempa
+ \edef\xwm@filefound{\xwm@tempa#1}%
+ \closein\@inputcheck
+ \cpt@choicefdtrue\loopbreak
+ }%
+ }%
+ \tsv@@loop*\xwm@inputpath
+ \if@boolTF{cpt@choicefd}\@firstoftwo\@secondoftwo
+}
+\robust@def*\xwm@nofileerr#1#2{%
+ \message{%
+ ^^J! Package xwatermark Error: File '#1.#2' not found.
+ ^^J^^JType x to quit, or <RETURN> to proceed,
+ ^^Jor enter new name (default extension: #2):^^J
+ }%
+ \begingroup
+ \endlinechar-1\global\read-1 to\@gtempa
+ \endgroup
+ \ifcsnullTF\@gtempa{}{%
+ \oifstrcmpTF\@gtempa{x}{%
+ \stop
+ }{%
+ \oifstrcmpTF\@gtempa{X}{%
+ \stop
+ }{%
+ \filename@parse\@gtempa
+ \edef#1{\filename@area\filename@base}%
+ \edef#2{\ifxTF\filename@ext\relax{#2}{\filename@ext}}%
+ \xwm@findpicfile{#1}{#2}%
+ }%
+ }%
+ }%
+}
+\robust@def*\xwm@findpicfile#1#2{%
+ \let\xwm@filefound\@empty
+ \edef\xwm@filegiven{#1.#2}%
+ \if@boolTF{xwm@pdf}{%
+ \xwm@f@ndpicfile{#1}{#2}{pdf,png,jpeg,mps}%
+ }{%
+ \xwm@f@ndpicfile{#1}{#2}{eps,ps}%
+ }%
+ \ifcsnullFT\xwm@filefound{}{\xwm@nofileerr{#1}{#2}}%
+}
+\robust@def*\xwm@f@ndpicfile#1#2#3{%
+ \xwm@swafalse
+ \xwmiffileexistsTF{#1.#2}{%
+ \xwm@swbtrue
+ }{%
+ \xwm@swbfalse
+ \def\csv@do##1{%
+ \xwmiffileexistsFT{#1.##1}{}{%
+ \xwm@swatrue\loopbreak
+ }%
+ }%
+ \csv@@loop[,]{#3}%
+ }%
+ \if@boolTF{xwm@swb}{}{%
+ \if@boolTF{xwm@swa}{%
+ \xwm@warn{File '\xwm@filegiven' doesn't exist
+ \MsgBrk on given path(s) '\xwm@inputpath',
+ \MsgBrk but I have found \xwm@filefound'}%
+ }{%
+ \let\xwm@filefound\@empty
+ \let\xwm@pathfound\@empty
+ }%
+ }%
+}
+\robust@def*\xwm@wallpaper@c{%
+ \if@boolTF{wlp@picontoptext}{%
+ \xwm@textwallpaper
+ \xwm@picwallpaper
+ }{%
+ \xwm@picwallpaper
+ \xwm@textwallpaper
+ }%
+ \if@boolFT{wlp@showpagecenter}{}\xwm@papercenter
+}
+\robust@def*\xwm@textwallpaper{%
+ \if@boolFT{wlp@tmark}{}{%
+ \if@boolTF{wlp@squaretiles}\xwm@sqtexttiles\xwm@texttiles
+ }%
+}
+\robust@def*\xwm@picwallpaper{%
+ \if@boolFT{wlp@pmark}{}{%
+ \if@boolTF{wlp@squaretiles}%
+ \xwm@sqpictiles\xwm@pictiles
+ }%
+}
+\robust@def*\xwm@dotiling{\xwm@makedraftbox\xwm@dotiling@a}
+\robust@def*\xwm@dotiling@a{%
+ \let\tiley\wlp@wpyoffset
+ \cptwhiledim\tiley<\paperheight-\wlp@wpyoffset\do{%
+ \cptdimdef\xwm@tempa{-\paperheight+\tiley}%
+ \let\tilex\wlp@wpxoffset
+ \cptwhiledim\tilex<\paperwidth-\wlp@wpxoffset\do{%
+ \leavevmode\@killglue
+ \xwm@put(\tilex,\xwm@tempa){\rotatebox[origin=c]
+ \xwm@currangle{%
+ \cptexpandsecond{\makebox(0,0)}{[\wlp@boxalign]}{%
+ \if@boolTF{xwm@draft}
+ {\xwm@draftbox{wlp}}{\copy\xwm@boxa}%
+ }%
+ }}%
+ \cptdimadd\tilex{\wlp@tilexsize+\wlp@tilexoffset}%
+ }%
+ \cptdimadd\tiley{\wlp@tileysize+\wlp@tileyoffset}%
+ }%
+}
+\robust@def*\xwm@toofewtiles#1{%
+ \ifnum\numexpr#1<4\relax
+ \xwm@err{Too few square wallpapers '#1';
+ \MsgBrk minimum expected: 4}\@ehc
+ \fi
+}
+\robust@def*\xwm@texttiles{%
+ \setbox\xwm@boxa=\hbox{%
+ \resizebox\wlp@tilexsize\wlp@tileysize
+ {\color{\wlp@textcolor}\wlp@textmark}%
+ }%
+ \let\xwm@currangle\wlp@textangle
+ \xwm@dotiling
+}
+\robust@def*\xwm@sqtexttiles{%
+ \xwm@toofewtiles\wlp@tileno
+ \cptdimdef\wlp@tilexsize{\paperwidth/\wlp@tileno}%
+ \let\wlp@tileysize\wlp@tilexsize
+ \setbox\xwm@boxa=\hbox{%
+ \resizebox\wlp@tilexsize\wlp@tileysize
+ {\color{\wlp@textcolor}\wlp@textmark}%
+ }%
+ \let\xwm@currangle\wlp@textangle
+ \xwm@dotiling
+}
+\robust@def*\xwm@tilepicbox{%
+ \xwm@findpicfile\wlp@picfile\wlp@picfileext
+ \setbox\xwm@boxa=\hbox{%
+ \cptexpandsecond\includegraphics{%
+ [\ifxwm@pdf viewport\else bb\fi=\wlp@picbb,
+ width=\the\dimexpr\wlp@tilexsize,height=
+ \the\dimexpr\wlp@tileysize,clip,
+ \wlp@graphicsoptions,\xwm@gr@phicsoptions]%
+ }{\xwm@filefound}%
+ }%
+}
+\robust@def*\xwm@pictiles{%
+ \xwm@tilepicbox
+ \let\xwm@currangle\wlp@picangle
+ \xwm@dotiling
+}
+\robust@def*\xwm@sqpictiles{%
+ \xwm@toofewtiles\wlp@tileno
+ \cptdimdef\wlp@tilexsize{\paperwidth/\wlp@tileno}%
+ \let\wlp@tileysize\wlp@tilexsize
+ \xwm@tilepicbox
+ \let\xwm@currangle\wlp@picangle
+ \xwm@dotiling
+}
+\robust@def*\xwmstrut#1#2{%
+ \relax\unskip
+ \ifhmode\nobreak\fi
+ \begingroup
+ \setbox\@tempboxa=\hbox{\vrule\@height#1\@depth#2\@width\z@pt}%
+ \ifmmode\copy\@tempboxa\else\unhcopy\@tempboxa\fi
+ \endgroup
+}
+\ltxkeys@definekeys*[XWM]<boxedminipage>[xwmbmp@]{%
+ width=\paperwidth;
+ textcolor=black;
+ framecolor=black;
+ framesep=3\p@;
+ framerule=0.4\p@;
+ height=\z@pt;
+ depth=\z@pt;
+ width=\paperwidth;
+ textalign=center/\xwm@settextalign\xwmbmp@textalign;
+ text-align=center/\setmnkey{textalign};
+}
+\robust@def*\xwmboxedminipage{\cpt@testopt\xwm@boxedminipage{}}
+\begingroup
+\catcode`\|=\catcode`\%
+\robust@gdef\xwm@boxedminipage[#1]#2{%
+ \ltxkeys@launchkeys[XWM]{boxedminipage}{#1}%
+ \stripallbrincs\xwmbmp@width
+ \stripallbrincs\xwmbmp@textcolor
+ \leavevmode\@pboxswfalse
+ \begingroup
+ \color{\xwmbmp@framecolor}%
+ \xifstrcmpTF\xwmbmp@innerpos{b}\vbox{%
+ \xifstrcmpTF\xwmbmp@innerpos{t}\vtop{%
+ \if@boolTF{mmode}\vcenter{%
+ \@pboxswtrue $\vcenter |$
+ }%
+ }%
+ }%
+ \bgroup
+ \hsize\xwmbmp@width
+ \hrule\@height\xwmbmp@framerule
+ \hbox\bgroup
+ \vrule\@width\xwmbmp@framerule\hskip\xwmbmp@framesep
+ \vbox\bgroup
+ \vskip\xwmbmp@framesep
+ \cptdimdef\xwm@dima{\hsize-2\xwmbmp@framerule-2\xwmbmp@framesep}%
+ \hsize\xwm@dima
+ \textwidth\xwm@dima\columnwidth\xwm@dima
+ \@parboxrestore
+ \c@mpfootnote\z@pt
+ \let\@footnotetext\@mpfootnotetext
+ \let\@listdepth\@mplistdepth\@mplistdepth\z@pt
+ \@minipagerestore\@minipagetrue
+ \everypar{\global\@minipagefalse\everypar{}}%
+ \leavevmode\@killglue
+ \xwmstrut\xwmbmp@height\z@pt
+ \noindent\xwmbmp@textcolor
+ \begin\xwmbmp@textalign
+}
+\robust@def\endxwmboxedminipage{%
+ \end\xwmbmp@textalign
+ \xwmstrut\z@pt\xwmbmp@depth
+ \ifvoid\@mpfootins\else
+ \vskip\skip\@mpfootins\footnoterule\unvbox\@mpfootins
+ \fi
+ \vskip\xwmbmp@framesep
+ \egroup
+ \hskip\xwmbmp@framesep\vrule\@width\xwmbmp@framerule
+ \egroup
+ \hrule\@height\xwmbmp@framerule
+ \egroup
+ \if@pboxsw\m@th$\fi |$
+ \leavevmode\@killglue\@ignoretrue
+ \endgroup
+}
+\endgroup
+
+\ltxkeys@definekeys*[XWM]<minipage>[xwmmp@]{%
+ width=\paperwidth;
+ textcolor=black;
+ framecolor=black;
+ framesep=3\p@;
+ framerule=0.4\p@;
+ height=\z@pt;
+ depth=\z@pt;
+ width=\hsize;
+ textalign=center/\xwm@settextalign\xwmmp@textalign;
+ text-align=center/\setmnkey{textalign};
+ framebox=true;
+ insertframe=true/\setmnkey{framebox};
+ insert-frame=true/\setmnkey{framebox};
+}
+\robust@def*\xwmminipage{\cpt@testopt\xwm@minipage{}}
+\robust@def\xwm@minipage[#1]#2{%
+ \ltxkeys@launchkeys[XWM]{minipage}{#1}%
+ \stripallbrincs\xwmmp@width
+ \stripallbrincs\xwmmp@textcolor
+ \edef\sav@fboxsep{\the\fboxsep}%
+ \edef\sav@fboxrule{\the\fboxrule}%
+ \fboxsep\xwmmp@framesep\fboxrule\xwmmp@framerule
+ \cptdimdef\xwmmp@boxwidth{\xwmmp@width-2\fboxsep-2\fboxrule}%
+ \def\xwm@printbox{%
+ \color{\xwmmp@framecolor}%
+ \ifxwmmp@framebox\fbox{\fi
+ \usebox\xwm@boxa
+ \ifxwmmp@framebox}\fi
+ }%
+ \@killglue\noindent
+ \begin{lrbox}\xwm@boxa
+ \@killglue\noindent
+ \begin{minipage}[c][\height][s]\xwmmp@boxwidth
+ \@killglue\noindent
+ \xwmstrut\xwmmp@height\z@pt
+ \begin\xwmmp@textalign
+ \textcolor{\xwmmp@textcolor}{#2}\relax
+ \end\xwmmp@textalign
+ \xwmstrut\z@pt\xwmmp@depth
+ \end{minipage}%
+ \@ignoretrue\@killglue
+ \end{lrbox}%
+ \@ignoretrue\@killglue\noindent
+ \xwm@printbox
+ \fboxsep\sav@fboxsep\fboxrule\sav@fboxrule
+ \normalcolor\@ignoretrue
+}
+\ltxkeys@definekeys*[XWM]<colorbox>[xwmcbx@]{%
+ width=\textwidth;
+ height=\z@pt;
+ depth=\z@pt;
+ framebox=true;
+ insertframe=true/\setmnkey{framebox};
+ insert-frame=true/\setmnkey{framebox};
+ textcolor=black;
+ fillcolor=white;
+ outerframecolor=black;
+ outer-frame-color=black/\setmnkey{outerframecolor};
+ innerframecolor=black;
+ inner-frame-color=black/\setmnkey{innerframecolor};
+ framesep=3\p@;
+ framerule=0.4\p@;
+ textalign=center/\xwm@settextalign\xwmcbx@textalign;
+ align=center/\setmnkey{textalign};
+ text-align=center/\setmnkey{textalign};
+}
+\robust@def*\xwmcolorbox{\cpt@testopt\xwm@colorbox{}}
+\robust@def\xwm@colorbox[#1]#2{%
+ \ltxkeys@launchkeys[XWM]{colorbox}{#1}%
+ \fboxsep\xwmcbx@framesep\fboxrule\xwmcbx@framerule
+ \removelastskip\noindent
+ \fcolorbox{\xwmcbx@outerframecolor}{\xwmcbx@fillcolor}{%
+ \cptexpandsecond\xwmminipage{[textalign=\xwmcbx@textalign,
+ framesep=\xwmcbx@framesep,framerule=\xwmcbx@framerule,
+ framecolor=\xwmcbx@innerframecolor,width=\xwmcbx@width,
+ height=\xwmcbx@height,depth=\xwmcbx@depth,
+ textcolor=\xwmcbx@textcolor,framebox=true]}{#2}%
+ }%
+ \removelastskip
+ \normalcolor
+}
+\ltxkeys@definekeys*[XWM]<makecolorbox>[xwmmbx@]{%
+ width=\textwidth;
+ height=\z@pt;
+ depth=\z@pt;
+ framebox=true;
+ textcolor=black;
+ fillcolor=white;
+ outerframecolor=black;
+ outer-frame-color=black/\setmnkey{outerframecolor};
+ innerframecolor=black;
+ inner-frame-color=black/\setmnkey{innerframecolor};
+ framesep=3\p@;
+ framerule=0.4\p@;
+ textalign=center/\xwm@settextalign\xwmmbx@textalign;
+ align=center/\setmnkey{textalign};
+ text-align=center/\setmnkey{textalign};
+ boxalign=center/\xwm@settextalign\xwmmbx@boxalign;
+}
+
+\robust@def*\makecolorbox{\cpt@testopt\xwm@makecolorbox{}}
+\robust@def*\xwm@makecolorbox[#1]#2{%
+ \ltxkeys@launchkeys[XWM]{makecolorbox}{#1}%
+ \begin{\xwmmbx@boxalign}%
+ \makebox[\z@pt][c]{%
+ \xwmstrut\xwmmbx@height\z@pt
+ \fboxsep\xwmmbx@framesep\fboxrule\xwmmbx@framerule
+ \fcolorbox{\xwmmbx@outerframecolor}{\xwmmbx@fillcolor}{%
+ \cptexpandsecond\xwmminipage{[textalign=\xwmmbx@textalign,
+ framesep=\xwmmbx@framesep,framerule=\xwmmbx@framerule,
+ framecolor=\xwmmbx@innerframecolor,width=\xwmmbx@width,
+ height=\xwmmbx@height,depth=\xwmmbx@depth,
+ textcolor=\xwmmbx@textcolor,framebox=
+ \thebool@normal{xwmmbx@framebox}]}{#2}%
+ }%
+ \xwmstrut\z@pt\xwmmbx@depth
+ }%
+ \end{\xwmmbx@boxalign}%
+ \removelastskip
+ \normalcolor
+}
+\ltxkeys@definekeys*[XWM]<shade>[xwmshd@]{%
+ width=\hsize;
+ leftadjust=\z@pt;
+ indent=\z@pt;
+ fillcolor=gray!75;
+ framecolor=black;
+ framesep=3\p@;
+ framerule=0.4\p@;
+ height=\z@pt;
+ depth=\z@pt;
+ textalign=justified/\xwm@settextalign\xwmshd@textalign;
+ textcolor=black
+}
+\robust@def*\xwm@frameshade{%
+ \def\FrameCommand{%
+ \clubpenalty\@m\widowpenalty\@m
+ \noindent\kern\xwmshd@leftadjust
+ \fboxrule\xwmshd@framerule\fboxsep\xwmshd@framesep
+ \fcolorbox{\xwmshd@framecolor}{\xwmshd@fillcolor}%
+ }%
+ \parindent\z@pt\finalhyphendemerits\z@pt
+ \cptdimdef\xwm@tempa{\xwmshd@width-(\xwmshd@framesep
+ +\xwmshd@framerule+\xwmshd@indent)}%
+ \color{\xwmshd@textcolor}%
+ \MakeFramed{%
+ \hsize\xwm@tempa\FrameRestore\@setminipage
+ }%
+ \xwmstrut\xwmshd@height\z@pt
+ \begin\xwmshd@textalign
+}
+\robust@def*\xwmshade{\cpt@testopt\xwm@shade{}}
+\robust@def*\xwm@shade[#1]{%
+ \ltxkeys@launchkeys[XWM]{shade}{#1}%
+ \xwm@frameshade
+}
+\robust@def*\endxwmshade{%
+ \end\xwmshd@textalign
+ \xwmstrut\z@pt\xwmshd@depth
+ \par\unskip\endMakeFramed\@ignoretrue
+}
+\ltxkeys@definekeys*[XWM]<fadingtext>[fad@]{%
+ textcolor=white;
+ boxcolor=black;
+ scale=1;
+ letterwidth=5mm;
+ barcolor=yellow;
+ height=\z@pt;
+ depth=\z@pt
+}
+\newcommand*\xwmfadingtext[2][]{%
+ \ltxkeys@launchkeys[XWM]{fadingtext}{#1}%
+ \begingroup
+ \@tempcnta\z@pt
+ \def\siso@do##1{%
+ \advance\@tempcnta\@ne
+ \csn@xdef{fade@\romannumeral\@tempcnta}{\cpttrimspace{##1}}%
+ }%
+ \siso@@loop{#2}%
+ \def\colbox##1{%
+ \color{.!80}%
+ \colorbox{.}{{%
+ \color{\fad@textcolor!\the\numexpr100-\@tempcnta/\icol*10\relax}%
+ \ifnum\icol=\@ne
+ \kern\dimexpr\fad@letterwidth/50\relax
+ \fi
+ \makebox[\fad@letterwidth]{##1}%
+ \ifnum\icol<\@tempcnta
+ \scalebox\fad@scale{\textcolor{\fad@barcolor}{$|$}}%
+ \else
+ \scalebox\fad@scale{\phantom{$|$}}%
+ \kern\dimexpr-\fad@letterwidth/10\relax
+ \fi
+ }}%
+ }%
+ \color{\fad@boxcolor}%
+ \chardef\icol\z@pt
+ \cptdotimes\@tempcnta{%
+ \pushnumber\icol
+ \colbox{\scalebox\fad@scale
+ {\xwmstrut\fad@height\fad@depth
+ \usename{fade@\romannumeral\icol}}}%
+ }%
+ \endgroup
+}
+\cptonlypreamble{%
+ \dummypagenos,\fancypagenos,
+ \FancyPageNumbers,\NoFancyPageNumbers
+}
+\newcommand*\dummypagenos[1][]{}
+\newcommand*\fancypagenos[1][]{%
+ \ifblankTF{#1}{}{\AtBeginDocument{\xwm@fancypagenos{#1}}}%
+}
+\robust@def*\NoFancyPageNumbers{%
+ \AfterStartOfDocument{\global\pgn@showpagenosfalse}%
+}
+\robust@def*\FancyPageNumbers{%
+ \AfterStartOfDocument{\global\pgn@showpagenostrue}%
+}
+\robust@def*\xwm@fancypagenos#1{%
+ \ltxkeys@launchkeys[XWM]{fancypagenos}{#1}%
+ \xwm@getposition\pgn@textxpos\pgn@textypos\pgn@coordunit
+ \ifnumcmpFT\c@page=\@ne{}{%
+ \AfterStartOfDocument{\thispagestyle{\xwm@frontpagestyle}}%
+ }%
+ \pagestyle{fancyplain}%
+ \fancyhf{}%
+ \cfoot{\pgn@cfoot}\rfoot{\pgn@rfoot}%
+ \lfoot{\pgn@lfoot}\chead{\pgn@chead}%
+ \rhead{\pgn@rhead}\lhead{\pgn@lhead}%
+ \ifpgn@showheadrule
+ \def\headrule{{%
+ \color{\pgn@headruleC}%
+ \hrule\@height\pgn@headruleH\@depth\pgn@headruleD
+ \@width\headwidth\vspace{\pgn@headruleS}%
+ \hrule\@height\pgn@headruleH\@depth\pgn@headruleD
+ \@width\headwidth\vspace{-\pgn@headruleS}%
+ }}%
+ \else
+ \let\headrule\relax
+ \fi
+ \ifpgn@showfootrule
+ \def\footrule{{%
+ \color{\pgn@footruleC}%
+ \hrule\@height\pgn@footruleH\@depth\pgn@footruleD
+ \@width\headwidth\vspace{\pgn@footruleS}%
+ \hrule\@height\pgn@footruleH\@depth\pgn@footruleD
+ \@width\headwidth\vspace{\pgn@footruleS}%
+ }}%
+ \else
+ \let\footrule\relax
+ \fi
+ \xwm@gethfoffset\pgn@hfoffsetL\pgn@hfoffsetR
+ \fancyhfoffset[R,L]\xwm@hfoffset
+ \AtBeginShipout{%
+ \if@boolTF{pgn@sendtoback}{%
+ \AtBeginShipoutUpperLeft{%
+ \xwm@f@ncyp@genos
+ }%
+ }{%
+ \AtBeginShipoutUpperLeftForeground{%
+ \xwm@f@ncyp@genos
+ }%
+ }%
+ }%
+}
+\robust@def*\xwm@f@ncypagenos{%
+ \def\pgn@textmark{\pgn@format{\normalfont\pgn@style}}%
+ \xwm@textbox{pgn}%
+}
+\robust@def*\xwm@f@ncyp@genos{%
+ \if@boolFT{pgn@showpagenos}{}{%
+ \ifnumcmpTF\c@page=\@ne{%
+ \ifpgn@showonpageone\xwm@f@ncypagenos\fi
+ }{%
+ \xwm@f@ncypagenos
+ }%
+ }%
+}
+\robust@def*\xwm@gethfoffset#1#2{%
+ \begingroup
+ \def\temp@err{%
+ \xwm@err{Only digits (without units) are allowed\MsgBrk
+ in the values of 'hfoffsetL' and 'hfoffsetR'}\@ehc
+ }%
+ \xifblankTF{#1}{}{%
+ \x@xwmifitemsinTF\xwm@allowedcoordunits{#1}\temp@err{}%
+ }%
+ \xifblankTF{#2}{}{%
+ \x@xwmifitemsinTF\xwm@allowedcoordunits{#2}\temp@err{}%
+ }%
+ \def\xwm@tempc##1##2{%
+ \xifblankTF{##1}{\def##2{1}}{\def##2{##1}}%
+ \ifdim##2\p@>\p@\def##2{1}\fi
+ }%
+ \xwm@tempc{#1}\xwm@tempa\xwm@tempc{#2}\xwm@tempb
+ \def\xwm@tempc##1{%
+ \xifinsetFT{.}{##1}{}{%
+ \def\xwm@tempd####1.####2\xwm@nil{\def##1{.####2}}%
+ \cptexpandsecond\xwm@tempd{##1}\xwm@nil
+ }%
+ }%
+ \xwm@tempc\xwm@tempa\xwm@tempc\xwm@tempb
+ \cptpassexpanded{%
+ \endgroup\def\noexpand\xwm@hfoffset{%
+ \the\dimexpr\xwm@tempa\marginparsep+%
+ \xwm@tempb\marginparwidth\relax
+ }%
+ }%
+}
+\robust@redef*\Gin@ii[#1]#2{%
+ \ifstrcmpTF{[}{#2}{%
+ \Gin@iii[#1][%
+ }{%
+ \begingroup
+ \@tempswafalse
+ \toks@{\Ginclude@graphics{#2}}%
+ \ltxkeys@setkeys{Gin}{#1}%
+ \Gin@esetsize
+ \the\toks@
+ \endgroup
+ }%
+}
+\robust@redef*\Grot@box@kv[#1]#2#3{%
+ \@begin@tempboxa\hbox{#3}%
+ \Grot@x\dimexpr\width/2\relax
+ \Grot@y\dimexpr(\height-\depth)/2\relax
+ \ltxkeys@setkeys{Grot}{#1}%
+ \setbox\z@pt\box\@tempboxa
+ \Grot@setangle{#2}%
+ \Grot@box
+ \@end@tempboxa
+}
\endinput
-%%% End of file xwatermark.sty %%% \ No newline at end of file
+%%% End of file xwatermark.sty %%%