Revert adding flatten-text to image (#5789)

This commit is contained in:
Laurenz 2025-02-02 20:25:58 +01:00 committed by GitHub
parent f239b0a6a1
commit 12dbb012b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 3 additions and 41 deletions

View File

@ -63,7 +63,6 @@ pub fn layout_image(
SvgImage::with_fonts(
data.clone(),
engine.world,
elem.flatten_text(styles),
&families(styles).map(|f| f.as_str()).collect::<Vec<_>>(),
)
.at(span)?,

View File

@ -150,12 +150,6 @@ pub struct ImageElem {
})]
#[borrowed]
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]
@ -199,10 +193,6 @@ impl ImageElem {
/// A hint to viewers how they should scale the image.
#[named]
scaling: Option<Smart<ImageScaling>>,
/// Whether text in SVG images should be converted into curves before
/// embedding.
#[named]
flatten_text: Option<bool>,
) -> StrResult<Content> {
let bytes = data.into_bytes();
let source = Derived::new(DataSource::Bytes(bytes.clone()), bytes);
@ -225,9 +215,6 @@ impl ImageElem {
if let Some(scaling) = scaling {
elem.push_scaling(scaling);
}
if let Some(flatten_text) = flatten_text {
elem.push_flatten_text(flatten_text);
}
Ok(elem.pack().spanned(span))
}
}

View File

@ -22,7 +22,6 @@ pub struct SvgImage(Arc<Repr>);
struct Repr {
data: Bytes,
size: Axes<f64>,
flatten_text: bool,
font_hash: u128,
tree: usvg::Tree,
}
@ -34,13 +33,7 @@ impl SvgImage {
pub fn new(data: Bytes) -> StrResult<SvgImage> {
let tree =
usvg::Tree::from_data(&data, &base_options()).map_err(format_usvg_error)?;
Ok(Self(Arc::new(Repr {
data,
size: tree_size(&tree),
font_hash: 0,
flatten_text: false,
tree,
})))
Ok(Self(Arc::new(Repr { data, size: tree_size(&tree), font_hash: 0, tree })))
}
/// Decode an SVG image with access to fonts.
@ -49,7 +42,6 @@ impl SvgImage {
pub fn with_fonts(
data: Bytes,
world: Tracked<dyn World + '_>,
flatten_text: bool,
families: &[&str],
) -> StrResult<SvgImage> {
let book = world.book();
@ -70,13 +62,7 @@ impl SvgImage {
)
.map_err(format_usvg_error)?;
let font_hash = resolver.into_inner().unwrap().finish();
Ok(Self(Arc::new(Repr {
data,
size: tree_size(&tree),
font_hash,
flatten_text,
tree,
})))
Ok(Self(Arc::new(Repr { data, size: tree_size(&tree), font_hash, tree })))
}
/// The raw image data.
@ -89,11 +75,6 @@ impl SvgImage {
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.
pub fn height(&self) -> f64 {
self.0.size.y
@ -112,7 +93,6 @@ impl Hash for Repr {
// all used fonts gives us something similar.
self.data.hash(state);
self.font_hash.hash(state);
self.flatten_text.hash(state);
}
}

View File

@ -205,11 +205,7 @@ fn encode_svg(
) -> Result<(Chunk, Ref), svg2pdf::ConversionError> {
svg2pdf::to_chunk(
svg.tree(),
svg2pdf::ConversionOptions {
pdfa,
embed_text: !svg.flatten_text(),
..Default::default()
},
svg2pdf::ConversionOptions { pdfa, ..Default::default() },
)
}