Skip to content

Commit 4a8fd0b

Browse files
Better implementation (#73)
* add * Update lib.rs * Got it working * Remove * Update lib.rs * Update lib.rs * Update lib.rs * Revert "Remove" This reverts commit d82fa8c. * Reapply "Remove" This reverts commit c707673. * Update lib.rs
1 parent fac8940 commit 4a8fd0b

File tree

1 file changed

+20
-36
lines changed

1 file changed

+20
-36
lines changed

src/rust/lib.rs

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -259,46 +259,30 @@ fn svg_to_bytes(
259259
}
260260
}
261261
let os = std::env::consts::OS;
262+
263+
let none_or_take = |item:Option<String>,otherwise:&str|{
264+
if item.is_none(){
265+
Some(otherwise.to_owned())
266+
}else{
267+
item
268+
}
269+
};
262270
match os {
263271
"windows" | "macos" => {
264-
if font_family.is_none() {
265-
font_family = Some("Times New Roman".to_owned());
266-
}
267-
if serif_family.is_none() {
268-
serif_family = Some("Times New Roman".to_owned());
269-
}
270-
if sans_serif_family.is_none() {
271-
sans_serif_family = Some("Arial".to_owned());
272-
}
273-
if cursive_family.is_none() {
274-
cursive_family = Some("Comic Sans MS".to_owned());
275-
}
276-
if fantasy_family.is_none() {
277-
fantasy_family = Some("Impact".to_owned());
278-
}
279-
if monospace_family.is_none() {
280-
monospace_family = Some("Courier New".to_owned());
281-
}
272+
font_family = none_or_take(font_family, "Times New Roman");
273+
serif_family = none_or_take(serif_family, "Times New Roman");
274+
sans_serif_family = none_or_take(sans_serif_family, "Arial");
275+
cursive_family = none_or_take(cursive_family, "Comic Sans MS");
276+
fantasy_family = none_or_take(fantasy_family, "Impact");
277+
monospace_family = none_or_take(monospace_family, "Courier New");
282278
}
283279
"linux" => {
284-
if font_family.is_none() {
285-
font_family = Some("Liberation Serif".to_owned());
286-
}
287-
if serif_family.is_none() {
288-
serif_family = Some("Liberation Serif".to_owned());
289-
}
290-
if sans_serif_family.is_none() {
291-
sans_serif_family = Some("Liberation Sans".to_owned());
292-
}
293-
if cursive_family.is_none() {
294-
cursive_family = Some("Comic Neue".to_owned());
295-
}
296-
if fantasy_family.is_none() {
297-
fantasy_family = Some("Anton".to_owned());
298-
}
299-
if monospace_family.is_none() {
300-
monospace_family = Some("Liberation Mono".to_owned());
301-
}
280+
font_family = none_or_take(font_family, "Liberation Serif");
281+
serif_family = none_or_take(serif_family, "Liberation Serif");
282+
sans_serif_family = none_or_take(sans_serif_family, "Liberation Sans");
283+
cursive_family = none_or_take(cursive_family, "Comic Neue");
284+
fantasy_family = none_or_take(fantasy_family, "Anton");
285+
monospace_family = none_or_take(monospace_family, "Liberation Mono");
302286
}
303287
_ => panic!("Unsupported operating system: {}", os),
304288
}

0 commit comments

Comments
 (0)