Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #24

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
404 changes: 54 additions & 350 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 7 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,27 @@ edition = "2021"

[dependencies]
image = { version = "0.25.1", default-features = false, features = ["jpeg", "png", "gif", "webp"] }
miniz_oxide = "0.7.4"
miniz_oxide = "0.8.0"
once_cell = "1.19.0"
pdf-writer = {git = "https://github.com/LaurenzV/pdf-writer", rev = "34c991f5"}
resvg = {git = "https://github.com/LaurenzV/resvg", rev = "1c2b6bd0"}
resvg = "0.43.0"
siphasher = "1.0.1"
skrifa = {git="https://github.com/LaurenzV/fontations", rev="0ed7955"}
skrifa = "0.21.0"
tiny-skia = "0.11.4"
subsetter = {git = "https://github.com/typst/subsetter/", rev="67bde74"}
tiny-skia-path = {git = "https://github.com/RazrFalcon/tiny-skia", rev="eec0a47"}
usvg = {git = "https://github.com/LaurenzV/resvg", rev="1c2b6bd0"}
cosmic-text = {git = "https://github.com/pop-os/cosmic-text", rev = "6f78d23"}
parley = {git = "https://github.com/linebender/parley", rev = "66979c5"}
tiny-skia-path = "0.11.4"
usvg = "0.43.0"
flate2 = "1.0.30"
fontdb = "0.20.0"
fontdb = "0.21.0"
yoke = { version = "0.7.4", features = ["derive"] }
float-cmp = "0.9.0"

[patch.crates-io]
tiny-skia-path = {git = "https://github.com/RazrFalcon/tiny-skia", rev="eec0a47"}

[dev-dependencies]
difference = "2.0.0"
image = "0.25.1"
paste = "1.0.15"
rustybuzz = "0.18.0"
sitro = {git = "https://github.com/LaurenzV/sitro", rev = "b475ddc3"}
cosmic-text = {git = "https://github.com/LaurenzV/cosmic-text", rev = "d8cad28"}


37 changes: 30 additions & 7 deletions src/font/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::chunk_container::ChunkContainer;
use crate::serialize::{Object, SerializerContext, SvgSettings};
use crate::surface::Surface;
use crate::type3_font::Type3ID;
use crate::util::Prehashed;
use crate::util::{Prehashed, RectWrapper};
use pdf_writer::{Chunk, Ref};
use skrifa::instance::Location;
use skrifa::outline::OutlinePen;
Expand Down Expand Up @@ -58,13 +58,30 @@ impl OutlinePen for OutlineBuilder {
}
}

#[derive(Debug)]
struct LocationWrapper(Location);

impl Hash for LocationWrapper {
fn hash<H: Hasher>(&self, state: &mut H) {
self.0.coords().hash(state);
}
}

impl PartialEq for LocationWrapper {
fn eq(&self, other: &Self) -> bool {
self.0.coords().eq(other.0.coords())
}
}

impl Eq for LocationWrapper {}

