chiark / gitweb /
pieces: break out svg_piece_raw, nfc
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Feb 2021 12:58:38 +0000 (12:58 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Feb 2021 12:58:38 +0000 (12:58 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/pieces.rs

index ba26b01e38974689a973a3e2d5e58da55957d34b..943d83d78d1fd0b401860ca89314ccd70c00d4ad 100644 (file)
@@ -129,28 +129,7 @@ impl Outline for SimpleShape {
 impl Piece for SimpleShape {
   #[throws(IE)]
   fn svg_piece(&self, f: &mut Html, pri: &PieceRenderInstructions) {
-    let f = &mut f.0;
-    let ef = |f: &mut String, cmap: &ColourMap, attrname: &str, otherwise| {
-      if let Some(colour) = cmap.get(pri.face) {
-        write!(f, r##" {}="{}""##, attrname, colour.0)
-      } else {
-        write!(f, "{}", otherwise)
-      }
-    };
-    if self.colours.len() == 0 {
-      write!(f,
-             r##"<path fill="none" \
-                  stroke-width="{}" stroke="transparent" d="{}"/>"##,
-             INVISIBLE_EDGE_SENSITIVE,
-             &self.path.0)?;
-    }
-    write!(f, r##"<path"##)?;
-    ef(f, &self.colours, "fill", r##" fill="none""##)?;
-    if self.edges.len() != 0 {
-      write!(f, r##" stroke-width="{}""##, &self.edge_width)?;
-    }
-    ef(f, &self.edges, "stroke", "")?;
-    write!(f, r##" d="{}"/>"##, &self.path.0)?;
+    self.svg_piece_raw(f, pri)?;
   }
   fn describe_html(&self, face: Option<FaceId>) -> Html {
     Html(if_chain! {
@@ -209,6 +188,35 @@ impl SimpleShape {
 
     shape
   }
+
+  #[throws(IE)]
+  fn svg_piece_raw<
+      >(&self, f: &mut Html, pri: &PieceRenderInstructions,
+  )
+  {
+    let f = &mut f.0;
+    let ef = |f: &mut String, cmap: &ColourMap, attrname: &str, otherwise| {
+      if let Some(colour) = cmap.get(pri.face) {
+        write!(f, r##" {}="{}""##, attrname, colour.0)
+      } else {
+        write!(f, "{}", otherwise)
+      }
+    };
+    if self.colours.len() == 0 {
+      write!(f,
+             r##"<path fill="none" \
+                  stroke-width="{}" stroke="transparent" d="{}"/>"##,
+             INVISIBLE_EDGE_SENSITIVE,
+             &self.path.0)?;
+    }
+    write!(f, r##"<path"##)?;
+    ef(f, &self.colours, "fill", r##" fill="none""##)?;
+    if self.edges.len() != 0 {
+      write!(f, r##" stroke-width="{}""##, &self.edge_width)?;
+    }
+    ef(f, &self.edges, "stroke", "")?;
+    write!(f, r##" d="{}"/>"##, &self.path.0)?;
+  }
 }
 
 #[typetag::serde(tag="type")]