From bca5119e8b93edaa13e391a84b7f90d2a6426230 Mon Sep 17 00:00:00 2001
From: Ryan Oldenburg <guzba8@gmail.com>
Date: Sat, 20 Feb 2021 13:31:25 -0600
Subject: [PATCH] linecap, linejoin

---
 src/pixie/fileformats/svg.nim | 38 +++++++++++++++++++++++++++++++++++
 src/pixie/paths.nim           |  6 ++++++
 2 files changed, 44 insertions(+)

diff --git a/src/pixie/fileformats/svg.nim b/src/pixie/fileformats/svg.nim
index 683fe68..3e0437e 100644
--- a/src/pixie/fileformats/svg.nim
+++ b/src/pixie/fileformats/svg.nim
@@ -8,6 +8,8 @@ const svgSignature* = "<?xml"
 type Ctx = object
   fill, stroke: ColorRGBA
   strokeWidth: float32
+  strokeLineCap: LineCap
+  strokeLineJoin: LineJoin
   transform: Mat3
 
 template failInvalid() =
@@ -25,6 +27,8 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
     fill = node.attr("fill")
     stroke = node.attr("stroke")
     strokeWidth = node.attr("stroke-width")
+    strokeLineCap = node.attr("stroke-linecap")
+    strokeLineJoin = node.attr("stroke-linejoin")
     transform = node.attr("transform")
 
   if fill == "":
@@ -46,6 +50,40 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
   else:
     result.strokeWidth = parseFloat(strokeWidth)
 
+  if strokeLineCap == "":
+    discard # Inherit
+  else:
+    case strokeLineCap:
+    of "butt":
+      result.strokeLineCap = lcButt
+    of "round":
+      result.strokeLineCap = lcRound
+    of "square":
+      result.strokeLineCap = lcSquare
+    of "inherit":
+      discard
+    else:
+      raise newException(
+        PixieError, "Invalid stroke-linecap value " & strokeLineCap
+      )
+
+  if strokeLineJoin == "":
+    discard # Inherit
+  else:
+    case strokeLineJoin:
+    of "miter":
+      result.strokeLineJoin = ljMiter
+    of "round":
+      result.strokeLineJoin = ljRound
+    of "bevel":
+      result.strokeLineJoin = ljBevel
+    of "inherit":
+      discard
+    else:
+      raise newException(
+        PixieError, "Invalid stroke-linejoin value " & strokeLineJoin
+      )
+
   if transform == "":
     discard # Inherit
   else:
diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim
index 48cf6d1..3bef039 100644
--- a/src/pixie/paths.nim
+++ b/src/pixie/paths.nim
@@ -8,6 +8,12 @@ type
     wrNonZero
     wrEvenOdd
 
+  LineCap* = enum
+    lcButt, lcRound, lcSquare
+
+  LineJoin* = enum
+    ljMiter, ljRound, ljBevel
+
   PathCommandKind* = enum
     ## Type of path commands
     Close,