mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 19:08:05 +08:00
Gradient Tool (#546)
* Refactor to support fill enum & svg defs * Init tool * Fix advertise * Gradient tool click and drag * Overlays * Drag overlays * Cleanup * Fix transform on elongated shapes * Snap rotate * Snapping * Add hints * Rename to solid * Code review changes Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
parent
2bf1d5ebea
commit
2aba0fc06b
@@ -385,7 +385,7 @@ impl PathGraph {
|
||||
concat_paths(&mut curve, &self.edge(vertices[index - 1].0, vertices[index].0, vertices[index].1).unwrap().curve);
|
||||
}
|
||||
curve.push(PathEl::ClosePath);
|
||||
ShapeLayer::from_bez_path(BezPath::from_vec(curve), *style, false)
|
||||
ShapeLayer::from_bez_path(BezPath::from_vec(curve), style.clone(), false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,14 @@ impl Default for Document {
|
||||
impl Document {
|
||||
/// Wrapper around render, that returns the whole document as a Response.
|
||||
pub fn render_root(&mut self, mode: ViewMode) -> String {
|
||||
self.root.render(&mut vec![], mode);
|
||||
self.root.cache.clone()
|
||||
let mut svg_defs = String::from("<defs>");
|
||||
|
||||
self.root.render(&mut vec![], mode, &mut svg_defs);
|
||||
|
||||
svg_defs.push_str("</defs>");
|
||||
|
||||
svg_defs.push_str(&self.root.cache);
|
||||
svg_defs
|
||||
}
|
||||
|
||||
pub fn current_state_identifier(&self) -> u64 {
|
||||
@@ -48,7 +54,7 @@ impl Document {
|
||||
|
||||
/// Checks whether each layer under `path` intersects with the provided `quad` and adds all intersection layers as paths to `intersections`.
|
||||
pub fn intersects_quad(&self, quad: Quad, path: &mut Vec<LayerId>, intersections: &mut Vec<Vec<LayerId>>) {
|
||||
self.layer(path).unwrap().intersects_quad(quad, path, intersections);
|
||||
self.layer(&path).unwrap().intersects_quad(quad, path, intersections);
|
||||
}
|
||||
|
||||
/// Checks whether each layer under the root path intersects with the provided `quad` and returns the paths to all intersecting layers.
|
||||
@@ -85,7 +91,7 @@ impl Document {
|
||||
return Ok(&self.root);
|
||||
}
|
||||
let (path, id) = split_path(path)?;
|
||||
self.folder(path)?.layer(id).ok_or_else(|| DocumentError::LayerNotFound(path.into()))
|
||||
self.folder(&path)?.layer(id).ok_or_else(|| DocumentError::LayerNotFound(path.into()))
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the layer or folder at the path.
|
||||
@@ -172,7 +178,7 @@ impl Document {
|
||||
}
|
||||
|
||||
pub fn folder_children_paths(&self, path: &[LayerId]) -> Vec<Vec<LayerId>> {
|
||||
if let Ok(folder) = self.folder(path) {
|
||||
if let Ok(folder) = self.folder(&path) {
|
||||
folder.list_layers().iter().map(|f| [path, &[*f]].concat()).collect()
|
||||
} else {
|
||||
vec![]
|
||||
@@ -251,7 +257,7 @@ impl Document {
|
||||
let mut layer_id = None;
|
||||
if let Ok((path, id)) = split_path(path) {
|
||||
layer_id = Some(id);
|
||||
self.mark_as_dirty(path)?;
|
||||
self.mark_as_dirty(&path)?;
|
||||
folder = self.folder_mut(path)?;
|
||||
if let Some(folder_layer) = folder.layer_mut(id) {
|
||||
*folder_layer = layer;
|
||||
@@ -294,12 +300,12 @@ impl Document {
|
||||
/// Deletes the layer specified by `path`.
|
||||
pub fn delete(&mut self, path: &[LayerId]) -> Result<(), DocumentError> {
|
||||
let (path, id) = split_path(path)?;
|
||||
self.mark_as_dirty(path)?;
|
||||
self.mark_as_dirty(&path)?;
|
||||
self.folder_mut(path)?.remove_layer(id)
|
||||
}
|
||||
|
||||
pub fn visible_layers(&self, path: &mut Vec<LayerId>, paths: &mut Vec<Vec<LayerId>>) -> Result<(), DocumentError> {
|
||||
if !self.layer(path)?.visible {
|
||||
if !self.layer(&path)?.visible {
|
||||
return Ok(());
|
||||
}
|
||||
if let Ok(folder) = self.folder(&path) {
|
||||
@@ -315,13 +321,13 @@ impl Document {
|
||||
}
|
||||
|
||||
pub fn viewport_bounding_box(&self, path: &[LayerId]) -> Result<Option<[DVec2; 2]>, DocumentError> {
|
||||
let layer = self.layer(path)?;
|
||||
let layer = self.layer(&path)?;
|
||||
let transform = self.multiply_transforms(path)?;
|
||||
Ok(layer.data.bounding_box(transform))
|
||||
}
|
||||
|
||||
pub fn bounding_box_and_transform(&self, path: &[LayerId]) -> Result<Option<([DVec2; 2], DAffine2)>, DocumentError> {
|
||||
let layer = self.layer(path)?;
|
||||
let layer = self.layer(&path)?;
|
||||
let transform = self.multiply_transforms(&path[..path.len() - 1])?;
|
||||
Ok(layer.data.bounding_box(layer.transform).map(|bounds| (bounds, transform)))
|
||||
}
|
||||
@@ -348,7 +354,7 @@ impl Document {
|
||||
}
|
||||
|
||||
pub fn mark_downstream_as_dirty(&mut self, path: &[LayerId]) -> Result<(), DocumentError> {
|
||||
let mut layer = self.layer_mut(path)?;
|
||||
let mut layer = self.layer_mut(&path)?;
|
||||
layer.cache_dirty = true;
|
||||
|
||||
let mut path = path.to_vec();
|
||||
@@ -427,59 +433,59 @@ impl Document {
|
||||
|
||||
/// Mutate the document by applying the `operation` to it. If the operation necessitates a
|
||||
/// reaction from the frontend, responses may be returned.
|
||||
pub fn handle_operation(&mut self, operation: &Operation) -> Result<Option<Vec<DocumentResponse>>, DocumentError> {
|
||||
pub fn handle_operation(&mut self, operation: Operation) -> Result<Option<Vec<DocumentResponse>>, DocumentError> {
|
||||
use DocumentResponse::*;
|
||||
|
||||
operation.pseudo_hash().hash(&mut self.state_identifier);
|
||||
|
||||
let responses = match &operation {
|
||||
let responses = match operation {
|
||||
Operation::AddEllipse { path, insert_index, transform, style } => {
|
||||
let layer = Layer::new(LayerDataType::Shape(ShapeLayer::ellipse(*style)), *transform);
|
||||
let layer = Layer::new(LayerDataType::Shape(ShapeLayer::ellipse(style)), transform);
|
||||
|
||||
self.set_layer(path, layer, *insert_index)?;
|
||||
self.set_layer(&path, layer, insert_index)?;
|
||||
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(path)].concat())
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::AddOverlayEllipse { path, transform, style } => {
|
||||
let mut ellipse = ShapeLayer::ellipse(*style);
|
||||
let mut ellipse = ShapeLayer::ellipse(style);
|
||||
ellipse.render_index = -1;
|
||||
|
||||
let layer = Layer::new(LayerDataType::Shape(ellipse), *transform);
|
||||
self.set_layer(path, layer, -1)?;
|
||||
let layer = Layer::new(LayerDataType::Shape(ellipse), transform);
|
||||
self.set_layer(&path, layer, -1)?;
|
||||
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }]].concat())
|
||||
Some([vec![DocumentChanged, CreatedLayer { path }]].concat())
|
||||
}
|
||||
Operation::AddRect { path, insert_index, transform, style } => {
|
||||
let layer = Layer::new(LayerDataType::Shape(ShapeLayer::rectangle(*style)), *transform);
|
||||
let layer = Layer::new(LayerDataType::Shape(ShapeLayer::rectangle(style)), transform);
|
||||
|
||||
self.set_layer(path, layer, *insert_index)?;
|
||||
self.set_layer(&path, layer, insert_index)?;
|
||||
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(path)].concat())
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::AddOverlayRect { path, transform, style } => {
|
||||
let mut rect = ShapeLayer::rectangle(*style);
|
||||
let mut rect = ShapeLayer::rectangle(style);
|
||||
rect.render_index = -1;
|
||||
|
||||
let layer = Layer::new(LayerDataType::Shape(rect), *transform);
|
||||
self.set_layer(path, layer, -1)?;
|
||||
let layer = Layer::new(LayerDataType::Shape(rect), transform);
|
||||
self.set_layer(&path, layer, -1)?;
|
||||
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }]].concat())
|
||||
Some([vec![DocumentChanged, CreatedLayer { path }]].concat())
|
||||
}
|
||||
Operation::AddLine { path, insert_index, transform, style } => {
|
||||
let layer = Layer::new(LayerDataType::Shape(ShapeLayer::line(*style)), *transform);
|
||||
let layer = Layer::new(LayerDataType::Shape(ShapeLayer::line(style)), transform);
|
||||
|
||||
self.set_layer(path, layer, *insert_index)?;
|
||||
self.set_layer(&path, layer, insert_index)?;
|
||||
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(path)].concat())
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::AddOverlayLine { path, transform, style } => {
|
||||
let mut line = ShapeLayer::line(*style);
|
||||
let mut line = ShapeLayer::line(style);
|
||||
line.render_index = -1;
|
||||
|
||||
let layer = Layer::new(LayerDataType::Shape(line), *transform);
|
||||
self.set_layer(path, layer, -1)?;
|
||||
let layer = Layer::new(LayerDataType::Shape(line), transform);
|
||||
self.set_layer(&path, layer, -1)?;
|
||||
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }]].concat())
|
||||
Some([vec![DocumentChanged, CreatedLayer { path }]].concat())
|
||||
}
|
||||
Operation::AddText {
|
||||
path,
|
||||
@@ -490,22 +496,22 @@ impl Document {
|
||||
style,
|
||||
size,
|
||||
} => {
|
||||
let layer = Layer::new(LayerDataType::Text(TextLayer::new(text.clone(), *style, *size)), *transform);
|
||||
let layer = Layer::new(LayerDataType::Text(TextLayer::new(text.clone(), style, size)), transform);
|
||||
|
||||
self.set_layer(path, layer, *insert_index)?;
|
||||
self.set_layer(&path, layer, insert_index)?;
|
||||
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(path)].concat())
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::SetTextEditability { path, editable } => {
|
||||
self.layer_mut(path)?.as_text_mut()?.editable = *editable;
|
||||
self.mark_as_dirty(path)?;
|
||||
self.layer_mut(&path)?.as_text_mut()?.editable = editable;
|
||||
self.mark_as_dirty(&path)?;
|
||||
Some(vec![DocumentChanged])
|
||||
}
|
||||
Operation::SetTextContent { path, new_text } => {
|
||||
self.layer_mut(path)?.as_text_mut()?.update_text(new_text.clone());
|
||||
self.mark_as_dirty(path)?;
|
||||
self.layer_mut(&path)?.as_text_mut()?.update_text(new_text.clone());
|
||||
self.mark_as_dirty(&path)?;
|
||||
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(path)].concat())
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::AddNgon {
|
||||
path,
|
||||
@@ -514,20 +520,20 @@ impl Document {
|
||||
style,
|
||||
sides,
|
||||
} => {
|
||||
let layer = Layer::new(LayerDataType::Shape(ShapeLayer::ngon(*sides, *style)), *transform);
|
||||
let layer = Layer::new(LayerDataType::Shape(ShapeLayer::ngon(sides, style)), transform);
|
||||
|
||||
self.set_layer(path, layer, *insert_index)?;
|
||||
self.set_layer(&path, layer, insert_index)?;
|
||||
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(path)].concat())
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::AddOverlayShape { path, style, bez_path, closed } => {
|
||||
let mut shape = ShapeLayer::from_bez_path(bez_path.clone(), *style, *closed);
|
||||
let mut shape = ShapeLayer::from_bez_path(bez_path.clone(), style, closed);
|
||||
shape.render_index = -1;
|
||||
|
||||
let layer = Layer::new(LayerDataType::Shape(shape), DAffine2::IDENTITY.to_cols_array());
|
||||
self.set_layer(path, layer, -1)?;
|
||||
self.set_layer(&path, layer, -1)?;
|
||||
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }]].concat())
|
||||
Some([vec![DocumentChanged, CreatedLayer { path }]].concat())
|
||||
}
|
||||
Operation::AddShape {
|
||||
path,
|
||||
@@ -537,9 +543,9 @@ impl Document {
|
||||
bez_path,
|
||||
closed,
|
||||
} => {
|
||||
let shape = ShapeLayer::from_bez_path(bez_path.clone(), *style, *closed);
|
||||
self.set_layer(path, Layer::new(LayerDataType::Shape(shape), *transform), *insert_index)?;
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }]].concat())
|
||||
let shape = ShapeLayer::from_bez_path(bez_path.clone(), style, closed);
|
||||
self.set_layer(&path, Layer::new(LayerDataType::Shape(shape), transform), insert_index)?;
|
||||
Some([vec![DocumentChanged, CreatedLayer { path }]].concat())
|
||||
}
|
||||
Operation::AddPolyline {
|
||||
path,
|
||||
@@ -549,8 +555,8 @@ impl Document {
|
||||
style,
|
||||
} => {
|
||||
let points: Vec<glam::DVec2> = points.iter().map(|&it| it.into()).collect();
|
||||
self.set_layer(path, Layer::new(LayerDataType::Shape(ShapeLayer::poly_line(points, *style)), *transform), *insert_index)?;
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(path)].concat())
|
||||
self.set_layer(&path, Layer::new(LayerDataType::Shape(ShapeLayer::poly_line(points, style)), transform), insert_index)?;
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::BooleanOperation { operation, selected } => {
|
||||
// TODO: proper difference
|
||||
@@ -565,13 +571,13 @@ impl Document {
|
||||
let mut responses = Vec::new();
|
||||
if selected.len() > 1 && selected.len() < 3 {
|
||||
// ? apparently `selected` should be reversed
|
||||
let mut shapes = self.transformed_shapes(selected)?;
|
||||
let mut shapes = self.transformed_shapes(&selected)?;
|
||||
let mut shape_drain = shapes.drain(..).rev();
|
||||
let new_shapes = boolean_operation(*operation, shape_drain.next().unwrap(), shape_drain.next().unwrap())?;
|
||||
let new_shapes = boolean_operation(operation, shape_drain.next().unwrap(), shape_drain.next().unwrap())?;
|
||||
|
||||
for path in selected {
|
||||
self.delete(path)?;
|
||||
responses.push(DocumentResponse::DeletedLayer { path: path.clone() })
|
||||
self.delete(&path)?;
|
||||
responses.push(DocumentResponse::DeletedLayer { path })
|
||||
}
|
||||
for new_shape in new_shapes {
|
||||
let new_id = self.add_layer(&[], Layer::new(LayerDataType::Shape(new_shape), DAffine2::IDENTITY.to_cols_array()), -1)?;
|
||||
@@ -588,8 +594,8 @@ impl Document {
|
||||
style,
|
||||
} => {
|
||||
let points: Vec<glam::DVec2> = points.iter().map(|&it| it.into()).collect();
|
||||
self.set_layer(path, Layer::new(LayerDataType::Shape(ShapeLayer::spline(points, *style)), *transform), *insert_index)?;
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(path)].concat())
|
||||
self.set_layer(&path, Layer::new(LayerDataType::Shape(ShapeLayer::spline(points, style)), transform), insert_index)?;
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::DeleteLayer { path } => {
|
||||
fn aggregate_deletions(folder: &FolderLayer, path: &mut Vec<LayerId>, responses: &mut Vec<DocumentResponse>) {
|
||||
@@ -603,10 +609,10 @@ impl Document {
|
||||
}
|
||||
}
|
||||
let mut responses = Vec::new();
|
||||
if let Ok(folder) = self.folder(path) {
|
||||
if let Ok(folder) = self.folder(&path) {
|
||||
aggregate_deletions(folder, &mut path.clone(), &mut responses)
|
||||
};
|
||||
self.delete(path)?;
|
||||
self.delete(&path)?;
|
||||
|
||||
let (folder, _) = split_path(path.as_slice()).unwrap_or((&[], 0));
|
||||
responses.extend([DocumentChanged, DeletedLayer { path: path.clone() }, FolderChanged { path: folder.to_vec() }]);
|
||||
@@ -618,10 +624,10 @@ impl Document {
|
||||
layer,
|
||||
insert_index,
|
||||
} => {
|
||||
let (folder_path, layer_id) = split_path(destination_path)?;
|
||||
let (folder_path, layer_id) = split_path(&destination_path)?;
|
||||
let folder = self.folder_mut(folder_path)?;
|
||||
folder.add_layer(layer.clone(), Some(layer_id), *insert_index).ok_or(DocumentError::IndexOutOfBounds)?;
|
||||
self.mark_as_dirty(destination_path)?;
|
||||
folder.add_layer(layer.clone(), Some(layer_id), insert_index).ok_or(DocumentError::IndexOutOfBounds)?;
|
||||
self.mark_as_dirty(&destination_path)?;
|
||||
|
||||
fn aggregate_insertions(folder: &FolderLayer, path: &mut Vec<LayerId>, responses: &mut Vec<DocumentResponse>) {
|
||||
for (id, layer) in folder.layer_ids.iter().zip(folder.layers()) {
|
||||
@@ -635,16 +641,16 @@ impl Document {
|
||||
}
|
||||
|
||||
let mut responses = Vec::new();
|
||||
if let Ok(folder) = self.folder(destination_path) {
|
||||
aggregate_insertions(folder, &mut destination_path.clone(), &mut responses)
|
||||
if let Ok(folder) = self.folder(&destination_path) {
|
||||
aggregate_insertions(folder, &mut destination_path.as_slice().to_vec(), &mut responses)
|
||||
};
|
||||
|
||||
responses.extend([DocumentChanged, CreatedLayer { path: destination_path.clone() }, FolderChanged { path: folder_path.to_vec() }]);
|
||||
responses.extend(update_thumbnails_upstream(destination_path));
|
||||
responses.extend(update_thumbnails_upstream(&destination_path));
|
||||
Some(responses)
|
||||
}
|
||||
Operation::DuplicateLayer { path } => {
|
||||
let layer = self.layer(path)?.clone();
|
||||
let layer = self.layer(&path)?.clone();
|
||||
let (folder_path, _) = split_path(path.as_slice()).unwrap_or((&[], 0));
|
||||
let folder = self.folder_mut(folder_path)?;
|
||||
if let Some(new_layer_id) = folder.add_layer(layer, None, -1) {
|
||||
@@ -662,126 +668,123 @@ impl Document {
|
||||
}
|
||||
}
|
||||
Operation::RenameLayer { layer_path: path, new_name: name } => {
|
||||
self.layer_mut(path)?.name = Some(name.clone());
|
||||
Some(vec![LayerChanged { path: path.clone() }])
|
||||
self.layer_mut(&path)?.name = Some(name.clone());
|
||||
Some(vec![LayerChanged { path }])
|
||||
}
|
||||
Operation::CreateFolder { path } => {
|
||||
self.set_layer(path, Layer::new(LayerDataType::Folder(FolderLayer::default()), DAffine2::IDENTITY.to_cols_array()), -1)?;
|
||||
self.mark_as_dirty(path)?;
|
||||
self.set_layer(&path, Layer::new(LayerDataType::Folder(FolderLayer::default()), DAffine2::IDENTITY.to_cols_array()), -1)?;
|
||||
self.mark_as_dirty(&path)?;
|
||||
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(path)].concat())
|
||||
Some([vec![DocumentChanged, CreatedLayer { path: path.clone() }], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::TransformLayer { path, transform } => {
|
||||
let layer = self.layer_mut(path).unwrap();
|
||||
let transform = DAffine2::from_cols_array(transform) * layer.transform;
|
||||
let layer = self.layer_mut(&path).unwrap();
|
||||
let transform = DAffine2::from_cols_array(&transform) * layer.transform;
|
||||
layer.transform = transform;
|
||||
self.mark_as_dirty(path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(path)].concat())
|
||||
self.mark_as_dirty(&path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::TransformLayerInViewport { path, transform } => {
|
||||
let transform = DAffine2::from_cols_array(transform);
|
||||
self.apply_transform_relative_to_viewport(path, transform)?;
|
||||
self.mark_as_dirty(path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(path)].concat())
|
||||
let transform = DAffine2::from_cols_array(&transform);
|
||||
self.apply_transform_relative_to_viewport(&path, transform)?;
|
||||
self.mark_as_dirty(&path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::SetLayerTransformInViewport { path, transform } => {
|
||||
let transform = DAffine2::from_cols_array(transform);
|
||||
self.set_transform_relative_to_viewport(path, transform)?;
|
||||
self.mark_as_dirty(path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(path)].concat())
|
||||
let transform = DAffine2::from_cols_array(&transform);
|
||||
self.set_transform_relative_to_viewport(&path, transform)?;
|
||||
self.mark_as_dirty(&path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::SetShapePath { path, bez_path } => {
|
||||
self.mark_as_dirty(path)?;
|
||||
self.mark_as_dirty(&path)?;
|
||||
|
||||
if let LayerDataType::Shape(shape) = &mut self.layer_mut(path)?.data {
|
||||
if let LayerDataType::Shape(shape) = &mut self.layer_mut(&path)?.data {
|
||||
shape.path = bez_path.clone();
|
||||
}
|
||||
Some(vec![DocumentChanged, LayerChanged { path: path.clone() }])
|
||||
Some(vec![DocumentChanged, LayerChanged { path }])
|
||||
}
|
||||
Operation::SetShapePathInViewport { path, bez_path, transform } => {
|
||||
let transform = DAffine2::from_cols_array(transform);
|
||||
self.set_transform_relative_to_viewport(path, transform)?;
|
||||
self.mark_as_dirty(path)?;
|
||||
let transform = DAffine2::from_cols_array(&transform);
|
||||
self.set_transform_relative_to_viewport(&path, transform)?;
|
||||
self.mark_as_dirty(&path)?;
|
||||
|
||||
if let LayerDataType::Text(t) = &mut self.layer_mut(path)?.data {
|
||||
if let LayerDataType::Text(t) = &mut self.layer_mut(&path)?.data {
|
||||
let bezpath = t.to_bez_path();
|
||||
self.layer_mut(path)?.data = layers::layer_info::LayerDataType::Shape(ShapeLayer::from_bez_path(bezpath, t.style, true));
|
||||
self.layer_mut(&path)?.data = layers::layer_info::LayerDataType::Shape(ShapeLayer::from_bez_path(bezpath, t.style.clone(), true));
|
||||
}
|
||||
|
||||
if let LayerDataType::Shape(shape) = &mut self.layer_mut(path)?.data {
|
||||
if let LayerDataType::Shape(shape) = &mut self.layer_mut(&path)?.data {
|
||||
shape.path = bez_path.clone();
|
||||
}
|
||||
Some([vec![DocumentChanged, LayerChanged { path: path.clone() }], update_thumbnails_upstream(path)].concat())
|
||||
Some([vec![DocumentChanged, LayerChanged { path: path.clone() }], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::TransformLayerInScope { path, transform, scope } => {
|
||||
let transform = DAffine2::from_cols_array(transform);
|
||||
let scope = DAffine2::from_cols_array(scope);
|
||||
self.transform_relative_to_scope(path, Some(scope), transform)?;
|
||||
self.mark_as_dirty(path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(path)].concat())
|
||||
let transform = DAffine2::from_cols_array(&transform);
|
||||
let scope = DAffine2::from_cols_array(&scope);
|
||||
self.transform_relative_to_scope(&path, Some(scope), transform)?;
|
||||
self.mark_as_dirty(&path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::SetLayerTransformInScope { path, transform, scope } => {
|
||||
let transform = DAffine2::from_cols_array(transform);
|
||||
let scope = DAffine2::from_cols_array(scope);
|
||||
self.set_transform_relative_to_scope(path, Some(scope), transform)?;
|
||||
self.mark_as_dirty(path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(path)].concat())
|
||||
let transform = DAffine2::from_cols_array(&transform);
|
||||
let scope = DAffine2::from_cols_array(&scope);
|
||||
self.set_transform_relative_to_scope(&path, Some(scope), transform)?;
|
||||
self.mark_as_dirty(&path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::SetLayerTransform { path, transform } => {
|
||||
let transform = DAffine2::from_cols_array(transform);
|
||||
let layer = self.layer_mut(path)?;
|
||||
let transform = DAffine2::from_cols_array(&transform);
|
||||
let layer = self.layer_mut(&path)?;
|
||||
layer.transform = transform;
|
||||
self.mark_as_dirty(path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(path)].concat())
|
||||
self.mark_as_dirty(&path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::ToggleLayerVisibility { path } => {
|
||||
self.mark_as_dirty(path)?;
|
||||
let layer = self.layer_mut(path)?;
|
||||
self.mark_as_dirty(&path)?;
|
||||
let layer = self.layer_mut(&path)?;
|
||||
layer.visible = !layer.visible;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(path)].concat())
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::SetLayerVisibility { path, visible } => {
|
||||
self.mark_as_dirty(path)?;
|
||||
let layer = self.layer_mut(path)?;
|
||||
layer.visible = *visible;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(path)].concat())
|
||||
self.mark_as_dirty(&path)?;
|
||||
let layer = self.layer_mut(&path)?;
|
||||
layer.visible = visible;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::SetLayerName { path, name } => {
|
||||
self.mark_as_dirty(path)?;
|
||||
let mut layer = self.layer_mut(path)?;
|
||||
self.mark_as_dirty(&path)?;
|
||||
let mut layer = self.layer_mut(&path)?;
|
||||
layer.name = if name.as_str() == "" { None } else { Some(name.clone()) };
|
||||
|
||||
Some(vec![LayerChanged { path: path.clone() }])
|
||||
Some(vec![LayerChanged { path }])
|
||||
}
|
||||
Operation::SetLayerBlendMode { path, blend_mode } => {
|
||||
self.mark_as_dirty(path)?;
|
||||
self.layer_mut(path)?.blend_mode = *blend_mode;
|
||||
self.mark_as_dirty(&path)?;
|
||||
self.layer_mut(&path)?.blend_mode = blend_mode;
|
||||
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(path)].concat())
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::SetLayerOpacity { path, opacity } => {
|
||||
self.mark_as_dirty(path)?;
|
||||
self.layer_mut(path)?.opacity = *opacity;
|
||||
self.mark_as_dirty(&path)?;
|
||||
self.layer_mut(&path)?.opacity = opacity;
|
||||
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(path)].concat())
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::SetLayerStyle { path, style } => {
|
||||
let layer = self.layer_mut(path)?;
|
||||
let layer = self.layer_mut(&path)?;
|
||||
match &mut layer.data {
|
||||
LayerDataType::Shape(s) => s.style = *style,
|
||||
LayerDataType::Shape(s) => s.style = style,
|
||||
_ => return Err(DocumentError::NotAShape),
|
||||
}
|
||||
self.mark_as_dirty(path)?;
|
||||
Some([vec![DocumentChanged, LayerChanged { path: path.clone() }], update_thumbnails_upstream(path)].concat())
|
||||
self.mark_as_dirty(&path)?;
|
||||
Some([vec![DocumentChanged, LayerChanged { path: path.clone() }], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
Operation::SetLayerFill { path, color } => {
|
||||
let layer = self.layer_mut(path)?;
|
||||
match &mut layer.data {
|
||||
LayerDataType::Shape(s) => s.style.set_fill(layers::style::Fill::new(*color)),
|
||||
_ => return Err(DocumentError::NotAShape),
|
||||
}
|
||||
self.mark_as_dirty(path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(path)].concat())
|
||||
Operation::SetLayerFill { path, fill } => {
|
||||
let layer = self.layer_mut(&path)?;
|
||||
layer.style_mut()?.set_fill(fill);
|
||||
self.mark_as_dirty(&path)?;
|
||||
Some([vec![DocumentChanged], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
};
|
||||
Ok(responses)
|
||||
|
||||
@@ -15,9 +15,9 @@ pub struct FolderLayer {
|
||||
}
|
||||
|
||||
impl LayerData for FolderLayer {
|
||||
fn render(&mut self, svg: &mut String, transforms: &mut Vec<glam::DAffine2>, view_mode: ViewMode) {
|
||||
fn render(&mut self, svg: &mut String, svg_defs: &mut String, transforms: &mut Vec<glam::DAffine2>, view_mode: ViewMode) {
|
||||
for layer in &mut self.layers {
|
||||
let _ = writeln!(svg, "{}", layer.render(transforms, view_mode));
|
||||
let _ = writeln!(svg, "{}", layer.render(transforms, view_mode, svg_defs));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::blend_mode::BlendMode;
|
||||
use super::folder_layer::FolderLayer;
|
||||
use super::shape_layer::ShapeLayer;
|
||||
use super::style::ViewMode;
|
||||
use super::style::{PathStyle, ViewMode};
|
||||
use super::text_layer::TextLayer;
|
||||
use crate::intersection::Quad;
|
||||
use crate::DocumentError;
|
||||
@@ -37,14 +37,14 @@ impl LayerDataType {
|
||||
}
|
||||
|
||||
pub trait LayerData {
|
||||
fn render(&mut self, svg: &mut String, transforms: &mut Vec<glam::DAffine2>, view_mode: ViewMode);
|
||||
fn render(&mut self, svg: &mut String, svg_defs: &mut String, transforms: &mut Vec<glam::DAffine2>, view_mode: ViewMode);
|
||||
fn intersects_quad(&self, quad: Quad, path: &mut Vec<LayerId>, intersections: &mut Vec<Vec<LayerId>>);
|
||||
fn bounding_box(&self, transform: glam::DAffine2) -> Option<[DVec2; 2]>;
|
||||
}
|
||||
|
||||
impl LayerData for LayerDataType {
|
||||
fn render(&mut self, svg: &mut String, transforms: &mut Vec<glam::DAffine2>, view_mode: ViewMode) {
|
||||
self.inner_mut().render(svg, transforms, view_mode)
|
||||
fn render(&mut self, svg: &mut String, svg_defs: &mut String, transforms: &mut Vec<glam::DAffine2>, view_mode: ViewMode) {
|
||||
self.inner_mut().render(svg, svg_defs, transforms, view_mode)
|
||||
}
|
||||
|
||||
fn intersects_quad(&self, quad: Quad, path: &mut Vec<LayerId>, intersections: &mut Vec<Vec<LayerId>>) {
|
||||
@@ -78,6 +78,8 @@ pub struct Layer {
|
||||
pub cache: String,
|
||||
#[serde(skip)]
|
||||
pub thumbnail_cache: String,
|
||||
#[serde(skip)]
|
||||
pub svg_defs_cache: String,
|
||||
#[serde(skip, default = "return_true")]
|
||||
pub cache_dirty: bool,
|
||||
pub blend_mode: BlendMode,
|
||||
@@ -93,6 +95,7 @@ impl Layer {
|
||||
transform: glam::DAffine2::from_cols_array(&transform),
|
||||
cache: String::new(),
|
||||
thumbnail_cache: String::new(),
|
||||
svg_defs_cache: String::new(),
|
||||
cache_dirty: true,
|
||||
blend_mode: BlendMode::Normal,
|
||||
opacity: 1.,
|
||||
@@ -103,7 +106,7 @@ impl Layer {
|
||||
LayerIter { stack: vec![self] }
|
||||
}
|
||||
|
||||
pub fn render(&mut self, transforms: &mut Vec<DAffine2>, view_mode: ViewMode) -> &str {
|
||||
pub fn render(&mut self, transforms: &mut Vec<DAffine2>, view_mode: ViewMode, svg_defs: &mut String) -> &str {
|
||||
if !self.visible {
|
||||
return "";
|
||||
}
|
||||
@@ -111,7 +114,8 @@ impl Layer {
|
||||
if self.cache_dirty {
|
||||
transforms.push(self.transform);
|
||||
self.thumbnail_cache.clear();
|
||||
self.data.render(&mut self.thumbnail_cache, transforms, view_mode);
|
||||
self.svg_defs_cache.clear();
|
||||
self.data.render(&mut self.thumbnail_cache, &mut self.svg_defs_cache, transforms, view_mode);
|
||||
|
||||
self.cache.clear();
|
||||
let _ = writeln!(self.cache, r#"<g transform="matrix("#);
|
||||
@@ -128,6 +132,7 @@ impl Layer {
|
||||
transforms.pop();
|
||||
self.cache_dirty = false;
|
||||
}
|
||||
svg_defs.push_str(&self.svg_defs_cache);
|
||||
|
||||
self.cache.as_str()
|
||||
}
|
||||
@@ -176,6 +181,22 @@ impl Layer {
|
||||
_ => Err(DocumentError::NotText),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn style(&self) -> Result<&PathStyle, DocumentError> {
|
||||
match &self.data {
|
||||
LayerDataType::Shape(s) => Ok(&s.style),
|
||||
LayerDataType::Text(t) => Ok(&t.style),
|
||||
_ => return Err(DocumentError::NotAShape),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn style_mut(&mut self) -> Result<&mut PathStyle, DocumentError> {
|
||||
match &mut self.data {
|
||||
LayerDataType::Shape(s) => Ok(&mut s.style),
|
||||
LayerDataType::Text(t) => Ok(&mut t.style),
|
||||
_ => return Err(DocumentError::NotAShape),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for Layer {
|
||||
@@ -187,6 +208,7 @@ impl Clone for Layer {
|
||||
transform: self.transform,
|
||||
cache: String::new(),
|
||||
thumbnail_cache: String::new(),
|
||||
svg_defs_cache: String::new(),
|
||||
cache_dirty: true,
|
||||
blend_mode: self.blend_mode,
|
||||
opacity: self.opacity,
|
||||
|
||||
@@ -21,7 +21,7 @@ pub struct ShapeLayer {
|
||||
}
|
||||
|
||||
impl LayerData for ShapeLayer {
|
||||
fn render(&mut self, svg: &mut String, transforms: &mut Vec<DAffine2>, view_mode: ViewMode) {
|
||||
fn render(&mut self, svg: &mut String, svg_defs: &mut String, transforms: &mut Vec<DAffine2>, view_mode: ViewMode) {
|
||||
let mut path = self.path.clone();
|
||||
let transform = self.transform(transforms, view_mode);
|
||||
let inverse = transform.inverse();
|
||||
@@ -36,7 +36,7 @@ impl LayerData for ShapeLayer {
|
||||
let _ = svg.write_str(&(entry.to_string() + if i == 5 { "" } else { "," }));
|
||||
});
|
||||
let _ = svg.write_str(r#")">"#);
|
||||
let _ = write!(svg, r#"<path d="{}" {} />"#, path.to_svg(), self.style.render(view_mode));
|
||||
let _ = write!(svg, r#"<path d="{}" {} />"#, path.to_svg(), self.style.render(view_mode, svg_defs));
|
||||
let _ = svg.write_str("</g>");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
use std::fmt::Write;
|
||||
|
||||
use crate::color::Color;
|
||||
use crate::consts::{LAYER_OUTLINE_STROKE_COLOR, LAYER_OUTLINE_STROKE_WIDTH};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use glam::{DAffine2, DVec2};
|
||||
|
||||
const OPACITY_PRECISION: usize = 3;
|
||||
|
||||
fn format_opacity(name: &str, opacity: f32) -> String {
|
||||
@@ -26,27 +30,106 @@ impl Default for ViewMode {
|
||||
}
|
||||
}
|
||||
|
||||
/// A gradient fill.
|
||||
///
|
||||
/// Contains the start and end points, along with the colors at varying points along the length.
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
|
||||
pub struct Fill {
|
||||
color: Color,
|
||||
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
|
||||
pub struct Gradient {
|
||||
pub start: DVec2,
|
||||
pub end: DVec2,
|
||||
pub transform: DAffine2,
|
||||
pub positions: Vec<(f64, Color)>,
|
||||
uuid: u64,
|
||||
}
|
||||
impl Gradient {
|
||||
/// Constructs a new gradient with the colors at 0 and 1 specified.
|
||||
pub fn new(start: DVec2, start_color: Color, end: DVec2, end_color: Color, transform: DAffine2, uuid: u64) -> Self {
|
||||
Gradient {
|
||||
start,
|
||||
end,
|
||||
positions: vec![(0., start_color), (1., end_color)],
|
||||
transform,
|
||||
uuid,
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds the gradient def with the uuid specified
|
||||
fn render_defs(&self, svg_defs: &mut String) {
|
||||
let positions = self
|
||||
.positions
|
||||
.iter()
|
||||
.map(|(position, color)| format!(r##"<stop offset="{}" stop-color="#{}" />"##, position, color.rgba_hex()))
|
||||
.collect::<String>();
|
||||
|
||||
let start = self.transform.inverse().transform_point2(self.start);
|
||||
let end = self.transform.inverse().transform_point2(self.end);
|
||||
|
||||
let transform = self
|
||||
.transform
|
||||
.to_cols_array()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, entry)| entry.to_string() + if i == 5 { "" } else { "," })
|
||||
.collect::<String>();
|
||||
|
||||
let _ = write!(
|
||||
svg_defs,
|
||||
r#"<linearGradient id="{}" x1="{}" x2="{}" y1="{}" y2="{}" gradientTransform="matrix({})">{}</linearGradient>"#,
|
||||
self.uuid, start.x, end.x, start.y, end.y, transform, positions
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Describes the fill of a layer.
|
||||
///
|
||||
/// Can be None, solid or potentially some sort of image or pattern
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub enum Fill {
|
||||
None,
|
||||
Solid(Color),
|
||||
LinearGradient(Gradient),
|
||||
}
|
||||
|
||||
impl Default for Fill {
|
||||
fn default() -> Self {
|
||||
Self::None
|
||||
}
|
||||
}
|
||||
|
||||
impl Fill {
|
||||
pub fn new(color: Color) -> Self {
|
||||
Self { color }
|
||||
/// Construct a new solid fill
|
||||
pub fn solid(color: Color) -> Self {
|
||||
Self::Solid(color)
|
||||
}
|
||||
|
||||
/// Evaluate the color at some point on the fill
|
||||
pub fn color(&self) -> Color {
|
||||
self.color
|
||||
match self {
|
||||
Self::None => Color::BLACK,
|
||||
Self::Solid(color) => *color,
|
||||
// ToDo: Should correctly sample the gradient
|
||||
Self::LinearGradient(Gradient { positions, .. }) => positions[0].1,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(fill: Option<Fill>) -> String {
|
||||
match fill {
|
||||
Some(c) => format!(r##" fill="#{}"{}"##, c.color.rgb_hex(), format_opacity("fill", c.color.a())),
|
||||
None => r#" fill="none""#.to_string(),
|
||||
/// Renders the fill, adding necessary defs.
|
||||
pub fn render(&self, svg_defs: &mut String) -> String {
|
||||
match self {
|
||||
Self::None => r#" fill="none""#.to_string(),
|
||||
Self::Solid(color) => format!(r##" fill="#{}"{}"##, color.rgb_hex(), format_opacity("fill", color.a())),
|
||||
Self::LinearGradient(gradient) => {
|
||||
gradient.render_defs(svg_defs);
|
||||
format!(r##" fill="url('#{}')""##, gradient.uuid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if the fill is not none
|
||||
pub fn is_some(&self) -> bool {
|
||||
*self != Self::None
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -75,19 +158,19 @@ impl Stroke {
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
|
||||
pub struct PathStyle {
|
||||
stroke: Option<Stroke>,
|
||||
fill: Option<Fill>,
|
||||
fill: Fill,
|
||||
}
|
||||
|
||||
impl PathStyle {
|
||||
pub fn new(stroke: Option<Stroke>, fill: Option<Fill>) -> Self {
|
||||
pub fn new(stroke: Option<Stroke>, fill: Fill) -> Self {
|
||||
Self { stroke, fill }
|
||||
}
|
||||
|
||||
pub fn fill(&self) -> Option<Fill> {
|
||||
self.fill
|
||||
pub fn fill(&self) -> &Fill {
|
||||
&self.fill
|
||||
}
|
||||
|
||||
pub fn stroke(&self) -> Option<Stroke> {
|
||||
@@ -95,7 +178,7 @@ impl PathStyle {
|
||||
}
|
||||
|
||||
pub fn set_fill(&mut self, fill: Fill) {
|
||||
self.fill = Some(fill);
|
||||
self.fill = fill;
|
||||
}
|
||||
|
||||
pub fn set_stroke(&mut self, stroke: Stroke) {
|
||||
@@ -103,17 +186,17 @@ impl PathStyle {
|
||||
}
|
||||
|
||||
pub fn clear_fill(&mut self) {
|
||||
self.fill = None;
|
||||
self.fill = Fill::None;
|
||||
}
|
||||
|
||||
pub fn clear_stroke(&mut self) {
|
||||
self.stroke = None;
|
||||
}
|
||||
|
||||
pub fn render(&self, view_mode: ViewMode) -> String {
|
||||
let fill_attribute = match (view_mode, self.fill) {
|
||||
(ViewMode::Outline, _) => Fill::render(None),
|
||||
(_, fill) => Fill::render(fill),
|
||||
pub fn render(&self, view_mode: ViewMode, svg_defs: &mut String) -> String {
|
||||
let fill_attribute = match (view_mode, &self.fill) {
|
||||
(ViewMode::Outline, _) => Fill::None.render(svg_defs),
|
||||
(_, fill) => fill.render(svg_defs),
|
||||
};
|
||||
let stroke_attribute = match (view_mode, self.stroke) {
|
||||
(ViewMode::Outline, _) => Stroke::new(LAYER_OUTLINE_STROKE_COLOR, LAYER_OUTLINE_STROKE_WIDTH).render(),
|
||||
|
||||
@@ -27,7 +27,7 @@ pub struct TextLayer {
|
||||
}
|
||||
|
||||
impl LayerData for TextLayer {
|
||||
fn render(&mut self, svg: &mut String, transforms: &mut Vec<DAffine2>, view_mode: ViewMode) {
|
||||
fn render(&mut self, svg: &mut String, svg_defs: &mut String, transforms: &mut Vec<DAffine2>, view_mode: ViewMode) {
|
||||
let transform = self.transform(transforms, view_mode);
|
||||
let inverse = transform.inverse();
|
||||
if !inverse.is_finite() {
|
||||
@@ -43,24 +43,20 @@ impl LayerData for TextLayer {
|
||||
if self.editable {
|
||||
let _ = write!(
|
||||
svg,
|
||||
r#"<foreignObject transform="matrix({})" style="color: {}"></foreignObject>"#,
|
||||
r#"<foreignObject transform="matrix({})"></foreignObject>"#,
|
||||
transform
|
||||
.to_cols_array()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, entry)| { entry.to_string() + if i == 5 { "" } else { "," } })
|
||||
.collect::<String>(),
|
||||
match self.style.fill() {
|
||||
Some(fill) => format!("#{}", fill.color().rgba_hex()),
|
||||
None => "gray".to_string(),
|
||||
}
|
||||
);
|
||||
} else {
|
||||
let mut path = self.to_bez_path();
|
||||
|
||||
path.apply_affine(glam_to_kurbo(transform));
|
||||
|
||||
let _ = write!(svg, r#"<path d="{}" {} />"#, path.to_svg(), self.style.render(view_mode));
|
||||
let _ = write!(svg, r#"<path d="{}" {} />"#, path.to_svg(), self.style.render(view_mode, svg_defs));
|
||||
}
|
||||
let _ = svg.write_str("</g>");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use crate::boolean_ops::BooleanOperation as BooleanOperationType;
|
||||
use crate::color::Color;
|
||||
use crate::layers::blend_mode::BlendMode;
|
||||
use crate::layers::layer_info::Layer;
|
||||
use crate::layers::style;
|
||||
@@ -179,7 +178,7 @@ pub enum Operation {
|
||||
},
|
||||
SetLayerFill {
|
||||
path: Vec<LayerId>,
|
||||
color: Color,
|
||||
fill: style::Fill,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user