[cairo] Problems with cairo_get_line_width and "new" semantics
spitzak at d2.com
Tue May 16 14:12:40 PDT 2006
Carl Worth wrote:
> Perhaps what we should do is to add two new functions for working with
> the pen directly as the ellipse it is?
> cairo_public void
> cairo_set_pen (cairo_t *cr,
> double line_width,
> const cairo_matrix_t *matrix);
> cairo_public void
> cairo_get_pen (cairo_t *cr,
> double *line_width,
> cairo_matrix_t *matrix);
> Then it's simple enough to specify cairo_set_line_width as being
> equivalent to calling cairo_set_pen with the matrix argument equal to
> the current CTM.
> Then I suppose cairo_get_line_width could be specified as being
> equivalent to cairo_get_pen and simply ignoring the matrix
> returned. That is, this would return a line width in the _original_
> user space and not in the current user space.
I think the "all api is in user CTM" idea would also apply here. So I
set_pen(size, matrix) would multiply the matrix by the CTM and store
that as the penCTM. It would also store the size.
get_pen() would divide the penCTM by the CTM and return that, and return
the size unchanged.
set_pen_width(size) would be the same as set_pen(size, identity).
get_pen_width() would return the size multiplied by the square root of
the determinant of the penCTM divided by the CTM.
What about dash patterns? It looks like these are going to have to be
specified in "pen space" since they are not vectors but instead
magnitudes. This would probably be the best api anyway because users
mostly want to turn dashes on/off and should not have to return to the
penCTM to do so.
For compatability with the current system, a "size" different than the
penCTM is needed. The actual pen is a circle of diameter "size" in the
penCTM, while dashes are measured in 1 unit lengths in the penCTM. (I'm
guessing that dashes are laid out in pen space, so that if the pen is an
ellipse the dashes are longer in lines parallel to the pen, please
correct me if wrong).
However the "size" could be eliminated, making it more consistent with
the proposed fontCTM, by measuring dashes in "pens". This is also
somewhat more user friendly as you can easily make evenly-spaced dots
with a line width between them. However it is not back-compatable...
A hybrid approach, proably useful for the internals, is to store a
penCTM in which the pen is a 1-unit circle, and store 1/size. Dash
patterns are multiplied by 1/size to get units in penCTM.
More information about the cairo