Skip to content

Commit

Permalink
Remove attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
yutannihilation committed Sep 28, 2024
1 parent a5bd2e1 commit 685766f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
38 changes: 14 additions & 24 deletions src/rust/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ impl<T: BuildPath> LyonPathBuilder<T> {
.collect()
}

pub fn ids(&self) -> [f32; 2] {
[self.cur_glyph_id as _, self.cur_path_id as _]
}

pub fn update_transform(&mut self) {
let transform = self
.base_transform
Expand Down Expand Up @@ -163,18 +159,20 @@ impl<T: BuildPath> LyonPathBuilder<T> {

// For path

pub type FlattenedPathBuilder = lyon::path::builder::Transformed<
lyon::path::builder::Flattened<lyon::path::path::BuilderWithAttributes>,
lyon::math::Transform,
pub type FlattenedPathBuilder = lyon::path::builder::NoAttributes<
lyon::path::builder::Transformed<
lyon::path::builder::Flattened<lyon::path::path::BuilderImpl>,
lyon::math::Transform,
>,
>;

impl BuildPath for FlattenedPathBuilder {
fn set_transform(&mut self, transform: lyon::math::Transform) {
self.set_transform(transform);
lyon::path::builder::Transformed::set_transform(self, transform);
}

fn new_builder(tolerance: f32) -> Self {
lyon::path::Path::builder_with_attributes(2)
lyon::path::Path::builder()
.flattened(tolerance)
.transformed(lyon::geom::euclid::Transform2D::identity())
}
Expand All @@ -191,9 +189,8 @@ impl LyonPathBuilderForPath {

// For stroke and fill

pub type NonFlattenedPathBuilder = lyon::path::builder::Transformed<
lyon::path::path::BuilderWithAttributes,
lyon::math::Transform,
pub type NonFlattenedPathBuilder = lyon::path::builder::NoAttributes<
lyon::path::builder::Transformed<lyon::path::path::BuilderImpl, lyon::math::Transform>,
>;

impl BuildPath for NonFlattenedPathBuilder {
Expand All @@ -202,8 +199,7 @@ impl BuildPath for NonFlattenedPathBuilder {
}

fn new_builder(_tolerance: f32) -> Self {
lyon::path::Path::builder_with_attributes(2)
.transformed(lyon::geom::euclid::Transform2D::identity())
lyon::path::Path::builder().transformed(lyon::geom::euclid::Transform2D::identity())
}
}

Expand All @@ -229,31 +225,25 @@ impl<T: BuildPath> ttf_parser::OutlineBuilder for LyonPathBuilder<T> {
.insert(self.cur_path_id, self.cur_glyph_id);

let at = point(x, y);
let custom_attributes = &self.ids();
self.cur_builder().begin(at, custom_attributes);
self.cur_builder().begin(at, &[]);
}

fn line_to(&mut self, x: f32, y: f32) {
let to = point(x, y);
let custom_attributes = &self.ids();
self.cur_builder().line_to(to, custom_attributes);
self.cur_builder().line_to(to, &[]);
}

fn quad_to(&mut self, x1: f32, y1: f32, x: f32, y: f32) {
let ctrl = point(x1, y1);
let to = point(x, y);
let custom_attributes = &self.ids();
self.cur_builder()
.quadratic_bezier_to(ctrl, to, custom_attributes);
self.cur_builder().quadratic_bezier_to(ctrl, to, &[]);
}

fn curve_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x: f32, y: f32) {
let ctrl1 = point(x1, y1);
let ctrl2 = point(x2, y2);
let to = point(x, y);
let custom_attributes = &self.ids();
self.cur_builder()
.cubic_bezier_to(ctrl1, ctrl2, to, custom_attributes);
self.cur_builder().cubic_bezier_to(ctrl1, ctrl2, to, &[]);
}

fn close(&mut self) {
Expand Down
14 changes: 5 additions & 9 deletions src/rust/src/into_fill_stroke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@ use lyon::tessellation::*;
use ttf_parser::RgbaColor;

#[derive(Copy, Clone, Debug)]
struct Vertex {
position: lyon::math::Point,
}
struct Vertex(lyon::math::Point);

// This can have some members so that it can be used in new_vertex(), but I
// don't find any useful usage yet.
struct VertexCtor {}

impl FillVertexConstructor<Vertex> for VertexCtor {
fn new_vertex(&mut self, vertex: FillVertex) -> Vertex {
let pos = vertex.position();
Vertex { position: pos }
Vertex(vertex.position())
}
}

impl StrokeVertexConstructor<Vertex> for VertexCtor {
fn new_vertex(&mut self, vertex: StrokeVertex) -> Vertex {
let pos = vertex.position();
Vertex { position: pos }
Vertex(vertex.position())
}
}

Expand Down Expand Up @@ -134,8 +130,8 @@ fn extract_vertex_buffer(
});
for (n, &i) in geometry.indices.iter().enumerate() {
if let Some(v) = geometry.vertices.get(i) {
dst.x.push(v.position.x as _);
dst.y.push(v.position.y as _);
dst.x.push(v.0.x as _);
dst.y.push(v.0.y as _);
dst.glyph_id.push(glyph_id);
if let Some(triangle_id) = &mut dst.triangle_id {
triangle_id.push(n as i32 / 3 + offset);
Expand Down

0 comments on commit 685766f

Please sign in to comment.