On Mon, 1 Feb 2010, "Robert A. T. Káldy" wrote:
> I can't figure out, how DrawScale and DrawTranslate really work. The
> official documentation is brief, but I would assume, that these
> transformation will affect either all objects before the function (like
> in PostScript) or all objects after the function (like in OpenGL). But
> consider this code:
>
> DrawContext dr = DrawAllocateContext(NULL, img);
> (...draw first set of objects...)
> DrawTranslate(dr, 50, 0)
> (...draw second set of objects...)
> DrawRender(dr);
>
> Then the translation is applied to first set (all objects shifted 50px
> rightwards) and to second set _twice_ (all objects shifted 100px
> rightwards!). With DrawScale it's similar - the first set would be
> enlarged twice and the second set four times.
DrawScale and DrawTranslate work on the current coordinate system as
opposed to the drawn object. For example, DrawTranslate() moves the
"0,0" coordinate position to a different place in the underlying
image.
It is important to understand that DrawPushGraphicContext()
"http://www.graphicsmagick.org/api/draw.html#drawpushgraphiccontext"
and DrawPopGraphicContext()
"http://www.graphicsmagick.org/api/draw.html#drawpopgraphiccontext"
implement a sort of stack. Any settings such as scaling, translation,
fill-color, etc., only apply to that level of the stack or deeper.
The settings are inherited and cumulative. So you can create a new
level using DrawPushGraphicContext(), apply some settings, do some
drawing, and then use DrawPopGraphicContext() to restore all the
previous settings. Or you can push yet another graphic context, add
more settings, and do some more drawing. Think of a scaled drawing
rendered inside another drawing. Just make sure that the pushed
contexts are eventually popped so they are balanced.
If you have WMF coder support in your GraphicsMagick and a Windows WMF
clip-art file, it is an excellent way to obtain a working example:
gm convert file.wmf file.mvg
where MVG is the texual equivalent of the C drawing commands. In
fact, you can use a text editor or a C program to write a text file
containing commands in MVG format and then read it as a file to
accomplish drawing a vector image.
Bob
--
Bob Friesenhahn
bfriesen@..., http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
|