Skip to content

Commit 4300a88

Browse files
Fix raster export scale factor (#3870)
* fix export scale factor * export scale increment step 0.5 * fix svg to raster export on web
1 parent f06983d commit 4300a88

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

editor/src/messages/dialog/export_dialog/export_dialog_message_handler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ impl LayoutHolder for ExportDialogMessageHandler {
113113
.unit("")
114114
.min(0.)
115115
.max((1_u64 << f64::MANTISSA_DIGITS) as f64)
116+
.increment_step(0.5)
116117
.disabled(self.file_type == FileType::Svg)
117118
.on_update(|number_input: &NumberInput| ExportDialogMessage::ScaleFactor { factor: number_input.value.unwrap() }.into())
118119
.min_width(200)

editor/src/node_graph_executor.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,19 @@ impl NodeGraphExecutor {
238238
ExportBounds::Artboard(id) => document.metadata().bounding_box_document(id),
239239
}
240240
.ok_or_else(|| "No bounding box".to_string())?;
241-
let resolution = (bounds[1] - bounds[0]).round().as_uvec2();
241+
242+
let resolution_in_document_space = bounds[1] - bounds[0];
243+
let export_resolution = resolution_in_document_space * export_config.scale_factor;
244+
let resolution = export_resolution.round().as_uvec2();
242245
let transform = DAffine2::from_translation(bounds[0]).inverse();
246+
let viewport = Footprint {
247+
resolution,
248+
transform,
249+
..Default::default()
250+
};
243251

244252
let render_config = RenderConfig {
245-
viewport: Footprint {
246-
resolution,
247-
transform,
248-
..Default::default()
249-
},
253+
viewport,
250254
scale: export_config.scale_factor,
251255
time: Default::default(),
252256
pointer: DVec2::ZERO,
@@ -256,7 +260,7 @@ impl NodeGraphExecutor {
256260
for_export: true,
257261
for_eyedropper: false,
258262
};
259-
export_config.size = resolution.as_dvec2();
263+
export_config.size = resolution;
260264

261265
// Execute the node graph
262266
self.runtime_io
@@ -425,7 +429,6 @@ impl NodeGraphExecutor {
425429
file_type,
426430
name,
427431
size,
428-
scale_factor,
429432
#[cfg(feature = "gpu")]
430433
transparent_background,
431434
artboard_name,
@@ -456,7 +459,7 @@ impl NodeGraphExecutor {
456459
});
457460
} else {
458461
let mime = file_type.to_mime().to_string();
459-
let size = (size * scale_factor).into();
462+
let size = size.as_dvec2().into();
460463
responses.add(FrontendMessage::TriggerExportImage { svg, name, mime, size });
461464
}
462465
}

editor/src/node_graph_executor/runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22
use crate::messages::frontend::utility_types::{ExportBounds, FileType};
3-
use glam::{DAffine2, DVec2};
3+
use glam::{DAffine2, UVec2};
44
use graph_craft::document::value::TaggedValue;
55
use graph_craft::document::{NodeId, NodeNetwork};
66
use graph_craft::graphene_compiler::Compiler;
@@ -84,7 +84,7 @@ pub struct ExportConfig {
8484
pub scale_factor: f64,
8585
pub bounds: ExportBounds,
8686
pub transparent_background: bool,
87-
pub size: DVec2,
87+
pub size: UVec2,
8888
pub artboard_name: Option<String>,
8989
pub artboard_count: usize,
9090
}

0 commit comments

Comments
 (0)