Skip to content

Commit 469e234

Browse files
committed
finish
1 parent f131a96 commit 469e234

File tree

9 files changed

+74
-31
lines changed

9 files changed

+74
-31
lines changed

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@ fontdb = "0.21.0"
2020
yoke = { version = "0.7.4", features = ["derive"] }
2121
float-cmp = "0.9.0"
2222

23-
[patch.crates-io]
24-
tiny-skia-path = {git = "https://github.com/RazrFalcon/tiny-skia", rev="eec0a47"}
25-
2623
[dev-dependencies]
2724
difference = "2.0.0"
2825
image = "0.25.1"
2926
paste = "1.0.15"
3027
rustybuzz = "0.18.0"
3128
sitro = {git = "https://github.com/LaurenzV/sitro", rev = "b475ddc3"}
32-
cosmic-text = {path = "../cosmic-text"}
29+
cosmic-text = {git = "https://github.com/LaurenzV/cosmic-text", rev = "d8cad28"}
3330

3431

src/font/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::chunk_container::ChunkContainer;
22
use crate::serialize::{Object, SerializerContext, SvgSettings};
33
use crate::surface::Surface;
44
use crate::type3_font::Type3ID;
5-
use crate::util::Prehashed;
5+
use crate::util::{Prehashed, RectWrapper};
66
use pdf_writer::{Chunk, Ref};
77
use skrifa::instance::Location;
88
use skrifa::outline::OutlinePen;
@@ -81,7 +81,7 @@ pub struct FontInfo {
8181
checksum: u32,
8282
location: LocationWrapper,
8383
pub(crate) units_per_em: u16,
84-
global_bbox: Rect,
84+
global_bbox: RectWrapper,
8585
postscript_name: Option<String>,
8686
ascent: FiniteF32,
8787
descent: FiniteF32,
@@ -168,7 +168,7 @@ impl FontInfo {
168168
is_monospaced,
169169
weight,
170170
italic_angle,
171-
global_bbox,
171+
global_bbox: RectWrapper(global_bbox),
172172
})
173173
}
174174
}
@@ -249,7 +249,7 @@ impl Font {
249249
}
250250

251251
pub fn bbox(&self) -> Rect {
252-
self.0.font_info.global_bbox
252+
self.0.font_info.global_bbox.0
253253
}
254254

255255
pub fn location_ref(&self) -> LocationRef {

src/object/image.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::chunk_container::ChunkContainer;
22
use crate::object::color_space::DEVICE_GRAY;
33
use crate::serialize::{Object, SerializerContext};
4-
use crate::util::{NameExt, Prehashed};
4+
use crate::util::{NameExt, Prehashed, SizeWrapper};
55
use image::{ColorType, DynamicImage, Luma, Rgb, Rgba};
66
use pdf_writer::{Chunk, Finish, Name, Ref};
77
use std::sync::Arc;
@@ -10,7 +10,7 @@ use tiny_skia_path::Size;
1010
#[derive(Debug, Hash, Eq, PartialEq)]
1111
pub struct Repr {
1212
image_data: Vec<u8>,
13-
size: Size,
13+
size: SizeWrapper,
1414
mask_data: Option<Vec<u8>>,
1515
color_type: ColorType,
1616
}
@@ -31,12 +31,12 @@ impl Image {
3131
image_data,
3232
mask_data,
3333
color_type,
34-
size,
34+
size: SizeWrapper(size),
3535
})))
3636
}
3737

3838
pub fn size(&self) -> Size {
39-
self.0.size
39+
self.0.size.0
4040
}
4141
}
4242

src/object/mask.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::surface::StreamBuilder;
77
use crate::transform::TransformWrapper;
88
use pdf_writer::{Chunk, Finish, Name, Ref};
99
use tiny_skia_path::Rect;
10+
use crate::util::RectWrapper;
1011

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

