Skip to content

Commit

Permalink
Fix export flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Nov 7, 2024
1 parent b64fea9 commit b694703
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ impl From<SkError> for Error {
pub(crate) const MAX_TEXT_WIDTH: f32 = 100_000.0;
pub(crate) const FILL_STYLE_HIDDEN_NAME: &str = "_fillStyle";
pub(crate) const STROKE_STYLE_HIDDEN_NAME: &str = "_strokeStyle";
pub(crate) const SVG_CTX_FLAG_HIDDEN_NAME: &str = "_svgCtxFlag";

pub struct Context {
pub(crate) surface: Surface,
Expand Down Expand Up @@ -878,6 +877,7 @@ pub struct ContextAttributes {
}

#[napi]
#[derive(Debug, Clone, Copy)]
pub enum SvgExportFlag {
ConvertTextToPaths = 0x01,
NoPrettyXML = 0x02,
Expand Down
15 changes: 7 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use napi::*;

use ctx::{
encode_surface, CanvasRenderingContext2D, Context, ContextData, ContextOutputData, SvgExportFlag,
FILL_STYLE_HIDDEN_NAME, STROKE_STYLE_HIDDEN_NAME, SVG_CTX_FLAG_HIDDEN_NAME,
FILL_STYLE_HIDDEN_NAME, STROKE_STYLE_HIDDEN_NAME,
};
use font::{init_font_regexp, FONT_REGEXP};
use sk::{ColorSpace, SkiaDataRef};
Expand Down 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 @@ -477,15 +478,13 @@ impl<'scope> SVGCanvas<'scope> {
| PropertyAttributes::Writable
| PropertyAttributes::Enumerable,
),
// Property::new(SVG_CTX_FLAG_HIDDEN_NAME)?
// .with_value(&env.create_string(flag.to_string())?)
// .with_property_attributes(PropertyAttributes::Writable | PropertyAttributes::Configurable),
])?;
env.adjust_external_memory((width * height * 4) as i64)?;

Ok(Self {
width,
height,
flag,
ctx: ctx.assign_to_this_with_attributes("ctx", PropertyAttributes::Default, &mut this)?,
})
}
Expand Down Expand Up @@ -542,9 +541,9 @@ impl<'scope> SVGCanvas<'scope> {
let height = self.height;
let old_ctx = mem::replace(
&mut self.ctx.context,
Context::new_svg(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 @@ -560,9 +559,9 @@ impl<'scope> SVGCanvas<'scope> {
let width = self.width;
let old_ctx = mem::replace(
&mut self.ctx.context,
Context::new_svg(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 b694703

Please sign in to comment.