Skip to content

Commit

Permalink
Update savvy to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yutannihilation committed Jan 9, 2024
1 parent 803a134 commit 0e2f982
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
12 changes: 6 additions & 6 deletions src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn string2any_family(
tolerance: f64,
line_width: f64,
ct: ConversionType,
) -> savvy::Result<savvy::SEXP> {
) -> savvy::Result<savvy::Sexp> {
let mut builder = builder::LyonPathBuilder::new(tolerance as _, line_width as _);

builder
Expand All @@ -44,7 +44,7 @@ fn string2any_file(
tolerance: f64,
line_width: f64,
ct: ConversionType,
) -> savvy::Result<savvy::SEXP> {
) -> savvy::Result<savvy::Sexp> {
let mut builder = builder::LyonPathBuilder::new(tolerance as _, line_width as _);

builder.outline_from_file(text, font_file).unwrap();
Expand All @@ -65,7 +65,7 @@ fn string2path_family(
font_weight: &str,
font_style: &str,
tolerance: f64,
) -> savvy::Result<savvy::SEXP> {
) -> savvy::Result<savvy::Sexp> {
string2any_family(
text,
font_family,
Expand All @@ -78,7 +78,7 @@ fn string2path_family(
}

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

Expand All @@ -90,7 +90,7 @@ fn string2stroke_family(
font_style: &str,
tolerance: f64,
line_width: f64,
) -> savvy::Result<savvy::SEXP> {
) -> savvy::Result<savvy::Sexp> {
string2any_family(
text,
font_family,
Expand All @@ -108,7 +108,7 @@ fn string2stroke_file(
font_file: &str,
tolerance: f64,
line_width: f64,
) -> savvy::Result<savvy::SEXP> {
) -> savvy::Result<savvy::Sexp> {
string2any_file(text, font_file, tolerance, line_width, ConversionType::Path)
}

Expand All @@ -119,7 +119,7 @@ fn string2fill_family(
font_weight: &str,
font_style: &str,
tolerance: f64,
) -> savvy::Result<savvy::SEXP> {
) -> savvy::Result<savvy::Sexp> {
string2any_family(
text,
font_family,
Expand All @@ -132,12 +132,12 @@ fn string2fill_family(
}

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

#[savvy]
fn dump_fontdb_impl() -> savvy::Result<savvy::SEXP> {
fn dump_fontdb_impl() -> savvy::Result<savvy::Sexp> {
let mut source: Vec<String> = Vec::new();
let mut index: Vec<i32> = Vec::new();
let mut family: Vec<String> = Vec::new();
Expand Down
42 changes: 25 additions & 17 deletions src/rust/src/result.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use savvy::{OwnedIntegerSxp, OwnedRealSxp, OwnedStringSxp};
use savvy::{OwnedIntegerSexp, OwnedRealSexp, OwnedStringSexp};

/// An intermediate form of the extracted path information to convert to a tibble.
pub struct PathTibble {
Expand All @@ -14,35 +14,35 @@ pub struct PathTibble {
pub triangle_id: Option<Vec<i32>>,
}

impl TryFrom<PathTibble> for savvy::SEXP {
impl TryFrom<PathTibble> for savvy::Sexp {
type Error = savvy::Error;

fn try_from(value: PathTibble) -> savvy::Result<Self> {
let len = if value.triangle_id.is_none() { 4 } else { 5 };
let mut out = savvy::OwnedListSxp::new(len, true)?;
let mut out = savvy::OwnedListSexp::new(len, true)?;

out.set_name_and_value(0, "x", <OwnedRealSxp>::try_from(value.x.as_slice())?)?;
out.set_name_and_value(1, "y", <OwnedRealSxp>::try_from(value.y.as_slice())?)?;
out.set_name_and_value(0, "x", <OwnedRealSexp>::try_from(value.x.as_slice())?)?;
out.set_name_and_value(1, "y", <OwnedRealSexp>::try_from(value.y.as_slice())?)?;
out.set_name_and_value(
2,
"glyph_id",
<OwnedIntegerSxp>::try_from(value.glyph_id.as_slice())?,
<OwnedIntegerSexp>::try_from(value.glyph_id.as_slice())?,
)?;
out.set_name_and_value(
3,
"path_id",
<OwnedIntegerSxp>::try_from(value.path_id.as_slice())?,
<OwnedIntegerSexp>::try_from(value.path_id.as_slice())?,
)?;

if let Some(triangle_id) = value.triangle_id {
out.set_name_and_value(
4,
"triangle_id",
<OwnedIntegerSxp>::try_from(triangle_id.as_slice())?,
<OwnedIntegerSexp>::try_from(triangle_id.as_slice())?,
)?;
}

Ok(out.into())
out.into()
}
}

Expand All @@ -55,29 +55,37 @@ pub struct FontDBTibble {
pub style: Vec<String>,
}

impl TryFrom<FontDBTibble> for savvy::SEXP {
impl TryFrom<FontDBTibble> for savvy::Sexp {
type Error = savvy::Error;
fn try_from(value: FontDBTibble) -> savvy::Result<Self> {
let mut out = savvy::OwnedListSxp::new(5, true)?;
let mut out = savvy::OwnedListSexp::new(5, true)?;

out.set_name_and_value(0, "x", <OwnedStringSxp>::try_from(value.source.as_slice())?)?;
out.set_name_and_value(1, "y", <OwnedIntegerSxp>::try_from(value.index.as_slice())?)?;
out.set_name_and_value(
0,
"x",
<OwnedStringSexp>::try_from(value.source.as_slice())?,
)?;
out.set_name_and_value(
1,
"y",
<OwnedIntegerSexp>::try_from(value.index.as_slice())?,
)?;
out.set_name_and_value(
2,
"family",
<OwnedStringSxp>::try_from(value.family.as_slice())?,
<OwnedStringSexp>::try_from(value.family.as_slice())?,
)?;
out.set_name_and_value(
3,
"weight",
<OwnedStringSxp>::try_from(value.weight.as_slice())?,
<OwnedStringSexp>::try_from(value.weight.as_slice())?,
)?;
out.set_name_and_value(
4,
"style",
<OwnedStringSxp>::try_from(value.style.as_slice())?,
<OwnedStringSexp>::try_from(value.style.as_slice())?,
)?;

Ok(out.into())
out.into()
}
}
Binary file modified src/rust/vendor.tar.xz
Binary file not shown.

0 comments on commit 0e2f982

Please sign in to comment.