In the files in src/display there are many instances of this
Inkscape::DrawingContext::Save save(dc);
First thing, I don't understand the syntax. What does the lower case
"save" in that line indicate? The only places "::Save save(" appear
in
the source code are instances
of this line.
Secondly, it acts strangely. Moving it around breaks graphics for some
reason that
escapes me. For instance this:
Inkscape::DrawingContext::Save save(dc); //PROBLEM LINE
dc.transform(aff);
double thickness = decorateItem(dc, aff, phase_length);
dc.setLineWidth(thickness);
dc.strokePreserve();
dc.newPath();
results in mangled graphics (text decoration drawn as if with a very
thick line, but in what appears to be the correct location), whereas
moving the first two lines above into
double DrawingText::decorateItem(DrawingContext &dc, Geom::Affine
const &aff,
double phase_length)
as the first two lines of that method results in normal graphics (text
decoration drawn with the expected line thickness). That is:
line1
line2
call
is broken but
call
(inside called function)
line1
line2
works. Moving "dc.setlinewidth()" from the position shown above into
decorateItem() as the line before its return does not make any
difference in either of these cases. decorateItem() just defines a
cairo path with moveto/lineto on
_ct in dc, it doesn't touch anything else in the dc.
Using the debugger and stepping through showed that execution of the
problem line passes through this:
DrawingContext::Save::Save(DrawingContext &dc)
: _dc(&dc)
{
_dc->save();
}
in drawing-context.cpp. _dc->save() just does
cairo_save(_ct);
I have never seen anything quite like this when using cairo directly,
that is, calling cairo_save() and cairo_restore() has never resulted in
mysteriousness of this level. And that seems to be mostly what the
DrawingContext does - it keeps track of (private)
cairo_t *_ct;
I would have thought that passing dc by reference should have made the
position of the problem line before the call, or just within the called
function, a moot point, but apparently not. This is so even though when
the address of _ct was checked with dc.raw(), before and after the
problem line, it didn't change. Whether or not the problem line was
before or inside decorateItem().
Can somebody please explain what is happening here?
Thanks,
David Mathog
mathog@...1176...
Manager, Sequence Analysis Facility, Biology Division, Caltech