     }
 
     func with(style:Style, block:() -> Void) {
-        CGContextSaveGState(self)
-        self.apply(style)
+        let savedStyle = self.style
+//        CGContextSaveGState(self)
+        self.style = style
+//        self.apply(style)
         block()
-        CGContextRestoreGState(self)
-    }
-}
+//        CGContextRestoreGState(self)
+        self.style = savedStyle
+    }
+}

        }
    }

    func apply(style:Style) {
        if let fillColor = style.fillColor {
            setFillColor(fillColor)
        }
        if let strokeColor = style.strokeColor {
            setStrokeColor(strokeColor)
        }
        if let lineWidth = style.lineWidth {
            setLineWidth(lineWidth)
        }
        if let lineCap = style.lineCap {
            setLineCap(lineCap)
        }
        if let lineJoin = style.lineJoin {
            setLineJoin(lineJoin)
        }
        if let miterLimit = style.miterLimit {
            setMiterLimit(miterLimit)
        }
        if let lineDash = style.lineDash {
            setLineDash(lineDash, phase: 0.0)
        }
        if let lineDashPhase = style.lineDashPhase {
            // TODO
        }
        if let flatness = style.flatness {
            setFlatness(flatness)
        }
        if let alpha = style.alpha {
            setAlpha(alpha)
        }
        if let blendMode = style.blendMode {
            setBlendMode(blendMode)
        }
    }

            }
            else {
                let style = Style()
                setAssociatedObject(self, &CGContext_Style_Key, style)
                return style
            }
        }
