Skip to content

Commit

Permalink
Reformat.
Browse files Browse the repository at this point in the history
  • Loading branch information
RazrFalcon committed Feb 6, 2024
1 parent 5abda47 commit f14ce90
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 42 deletions.
2 changes: 1 addition & 1 deletion crates/c-api/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use std::os::raw::c_char;
use std::slice;

use resvg::tiny_skia;
use resvg::usvg;
#[cfg(feature = "text")]
use resvg::usvg::fontdb;
use resvg::usvg;

/// @brief List of possible errors.
#[repr(C)]
Expand Down
7 changes: 2 additions & 5 deletions crates/usvg/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,8 @@ fn process(args: Args) -> Result<(), String> {
shape_rendering: args.shape_rendering,
text_rendering: args.text_rendering,
image_rendering: args.image_rendering,
default_size: usvg::Size::from_wh(
args.default_width as f32,
args.default_height as f32,
)
.unwrap(),
default_size: usvg::Size::from_wh(args.default_width as f32, args.default_height as f32)
.unwrap(),
image_href_resolver: usvg::ImageHrefResolver::default(),
};

Expand Down
4 changes: 2 additions & 2 deletions crates/usvg/src/parser/clippath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use std::cell::RefCell;
use std::rc::Rc;
use std::str::FromStr;
use std::cell::RefCell;

use crate::{ClipPath, Group, SharedClipPath, Transform, Units};
use super::converter;
use super::svgtree::{AId, EId, SvgNode};
use crate::{ClipPath, Group, SharedClipPath, Transform, Units};

