VectorCraft: An open-source, vector art tool written by scratch in pure Rust
Merge wp/C1
bflatastic41f2af932c9e
diff --cc crates/doc/src/appearance.rsindex 69597c834,e59d8f292..b72f79c03--- a/crates/doc/src/appearance.rs+++ b/crates/doc/src/appearance.rs@@@ -220,18 -255,21 +264,31 @@@ impl StrokeLayerblend: BlendMode::Normal,visible: true,effects: vec![],+ arrow_align: ArrowAlign::Extend,}}+ /// Weight of the start (`end == false`) or end arrowhead: stroke weight × its scale, at least+ /// a quarter point. A head of weight `hw` is `4·hw` long and wide.+ pub fn arrow_weight(&self, end: bool) -> f64 {+ let pct = if end { self.arrow_scale.1 } else { self.arrow_scale.0 };+ (self.width * pct / 100.0).max(0.25)+ }+ /// How far the arrowheads can reach from the path's end points (0 without heads): the+ /// head's diagonal, or with [`ArrowAlign::Extend`] its length plus the cap past the end.+ pub fn arrow_reach(&self) -> f64 {+ let reach = |head: Option<Arrowhead>, end: bool| head.map_or(0.0, |_| 4.5 * self.arrow_weight(end) + self.width / 2.0);+ reach(self.start_arrow, false).max(reach(self.end_arrow, true))+ }+ /// The box an unplaced gradient on this stroke fits to (see [`stroke_paint_bounds`]).+ pub fn paint_bounds(&self, geometric: vectorcraft_geom::Rect) -> vectorcraft_geom::Rect {+ stroke_paint_bounds(geometric, self.width)+ }+}++/// The box an unplaced gradient on a stroke of `width` fits to: the geometric bounds grown by half+/// the weight (object strokes and type strokes alike, on screen and in exports).+pub fn stroke_paint_bounds(geometric: vectorcraft_geom::Rect, width: f64) -> vectorcraft_geom::Rect {+ geometric.inflate(width / 2.0, width / 2.0)}/// One entry of the appearance stack.diff --cc crates/engine/src/lib.rsindex 53850b008,d5920467a..7b325cf6d--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@@ -740,8 -733,8 +740,10 @@@ mod tests_pattern#[cfg(test)]mod tests_prefs;#[cfg(test)]+mod tests_swatches;+#[cfg(test)]+ mod tests_strokegeom;+ #[cfg(test)]mod tests_textedit;#[cfg(test)]mod tests_xform;diff --cc crates/pdf/src/export.rsindex cc7179a14,9be82c86d..935f442cd--- a/crates/pdf/src/export.rs+++ b/crates/pdf/src/export.rs@@@ -11,10 -11,9 +11,10 @@@ use krilla::num::NormalizedF32use krilla::page::PageSettings;use krilla::paint::{Fill, LinearGradient, RadialGradient, SpreadMethod, Stop, Stroke, StrokeDash};use krilla::surface::Surface;- use kurbo::{ParamCurve, ParamCurveDeriv, PathEl, Shape, Vec2};+ use kurbo::{PathEl, Shape, Vec2};use vectorcraft_color::{BlendMode, Color, GradientKind, Paint};+use vectorcraft_doc::appearance::stroke_paint_bounds;- use vectorcraft_doc::{AppearanceItem, Arrowhead, Document, LineCap, LineJoin, Node, NodeKind, StrokeAlign, StrokeLayer, TextObject};+ use vectorcraft_doc::{AppearanceItem, Document, LineCap, LineJoin, Node, NodeKind, StrokeAlign, StrokeLayer, TextObject};use vectorcraft_geom::{Affine, BezPath, FillRule, Rect};use crate::{Compatibility, ExportReport, PdfError, PdfOptions};diff --cc crates/render/src/lib.rsindex f7d72e92b,376f0568f..19579ef7b--- a/crates/render/src/lib.rs+++ b/crates/render/src/lib.rs@@@ -17,8 -16,7 +16,8 @@@ pub mod proofuse std::collections::HashMap;use std::sync::Arc;+use vectorcraft_doc::appearance::stroke_paint_bounds;- use vectorcraft_doc::{AppearanceItem, Document, LineCap, LineJoin, Node, NodeId, NodeKind, StrokeAlign, StrokeLayer, TextObject};+ use vectorcraft_doc::{AppearanceItem, Document, Node, NodeId, NodeKind, StrokeAlign, StrokeLayer, TextObject};use vectorcraft_geom::{Affine, BezPath, FillRule, Rect, Shape};use vello_cpu::kurbo;use vello_cpu::peniko::{self, BlendMode, Compose, Mix};@@@ -28,33 -27,7 +28,32 @@@ pub use live::expand_livepub use pattern::render_pattern_swatch;pub use vectorcraft_effects as effects;pub use vello_cpu;- pub use width::width_outline;+/// Largest raster an export may ask [`Renderer::render_region`] for, per side. The CPU rasteriser+/// addresses at most `u16::MAX` pixels per side (and panics at that edge).+pub const MAX_RASTER_SIDE: u32 = 32_768;+/// Largest raster an export may ask for in total (16384², 1 GiB of RGBA pixels).+pub const MAX_RASTER_PIXELS: u64 = 1 << 28;++/// Pixel size of `region` rendered at `scale` (as [`Renderer::render_region`] rounds it), or an error+/// when it exceeds [`MAX_RASTER_SIDE`] / [`MAX_RASTER_PIXELS`]. Raster exports check this first,+/// because the renderer can only clamp (wrong picture) or fail (abort) at those sizes.+pub fn raster_size(region: Rect, scale: f64) -> Result<(u32, u32), String> {+ if !(scale.is_finite() && scale > 0.0) {+ return Err(format!("invalid scale {scale}"));+ }+ let w = (region.width() * scale).round().max(1.0);+ let h = (region.height() * scale).round().max(1.0);+ let max = f64::from(MAX_RASTER_SIDE);+ if !(w <= max && h <= max && w * h <= MAX_RASTER_PIXELS as f64) {+ return Err(format!(+ "the image would be {w:.0} × {h:.0} pixels; raster exports are limited to {MAX_RASTER_SIDE} pixels per side and {} megapixels: lower the scale or resolution",+ MAX_RASTER_PIXELS / 1_000_000+ ));+ }+ Ok((w as u32, h as u32))+}+/// Rendering options.#[derive(Clone, Debug)]pub struct RenderOptions {