Skip to content

Commit

Permalink
Remove the drawing modes
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Oct 18, 2023
1 parent f32418c commit 1d1f73f
Show file tree
Hide file tree
Showing 172 changed files with 24 additions and 936 deletions.
10 changes: 5 additions & 5 deletions founder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ repository = "https://github.com/bodoni/workbench/tree/main/founder"
exclude = ["tests/fixtures/*"]

[features]
default = ["bin"]
bin = ["arguments", "colored", "resvg"]
default = ["binary"]
binary = ["arguments", "colored", "resvg"]

[[bin]]
name = "founder"
Expand All @@ -21,17 +21,17 @@ path = "src/bin/main.rs"
[[bin]]
name = "founder-rasterize"
path = "src/bin/rasterize.rs"
required-features = ["bin"]
required-features = ["binary"]

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

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

[dependencies]
folder = "0.5"
Expand Down
34 changes: 8 additions & 26 deletions founder/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,11 @@ test-vectorize:
--workers "$$((4 * $$(nproc --all)))" \
> /dev/null

.PHONY: test-vectorize-selected-free
test: test-vectorize-selected-free
test-vectorize-selected-free:
rm -rf tests/fixtures/vectorize/free
cp -R tests/fixtures/fonts tests/fixtures/vectorize/free
cargo run --bin founder-vectorize -- --path tests/fixtures/vectorize/free --mode free
rm tests/fixtures/vectorize/free/*.{otf,ttf}
[ "$$(git diff tests/fixtures/vectorize/free | wc -l | xargs)" = 0 ] || exit 1

.PHONY: test-vectorize-selected-local
test: test-vectorize-selected-local
test-vectorize-selected-local:
rm -rf tests/fixtures/vectorize/local
cp -R tests/fixtures/fonts tests/fixtures/vectorize/local
cargo run --bin founder-vectorize -- --path tests/fixtures/vectorize/local --mode local
rm tests/fixtures/vectorize/local/*.{otf,ttf}
[ "$$(git diff tests/fixtures/vectorize/local | wc -l | xargs)" = 0 ] || exit 1

.PHONY: test-vectorize-selected-global
test: test-vectorize-selected-global
test-vectorize-selected-global:
rm -rf tests/fixtures/vectorize/global
cp -R tests/fixtures/fonts tests/fixtures/vectorize/global
cargo run --bin founder-vectorize -- --path tests/fixtures/vectorize/global --mode global
rm tests/fixtures/vectorize/global/*.{otf,ttf}
[ "$$(git diff tests/fixtures/vectorize/global | wc -l | xargs)" = 0 ] || exit 1
.PHONY: test-vectorize-selected
test: test-vectorize-selected
test-vectorize-selected:
rm -rf tests/fixtures/vectorize
cp -R tests/fixtures/fonts tests/fixtures/vectorize
cargo run --bin founder-vectorize -- --path tests/fixtures/vectorize
rm tests/fixtures/vectorize/*.{otf,ttf}
[ "$$(git diff tests/fixtures/vectorize | wc -l | xargs)" = 0 ] || exit 1
11 changes: 3 additions & 8 deletions founder/src/bin/vectorize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,27 @@ fn main() {
let characters = arguments
.get::<String>("characters")
.unwrap_or_else(|| "BESbswy".to_string());
let mode = arguments
.get::<String>("mode")
.unwrap_or_else(|| "global".to_string());
let excludes = arguments.get_all::<String>("exclude").unwrap_or(vec![]);
let excludes = excludes.iter().map(String::as_str).collect::<Vec<_>>();
support::summarize(
&folder::scan(
&path,
|path| support::filter(path, &[".otf", ".ttf"], &excludes),
process,
(characters, mode),
characters,
arguments.get::<usize>("workers").unwrap_or(1),
)
.collect::<Vec<_>>(),
);
}

fn process(path: &Path, (characters, mode): (String, String)) -> Result<Option<()>> {
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, &mode) {
match subprocess(path, &characters, DOCUMENT_SIZE, MARGIN_SIZE) {
Ok(results) => {
let mut option = None;
for (character, document) in results
Expand Down Expand Up @@ -75,7 +72,6 @@ fn subprocess(
characters: &str,
document_size: f32,
margin_size: f32,
mode: &str,
) -> Result<Vec<(char, Option<element::SVG>)>> {
use font::File;

Expand Down Expand Up @@ -103,7 +99,6 @@ fn subprocess(
&metrics,
reference,
document_size - 2.0 * margin_size,
mode,
);
let transform = format!(
"translate({margin_size} {margin_size}) scale({scale}) translate({x} {y}) scale(1 -1)",
Expand Down
37 changes: 8 additions & 29 deletions founder/src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,16 @@ pub fn draw(glyph: &Glyph) -> element::Group {

pub fn transform(
glyph: &Glyph,
metrics: &Metrics,
_: &Metrics,
reference: &Glyph,
document_size: Number,
mode: &str,
) -> (Number, Number, Number) {
let (x, y, scale);
match mode {
"free" => {
let (left, bottom, right, top) = glyph.bounding_box;
let glyph_size = (right - left).max(top - bottom);
scale = document_size / glyph_size;
x = -left + (glyph_size - (right - left)) / 2.0;
y = top + (glyph_size - (top - bottom)) / 2.0;
}
"local" => {
let (left, _, right, _) = glyph.bounding_box;
let glyph_size = metrics.ascender - metrics.descender;
scale = document_size / glyph_size;
x = -glyph.side_bearings.0 + (glyph_size - (right - left)) / 2.0;
y = metrics.ascender;
}
"global" => {
const BASELINE: Number = 0.75;
const MULTIPLIER: Number = 1.75;
let (left, _, right, _) = glyph.bounding_box;
let glyph_size = MULTIPLIER * reference.bounding_box.3;
scale = document_size / glyph_size;
x = -glyph.side_bearings.0 + (glyph_size - (right - left)) / 2.0;
y = BASELINE * glyph_size;
}
_ => unreachable!(),
}
const BASELINE: Number = 0.75;
const MULTIPLIER: Number = 1.75;
let (left, _, right, _) = glyph.bounding_box;
let glyph_size = MULTIPLIER * reference.bounding_box.3;
let scale = document_size / glyph_size;
let x = -glyph.side_bearings.0 + (glyph_size - (right - left)) / 2.0;
let y = BASELINE * glyph_size;
(x, y, scale)
}
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Loading

0 comments on commit 1d1f73f

Please sign in to comment.