Unify AspectRatio, clip, and Viewport operations
Loosely quoting some relevant parts of the spec:
- All elements that establish a new viewport (
svg
,symbol
,image
,marker
,pattern
) elements have attributeviewBox
. Its value isx y width height
, which define a new coordinate system inside a rectangle in the parent coordinate system. - The rectangle in the parent coordinate system is specified by the
x
,y
,width
,height
attributes, for example, in theimage
element or in theuse
element that references asymbol
. - Positioning/scaling of the viewport is controlled by the
preserveAspectRatio
attribute. - Whether there's a clipping rectangle set on the x/y/width/height viewport or the viewBox is controlled by the
clip
property, which we currently don't support (#272).
#92 (closed) is about a real bug where we don't clip symbol
and svg
appropriately. I am not sure if this is just due to incorrect defaults on the overflow
property for the symbol
element, or if we are calling draw_in_viewport()
incorrectly for it.
We do the scaling/positioning of the preserveAspectRatio
value in aspect_ratio.rs
. However, we make it the caller's responsibility to:
- deal with viewbox.x and viewbox.y; that logic only deals with width and height.
- deal with a non-exixtent
viewBox
attribute. - deal with clipping rectangles
It would be nice to unify all of this, including making image.rs
use the viewport logic.
viewport.rs
already deals with a bunch of this stuff. It doesn't handle the special case of the marker
element; it would be nice to have it there, too. Note that marker
does not have x
, y
, width
, height
attributes; instead it uses refX
/refY
for the anchor point plus a viewport size defined by markerWidth
/markerHeight
after scaling for markerUnits
.