Skip to content
Open
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ impl TableItemLayout for Graphic {
Self::RasterGPU(list) => list.identifier(),
Self::Color(list) => list.identifier(),
Self::Gradient(list) => list.identifier(),
Self::Text(list) => list.identifier(),
}
}
// Don't put a breadcrumb for Graphic
Expand All @@ -349,6 +350,7 @@ impl TableItemLayout for Graphic {
Self::RasterGPU(list) => list.layout_with_breadcrumb(data),
Self::Color(list) => list.layout_with_breadcrumb(data),
Self::Gradient(list) => list.layout_with_breadcrumb(data),
Self::Text(list) => list.layout_with_breadcrumb(data),
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion editor/src/node_graph_executor/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use graphene_std::ops::Convert;
#[cfg(all(target_family = "wasm", feature = "gpu", feature = "wasm"))]
use graphene_std::platform_application_io::canvas_utils::{Canvas, CanvasSurface, CanvasSurfaceHandle};
use graphene_std::raster_types::Raster;
use graphene_std::renderer::{Render, RenderParams, RenderSvgSegmentList, SvgRender, SvgSegment};
use graphene_std::renderer::{Render, RenderParams, RenderSvgSegmentList, SvgRender, SvgSegment, set_render_fonts};
use graphene_std::text::FontCache;
use graphene_std::transform::RenderQuality;
use graphene_std::vector::Vector;
Expand Down Expand Up @@ -395,6 +395,8 @@ impl NodeRuntime {
async fn execute_network(&mut self, render_config: RenderConfig) -> Result<TaggedValue, String> {
use graph_craft::graphene_compiler::Executor;

set_render_fonts(self.editor_api.font_cache.iter_fonts().map(|(family, bytes)| (family.to_string(), Arc::from(bytes))));

match self.executor.input_type() {
Some(t) if t == concrete!(RenderConfig) => (&self.executor).execute(render_config).await.map_err(|e| e.to_string()),
Some(t) if t == concrete!(()) => (&self.executor).execute(()).await.map_err(|e| e.to_string()),
Expand Down
2 changes: 1 addition & 1 deletion node-graph/libraries/core-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub use graphene_hash;
pub use graphene_hash::CacheHash;
pub use list::{
ATTR_BACKGROUND, ATTR_BLEND_MODE, ATTR_CLIP, ATTR_CLIPPING_MASK, ATTR_DIMENSIONS, ATTR_EDITOR_CLICK_TARGET, ATTR_EDITOR_LAYER_PATH, ATTR_EDITOR_MERGED_LAYERS, ATTR_EDITOR_TEXT_FRAME, ATTR_END,
ATTR_GRADIENT_TYPE, ATTR_LOCATION, ATTR_NAME, ATTR_OPACITY, ATTR_OPACITY_FILL, ATTR_SPREAD_METHOD, ATTR_START, ATTR_TRANSFORM, ATTR_TYPE,
ATTR_FONT_FAMILY, ATTR_FONT_SIZE, ATTR_GRADIENT_TYPE, ATTR_LOCATION, ATTR_NAME, ATTR_OPACITY, ATTR_OPACITY_FILL, ATTR_SPREAD_METHOD, ATTR_START, ATTR_TRANSFORM, ATTR_TYPE,
};
pub use memo::MemoHash;
pub use no_std_types::AsU32;
Expand Down
6 changes: 6 additions & 0 deletions node-graph/libraries/core-types/src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ pub const ATTR_SPREAD_METHOD: &str = "spread_method";
/// Gradient's `GradientType` (`Linear` or `Radial`).
pub const ATTR_GRADIENT_TYPE: &str = "gradient_type";

/// Text item's font family (`String`, implicit default `"sans-serif"`).
pub const ATTR_FONT_FAMILY: &str = "font_family";

/// Text item's font size in document-space units (`f64`, implicit default `16.`).
pub const ATTR_FONT_SIZE: &str = "font_size";

// ========================
// TRAIT: AnyAttributeValue
// ========================
Expand Down
6 changes: 6 additions & 0 deletions node-graph/libraries/core-types/src/render_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ impl RenderComplexity for Color {
1
}
}

impl RenderComplexity for String {
fn render_complexity(&self) -> usize {
1
}
}
29 changes: 29 additions & 0 deletions node-graph/libraries/graphic-types/src/graphic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub enum Graphic {
RasterGPU(List<Raster<GPU>>),
Color(List<Color>),
Gradient(List<GradientStops>),
Text(List<String>),
}

impl Default for Graphic {
Expand Down Expand Up @@ -103,6 +104,18 @@ impl From<List<GradientStops>> for Graphic {
}
}

// String
impl From<String> for Graphic {
fn from(text: String) -> Self {
Graphic::Text(List::new_from_element(text))
}
}
impl From<List<String>> for Graphic {
fn from(text: List<String>) -> Self {
Graphic::Text(text)
}
}

/// Deeply flattens a `List<Graphic>`, collecting only elements matching a specific variant (extracted by `extract_variant`)
/// and discarding all other non-matching content. Recursion through `Graphic::Graphic` sub-`List`s composes transforms and opacity.
fn flatten_graphic_list<T>(content: List<Graphic>, extract_variant: fn(Graphic) -> Option<List<T>>) -> List<T> {
Expand Down Expand Up @@ -199,6 +212,12 @@ impl TryFromGraphic for GradientStops {
}
}

impl TryFromGraphic for String {
fn try_from_graphic(graphic: Graphic) -> Option<List<Self>> {
if let Graphic::Text(t) = graphic { Some(t) } else { None }
}
}

// Local trait to convert types to List<Graphic> (avoids orphan rule issues)
pub trait IntoGraphicList {
fn into_graphic_list(self) -> List<Graphic>;
Expand Down Expand Up @@ -255,6 +274,12 @@ impl IntoGraphicList for List<GradientStops> {
}
}

impl IntoGraphicList for List<String> {
fn into_graphic_list(self) -> List<Graphic> {
List::new_from_element(Graphic::Text(self))
}
}

impl IntoGraphicList for DAffine2 {
fn into_graphic_list(self) -> List<Graphic> {
List::new_from_element(Graphic::default())
Expand Down Expand Up @@ -324,6 +349,7 @@ impl Graphic {
Graphic::RasterGPU(list) => all_clipped(list),
Graphic::Color(list) => all_clipped(list),
Graphic::Gradient(list) => all_clipped(list),
Graphic::Text(list) => all_clipped(list),
}
}

Expand All @@ -348,6 +374,7 @@ impl BoundingBox for Graphic {
Graphic::Graphic(list) => list.bounding_box(transform, include_stroke),
Graphic::Color(list) => list.bounding_box(transform, include_stroke),
Graphic::Gradient(list) => list.bounding_box(transform, include_stroke),
Graphic::Text(_) => RenderBoundingBox::Infinite,
}
}

Expand All @@ -359,6 +386,7 @@ impl BoundingBox for Graphic {
Graphic::Graphic(graphic) => graphic.thumbnail_bounding_box(transform, include_stroke),
Graphic::Color(color) => color.thumbnail_bounding_box(transform, include_stroke),
Graphic::Gradient(gradient) => gradient.thumbnail_bounding_box(transform, include_stroke),
Graphic::Text(_) => RenderBoundingBox::Infinite,
}
}
}
Expand Down Expand Up @@ -388,6 +416,7 @@ impl RenderComplexity for Graphic {
Self::RasterGPU(list) => list.render_complexity(),
Self::Color(list) => list.render_complexity(),
Self::Gradient(list) => list.render_complexity(),
Self::Text(list) => list.len(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions node-graph/libraries/rendering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ vector-types = { workspace = true }
graphic-types = { workspace = true }
vello = { workspace = true }
vello_encoding = { workspace = true }
parley = { workspace = true }
skrifa = { workspace = true }

# Optional workspace dependencies
serde = { workspace = true, optional = true }
Loading
Loading