Skip to content

Commit 08b25f6

Browse files
committed
New Typography type
1 parent 485152b commit 08b25f6

File tree

13 files changed

+356
-71
lines changed

13 files changed

+356
-71
lines changed

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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use graphene_std::gradient::GradientStops;
1212
use graphene_std::memo::IORecord;
1313
use graphene_std::raster_types::{CPU, GPU, Raster};
1414
use graphene_std::table::Table;
15+
use graphene_std::text::Typography;
1516
use graphene_std::vector::Vector;
1617
use graphene_std::vector::style::{Fill, FillChoice};
1718
use graphene_std::{Artboard, Graphic};
@@ -266,6 +267,7 @@ impl TableRowLayout for Graphic {
266267
Self::RasterGPU(table) => table.identifier(),
267268
Self::Color(table) => table.identifier(),
268269
Self::Gradient(table) => table.identifier(),
270+
Self::Typography(table) => table.identifier(),
269271
}
270272
}
271273
// Don't put a breadcrumb for Graphic
@@ -280,6 +282,7 @@ impl TableRowLayout for Graphic {
280282
Self::RasterGPU(table) => table.layout_with_breadcrumb(data),
281283
Self::Color(table) => table.layout_with_breadcrumb(data),
282284
Self::Gradient(table) => table.layout_with_breadcrumb(data),
285+
Self::Typography(table) => table.layout_with_breadcrumb(data),
283286
}
284287
}
285288
}
@@ -504,6 +507,21 @@ impl TableRowLayout for GradientStops {
504507
}
505508
}
506509

510+
impl TableRowLayout for Typography {
511+
fn type_name() -> &'static str {
512+
"Typography"
513+
}
514+
fn identifier(&self) -> String {
515+
"Typography".to_string()
516+
}
517+
fn element_widget(&self, _index: usize) -> WidgetHolder {
518+
TextLabel::new("Not supported").widget_holder()
519+
}
520+
fn element_page(&self, _data: &mut LayoutData) -> Vec<LayoutGroup> {
521+
vec![LayoutGroup::Row { widgets: Vec::new() }]
522+
}
523+
}
524+
507525
impl TableRowLayout for f64 {
508526
fn type_name() -> &'static str {
509527
"Number (f64)"

editor/src/messages/portfolio/document/overlays/utility_types_vello.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use core::borrow::Borrow;
99
use core::f64::consts::{FRAC_PI_2, PI, TAU};
1010
use glam::{DAffine2, DVec2};
1111
use graphene_std::Color;
12+
use graphene_std::consts::SOURCE_SANS_FONT_DATA;
1213
use graphene_std::math::quad::Quad;
1314
use graphene_std::subpath::{self, Subpath};
1415
use graphene_std::table::Table;
@@ -1021,10 +1022,7 @@ impl OverlayContextInternal {
10211022
align: TextAlign::Left,
10221023
};
10231024

1024-
// Load Source Sans Pro font data
1025-
// TODO: Grab this from the node_modules folder (either with `include_bytes!` or ideally at runtime) instead of checking the font file into the repo.
1026-
// TODO: And maybe use the WOFF2 version (if it's supported) for its smaller, compressed file size.
1027-
const FONT_DATA: &[u8] = include_bytes!("source-sans-pro-regular.ttf");
1025+
const FONT_DATA: &[u8] = SOURCE_SANS_FONT_DATA;
10281026
let font_blob = Some(load_font(FONT_DATA));
10291027

10301028
// Convert text to paths and calculate actual bounds
@@ -1048,10 +1046,7 @@ impl OverlayContextInternal {
10481046
align: TextAlign::Left, // We'll handle alignment manually via pivot
10491047
};
10501048

1051-
// Load Source Sans Pro font data
1052-
// TODO: Grab this from the node_modules folder (either with `include_bytes!` or ideally at runtime) instead of checking the font file into the repo.
1053-
// TODO: And maybe use the WOFF2 version (if it's supported) for its smaller, compressed file size.
1054-
const FONT_DATA: &[u8] = include_bytes!("source-sans-pro-regular.ttf");
1049+
const FONT_DATA: &[u8] = SOURCE_SANS_FONT_DATA;
10551050
let font_blob = Some(load_font(FONT_DATA));
10561051

10571052
// Convert text to vector paths using the existing text system

node-graph/gcore/src/bounds.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{Color, gradient::GradientStops};
1+
use crate::{Color, gradient::GradientStops, text::Typography};
22
use glam::{DAffine2, DVec2};
33

44
#[derive(Clone, Copy, Default, Debug, PartialEq)]
@@ -38,3 +38,9 @@ impl BoundingBox for GradientStops {
3838
RenderBoundingBox::Infinite
3939
}
4040
}
41+
impl BoundingBox for Typography {
42+
fn bounding_box(&self, transform: DAffine2, _include_stroke: bool) -> RenderBoundingBox {
43+
let bbox = DVec2::new(self.layout.full_width() as f64, self.layout.height() as f64);
44+
RenderBoundingBox::Rectangle([transform.transform_point2(DVec2::ZERO), transform.transform_point2(bbox)])
45+
}
46+
}

