Skip to content

Commit

Permalink
Tweak (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
yutannihilation authored Sep 19, 2024
1 parent b10132e commit b6611d2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
* The clip and layer composition information are just discarded. While
this can be useful, it's not very easy to use these information in R.

* Fix `string2fill()` and `string2stroke()`; when the second argument is a path
to a file, these unintentionally worked as `string2path()`.

# string2path 0.1.8

* This is a maintenance release to comply with the CRAN repository policy.
Expand Down
7 changes: 3 additions & 4 deletions src/rust/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,11 @@ impl LyonPathBuilder {
if font.is_color_glyph(cur_glyph) {
let mut painter = LyonPathBuilderForPaint::new(self, &font);
let fg_color = RgbaColor::new(0, 0, 0, 255);
font.paint_color_glyph(cur_glyph, 1, fg_color, &mut painter);
let res = font.paint_color_glyph(cur_glyph, 0, fg_color, &mut painter);
res.ok_or_else(|| savvy::Error::new(&format!("Failed to outline char '{c}'")))?;
} else {
let res = font.outline_glyph(cur_glyph, self);
if res.is_none() {
return Err(savvy::Error::new(&format!("Failed to outline char '{c}'")));
}
res.ok_or_else(|| savvy::Error::new(&format!("Failed to outline char '{c}'")))?;
}

if let Some(ha) = font.glyph_hor_advance(cur_glyph) {
Expand Down
4 changes: 2 additions & 2 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn string2stroke_file(
tolerance: f64,
line_width: f64,
) -> savvy::Result<savvy::Sexp> {
string2any_file(text, font_file, tolerance, line_width, ConversionType::Path)
string2any_file(text, font_file, tolerance, line_width, ConversionType::Stroke)
}

#[savvy]
Expand All @@ -134,7 +134,7 @@ fn string2fill_family(

#[savvy]
fn string2fill_file(text: &str, font_file: &str, tolerance: f64) -> savvy::Result<savvy::Sexp> {
string2any_file(text, font_file, tolerance, 0., ConversionType::Path)
string2any_file(text, font_file, tolerance, 0., ConversionType::Fill)
}

#[savvy]
Expand Down
41 changes: 27 additions & 14 deletions tests/testthat/_snaps/snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,39 @@
Code
string2stroke("A", "./font/test.ttf")
Output
# A tibble: 4 x 4
x y glyph_id path_id
<dbl> <dbl> <int> <int>
1 0 0 0 0
2 0.800 0.800 0 0
3 0 0.800 0 0
4 0 0 0 0
# A tibble: 18 x 5
x y glyph_id path_id triangle_id
<dbl> <dbl> <int> <int> <int>
1 0.836 0.815 0 0 0
2 0.764 0.785 0 0 0
3 0.0150 0.785 0 0 0
4 0.836 0.815 0 0 1
5 0.0150 0.785 0 0 1
6 -0.0150 0.815 0 0 1
7 -0.0150 0.815 0 0 2
8 0.0150 0.785 0 0 2
9 0.0150 0.0362 0 0 2
10 -0.0150 0.815 0 0 3
11 0.0150 0.0362 0 0 3
12 -0.0150 -0.0362 0 0 3
13 -0.0150 -0.0362 0 0 4
14 0.0150 0.0362 0 0 4
15 0.764 0.785 0 0 4
16 -0.0150 -0.0362 0 0 5
17 0.764 0.785 0 0 5
18 0.836 0.815 0 0 5

---

Code
string2fill("A", "./font/test.ttf")
Output
# A tibble: 4 x 4
x y glyph_id path_id
<dbl> <dbl> <int> <int>
1 0 0 0 0
2 0.800 0.800 0 0
3 0 0.800 0 0
4 0 0 0 0
# A tibble: 3 x 5
x y glyph_id path_id triangle_id
<dbl> <dbl> <int> <int> <int>
1 0 0 0 0 0
2 0 0.800 0 0 0
3 0.800 0.800 0 0 0

# the data extracted from installed font are as expected

Expand Down

0 comments on commit b6611d2

Please sign in to comment.