Skip to content

Commit

Permalink
dev: disable inlined svg
Browse files Browse the repository at this point in the history
  • Loading branch information
Myriad-Dreamin committed Nov 11, 2023
1 parent 2c68f76 commit 1b77457
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
19 changes: 12 additions & 7 deletions exporter/svg/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub trait NotifyPaint {
}

pub trait DynExportFeature {
fn enable_inlined_svg(&self) -> bool;

fn should_render_text_element(&self) -> bool;

fn use_stable_glyph_id(&self) -> bool;
Expand Down Expand Up @@ -487,8 +489,9 @@ impl<
self.content.push(render_path(path, state, abs_ref))
}

fn render_image(&mut self, _ctx: &mut C, image_item: &ir::ImageItem) {
self.content.push(render_image_item(image_item))
fn render_image(&mut self, ctx: &mut C, image_item: &ir::ImageItem) {
self.content
.push(render_image_item(image_item, ctx.enable_inlined_svg()))
}

#[inline]
Expand Down Expand Up @@ -687,12 +690,14 @@ fn render_path(path: &ir::PathItem, state: RenderState, abs_ref: &Fingerprint) -

/// Render a [`ir::ImageItem`] into svg text.
#[comemo::memoize]
fn render_image_item(img: &ir::ImageItem) -> SvgText {
match &img.image.alt {
Some(t) if t.as_ref() == "!typst-inlined-svg" => {
return SvgText::Plain(String::from_utf8(img.image.data.clone()).unwrap())
fn render_image_item(img: &ir::ImageItem, enable_inlined: bool) -> SvgText {
if enable_inlined {
match &img.image.alt {
Some(t) if t.as_ref() == "!typst-inlined-svg" => {
return SvgText::Plain(String::from_utf8(img.image.data.clone()).unwrap())
}
_ => {}
}
_ => {}
}

SvgText::Plain(render_image(&img.image, img.size, true, ""))
Expand Down
5 changes: 5 additions & 0 deletions exporter/svg/src/frontend/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ pub struct RenderContext<'m, 't, Feat: ExportFeature> {
}

impl<'m, 't, Feat: ExportFeature> DynExportFeature for RenderContext<'m, 't, Feat> {
#[inline]
fn enable_inlined_svg(&self) -> bool {
Feat::ENABLE_INLINED_SVG
}

#[inline]
fn should_render_text_element(&self) -> bool {
Feat::SHOULD_RENDER_TEXT_ELEMENT && self.should_render_text_element
Expand Down
1 change: 1 addition & 0 deletions exporter/svg/src/frontend/incremental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
struct IncrementalExportFeature;

impl ExportFeature for IncrementalExportFeature {
const ENABLE_INLINED_SVG: bool = false;
const ENABLE_TRACING: bool = false;
const SHOULD_ATTACH_DEBUG_INFO: bool = false;
const SHOULD_RENDER_TEXT_ELEMENT: bool = true;
Expand Down
5 changes: 5 additions & 0 deletions exporter/svg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub trait ExportFeature {
/// Whether to attach debug info to svg elements.
const SHOULD_ATTACH_DEBUG_INFO: bool;

/// Whether to enable inlined svg.
const ENABLE_INLINED_SVG: bool;

/// Whether to render text element.
/// The text elements is selectable and searchable.
const SHOULD_RENDER_TEXT_ELEMENT: bool;
Expand All @@ -76,6 +79,7 @@ pub struct DefaultExportFeature;
pub type DefaultSvgTask = SvgTask<DefaultExportFeature>;

impl ExportFeature for DefaultExportFeature {
const ENABLE_INLINED_SVG: bool = false;
const ENABLE_TRACING: bool = false;
const SHOULD_ATTACH_DEBUG_INFO: bool = false;
const SHOULD_RENDER_TEXT_ELEMENT: bool = true;
Expand All @@ -90,6 +94,7 @@ pub struct SvgExportFeature;
pub type PlainSvgTask = SvgTask<SvgExportFeature>;

impl ExportFeature for SvgExportFeature {
const ENABLE_INLINED_SVG: bool = false;
const ENABLE_TRACING: bool = false;
const SHOULD_ATTACH_DEBUG_INFO: bool = false;
const SHOULD_RENDER_TEXT_ELEMENT: bool = true;
Expand Down

0 comments on commit 1b77457

Please sign in to comment.