pub(crate) fn convert(
node: SvgNode,
Expand Down
2 changes: 1 addition & 1 deletion crates/usvg/src/parser/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use std::str::FromStr;

use svgtypes::{Length, LengthUnit as Unit, PaintOrderKind, TransformOrigin};

use crate::*;
use super::svgtree::{self, AId, EId, FromValue, SvgNode};
use super::units::{self, convert_length};
use super::{Error, Options};
use crate::*;

#[derive(Clone)]
pub struct State<'a> {
Expand Down
3 changes: 1 addition & 2 deletions crates/usvg/src/parser/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use strict_num::PositiveF32;
use svgtypes::{Length, LengthUnit as Unit};

use crate::{
filter, filter::*,
ApproxZeroUlps, Color, Group, Node, NonZeroF32, NonZeroRect, Opacity, Units,
filter, filter::*, ApproxZeroUlps, Color, Group, Node, NonZeroF32, NonZeroRect, Opacity, Units,
};

use super::converter::{self, SvgColorExt};
Expand Down
2 changes: 1 addition & 1 deletion crates/usvg/src/parser/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use std::sync::Arc;

use svgtypes::Length;

use crate::{Group, Image, ImageKind, Node, NonZeroRect, Size, Transform, Tree, ViewBox};
use super::svgtree::{AId, SvgNode};
use super::{converter, OptionLog, Options};
use crate::{Group, Image, ImageKind, Node, NonZeroRect, Size, Transform, Tree, ViewBox};

/// A shorthand for [ImageHrefResolver]'s data function.
pub type ImageHrefDataResolverFn =
Expand Down
9 changes: 5 additions & 4 deletions crates/usvg/src/parser/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use std::rc::Rc;
use std::cell::RefCell;
use std::rc::Rc;

use strict_num::NonZeroPositiveF32;
use svgtypes::Length;
use tiny_skia_path::Point;

use crate::{
ApproxEqUlps, ApproxZeroUlps, ClipPath, Fill, Group, Node, NonZeroRect, Path, Size, Transform, ViewBox
};
use super::converter;
use super::svgtree::{AId, EId, SvgNode};
use crate::{
ApproxEqUlps, ApproxZeroUlps, ClipPath, Fill, Group, Node, NonZeroRect, Path, Size, Transform,
ViewBox,
};

// Similar to `tiny_skia_path::PathSegment`, but without the `QuadTo`.
#[derive(Copy, Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion crates/usvg/src/parser/mask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::rc::Rc;

use svgtypes::{Length, LengthUnit as Unit};

use crate::{Group, Mask, MaskType, NonZeroRect, SharedMask, Units};
use super::svgtree::{AId, EId, SvgNode};
use super::{converter, OptionLog};
use crate::{Group, Mask, MaskType, NonZeroRect, SharedMask, Units};

pub(crate) fn convert(
node: SvgNode,
Expand Down
2 changes: 1 addition & 1 deletion crates/usvg/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ mod text;
mod units;
mod use_node;

pub use image::{ImageHrefDataResolverFn, ImageHrefResolver, ImageHrefStringResolverFn};
pub use options::Options;
pub use image::{ImageHrefResolver, ImageHrefDataResolverFn, ImageHrefStringResolverFn};
pub(crate) use svgtree::{AId, EId};

/// List of all errors.
Expand Down
2 changes: 1 addition & 1 deletion crates/usvg/src/parser/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use crate::{ImageRendering, ShapeRendering, Size, TextRendering, ImageHrefResolver};
use crate::{ImageHrefResolver, ImageRendering, ShapeRendering, Size, TextRendering};

/// Processing options.
#[derive(Debug)]
Expand Down
3 changes: 1 addition & 2 deletions crates/usvg/src/parser/paint_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use std::cell::RefCell;
use std::rc::Rc;
use std::str::FromStr;
use std::cell::RefCell;

use strict_num::PositiveF32;
use svgtypes::{Length, LengthUnit as Unit};
Expand All @@ -14,7 +14,6 @@ use super::svgtree::{AId, EId, SvgNode};
use super::OptionLog;
use crate::*;


pub(crate) enum ServerOrColor {
Server(Paint),
Color { color: Color, opacity: Opacity },
Expand Down
2 changes: 1 addition & 1 deletion crates/usvg/src/parser/shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::rc::Rc;
use svgtypes::Length;
use tiny_skia_path::Path;

use crate::{ApproxEqUlps, IsValidLength, Rect};
use super::svgtree::{AId, EId, SvgNode};
use super::{converter, units};
use crate::{ApproxEqUlps, IsValidLength, Rect};

pub(crate) fn convert(node: SvgNode, state: &converter::State) -> Option<Rc<Path>> {
match node.tag_name()? {
Expand Down
5 changes: 4 additions & 1 deletion crates/usvg/src/parser/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use crate::{ApproxEqUlps, Color, Fill, FillRule, LineCap, LineJoin, Opacity, Paint, Stroke, StrokeMiterlimit, Units};
use super::converter::{self, SvgColorExt};
use super::paint_server;
use super::svgtree::{AId, FromValue, SvgNode};
use crate::{
ApproxEqUlps, Color, Fill, FillRule, LineCap, LineJoin, Opacity, Paint, Stroke,
StrokeMiterlimit, Units,
};

impl<'a, 'input: 'a> FromValue<'a, 'input> for LineCap {
fn parse(_: SvgNode, _: AId, value: &str) -> Option<Self> {
Expand Down
9 changes: 5 additions & 4 deletions crates/usvg/src/parser/svgtree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ mod text;

use tiny_skia_path::Transform;

use crate::{
BlendMode, ImageRendering, Opacity, ShapeRendering, SpreadMethod, TextRendering, Units,
Visibility,
};
pub use names::{AId, EId};
use crate::{BlendMode, ImageRendering, Opacity, ShapeRendering, SpreadMethod, TextRendering, Units, Visibility};

/// An SVG tree container.
///
Expand Down Expand Up @@ -854,9 +857,7 @@ impl<'a, 'input: 'a> FromValue<'a, 'input> for Opacity {
fn parse(_: SvgNode, _: AId, value: &str) -> Option<Self> {
let length = svgtypes::Length::from_str(value).ok()?;
if length.unit == svgtypes::LengthUnit::Percent {
Some(Opacity::new_clamped(
length.number as f32 / 100.0,
))
Some(Opacity::new_clamped(length.number as f32 / 100.0))
} else if length.unit == svgtypes::LengthUnit::None {
Some(Opacity::new_clamped(length.number as f32))
} else {
Expand Down
2 changes: 1 addition & 1 deletion crates/usvg/src/parser/switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

use crate::{Group, Node};
use super::svgtree::{AId, SvgNode};
use super::{converter, Options};
use crate::{Group, Node};

// Full list can be found here: https://www.w3.org/TR/SVG11/feature.html
static FEATURES: &[&str] = &[
Expand Down
2 changes: 1 addition & 1 deletion crates/usvg/src/parser/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::rc::Rc;
use kurbo::{ParamCurve, ParamCurveArclen};
use svgtypes::{parse_font_families, FontFamily, Length, LengthUnit};

use crate::*;
use super::svgtree::{AId, EId, FromValue, SvgNode};
use super::{converter, style, OptionLog};
use crate::*;

impl<'a, 'input: 'a> FromValue<'a, 'input> for TextAnchor {
fn parse(_: SvgNode, _: AId, value: &str) -> Option<Self> {
Expand Down
2 changes: 1 addition & 1 deletion crates/usvg/src/parser/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use svgtypes::{Length, LengthUnit as Unit};

use crate::Units;
use super::converter;
use super::svgtree::{AId, SvgNode};
use crate::Units;

#[inline(never)]
pub(crate) fn convert_length(
Expand Down
2 changes: 1 addition & 1 deletion crates/usvg/src/parser/use_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use std::rc::Rc;

use svgtypes::{Length, LengthUnit};

use crate::{Group, IsValidLength, Node, NonZeroRect, Path, Size, Transform};
use super::converter;
use super::svgtree::{AId, EId, SvgNode};
use crate::{Group, IsValidLength, Node, NonZeroRect, Path, Size, Transform};

// TODO: do not return Option<()>
pub(crate) fn convert(
Expand Down
21 changes: 10 additions & 11 deletions crates/usvg/tests/write.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use once_cell::sync::Lazy;

static GLOBAL_FONTDB: Lazy<std::sync::Mutex<usvg::fontdb::Database>> =
Lazy::new(|| {
let mut fontdb = usvg::fontdb::Database::new();
fontdb.load_fonts_dir("../resvg/tests/fonts");
fontdb.set_serif_family("Noto Serif");
fontdb.set_sans_serif_family("Noto Sans");
fontdb.set_cursive_family("Yellowtail");
fontdb.set_fantasy_family("Sedgwick Ave Display");
fontdb.set_monospace_family("Noto Mono");
std::sync::Mutex::new(fontdb)
});
static GLOBAL_FONTDB: Lazy<std::sync::Mutex<usvg::fontdb::Database>> = Lazy::new(|| {
let mut fontdb = usvg::fontdb::Database::new();
fontdb.load_fonts_dir("../resvg/tests/fonts");
fontdb.set_serif_family("Noto Serif");
fontdb.set_sans_serif_family("Noto Sans");
fontdb.set_cursive_family("Yellowtail");
fontdb.set_fantasy_family("Sedgwick Ave Display");
fontdb.set_monospace_family("Noto Mono");
std::sync::Mutex::new(fontdb)
});

fn resave(name: &str) {
resave_impl(name, None, false);
Expand Down

0 comments on commit f14ce90

Please sign in to comment.