+
+(defun image-surface-create-from-svg (filename &key width height (format :argb32)id)
+ (with-handle (handle :filename filename)
+ (multiple-value-bind (width height)
+ (cond
+ ((and width height) (values width height))
+ (width
+ (let ((ratio (/ (handle-height handle) (handle-width handle))))
+ (values width (truncate (* width ratio)))))
+ (height
+ (let ((ratio (/ (handle-width handle) (handle-height handle))))
+ (values (truncate (* height ratio)) height)))
+ (t (values (handle-width handle) (handle-height handle))))
+ (let ((image (make-instance 'cairo:image-surface
+ :width width :height height :format format)))
+ (cairo:with-surface (image cr)
+ (cairo:scale cr (/ width (handle-width handle)) (/ height (handle-height handle)))
+ (render-cairo handle cr id))
+ image))))