5 | 5 |
extern crate rrecutils;
|
6 | 6 |
extern crate rsvg;
|
7 | 7 |
|
| 8 |
mod markup;
|
| 9 |
|
8 | 10 |
use std::{fs,io};
|
9 | |
use pango::LayoutExt;
|
10 | 11 |
use rsvg::HandleExt;
|
11 | 12 |
|
12 | 13 |
const SCALE: i32 = 3;
|
|
128 | 129 |
}
|
129 | 130 |
}
|
130 | 131 |
|
131 | |
|
132 | |
|
133 | 132 |
fn draw_card(card: &Card) -> Result<(), failure::Error> {
|
134 | 133 |
use CardType::*;
|
135 | 134 |
|
|
153 | 152 |
ctx.stroke();
|
154 | 153 |
|
155 | 154 |
ctx.set_source_rgb(0.0, 0.0, 0.0);
|
156 | |
let layout = pangocairo::functions::create_layout(&ctx)
|
157 | |
.ok_or(format_err!("Unable to create Pango layout"))?;
|
158 | |
let mut font = pango::FontDescription::from_string("Fira Sans 12");
|
159 | |
font.set_weight(pango::Weight::Bold);
|
160 | |
layout.set_font_description(&font);
|
161 | 155 |
|
162 | 156 |
ctx.move_to(100.0, 8.0);
|
163 | |
let title = match card.card_type {
|
| 157 |
let mut buf = markup::MarkupBuffer::new();
|
| 158 |
|
| 159 |
match card.card_type {
|
164 | 160 |
Weapon { ref weapon_type, .. } =>
|
165 | |
format!("{} (Weapon, {:?})", card.name, weapon_type),
|
| 161 |
buf.push(&format!("{} (Weapon, {:?})", card.name, weapon_type)),
|
166 | 162 |
Monster { ref hp, ref melee, ref ranged, ref arcane, ref defense, .. } => {
|
167 | |
let mut buf = String::new();
|
168 | |
buf.push_str(&format!(
|
169 | |
"{} (Beast <span font='8' font_weight='heavy'>HP</span>{}",
|
170 | |
card.name,
|
171 | |
hp,
|
172 | |
));
|
| 163 |
buf.push(&format!("{} (Beast ", card.name));
|
| 164 |
|
| 165 |
buf.markup().size(8).weight("heavy").push("HP");
|
| 166 |
buf.push(&format!("{}", hp));
|
| 167 |
|
173 | 168 |
if let &Some(ref m) = melee {
|
174 | |
buf.push_str(&format!(" <span font='8' font_weight='heavy'>M</span>{}", m));
|
175 | |
}
|
| 169 |
buf.space();
|
| 170 |
buf.markup().size(8).weight("heavy").push("M");
|
| 171 |
buf.push(m);
|
| 172 |
}
|
| 173 |
|
176 | 174 |
if let &Some(ref m) = ranged {
|
177 | |
buf.push_str(&format!(" <span font='8' font_weight='heavy'>R</span>{}", m));
|
178 | |
}
|
| 175 |
buf.space();
|
| 176 |
buf.markup().size(8).weight("heavy").push("R");
|
| 177 |
buf.push(m);
|
| 178 |
}
|
| 179 |
|
179 | 180 |
if let &Some(ref m) = arcane {
|
180 | |
buf.push_str(&format!(" <span font='8' font_weight='heavy'>A</span>{}", m));
|
181 | |
}
|
| 181 |
buf.space();
|
| 182 |
buf.markup().size(8).weight("heavy").push("A");
|
| 183 |
buf.push(m);
|
| 184 |
}
|
| 185 |
|
182 | 186 |
if let &Some(ref m) = defense {
|
183 | |
buf.push_str(&format!(" <span font='8' font_weight='heavy'>D</span>{}", m));
|
184 | |
}
|
185 | |
buf.push_str(")");
|
186 | |
buf
|
| 187 |
buf.space();
|
| 188 |
buf.markup().size(8).weight("heavy").push("D");
|
| 189 |
buf.push(m);
|
| 190 |
}
|
| 191 |
buf.push(")");
|
187 | 192 |
}
|
188 | |
Generic { ref kind, .. } => format!("{} ({:?})", card.name, kind),
|
| 193 |
Generic { ref kind, .. } =>
|
| 194 |
buf.push(&format!("{} ({:?})", card.name, kind)),
|
189 | 195 |
};
|
190 | 196 |
|
191 | |
let (attrs, text, _) = pango::parse_markup(&title, '\0')?;
|
192 | |
layout.set_attributes(&attrs);
|
193 | |
layout.set_text(&text);
|
194 | |
pangocairo::functions::show_layout(&ctx, &layout);
|
| 197 |
buf.show_with_font(&ctx, markup::title_font(), None)?;
|
195 | 198 |
|
196 | 199 |
ctx.move_to(115.0, 26.0);
|
197 | |
let layout = pangocairo::functions::create_layout(&ctx)
|
198 | |
.ok_or(format_err!("Unable to create Pango layout"))?;
|
199 | |
layout.set_width((390 - 115) * pango::SCALE);
|
200 | |
let mut font = pango::FontDescription::from_string("Fira Sans 10");
|
201 | |
font.set_weight(pango::Weight::Normal);
|
202 | |
layout.set_font_description(&font);
|
203 | |
|
204 | |
let (attrs, text, _) = {
|
205 | |
let mut buf = String::new();
|
206 | |
match card.card_type {
|
207 | |
Weapon { ability, effect, .. } => {
|
208 | |
buf.push_str("<span font_weight=\"bold\">");
|
209 | |
buf.push_str(ability);
|
210 | |
buf.push_str(":</span> ");
|
211 | |
buf.push_str(effect);
|
212 | |
},
|
213 | |
Monster { action, effect, .. } => {
|
214 | |
buf.push_str("<span font_weight=\"bold\">");
|
215 | |
buf.push_str(action);
|
216 | |
buf.push_str(":</span> ");
|
217 | |
buf.push_str(effect);
|
218 | |
},
|
219 | |
Generic { effect, .. } => {
|
220 | |
buf.push_str(effect);
|
221 | |
},
|
222 | |
}
|
223 | |
pango::parse_markup(&buf, '\0')?
|
| 200 |
let mut buf = markup::MarkupBuffer::new();
|
| 201 |
|
| 202 |
match card.card_type {
|
| 203 |
Weapon { ability, effect, .. } => {
|
| 204 |
buf.markup().weight("bold").push(&format!("{}: ", ability));
|
| 205 |
buf.push(effect);
|
| 206 |
},
|
| 207 |
Monster { action, effect, .. } => {
|
| 208 |
buf.markup().weight("bold").push(&format!("{}: ", action));
|
| 209 |
buf.push(effect);
|
| 210 |
},
|
| 211 |
Generic { effect, .. } => {
|
| 212 |
buf.push(effect);
|
| 213 |
},
|
224 | 214 |
};
|
225 | 215 |
|
226 | |
layout.set_attributes(&attrs);
|
227 | |
layout.set_text(&text);
|
228 | |
pangocairo::functions::show_layout(&ctx, &layout);
|
| 216 |
buf.show_with_font(&ctx, markup::body_font(), Some(390 - 115))?;
|
229 | 217 |
|
230 | 218 |
let icon = rsvg::Handle::new_from_file(&card.icon)
|
231 | 219 |
.map_err(|_| format_err!("Error loading image: {}", card.icon))?;
|