diff options
author | Karl Berry <karl@freefriends.org> | 2009-12-11 17:29:21 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-12-11 17:29:21 +0000 |
commit | 255ba44b76120637be9f2d3d81ddda836a37c128 (patch) | |
tree | 6a32a283c8bf4a96b076f0eff23ec30416071e1a /Master/texmf-dist/tex/latex/xwatermark | |
parent | 3225c190bb874fa17c648d7e7a4a5f9340b37eff (diff) |
new package xwatermark 1.3 (9dec09)
git-svn-id: svn://tug.org/texlive/trunk@16366 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/xwatermark')
-rw-r--r-- | Master/texmf-dist/tex/latex/xwatermark/xwatermark.sty | 467 |
1 files changed, 467 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/xwatermark/xwatermark.sty b/Master/texmf-dist/tex/latex/xwatermark/xwatermark.sty new file mode 100644 index 00000000000..653ab50f239 --- /dev/null +++ b/Master/texmf-dist/tex/latex/xwatermark/xwatermark.sty @@ -0,0 +1,467 @@ +%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% +% This is file 'xwatermark.sty', version 1.3. % +% % +% This package puts user-specified watermarks (graphics and arbitrary % +% texts) on select pages of documents. It is more general than, eg, the % +% packages 'draftwatermark', 'watermark' and 'draftmark'. See package % +% documentation for further details. % +% % +% This work may be distributed and/or modified under the conditions % +% of the LaTeX Project Public License, either version 1.3 of this % +% license or any later version. The latest version of this license % +% is in http://www.latex-project.org/lppl.txt and version 1.3 or later % +% is part of all distributions of LaTeX version 2005/12/01 or later. % +% % +% The LPPL maintenance status of this software is 'author-maintained'. % +% % +% This software is provided 'as it is', without warranty of any kind, % +% either expressed or implied, including, but not limited to, the % +% implied warranties of merchantability and fitness for a particular % +% purpose. % +% % +% Copyright (c) 2009 Ahmed Musa (a.musa@rocketmail.com). % +%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% +\begingroup +\catcode064=11% @ +\catcode123=01% { +\catcode125=02% } +\def\x{\endgroup + \edef\xwm@RestoreCodeAtEnd{% + \catcode035=\the\catcode035\relax + \catcode064=\the\catcode064\relax + \catcode123=\the\catcode123\relax + \catcode125=\the\catcode125\relax + }% +} +\x +\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{061}{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.3 2009/10/27 09:00:00 Ahmed Musa Exp $ +\ProvidesPackage{xwatermark}[\filedate\space\fileversion\space\filedesc] +\NeedsTeXFormat{LaTeX2e}[1996/12/01] +\RequirePackage{etextools}[2009/09/30] +\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}} +\newrobustcmd*\xwm@numdef[2]{% + \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]{% + \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\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 + \expandafter\xwm@err{Empty page range passed to package} + \else + \expandafter\xwm@err{Only page \xwm@pagestart\MessageBreak + was passed as page range} + \fi + }{% + \xwm@pagerange@split#1\@nil + }% +} +\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 + \expandafter\expandafter\expandafter% + \xwm@err{No ending page for page range} + \else + \expandafter\expandafter\expandafter% + \xwm@info{Page range:\space + \xwm@pagestart\space to \xwm@pageend} + \fi + \fi + }{% + \xwm@err{Too many hyphens in page range} + }% +} +\new\def\xwm@pagerange@ifhyphen#1-#2\@nil{% + \ifstrempty{#2}{\expandafter\@firstoftwo}{\expandafter\@secondoftwo} +} +\RequirePackage{fix-cm} +\RequirePackage{graphicx} +\RequirePackage{xkeyval}[2008/08/13] +\RequirePackage{atbegshi} +\RequirePackage{picture} +\@ifpackageloaded{xcolor}{% + \xwm@info{You have loaded 'xcolor' package\MessageBreak + with options that possibly differ\MessageBreak + from those of 'xwatermark' package} +}{% + \RequirePackage[dvipsnames*,svgnames*,x11names*,table,hyperref]{xcolor} + \xwm@info{'xcolor' package loaded with\MessageBreak + options 'dvipsnames', 'svgnames',\MessageBreak + 'x11names', 'table', 'hyperref'} +} +\RequirePackage{xifthen}[2009/04/17] +\RequirePackage{ifpdf} +\RequirePackage{boxedminipage} +\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 +\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'}}{} + \fi + } +} +\define@choicekey*+[XWM]{xwatermark}{align}[\xwm@val\xwm@nr]% +{center,right,left,justified}[center]{% + \ifcase\xwm@nr\relax + \def\xwm@align{\centering}% + \or + \def\xwm@align{\flushright}% + \or + \def\xwm@align{\flushleft}% + \or + \let\xwm@align\relax + \fi +}{% + \xwm@err{Inadmissible value '#1' for align} +} +\define@cmdkey[XWM]{xwatermark}[xwm@]{page}[1]{% + \xwm@bool@onepageonlytrue + \xwm@minmark=1\relax +} +\define@key[XWM]{xwatermark}{pages}[1-1]{% + \xwm@bool@prangetrue + \xwm@pagerange{#1}% + \xwm@minmark=1\relax +} +\ifpdf\new\def\xwm@picfilex{pdf}\else\new\def\xwm@picfilex{eps}\fi +\define@cmdkey[XWM]{xwatermark}[xwm@]{picscale}[1]{} +\define@cmdkey[XWM]{xwatermark}[xwm@]{picbb}[0 0 100 100]{} +\define@cmdkey[XWM]{xwatermark}[xwm@]{picfile}[]{% + \ifstrempty{#1}{\xwm@bool@pmarkfalse}{% + \xwm@bool@pmarktrue + \xwm@minmark=\@ne\relax + } +} +\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}} + \ifpdf + \ifthenelse{\isempty{\xwm@picfilex}\OR\equal{\xwm@picfilex}{eps}}% + {\def\xwm@picfilex{pdf}}{}% + \else + \ifthenelse{\isempty{\xwm@picfilex}\OR\equal{\xwm@picfilex}{pdf}% + \OR\equal{\xwm@picfilex}{png}\OR\equal{\xwm@picfilex}{jpeg}}% + {\def\xwm@picfilex{eps}}{}% + \fi +} +\define@cmdkey[XWM]{xwatermark}[xwm@]{color}[gray!25]{} +\define@cmdkey[XWM]{xwatermark}[xwm@]{fontfamily}[bch]{} +\define@cmdkey[XWM]{xwatermark}[xwm@]{angle}[45]{} +\define@cmdkey[XWM]{xwatermark}[xwm@]{scale}[1]{} +\define@cmdkey[XWM]{xwatermark}[xwm@]{coordunit}[mm]{} +\define@cmdkey[XWM]{xwatermark}[xwm@]{fontsize}[5cm]{} +\define@cmdkey[XWM]{xwatermark}[xwm@]{fontseries}[b]{} +\define@cmdkey[XWM]{xwatermark}[xwm@]{height}[\paperwidth]{} +\define@cmdkey[XWM]{xwatermark}[xwm@]{width}[\paperheight]{} +\define@cmdkeys[XWM]{xwatermark}[xwm@]{xcoord,ycoord}[\z@] +\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}} +\def\xwm@nolateoptions{printwatermark,allpages,evenpages,oddpages,% + firstpage,page,pages} +\AtBeginDocument{% + \@for\@mem:=\xwm@nolateoptions\do{% + \key@ifundefined[XWM]{xwatermark}{\@mem}{}{% + \disable@keys[XWM]{xwatermark}{\@mem}% + }% + }% +} +\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}}% +}% +\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% + }}}}\relax + \removelastskip\normalcolor% +}% +\newcommand\xwm@insert@picmark@a{% + \xwm@align + \makebox(0,0){\rotatebox{\xwm@angle}{\xwm@insertpic}}\relax +}% +\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 + \ifodd\c@page\else + \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 + \fi +}% +\ifxwm@printwatermark + \AtBeginShipout{\AtBeginShipoutUpperLeft{\xwm@insertmark}} + \xwm@info{Option 'printwatermark=true': watermark printed} +\fi +\define@cmdkey[XWM]{minipage}[mp@]{width}[\paperwidth]{} +\define@cmdkey[XWM]{minipage}[mp@]{textcolor}[black]{} +\define@cmdkey[XWM]{minipage}[mp@]{framecolor}[white]{} +\define@cmdkey[XWM]{minipage}[mp@]{framesep}[3pt]{} +\define@cmdkey[XWM]{minipage}[mp@]{framerule}[.4pt]{} +\define@cmdkey[XWM]{minipage}[mp@]{text}[No text passed.]{} +\define@key[XWM]{minipage}{align}[center]{% + \begingroup + \protected@edef\@tempa{#1}% + \def\@tempb{center}% + \ifx\@tempa\@tempb + \gdef\mp@align{\centering}% + \else + \def\@tempb{right}% + \ifx\@tempa\@tempb + \gdef\mp@align{\flushright}% + \else + \def\@tempb{left}% + \ifx\@tempa\@tempb + \gdef\mp@align{\flushleft}% + \else + \def\@tempb{justified}% + \ifx\@tempa\@tempb + \global\let\mp@align\relax + \else + \xwm@err{Inadmissible value '#1' for minipage's align} + \fi + \fi + \fi + \fi + \endgroup +} +\presetkeys[XWM]{minipage}{align,width,textcolor,text,framesep, + framerule,framecolor}{}% +\long\def\xwminipage#1{% + \setkeys[XWM]{minipage}{#1}% + \begingroup + \fboxsep=\mp@framesep\relax + \fboxrule=\mp@framerule\relax + \removelastskip + \color{\mp@framecolor}% + \noindent + \begin{boxedminipage}{\mp@width}% + \mp@align\textcolor{\mp@textcolor}{\mp@text}% + \end{boxedminipage}\relax + \removelastskip + \endgroup +}% +\define@cmdkey[XWM]{colorbox}[cb@]{width}[\textwidth]{} +\define@cmdkey[XWM]{colorbox}[cb@]{textcolor}[black]{} +\define@cmdkey[XWM]{colorbox}[cb@]{fillcolor}[yellow!55]{} +\define@cmdkey[XWM]{colorbox}[cb@]{framecolor}[white]{} +\define@cmdkey[XWM]{colorbox}[cb@]{text}[No text passed.]{} +\define@cmdkey[XWM]{colorbox}[cb@]{framesep}[3\p@]{} +\define@cmdkey[XWM]{colorbox}[cb@]{framerule}[0.4\p@]{} +\define@choicekey*+[XWM]{colorbox}{align}[\cb@val\cb@nr]% +{center,right,left,justified}[center]{% + \protected@edef\cb@align{\cb@val} +}{% + \xwm@err{Inadmissible value '#1' for colorbox's align} +} +\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}{\relax + \xwminipage{framesep=\cb@framesep,framerule=\cb@framerule, + framecolor=\cb@framecolor,align=\cb@align,width=\cb@width, + text=\cb@text,textcolor=\cb@textcolor% + }\relax + }% + \removelastskip\normalcolor +}% +\newcommand\ywcolorbox[1]{% + \setkeys[XWM]{colorbox}{#1}% + \color{\cb@framecolor}% + \begin{center} + \makebox[\z@][c]{% + \colorbox{\cb@fillcolor}{\relax + \xwminipage{framesep=\cb@framesep,framerule=\cb@framerule, + framecolor=\cb@framecolor,align=\cb@align,width=\cb@width, + text=\cb@text,textcolor=\cb@textcolor + }\relax + }% + }% + \end{center} + \removelastskip\normalcolor +}% +\new\def\xwm@insertpic{\begingroup + \protected@edef\@tempa{\endgroup% + \ifpdf + \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}}% + \else + \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}}% + \fi% + }\@tempa% +} +% Patch for xkeyval.sty: +\renewrobustcmd\XKV@disable@keys[1]{% + \XKV@checksanitizeb{#1}\XKV@tempa + \XKV@for@o\XKV@tempa\XKV@tempa{% + \XKV@ifundefined{\XKV@header\XKV@tempa}{% + \XKV@err{key '\XKV@tempa' undefined}% + }{% + \edef\XKV@tempb{% + \noexpand\xwm@err{Key '\XKV@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}% + }% + \XKV@ifundefined{\XKV@header\XKV@tempa @default}{% + \edef\XKV@tempc{\noexpand\XKV@define@key{\XKV@tempa}}% + }{% + \edef\XKV@tempc{\noexpand\XKV@define@key{\XKV@tempa}[]}% + }% + \expandafter\XKV@tempc\expandafter{\XKV@tempb}% + }% + }% +} + +\endinput |