Skip to main content

bymsdfgen_core/generator/
config.rs

1//! Generator and error-correction configuration. Port of `generator-config.h`.
2
3/// Error-correction mode of operation.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum ErrorCorrectionMode {
6    /// Skip the error-correction pass.
7    Disabled,
8    /// Correct all discontinuities regardless of edge impact.
9    Indiscriminate,
10    /// Correct artifacts only when edges/corners are not affected.
11    EdgePriority,
12    /// Only correct artifacts at edges.
13    EdgeOnly,
14}
15
16/// Whether to compute exact shape distance at suspected artifacts.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum DistanceCheckMode {
19    DoNotCheckDistance,
20    CheckDistanceAtEdge,
21    AlwaysCheckDistance,
22}
23
24pub const DEFAULT_MIN_DEVIATION_RATIO: f64 = 1.111_111_111_111_111_1;
25pub const DEFAULT_MIN_IMPROVE_RATIO: f64 = 1.111_111_111_111_111_1;
26
27/// Configuration of the MSDF error-correction pass.
28#[derive(Debug, Clone, Copy)]
29pub struct ErrorCorrectionConfig {
30    pub mode: ErrorCorrectionMode,
31    pub distance_check_mode: DistanceCheckMode,
32    pub min_deviation_ratio: f64,
33    pub min_improve_ratio: f64,
34}
35
36impl Default for ErrorCorrectionConfig {
37    fn default() -> Self {
38        ErrorCorrectionConfig {
39            mode: ErrorCorrectionMode::EdgePriority,
40            distance_check_mode: DistanceCheckMode::CheckDistanceAtEdge,
41            min_deviation_ratio: DEFAULT_MIN_DEVIATION_RATIO,
42            min_improve_ratio: DEFAULT_MIN_IMPROVE_RATIO,
43        }
44    }
45}
46
47/// Configuration of the distance-field generator.
48#[derive(Debug, Clone, Copy)]
49pub struct GeneratorConfig {
50    /// Use the overlapping-contour-aware algorithm.
51    pub overlap_support: bool,
52}
53
54impl Default for GeneratorConfig {
55    fn default() -> Self {
56        GeneratorConfig {
57            overlap_support: true,
58        }
59    }
60}
61
62/// Configuration of the multi-channel generator (adds error correction).
63#[derive(Debug, Clone, Copy)]
64pub struct MsdfGeneratorConfig {
65    pub overlap_support: bool,
66    pub error_correction: ErrorCorrectionConfig,
67}
68
69impl Default for MsdfGeneratorConfig {
70    fn default() -> Self {
71        MsdfGeneratorConfig {
72            overlap_support: true,
73            error_correction: ErrorCorrectionConfig::default(),
74        }
75    }
76}
77
78impl MsdfGeneratorConfig {
79    pub fn new(overlap_support: bool, error_correction: ErrorCorrectionConfig) -> Self {
80        MsdfGeneratorConfig {
81            overlap_support,
82            error_correction,
83        }
84    }
85}