Skip to content

Commit

Permalink
Add a command for listing features
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed May 20, 2024
1 parent cc6cff8 commit a05d6ec
Show file tree
Hide file tree
Showing 14 changed files with 504 additions and 28 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ binary = ["arguments", "colored", "resvg"]
name = "founder"
path = "src/bin/main.rs"

[[bin]]
name = "founder-feature"
path = "src/bin/feature.rs"
required-features = ["binary"]

[[bin]]
name = "founder-name"
path = "src/bin/name.rs"
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ all: test
.PHONY: test
test:

.PHONY: test-feature-internal
test: test-feature-internal
test-feature-internal:
cargo run --bin founder-feature -- \
--path tests/fixtures/internal
rm -rf tests/fixtures/internal/feature/*
mv tests/fixtures/internal/fonts/*.txt tests/fixtures/internal/feature
[ "$$(git diff tests/fixtures/internal/feature | wc -l | xargs)" = 0 ] || exit 1

.PHONY: test-name-internal
test: test-name-internal
test-name-internal:
Expand Down
72 changes: 72 additions & 0 deletions src/bin/feature.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
mod support;

use std::io::Result;
use std::path::{Path, PathBuf};

use colored::Colorize;
use font::opentype::truetype::Tag;

fn main() {
let arguments = arguments::parse(std::env::args()).unwrap();
let path: PathBuf = arguments
.get::<String>("path")
.unwrap_or_else(|| ".".to_string())
.into();
let excludes = arguments.get_all::<String>("exclude").unwrap_or_default();
let excludes = excludes.iter().map(String::as_str).collect::<Vec<_>>();
support::summarize(
&folder::scan(
&path,
|path| support::filter(path, &[".otf", ".ttf"], &excludes),
process,
(),
arguments.get::<usize>("workers"),
)
.collect::<Vec<_>>(),
);
}

fn process(path: &Path, _: ()) -> Result<Option<()>> {
use std::io::Write;

match subprocess(path) {
Ok(result) => {
{
let path = path
.parent()
.unwrap()
.join(path.file_stem().unwrap())
.with_extension("txt");
let mut file = std::fs::File::create(path)?;
write!(file, "{result}")?;
}
eprintln!("{} {path:?}", "[success]".green());
Ok(Some(()))
}
Err(error) => {
eprintln!("{} {path:?} ({error:?})", "[failure]".red());
Err(error)
}
}
}

fn subprocess(path: &Path) -> Result<String> {
use std::fmt::Write;

let font::File { mut fonts } = font::File::open(path)?;
let mut string = String::new();
for (feature, value) in fonts[0].features()? {
let feature = Tag::from(feature);
let feature = feature.as_str().unwrap_or("<none>");
for (script, value) in value.scripts {
let script = Tag::from(script);
let script = script.as_str().unwrap_or("<none>");
for language in value {
let language = language.map(Tag::from);
let language = language.as_ref().and_then(Tag::as_str).unwrap_or("<none>");
writeln!(string, "{feature: <10} {script: <10} {language}").unwrap();
}
}
}
Ok(string)
}
11 changes: 2 additions & 9 deletions src/bin/name.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
mod support;

extern crate arguments;
extern crate colored;
extern crate folder;
extern crate founder;

use std::io::Result;
use std::path::{Path, PathBuf};

Expand All @@ -31,7 +26,6 @@ fn main() {
}

fn process(path: &Path, _: ()) -> Result<Option<()>> {
use std::fs::File;
use std::io::Write;

match subprocess(path) {
Expand All @@ -42,7 +36,7 @@ fn process(path: &Path, _: ()) -> Result<Option<()>> {
.unwrap()
.join(path.file_stem().unwrap())
.with_extension("txt");
let mut file = File::create(path)?;
let mut file = std::fs::File::create(path)?;
write!(file, "{result}")?;
}
eprintln!("{} {path:?}", "[success]".green());
Expand All @@ -56,10 +50,9 @@ fn process(path: &Path, _: ()) -> Result<Option<()>> {
}

fn subprocess(path: &Path) -> Result<String> {
use font::File;
use std::fmt::Write;

let File { mut fonts } = File::open(path)?;
let font::File { mut fonts } = font::File::open(path)?;
let mut string = String::new();
let table = fonts[0].names()?;
let table = table.borrow();
Expand Down
6 changes: 0 additions & 6 deletions src/bin/rasterize.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
mod support;

extern crate arguments;
extern crate colored;
extern crate folder;
extern crate founder;
extern crate resvg;

use std::io::Result;
use std::path::{Path, PathBuf};

Expand Down
19 changes: 6 additions & 13 deletions src/bin/vectorize.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
mod support;

extern crate arguments;
extern crate colored;
extern crate folder;
extern crate founder;

use std::io::Result;
use std::path::{Path, PathBuf};

use colored::Colorize;
use svg::node::element;
use svg::Document;

const DOCUMENT_SIZE: f32 = 512.0;
const MARGIN_SIZE: f32 = 8.0;
const REFERENCES: &[char; 2] = &['X', '0'];

fn main() {
let arguments = arguments::parse(std::env::args()).unwrap();
let path: PathBuf = arguments
Expand All @@ -36,11 +35,8 @@ fn main() {
}

fn process(path: &Path, characters: String) -> Result<Option<()>> {
use std::fs::File;
use std::io::Write;

const DOCUMENT_SIZE: f32 = 512.0;
const MARGIN_SIZE: f32 = 8.0;
match subprocess(path, &characters, DOCUMENT_SIZE, MARGIN_SIZE) {
Ok(results) => {
let mut option = None;
Expand All @@ -53,7 +49,7 @@ fn process(path: &Path, characters: String) -> Result<Option<()>> {
let path = path.parent().unwrap().join(path.file_stem().unwrap());
std::fs::create_dir_all(&path)?;
let path = path.join(character).with_extension("svg");
let mut file = File::create(path)?;
let mut file = std::fs::File::create(path)?;
write!(file, "{document}")?;
option = Some(());
}
Expand All @@ -73,10 +69,7 @@ fn subprocess(
document_size: f32,
margin_size: f32,
) -> Result<Vec<(char, Option<element::SVG>)>> {
use font::File;

const REFERENCES: &[char; 2] = &['X', '0'];
let File { mut fonts } = File::open(path)?;
let font::File { mut fonts } = font::File::open(path)?;
let metrics = fonts[0].metrics()?;
let mut reference = None;
for character in REFERENCES.iter() {
Expand Down
Empty file.
124 changes: 124 additions & 0 deletions tests/fixtures/internal/feature/CrimsonText-Regular.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
case DFLT <none>
case latn <none>
case latn AZE
case latn CAT
case latn CRT
case latn KAZ
case latn MOL
case latn ROM
case latn TAT
case latn TRK
ccmp DFLT <none>
ccmp latn <none>
ccmp latn AZE
ccmp latn CAT
ccmp latn CRT
ccmp latn KAZ
ccmp latn MOL
ccmp latn ROM
ccmp latn TAT
ccmp latn TRK
dlig DFLT <none>
dlig latn <none>
dlig latn AZE
dlig latn CAT
dlig latn CRT
dlig latn KAZ
dlig latn MOL
dlig latn ROM
dlig latn TAT
dlig latn TRK
dnom DFLT <none>
dnom latn <none>
dnom latn AZE
dnom latn CAT
dnom latn CRT
dnom latn KAZ
dnom latn MOL
dnom latn ROM
dnom latn TAT
dnom latn TRK
frac DFLT <none>
frac latn <none>
frac latn AZE
frac latn CAT
frac latn CRT
frac latn KAZ
frac latn MOL
frac latn ROM
frac latn TAT
frac latn TRK
kern DFLT <none>
kern latn <none>
liga DFLT <none>
liga latn <none>
liga latn AZE
liga latn CAT
liga latn CRT
liga latn KAZ
liga latn MOL
liga latn ROM
liga latn TAT
liga latn TRK
locl latn AZE
locl latn CAT
locl latn CRT
locl latn KAZ
locl latn MOL
locl latn ROM
locl latn TAT
locl latn TRK
mark DFLT <none>
mark latn <none>
mkmk DFLT <none>
mkmk latn <none>
numr DFLT <none>
numr latn <none>
numr latn AZE
numr latn CAT
numr latn CRT
numr latn KAZ
numr latn MOL
numr latn ROM
numr latn TAT
numr latn TRK
sinf DFLT <none>
sinf latn <none>
sinf latn AZE
sinf latn CAT
sinf latn CRT
sinf latn KAZ
sinf latn MOL
sinf latn ROM
sinf latn TAT
sinf latn TRK
subs DFLT <none>
subs latn <none>
subs latn AZE
subs latn CAT
subs latn CRT
subs latn KAZ
subs latn MOL
subs latn ROM
subs latn TAT
subs latn TRK
sups DFLT <none>
sups latn <none>
sups latn AZE
sups latn CAT
sups latn CRT
sups latn KAZ
sups latn MOL
sups latn ROM
sups latn TAT
sups latn TRK
zero DFLT <none>
zero latn <none>
zero latn AZE
zero latn CAT
zero latn CRT
zero latn KAZ
zero latn MOL
zero latn ROM
zero latn TAT
zero latn TRK
2 changes: 2 additions & 0 deletions tests/fixtures/internal/feature/Numans-Regular.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kern DFLT <none>
kern latn <none>
29 changes: 29 additions & 0 deletions tests/fixtures/internal/feature/OpenSans-Italic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
liga latn <none>
liga latn MOL
liga latn ROM
lnum latn <none>
lnum latn MOL
lnum latn ROM
locl latn MOL
locl latn ROM
onum latn <none>
onum latn MOL
onum latn ROM
pnum latn <none>
pnum latn MOL
pnum latn ROM
salt latn <none>
salt latn MOL
salt latn ROM
ss01 latn <none>
ss01 latn MOL
ss01 latn ROM
ss02 latn <none>
ss02 latn MOL
ss02 latn ROM
ss03 latn <none>
ss03 latn MOL
ss03 latn ROM
tnum latn <none>
tnum latn MOL
tnum latn ROM
Empty file.
Loading

0 comments on commit a05d6ec

Please sign in to comment.