node-graph/gcore/src/consts.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ pub const LAYER_OUTLINE_STROKE_WEIGHT: f64 = 0.5;
77
// Fonts
88
pub const DEFAULT_FONT_FAMILY: &str = "Cabin";
99
pub const DEFAULT_FONT_STYLE: &str = "Regular (400)";
10+
11+
// Load Source Sans Pro font data
12+
// TODO: Grab this from the node_modules folder (either with `include_bytes!` or ideally at runtime) instead of checking the font file into the repo.
13+
// TODO: And maybe use the WOFF2 version (if it's supported) for its smaller, compressed file size.
14+
pub const SOURCE_SANS_FONT_DATA: &[u8] = include_bytes!("text/source-sans-pro-regular.ttf");
15+
pub const SOURCE_SANS_FONT_FAMILY: &str = "Source Sans Pro";
16+
pub const SOURCE_SANS_FONT_STYLE: &str = "Regular (400)";

node-graph/gcore/src/graphic.rs

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::bounds::{BoundingBox, RenderBoundingBox};
33
use crate::gradient::GradientStops;
44
use crate::raster_types::{CPU, GPU, Raster};
55
use crate::table::{Table, TableRow};
6+
use crate::text::Typography;
67
use crate::uuid::NodeId;
78
use crate::vector::Vector;
89
use crate::{Artboard, Color, Ctx};
@@ -11,14 +12,34 @@ use glam::{DAffine2, DVec2};
1112
use std::hash::Hash;
1213

1314
/// The possible forms of graphical content that can be rendered by the Render node into either an image or SVG syntax.
14-
#[derive(Clone, Debug, Hash, PartialEq, DynAny, serde::Serialize, serde::Deserialize)]
15+
#[derive(Clone, Debug, Hash, PartialEq, DynAny)]
1516
pub enum Graphic {
1617
Graphic(Table<Graphic>),
1718
Vector(Table<Vector>),
1819
RasterCPU(Table<Raster<CPU>>),
1920
RasterGPU(Table<Raster<GPU>>),
2021
Color(Table<Color>),
2122
Gradient(Table<GradientStops>),
23+
Typography(Table<Typography>),
24+
}
25+
26+
impl serde::Serialize for Graphic {
27+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
28+
where
29+
S: serde::Serializer,
30+
{
31+
let default: Table<Graphic> = Table::new();
32+
default.serialize(serializer)
33+
}
34+
}
35+
36+
impl<'de> serde::Deserialize<'de> for Graphic {
37+
fn deserialize<D>(_deserializer: D) -> Result<Self, D::Error>
38+
where
39+
D: serde::Deserializer<'de>,
40+
{
41+
Ok(Graphic::Graphic(Table::new()))
42+
}
2243
}
2344

2445
impl Default for Graphic {
@@ -232,6 +253,7 @@ impl Graphic {
232253
Graphic::RasterGPU(raster) => raster.iter().all(|row| row.alpha_blending.clip),
233254
Graphic::Color(color) => color.iter().all(|row| row.alpha_blending.clip),
234255
Graphic::Gradient(gradient) => gradient.iter().all(|row| row.alpha_blending.clip),
256+
Graphic::Typography(typography) => typography.iter().all(|row| row.alpha_blending.clip),
235257
}
236258
}
237259

@@ -256,6 +278,7 @@ impl BoundingBox for Graphic {
256278
Graphic::Graphic(graphic) => graphic.bounding_box(transform, include_stroke),
257279
Graphic::Color(color) => color.bounding_box(transform, include_stroke),
258280
Graphic::Gradient(gradient) => gradient.bounding_box(transform, include_stroke),
281+
Graphic::Typography(typography) => typography.bounding_box(transform, include_stroke),
259282
}
260283
}
261284
}
@@ -507,34 +530,15 @@ pub fn migrate_graphic<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Res
507530
elements: Vec<(Graphic, Option<NodeId>)>,
508531
}
509532

