-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mapbox and MapLibre both support SDF icons, sprites that store a signed distance field in their alpha channel. They're not well documented (Mapbox calls them re-colourable images and MapLibre doesn't really mention them) and they're pretty much abandoned as an idea (see the conversation in mapbox/mapbox-gl-style-spec#444). But nevertheless both style specs support them and so Spreet should be able to generate SDF spritesheets. Stadia Maps's sdf_glyph_renderer crate supports signed distance field generation and so we can use that to do the heavy lifting. Although in theory a single spritesheet can mix-and-match SDF sprites with non-SDF sprites, in practice spritesheets tend to include one or the other but not both. And so for now I think it's fine for support to be all-or-nothing: a spritesheet can have all SDF icons, or no SDF icons. If there's demand in the future, we can support mixing.
- Loading branch information
Showing
10 changed files
with
186 additions
and
6 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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 |
---|---|---|
|
@@ -199,6 +199,30 @@ fn spreet_can_output_stretchable_icons() -> Result<(), Box<dyn std::error::Error | |
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn spreet_can_output_sdf_icons() -> Result<(), Box<dyn std::error::Error>> { | ||
let temp = assert_fs::TempDir::new().unwrap(); | ||
|
||
let mut cmd = Command::cargo_bin("spreet")?; | ||
cmd.arg("tests/fixtures/svgs") | ||
.arg(temp.join("sdf@2x")) | ||
.arg("--sdf") | ||
.arg("--retina") | ||
.arg("--recursive") | ||
.assert() | ||
.success(); | ||
|
||
let expected_spritesheet = Path::new("tests/fixtures/output/[email protected]"); | ||
let actual_spritesheet = predicate::path::eq_file(temp.join("[email protected]")); | ||
let expected_index = Path::new("tests/fixtures/output/[email protected]"); | ||
let actual_index = predicate::path::eq_file(temp.join("[email protected]")); | ||
|
||
assert!(actual_spritesheet.eval(expected_spritesheet)); | ||
assert!(actual_index.eval(expected_index)); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn spreet_rejects_non_existent_input_directory() { | ||
let mut cmd = Command::cargo_bin("spreet").unwrap(); | ||
|
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,34 @@ | ||
{ | ||
"another_bicycle": { | ||
"height": 36, | ||
"pixelRatio": 2, | ||
"width": 36, | ||
"x": 84, | ||
"y": 0, | ||
"sdf": true | ||
}, | ||
"bicycle": { | ||
"height": 36, | ||
"pixelRatio": 2, | ||
"width": 36, | ||
"x": 84, | ||
"y": 36, | ||
"sdf": true | ||
}, | ||
"circle": { | ||
"height": 46, | ||
"pixelRatio": 2, | ||
"width": 46, | ||
"x": 0, | ||
"y": 0, | ||
"sdf": true | ||
}, | ||
"recursive/bear": { | ||
"height": 38, | ||
"pixelRatio": 2, | ||
"width": 38, | ||
"x": 46, | ||
"y": 0, | ||
"sdf": true | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.