Scrolling within a Cairo Context

Hello there,

I'm experimenting with python-poppler bindings[1], which allows me to
draw a PDF file to a Cairo backend. Some time ago, I combined wx-Cairo
and python-poppler, and did a little Proof of Concept with it [2], and
it works fine. The problem is when I want to add scrollbars and zoom
in/out to it.

I started drawing in a wxPanel inside a wxScrolledWindow, and it
scrolled ok, but the problem came with the zoom in/out: I couldn't get
to scale the scrollbars when zooming. After that, I read that for
"dynamic" scrollbars, I should inherit from wxScrolledWindow and
manage the events manually (don't know how to do this...) :-/ (here is
that example [3]).

After that, I read an answer from Andrea about scrolling an image [4],
and I got this far: it initially shows ok [5], but here's the behavior
when scrolling [6]. I know I should handle the scrolling and redraw,
but I don' t know how to do this with Cairo... :-/

Here is the code, inheriting from wxScrolledWindow [7].

Any hints? I'd like to make a *very simple* PDF Viewer using python-poppler...

Thanks

PS: The python-poppler bindings are available in Linux and OSX by now
(in Ubuntu is available with the "python-poppler" package name).

[1] https://launchpad.net/poppler-python
[2] http://pastebin.com/fe17a865
[3] http://pastebin.com/4q0ixks5
[4] http://groups.google.com/group/wxpython-users/browse_thread/thread/d9ed6e48662a5076/6433cc8f7f9886d4
[5] http://img696.imageshack.us/img696/3913/pantallazowxpdfviewer.png
[6] http://img684.imageshack.us/img684/5325/pantallazowxpdfviewer1.png
[7] http://pastebin.com/E7WNfRwg

···

--
Marcelo F. Fernández
Buenos Aires, Argentina
Licenciado en Sistemas - CCNA

E-Mail: marcelo.fidel.fernandez@gmail.com
Blog: http://blog.marcelofernandez.info
Twitter: http://twitter.com/fidelfernandez

When a scrolled window is scrolled the following two things happen:

* The pixels on screen are shifted appropriately
* An EVT_PAINT event will be sent with the newly exposed area of the
window set in the update region.

The actual window coordinates on screen are still based on (0,0) being
in the upper left corner (device coordinates,) so for normal DC
drawing wx.ScrolledWindow lets you compensate for that by shifting the
origin using self.PrepareDC, (logical coordinates.)

You'll need to do something similar with cairo, basically offsetting
the drawing such that the fraction of the whole page that gets
rendered to the window corresponds to the scroll offsets.

···

On Apr 12, 10:32 am, Marcelo Fernandez <marcelo.fidel.fernan...@gmail.com> wrote:

After that, I read an answer from Andrea about scrolling an image [4],
and I got this far: it initially shows ok [5], but here's the behavior
when scrolling [6]. I know I should handle the scrolling and redraw,
but I don' t know how to do this with Cairo... :-/