Skip to main content
← Back to kicad-monkey Rust Docs kicad-monkey Rust Crate API Reference

kicad_monkey_codegen/
text_contract.rs

1//! Record schemas whose parts are the text engine's own contract
2//! (`cad_text_realization::contract`): typify refers to those types instead of
3//! emitting copies.
4use typify::TypeSpaceSettings;
5
6/// `(schema definition, cad_text_realization type)` per record schema.
7const SHAPING_RECORD_TEXT_TYPES: &[(&str, &str)] = &[
8    ("DefaultIgnorablePolicy", "DefaultIgnorablePolicy"),
9    ("FontVariationCoordinate", "FontVariationCoordinate"),
10    ("OpenTypeTag", "OpenTypeTag"),
11    ("Sha256Hex", "Sha256Hex"),
12    ("ShapedGlyph", "ShapedGlyph"),
13    ("ShapingBufferProperties", "ShapingBufferProperties"),
14    ("ShapingClusterLevel", "ShapingClusterLevel"),
15    ("ShapingFeature", "ShapingFeature"),
16    ("ShapingInput", "ShapingInput"),
17    ("TextDirection", "TextDirection"),
18    ("TextSafeInteger", "SafeInteger"),
19];
20const OUTLINE_VECTOR_TEXT_TYPES: &[(&str, &str)] = &[
21    ("FontVariationCoordinate", "FontVariationCoordinate"),
22    ("OpenTypeTag", "OpenTypeTag"),
23    ("OutlineClose", "OutlineClose"),
24    ("OutlineCommand", "OutlineCommand"),
25    ("OutlineCurveTo", "OutlineCurveTo"),
26    ("OutlineLineTo", "OutlineLineTo"),
27    ("OutlineMoveTo", "OutlineMoveTo"),
28    ("OutlineQuadTo", "OutlineQuadTo"),
29    ("Sha256Hex", "Sha256Hex"),
30];
31
32/// Map `schema_name`'s text-engine parts onto `cad_text_realization`; false
33/// when the schema has none.
34pub fn replace_text_contract_types(schema_name: &str, settings: &mut TypeSpaceSettings) -> bool {
35    let types = match schema_name {
36        "ShapingRecord.json" => SHAPING_RECORD_TEXT_TYPES,
37        "OutlineVector.json" => OUTLINE_VECTOR_TEXT_TYPES,
38        _ => return false,
39    };
40    for (schema_type, rust_type) in types {
41        settings.with_replacement(
42            schema_type,
43            format!("::cad_text_realization::{rust_type}"),
44            [].into_iter(),
45        );
46    }
47    true
48}