Comment 2 for bug 561857

Revision history for this message
v1nce (vincent-pennec) wrote :

CONTEXT:
SVG says the stroke will be 50% in the shape and 50 % outside. This is nor good nor bad, this is a choice and we have to go with it.
This choice has (dis)advantages like IE box model vs W3c box model and if does the border width count in element width.

PROBLEM :
Strokes look blurry when their sizes are (2n+1) pixels (see pixelsnap addin) because they don't fill "complete" pixels but rather 50%.
There would be no (less) problem if the stroke was drawn OUTSIDE of the shape.

(not a practical) SOLUTION? :
all shapes should be offseted by 0.5 px so that the stroke fills a complete pixel.

Offseting could be done more efficiently by using a grid but no combination of grid snaping looks effective to me :

eg:

new 32*32px document
new grid 1*1 starting @ 0,0 maingrid @ 5,5

Bounding Box
============
snap to bounding box = true
snap to nodes = false

draw a rect with a 1 px border
=> Bad : the first point isn't grabbed by grid.

resize(if visual)
=> Good : the border fits in a full pixel
resize(if geometric)
=> Bad : the border spread over 2 pixels

draw a complex shape with a 1 px border and try to move a node
=> Bad : node isn't aligned [because snap to nodes is off]

Snap to node
============
snap to bounding box = flase
snap to nodes = true

draw a rect with a 1 px border
=> Bad[*] : the first point is grabbed by grid at integer coordinates x,y so the border spread over two pixels (50% inside the shape, 50% outside the shape)

resize
=> Bad : the border spread over 2 pixels

draw a complex shape with a 1 px border and try to move a node
=> Bad : node is grabbed by grid at integer coordinates x,y so the border spread over two pixels

One could go with 0.5,0.5 grid and snap to node, but if you draw shapes with no (or 2n+0px) border the shapes may fall in between pixels.

THE MOST EFFECTIVE :
Visual bounding box works rather well for rectangle, but I don't want to snap only corner of a rectangle but all nodes of a complex shape.

So I propose to extend the visual concept from bounding box to shape. In this mode, all nodes would be offseted using a erosion of 0.5*stroke width
and so
the stroke would look like it is outside of the shape and
nodes will look like being at the fronteer with the stroke instead of being in the middle.

If there are straight horizontal/vertical lines in your complex shape and you grid-align your nodes, then the stroke will be 100% perfect

The underlying coordinates of nodes will still be in svg mode but their display on screen will be faked (like coordinates for the visual bounding box)

ANOTHER SOLUTION
that solves less problems but is simpler : add an option so that when the stroke width is a straight (2n+1) multiple of grid size then the nodes are not aligned on integer coordinates but at x+0.5*gridwidth