#[derive(Debug, Hash, Eq, PartialEq)]
pub struct FontInfo {
index: u32,
checksum: u32,
location: Location,
location: LocationWrapper,
pub(crate) units_per_em: u16,
global_bbox: Rect,
global_bbox: RectWrapper,
postscript_name: Option<String>,
ascent: FiniteF32,
descent: FiniteF32,
Expand All @@ -76,6 +93,7 @@ pub struct FontInfo {

struct Repr {
font_info: Arc<FontInfo>,
font_data: Arc<dyn AsRef<[u8]> + Send + Sync>,
font_ref_yoke: Yoke<FontRefWrapper<'static>, Arc<dyn AsRef<[u8]> + Send + Sync>>,
}

Expand Down Expand Up @@ -141,7 +159,7 @@ impl FontInfo {
Some(FontInfo {
index,
checksum,
location,
location: LocationWrapper(location),
units_per_em,
postscript_name,
ascent,
Expand All @@ -150,7 +168,7 @@ impl FontInfo {
is_monospaced,
weight,
italic_angle,
global_bbox,
global_bbox: RectWrapper(global_bbox),
})
}
}
Expand Down Expand Up @@ -184,6 +202,7 @@ impl Font {
);

Some(Font(Arc::new(Prehashed::new(Repr {
font_data: data,
font_ref_yoke,
font_info,
}))))
Expand Down Expand Up @@ -230,17 +249,21 @@ impl Font {
}

pub fn bbox(&self) -> Rect {
self.0.font_info.global_bbox
self.0.font_info.global_bbox.0
}

pub fn location_ref(&self) -> LocationRef {
(&self.0.font_info.location).into()
(&self.0.font_info.location.0).into()
}

pub fn font_ref(&self) -> &FontRef {
&self.0.font_ref_yoke.get().font_ref
}

pub fn font_data(&self) -> Arc<dyn AsRef<[u8]> + Send + Sync> {
self.0.font_data.clone()
}

pub fn advance_width(&self, glyph_id: GlyphId) -> Option<f32> {
self.font_ref()
.glyph_metrics(Size::unscaled(), self.location_ref())
Expand Down
2 changes: 1 addition & 1 deletion src/font/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn draw_glyph(
.svg()
.and_then(|svg_table| svg_table.glyph_data(glyph))
{
let mut data = svg_data.get();
let mut data = svg_data;

let mut decoded = vec![];
if data.starts_with(&[0x1f, 0x8b]) {
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ pub(crate) mod test_utils {
}

pub fn simple_shape(text: &str, dir: Direction, font: Font, size: f32) -> Vec<Glyph> {
let rb_font = rustybuzz::Face::from_slice(font.font_ref().data().as_bytes(), 0).unwrap();
let data = font.font_data();
let rb_font = rustybuzz::Face::from_slice(data.as_ref().as_ref(), 0).unwrap();

let mut buffer = UnicodeBuffer::new();
buffer.push_str(text);
Expand Down
9 changes: 5 additions & 4 deletions src/object/cid_font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pdf_writer::types::{CidFontType, FontFlags, SystemInfo, UnicodeCmap};
use pdf_writer::{Chunk, Filter, Finish, Name, Ref, Str};
use skrifa::raw::tables::cff::Cff;
use skrifa::raw::{TableProvider, TopLevelTable};
use skrifa::{FontRef, GlyphId};
use skrifa::GlyphId;
use std::collections::BTreeMap;
use subsetter::GlyphRemapper;

Expand Down Expand Up @@ -104,7 +104,7 @@ impl CIDFont {
let is_cff = self.font.font_ref().cff().is_ok();

let (subsetted_font, filter) =
subset_font(sc, self.font.font_ref(), self.font.index(), &glyph_remapper);
subset_font(sc, &self.font, self.font.index(), &glyph_remapper);

let postscript_name = self.font.postscript_name().unwrap_or("unknown");
let subset_tag = subset_tag(&subsetted_font);
Expand Down Expand Up @@ -214,11 +214,12 @@ impl CIDFont {
/// Subset a font with the given glyphs.
fn subset_font(
sc: &SerializerContext,
font_ref: &FontRef,
font: &Font,
index: u32,
glyph_remapper: &GlyphRemapper,
) -> (Vec<u8>, Filter) {
let subsetted = subsetter::subset(font_ref.data().as_bytes(), index, glyph_remapper).unwrap();
let font_data = font.font_data();
let subsetted = subsetter::subset(font_data.as_ref().as_ref(), index, glyph_remapper).unwrap();
let mut data = subsetted.as_slice();

// If we have a CFF font, only embed the standalone CFF program.
Expand Down
8 changes: 4 additions & 4 deletions src/object/image.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::chunk_container::ChunkContainer;
use crate::object::color_space::DEVICE_GRAY;
use crate::serialize::{Object, SerializerContext};
use crate::util::{NameExt, Prehashed};
use crate::util::{NameExt, Prehashed, SizeWrapper};
use image::{ColorType, DynamicImage, Luma, Rgb, Rgba};
use pdf_writer::{Chunk, Finish, Name, Ref};
use std::sync::Arc;
Expand All @@ -10,7 +10,7 @@ use tiny_skia_path::Size;
#[derive(Debug, Hash, Eq, PartialEq)]
pub struct Repr {
image_data: Vec<u8>,
size: Size,
size: SizeWrapper,
mask_data: Option<Vec<u8>>,
color_type: ColorType,
}
Expand All @@ -31,12 +31,12 @@ impl Image {
image_data,
mask_data,
color_type,
size,
size: SizeWrapper(size),
})))
}

pub fn size(&self) -> Size {
self.0.size
self.0.size.0
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/object/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::surface::StreamBuilder;
use crate::transform::TransformWrapper;
use pdf_writer::{Chunk, Finish, Name, Ref};
use tiny_skia_path::Rect;
use crate::util::RectWrapper;

/// A mask.
#[derive(PartialEq, Eq, Debug, Hash, Clone)]
Expand All @@ -19,7 +20,7 @@ pub struct Mask {
/// transparencies, we create a custom mask where we call the shading operator. In this case,
/// we want to manually set the bbox of the underlying XObject to match the shape that the
/// gradient is being applied to.
custom_bbox: Option<Rect>,
custom_bbox: Option<RectWrapper>,
}

impl Mask {
Expand Down Expand Up @@ -67,7 +68,7 @@ impl Mask {
Some(Self {
stream: shading_stream,
mask_type: MaskType::Luminosity,
custom_bbox: Some(bbox),
custom_bbox: Some(RectWrapper(bbox)),
})
}
}
Expand Down Expand Up @@ -103,7 +104,7 @@ impl Object for Mask {
self.stream.clone(),
false,
true,
self.custom_bbox,
self.custom_bbox.map(|c| c.0),
));

let mut dict = chunk.indirect(root_ref).dict();
Expand Down
8 changes: 4 additions & 4 deletions src/object/shading_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::object::color_space::{Color, ColorSpace};
use crate::paint::SpreadMethod;
use crate::serialize::{Object, SerializerContext};
use crate::transform::TransformWrapper;
use crate::util::RectExt;
use crate::util::{RectExt, RectWrapper};
use crate::{LinearGradient, RadialGradient, SweepGradient};
use pdf_writer::types::FunctionShadingType;
use pdf_writer::{Chunk, Finish, Name, Ref};
Expand Down Expand Up @@ -36,7 +36,7 @@ pub struct PostScriptGradient {
pub min: FiniteF32,
pub max: FiniteF32,
pub stops: Vec<Stop>,
pub domain: Rect,
pub domain: RectWrapper,
pub spread_method: SpreadMethod,
pub gradient_type: GradientType,
}
Expand Down Expand Up @@ -110,7 +110,7 @@ where
.into_iter()
.map(|s| s.into())
.collect::<Vec<Stop>>(),
domain: get_expanded_bbox(bbox, self.transform.post_concat(ts)),
domain: RectWrapper(get_expanded_bbox(bbox, self.transform.post_concat(ts))),
spread_method: self.spread_method,
gradient_type: GradientType::Linear,
}),
Expand Down Expand Up @@ -141,7 +141,7 @@ where
.into_iter()
.map(|s| s.into())
.collect::<Vec<Stop>>(),
domain: get_expanded_bbox(bbox, transform),
domain: RectWrapper(get_expanded_bbox(bbox, transform)),
spread_method: self.spread_method,
gradient_type: GradientType::Sweep,
}),
Expand Down
10 changes: 5 additions & 5 deletions src/object/xobject.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::chunk_container::ChunkContainer;
use crate::serialize::{Object, SerializerContext};
use crate::stream::Stream;
use crate::util::RectExt;
use crate::util::{RectExt, RectWrapper};
use pdf_writer::{Chunk, Finish, Name, Ref};
use tiny_skia_path::Rect;

Expand All @@ -10,7 +10,7 @@ pub struct XObject {
stream: Stream,
isolated: bool,
transparency_group_color_space: bool,
custom_bbox: Option<Rect>,
custom_bbox: Option<RectWrapper>,
}

impl XObject {
Expand All @@ -24,12 +24,12 @@ impl XObject {
stream,
isolated,
transparency_group_color_space,
custom_bbox,
custom_bbox: custom_bbox.map(|c| RectWrapper(c)),
}
}

pub fn bbox(&self) -> Rect {
self.custom_bbox.unwrap_or(self.stream.bbox())
self.custom_bbox.map(|c| c.0).unwrap_or(self.stream.bbox())
}
}

Expand All @@ -53,7 +53,7 @@ impl Object for XObject {
self.stream
.resource_dictionary()
.to_pdf_resources(sc, &mut x_object);
x_object.bbox(self.custom_bbox.unwrap_or(self.stream.bbox()).to_pdf_rect());
x_object.bbox(self.custom_bbox.map(|c| c.0).unwrap_or(self.stream.bbox()).to_pdf_rect());

if self.isolated || self.transparency_group_color_space {
let mut group = x_object.group();
Expand Down
10 changes: 5 additions & 5 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::resource::{
};
use crate::serialize::{FontContainer, PDFGlyph, SerializerContext};
use crate::transform::TransformWrapper;
use crate::util::{calculate_stroke_bbox, LineCapExt, LineJoinExt, NameExt, RectExt, TransformExt};
use crate::util::{calculate_stroke_bbox, LineCapExt, LineJoinExt, NameExt, RectExt, RectWrapper, TransformExt};
use crate::{Fill, FillRule, LineCap, LineJoin, Paint, Stroke};
use float_cmp::approx_eq;
use pdf_writer::types::TextRenderingMode;
Expand All @@ -31,7 +31,7 @@ use tiny_skia_path::{FiniteF32, NormalizedF32, Path, PathSegment, Rect, Size, Tr
#[derive(Debug, Hash, Eq, PartialEq, Clone)]
struct Repr {
content: Vec<u8>,
bbox: Rect,
bbox: RectWrapper,
resource_dictionary: ResourceDictionary,
}

Expand All @@ -46,7 +46,7 @@ impl Stream {
) -> Self {
Self(Arc::new(Repr {
content,
bbox,
bbox: RectWrapper(bbox),
resource_dictionary,
}))
}
Expand All @@ -56,7 +56,7 @@ impl Stream {
}

pub(crate) fn bbox(&self) -> Rect {
self.0.bbox
self.0.bbox.0
}

pub(crate) fn resource_dictionary(&self) -> &ResourceDictionary {
Expand All @@ -66,7 +66,7 @@ impl Stream {
pub fn empty() -> Self {
Self(Arc::new(Repr {
content: vec![],
bbox: Rect::from_xywh(0.0, 0.0, 0.0, 0.0).unwrap(),
bbox: RectWrapper(Rect::from_xywh(0.0, 0.0, 0.0, 0.0).unwrap()),
resource_dictionary: ResourceDictionaryBuilder::new().finish(),
}))
}
Expand Down
Loading