                     (BasicStroke. width cap-code join-code miter-limit)))))
     (when (and x y (or rotate scale scale-x scale-y))
       (doto g2d
-        (.translate x y)
+        (.translate (double x) (double y))
         (.rotate (* degrees-to-radians (or rotate 0.0)))
         (.scale (or scale-x scale 1.0) (or scale-y scale 1.0))
-        (.translate (- x) (- y)))))
+        (.translate (double (- x)) (double (- y))))))
+
+(defn intersect-shapes [shape1 shape2]
+  (doto (Area. shape1) (.intersect (Area. shape2))))
+
+(defn- with-g2d-clip-fn [g2d clip body-fn]
+  (let [original-clip (.getClip g2d)]
+    (.setClip g2d (intersect-shapes clip original-clip))
+    (body-fn)
+    (.setClip g2d original-clip)))
 
 (defn- with-g2d-state-fn [g2d params body-fn]
   (let [color (.getColor g2d)

                 (float (+ y (/ height 2))))))

(defmethod draw-primitive String
  [g2d text {:keys [x y font fill stroke]}]
  (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)

;
; gradients
; affine transforms

(defn read-image [file]
  (javax.imageio.ImageIO/read (clojure.java.io/file file)))

(defn enable-anti-aliasing
  "Turn on (off) anti-aliasing for a graphics context."
