[cairo] Problems with cairo_get_line_width and "new" semantics

Carl Worth cworth at cworth.org
Tue May 16 09:49:50 PDT 2006


On Tue, 16 May 2006 01:41:19 -0700, Carl Worth wrote:
> On Tue, 16 May 2006 04:06:00 -0400 (EDT), Behdad Esfahbod wrote:
> > Thinking about what new API we need to support the font ctm,
> > leads me to this other question: what does cairo_get_line_width
> > return?
> 
> A good question.
> 
> The easy answer I have here is that this is a value that crosses the
> user-level API so it must necessarily be in the current user
> space. Let's see how that plays out:

It turns out this doesn't play out well at all.

> 	cairo_set_line_width (cr, cairo_get_line_width (cr));

While the above seems appealing, it's also totally impossible.

When we call set_line_width what we are doing is constructing a pen
that is elliptical in device space. The pen is specified by the pair
of the line_width value and a pen matrix (the CTM at the time of
set_line_width). The line width controls the size of the pen while the
matrix controls the ratio and orientation of the major/minor axes of
the ellipse.

Now, at the time of get_line_width, the CTM may be different than the
pen's matrix. In this case it's quite easy to demonstrate cases where
no call to set_line_width will achieve the current pen, (imagine a
change in relative scale or orientation of ellipse axes).

So the requirement of being able to do:

	set_line_width (get_line_width())

without changing the current pen is intractable and must be rejected.

So what query functionality should we provide instead? It seems we
should provide the actual information in the graphics state, which
would be a pen (both a line_width and a matrix).

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.

Thoughts?

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20060516/f06db937/attachment.pgp


More information about the cairo mailing list