mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-11 01:40:56 +08:00
Bezier-rs: continue converting demos from canvas to SVG (#779)
* Convert constructor to use svg * Convert the through_points functions to svg * Convert length, lut, derivative, and tangent from canvas to svg * Fixed bug when t1 == t2 in split * Converted split and trim to use svg representation, and swapped slider options default to use quadratic options * Convert normal and curvature to use svg representation in bezier-rs-demos * Convert the project function to use svg representation in bezier-rs-demos * Convert the local_extrema, bbox, and inflections to use svgs * Add text offset constants * Fix typo Co-authored-by: Robert Nadal <Robnadal44@gmail.com> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Robert Nadal
Keavon Chambers
parent
e9cd792635
commit
55f6d13daf
@@ -4,8 +4,12 @@ pub const SVG_CLOSE_TAG: &str = "</svg>";
|
||||
|
||||
// Stylistic constants
|
||||
pub const BLACK: &str = "black";
|
||||
pub const WHITE: &str = "white";
|
||||
pub const GRAY: &str = "gray";
|
||||
pub const RED: &str = "red";
|
||||
pub const ORANGE: &str = "orange";
|
||||
pub const GREEN: &str = "green";
|
||||
pub const NONE: &str = "none";
|
||||
|
||||
// Default attributes
|
||||
pub const CURVE_ATTRIBUTES: &str = "stroke=\"black\" stroke-width=\"2\" fill=\"none\"";
|
||||
@@ -13,7 +17,21 @@ pub const HANDLE_LINE_ATTRIBUTES: &str = "stroke=\"gray\" stroke-width=\"1\" fil
|
||||
pub const ANCHOR_ATTRIBUTES: &str = "r=\"4\" stroke=\"black\" stroke-width=\"2\" fill=\"white\"";
|
||||
pub const HANDLE_ATTRIBUTES: &str = "r=\"3\" stroke=\"gray\" stroke-width=\"1.5\" fill=\"white\"";
|
||||
|
||||
/// Helper function to create an SVG text entitty.
|
||||
// Text constants
|
||||
pub const TEXT_OFFSET_X: f64 = 5.;
|
||||
pub const TEXT_OFFSET_Y: f64 = 193.;
|
||||
|
||||
/// Helper function to create an SVG text entity.
|
||||
pub fn draw_text(text: String, x_pos: f64, y_pos: f64, fill: &str) -> String {
|
||||
format!(r#"<text x="{x_pos}" y="{y_pos}" fill="{fill}">{text}</text>"#)
|
||||
}
|
||||
|
||||
/// Helper function to create an SVG circle entity.
|
||||
pub fn draw_circle(x_pos: f64, y_pos: f64, radius: f64, stroke: &str, stroke_width: f64, fill: &str) -> String {
|
||||
format!(r#"<circle cx="{x_pos}" cy="{y_pos}" r="{radius}" stroke="{stroke}" stroke-width="{stroke_width}" fill="{fill}"/>"#)
|
||||
}
|
||||
|
||||
/// Helper function to create an SVG circle entity.
|
||||
pub fn draw_line(start_x: f64, start_y: f64, end_x: f64, end_y: f64, stroke: &str, stroke_width: f64) -> String {
|
||||
format!(r#"<line x1="{start_x}" y1="{start_y}" x2="{end_x}" y2="{end_y}" stroke="{stroke}" stroke-width="{stroke_width}"/>"#)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user