Skip to content

Commit

Permalink
Make terminal error only on mandatory bases
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Nov 28, 2024
1 parent 035ec79 commit fedbe0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions shaperglot-lib/src/checks/codepoint_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct CodepointCoverage {
strings: HashSet<String>,
/// The unique code to return on failure (e.g. "marks-missing")
code: String,
/// Whether to mark the problem as terminal if no codepoints are found
terminal_if_empty: bool,
}

fn can_shape(text: &str, face: &Face) -> bool {
Expand Down Expand Up @@ -53,7 +55,7 @@ impl CheckImplementation for CodepointCoverage {
missing_things.join(", ")
),
);
if missing_things.len() == self.strings.len() {
if missing_things.len() == self.strings.len() && self.terminal_if_empty {
fail.terminal = true;
}
fail.context = json!({"glyphs": missing_things});
Expand All @@ -76,10 +78,11 @@ impl CheckImplementation for CodepointCoverage {

impl CodepointCoverage {
/// Create a new `CodepointCoverage` check implementation
pub fn new(test_strings: Vec<String>, code: String) -> Self {
pub fn new(test_strings: Vec<String>, code: String, terminal_if_empty: bool) -> Self {
Self {
strings: test_strings.into_iter().collect(),
code,
terminal_if_empty,
}
}
}
3 changes: 3 additions & 0 deletions shaperglot-lib/src/providers/orthographies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn mandatory_orthography(language: &Language) -> Check {
implementations: vec![CheckType::CodepointCoverage(CodepointCoverage::new(
language.bases.clone(),
"base".to_string(),
true,
))],
};
let marks: Vec<String> = language.marks.iter().map(|s| s.replace("◌", "")).collect();
Expand All @@ -68,6 +69,7 @@ fn mandatory_orthography(language: &Language) -> Check {
.push(CheckType::CodepointCoverage(CodepointCoverage::new(
marks,
"mark".to_string(),
false,
)));
}
let complex_bases: Vec<ShapingInput> = language
Expand Down Expand Up @@ -128,6 +130,7 @@ fn auxiliaries_check(language: &Language) -> Option<Check> {
.push(CheckType::CodepointCoverage(CodepointCoverage::new(
vec![codepoint.clone()],
"auxiliary".to_string(),
false,
)));
}
// If auxiliary exemplars contain marks, they SHOULD NOT be orphaned.
Expand Down

0 comments on commit fedbe0c

Please sign in to comment.