GraphicsContext Bugs ???

Hello,

I'm using wx.lib.graphics.GraphicsContext whith cairo surfaces for a new project and found some issues:

1. DrawBitpap not use the correct x,y position:

DrawBitmap() scale the context to adjust the image to the width and height received, but set the x,y position after scale, then the x,y coords are also modified in the context.

Graphics.py:

def DrawBitmap(self, bmp, x, y, w=-1, h=-1):
     ...
     self._context.scale(scaleX, scaleY)
     self._context.translate(x, y)
     ...

The problem is solved putting translate before rescale:

     ...
     # Set position before scale
     self._context.translate(x, y)
     self._context.scale(scaleX, scaleY)
     ...

2. PushState & PopState don't save/restore Pen, Brush and Font.

If you PushState(), set a Font/Brush/Pen, draw anything and then PopState(), those objects are not restored.

GraphicsContext do not apply them when you do SetPen/SetBrush/SetFont. GraphicsContext save it on internal vars and apply them when execute a draw operation.

if you:
  SetFont(...."Arial")

  PushState()
  SetFont(...."Times New Roman")
  DrawText("Text with Times new Roman")
  PopState()

and then
  DrawText("Text")

PopState must restore the Font previous at PushState, but do not it. The las text is printed with Times New Roman because DrawText() instead use the current surface font, apply the last font used and saved in a GraphicsContext var.

In this case the solution is more complex because affects to all Draw... functions.

wx version: '2.8.12.1 (msw-unicode)'

Sorry for my bad english.

Should I open bugs?

···

--
Oswaldo

Hello,

I'm using wx.lib.graphics.GraphicsContext whith cairo surfaces for a new
project and found some issues:

1. DrawBitpap not use the correct x,y position:

DrawBitmap() scale the context to adjust the image to the width and
height received, but set the x,y position after scale, then the x,y
coords are also modified in the context.

Graphics.py:

def DrawBitmap(self, bmp, x, y, w=-1, h=-1):
...
self._context.scale(scaleX, scaleY)
self._context.translate(x, y)
...

The problem is solved putting translate before rescale:

...
# Set position before scale
self._context.translate(x, y)
self._context.scale(scaleX, scaleY)
...

This has already been changed in the 2.9 version of the code.

2. PushState & PopState don't save/restore Pen, Brush and Font.

If you PushState(), set a Font/Brush/Pen, draw anything and then
PopState(), those objects are not restored.

I think we're just going to have to live with this one. I'd like to maintain as much compatibility with the C++ wxGraphicsContext as possible and it appears that it is only saving/restoring the transformation matrix there. It shouldn't be too hard to wrap your own Push/Pop around it that also saves/restores the pen, brush and font if you need that.

···

On 1/9/12 11:29 AM, Oswaldo wrote:

--
Robin Dunn
Software Craftsman

El 13/01/2012 6:47, Robin Dunn escribi�:

···

On 1/9/12 11:29 AM, Oswaldo wrote:

Hello,

I'm using wx.lib.graphics.GraphicsContext whith cairo surfaces for a new
project and found some issues:

1. DrawBitpap not use the correct x,y position:

DrawBitmap() scale the context to adjust the image to the width and
height received, but set the x,y position after scale, then the x,y
coords are also modified in the context.

Graphics.py:

def DrawBitmap(self, bmp, x, y, w=-1, h=-1):
...
self._context.scale(scaleX, scaleY)
self._context.translate(x, y)
...

The problem is solved putting translate before rescale:

...
# Set position before scale
self._context.translate(x, y)
self._context.scale(scaleX, scaleY)
...

This has already been changed in the 2.9 version of the code.

2. PushState & PopState don't save/restore Pen, Brush and Font.

If you PushState(), set a Font/Brush/Pen, draw anything and then
PopState(), those objects are not restored.

I think we're just going to have to live with this one. I'd like to
maintain as much compatibility with the C++ wxGraphicsContext as
possible and it appears that it is only saving/restoring the
transformation matrix there. It shouldn't be too hard to wrap your own
Push/Pop around it that also saves/restores the pen, brush and font if
you need that.

Ok, I've created my own stack for pens, brushes and fonts.

Thanks.

--
Oswaldo