diff options
author | Jovansonlee Cesar <ivanceras@gmail.com> | 2018-10-05 04:25:11 +0800 |
---|---|---|
committer | Jovansonlee Cesar <ivanceras@gmail.com> | 2018-10-05 04:25:11 +0800 |
commit | 166a8a8e20391984990b049528d5d6afbf0cc4ce (patch) | |
tree | a83af1d1239beda5f06ec008e09a7c723e48ce90 | |
parent | ffac40b6fe04632e58f0ae225467a56cfaf9fb52 (diff) |
Make the settings affect the styling
remove unused settings fields
-rw-r--r-- | svgbob/src/element.rs | 1 | ||||
-rw-r--r-- | svgbob/src/grid.rs | 105 | ||||
-rw-r--r-- | svgbob/src/settings.rs | 50 |
3 files changed, 58 insertions, 98 deletions
diff --git a/svgbob/src/element.rs b/svgbob/src/element.rs index f723a35..9a1902c 100644 --- a/svgbob/src/element.rs +++ b/svgbob/src/element.rs @@ -343,7 +343,6 @@ impl Element { match *stroke { Solid => (), Dashed => { - svg_line.assign("fill", "none"); svg_line.assign("class","dashed"); } }; diff --git a/svgbob/src/grid.rs b/svgbob/src/grid.rs index 1c8966c..83e9ba8 100644 --- a/svgbob/src/grid.rs +++ b/svgbob/src/grid.rs @@ -341,42 +341,57 @@ fn get_defs() -> Definitions { fn get_styles(settings: &Settings) -> Style { let style = format!( r#" - rect.backdrop {{ - fill: {background_color}; - }} - line,path {{ - stroke: {stroke_color}; - stroke-width: {stroke_width}; - stroke-opacity: 1; - fill-opacity: 1; - stroke-linecap: round; - stroke-linejoin: miter; - }} - line.dashed {{ - stroke-dasharray: 5; - }} - circle.solid {{ - fill:{stroke_color}; - stroke: black; - stroke-width: {stroke_width}; - stroke-opacity: 1; - fill-opacity: 1; - stroke-linecap: round; - stroke-linejoin: miter; - }} - circle.open {{ - fill:none; - stroke: black; - stroke-width: {stroke_width}; - stroke-opacity: 1; - fill-opacity: 1; - stroke-linecap: round; - stroke-linejoin: miter; - }} - tspan.head{{ - fill: none; - stroke: none; - }} +rect.backdrop {{ + fill: {background_color}; +}} +text{{ + fill: {stroke_color}; +}} + +circle {{ + fill: none; + stroke: {stroke_color}; + stroke-width: {stroke_width}; +}} + +line {{ + stroke: {stroke_color}; + stroke-width: {stroke_width}; + stroke-opacity: 1; + fill-opacity: 1; + stroke-linecap: round; + stroke-linejoin: miter; +}} + +path {{ + fill: none; + stroke: {stroke_color}; + stroke-width: {stroke_width}; + stroke-opacity: 1; + fill-opacity: 1; + stroke-linecap: round; + stroke-linejoin: miter; +}} + +line.dashed {{ + stroke-dasharray: 5; +}} + +.fg_fill {{ + fill: {stroke_color}; +}} + + +.bg_fill {{ + fill: {background_color}; + stroke: {stroke_color}; + stroke-width: {stroke_width}; +}} + +tspan.head{{ + fill: none; + stroke: none; +}} "#, stroke_width = settings.stroke_width, stroke_color = &settings.stroke_color, @@ -398,7 +413,7 @@ fn arrow_marker() -> Marker { let path = SvgPolygon::new() .set("points", "0,0 0,4 8,2 0,0") - .set("fill", "black"); + .set("class", "fg_fill"); marker.append(path); marker @@ -416,9 +431,7 @@ fn clear_arrow_marker() -> Marker { let path = SvgPolygon::new() .set("points", "2,2 2,12 18,7 2,2") - .set("fill", "none") - .set("stroke-width", 2) - .set("stroke", "black"); + .set("class", "bg_fill"); marker.append(path); marker @@ -443,7 +456,7 @@ fn circle_marker() -> Marker { .set("cx",10) .set("cy",10) .set("r",8) - .set("fill","black"); + .set("class", "fg_fill"); marker.append(circle); marker } @@ -463,7 +476,7 @@ fn square_marker() -> Marker { .set("y",0) .set("width",20) .set("height",20) - .set("fill","black"); + .set("class", "fg_fill"); marker.append(square); marker } @@ -482,9 +495,7 @@ fn open_circle_marker() -> Marker { .set("cx",10) .set("cy",10) .set("r",4) - .set("stroke","black") - .set("stroke-width",2) - .set("fill","white"); + .set("class", "bg_fill"); marker.append(circle); marker } @@ -502,9 +513,7 @@ fn big_open_circle_marker() -> Marker { .set("cx",20) .set("cy",20) .set("r",6) - .set("stroke","black") - .set("stroke-width",2) - .set("fill","white"); + .set("class", "bg_fill"); marker.append(circle); marker } diff --git a/svgbob/src/settings.rs b/svgbob/src/settings.rs index ec20900..addba26 100644 --- a/svgbob/src/settings.rs +++ b/svgbob/src/settings.rs @@ -1,17 +1,8 @@ -/// optimization options: -/// 1. None -> Fastest, but not correct looking (paths and text are not reduced) -/// 2. Fast -> Fast and correct looking (text are reduced) -/// 3. All -> Correct looking but slow (paths and text are reduced) #[derive(Debug, Clone)] pub struct Settings { pub text_width: f32, pub text_height: f32, - /// do optimization? if false then every piece are disconnected - pub optimize: bool, - /// if optmization is enabled, - /// true means all reduceable paths will be in 1 path definition - pub compact_path: bool, /// the svg class of the generated svg pub class: Option<String>, /// the id of the generated svg @@ -41,43 +32,6 @@ impl Settings { self.stroke_width = self.stroke_width * scale; } - pub fn no_optimization() -> Settings { - let mut settings = Settings::default(); - settings.optimize = false; - settings.compact_path = false; - settings - } - - pub fn separate_lines() -> Settings { - let mut settings = Settings::default(); - settings.optimize = true; - settings.compact_path = false; - settings - } - - pub fn compact() -> Settings { - let mut settings = Settings::default(); - settings.optimize = true; - settings.compact_path = true; - settings - } - - fn set_id(&mut self, id: String) { - self.id = Some(id); - } - - fn set_class(&mut self, class: String) { - self.class = Some(class); - } - - pub fn set_selector(&mut self, id: Option<String>, class: Option<String>) { - if let Some(id) = id { - self.set_id(id); - } - if let Some(class) = class { - self.set_class(class); - } - } } impl Default for Settings { @@ -85,14 +39,12 @@ impl Default for Settings { Settings { text_width: 8.0, text_height: 16.0, - optimize: true, - compact_path: true, class: Some("bob".to_string()), id: None, font_family: "arial".to_string(), font_size: 14.0, stroke_width: 2.0, - stroke_color: "black".into(), + stroke_color: "currentColor".into(), background_color: "white".into(), } } |