-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Use system fonts as catalog on Desktop App #4035
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
78d6cb2
d436d36
c9f82ad
8cdcd6e
6ca04e7
c5cfba6
de1cd03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,7 +1,7 @@ | ||||||
| use super::document::utility_types::document_metadata::LayerNodeIdentifier; | ||||||
| use super::document::utility_types::network_interface; | ||||||
| use super::persistent_state::{PersistentStateMessage, PersistentStateMessageContext, PersistentStateMessageHandler}; | ||||||
| use super::utility_types::{CachedData, PanelLayoutSubdivision, PanelType, WorkspacePanelLayout}; | ||||||
| use super::utility_types::{CachedData, FontCatalog, FontCatalogFamily, FontCatalogStyle, PanelLayoutSubdivision, PanelType, WorkspacePanelLayout}; | ||||||
| use crate::application::{Editor, generate_uuid}; | ||||||
| use crate::consts::{DEFAULT_DOCUMENT_NAME, DEFAULT_STROKE_WIDTH, FILE_EXTENSION}; | ||||||
| use crate::messages::animation::TimingInformation; | ||||||
|
|
@@ -34,6 +34,7 @@ use graphene_std::subpath::BezierHandles; | |||||
| use graphene_std::text::Font; | ||||||
| use graphene_std::vector::misc::HandleId; | ||||||
| use graphene_std::vector::{PointId, SegmentId, Vector, VectorModificationType}; | ||||||
| use parley::{FontContext, FontStyle}; | ||||||
| use std::path::PathBuf; | ||||||
| use std::vec; | ||||||
|
|
||||||
|
|
@@ -441,7 +442,42 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageContext<'_>> for Portfolio | |||||
| let catalog = &self.cached_data.font_catalog; | ||||||
|
|
||||||
| if catalog.0.is_empty() { | ||||||
| responses.add_front(FrontendMessage::TriggerFontCatalogLoad); | ||||||
| if Editor::environment().is_desktop() { | ||||||
| let system_font_context = FontContext::new(); // create system font context | ||||||
| let mut system_font_collection = system_font_context.collection; | ||||||
| let mut system_font_collection_again = system_font_collection.clone(); // because parley was not made correctly | ||||||
|
|
||||||
| // shove font metadata into cached data catalog | ||||||
| // simultaneously?? call font loaded a bunch of times to shove data into font data cache | ||||||
| let mut system_font_family_names = Vec::new(); | ||||||
| system_font_family_names.extend(system_font_collection.family_names()); | ||||||
| log::error!("fonts are: {:?}", system_font_family_names); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| let mut families_for_catalog = Vec::new(); | ||||||
| for name in system_font_family_names { | ||||||
| let family = system_font_collection_again.family_by_name(name).unwrap(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using
Suggested change
|
||||||
| let mut styles = Vec::new(); | ||||||
| for font in family.fonts() { | ||||||
| let style = FontCatalogStyle { | ||||||
| weight: (font.weight().value()) as u32, | ||||||
| italic: font.style() == FontStyle::Italic, | ||||||
| url: "".to_owned(), | ||||||
| }; | ||||||
| let mut font_data_vec = Vec::new(); | ||||||
| font_data_vec.extend(font.load(None).unwrap().data()); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| responses.add(PortfolioMessage::FontLoaded { | ||||||
| font_family: name.to_owned(), | ||||||
| font_style: style.to_named_style(), | ||||||
| data: font_data_vec, | ||||||
| }); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Loading the full data for every system font and sending it through the message system is extremely inefficient. This will cause significant performance degradation and high memory consumption on startup, especially for users with many installed fonts. Font data should be loaded lazily only when a specific font is required for rendering, rather than populating the entire cache upfront. |
||||||
| styles.push(style); | ||||||
| } | ||||||
| let family_for_catalog = FontCatalogFamily { name: name.to_owned(), styles }; | ||||||
| families_for_catalog.push(family_for_catalog); | ||||||
| } | ||||||
| self.cached_data.font_catalog = FontCatalog(families_for_catalog); | ||||||
| } else { | ||||||
| responses.add_front(FrontendMessage::TriggerFontCatalogLoad); | ||||||
| } | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cloning the entire font collection is an expensive operation. If
parleyrequires ownership or a mutable reference that prevents using the originalsystem_font_collection, consider if there is a way to restructure the access to avoid this clone.