Skip to content

Commit cfdd328

Browse files
feat: Render List<String> as raw paths in SVG and Vell mode
1 parent 98daa75 commit cfdd328

12 files changed

Lines changed: 397 additions & 6 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editor/src/messages/portfolio/document/data_panel/data_panel_message_handler.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ impl TableItemLayout for Graphic {
335335
Self::RasterGPU(list) => list.identifier(),
336336
Self::Color(list) => list.identifier(),
337337
Self::Gradient(list) => list.identifier(),
338+
Self::Text(list) => list.identifier(),
338339
}
339340
}
340341
// Don't put a breadcrumb for Graphic
@@ -349,6 +350,7 @@ impl TableItemLayout for Graphic {
349350
Self::RasterGPU(list) => list.layout_with_breadcrumb(data),
350351
Self::Color(list) => list.layout_with_breadcrumb(data),
351352
Self::Gradient(list) => list.layout_with_breadcrumb(data),
353+
Self::Text(list) => list.layout_with_breadcrumb(data),
352354
}
353355
}
354356
}

editor/src/node_graph_executor/runtime.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use graphene_std::ops::Convert;
1515
#[cfg(all(target_family = "wasm", feature = "gpu", feature = "wasm"))]
1616
use graphene_std::platform_application_io::canvas_utils::{Canvas, CanvasSurface, CanvasSurfaceHandle};
1717
use graphene_std::raster_types::Raster;
18-
use graphene_std::renderer::{Render, RenderParams, RenderSvgSegmentList, SvgRender, SvgSegment};
18+
use graphene_std::renderer::{Render, RenderParams, RenderSvgSegmentList, SvgRender, SvgSegment, set_render_fonts};
1919
use graphene_std::text::FontCache;
2020
use graphene_std::transform::RenderQuality;
2121
use graphene_std::vector::Vector;
@@ -395,6 +395,8 @@ impl NodeRuntime {
395395
async fn execute_network(&mut self, render_config: RenderConfig) -> Result<TaggedValue, String> {
396396
use graph_craft::graphene_compiler::Executor;
397397

398+
set_render_fonts(self.editor_api.font_cache.iter_fonts().map(|(family, bytes)| (family.to_string(), bytes)));
399+
398400
match self.executor.input_type() {
399401
Some(t) if t == concrete!(RenderConfig) => (&self.executor).execute(render_config).await.map_err(|e| e.to_string()),
400402
Some(t) if t == concrete!(()) => (&self.executor).execute(()).await.map_err(|e| e.to_string()),

node-graph/libraries/core-types/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub use graphene_hash;
2525
pub use graphene_hash::CacheHash;
2626
pub use list::{
2727
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,
28-
ATTR_GRADIENT_TYPE, ATTR_LOCATION, ATTR_NAME, ATTR_OPACITY, ATTR_OPACITY_FILL, ATTR_SPREAD_METHOD, ATTR_START, ATTR_TRANSFORM, ATTR_TYPE,
28+
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,
2929
};
3030
pub use memo::MemoHash;
3131
pub use no_std_types::AsU32;

node-graph/libraries/core-types/src/list.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ pub const ATTR_SPREAD_METHOD: &str = "spread_method";
7777
/// Gradient's `GradientType` (`Linear` or `Radial`).
7878
pub const ATTR_GRADIENT_TYPE: &str = "gradient_type";
7979

80+
/// Text item's font family (`String`, implicit default `"sans-serif"`).
81+
pub const ATTR_FONT_FAMILY: &str = "font_family";
82+
83+
/// Text item's font size in document-space units (`f64`, implicit default `16.`).
84+
pub const ATTR_FONT_SIZE: &str = "font_size";
85+
8086
// ========================
8187
// TRAIT: AnyAttributeValue
8288
// ========================

node-graph/libraries/core-types/src/render_complexity.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ impl RenderComplexity for Color {
1919
1
2020
}
2121
}
22+
23+
impl RenderComplexity for String {
24+
fn render_complexity(&self) -> usize {
25+
1
26+
}
27+
}

node-graph/libraries/graphic-types/src/graphic.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub enum Graphic {
2222
RasterGPU(List<Raster<GPU>>),
2323
Color(List<Color>),
2424
Gradient(List<GradientStops>),
25+
Text(List<String>),
2526
}
2627

2728
impl Default for Graphic {
@@ -103,6 +104,18 @@ impl From<List<GradientStops>> for Graphic {
103104
}
104105
}
105106

107+
// String
108+
impl From<String> for Graphic {
109+
fn from(text: String) -> Self {
110+
Graphic::Text(List::new_from_element(text))
111+
}
112+
}
113+
impl From<List<String>> for Graphic {
114+
fn from(text: List<String>) -> Self {
115+
Graphic::Text(text)
116+
}
117+
}
118+
106119
/// Deeply flattens a `List<Graphic>`, collecting only elements matching a specific variant (extracted by `extract_variant`)
107120
/// and discarding all other non-matching content. Recursion through `Graphic::Graphic` sub-`List`s composes transforms and opacity.
108121
fn flatten_graphic_list<T>(content: List<Graphic>, extract_variant: fn(Graphic) -> Option<List<T>>) -> List<T> {
@@ -199,6 +212,12 @@ impl TryFromGraphic for GradientStops {
199212
}
200213
}
201214

215+
impl TryFromGraphic for String {
216+
fn try_from_graphic(graphic: Graphic) -> Option<List<Self>> {
217+
if let Graphic::Text(t) = graphic { Some(t) } else { None }
218+
}
219+
}
220+
202221
// Local trait to convert types to List<Graphic> (avoids orphan rule issues)
203222
pub trait IntoGraphicList {
204223
fn into_graphic_list(self) -> List<Graphic>;
@@ -255,6 +274,12 @@ impl IntoGraphicList for List<GradientStops> {
255274
}
256275
}
257276

277+
impl IntoGraphicList for List<String> {
278+
fn into_graphic_list(self) -> List<Graphic> {
279+
List::new_from_element(Graphic::Text(self))
280+
}
281+
}
282+
258283
impl IntoGraphicList for DAffine2 {
259284
fn into_graphic_list(self) -> List<Graphic> {
260285
List::new_from_element(Graphic::default())
@@ -324,6 +349,7 @@ impl Graphic {
324349
Graphic::RasterGPU(list) => all_clipped(list),
325350
Graphic::Color(list) => all_clipped(list),
326351
Graphic::Gradient(list) => all_clipped(list),
352+
Graphic::Text(list) => all_clipped(list),
327353
}
328354
}
329355

@@ -348,6 +374,7 @@ impl BoundingBox for Graphic {
348374
Graphic::Graphic(list) => list.bounding_box(transform, include_stroke),
349375
Graphic::Color(list) => list.bounding_box(transform, include_stroke),
350376
Graphic::Gradient(list) => list.bounding_box(transform, include_stroke),
377+
Graphic::Text(_) => RenderBoundingBox::None,
351378
}
352379
}
353380

@@ -359,6 +386,7 @@ impl BoundingBox for Graphic {
359386
Graphic::Graphic(graphic) => graphic.thumbnail_bounding_box(transform, include_stroke),
360387
Graphic::Color(color) => color.thumbnail_bounding_box(transform, include_stroke),
361388
Graphic::Gradient(gradient) => gradient.thumbnail_bounding_box(transform, include_stroke),
389+
Graphic::Text(_) => RenderBoundingBox::None,
362390
}
363391
}
364392
}
@@ -388,6 +416,7 @@ impl RenderComplexity for Graphic {
388416
Self::RasterGPU(list) => list.render_complexity(),
389417
Self::Color(list) => list.render_complexity(),
390418
Self::Gradient(list) => list.render_complexity(),
419+
Self::Text(list) => list.len(),
391420
}
392421
}
393422
}

node-graph/libraries/rendering/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ vector-types = { workspace = true }
2727
graphic-types = { workspace = true }
2828
vello = { workspace = true }
2929
vello_encoding = { workspace = true }
30+
parley = { workspace = true }
31+
skrifa = { workspace = true }
3032

3133
# Optional workspace dependencies
3234
serde = { workspace = true, optional = true }

0 commit comments

Comments
 (0)