Debian Codegraph @

texmf-dist/tex/latex/worldflags/worldflags.sty

raw
1 % =============================================================================
2 % worldflags.sty - Flags of the World with TikZ
3 % (c) Wilhelm Haager 2021-05-12
4 % 2022-07-09 ... option "variant" added
5 % =============================================================================
6 \RequirePackage{ifthen}
7 \RequirePackage{tikz}
8 \RequirePackage{xcolor}
9 \RequirePackage{etex}
10 \RequirePackage{xkeyval}
11 \RequirePackage{graphicx}
12 \usetikzlibrary{calc,shadows,shapes,shapes.symbols,positioning,math,decorations.text}
13 \definecolor{gridcolor}{rgb}{0.8,0.8,0.8}
14
15 % ----------------------------------------------------------------------------
16 % Default values
17 % ----------------------------------------------------------------------------
18 \newdimen\fl@gwidth\fl@gwidth=15mm
19 \newdimen\fl@glength\fl@glength=0mm
20 \newdimen\fl@gframe\fl@gframe=0.2mm
21 \def\fl@gvariant{0} % 2022-07-09
22 \def\fl@gstretch{0}
23 \def\fr@mecolor{black!60}
24 \def\gr@dcolor{black!80}
25 \newif\if@mbl@m\@mbl@mtrue
26 \newif\if@rid\@ridfalse
27 \newif\ifn@@mbl@m\n@@mbl@mtrue
28 \def\view@ngle{0}
29 \def\hang@ngle{0}
30
31 % ----------------------------------------------------------------------------
32 % 2 horizontal stripes
33 % ----------------------------------------------------------------------------
34 \def\wf@hstripesII#1#2{% 3 horizontal stripes
35 \fill [#1] (0,1/2) rectangle (\flaglength,1);
36 \fill [#2] (0,0) rectangle (\flaglength,1/2);}
37
38 % ----------------------------------------------------------------------------
39 % 3 horizontal stripes
40 % ----------------------------------------------------------------------------
41 \def\wf@hstripesIII#1#2#3{% 3 horizontal stripes
42 \fill [#1] (0,2/3) rectangle (\flaglength,1);
43 \fill [#2] (0,1/3) rectangle (\flaglength,2/3);
44 \fill [#3] (0,0) rectangle (\flaglength,1/3);}
45
46 % ----------------------------------------------------------------------------
47 % 4 horizontal stripes
48 % ----------------------------------------------------------------------------
49 \def\wf@hstripesIV#1#2#3#4{%
50 \fill [#1] (0,3/4) rectangle (\flaglength,1);
51 \fill [#2] (0,1/2) rectangle (\flaglength,3/4);
52 \fill [#3] (0,1/4) rectangle (\flaglength,1/2);
53 \fill [#4] (0,0) rectangle (\flaglength,1/4);}
54
55 % ----------------------------------------------------------------------------
56 % 5 horizontal stripes
57 % ----------------------------------------------------------------------------
58 \def\wf@hstripesV#1#2#3#4#5{%
59 \fill [#1] (0,4/5) rectangle (\flaglength,1);
60 \fill [#2] (0,3/5) rectangle (\flaglength,4/5);
61 \fill [#3] (0,2/5) rectangle (\flaglength,3/5);
62 \fill [#4] (0,1/5) rectangle (\flaglength,2/5);
63 \fill [#5] (0,0) rectangle (\flaglength,1/5);}
64
65 % ----------------------------------------------------------------------------
66 % 6 horizontal stripes
67 % ----------------------------------------------------------------------------
68 \def\wf@hstripesVI#1#2#3#4#5#6{%
69 \fill [#1] (0,5/6) rectangle (\flaglength,1);
70 \fill [#2] (0,4/6) rectangle (\flaglength,5/6);
71 \fill [#3] (0,3/6) rectangle (\flaglength,4/6);
72 \fill [#4] (0,2/6) rectangle (\flaglength,3/6);
73 \fill [#5] (0,1/6) rectangle (\flaglength,2/6);
74 \fill [#6] (0,0) rectangle (\flaglength,1/6);}
75
76 % ----------------------------------------------------------------------------
77 % 2 vertical stripes
78 % ----------------------------------------------------------------------------
79 \def\wf@vstripesII#1#2{% 2 vertical stripes
80 \fill [#1] (0,0) rectangle (0.5\flaglength,1);
81 \fill [#2] (0.5\flaglength,0) rectangle (\flaglength,1);}
82
83 % ----------------------------------------------------------------------------
84 % 3 vertical stripes
85 % ----------------------------------------------------------------------------
86 \def\wf@vstripesIII#1#2#3{% 3 vertical stripes
87 \fill [#1] (0,0) rectangle (\flaglength/3,1);
88 \fill [#2] (\flaglength/3,0) rectangle (2\flaglength/3,1);
89 \fill [#3] (2\flaglength/3,0) rectangle (\flaglength,1);}
90
91 % ----------------------------------------------------------------------------
92 % Vertical bar (width relative to flagWIDTH)
93 % ----------------------------------------------------------------------------
94 % #1...color, #2...position, #3...width
95 \def\wf@vbar#1#2#3{%
96 \fill [#1] (#2,0) ++(-#3/2,0)
97 rectangle ++(#3,1);}
98
99 % ----------------------------------------------------------------------------
100 % Horizontal bar (width relative to flagwidth)
101 % ----------------------------------------------------------------------------
102 % #1...color, #2...position, #3...width
103 \def\wf@hbar#1#2#3{%
104 \fill [#1] (0,#2) ++(0,-#3/2)
105 rectangle ++(\flaglength,#3);}
106
107 % ----------------------------------------------------------------------------
108 % Cevron; #1...color, #2...width
109 % ----------------------------------------------------------------------------
110 \def\wf@chevron#1#2{%
111 \fill [#1] (0,0)--(0,1)--(#2,0.5)--cycle;}
112
113 % ----------------------------------------------------------------------------
114 % n-pointed-star
115 % ----------------------------------------------------------------------------
116 % #1...color, #2...points, #3...coordinate, #4...outer radius,
117 % #5...inner radius, #6...angle
118 \def\wf@starn#1#2#3#4#5#6{%
119 \begin{scope}[shift={#3},rotate=#6]
120 \fill [#1] (90:#4) foreach \n in {1,...,#2}
121 {--(90-180/#2+\n*360/#2:#5)--(90+\n*360/#2:#4)}--cycle;
122 \end{scope}}
123
124 % ----------------------------------------------------------------------------
125 % 5-pointed-star
126 % ----------------------------------------------------------------------------
127 % #1...color, #2...coordinate, #3...outer radius, #4...angle
128 \def\wf@starV#1#2#3#4{\starn{#1}{5}{#2}{#3}{0.381966*#3}{#4}}
129
130 % ----------------------------------------------------------------------------
131 % 6-pointed-star
132 % ----------------------------------------------------------------------------
133 % #1...color, #2...coordinate, #3...outer radius, #4...angle
134 \def\wf@starVI#1#2#3#4{\starn{#1}{6}{#2}{#3}{0.57735*#3}{#4}}
135
136 % ----------------------------------------------------------------------------
137 % Background; #1...color
138 % ----------------------------------------------------------------------------
139 \def\wf@background#1{%
140 \fill [#1] (0,0) rectangle (\flaglength,\flagwidth);}
141
142 % ----------------------------------------------------------------------------
143 % Moon
144 % ----------------------------------------------------------------------------
145 % #1...color, #2...outer coordinates, #3...outer radius,
146 % #4 inner coordinates #5...inner radius
147 \def\wf@moon#1#2#3#4#5{%
148 \begin{scope}
149 \clip #2 circle (#3);
150 \fill [even odd rule,#1] #2 circle (1.01*#3) #4 circle (#5);
151 \end{scope}}
152
153 % ----------------------------------------------------------------------------
154 % Natural aspect-ratio of a flag (for internal use)
155 % ----------------------------------------------------------------------------
156 \def\wf@aspectratio#1{%
157 \ifx\flagstretch\undefined\def\flagstretch{0}\fi
158 \ifx\flaglength\undefined\newdimen\flaglength\flaglength0pt\fi
159 \ifdim\flaglength=0pt\pgfmathparse{\flagwidth/(#1)}\pgfmathsetlength{\flaglength}{\pgfmathresult}\fi
160 \ifdim\flagwidth=0pt\pgfmathparse{\flaglength*(#1)}\pgfmathsetlength{\flagwidth}{\pgfmathresult}\fi
161 \pgfmathparse{(\flaglength/\flagwidth*(#1)-1)*\flagstretch+1}
162 \edef\stretchfactor{\pgfmathresult}}
163
164 % ----------------------------------------------------------------------------
165 % wf@framecode and wf@gridcode
166 % ----------------------------------------------------------------------------
167 \def\wf@framecode#1{\end{scope}
168 \ifx\framecolor\undefined\global\def\framecolor{\fr@mecolor}\fi
169 \ifx\flagframe\undefined\newdimen\flagframe\global\flagframe\fl@gframe\fi
170 \ifdim\flagframe>0pt
171 \begin{scope}[\framecolor,line width=\flagframe]
172 \ifx.#1.\draw (0,0) rectangle (\flaglength,\flagwidth);
173 \else#1\fi
174 \end{scope}
175 \fi
176 \begin{scope}}
177 \def\wf@gridcode{\ifgrid % Version 2023-07-03
178 \begin{scope}[x=1mm,y=1mm,black,line width=0.1pt]
179 \draw [\gr@dcolor,opacity=0.15,xstep=1mm,ystep=1mm] (0,0) grid (\flaglength,\flagwidth);
180 \draw [\gr@dcolor,opacity=0.15,xstep=5mm,ystep=5mm] (0,0) grid (\flaglength,\flagwidth);
181 \draw [\gr@dcolor,opacity=0.15,xstep=10mm,ystep=10mm] (0,0) grid (\flaglength,\flagwidth);
182 \end{scope}
183 \fi}
184
185 % ----------------------------------------------------------------------------
186 % Environment flagdescription
187 % ----------------------------------------------------------------------------
188 \newenvironment{flagdescription}[1]{%
189 % \begingroup
190 \def\makeifgrid{\newif\ifgrid\if@rid\gridtrue\else\gridfalse\fi}
191 \ifx\flagwidth\undefined\newdimen\flagwidth\flagwidth\fl@gwidth\fi
192 \ifx\ifgrid\undefined\makeifgrid\fi
193 \let\hstripesII=\wf@hstripesII
194 \let\hstripesIII=\wf@hstripesIII
195 \let\hstripesIV=\wf@hstripesIV
196 \let\hstripesV=\wf@hstripesV
197 \let\hstripesVI=\wf@hstripesVI
198 \let\vstripesII=\wf@vstripesII
199 \let\vstripesIII=\wf@vstripesIII
200 \let\starn=\wf@starn
201 \let\starV=\wf@starV
202 \let\starVI=\wf@starVI
203 \let\moon=\wf@moon
204 \let\unionjack=\wf@unionjack
205 \let\hbar=\wf@hbar
206 \let\vbar=\wf@vbar
207 \let\chevron=\wf@chevron
208 \let\framecode=\wf@framecode
209 \let\gridcode=\wf@gridcode
210 \let\background=\wf@background
211 \wf@aspectratio{#1}
212 \ifx\viewangle\undefined\def\viewangle{0}\fi
213 \ifx\hangangle\undefined\def\hangangle{0}\fi
214 \begin{scope}[x=\flagwidth,y=\flagwidth,cm={cos(\viewangle)*cos(\hangangle),
215 -sin(\hangangle),0,1,(0,0)}]
216 \begin{scope}[shift={(-0.5\flaglength,-0.5\flagwidth)}]
217 \begin{scope} % inner scope for clipping
218 \clip (0,0) rectangle (\flaglength,\flagwidth);
219 \coordinate (-0) at (0.5\flaglength,0.5\flagwidth);
220 \coordinate (-nw) at (0,\flagwidth);
221 \coordinate (-w) at (0,0.5\flagwidth);
222 \coordinate (-sw) at (0,0);
223 \coordinate (-n) at (0.5\flaglength,\flagwidth);
224 \coordinate (-s) at (0.5\flaglength,0);
225 \coordinate (-ne) at (\flaglength,\flagwidth);
226 \coordinate (-e) at (\flaglength,0.5\flagwidth);
227 \coordinate (-se) at (\flaglength,0);}
228 {\end{scope}\wf@gridcode\end{scope}\end{scope}%\endgroup
229 \global\let\flagvariant\undefined % 2022-07-09
230 \global\let\flagwidth\undefined
231 \global\let\flaglength\undefined
232 \global\let\flagframe\undefined
233 \global\let\flagstretch\undefined
234 \global\let\framecolor\undefined
235 \global\let\ifemblem\undefined
236 \global\let\ifnoemblem\undefined
237 \global\let\ifgrid\undefined
238 \global\let\viewangle\undefined
239 \global\let\hangangle\undefined
240 }
241
242 % ----------------------------------------------------------------------------
243 % Union Jack (neuer Versuch, 12.4.2021)
244 % ----------------------------------------------------------------------------
245 \def\wf@unionjack#1#2#3#4{%
246 \begin{scope}[cm={1,0,0,1,(#1,#2)}]
247 \newdimen\b\b=#3\advance\b by -#1
248 \newdimen\h\h=#4\advance\h by -#2
249 \newdimen\lwb\lwb=\h\divide \lwb by 3
250 \newdimen\lws\lws=\h\divide \lws by 5
251 \pgfmathparse{atan2(\h,\b)}
252 \edef\winkel{\pgfmathresult}
253 \clip (0,0) rectangle (\b,\h);
254 \fill [blue] (0,0) rectangle (\b,\h);
255 \draw [white,line width=\lws] (0,\h)--(\b,0) (0,0)--(\b,\h);
256 \begin{scope}[rotate around={\winkel:(\b/2,\h/2)}]
257 \draw [red,line width=\lws/3,yshift=\lws/6] (0.5\b,0.5\h)--++(0:0.701\b);
258 \draw [red,line width=\lws/3,yshift=-\lws/6] (0.5\b,0.5\h)--++(180:0.701\b);
259 \end{scope}
260 \begin{scope}[rotate around={-\winkel:(\b/2,\h/2)}]
261 \draw [red,line width=\lws/3,yshift=\lws/6] (0.5\b,0.5\h)--++(0:0.701\b);
262 \draw [red,line width=\lws/3,yshift=-\lws/6] (0.5\b,0.5\h)--++(180:0.701\b);
263 \end{scope}
264 \draw [white,line width=\lwb] (-0.5\b,\h/2)--(1.5\b,\h/2) (\b/2,-\h)--(\b/2,2\h);
265 \draw [red,line width=\lws] (-0.5\b,\h/2)--(1.5\b,\h/2) (\b/2,-\h)--(\b/2,2\h);
266 \end{scope}}
267
268 % ----------------------------------------------------------------------------
269 % Key Management
270 % ----------------------------------------------------------------------------
271 \define@key{worldflag}{variant}{\def\flagvariant{#1}} % 2022-07-09
272 \define@key{worldflag}{length}{\flaglength#1}
273 \define@key{worldflag}{width}{\flagwidth#1}
274 \define@key{worldflag}{framewidth}{\flagframe#1}
275 \define@key{worldflag}{framecolor}{\def\framecolor{#1}}
276 \define@key{worldflag}{emblem}[true]{\emblemtrue\noemblemfalse}
277 \define@key{worldflag}{noemblem}[true]{\noemblemtrue\emblemfalse}
278 \define@key{worldflag}{emblemdefault}[true]{\noemblemtrue\emblemtrue}
279 \define@key{worldflag}{grid}[black!80]{\gridtrue\def\gr@dcolor{#1}}
280 \define@key{worldflag}{stretch}[1]{\def\flagstretch{#1}}
281 \define@key{worldflag}{turn}[1]{\def\viewangle{#1}}
282 \define@key{worldflag}{hang}[1]{\def\hangangle{#1}}
283
284 \define@key{flagsdefault}{variant}{\def\fl@gvariant{#1}} % 2022-07-09
285 \define@key{flagsdefault}{length}{\fl@glength#1}
286 \define@key{flagsdefault}{width}{\fl@gwidth#1}
287 \define@key{flagsdefault}{framewidth}{\fl@gframe#1}
288 \define@key{flagsdefault}{framecolor}{\def\fr@mecolor{#1}}
289 \define@key{flagsdefault}{emblem}[true]{\@mbl@mtrue\n@@mbl@mfalse}
290 \define@key{flagsdefault}{noemblem}[true]{\n@@mbl@mtrue\@mbl@mfalse}
291 \define@key{flagsdefault}{emblemdefault}[true]{\n@@mbl@mtrue\@mbl@mtrue}
292 \define@key{flagsdefault}{grid}[black!80]{\@ridtrue\def\gr@dcolor{#1}}
293 \define@key{flagsdefault}{stretch}[1]{\def\fl@gstretch{#1}}
294 \define@key{flagsdefault}{turn}[1]{\def\view@ngle{#1}}
295 \define@key{flagsdefault}{hang}[1]{\def\hang@ngle{#1}}
296
297 % ----------------------------------------------------------------------------
298 % flagsdefault - setting default values
299 % ----------------------------------------------------------------------------
300 \def\flagsdefault{\@ifnextchar[\@flagsdefault{\@flagsdefault[]}}
301 \def\@flagsdefault[#1]{\setkeys{flagsdefault}{#1}}
302
303 % ----------------------------------------------------------------------------
304 % worldflag (as tikzpicture)
305 % ----------------------------------------------------------------------------
306 \def\worldflag{\@ifnextchar[\@worldflag{\@worldflag[]}}%
307 \def\@worldflag[#1]#2{%
308 \def\framecolor{\fr@mecolor}%
309 \newdimen\flagwidth\flagwidth=\fl@gwidth
310 \newdimen\flaglength\flaglength=\fl@glength
311 \newdimen\flagframe\flagframe=\fl@gframe
312 \def\flagstretch{\fl@gstretch}%
313 \def\flagvariant{\fl@gvariant}% 2022-07-009
314 \newif\ifgrid\if@rid\gridtrue\else\gridfalse\fi
315 \newif\ifemblem\if@mbl@m\emblemtrue\else\emblemfalse\fi
316 \newif\ifnoemblem\ifn@@mbl@m\noemblemtrue\else\noemblemfalse\fi
317 \def\viewangle{0}%
318 \def\hangangle{0}%
319 \setkeys{worldflag}{#1}%
320 \IfFileExists{worldflag_#2.tex}{%
321 \begin{tikzpicture} % [opacity=0.3] % zum Testen
322 \input{worldflag_#2.tex}
323 \end{tikzpicture}}{\relax}
324 }
325
326 % ----------------------------------------------------------------------------
327 % worldflag (as pic)
328 % ----------------------------------------------------------------------------
329 \tikzset{length/.style={execute at begin scope={\newdimen\flaglength\flaglength=#1}}}
330 \tikzset{width/.style={execute at begin scope={\newdimen\flagwidth\flagwidth=#1}}}
331 \tikzset{framewidth/.style={execute at begin scope={\newdimen\flagframe\flagframe=#1}}}
332 \tikzset{stretch/.style={execute at begin scope={\def\flagstretch{#1}}}}
333 \tikzset{framecolor/.style={execute at begin scope={\def\framecolor{#1}}}}
334 \tikzset{country/.style={execute at begin scope={\def\country{#1}}}}
335 \tikzset{variant/.style={execute at begin scope={\def\flagvariant{#1}}}} % 2022-07-09
336 \tikzset{emblem/.style={execute at begin scope={\newif\ifemblem\emblemtrue\newif\ifnoemblem\noemblemfalse}}}
337 \tikzset{grid/.style={execute at begin scope={\newif\ifgrid\gridtrue}}}
338 \tikzset{noemblem/.style={execute at begin scope={\newif\ifnoemblem\noemblemtrue}}}
339 \tikzset{emblemdefault/.style={execute at begin scope={\newif\ifnoemblem\noemblemtrue\newif\ifemblem\emblemtrue}}}
340 \tikzset{turn/.style={execute at begin scope={\def\viewangle{#1}}}}
341 \tikzset{hang/.style={execute at begin scope={\def\hangangle{#1}}}}
342 \tikzset{
343 worldflag/.pic={
344 \ifx\flagwidth\undefined\newdimen\flagwidth\global\flagwidth=\fl@gwidth\fi
345 \ifx\flaglength\undefined\newdimen\flaglength\global\flaglength=\fl@glength\fi
346 \ifx\flagframe\undefined\newdimen\flagframe\global\flagframe=\fl@gframe\fi
347 \ifx\flagstretch\undefined\def\flagstretch{\fl@gstretch}\fi
348 \ifx\flagvariant\undefined\def\flagvariant{\fl@gvariant}\fi % 2022-07-09
349 \ifx\framecolor\undefined\def\framecolor{\fr@mecolor}\fi
350 \def\makeifgrid{\newif\ifgrid\if@rid\gridtrue\else\gridfalse\fi}
351 \ifx\ifgrid\undefined\makeifgrid\fi
352 \def\makeifemblem{\newif\ifemblem\if@mbl@m\emblemtrue\else\emblemfalse\fi}
353 \ifx\ifemblem\undefined\makeifemblem\fi
354 \def\makeifnoemblem{\newif\ifnoemblem\ifn@@mbl@m\noemblemtrue\else\noemblemfalse\fi}
355 \ifx\ifnoemblem\undefined\makeifnoemblem\fi
356 \ifx\viewangle\undefined\def\viewangle{\view@ngle}\fi
357 \ifx\hangangle\undefined\def\hangangle{\hang@ngle}\fi
358 \IfFileExists{worldflag_\country.tex}{\input{worldflag_\country.tex}}{\relax}
359 }
360 }
361
362 % ----------------------------------------------------------------------------
363 % Colors for Signal Flags
364 % ----------------------------------------------------------------------------
365 \def\SignalFlagColorDefinitions{%
366 % \definecolor{red}{RGB}{167,41,33}
367 \definecolor{gold}{RGB}{255,230,0}
368 % \definecolor{green}{RGB}{54,103,53}
369 % \definecolor{blue}{RGB}{25,49,83}
370 % \definecolor{white}{RGB}{233,224,210}
371 \definecolor{red}{RGB}{220,0,0}
372 \definecolor{blue}{RGB}{0,0,210}
373 }