bmfont_rs/settings.rs
1/// Font import behavior settings.
2///
3/// This struct specifies Font import behavior, allowing us to import certain partially
4/// broken/ non-compliant BMFont files.
5///
6/// # Example
7///
8/// ```no_run
9/// use std::io;
10/// use std::io::prelude::*;
11/// use std::fs;
12///
13/// fn main() -> bmfont_rs::Result<()> {
14/// let src = fs::read_to_string("font.txt")?;
15/// let settings = bmfont_rs::LoadSettings::default().ignore_counts();
16/// let font = bmfont_rs::text::from_str_ext(&src, &settings)?;
17/// println!("{:?}", font);
18/// Ok(())
19/// }
20/// ```
21#[derive(Debug, Default, Clone, Copy)]
22#[non_exhaustive]
23pub struct LoadSettings {
24 /// Allow String control characters.
25 pub allow_string_control_characters: bool,
26 /// Ignore incorrect character and kerning counts.
27 pub ignore_counts: bool,
28 /// Ignore invalid tags.
29 pub ignore_invalid_tags: bool,
30}
31
32impl LoadSettings {
33 // As we have exhaustive fields, we'll rely on builder type setter functions as opposed to
34 // a 'new' function. This should enable us to add additional fields without breaking the
35 // existing API.
36
37 /// Set ignore_counts to true. Returns self.
38 pub fn ignore_counts(mut self) -> Self {
39 self.ignore_counts = true;
40 self
41 }
42
43 /// Set ignore_invalid_tags to true. Returns self.
44 pub fn ignore_invalid_tags(mut self) -> Self {
45 self.ignore_invalid_tags = true;
46 self
47 }
48
49 /// Set allow_string_control_characters to true. Returns self.
50 pub fn allow_string_control_characters(mut self) -> Self {
51 self.allow_string_control_characters = true;
52 self
53 }
54}