2526
impl Mask {
@@ -67,7 +68,7 @@ impl Mask {
6768
Some(Self {
6869
stream: shading_stream,
6970
mask_type: MaskType::Luminosity,
70-
custom_bbox: Some(bbox),
71+
custom_bbox: Some(RectWrapper(bbox)),
7172
})
7273
}
7374
}
@@ -103,7 +104,7 @@ impl Object for Mask {
103104
self.stream.clone(),
104105
false,
105106
true,
106-
self.custom_bbox,
107+
self.custom_bbox.map(|c| c.0),
107108
));
108109

109110
let mut dict = chunk.indirect(root_ref).dict();

src/object/shading_function.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::object::color_space::{Color, ColorSpace};
33
use crate::paint::SpreadMethod;
44
use crate::serialize::{Object, SerializerContext};
55
use crate::transform::TransformWrapper;
6-
use crate::util::RectExt;
6+
use crate::util::{RectExt, RectWrapper};
77
use crate::{LinearGradient, RadialGradient, SweepGradient};
88
use pdf_writer::types::FunctionShadingType;
99
use pdf_writer::{Chunk, Finish, Name, Ref};
@@ -36,7 +36,7 @@ pub struct PostScriptGradient {
3636
pub min: FiniteF32,
3737
pub max: FiniteF32,
3838
pub stops: Vec<Stop>,
39-
pub domain: Rect,
39+
pub domain: RectWrapper,
4040
pub spread_method: SpreadMethod,
4141
pub gradient_type: GradientType,
4242
}
@@ -110,7 +110,7 @@ where
110110
.into_iter()
111111
.map(|s| s.into())
112112
.collect::<Vec<Stop>>(),
113-
domain: get_expanded_bbox(bbox, self.transform.post_concat(ts)),
113+
domain: RectWrapper(get_expanded_bbox(bbox, self.transform.post_concat(ts))),
114114
spread_method: self.spread_method,
115115
gradient_type: GradientType::Linear,
116116
}),
@@ -141,7 +141,7 @@ where
141141
.into_iter()
142142
.map(|s| s.into())
143143
.collect::<Vec<Stop>>(),
144-
domain: get_expanded_bbox(bbox, transform),
144+
domain: RectWrapper(get_expanded_bbox(bbox, transform)),
145145
spread_method: self.spread_method,
146146
gradient_type: GradientType::Sweep,
147147
}),

src/object/xobject.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::chunk_container::ChunkContainer;
22
use crate::serialize::{Object, SerializerContext};
33
use crate::stream::Stream;
4-
use crate::util::RectExt;
4+
use crate::util::{RectExt, RectWrapper};
55
use pdf_writer::{Chunk, Finish, Name, Ref};
66
use tiny_skia_path::Rect;
77

@@ -10,7 +10,7 @@ pub struct XObject {
1010
stream: Stream,
1111
isolated: bool,
1212
transparency_group_color_space: bool,
13-
custom_bbox: Option<Rect>,
13+
custom_bbox: Option<RectWrapper>,
1414
}
1515

1616
impl XObject {
@@ -24,12 +24,12 @@ impl XObject {
2424
stream,
2525
isolated,
2626
transparency_group_color_space,
27-
custom_bbox,
27+
custom_bbox: custom_bbox.map(|c| RectWrapper(c)),
2828
}
2929
}
3030

3131
pub fn bbox(&self) -> Rect {
32-
self.custom_bbox.unwrap_or(self.stream.bbox())
32+
self.custom_bbox.map(|c| c.0).unwrap_or(self.stream.bbox())
3333
}
3434
}
3535

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

