Skip to content

Commit 7cc3097

Browse files
authored
Make the Outline render mode draw with consistent stroke thickness at any viewport zoom (#3848)
* Remove dead code for now-retired SVG implementation * Implement viewport zoom compensation for thickness
1 parent a8b5203 commit 7cc3097

File tree

7 files changed

+7
-26
lines changed

7 files changed

+7
-26
lines changed

editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,6 @@ impl TableRowLayout for Vector {
432432
TextLabel::new("Stroke Transform").narrow(true).widget_instance(),
433433
TextLabel::new(format_transform_matrix(&stroke.transform)).narrow(true).widget_instance(),
434434
]);
435-
table_rows.push(vec![
436-
TextLabel::new("Stroke Non-Scaling").narrow(true).widget_instance(),
437-
TextLabel::new((if stroke.non_scaling { "Yes" } else { "No" }).to_string()).narrow(true).widget_instance(),
438-
]);
439435
table_rows.push(vec![
440436
TextLabel::new("Stroke Paint Order").narrow(true).widget_instance(),
441437
TextLabel::new(stroke.paint_order.to_string()).narrow(true).widget_instance(),

editor/src/messages/portfolio/document/graph_operation/graph_operation_message_handler.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,6 @@ fn apply_usvg_stroke(stroke: &usvg::Stroke, modify_inputs: &mut ModifyInputsCont
515515
align: StrokeAlign::Center,
516516
paint_order: PaintOrder::StrokeAbove,
517517
transform,
518-
non_scaling: false,
519518
})
520519
}
521520
}

node-graph/libraries/rendering/src/render_ext.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ impl RenderExt for Stroke {
148148
if let Some(stroke_join_miter_limit) = stroke_join_miter_limit {
149149
let _ = write!(&mut attributes, r#" stroke-miterlimit="{stroke_join_miter_limit}""#);
150150
}
151-
// Add vector-effect attribute to make strokes non-scaling
152-
if self.non_scaling {
153-
let _ = write!(&mut attributes, r#" vector-effect="non-scaling-stroke""#);
154-
}
155151
if paint_order.is_some() {
156152
let _ = write!(&mut attributes, r#" style="paint-order: stroke;" "#);
157153
}

node-graph/libraries/rendering/src/renderer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ pub struct RenderParams {
180180
pub aligned_strokes: bool,
181181
pub override_paint_order: bool,
182182
pub artboard_background: Option<Color>,
183+
/// Viewport zoom level (document-space scale). Used to compute constant viewport-pixel stroke widths in Outline mode.
184+
pub viewport_zoom: f64,
183185
}
184186

185187
impl Hash for RenderParams {
@@ -197,6 +199,7 @@ impl Hash for RenderParams {
197199
self.aligned_strokes.hash(state);
198200
self.override_paint_order.hash(state);
199201
self.artboard_background.hash(state);
202+
self.viewport_zoom.to_bits().hash(state);
200203
}
201204
}
202205

@@ -1109,7 +1112,7 @@ impl Render for Table<Vector> {
11091112
match render_params.render_mode {
11101113
RenderMode::Outline => {
11111114
let outline_stroke = kurbo::Stroke {
1112-
width: LAYER_OUTLINE_STROKE_WEIGHT,
1115+
width: LAYER_OUTLINE_STROKE_WEIGHT / if render_params.viewport_zoom > 0. { render_params.viewport_zoom } else { 1. },
11131116
miter_limit: 4.,
11141117
join: Join::Miter,
11151118
start_cap: Cap::Butt,

node-graph/libraries/vector-types/src/vector/style.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,6 @@ pub struct Stroke {
309309
#[serde(default = "daffine2_identity")]
310310
pub transform: DAffine2,
311311
#[serde(default)]
312-
pub non_scaling: bool,
313-
#[serde(default)]
314312
pub paint_order: PaintOrder,
315313
}
316314

@@ -328,7 +326,6 @@ impl std::hash::Hash for Stroke {
328326
self.join_miter_limit.to_bits().hash(state);
329327
self.align.hash(state);
330328
self.transform.to_cols_array().iter().for_each(|x| x.to_bits().hash(state));
331-
self.non_scaling.hash(state);
332329
self.paint_order.hash(state);
333330
}
334331
}
@@ -345,7 +342,6 @@ impl Stroke {
345342
join_miter_limit: 4.,
346343
align: StrokeAlign::Center,
347344
transform: DAffine2::IDENTITY,
348-
non_scaling: false,
349345
paint_order: PaintOrder::StrokeAbove,
350346
}
351347
}
@@ -364,7 +360,6 @@ impl Stroke {
364360
time * self.transform.matrix2 + (1. - time) * other.transform.matrix2,
365361
self.transform.translation * time + other.transform.translation * (1. - time),
366362
),
367-
non_scaling: if time < 0.5 { self.non_scaling } else { other.non_scaling },
368363
paint_order: if time < 0.5 { self.paint_order } else { other.paint_order },
369364
}
370365
}
@@ -462,11 +457,6 @@ impl Stroke {
462457
self
463458
}
464459

465-
pub fn with_non_scaling(mut self, non_scaling: bool) -> Self {
466-
self.non_scaling = non_scaling;
467-
self
468-
}
469-
470460
pub fn has_renderable_stroke(&self) -> bool {
471461
self.weight > 0. && self.color.is_some_and(|color| color.a() != 0.)
472462
}
@@ -485,7 +475,6 @@ impl Default for Stroke {
485475
join_miter_limit: 4.,
486476
align: StrokeAlign::Center,
487477
transform: DAffine2::IDENTITY,
488-
non_scaling: false,
489478
paint_order: PaintOrder::default(),
490479
}
491480
}

node-graph/nodes/gstd/src/render_node.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
use core_types::table::Table;
2-
use core_types::transform::Footprint;
2+
use core_types::transform::{Footprint, Transform};
33
use core_types::{CloneVarArgs, ExtractAll, ExtractVarArgs};
44
use core_types::{Color, Context, Ctx, ExtractFootprint, OwnedContextImpl, WasmNotSend};
55
use graph_craft::document::value::RenderOutput;
66
pub use graph_craft::document::value::RenderOutputType;
77
pub use graph_craft::wasm_application_io::*;
88
use graphene_application_io::{ApplicationIo, ExportFormat, ImageTexture, RenderConfig};
9-
use graphic_types::Artboard;
10-
use graphic_types::Graphic;
11-
use graphic_types::Vector;
129
use graphic_types::raster_types::Image;
1310
use graphic_types::raster_types::{CPU, Raster};
11+
use graphic_types::{Artboard, Graphic, Vector};
1412
use rendering::{Render, RenderOutputType as RenderOutputTypeRequest, RenderParams, RenderSvgSegmentList, SvgRender, format_transform_matrix};
1513
use rendering::{RenderMetadata, SvgSegment};
1614
use std::collections::HashMap;
@@ -110,6 +108,7 @@ async fn create_context<'a: 'n>(
110108
render_output_type,
111109
footprint: Footprint::default(),
112110
scale: render_config.scale,
111+
viewport_zoom: footprint.decompose_scale().x,
113112
..Default::default()
114113
};
115114

node-graph/nodes/vector/src/vector_nodes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ where
211211
join_miter_limit: miter_limit,
212212
align,
213213
transform: DAffine2::IDENTITY,
214-
non_scaling: false,
215214
paint_order,
216215
};
217216

0 commit comments

Comments
 (0)