mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-25 03:38:11 +08:00
Image and text bug fixes (#685)
* Image and text bugfixes * Mark only the required layer types as dirty * Fix doctest * Disable selection if empty * Cleanup naming * Simplify cache deleting on export * Minor css style change * Nit Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Keavon Chambers
parent
ee98908d88
commit
2191b09f9f
@@ -3,9 +3,9 @@ use crate::intersection::Quad;
|
||||
use crate::layers;
|
||||
use crate::layers::folder_layer::FolderLayer;
|
||||
use crate::layers::image_layer::ImageLayer;
|
||||
use crate::layers::layer_info::{Layer, LayerData, LayerDataType};
|
||||
use crate::layers::layer_info::{Layer, LayerData, LayerDataType, LayerDataTypeDiscriminant};
|
||||
use crate::layers::shape_layer::ShapeLayer;
|
||||
use crate::layers::style::ViewMode;
|
||||
use crate::layers::style::RenderData;
|
||||
use crate::layers::text_layer::{Font, FontCache, TextLayer};
|
||||
use crate::{DocumentError, DocumentResponse, Operation};
|
||||
|
||||
@@ -42,10 +42,10 @@ 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, font_cache: &FontCache, culling_bounds: Option<[DVec2; 2]>) -> String {
|
||||
pub fn render_root(&mut self, render_data: RenderData) -> String {
|
||||
let mut svg_defs = String::from("<defs>");
|
||||
|
||||
self.root.render(&mut vec![], mode, &mut svg_defs, font_cache, culling_bounds);
|
||||
self.root.render(&mut vec![], &mut svg_defs, render_data);
|
||||
|
||||
svg_defs.push_str("</defs>");
|
||||
|
||||
@@ -375,6 +375,27 @@ impl Document {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Marks all decendants of the specified [Layer] of a specific [LayerDataType] as dirty
|
||||
fn mark_layers_of_type_as_dirty(root: &mut Layer, data_type: LayerDataTypeDiscriminant) -> bool {
|
||||
if let LayerDataType::Folder(folder) = &mut root.data {
|
||||
let mut dirty = false;
|
||||
for layer in folder.layers_mut() {
|
||||
dirty = Self::mark_layers_of_type_as_dirty(layer, data_type) || dirty;
|
||||
}
|
||||
root.cache_dirty = dirty;
|
||||
}
|
||||
if LayerDataTypeDiscriminant::from(&root.data) == data_type {
|
||||
root.cache_dirty = true;
|
||||
}
|
||||
|
||||
root.cache_dirty
|
||||
}
|
||||
|
||||
/// Marks all layers in the [Document] of a specific [LayerDataType] as dirty
|
||||
pub fn mark_all_layers_of_type_as_dirty(&mut self, data_type: LayerDataTypeDiscriminant) -> bool {
|
||||
Self::mark_layers_of_type_as_dirty(&mut self.root, data_type)
|
||||
}
|
||||
|
||||
pub fn transforms(&self, path: &[LayerId]) -> Result<Vec<DAffine2>, DocumentError> {
|
||||
let mut root = &self.root;
|
||||
let mut transforms = vec![self.root.transform];
|
||||
@@ -697,7 +718,7 @@ impl Document {
|
||||
|
||||
text.font = Font::new(font_family, font_style);
|
||||
text.size = size;
|
||||
text.regenerate_path(text.load_face(font_cache));
|
||||
text.cached_path = Some(text.generate_path(text.load_face(font_cache)));
|
||||
self.mark_as_dirty(&path)?;
|
||||
Some([vec![DocumentChanged, LayerChanged { path: path.clone() }], update_thumbnails_upstream(&path)].concat())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user