Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Aug 31, 2024
1 parent 1ab45e7 commit e18f9b8
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 47 deletions.
6 changes: 1 addition & 5 deletions src/object/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ pub enum Action {
}

impl Action {
pub(crate) fn serialize(
&self,
_: &mut SerializerContext,
action: pdf_writer::writers::Action,
) {
pub(crate) fn serialize(&self, _: &mut SerializerContext, action: pdf_writer::writers::Action) {
match self {
Action::Link(link) => link.serialize(action),
}
Expand Down
26 changes: 10 additions & 16 deletions src/object/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::error::KrillaResult;
use crate::object::action::Action;
use crate::object::destination::Destination;
use crate::serialize::{Object, SerializerContext};
use crate::serialize::SerializerContext;
use crate::util::RectExt;
use pdf_writer::types::AnnotationType;
use pdf_writer::{Chunk, Finish, Name, Ref};
Expand Down Expand Up @@ -70,9 +70,12 @@ impl LinkAnnotation {
annotation.border(0.0, 0.0, 0.0, None);

match &self.target {
Target::Destination(destination) => {
destination.serialize(sc, annotation.insert(Name(b"Dest")).start::<pdf_writer::writers::Destination>())?
}
Target::Destination(destination) => destination.serialize(
sc,
annotation
.insert(Name(b"Dest"))
.start::<pdf_writer::writers::Destination>(),
)?,
Target::Action(action) => action.serialize(sc, annotation.action()),
};

Expand All @@ -89,15 +92,12 @@ mod tests {
use crate::object::annotation::{LinkAnnotation, Target};
use crate::object::destination::XyzDestination;

use crate::color::rgb;
use crate::color::rgb::Rgb;
use crate::serialize::SerializeSettings;
use crate::surface::PageBuilder;
use crate::tests::{default_size, green_fill, rect_to_path, red_fill};
use crate::{Fill, Paint};

use krilla_macros::snapshot;
use tiny_skia_path::{Point, Rect, Size};
use usvg::NormalizedF32;

#[snapshot(single_page)]
fn annotation_to_link(page: &mut PageBuilder) {
Expand Down Expand Up @@ -143,10 +143,7 @@ mod tests {
);

let mut surface = page.surface();
surface.fill_path(
&rect_to_path(50.0, 0.0, 150.0, 100.0),
red_fill(1.0)
);
surface.fill_path(&rect_to_path(50.0, 0.0, 150.0, 100.0), red_fill(1.0));
surface.finish();
page.finish();

Expand All @@ -161,10 +158,7 @@ mod tests {
.into(),
);
let mut my_surface = page.surface();
my_surface.fill_path(
&rect_to_path(50.0, 100.0, 150.0, 200.0),
green_fill(1.0),
);
my_surface.fill_path(&rect_to_path(50.0, 100.0, 150.0, 200.0), green_fill(1.0));

my_surface.finish();
page.finish();
Expand Down
16 changes: 11 additions & 5 deletions src/object/destination.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Destinations in a PDF document.
use crate::chunk_container::ChunkContainer;
use crate::error::{KrillaError, KrillaResult};
use crate::serialize::{Object, SerializerContext};
use pdf_writer::{Chunk, Ref};
use crate::serialize::SerializerContext;
use std::hash::{Hash, Hasher};
use tiny_skia_path::{Point, Transform};

Expand All @@ -15,7 +13,11 @@ pub enum Destination {
}

impl Destination {
pub(crate) fn serialize(&self, sc: &mut SerializerContext, destination: pdf_writer::writers::Destination) -> KrillaResult<()> {
pub(crate) fn serialize(
&self,
sc: &mut SerializerContext,
destination: pdf_writer::writers::Destination,
) -> KrillaResult<()> {
match self {
Destination::Xyz(xyz) => xyz.serialize(sc, destination),
}
Expand Down Expand Up @@ -51,7 +53,11 @@ impl XyzDestination {
Self { page_index, point }
}

pub(crate) fn serialize(&self, sc: &mut SerializerContext, mut destination: pdf_writer::writers::Destination) -> KrillaResult<()> {
pub(crate) fn serialize(
&self,
sc: &mut SerializerContext,
destination: pdf_writer::writers::Destination,
) -> KrillaResult<()> {
let page_info = sc
.page_infos()
.get(self.page_index)
Expand Down
16 changes: 4 additions & 12 deletions src/object/mask.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
///! Creating and using masks.
use crate::chunk_container::ChunkContainer;
use crate::error::KrillaResult;
use crate::object::shading_function::{GradientProperties, ShadingFunction};
Expand Down Expand Up @@ -130,11 +129,11 @@ mod tests {
use crate::surface::{StreamBuilder, Surface};

use crate::color::rgb;
use crate::tests::{rect_to_path, red_fill};
use crate::{Fill, MaskType, Paint};
use krilla_macros::{snapshot, visreg};
use tiny_skia_path::{PathBuilder, Rect};
use usvg::NormalizedF32;
use crate::tests::{rect_to_path, red_fill};

fn mask_snapshot_impl(mask_type: MaskType, sc: &mut SerializerContext) {
let mut stream_builder = StreamBuilder::new(sc);
Expand All @@ -144,10 +143,7 @@ mod tests {
builder.push_rect(Rect::from_xywh(20.0, 20.0, 160.0, 160.0).unwrap());
let path = builder.finish().unwrap();

surface.fill_path(
&path,
red_fill(0.5),
);
surface.fill_path(&path, red_fill(0.5));
surface.finish();
let mask = Mask::new(stream_builder.finish(), mask_type);
sc.add_object(mask).unwrap();
Expand All @@ -156,12 +152,9 @@ mod tests {
fn mask_visreg_impl(mask_type: MaskType, surface: &mut Surface, color: rgb::Color) {
let mut stream_builder = surface.stream_builder();
let mut sub_surface = stream_builder.surface();
let path = rect_to_path(20.0, 20.0, 180.0 ,180.0);
let path = rect_to_path(20.0, 20.0, 180.0, 180.0);

sub_surface.fill_path(
&path,
red_fill(0.2),
);
sub_surface.fill_path(&path, red_fill(0.2));
sub_surface.finish();

let mask = Mask::new(stream_builder.finish(), mask_type);
Expand All @@ -187,7 +180,6 @@ mod tests {
mask_visreg_impl(MaskType::Luminosity, surface, rgb::Color::new(0, 255, 0));
}


#[visreg(all)]
pub fn mask_alpha(surface: &mut Surface) {
mask_visreg_impl(MaskType::Luminosity, surface, rgb::Color::new(0, 0, 128));
Expand Down
20 changes: 13 additions & 7 deletions src/object/outline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
use crate::error::KrillaResult;
use crate::object::destination::XyzDestination;
use crate::serialize::{Object, SerializerContext};
use pdf_writer::{Chunk, Finish, Name, Ref, TextStr};
use crate::serialize::SerializerContext;
use pdf_writer::{Chunk, Finish, Ref, TextStr};

/// An outline.
///
Expand Down Expand Up @@ -100,7 +100,7 @@ pub struct OutlineNode {
/// The text of the outline entry.
text: String,
/// The destination of the outline entry.
destination: XyzDestination
destination: XyzDestination,
}

impl OutlineNode {
Expand Down Expand Up @@ -193,10 +193,10 @@ mod tests {
use crate::document::Document;
use crate::object::outline::{Outline, OutlineNode};

use krilla_macros::snapshot;
use tiny_skia_path::{Point, Size};
use crate::destination::XyzDestination;
use crate::tests::{blue_fill, green_fill, rect_to_path, red_fill};
use krilla_macros::snapshot;
use tiny_skia_path::{Point, Size};

#[snapshot(document)]
fn outline_simple(db: &mut Document) {
Expand All @@ -212,13 +212,19 @@ mod tests {
}
let mut outline = Outline::new();

let mut child1 = OutlineNode::new("Heading 1".to_string(), XyzDestination::new(0, Point::from_xy(0.0, 0.0)));
let mut child1 = OutlineNode::new(
"Heading 1".to_string(),
XyzDestination::new(0, Point::from_xy(0.0, 0.0)),
);
child1.push_child(OutlineNode::new(
"Heading 1.1".to_string(),
XyzDestination::new(1, Point::from_xy(50.0, 50.0)),
));

let child2 = OutlineNode::new("Heading 2".to_string(), XyzDestination::new(2, Point::from_xy(100.0, 100.0)));
let child2 = OutlineNode::new(
"Heading 2".to_string(),
XyzDestination::new(2, Point::from_xy(100.0, 100.0)),
);

outline.push_child(child1);
outline.push_child(child2);
Expand Down
1 change: 0 additions & 1 deletion src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ impl SerializerContext {
self.chunk_container.outline = Some((outline_ref, chunk));
}


let fonts = std::mem::take(&mut self.font_map);
for font_container in fonts.values() {
match &*font_container.borrow() {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::color::rgb;
use crate::color::rgb::Rgb;
use crate::document::Document;
use crate::font::Font;
use crate::image::Image;
Expand All @@ -18,7 +19,6 @@ use std::env;
use std::path::PathBuf;
use std::sync::{Arc, LazyLock};
use tiny_skia_path::{NormalizedF32, Path, PathBuilder, Point, Rect};
use crate::color::rgb::Rgb;

mod manual;
mod visreg;
Expand Down

0 comments on commit e18f9b8

Please sign in to comment.