this repo has no description
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

🚧 Start implementing hatched fill patterns

authored by

Gwenn Le Bihan and committed by
Ewen Le Bihan
6881fe3d a8821c0d

+48 -4
+48 -4
src/fill.rs
··· 1 1 use crate::{Color, ColorMapping, RenderCSS}; 2 2 3 3 #[derive(Debug, Clone, Copy)] 4 + pub enum HatchDirection { 5 + Horizontal, 6 + Vertical, 7 + BottomUpDiagonal, 8 + TopDownDiagonal, 9 + } 10 + 11 + impl HatchDirection { 12 + pub fn svg_filter_name(&self) -> String { 13 + "hatch-".to_owned() 14 + + match self { 15 + HatchDirection::Horizontal => "horizontal", 16 + HatchDirection::Vertical => "vertical", 17 + HatchDirection::BottomUpDiagonal => "bottom-up", 18 + HatchDirection::TopDownDiagonal => "top-down", 19 + } 20 + } 21 + 22 + pub fn svg_pattern_definition(&self) -> String { 23 + // https://stackoverflow.com/a/14500054/9943464 24 + format!( 25 + r#"<pattern id="{}" patternUnits="userSpaceOnUse" width="{}" height="{}">"#, 26 + self.svg_filter_name(), 27 + todo!(), 28 + todo!() 29 + ) + &match self { 30 + HatchDirection::BottomUpDiagonal => format!( 31 + r#"<path 32 + d="M-1,1 l2,-2 33 + M0,4 l4,-4 34 + M3,5 l2,-2" 35 + style="stroke:black; stroke-width:1" 36 + />"# 37 + ), 38 + HatchDirection::Horizontal => todo!(), 39 + HatchDirection::Vertical => todo!(), 40 + HatchDirection::TopDownDiagonal => todo!(), 41 + } + "</pattern>" 42 + } 43 + } 44 + 45 + #[derive(Debug, Clone, Copy)] 4 46 pub enum Fill { 5 47 Solid(Color), 6 48 Translucent(Color, f32), 7 - Hatched, 8 - Dotted, 49 + Hatched(HatchDirection), 50 + Dotted(f32), 9 51 } 10 52 11 53 impl RenderCSS for Fill { ··· 17 59 Fill::Translucent(color, opacity) => { 18 60 format!("fill: {}; opacity: {};", color.to_string(colormap), opacity) 19 61 } 20 - Fill::Dotted => unimplemented!(), 21 - Fill::Hatched => unimplemented!(), 62 + Fill::Dotted(radius) => unimplemented!(), 63 + Fill::Hatched(direction) => { 64 + format!("fill: url(#{});", direction.svg_filter_name()) 65 + } 22 66 } 23 67 } 24 68