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:
0HyperCube
2022-06-30 02:18:01 +01:00
committed by Keavon Chambers
co-authored by Keavon Chambers
parent 2e3e079982
commit 020f700c92
22 changed files with 243 additions and 128 deletions
@@ -7,6 +7,7 @@ use crate::layout::layout_message::LayoutTarget;
use crate::layout::widgets::PropertyHolder;
use crate::{dialog, message_prelude::*};
use graphene::layers::layer_info::LayerDataTypeDiscriminant;
use graphene::layers::text_layer::{Font, FontCache};
use graphene::Operation as DocumentOperation;
@@ -47,11 +48,10 @@ impl PortfolioMessageHandler {
// Uses binary search to find the index of the element where number is bigger than i
let new_doc_title_num = doc_title_numbers.binary_search(&0).map_or_else(|e| e, |v| v) + 1;
let name = match new_doc_title_num {
match new_doc_title_num {
1 => DEFAULT_DOCUMENT_NAME.to_string(),
_ => format!("{} {}", DEFAULT_DOCUMENT_NAME, new_doc_title_num),
};
name
}
}
// TODO Fix how this doesn't preserve tab order upon loading new document from *File > Load*
@@ -81,7 +81,7 @@ impl PortfolioMessageHandler {
);
new_document.update_layer_tree_options_bar_widgets(responses, &self.font_cache);
new_document.load_image_data(responses, &new_document.graphene_document.root.data, Vec::new());
new_document.load_layer_resources(responses, &new_document.graphene_document.root.data, Vec::new());
self.documents.insert(document_id, new_document);
@@ -287,7 +287,8 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
is_default,
} => {
self.font_cache.insert(Font::new(font_family, font_style), preview_url, data, is_default);
responses.push_back(DocumentMessage::DirtyRenderDocument.into());
self.active_document_mut().graphene_document.mark_all_layers_of_type_as_dirty(LayerDataTypeDiscriminant::Text);
responses.push_back(DocumentMessage::RenderDocument.into());
}
LoadFont { font, is_default } => {
if !self.font_cache.loaded_font(&font) {
@@ -387,7 +388,7 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
}
.into(),
);
self.active_document().load_image_data(responses, &entry.layer.data, destination_path.clone());
self.active_document().load_layer_resources(responses, &entry.layer.data, destination_path.clone());
responses.push_front(
DocumentOperation::InsertLayer {
layer: entry.layer.clone(),
@@ -428,7 +429,7 @@ impl MessageHandler<PortfolioMessage, &InputPreprocessorMessageHandler> for Port
}
.into(),
);
self.active_document().load_image_data(responses, &entry.layer.data, destination_path.clone());
self.active_document().load_layer_resources(responses, &entry.layer.data, destination_path.clone());
responses.push_front(
DocumentOperation::InsertLayer {
layer: entry.layer.clone(),