mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 07:18:04 +08:00
Move font cache to text folder as static var
This commit is contained in:
@@ -52,8 +52,7 @@ impl Editor {
|
||||
previewed_node,
|
||||
};
|
||||
let opacity = active_document.graph_fade_artwork_percentage;
|
||||
let font_cache = self.dispatcher.message_handlers.portfolio_message_handler.persistent_data.font_cache.clone();
|
||||
let node_graph_overlay_node = generate_node_graph_overlay(node_graph_render_data, opacity, font_cache);
|
||||
let node_graph_overlay_node = generate_node_graph_overlay(node_graph_render_data, opacity);
|
||||
Some(NodeNetwork {
|
||||
exports: vec![NodeInput::node(NodeId(0), 0)],
|
||||
nodes: vec![(NodeId(0), node_graph_overlay_node)].into_iter().collect(),
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use graph_craft::{
|
||||
concrete,
|
||||
document::{DocumentNode, DocumentNodeImplementation, NodeInput, NodeNetwork, value::TaggedValue},
|
||||
@@ -7,14 +5,11 @@ use graph_craft::{
|
||||
use graphene_std::{
|
||||
node_graph_overlay::{types::NodeGraphOverlayData, ui_context::UIContext},
|
||||
table::Table,
|
||||
text::FontCache,
|
||||
uuid::NodeId,
|
||||
};
|
||||
|
||||
/// https://excalidraw.com/#json=LgKS6I4lQvGPmke06ZJyp,D9aON9vVZJAjNnZWfwy_SQ
|
||||
pub fn generate_node_graph_overlay(node_graph_overlay_data: NodeGraphOverlayData, opacity: f64, font_cache: Arc<FontCache>) -> DocumentNode {
|
||||
let font_cache_id = NodeId::new();
|
||||
|
||||
pub fn generate_node_graph_overlay(node_graph_overlay_data: NodeGraphOverlayData, opacity: f64) -> DocumentNode {
|
||||
let generate_nodes_id = NodeId::new();
|
||||
let cache_nodes_id = NodeId::new();
|
||||
let transform_nodes_id = NodeId::new();
|
||||
@@ -39,20 +34,12 @@ pub fn generate_node_graph_overlay(node_graph_overlay_data: NodeGraphOverlayData
|
||||
implementation: DocumentNodeImplementation::Network(NodeNetwork {
|
||||
exports: vec![NodeInput::node(send_overlay_id, 0)],
|
||||
nodes: vec![
|
||||
(
|
||||
font_cache_id,
|
||||
DocumentNode {
|
||||
inputs: vec![NodeInput::value(TaggedValue::FontCache(font_cache), false)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::ops::identity::IDENTIFIER),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
// Create the nodes
|
||||
(
|
||||
generate_nodes_id,
|
||||
DocumentNode {
|
||||
call_argument: concrete!(UIContext),
|
||||
inputs: vec![NodeInput::network(concrete!(UIContext), 1), NodeInput::node(font_cache_id, 0)],
|
||||
inputs: vec![NodeInput::network(concrete!(UIContext), 1)],
|
||||
implementation: DocumentNodeImplementation::ProtoNode("graphene_core::node_graph_overlay::GenerateNodesNode".into()),
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
@@ -1022,8 +1022,7 @@ impl OverlayContextInternal {
|
||||
align: TextAlign::Left,
|
||||
};
|
||||
|
||||
const FONT_DATA: &[u8] = SOURCE_SANS_FONT_DATA;
|
||||
let font_blob = Some(load_font(FONT_DATA));
|
||||
let font_blob = Some(load_font(SOURCE_SANS_FONT_DATA));
|
||||
|
||||
// Convert text to paths and calculate actual bounds
|
||||
let text_table = to_path(text, font_blob, typesetting, false);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use graphene_core_shaders::Ctx;
|
||||
|
||||
use crate::{
|
||||
@@ -11,7 +9,6 @@ use crate::{
|
||||
ui_context::{UIContext, UIRuntimeResponse},
|
||||
},
|
||||
table::Table,
|
||||
text::FontCache,
|
||||
transform::ApplyTransform,
|
||||
};
|
||||
|
||||
@@ -22,12 +19,12 @@ pub mod types;
|
||||
pub mod ui_context;
|
||||
|
||||
#[node_macro::node(skip_impl)]
|
||||
pub fn generate_nodes(_: impl Ctx, node_graph_overlay_data: NodeGraphOverlayData, font_cache: Arc<FontCache>) -> Table<Graphic> {
|
||||
pub fn generate_nodes(_: impl Ctx, node_graph_overlay_data: NodeGraphOverlayData) -> Table<Graphic> {
|
||||
let mut nodes_and_wires = Table::new();
|
||||
let layers = draw_layers(&node_graph_overlay_data.nodes_to_render, font_cache.as_ref());
|
||||
let layers = draw_layers(&node_graph_overlay_data.nodes_to_render);
|
||||
nodes_and_wires.extend(layers);
|
||||
|
||||
let nodes = draw_nodes(&node_graph_overlay_data.nodes_to_render, font_cache.as_ref());
|
||||
let nodes = draw_nodes(&node_graph_overlay_data.nodes_to_render);
|
||||
nodes_and_wires.extend(nodes);
|
||||
|
||||
nodes_and_wires
|
||||
|
||||
@@ -5,17 +5,18 @@ use kurbo::{BezPath, Rect, RoundedRect, Shape};
|
||||
use crate::{
|
||||
Graphic,
|
||||
bounds::{BoundingBox, RenderBoundingBox},
|
||||
consts::SOURCE_SANS_FONT_DATA,
|
||||
node_graph_overlay::{
|
||||
consts::*,
|
||||
types::{FrontendGraphDataType, FrontendNodeToRender},
|
||||
},
|
||||
table::{Table, TableRow},
|
||||
text::{self, FontCache, TextAlign, TypesettingConfig},
|
||||
text::{self, TextAlign, TypesettingConfig},
|
||||
transform::ApplyTransform,
|
||||
vector::{Vector, style::Fill},
|
||||
};
|
||||
|
||||
pub fn draw_nodes(nodes: &Vec<FrontendNodeToRender>, _font_cache: &FontCache) -> Table<Graphic> {
|
||||
pub fn draw_nodes(nodes: &Vec<FrontendNodeToRender>) -> Table<Graphic> {
|
||||
let mut node_table = Table::new();
|
||||
for node_to_render in nodes {
|
||||
if let Some(frontend_node) = node_to_render.node_or_layer.node.as_ref() {
|
||||
@@ -94,7 +95,7 @@ pub fn draw_nodes(nodes: &Vec<FrontendNodeToRender>, _font_cache: &FontCache) ->
|
||||
node_table
|
||||
}
|
||||
|
||||
pub fn draw_layers(nodes: &Vec<FrontendNodeToRender>, font_cache: &FontCache) -> Table<Graphic> {
|
||||
pub fn draw_layers(nodes: &Vec<FrontendNodeToRender>) -> Table<Graphic> {
|
||||
let mut layer_table = Table::new();
|
||||
for node_to_render in nodes {
|
||||
if let Some(frontend_layer) = node_to_render.node_or_layer.layer.as_ref() {
|
||||
@@ -120,7 +121,7 @@ pub fn draw_layers(nodes: &Vec<FrontendNodeToRender>, font_cache: &FontCache) ->
|
||||
align: TextAlign::Left,
|
||||
};
|
||||
|
||||
let font_blob = Some(text::load_font(font_cache.source_sans_pro()));
|
||||
let font_blob = Some(text::load_font(SOURCE_SANS_FONT_DATA));
|
||||
let mut text_table = crate::text::to_path(&node_to_render.metadata.display_name, font_blob, typesetting, false);
|
||||
|
||||
let text_width = if let RenderBoundingBox::Rectangle(bbox) = text_table.bounding_box(DAffine2::default(), true) {
|
||||
|
||||
@@ -24,7 +24,6 @@ use graphene_std::gradient::GradientStops;
|
||||
use graphene_std::node_graph_overlay::types::NodeGraphOverlayData;
|
||||
use graphene_std::node_graph_overlay::ui_context::UIContext;
|
||||
use graphene_std::table::Table;
|
||||
use graphene_std::text::FontCache;
|
||||
use graphene_std::transform::Footprint;
|
||||
use graphene_std::uuid::NodeId;
|
||||
use graphene_std::vector::Vector;
|
||||
@@ -254,7 +253,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
|
||||
node_io
|
||||
},
|
||||
),
|
||||
async_node!(graphene_core::node_graph_overlay::GenerateNodesNode<_, _>, input: UIContext, fn_params: [UIContext => NodeGraphOverlayData, UIContext => Arc<FontCache>]),
|
||||
async_node!(graphene_core::node_graph_overlay::GenerateNodesNode<_>, input: UIContext, fn_params: [UIContext => NodeGraphOverlayData]),
|
||||
async_node!(graphene_core::node_graph_overlay::TransformNodesNode<_>, input: UIContext, fn_params: [UIContext =>Table<Graphic>]),
|
||||
async_node!(graphene_core::node_graph_overlay::DotGridBackgroundNode<_>, input: UIContext, fn_params: [UIContext =>f64]),
|
||||
async_node!(graphene_core::node_graph_overlay::NodeGraphUiExtendNode<_, _>, input: UIContext, fn_params: [UIContext =>Table<Graphic>, UIContext =>Table<Graphic>]),
|
||||
|
||||
Reference in New Issue
Block a user