Skip to content

Commit 9749896

Browse files
committed
Simplify CI and formatting configuration
1 parent 3c7ebe4 commit 9749896

7 files changed

Lines changed: 55 additions & 119 deletions

File tree

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: Continuous integration
2+
on: [push, pull_request]
3+
4+
jobs:
5+
ci:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v3
9+
- uses: dtolnay/rust-toolchain@stable
10+
- run: cargo build
11+
- run: cargo test

.github/workflows/rust.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

rustfmt.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
unstable_features = true
2-
3-
overflow_delimited_expr = true
4-
spaces_around_ranges = true
5-
use_field_init_shorthand = true
6-
merge_derives = false
7-
1+
use_small_heuristics = "Max"
82
max_width = 90
9-
struct_lit_width = 40
103
chain_width = 70
11-
single_line_if_else_max_width = 60
4+
struct_lit_width = 50
5+
use_field_init_shorthand = true
6+
merge_derives = false

src/defer.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,12 @@ pub fn write_gradients(
167167
shading.shading_type(pending.shading_type);
168168
shading.color_space().srgb();
169169
shading.function(func);
170-
shading.coords(pending.coords.into_iter().take(
171-
if pending.shading_type == ShadingType::Axial {
172-
4
173-
} else {
174-
6
175-
},
176-
));
170+
shading.coords(
171+
pending
172+
.coords
173+
.into_iter()
174+
.take(if pending.shading_type == ShadingType::Axial { 4 } else { 6 }),
175+
);
177176
shading.extend([true, true]);
178177
}
179178

src/lib.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -443,17 +443,10 @@ fn get_sizings(tree: &Tree, options: &Options) -> (CoordToPdf, Rect) {
443443
(native_size.width(), native_size.height())
444444
};
445445

446-
let c = CoordToPdf::new(
447-
viewport,
448-
options.dpi,
449-
tree.svg_node().view_box,
450-
options.aspect,
451-
);
452-
453-
(
454-
c,
455-
Rect::new(0.0, 0.0, c.px_to_pt(viewport.0), c.px_to_pt(viewport.1)),
456-
)
446+
let c =
447+
CoordToPdf::new(viewport, options.dpi, tree.svg_node().view_box, options.aspect);
448+
449+
(c, Rect::new(0.0, 0.0, c.px_to_pt(viewport.0), c.px_to_pt(viewport.1)))
457450
}
458451

459452
fn preregister(tree: &Tree, writer: &mut PdfWriter, ctx: &mut Context) {
@@ -510,7 +503,11 @@ fn content_stream<'a>(
510503

511504
let res = content.finish();
512505

513-
if ctx.compress { deflate(&res) } else { res }
506+
if ctx.compress {
507+
deflate(&res)
508+
} else {
509+
res
510+
}
514511
}
515512

516513
/// Draw a clipping path into a content stream.
@@ -784,7 +781,7 @@ mod tests {
784781
let buf = convert_str(&doc, options).unwrap();
785782

786783
let len = base_name.len();
787-
let file_name = format!("{}.pdf", &base_name[0 .. len - 4]);
784+
let file_name = format!("{}.pdf", &base_name[0..len - 4]);
788785

789786
std::fs::write(format!("target/{}", file_name), buf).unwrap();
790787
}

