-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fonts as resources #4165
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
Draft
timon-schelling
wants to merge
3
commits into
master
Choose a base branch
from
fonts-as-resources
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Fonts as resources #4165
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-116 KB
editor/src/messages/portfolio/document/overlays/source-sans-pro-regular.ttf
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
editor/src/messages/portfolio/document/utility_types/text_resource_resolution.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| use crate::messages::portfolio::document::utility_types::network_interface::{InputConnector, NodeNetworkInterface}; | ||
| use crate::messages::portfolio::utility_types::FontCache; | ||
| use graph_craft::application_io::ResourceHash; | ||
| use graph_craft::document::value::TaggedValue; | ||
| use graph_craft::document::{DocumentNodeImplementation, NodeId, NodeInput, NodeNetwork}; | ||
| use graphene_std::NodeInputDecleration; | ||
| use graphene_std::text::Font; | ||
|
|
||
| const TEXT_NODE_FONT_RESOURCE_INPUT_INDEX: usize = 3; | ||
|
|
||
| pub fn patch_text_nodes_with_loaded_font(network_interface: &mut NodeNetworkInterface, target_font: &Font, hash: ResourceHash) -> bool { | ||
| let updates = collect_text_node_updates(network_interface.document_network(), &[], &mut |font, current| { | ||
| if font != target_font { | ||
| return false; | ||
| } | ||
| matches!(current, TaggedValue::None) | ||
| }); | ||
|
|
||
| let patched_any = !updates.is_empty(); | ||
| for (network_path, node_id, _font) in updates { | ||
| network_interface.set_input( | ||
| &InputConnector::node(node_id, TEXT_NODE_FONT_RESOURCE_INPUT_INDEX), | ||
| NodeInput::value(TaggedValue::Resource(hash), false), | ||
| &network_path, | ||
| ); | ||
| } | ||
| patched_any | ||
| } | ||
|
|
||
| pub fn fonts_missing_text_resources(network: &NodeNetwork) -> Vec<Font> { | ||
| let updates = collect_text_node_updates(network, &[], &mut |_font, current| matches!(current, TaggedValue::None)); | ||
|
|
||
| let mut fonts = Vec::new(); | ||
| for (_network_path, _node_id, font) in updates { | ||
| if !fonts.contains(&font) { | ||
| fonts.push(font); | ||
| } | ||
| } | ||
| fonts | ||
| } | ||
|
|
||
| pub fn refresh_text_node_font_resources(network_interface: &mut NodeNetworkInterface, font_cache: &FontCache) -> Vec<Font> { | ||
| let updates = collect_text_node_updates(network_interface.document_network(), &[], &mut |_font, _current| true); | ||
|
|
||
| let mut needs_loading = Vec::new(); | ||
| for (network_path, node_id, font) in updates { | ||
| let current_input = network_interface | ||
| .input_from_connector(&InputConnector::node(node_id, TEXT_NODE_FONT_RESOURCE_INPUT_INDEX), &network_path) | ||
| .cloned(); | ||
|
|
||
| let current_value = current_input.as_ref().and_then(|input| input.as_value()); | ||
|
|
||
| if font_cache.contains(&font) { | ||
| if matches!(current_value, Some(TaggedValue::None)) && !needs_loading.contains(&font) { | ||
| needs_loading.push(font); | ||
| } | ||
| } else { | ||
| if !matches!(current_value, Some(TaggedValue::None)) { | ||
| network_interface.set_input( | ||
| &InputConnector::node(node_id, TEXT_NODE_FONT_RESOURCE_INPUT_INDEX), | ||
| NodeInput::value(TaggedValue::None, false), | ||
| &network_path, | ||
| ); | ||
| } | ||
| if !needs_loading.contains(&font) { | ||
| needs_loading.push(font); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| needs_loading | ||
| } | ||
|
|
||
| fn collect_text_node_updates(network: &NodeNetwork, parent_path: &[NodeId], predicate: &mut dyn FnMut(&Font, &TaggedValue) -> bool) -> Vec<(Vec<NodeId>, NodeId, Font)> { | ||
| let mut out = Vec::new(); | ||
| for (node_id, node) in network.nodes.iter() { | ||
| if let DocumentNodeImplementation::Network(nested) = &node.implementation { | ||
| let mut path = parent_path.to_vec(); | ||
| path.push(*node_id); | ||
| out.extend(collect_text_node_updates(nested, &path, predicate)); | ||
| continue; | ||
| } | ||
|
|
||
| let is_text_node = matches!(&node.implementation, DocumentNodeImplementation::ProtoNode(identifier) if *identifier == graphene_std::text::text::IDENTIFIER); | ||
| if !is_text_node { | ||
| continue; | ||
| } | ||
|
|
||
| let Some(NodeInput::Value { tagged_value, .. }) = node.inputs.get(graphene_std::text::text::FontInput::INDEX) else { | ||
| continue; | ||
| }; | ||
| let TaggedValue::Font(font) = (**tagged_value).clone() else { continue }; | ||
|
|
||
| let Some(NodeInput::Value { tagged_value: resource_value, .. }) = node.inputs.get(TEXT_NODE_FONT_RESOURCE_INPUT_INDEX) else { | ||
| continue; | ||
| }; | ||
|
|
||
| if predicate(&font, resource_value) { | ||
| out.push((parent_path.to_vec(), *node_id, font)); | ||
| } | ||
| } | ||
| out | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The migration loop bounds are incorrect. The new text node definition has 12 inputs (indices 0-11). The current loop 3..=12 attempts to set inputs up to index 13, which exceeds the available slots and will cause a panic. While removing old data migrations for features that are being retired is acceptable, the loop must still stay within the bounds of the new node's inputs.
References