       (let [params (merge default-primitive-params
                                         (:params item))]
       (set-style g2d params)
-      (draw-primitive g2d (:type item) params)))))
+      (draw-primitive g2d (:type item) (complete-coordinates params))))))
 
 (defn paint-canvas-graphics [^Graphics graphics data]
   (draw-primitives graphics data))

  (doto g2d
    (.setColor (:color params))))

(defmulti draw-primitive (fn [g2d shape params] shape))

(defmethod draw-primitive :primitive-arc
  [g2d shape {:keys [x y w h filled start-angle arc-angle]}]
  (if filled
    (.fillArc g2d x y w h start-angle arc-angle)
    (.drawArc g2d x y w h start-angle arc-angle)))

(defmethod draw-primitive :primitive-ellipse
  [g2d shape {:keys [x y w h filled]}]
  (if filled
    (.fillOval g2d x y w h)
    (.drawOval g2d x y w h)))

(defmethod draw-primitive :primitive-image
  [g2d shape {:keys [image x y w h]}]
  (.drawImage g2d
              image x y
              (or w (.getWidth image))
              (or h (.getHeight image)) nil))

(defmethod draw-primitive :primitive-line
  [g2d shape {:keys [x y w h filled]}]
  (.drawLine g2d x y (+ x w) (+ x h)))

(defmethod draw-primitive :primitive-polygon
  [g2d shape {:keys [vertices filled closed]}]

        (.drawPolyline g2d xs ys n)))

(defmethod draw-primitive :primitive-rect
  [g2d shape {:keys [l t w h filled]}]
  (if filled
    (.fillRect g2d l t w h)
    (.drawRect g2d l t w h)))

(defmethod draw-primitive :primitive-round-rect
  [g2d shape {:keys [l t w h filled arc-width arc-height]}]
  (if filled
    (.fillRoundRect g2d l t w h arc-width arc-height)
    (.drawRoundRect g2d l t w h arc-width arc-height)))

(defn draw-string-center
  "Draw a string centered at position x,y."
  [^Graphics2D graphics ^String text x y]
  (let [context (.getFontRenderContext graphics)
        height (.. graphics
                   getFont (createGlyphVector context text)
                   getVisualBounds
                   getHeight)
        width (.. graphics
                  getFontMetrics
                  (getStringBounds text graphics)
                  getWidth)]
    (.drawString graphics text
                 (float (- x (/ width 2)))
                 (float (+ y (/ height 2))))))

(defmethod draw-primitive :primitive-text
  [g2d shape  {:keys [text x y font]}]
  (let [{:keys [name bold italic underline strikethrough size]} font
        style (bit-or (if bold Font/BOLD 0) (if italic Font/ITALIC 0))
        font1 (Font. name style size)
        attributes (.getAttributes font1)]
    (doto attributes
      (.put TextAttribute/STRIKETHROUGH
            (if strikethrough TextAttribute/STRIKETHROUGH_ON false))
      (.put TextAttribute/UNDERLINE
            (if underline TextAttribute/UNDERLINE_ON -1)))
    (let [font2 (Font. attributes)]
      (.setFont g2d font2)
      (draw-string-center g2d text x y))))

(defn draw-primitives [g2d items]
  (enable-anti-aliasing g2d)
