Fix raster export scale factor (#3870)

* fix export scale factor

* export scale increment step 0.5

* fix svg to raster export on web
This commit is contained in:
Timon 2026-03-10 02:23:42 +01:00 committed by GitHub
parent f06983d072
commit 4300a885dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 11 deletions

View File

@ -113,6 +113,7 @@ impl LayoutHolder for ExportDialogMessageHandler {
.unit("") .unit("")
.min(0.) .min(0.)
.max((1_u64 << f64::MANTISSA_DIGITS) as f64) .max((1_u64 << f64::MANTISSA_DIGITS) as f64)
.increment_step(0.5)
.disabled(self.file_type == FileType::Svg) .disabled(self.file_type == FileType::Svg)
.on_update(|number_input: &NumberInput| ExportDialogMessage::ScaleFactor { factor: number_input.value.unwrap() }.into()) .on_update(|number_input: &NumberInput| ExportDialogMessage::ScaleFactor { factor: number_input.value.unwrap() }.into())
.min_width(200) .min_width(200)

View File

@ -238,15 +238,19 @@ impl NodeGraphExecutor {
ExportBounds::Artboard(id) => document.metadata().bounding_box_document(id), ExportBounds::Artboard(id) => document.metadata().bounding_box_document(id),
} }
.ok_or_else(|| "No bounding box".to_string())?; .ok_or_else(|| "No bounding box".to_string())?;
let resolution = (bounds[1] - bounds[0]).round().as_uvec2();
let resolution_in_document_space = bounds[1] - bounds[0];
let export_resolution = resolution_in_document_space * export_config.scale_factor;
let resolution = export_resolution.round().as_uvec2();
let transform = DAffine2::from_translation(bounds[0]).inverse(); let transform = DAffine2::from_translation(bounds[0]).inverse();
let viewport = Footprint {
resolution,
transform,
..Default::default()
};
let render_config = RenderConfig { let render_config = RenderConfig {
viewport: Footprint { viewport,
resolution,
transform,
..Default::default()
},
scale: export_config.scale_factor, scale: export_config.scale_factor,
time: Default::default(), time: Default::default(),
pointer: DVec2::ZERO, pointer: DVec2::ZERO,
@ -256,7 +260,7 @@ impl NodeGraphExecutor {
for_export: true, for_export: true,
for_eyedropper: false, for_eyedropper: false,
}; };
export_config.size = resolution.as_dvec2(); export_config.size = resolution;
// Execute the node graph // Execute the node graph
self.runtime_io self.runtime_io
@ -425,7 +429,6 @@ impl NodeGraphExecutor {
file_type, file_type,
name, name,
size, size,
scale_factor,
#[cfg(feature = "gpu")] #[cfg(feature = "gpu")]
transparent_background, transparent_background,
artboard_name, artboard_name,
@ -456,7 +459,7 @@ impl NodeGraphExecutor {
}); });
} else { } else {
let mime = file_type.to_mime().to_string(); let mime = file_type.to_mime().to_string();
let size = (size * scale_factor).into(); let size = size.as_dvec2().into();
responses.add(FrontendMessage::TriggerExportImage { svg, name, mime, size }); responses.add(FrontendMessage::TriggerExportImage { svg, name, mime, size });
} }
} }

View File

@ -1,6 +1,6 @@
use super::*; use super::*;
use crate::messages::frontend::utility_types::{ExportBounds, FileType}; use crate::messages::frontend::utility_types::{ExportBounds, FileType};
use glam::{DAffine2, DVec2}; use glam::{DAffine2, UVec2};
use graph_craft::document::value::TaggedValue; use graph_craft::document::value::TaggedValue;
use graph_craft::document::{NodeId, NodeNetwork}; use graph_craft::document::{NodeId, NodeNetwork};
use graph_craft::graphene_compiler::Compiler; use graph_craft::graphene_compiler::Compiler;
@ -84,7 +84,7 @@ pub struct ExportConfig {
pub scale_factor: f64, pub scale_factor: f64,
pub bounds: ExportBounds, pub bounds: ExportBounds,
pub transparent_background: bool, pub transparent_background: bool,
pub size: DVec2, pub size: UVec2,
pub artboard_name: Option<String>, pub artboard_name: Option<String>,
pub artboard_count: usize, pub artboard_count: usize,
} }