Skip to content

Refactor font loading from per-document to the portfolio #659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions editor/src/communication/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const SIDE_EFFECT_FREE_MESSAGES: &[MessageDiscriminant] = &[
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateDocumentLayerDetails),
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateDocumentLayerTreeStructure),
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateOpenDocumentsList),
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::TriggerFontLoad),
MessageDiscriminant::Tool(ToolMessageDiscriminant::DocumentIsDirty),
];

Expand Down Expand Up @@ -108,6 +109,7 @@ impl Dispatcher {
(
self.message_handlers.portfolio_message_handler.active_document(),
&self.message_handlers.input_preprocessor_message_handler,
self.message_handlers.portfolio_message_handler.font_cache(),
),
&mut self.message_queue,
);
Expand Down
5 changes: 5 additions & 0 deletions editor/src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use graphene::color::Color;
use graphene::layers::text_layer::Font;

// Viewport
pub const VIEWPORT_ZOOM_WHEEL_RATE: f64 = 1. / 600.;
Expand Down Expand Up @@ -65,6 +66,10 @@ pub const FILE_SAVE_SUFFIX: &str = ".graphite";
// Colors
pub const COLOR_ACCENT: Color = Color::from_unsafe(0x00 as f32 / 255., 0xA8 as f32 / 255., 0xFF as f32 / 255.);

// Fonts
pub const DEFAULT_FONT_FAMILY: &str = "Merriweather";
pub const DEFAULT_FONT_STYLE: &str = "Normal (400)";

// Document
pub const GRAPHITE_DOCUMENT_VERSION: &str = "0.0.8"; // Remember to save a simple document and replace the test file at: editor\src\communication\graphite-test-document.graphite
pub const VIEWPORT_ZOOM_TO_FIT_PADDING_SCALE_FACTOR: f32 = 1.05;
4 changes: 3 additions & 1 deletion editor/src/dialog/dialogs/coming_soon_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{layout::widgets::*, message_prelude::FrontendMessage};

use std::fmt::Write;

/// A dialog to notify users of an unfinished issue, optionally with an issue number.
pub struct ComingSoon {
pub issue: Option<i32>,
Expand All @@ -16,7 +18,7 @@ impl PropertyHolder for ComingSoon {
..Default::default()
}))];
if let Some(issue) = self.issue {
details += &format!("— but you can help add it!\nSee issue #{issue} on GitHub.");
let _ = write!(details, "— but you can help add it!\nSee issue #{issue} on GitHub.");
buttons.push(WidgetHolder::new(Widget::TextButton(TextButton {
label: format!("Issue #{issue}"),
min_width: 96,
Expand Down
9 changes: 5 additions & 4 deletions editor/src/document/artboard_message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::message_prelude::*;
use graphene::color::Color;
use graphene::document::Document as GrapheneDocument;
use graphene::layers::style::{self, Fill, ViewMode};
use graphene::layers::text_layer::FontCache;
use graphene::DocumentResponse;
use graphene::Operation as DocumentOperation;

Expand All @@ -22,16 +23,16 @@ impl ArtboardMessageHandler {
}
}

impl MessageHandler<ArtboardMessage, ()> for ArtboardMessageHandler {
impl MessageHandler<ArtboardMessage, &FontCache> for ArtboardMessageHandler {
#[remain::check]
fn process_action(&mut self, message: ArtboardMessage, _: (), responses: &mut VecDeque<Message>) {
fn process_action(&mut self, message: ArtboardMessage, font_cache: &FontCache, responses: &mut VecDeque<Message>) {
use ArtboardMessage::*;

#[remain::sorted]
match message {
// Sub-messages
#[remain::unsorted]
DispatchOperation(operation) => match self.artboards_graphene_document.handle_operation(*operation) {
DispatchOperation(operation) => match self.artboards_graphene_document.handle_operation(*operation, font_cache) {
Ok(Some(document_responses)) => {
for response in document_responses {
match &response {
Expand Down Expand Up @@ -86,7 +87,7 @@ impl MessageHandler<ArtboardMessage, ()> for ArtboardMessageHandler {
} else {
responses.push_back(
FrontendMessage::UpdateDocumentArtboards {
svg: self.artboards_graphene_document.render_root(ViewMode::Normal),
svg: self.artboards_graphene_document.render_root(ViewMode::Normal, font_cache),
}
.into(),
);
Expand Down
8 changes: 0 additions & 8 deletions editor/src/document/document_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,10 @@ pub enum DocumentMessage {
FolderChanged {
affected_folder_path: Vec<LayerId>,
},
FontLoaded {
font_file_url: String,
data: Vec<u8>,
is_default: bool,
},
GroupSelectedLayers,
LayerChanged {
affected_layer_path: Vec<LayerId>,
},
LoadFont {
font_file_url: String,
},
MoveSelectedLayersTo {
folder_path: Vec<LayerId>,
insert_index: isize,
Expand Down
Loading