summaryrefslogtreecommitdiff
path: root/graphics/pgf/contrib/playcards/playcards.sty
blob: 4b5d8fb85b1667f7dcb109a6a27bf003d17cc170 (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
% Clément PAGÈS <contact@clementpages.fr>
%
% Version 0.2
%
% Draws basic playcards with Tikz. Inspired by https://tex.stackexchange.com/questions/47924/creating-playing-cards-using-tikz
%
% Provides cards for a4paper format
%
% Licence Gnu Lesser General Public Licence https://www.gnu.org/licenses/lgpl-3.0.html



\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{playcards}[2023/05/02, Personal commands]

\RequirePackage{simplekv}
\RequirePackage{graphicx}
\RequirePackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{shadows}
\usepgflibrary {shadings}
\tikzset{
    x=1mm,y=1mm,
    cardcorners/.style={
        rounded corners=4
    },
}

% Check if attor is given a optional parameter
\newif\if@loadanttorfont\@loadanttorfontfalse
\DeclareOption{anttor}{\@loadanttorfonttrue}
\ProcessOptions\relax


\RequirePackage[outline]{contour}

\pgfmathsetmacro{\cardwidth}{59}
\pgfmathsetmacro{\cardheight}{89}
\pgfmathsetmacro{\cardmargin}{4}
\pgfmathsetmacro{\cardwidthbody}{\cardwidth-\cardmargin}
\pgfmathsetmacro{\cardheightbody}{\cardheight-\cardmargin}
\pgfmathsetmacro{\stripwidth}{10}
\pgfmathsetmacro{\strippadding}{2}


\def\shapeCard{(0,0) rectangle (\cardwidth,\cardheight)}
\def\shapeCardBody{(0,0) rectangle (\cardwidthbody,\cardheightbody)}
\def\shapeMargin{(\cardmargin,\cardmargin) rectangle (\cardwidthbody,\cardheightbody)}



\newcommand{\carddebug}{
    \draw [step=1,help lines] (0,0) grid (\cardwidth,\cardheight);
}

\newcommand{\cardborder}{
    \draw[lightgray,cardcorners] \shapeCard;
    \draw[black,cardcorners,line width=1pt] \shapeMargin;
}

\newcommand{\cardpadding}{
    \draw[white,cardcorners] {(0,0) rectangle (\cardwidth+2,\cardheight+2)};
}


\setKVdefault[RectoKeys]{borders=true, trame=true, corners=true, backgroundImg=true, textColor=black, backgroundColor=red, contentsFontSize=120, circleRay=20}
\setKVdefault[VersoKeys]{backgroundImg=true, trame=true, contentsFontSize=50}



\newcommand{\cardbackgroundverso}[2][]{
    \pgfmathsetmacro{\textsize}{\useKV[VersoKeys]{contentsFontSize}}
    \pgfmathsetmacro{\textlineskip}{1.2*\textsize}
	\clip[cardcorners] \shapeCard;
    \ifboolKV[VersoKeys]{backgroundImg} {%
		\begin{scope} % Draw background
			\draw[shading=color wheel,opacity=0.6] (0,0) rectangle (\cardwidth,\cardheight);
		\end{scope}
	}{%
		\draw[cardcorners, line width=1pt] \shapeCard;%
	}%
    \begin{scope}[shift={(0.5*\cardwidth,0.5*\cardheight)}] % White text
        \node[rotate=45, color=white] at (0,0) {\contourlength{1pt}\contour{black!}{\fontsize{\textsize}{\textlineskip pt}\selectfont #2}};
    \end{scope}
}


\newcommand{\cardcontent}[2][]{
    \pgfmathsetmacro{\textsize}{\useKV[RectoKeys]{contentsFontSize}}
    \pgfmathsetmacro{\textlineskip}{1.2*\textsize}
    \showKV[RectoKeys]{backgroundImg}
    \showKV[RectoKeys]{backgroundColor}
    \begin{scope}
		\ifboolKV[RectoKeys]{borders} {
			\clip[cardcorners] \shapeMargin;
		}{
			\clip[cardcorners] \shapeCard;
		}
		\ifboolKV[RectoKeys]{backgroundImg} {
			\shade[xshift=29.5mm, yshift=44.5mm, inner color={\useKV[RectoKeys]{backgroundColor}}, outer color=white] circle (\cardwidth) circle({\useKV[RectoKeys]{circleRay}});
		}
		{}
		\draw[color=white] (0,0) -- (60,70);
		\draw[color=white] (0,20) -- (60,15);
		\draw[color=white] (0,24) -- (60,30);
		\draw[color=white] (0,37) -- (60,36);
		\draw[color=white] (0,40) -- (60,60);
		\draw[color=white] (0,47) -- (60,5);
		\draw[color=white] (0,55) -- (60,45);
		\draw[color=white] (0,70) -- (40,0);
		\draw[color=white] (0,76) -- (60,65);
		\draw[color=white] (0,80) -- (25,0);
		\draw[color=white] (20,80) -- (15,0);
		\draw[color=white] (35,90) -- (0,80);
		\draw[color=white] (40,90) -- (60,-20);
		\draw[color=white] (0,5) -- (60,90);
		\draw[xshift=29.5mm, yshift=44.5mm, fill=white, color=white] circle(({\useKV[RectoKeys]{circleRay}});
	\end{scope}
	\node[align=center, text width=5 cm] at (0.5*\cardwidth,0.5*\cardheight) {{\color{\useKV[RectoKeys]{textColor}}\fontsize{\textsize}{\textlineskip}\selectfont #2}};
}

\newcommand{\cardcorner}[1]{
	\begin{scope}[shift={(13,76)}]
		\draw[rotate=30, fill=white, color=white] (0,0) ellipse (8 and 5) node[color=black, rotate=30]{{\color{\useKV[RectoKeys]{textColor}}{\fontsize{36pt}{43pt}\selectfont #1}}};
	\end{scope}
	\begin{scope}[shift={(\cardwidth-13,\cardheight-76)}]
		\draw[rotate=30, fill=white, color=white] (0,0) ellipse (8 and 5) node[rotate=210, color=black]{{\color{\useKV[RectoKeys]{textColor}}{\fontsize{36pt}{43pt}\selectfont #1}}};
	\end{scope}
}


\newcommand{\drawcardrecto}[2][]{
	\begin{tikzpicture}
		\cardborder
		\cardpadding
		\cardcontent{#2}
		\ifboolKV[RectoKeys]{corners}{
			\cardcorner{#2}
		}{
		}
	\end{tikzpicture}%
}


\newcommand{\drawcardverso}[2][]{
	\begin{tikzpicture}%
		\cardpadding
		\cardbackgroundverso{#2}
	\end{tikzpicture}
}


\newcommand{\drawcardsverso}[2][]{
	\if@loadanttorfont % Change card font to anttor if parameter antor given
		\fontfamily{antt}
	\fi
    \useKVdefault[VersoKeys]%
    \setKV[VersoKeys]{#1}%
    \ifboolKV[VersoKeys]{trame}{%
		\foreach \k in {0,...,2}{%
			\foreach \n in {0,...,2}{%
				\noindent\drawcardverso{#2}%
			}\\%
		}%
	}{%
		\noindent\drawcardverso{#2}%
	}%
}

\newcommand{\drawcardsrecto}[2][] {
	\if@loadanttorfont % Change card font to anttor if parameter antor given
		\fontfamily{antt}
	\fi
	\useKVdefault[RectoKeys]%
	\setKV[RectoKeys]{#1}%
	\ifboolKV[RectoKeys]{trame}{
		\foreach \k in {0,...,2}{%
			\foreach \n in {0,...,2}{%
				\noindent\drawcardrecto{#2}%
			}\\%
		}%
	}{
		\noindent\drawcardrecto{#2}%
	}%
}