-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcard-style.cls
172 lines (144 loc) · 5.19 KB
/
card-style.cls
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
\NeedsTeXFormat{LaTeX2e}[2020/10/01]
\ProvidesClass{card-style}
[2023/08/25 v0.01]
\LoadClass[DIV=21, fontsize=7.5pt]{scrartcl}
\KOMAoptions{paper=63mm:88mm, DIV=21, fontsize=7.5pt}
\RequirePackage{xcolor}
\RequirePackage{fontspec}
\RequirePackage{mathtools}
\RequirePackage{tikz}
\RequirePackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math}
\RequirePackage{multicol}
\RequirePackage{xparse}
\RequirePackage[left=4mm, right=4mm, top=4mm, bottom=4mm]{geometry}
\RequirePackage[implicit=false]{hyperref}
\RequirePackage{bookmark}
\usetikzlibrary{svg.path}
\usetikzlibrary{fit}
\usetikzlibrary{backgrounds}
\input{fonts.tex}
\input{symbols.tex}
\input{card-filter.tex}
\setlength\parindent{0pt} % todo: avoid in favor of some komascript feature
\setlength\parskip{4pt} % todo: avoid in favor of some komascript feature
\addtokomafont{section}{\normalfont\postamt}
\addtokomafont{subsection}{\normalfont\mittelschrift}
% move the card headings higher (into the page border?)
% TODO: don't hardcode the beforeskip like this here, it's currently calculated as
% 2*(baselineskip in section heading)-(baselineskip before section heading)
% to typeset it as if there was no content beforehand
\RedeclareSectionCommand[runin=false, afterindent=false, beforeskip=-16.91999pt]{section}
\renewcommand*{\sectionformat}{}
\renewcommand*{\subsectionformat}{}
\newcommand{\Category}[1]{\clearpage\bookmark[page=\thepage, level=0]{#1}}
\newcounter{cards}
\input{palette.tex}
\newif\ifCardStyle@shouldDrawBorder
\pgfkeys{
/cardStyle border/.is family, /cardStyle border,
%
shouldDrawBorder/.is if=CardStyle@shouldDrawBorder,
color/.estore in = \cardStyle@borderColor,
color/.append style = shouldDrawBorder,
%
default/.style = {
shouldDrawBorder=false
},
%
type/.is choice,
type/.add code={\ifnum \pdfstrcmp{#1}{}=0\else}{\fi}, % don't do anything for an empty type
%
type/.cd,
Item/.style = {color=accent-blue},
Action/.style = {color=accent-red},
Spell/.style = {color=accent-purple},
Cantrip/.style = {color=accent-purple!40},
Focus/.style = {color=accent-purple!70},
Rule/.style = {color=accent-gray},
Condition/.style = {color=accent-brown},
.unknown/.style = {shouldDrawBorder=false}
}
\newcommand{\cardStyle@drawCardFrame}[1]{%
\pgfkeys{/cardStyle border, default, type=#1}
\ifCardStyle@shouldDrawBorder
\tikz[remember picture,overlay] {%
\draw [color=\cardStyle@borderColor,rounded corners=4mm,line width=4mm]
(current page.north east)
+(-24mm,0mm) coordinate(a)
+(0mm, -2.5mm) coordinate(b)
(current page.north west)
{[rounded corners=0mm]--(a)}
{[rounded corners=1mm]--(a |- b)}
{[rounded corners=0mm]--(b)}
--(current page.south east)
--(current page.south west)
--cycle
(a) -- (current page.north east)
-- +(1mm,0mm);
}
\fi
}
\xdef\cardStyle@currentCardCategory{None}
\AddToHook{shipout/background}{\cardStyle@drawCardFrame{\cardStyle@currentCardCategory}}
% Code to swallow cards that should not be visible
\def\cardStyle@swallowCode#1{%
\ifnum\pdfstrcmp{#1}{card}=0%
\end{card}%
\else
\expandafter\cardStyle@swallowContent
\fi
}
\long\def\cardStyle@swallowContent#1{%
\def\a{#1}%
\def\b{\end}%
\ifx\a\b
\expandafter\cardStyle@swallowCode
\else
\expandafter\cardStyle@swallowContent
\fi
}
% \begin{card}{<card-type>}{<level>}{<title>}[<source-book>][<source-page>]
% ...
% \end{card}
% TODO: make reference mandatory, but we need to define all the references first
\NewDocumentEnvironment{card}{mmmoo}{%
\ifVisible[type=#1, level=#2, title=#3, source book=#4,
collection value=\ifcsname currentValueInCardCollection\endcsname\currentValueInCardCollection\fi]%
%
\clearpage%
%
% Check that last card fitted on one page
\pgfmathparse{int(\value{cards})}
\ifnum\pgfmathresult=0
\pgfmathparse{int(\value{page})}
\xdef\pageOfFirstCard{\pgfmathresult}
\else
\pgfmathparse{int(\value{page} - \pageOfFirstCard - \value{cards})}
\ifnum\pgfmathresult=0
% good
\else
\ClassWarning{card-style}{Previous card defined in \LastCardFilePath\space needed \pgfmathresult\space pages too much}
% make sure remaining cards are not warned against, by pretending there were more cards
\addtocounter{cards}{\pgfmathresult}
\fi
\fi
% store current file in LastCardFilePath, in case it's needed later to produce a better error message
\xdef\LastCardFilePath{\CurrentFilePath/\CurrentFile}
\xdef\cardStyle@currentCardCategory{#1}
\stepcounter{cards}
\bookmark[page=\thepage, level=1]{#3 \ifnum\pdfstrcmp{#2}{}=0\else (#1 #2)\fi}%
\raisebox{0pt}[0pt][0pt]{}%
\hfill\raisebox{1.2em}[0pt][0pt]{\normalfont\color{white}\postamt#1 #2}%
\section{#3 \hfill \IfValueT{#4}{\IfValueT{#5}{\Reference{#4}{#5}}}}%
\else
\expandafter\cardStyle@swallowContent
\fi
}{}
\NewDocumentEnvironment{card-collection}{mmmoomom +b}{%
\edef\temp{\noexpand\foreach\IfValueTF{#7}{[\unexpanded{#7}]}{}}%
\temp#6 in{#8}{\edef\currentValueInCardCollection{#6}\begin{card}{#1}{#2}{#3}[#4][#5]#9\end{card}}%
}%
\pagestyle{empty}
% Prefer underfull over overfull boxes
\pretolerance=150
\tolerance=900