From 2129e4f2e128afd95b04aabfca48490ca7c51967 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 20 Jun 2019 15:51:25 -0700 Subject: [PATCH] Add missing path methods to the C API --- c/include/pathfinder/pathfinder.h | 20 ++++++++++++++ c/src/lib.rs | 44 ++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/c/include/pathfinder/pathfinder.h b/c/include/pathfinder/pathfinder.h index b89404d4..6073bb51 100644 --- a/c/include/pathfinder/pathfinder.h +++ b/c/include/pathfinder/pathfinder.h @@ -29,6 +29,11 @@ extern "C" { #define PF_LINE_JOIN_BEVEL 1 #define PF_LINE_JOIN_ROUND 2 +// `geometry` + +#define PF_ARC_DIRECTION_CW 0 +#define PF_ARC_DIRECTION_CCW 1 + // `gl` #define PF_GL_VERSION_GL3 0 @@ -50,6 +55,7 @@ struct PFCanvasFontContext; typedef struct PFCanvasFontContext *PFCanvasFontContextRef; typedef uint8_t PFLineCap; typedef uint8_t PFLineJoin; +typedef uint8_t PFArcDirection; // `geometry` @@ -139,6 +145,20 @@ void PFPathBezierCurveTo(PFPathRef path, const PFVector2F *ctrl0, const PFVector2F *ctrl1, const PFVector2F *to); +void PFPathArc(PFPathRef path, + const PFVector2F *center, + float radius, + float start_angle, + float end_angle, + PFArcDirection direction); +void PFPathArcTo(PFPathRef path, const PFVector2F *ctrl, const PFVector2F *to, float radius); +void PFPathRect(PFPathRef path, const PFRectF *rect); +void PFPathEllipse(PFPathRef path, + const PFVector2F *center, + const PFVector2F *axes, + float rotation, + float start_angle, + float end_angle); void PFPathClosePath(PFPathRef path); // `gl` diff --git a/c/src/lib.rs b/c/src/lib.rs index e9cb913d..4fc204f2 100644 --- a/c/src/lib.rs +++ b/c/src/lib.rs @@ -12,9 +12,10 @@ use gl; use pathfinder_canvas::{CanvasFontContext, CanvasRenderingContext2D, LineJoin, Path2D}; -use pathfinder_geometry::basic::vector::{Vector2F, Vector2I}; use pathfinder_geometry::basic::rect::{RectF, RectI}; +use pathfinder_geometry::basic::vector::{Vector2F, Vector2I}; use pathfinder_geometry::color::ColorF; +use pathfinder_geometry::outline::ArcDirection; use pathfinder_geometry::stroke::LineCap; use pathfinder_gl::{GLDevice, GLVersion}; use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader}; @@ -41,7 +42,13 @@ pub const PF_LINE_JOIN_MITER: u8 = 0; pub const PF_LINE_JOIN_BEVEL: u8 = 1; pub const PF_LINE_JOIN_ROUND: u8 = 2; +// `geometry` + +pub const PF_ARC_DIRECTION_CW: u8 = 0; +pub const PF_ARC_DIRECTION_CCW: u8 = 1; + // `renderer` + pub const PF_RENDERER_OPTIONS_FLAGS_HAS_BACKGROUND_COLOR: u8 = 0x1; // Types @@ -52,6 +59,7 @@ pub type PFPathRef = *mut Path2D; pub type PFCanvasFontContextRef = *mut CanvasFontContext; pub type PFLineCap = u8; pub type PFLineJoin = u8; +pub type PFArcDirection = u8; // `geometry` #[repr(C)] @@ -249,6 +257,40 @@ pub unsafe extern "C" fn PFPathBezierCurveTo(path: PFPathRef, (*path).bezier_curve_to((*ctrl0).to_rust(), (*ctrl1).to_rust(), (*to).to_rust()) } +#[no_mangle] +pub unsafe extern "C" fn PFPathArc(path: PFPathRef, + center: *const PFVector2F, + radius: f32, + start_angle: f32, + end_angle: f32, + direction: PFArcDirection) { + let direction = if direction == 0 { ArcDirection::CW } else { ArcDirection::CCW }; + (*path).arc((*center).to_rust(), radius, start_angle, end_angle, direction) +} + +#[no_mangle] +pub unsafe extern "C" fn PFPathArcTo(path: PFPathRef, + ctrl: *const PFVector2F, + to: *const PFVector2F, + radius: f32) { + (*path).arc_to((*ctrl).to_rust(), (*to).to_rust(), radius) +} + +#[no_mangle] +pub unsafe extern "C" fn PFPathRect(path: PFPathRef, rect: *const PFRectF) { + (*path).rect((*rect).to_rust()) +} + +#[no_mangle] +pub unsafe extern "C" fn PFPathEllipse(path: PFPathRef, + center: *const PFVector2F, + axes: *const PFVector2F, + rotation: f32, + start_angle: f32, + end_angle: f32) { + (*path).ellipse((*center).to_rust(), (*axes).to_rust(), rotation, start_angle, end_angle) +} + #[no_mangle] pub unsafe extern "C" fn PFPathClosePath(path: PFPathRef) { (*path).close_path()