summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-04-04 14:36:25 +0200
committerLaurenz <laurmaedje@gmail.com>2023-04-04 14:36:25 +0200
commitc2d88989a732aed01f4274b8813fecff07bcca19 (patch)
treeabcd9efa22ae998bf938ed0aab8b8f205d46f149
parent8271ba5a521b2d442c605314124af2e456c1aa48 (diff)
Format code
-rw-r--r--library/src/compute/data.rs16
-rw-r--r--library/src/meta/numbering.rs4
-rw-r--r--src/export/render.rs68
3 files changed, 55 insertions, 33 deletions
diff --git a/library/src/compute/data.rs b/library/src/compute/data.rs
index c2dc632b..1e0edebb 100644
--- a/library/src/compute/data.rs
+++ b/library/src/compute/data.rs
@@ -212,21 +212,21 @@ fn format_json_error(error: serde_json::Error) -> String {
/// The file must contain a valid YAML object or array. YAML mappings will be
/// converted into Typst dictionaries, and YAML sequences will be converted into
/// Typst arrays. Strings and booleans will be converted into the Typst
-/// equivalents, null-values (`null`, `~` or empty ``) will be converted into
-/// `{none}`, and numbers will be converted to floats or integers depending on
+/// equivalents, null-values (`null`, `~` or empty ``) will be converted into
+/// `{none}`, and numbers will be converted to floats or integers depending on
/// whether they are whole numbers.
///
-/// Note that mapping keys that are not a string cause the entry to be
+/// Note that mapping keys that are not a string cause the entry to be
/// discarded.
-///
+///
/// Custom YAML tags are ignored, though the loaded value will still be
/// present.
-///
+///
/// The function returns a dictionary or value or an array, depending on
/// the YAML file.
///
/// The YAML files in the example contain objects with authors as keys,
-/// each with a sequence of their own submapping with the keys
+/// each with a sequence of their own submapping with the keys
/// "title" and "published"
///
/// ## Example
@@ -275,9 +275,9 @@ fn convert_yaml(value: serde_yaml::Value) -> Value {
serde_yaml::Value::Mapping(v) => Value::Dict(
v.into_iter()
.map(|(key, value)| (convert_yaml_key(key), convert_yaml(value)))
- .filter_map(|(key, value)| key.map(|key|(key, value)))
+ .filter_map(|(key, value)| key.map(|key| (key, value)))
.collect(),
- )
+ ),
}
}
diff --git a/library/src/meta/numbering.rs b/library/src/meta/numbering.rs
index 07796981..f155abf8 100644
--- a/library/src/meta/numbering.rs
+++ b/library/src/meta/numbering.rs
@@ -363,7 +363,7 @@ impl NumberingKind {
let symbol = SYMBOLS[(n - 1) % SYMBOLS.len()];
let amount = ((n - 1) / SYMBOLS.len()) + 1;
std::iter::repeat(symbol).take(amount).collect()
- },
+ }
Self::Hebrew => {
if n == 0 {
return '-'.into();
@@ -410,7 +410,7 @@ impl NumberingKind {
n -= value;
continue;
- },
+ }
}
break 'outer;
}
diff --git a/src/export/render.rs b/src/export/render.rs
index 7dd78c5f..89e45b15 100644
--- a/src/export/render.rs
+++ b/src/export/render.rs
@@ -193,13 +193,21 @@ fn render_svg_glyph(
// be on the safe size. We also compute the intersection
// with the canvas rectangle
let svg_ts = usvg::Transform::new(
- ts.sx.into(), ts.kx.into(),
- ts.ky.into(), ts.sy.into(),
- ts.tx.into(), ts.ty.into());
- let bbox = bbox.transform(&svg_ts)?
- .to_screen_rect();
- let bbox = usvg::ScreenRect::new(bbox.left()-5, bbox.y()-5, bbox.width()+10, bbox.height()+10)?
- .fit_to_rect(canvas_rect);
+ ts.sx.into(),
+ ts.kx.into(),
+ ts.ky.into(),
+ ts.sy.into(),
+ ts.tx.into(),
+ ts.ty.into(),
+ );
+ let bbox = bbox.transform(&svg_ts)?.to_screen_rect();
+ let bbox = usvg::ScreenRect::new(
+ bbox.left() - 5,
+ bbox.y() - 5,
+ bbox.width() + 10,
+ bbox.height() + 10,
+ )?
+ .fit_to_rect(canvas_rect);
let mut pixmap = sk::Pixmap::new(bbox.width(), bbox.height())?;
@@ -207,7 +215,14 @@ fn render_svg_glyph(
let ts = ts.post_translate(-bbox.left() as f32, -bbox.top() as f32);
resvg::render(&tree, FitTo::Original, ts, pixmap.as_mut())?;
- canvas.draw_pixmap(bbox.left(), bbox.top(), pixmap.as_ref(), &sk::PixmapPaint::default(), sk::Transform::identity(), mask)
+ canvas.draw_pixmap(
+ bbox.left(),
+ bbox.top(),
+ pixmap.as_ref(),
+ &sk::PixmapPaint::default(),
+ sk::Transform::identity(),
+ mask,
+ )
}
/// Render a bitmap glyph into the canvas.
@@ -282,32 +297,39 @@ fn render_outline_glyph(
// Pad the pixmap with 1 pixel in each dimension so that we do
// not get any problem with floating point errors along ther border
- let mut pixmap = sk::Pixmap::new(mw+2, mh+2)?;
+ let mut pixmap = sk::Pixmap::new(mw + 2, mh + 2)?;
for x in 0..mw {
for y in 0..mh {
let alpha = bitmap.coverage[(y * mw + x) as usize];
let color = sk::ColorU8::from_rgba(c.r, c.g, c.b, alpha).premultiply();
- pixmap.pixels_mut()[((y+1) * (mw+2) + (x+1)) as usize] = color;
+ pixmap.pixels_mut()[((y + 1) * (mw + 2) + (x + 1)) as usize] = color;
}
}
let left = bitmap.left;
let top = bitmap.top;
- canvas.draw_pixmap(left-1, top-1, pixmap.as_ref(), &sk::PixmapPaint::default(), sk::Transform::identity(), mask)
+ canvas.draw_pixmap(
+ left - 1,
+ top - 1,
+ pixmap.as_ref(),
+ &sk::PixmapPaint::default(),
+ sk::Transform::identity(),
+ mask,
+ )
} else {
- let cw = canvas.width() as i32;
- let ch = canvas.height() as i32;
- let mw = bitmap.width as i32;
- let mh = bitmap.height as i32;
-
- // Determine the pixel bounding box that we actually need to draw.
- let left = bitmap.left;
- let right = left + mw;
- let top = bitmap.top;
- let bottom = top + mh;
-
- // Premultiply the text color.
+ let cw = canvas.width() as i32;
+ let ch = canvas.height() as i32;
+ let mw = bitmap.width as i32;
+ let mh = bitmap.height as i32;
+
+ // Determine the pixel bounding box that we actually need to draw.
+ let left = bitmap.left;
+ let right = left + mw;
+ let top = bitmap.top;
+ let bottom = top + mh;
+
+ // Premultiply the text color.
let Paint::Solid(color) = text.fill;
let c = color.to_rgba();
let color = sk::ColorU8::from_rgba(c.r, c.g, c.b, 255).premultiply().get();