-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
440d664
commit 564e18c
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use std::collections::HashMap; | ||
|
||
use fontspector_checkapi::{constants::GlyphClass, prelude::*, testfont, FileTypeConvert}; | ||
use read_fonts::TableProvider; | ||
use skrifa::{GlyphId, MetadataProvider}; | ||
use unicode_properties::{GeneralCategory, UnicodeGeneralCategory}; | ||
|
||
fn is_space(c: char) -> bool { | ||
matches!( | ||
c.general_category(), | ||
GeneralCategory::SpaceSeparator | ||
| GeneralCategory::LineSeparator | ||
| GeneralCategory::ParagraphSeparator | ||
| GeneralCategory::Format | ||
| GeneralCategory::NonspacingMark | ||
| GeneralCategory::Control | ||
) | ||
} | ||
|
||
#[check( | ||
id = "base_has_width", | ||
rationale = "Base characters should have non-zero advance width.", | ||
proposal = "Rod on chat", | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
simoncozens
Author
Owner
|
||
title = "Check base characters have non-zero advance width." | ||
)] | ||
fn base_has_width(f: &Testable, context: &Context) -> CheckFnResult { | ||
let font = testfont!(f); | ||
let hmtx = font.font().hmtx()?; | ||
let mut problems = vec![]; | ||
let reverse_charmap: HashMap<_, _> = font | ||
.font() | ||
.charmap() | ||
.mappings() | ||
.map(|(c, g)| (g, c)) | ||
.collect(); | ||
for (gid, metric) in hmtx.h_metrics().iter().enumerate() { | ||
let gid = GlyphId::new(gid as u16); | ||
if metric.advance() == 0 && font.gdef_class(gid) != Some(GlyphClass::Mark) { | ||
let codepoint = reverse_charmap.get(&gid); | ||
if codepoint == Some(&0) || codepoint.is_none() { | ||
continue; | ||
} | ||
if codepoint | ||
.and_then(|c| char::from_u32(*c)) | ||
.map_or(false, is_space) | ||
{ | ||
continue; | ||
} | ||
#[allow(clippy::unwrap_used)] | ||
let name = font.glyph_name_for_id(gid, true).unwrap(); | ||
if name == "NULL" { | ||
continue; | ||
} | ||
problems.push(format!("{} ({:?})", name, codepoint)); | ||
} | ||
} | ||
if problems.is_empty() { | ||
Ok(Status::just_one_pass()) | ||
} else { | ||
Ok(Status::just_one_fail( | ||
"zero-width-bases", | ||
&format!( | ||
"The following glyphs had zero advance width:\n{}", | ||
bullet_list(context, problems), | ||
), | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
That's funny :-P
I'd rather open an issue, describe in more detail what was the context of the conversation and then add the issue URL here.