Skip to content

Commit 8923b68

Browse files
0HyperCubeKeavon
andcommitted
Refactor font loading from per-document to the portfolio (#659)
* Cleanup default font loading * Refactor fonts * Fix menulist mouse navigation * Format * Formatting * Move default font into consts.rs Co-authored-by: Keavon Chambers <keavon@keavon.com>
1 parent d4539bc commit 8923b68

60 files changed

Lines changed: 826 additions & 842 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

editor/src/communication/dispatcher.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const SIDE_EFFECT_FREE_MESSAGES: &[MessageDiscriminant] = &[
4141
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateDocumentLayerDetails),
4242
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateDocumentLayerTreeStructure),
4343
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::UpdateOpenDocumentsList),
44+
MessageDiscriminant::Frontend(FrontendMessageDiscriminant::TriggerFontLoad),
4445
MessageDiscriminant::Tool(ToolMessageDiscriminant::DocumentIsDirty),
4546
];
4647

@@ -108,6 +109,7 @@ impl Dispatcher {
108109
(
109110
self.message_handlers.portfolio_message_handler.active_document(),
110111
&self.message_handlers.input_preprocessor_message_handler,
112+
self.message_handlers.portfolio_message_handler.font_cache(),
111113
),
112114
&mut self.message_queue,
113115
);

editor/src/consts.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use graphene::color::Color;
2+
use graphene::layers::text_layer::Font;
23

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

69+
// Fonts
70+
pub const DEFAULT_FONT_FAMILY: &str = "Merriweather";
71+
pub const DEFAULT_FONT_STYLE: &str = "Normal (400)";
72+
6873
// Document
6974
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
7075
pub const VIEWPORT_ZOOM_TO_FIT_PADDING_SCALE_FACTOR: f32 = 1.05;

editor/src/dialog/dialogs/coming_soon_dialog.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::{layout::widgets::*, message_prelude::FrontendMessage};
22

3+
use std::fmt::Write;
4+
35
/// A dialog to notify users of an unfinished issue, optionally with an issue number.
46
pub struct ComingSoon {
57
pub issue: Option<i32>,
@@ -16,7 +18,7 @@ impl PropertyHolder for ComingSoon {
1618
..Default::default()
1719
}))];
1820
if let Some(issue) = self.issue {
19-
details += &format!("— but you can help add it!\nSee issue #{issue} on GitHub.");
21+
let _ = write!(details, "— but you can help add it!\nSee issue #{issue} on GitHub.");
2022
buttons.push(WidgetHolder::new(Widget::TextButton(TextButton {
2123
label: format!("Issue #{issue}"),
2224
min_width: 96,

editor/src/document/artboard_message_handler.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::message_prelude::*;
33
use graphene::color::Color;
44
use graphene::document::Document as GrapheneDocument;
55
use graphene::layers::style::{self, Fill, ViewMode};
6+
use graphene::layers::text_layer::FontCache;
67
use graphene::DocumentResponse;
78
use graphene::Operation as DocumentOperation;
89

@@ -22,16 +23,16 @@ impl ArtboardMessageHandler {
2223
}
2324
}
2425

25-
impl MessageHandler<ArtboardMessage, ()> for ArtboardMessageHandler {
26+
impl MessageHandler<ArtboardMessage, &FontCache> for ArtboardMessageHandler {
2627
#[remain::check]
27-
fn process_action(&mut self, message: ArtboardMessage, _: (), responses: &mut VecDeque<Message>) {
28+
fn process_action(&mut self, message: ArtboardMessage, font_cache: &FontCache, responses: &mut VecDeque<Message>) {
2829
use ArtboardMessage::*;
2930

3031
#[remain::sorted]
3132
match message {
3233
// Sub-messages
3334
#[remain::unsorted]
34-
DispatchOperation(operation) => match self.artboards_graphene_document.handle_operation(*operation) {
35+
DispatchOperation(operation) => match self.artboards_graphene_document.handle_operation(*operation, font_cache) {
3536
Ok(Some(document_responses)) => {
3637
for response in document_responses {
3738
match &response {
@@ -86,7 +87,7 @@ impl MessageHandler<ArtboardMessage, ()> for ArtboardMessageHandler {
8687
} else {
8788
responses.push_back(
8889
FrontendMessage::UpdateDocumentArtboards {
89-
svg: self.artboards_graphene_document.render_root(ViewMode::Normal),
90+
svg: self.artboards_graphene_document.render_root(ViewMode::Normal, font_cache),
9091
}
9192
.into(),
9293
);

editor/src/document/document_message.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,10 @@ pub enum DocumentMessage {
7272
FolderChanged {
7373
affected_folder_path: Vec<LayerId>,
7474
},
75-
FontLoaded {
76-
font_file_url: String,
77-
data: Vec<u8>,
78-
is_default: bool,
79-
},
8075
GroupSelectedLayers,
8176
LayerChanged {
8277
affected_layer_path: Vec<LayerId>,
8378
},
84-
LoadFont {
85-
font_file_url: String,
86-
},
8779
MoveSelectedLayersTo {
8880
folder_path: Vec<LayerId>,
8981
insert_index: isize,

0 commit comments

Comments
 (0)