Skip to content

Commit

Permalink
fix: svg context (#932)
Browse files Browse the repository at this point in the history
* fix: svg context wip

* Fix export flag

---------

Co-authored-by: LongYinan <[email protected]>
  • Loading branch information
twlite and Brooooooklyn authored Nov 7, 2024
1 parent cfc4da5 commit 8b53e25
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ pub struct ContextAttributes {
}

#[napi]
#[derive(Debug, Clone, Copy)]
pub enum SvgExportFlag {
ConvertTextToPaths = 0x01,
NoPrettyXML = 0x02,
Expand Down
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ pub struct SVGCanvas<'scope> {
pub width: u32,
pub height: u32,
pub(crate) ctx: ClassInstance<'scope, CanvasRenderingContext2D>,
pub(crate) flag: SvgExportFlag,
}

#[napi]
Expand Down Expand Up @@ -483,6 +484,7 @@ impl<'scope> SVGCanvas<'scope> {
Ok(Self {
width,
height,
flag,
ctx: ctx.assign_to_this_with_attributes("ctx", PropertyAttributes::Default, &mut this)?,
})
}
Expand Down Expand Up @@ -539,9 +541,9 @@ impl<'scope> SVGCanvas<'scope> {
let height = self.height;
let old_ctx = mem::replace(
&mut self.ctx.context,
Context::new(width, height, ColorSpace::default())?,
Context::new_svg(width, height, self.flag.into(), ColorSpace::default())?,
);
env.adjust_external_memory((width as i64 - old_ctx.width as i64) * 4)?;
env.adjust_external_memory((width as i64 - old_ctx.width as i64) * (height as i64) * 4)?;
Ok(())
}

Expand All @@ -557,9 +559,9 @@ impl<'scope> SVGCanvas<'scope> {
let width = self.width;
let old_ctx = mem::replace(
&mut self.ctx.context,
Context::new(width, height, ColorSpace::default())?,
Context::new_svg(width, height, self.flag.into(), ColorSpace::default())?,
);
env.adjust_external_memory((height as i64 - old_ctx.height as i64) * 4)?;
env.adjust_external_memory((width as i64) * (height as i64 - old_ctx.height as i64) * 4)?;
Ok(())
}

Expand Down

0 comments on commit 8b53e25

Please sign in to comment.