Current section
Files
Jump to
Current section
Files
native/skia_native/src/generated_path.rs
// Generated by mix skia.codegen. Do not edit by hand.
fn decode_path_direction(value: Atom) -> NifResult<PathDirection> {
match value {
value if value == atoms::cw() => Ok(PathDirection::CW),
value if value == atoms::ccw() => Ok(PathDirection::CCW),
_ => Err(rustler::Error::BadArg),
}
}
fn build_path<'a>(path_term: Term<'a>) -> NifResult<skia_safe::Path> {
match path_term.decode::<(Atom, String)>() {
Ok((tag, svg)) => {
if tag == atoms::svg() {
Ok(skia_safe::Path::from_svg(svg).ok_or(rustler::Error::BadArg)?)
} else {
build_path_from_compact_tuple(path_term)
}
}
Err(_reason) => build_path_from_compact_tuple(path_term),
}
}
fn build_path_from_compact_tuple<'a>(path_term: Term<'a>) -> NifResult<skia_safe::Path> {
match path_term.decode::<(Atom, Vec<Term<'a>>)>() {
Ok((tag, segments)) => {
if tag == atoms::p() {
build_compact_path(segments)
} else {
build_path_from_svg_field(path_term)
}
}
Err(_reason) => build_path_from_svg_field(path_term),
}
}
fn build_path_from_svg_field<'a>(path_term: Term<'a>) -> NifResult<skia_safe::Path> {
match path_term.map_get(atoms::svg()) {
Ok(svg_term) => {
match svg_term.decode::<String>() {
Ok(svg) => {
Ok(skia_safe::Path::from_svg(svg).ok_or(rustler::Error::BadArg)?)
}
Err(_reason) => build_path_from_segments_field(path_term),
}
}
Err(_reason) => build_path_from_segments_field(path_term),
}
}
fn build_path_from_segments_field<'a>(
path_term: Term<'a>,
) -> NifResult<skia_safe::Path> {
let segments = path_term.map_get(atoms::segments())?.decode::<Vec<Term<'a>>>()?;
let mut builder = PathBuilder::new();
for segment in segments.into_iter().rev() {
match segment.decode::<Atom>() {
Ok(op) => {
match op {
value if value == atoms::close() => {
builder.close();
}
_ => {}
};
}
Err(_reason) => {}
};
match segment.decode::<(Atom, f64, f64)>() {
Ok((op, x, y)) => {
let point = (x as f32, y as f32);
match op {
value if value == atoms::move_to() => {
builder.move_to(point);
}
value if value == atoms::line_to() => {
builder.line_to(point);
}
value if value == atoms::r_move_to() => {
builder.r_move_to(point);
}
value if value == atoms::r_line_to() => {
builder.r_line_to(point);
}
_ => {}
};
}
Err(_reason) => {}
};
match segment.decode::<(Atom, f64, f64, f64, f64)>() {
Ok((op, cx, cy, x, y)) => {
let control = (cx as f32, cy as f32);
let point = (x as f32, y as f32);
match op {
value if value == atoms::quad_to() => {
builder.quad_to(control, point);
}
value if value == atoms::r_quad_to() => {
builder.r_quad_to(control, point);
}
_ => {}
};
}
Err(_reason) => {}
};
match segment.decode::<(Atom, f64, f64, f64, f64, f64)>() {
Ok((op, cx, cy, x, y, weight)) => {
let control = (cx as f32, cy as f32);
let point = (x as f32, y as f32);
match op {
value if value == atoms::conic_to() => {
builder.conic_to(control, point, weight as f32);
}
value if value == atoms::r_conic_to() => {
builder.r_conic_to(control, point, weight as f32);
}
_ => {}
};
}
Err(_reason) => {}
};
match segment.decode::<(Atom, f64, f64, f64, f64, f64, Term<'a>)>() {
Ok((op, x, y, width, height, start, arc_opts)) => {
if op == atoms::arc_to() {
let (sweep, force_move_to) = arc_opts.decode::<(f64, bool)>()?;
builder
.arc_to(
Rect::from_xywh(
x as f32,
y as f32,
width as f32,
height as f32,
),
start as f32,
sweep as f32,
force_move_to,
);
}
}
Err(_reason) => {}
};
match segment.decode::<(Atom, f64, f64, f64, Term<'a>)>() {
Ok((op, rx, ry, x_axis_rotate, arc_opts)) => {
if op == atoms::r_arc_to() {
let (large_arc, sweep, dx, dy) = arc_opts
.decode::<(bool, Atom, f64, f64)>()?;
let arc_size = if large_arc {
skia_safe::path_builder::ArcSize::Large
} else {
skia_safe::path_builder::ArcSize::Small
};
builder
.r_arc_to(
(rx as f32, ry as f32),
x_axis_rotate as f32,
arc_size,
decode_path_direction(sweep)?,
(dx as f32, dy as f32),
);
}
}
Err(_reason) => {}
};
match segment.decode::<(Atom, f64, f64, f64, f64, f64, f64)>() {
Ok((op, x, y, width, height, rx, ry)) => {
if op == atoms::rrect() {
builder
.add_rrect(
RRect::new_rect_xy(
Rect::from_xywh(
x as f32,
y as f32,
width as f32,
height as f32,
),
rx as f32,
ry as f32,
),
None,
None,
);
}
}
Err(_reason) => {}
};
match segment.decode::<(Atom, f64, f64, f64, f64, f64, f64)>() {
Ok((op, c1x, c1y, c2x, c2y, x, y)) => {
let control_1 = (c1x as f32, c1y as f32);
let control_2 = (c2x as f32, c2y as f32);
let point = (x as f32, y as f32);
match op {
value if value == atoms::cubic_to() => {
builder.cubic_to(control_1, control_2, point);
}
value if value == atoms::r_cubic_to() => {
builder.r_cubic_to(control_1, control_2, point);
}
_ => {}
};
}
Err(_reason) => {}
};
}
Ok(builder.detach())
}
fn build_compact_path<'a>(segments: Vec<Term<'a>>) -> NifResult<skia_safe::Path> {
let mut builder = PathBuilder::new();
for segment in segments {
match segment.decode::<(i64,)>() {
Ok(close) => {
if close.0 == 14 {
builder.close();
}
}
Err(_reason) => {}
};
match segment.decode::<(i64, f64, f64)>() {
Ok((op, x, y)) => {
let point = (x as f32, y as f32);
match op {
1 => {
builder.move_to(point);
}
2 => {
builder.line_to(point);
}
6 => {
builder.r_move_to(point);
}
7 => {
builder.r_line_to(point);
}
_ => {}
};
}
Err(_reason) => {}
};
match segment.decode::<(i64, f64, f64, f64, f64)>() {
Ok((op, cx, cy, x, y)) => {
let control = (cx as f32, cy as f32);
let point = (x as f32, y as f32);
match op {
3 => {
builder.quad_to(control, point);
}
8 => {
builder.r_quad_to(control, point);
}
_ => {}
};
}
Err(_reason) => {}
};
match segment.decode::<(i64, f64, f64, f64, f64, f64)>() {
Ok((op, cx, cy, x, y, weight)) => {
let control = (cx as f32, cy as f32);
let point = (x as f32, y as f32);
match op {
4 => {
builder.conic_to(control, point, weight as f32);
}
9 => {
builder.r_conic_to(control, point, weight as f32);
}
_ => {}
};
}
Err(_reason) => {}
};
match segment.decode::<(i64, f64, f64, f64, f64, f64, f64)>() {
Ok((op, c1x, c1y, c2x, c2y, x, y)) => {
let control_1 = (c1x as f32, c1y as f32);
let control_2 = (c2x as f32, c2y as f32);
let point = (x as f32, y as f32);
match op {
5 => {
builder.cubic_to(control_1, control_2, point);
}
10 => {
builder.r_cubic_to(control_1, control_2, point);
}
13 => {
builder
.add_rrect(
RRect::new_rect_xy(
Rect::from_xywh(
c1x as f32,
c1y as f32,
c2x as f32,
c2y as f32,
),
x as f32,
y as f32,
),
None,
None,
);
}
_ => {}
};
}
Err(_reason) => {}
};
match segment.decode::<(i64, f64, f64, f64, f64, f64, Term<'a>)>() {
Ok((op, x, y, width, height, start, arc_opts)) => {
if op == 11 {
let (sweep, force_move_to) = arc_opts.decode::<(f64, bool)>()?;
builder
.arc_to(
Rect::from_xywh(
x as f32,
y as f32,
width as f32,
height as f32,
),
start as f32,
sweep as f32,
force_move_to,
);
}
}
Err(_reason) => {}
};
match segment.decode::<(i64, f64, f64, f64, Term<'a>)>() {
Ok((op, rx, ry, x_axis_rotate, arc_opts)) => {
if op == 12 {
let (large_arc, sweep, dx, dy) = arc_opts
.decode::<(bool, Atom, f64, f64)>()?;
let arc_size = if large_arc {
skia_safe::path_builder::ArcSize::Large
} else {
skia_safe::path_builder::ArcSize::Small
};
builder
.r_arc_to(
(rx as f32, ry as f32),
x_axis_rotate as f32,
arc_size,
decode_path_direction(sweep)?,
(dx as f32, dy as f32),
);
}
}
Err(_reason) => {}
};
}
Ok(builder.detach())
}