mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Revert adding flatten-text
to image
(#5789)
This commit is contained in:
parent
f239b0a6a1
commit
12dbb012b1
@ -63,7 +63,6 @@ pub fn layout_image(
|
|||||||
SvgImage::with_fonts(
|
SvgImage::with_fonts(
|
||||||
data.clone(),
|
data.clone(),
|
||||||
engine.world,
|
engine.world,
|
||||||
elem.flatten_text(styles),
|
|
||||||
&families(styles).map(|f| f.as_str()).collect::<Vec<_>>(),
|
&families(styles).map(|f| f.as_str()).collect::<Vec<_>>(),
|
||||||
)
|
)
|
||||||
.at(span)?,
|
.at(span)?,
|
||||||
|
@ -150,12 +150,6 @@ pub struct ImageElem {
|
|||||||
})]
|
})]
|
||||||
#[borrowed]
|
#[borrowed]
|
||||||
pub icc: Smart<Derived<DataSource, Bytes>>,
|
pub icc: Smart<Derived<DataSource, Bytes>>,
|
||||||
|
|
||||||
/// Whether text in SVG images should be converted into curves before
|
|
||||||
/// embedding. This will result in the text becoming unselectable in the
|
|
||||||
/// output.
|
|
||||||
#[default(false)]
|
|
||||||
pub flatten_text: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[scope]
|
#[scope]
|
||||||
@ -199,10 +193,6 @@ impl ImageElem {
|
|||||||
/// A hint to viewers how they should scale the image.
|
/// A hint to viewers how they should scale the image.
|
||||||
#[named]
|
#[named]
|
||||||
scaling: Option<Smart<ImageScaling>>,
|
scaling: Option<Smart<ImageScaling>>,
|
||||||
/// Whether text in SVG images should be converted into curves before
|
|
||||||
/// embedding.
|
|
||||||
#[named]
|
|
||||||
flatten_text: Option<bool>,
|
|
||||||
) -> StrResult<Content> {
|
) -> StrResult<Content> {
|
||||||
let bytes = data.into_bytes();
|
let bytes = data.into_bytes();
|
||||||
let source = Derived::new(DataSource::Bytes(bytes.clone()), bytes);
|
let source = Derived::new(DataSource::Bytes(bytes.clone()), bytes);
|
||||||
@ -225,9 +215,6 @@ impl ImageElem {
|
|||||||
if let Some(scaling) = scaling {
|
if let Some(scaling) = scaling {
|
||||||
elem.push_scaling(scaling);
|
elem.push_scaling(scaling);
|
||||||
}
|
}
|
||||||
if let Some(flatten_text) = flatten_text {
|
|
||||||
elem.push_flatten_text(flatten_text);
|
|
||||||
}
|
|
||||||
Ok(elem.pack().spanned(span))
|
Ok(elem.pack().spanned(span))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ pub struct SvgImage(Arc<Repr>);
|
|||||||
struct Repr {
|
struct Repr {
|
||||||
data: Bytes,
|
data: Bytes,
|
||||||
size: Axes<f64>,
|
size: Axes<f64>,
|
||||||
flatten_text: bool,
|
|
||||||
font_hash: u128,
|
font_hash: u128,
|
||||||
tree: usvg::Tree,
|
tree: usvg::Tree,
|
||||||
}
|
}
|
||||||
@ -34,13 +33,7 @@ impl SvgImage {
|
|||||||
pub fn new(data: Bytes) -> StrResult<SvgImage> {
|
pub fn new(data: Bytes) -> StrResult<SvgImage> {
|
||||||
let tree =
|
let tree =
|
||||||
usvg::Tree::from_data(&data, &base_options()).map_err(format_usvg_error)?;
|
usvg::Tree::from_data(&data, &base_options()).map_err(format_usvg_error)?;
|
||||||
Ok(Self(Arc::new(Repr {
|
Ok(Self(Arc::new(Repr { data, size: tree_size(&tree), font_hash: 0, tree })))
|
||||||
data,
|
|
||||||
size: tree_size(&tree),
|
|
||||||
font_hash: 0,
|
|
||||||
flatten_text: false,
|
|
||||||
tree,
|
|
||||||
})))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decode an SVG image with access to fonts.
|
/// Decode an SVG image with access to fonts.
|
||||||
@ -49,7 +42,6 @@ impl SvgImage {
|
|||||||
pub fn with_fonts(
|
pub fn with_fonts(
|
||||||
data: Bytes,
|
data: Bytes,
|
||||||
world: Tracked<dyn World + '_>,
|
world: Tracked<dyn World + '_>,
|
||||||
flatten_text: bool,
|
|
||||||
families: &[&str],
|
families: &[&str],
|
||||||
) -> StrResult<SvgImage> {
|
) -> StrResult<SvgImage> {
|
||||||
let book = world.book();
|
let book = world.book();
|
||||||
@ -70,13 +62,7 @@ impl SvgImage {
|
|||||||
)
|
)
|
||||||
.map_err(format_usvg_error)?;
|
.map_err(format_usvg_error)?;
|
||||||
let font_hash = resolver.into_inner().unwrap().finish();
|
let font_hash = resolver.into_inner().unwrap().finish();
|
||||||
Ok(Self(Arc::new(Repr {
|
Ok(Self(Arc::new(Repr { data, size: tree_size(&tree), font_hash, tree })))
|
||||||
data,
|
|
||||||
size: tree_size(&tree),
|
|
||||||
font_hash,
|
|
||||||
flatten_text,
|
|
||||||
tree,
|
|
||||||
})))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The raw image data.
|
/// The raw image data.
|
||||||
@ -89,11 +75,6 @@ impl SvgImage {
|
|||||||
self.0.size.x
|
self.0.size.x
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the SVG's text should be flattened.
|
|
||||||
pub fn flatten_text(&self) -> bool {
|
|
||||||
self.0.flatten_text
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The SVG's height in pixels.
|
/// The SVG's height in pixels.
|
||||||
pub fn height(&self) -> f64 {
|
pub fn height(&self) -> f64 {
|
||||||
self.0.size.y
|
self.0.size.y
|
||||||
@ -112,7 +93,6 @@ impl Hash for Repr {
|
|||||||
// all used fonts gives us something similar.
|
// all used fonts gives us something similar.
|
||||||
self.data.hash(state);
|
self.data.hash(state);
|
||||||
self.font_hash.hash(state);
|
self.font_hash.hash(state);
|
||||||
self.flatten_text.hash(state);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,11 +205,7 @@ fn encode_svg(
|
|||||||
) -> Result<(Chunk, Ref), svg2pdf::ConversionError> {
|
) -> Result<(Chunk, Ref), svg2pdf::ConversionError> {
|
||||||
svg2pdf::to_chunk(
|
svg2pdf::to_chunk(
|
||||||
svg.tree(),
|
svg.tree(),
|
||||||
svg2pdf::ConversionOptions {
|
svg2pdf::ConversionOptions { pdfa, ..Default::default() },
|
||||||
pdfa,
|
|
||||||
embed_text: !svg.flatten_text(),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user