[cairo] Cairo and ISO C++

Behdad Esfahbod behdad at behdad.org
Tue Jan 14 00:40:39 PST 2014

On 14-01-02 02:51 AM, Herb Sutter wrote:
> Thanks Behdad,
>> During cairo's development, there were some decisions made that we
>> regretted later on.  I was going to suggest that those be revisited for
>> standardization, but reading the documents you linked, I think that will go
>> down the same design-by-committee path that you are trying to avoid.
> It sounds like those would be good to know about regardless, if you could share.
> Actually we mainly want to avoid that for the initial proposal, but if there are known 'errata' that would be good to know about. Possibly they could be addressed in the C++ wrapping, if they can be addressed without changing Cairo. Alternatively, perhaps this would be a good point to consider addressing some of them in Cairo as well if you think that's proper, given that if this standardization process bears fruit the audience of the Cairo API will expand to a lot of new users. In any event I think it would be good to know about them.

Bill already mentioned most of what I had in mind.  To reiterate:  Currently
when one sets line width and font size, those are recorded in user-space, and
as such following transformation matrix changes will change the final line
width / font size.  This is unintuitive and troublesome.  Example:

  set_line_width (10)
  scale (2)
  move_to / line_to / ...
  stroke ()

The stroke will now have width 20, not 10.

To fix this, we want to lock the line width / font size in device space at the
time they are set.  To fix these in the wrapper is not impossible:

  - During set_line_width / set_font_size, multiply them by the current
transformation matrix and set to *that*,

  - During stroke() / show_text/glyphs/...(), cairo_save(), set transformation
matrix to identity, stroke/show_text/..., and cairo_restore(),

There are a few problems with this:

  - For font_size: show_text/glyphs/... take glyph coordinates, so we need to
multiply those by the current transformation matrix before resetting the
matrix.  Alternatively, we can transform the font matrix by inverse of current
transformation matrix and set that before the operation.

  - For line_width there are more problems:

    * Currently the set/get_line_width operate on a single number.  Whereas
the stroke shape after a transformation matrix becomes an ellipse, so we
cannot express that with a single number.  We can try saving the
transformation matrix at the time of set_line_width, and before calling
stroke(), set that matrix.  But tracking this with cairo_save()/restore()
becomes tricky.  Also, this has implications on dashed lines.  I think the
dash pattern also suffers from the same shortcomings.

To summarize: there's a reason we have not fixed these in cairo itself: they
are tricky to resolve now.  Perhaps others have ideas?  Perhaps we can add
ugly-named new functions with the more useful semantics?


More information about the cairo mailing list