src/render.rs

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,8 @@ fn render_path_partial(
130130
// Soft Mask. Because we want the masks to intersect instead, we wrap
131131
// the path in a transparency group instead.
132132
let mut xobj_content = if let Some(alpha_func) = fill_g_alpha {
133-
let smask_form_ref = prep_shading(
134-
alpha_func,
135-
fill_gradient.as_ref().unwrap(),
136-
bbox,
137-
writer,
138-
ctx,
139-
);
133+
let smask_form_ref =
134+
prep_shading(alpha_func, fill_gradient.as_ref().unwrap(), bbox, writer, ctx);
140135

141136
Some(start_wrap(smask_form_ref, content, ctx))
142137
} else if let Some(alpha_func) = stroke_g_alpha {
@@ -267,11 +262,7 @@ fn render_path_partial(
267262

268263
draw_path(&path.data.0, path.transform, content, &ctx.c);
269264

270-
match (
271-
path.fill.as_ref().map(|f| f.rule),
272-
fill,
273-
path.stroke.is_some() && stroke,
274-
) {
265+
match (path.fill.as_ref().map(|f| f.rule), fill, path.stroke.is_some() && stroke) {
275266
(Some(FillRule::NonZero), true, true) => content.fill_nonzero_and_stroke(),
276267
(Some(FillRule::EvenOdd), true, true) => content.fill_even_odd_and_stroke(),
277268
(Some(FillRule::NonZero), true, false) => content.fill_nonzero(),
@@ -367,13 +358,12 @@ fn prep_shading(
367358
shading.shading_type(gradient.shading_type);
368359
shading.color_space().d65_gray();
369360
shading.function(alpha_func);
370-
shading.coords(gradient.transformed_coords(&ctx.c, bbox).into_iter().take(
371-
if gradient.shading_type == ShadingType::Axial {
372-
4
373-
} else {
374-
6
375-
},
376-
));
361+
shading.coords(
362+
gradient
363+
.transformed_coords(&ctx.c, bbox)
364+
.into_iter()
365+
.take(if gradient.shading_type == ShadingType::Axial { 4 } else { 6 }),
366+
);
377367
shading.extend([true, true]);
378368
shading.finish();
379369

@@ -452,11 +442,7 @@ fn prep_pattern(
452442
} else if pattern.content_units == Units::ObjectBoundingBox {
453443
let viewbox = ViewBox {
454444
rect: usvg::Rect::new(0.0, 0.0, 1.0, 1.0).unwrap(),
455-
aspect: AspectRatio {
456-
defer: false,
457-
align: Align::None,
458-
slice: false,
459-
},
445+
aspect: AspectRatio { defer: false, align: Align::None, slice: false },
460446
};
461447

462448
CoordToPdf::new((bbox.width(), bbox.height()), ctx.c.dpi(), viewbox, None)
@@ -522,14 +508,8 @@ impl Render for usvg::Group {
522508

523509
// Every group is an isolated transparency group, it needs to be painted
524510
// onto its own canvas.
525-
let mut form = form_xobject(
526-
writer,
527-
group_ref,
528-
&child_content,
529-
pdf_bbox,
530-
ctx.compress,
531-
true,
532-
);
511+
let mut form =
512+
form_xobject(writer, group_ref, &child_content, pdf_bbox, ctx.compress, true);
533513

534514
let mut resources = form.resources();
535515
ctx.pop(&mut resources);
@@ -577,12 +557,10 @@ impl Render for usvg::Image {
577557
let image_ref = ctx.alloc_ref();
578558

579559
#[cfg(any(feature = "png", feature = "jpeg", feature = "gif"))]
580-
let set_image_props = |
581-
image: &mut ImageXObject,
582-
raster_size: &mut Option<(u32, u32)>,
583-
decoded: &DynamicImage,
584-
grey: bool,
585-
| {
560+
let set_image_props = |image: &mut ImageXObject,
561+
raster_size: &mut Option<(u32, u32)>,
562+
decoded: &DynamicImage,
563+
grey: bool| {
586564
let color = decoded.color();
587565
*raster_size = Some((decoded.width(), decoded.height()));
588566
image.width(decoded.width() as i32);
@@ -871,11 +849,7 @@ impl Gradient {
871849
c: &CoordToPdf,
872850
bbox: usvg::Rect,
873851
) -> [f32; 6] {
874-
let max = if bbox.width() > bbox.height() {
875-
bbox.width()
876-
} else {
877-
bbox.height()
878-
};
852+
let max = if bbox.width() > bbox.height() { bbox.width() } else { bbox.height() };
879853

880854
let coords = if self.transform_coords {
881855
let (x1, y1) = c.point((
@@ -897,22 +871,13 @@ impl Gradient {
897871
} else {
898872
let (x1, y1) = c.point((self.coords[0], self.coords[1]));
899873
let (x2, y2) = c.point((self.coords[2], self.coords[3]));
900-
[
901-
x1,
902-
y1,
903-
x2,
904-
y2,
905-
c.px_to_pt(self.coords[4]),
906-
c.px_to_pt(self.coords[5]),
907-
]
874+
[x1, y1, x2, y2, c.px_to_pt(self.coords[4]), c.px_to_pt(self.coords[5])]
908875
};
909876

910877
if self.shading_type == ShadingType::Axial {
911878
[coords[0], coords[1], coords[2], coords[3], 0.0, 0.0]
912879
} else {
913-
[
914-
coords[0], coords[1], coords[4], coords[2], coords[3], coords[5],
915-
]
880+
[coords[0], coords[1], coords[4], coords[2], coords[3], coords[5]]
916881
}
917882
}
918883
}

src/scale.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ impl CoordToPdf {
3333
let viewport_ratio = viewport.0 / viewport.1;
3434

3535
let aspect = if let Some(aspect) = aspect_ratio {
36-
if aspect.defer { viewbox.aspect } else { aspect }
36+
if aspect.defer {
37+
viewbox.aspect
38+
} else {
39+
aspect
40+
}
3741
} else {
3842
viewbox.aspect
3943
};

0 commit comments

Comments
 (0)