510-
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
511-
pub struct OlderTable<T> {
512-
id: Vec<u64>,
513-
#[serde(alias = "instances", alias = "instance")]
514-
element: Vec<T>,
515-
}
516-
517-
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
518-
pub struct OldTable<T> {
519-
id: Vec<u64>,
520-
#[serde(alias = "instances", alias = "instance")]
521-
element: Vec<T>,
522-
transform: Vec<DAffine2>,
523-
alpha_blending: Vec<AlphaBlending>,
524-
}
525-
526533
#[derive(serde::Serialize, serde::Deserialize)]
527534
#[serde(untagged)]
528-
enum GraphicFormat {
535+
enum EitherFormat {
529536
OldGraphicGroup(OldGraphicGroup),
530-
OlderTableOldGraphicGroup(OlderTable<OldGraphicGroup>),
531-
OldTableOldGraphicGroup(OldTable<OldGraphicGroup>),
532-
OldTableGraphicGroup(OldTable<GraphicGroup>),
533537
Table(serde_json::Value),
534538
}
535539

536-
Ok(match GraphicFormat::deserialize(deserializer)? {
537-
GraphicFormat::OldGraphicGroup(old) => {
540+
Ok(match EitherFormat::deserialize(deserializer)? {
541+
EitherFormat::OldGraphicGroup(old) => {
538542
let mut graphic_table = Table::new();
539543
for (graphic, source_node_id) in old.elements {
540544
graphic_table.push(TableRow {
@@ -546,43 +550,7 @@ pub fn migrate_graphic<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Res
546550
}
547551
graphic_table
548552
}
549-
GraphicFormat::OlderTableOldGraphicGroup(old) => old
550-
.element
551-
.into_iter()
552-
.flat_map(|element| {
553-
element.elements.into_iter().map(move |(graphic, source_node_id)| TableRow {
554-
element: graphic,
555-
transform: element.transform,
556-
alpha_blending: element.alpha_blending,
557-
source_node_id,
558-
})
559-
})
560-
.collect(),
561-
GraphicFormat::OldTableOldGraphicGroup(old) => old
562-
.element
563-
.into_iter()
564-
.flat_map(|element| {
565-
element.elements.into_iter().map(move |(graphic, source_node_id)| TableRow {
566-
element: graphic,
567-
transform: element.transform,
568-
alpha_blending: element.alpha_blending,
569-
source_node_id,
570-
})
571-
})
572-
.collect(),
573-
GraphicFormat::OldTableGraphicGroup(old) => old
574-
.element
575-
.into_iter()
576-
.flat_map(|element| {
577-
element.elements.into_iter().map(move |(graphic, source_node_id)| TableRow {
578-
element: graphic,
579-
transform: Default::default(),
580-
alpha_blending: Default::default(),
581-
source_node_id,
582-
})
583-
})
584-
.collect(),
585-
GraphicFormat::Table(value) => {
553+
EitherFormat::Table(value) => {
586554
// Try to deserialize as either table format
587555
if let Ok(old_table) = serde_json::from_value::<Table<GraphicGroup>>(value.clone()) {
588556
let mut graphic_table = Table::new();

node-graph/gcore/src/render_complexity.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::gradient::GradientStops;
22
use crate::raster_types::{CPU, GPU, Raster};
33
use crate::table::Table;
4+
use crate::text::Typography;
45
use crate::vector::Vector;
56
use crate::{Artboard, Color, Graphic};
67

@@ -31,6 +32,7 @@ impl RenderComplexity for Graphic {
3132
Self::RasterGPU(table) => table.render_complexity(),
3233
Self::Color(table) => table.render_complexity(),
3334
Self::Gradient(table) => table.render_complexity(),
35+
Self::Typography(table) => table.render_complexity(),
3436
}
3537
}
3638
}
@@ -65,3 +67,9 @@ impl RenderComplexity for GradientStops {
6567
1
6668
}
6769
}
70+
71+
impl RenderComplexity for Typography {
72+
fn render_complexity(&self) -> usize {
73+
1
74+
}
75+
}

0 commit comments

Comments
 (0)