5858
if self.isolated || self.transparency_group_color_space {
5959
let mut group = x_object.group();

src/stream.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::resource::{
1717
};
1818
use crate::serialize::{FontContainer, PDFGlyph, SerializerContext};
1919
use crate::transform::TransformWrapper;
20-
use crate::util::{calculate_stroke_bbox, LineCapExt, LineJoinExt, NameExt, RectExt, TransformExt};
20+
use crate::util::{calculate_stroke_bbox, LineCapExt, LineJoinExt, NameExt, RectExt, RectWrapper, TransformExt};
2121
use crate::{Fill, FillRule, LineCap, LineJoin, Paint, Stroke};
2222
use float_cmp::approx_eq;
2323
use pdf_writer::types::TextRenderingMode;
@@ -31,7 +31,7 @@ use tiny_skia_path::{FiniteF32, NormalizedF32, Path, PathSegment, Rect, Size, Tr
3131
#[derive(Debug, Hash, Eq, PartialEq, Clone)]
3232
struct Repr {
3333
content: Vec<u8>,
34-
bbox: Rect,
34+
bbox: RectWrapper,
3535
resource_dictionary: ResourceDictionary,
3636
}
3737

@@ -46,7 +46,7 @@ impl Stream {
4646
) -> Self {
4747
Self(Arc::new(Repr {
4848
content,
49-
bbox,
49+
bbox: RectWrapper(bbox),
5050
resource_dictionary,
5151
}))
5252
}
@@ -56,7 +56,7 @@ impl Stream {
5656
}
5757

5858
pub(crate) fn bbox(&self) -> Rect {
59-
self.0.bbox
59+
self.0.bbox.0
6060
}
6161

6262
pub(crate) fn resource_dictionary(&self) -> &ResourceDictionary {
@@ -66,7 +66,7 @@ impl Stream {
6666
pub fn empty() -> Self {
6767
Self(Arc::new(Repr {
6868
content: vec![],
69-
bbox: Rect::from_xywh(0.0, 0.0, 0.0, 0.0).unwrap(),
69+
bbox: RectWrapper(Rect::from_xywh(0.0, 0.0, 0.0, 0.0).unwrap()),
7070
resource_dictionary: ResourceDictionaryBuilder::new().finish(),
7171
}))
7272
}

src/util.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::fmt;
77
use std::fmt::Debug;
88
use std::hash::{Hash, Hasher};
99
use std::ops::Deref;
10-
use tiny_skia_path::{Path, PathBuilder, Rect};
10+
use tiny_skia_path::{FiniteF32, Path, PathBuilder, Rect, Size};
1111

1212
pub trait NameExt {
1313
fn to_pdf_name(&self) -> Name;
@@ -202,3 +202,46 @@ where
202202
Some((key, head))
203203
}
204204
}
205+
206+
// TODO: Remove with new resvg release
207+
#[derive(Copy, Clone, PartialEq, Debug)]
208+
pub struct RectWrapper(pub Rect);
209+
210+
impl Deref for RectWrapper {
211+
type Target = Rect;
212+
213+
fn deref(&self) -> &Self::Target {
214+
&self.0
215+
}
216+
}
217+
218+
impl Eq for RectWrapper {}
219+
220+
impl Hash for RectWrapper {
221+
fn hash<H: Hasher>(&self, state: &mut H) {
222+
FiniteF32::new(self.0.left()).unwrap().hash(state);
223+
FiniteF32::new(self.0.top()).unwrap().hash(state);
224+
FiniteF32::new(self.0.right()).unwrap().hash(state);
225+
FiniteF32::new(self.0.bottom()).unwrap().hash(state);
226+
}
227+
}
228+
229+
#[derive(Copy, Clone, PartialEq, Debug)]
230+
pub struct SizeWrapper(pub Size);
231+
232+
impl Deref for SizeWrapper {
233+
type Target = Size;
234+
235+
fn deref(&self) -> &Self::Target {
236+
&self.0
237+
}
238+
}
239+
240+
impl Eq for SizeWrapper {}
241+
242+
impl Hash for SizeWrapper {
243+
fn hash<H: Hasher>(&self, state: &mut H) {
244+
FiniteF32::new(self.0.width()).unwrap().hash(state);
245+
FiniteF32::new(self.0.height()).unwrap().hash(state);
246+
}
247+
}

0 commit comments

Comments
 (0)