[cairo] Help the struggling newby!

Maarten Bosmans mkbosmans at gmail.com
Mon Aug 15 00:30:49 PDT 2011


2011/8/15 Andrew Ellis <andrewjellis at hotmail.com>:
> Hi Maarten
> I'm very tied to VB6.  The application in question is currently around
> 130,000 lines of code.  It's in several layers (client-server) and of
> course, I guess the user interface layer could be migrated to something else
> if I can still access objects in the middleware (which resides on a server
> machine as an out-of-process COM object).  But I'd really rather not have to
> do that.

OK, fair enough, VB6 it is then.

> There are several things I'd like to do with my graphics, and while it would
> be *possible* to do them using VB, it would be rather slow.  I could
> possibly use Windows GDI calls to achieve these objectives, but I don't have
> a lot of experience with that, so the idea of using a DLL built as a wrapper
> for tried-and-tested graphics functionality is attractive.

Yup, Cairo is a nice wrapper around the GDI functionality. Although in
my experience Cairo's image backend (using pixman under the hood) is
substantially faster. Luckily once you have written the cairo code,
the surface type used in not important anymore. This also means that
you application instantly gains high-quality pdf-export capability
when ported to cairo.

> The application has objects with two kinds of image.  The first type is
> calculated from other properties the object may have, and is then drawn
> using VB's line-drawing primitives.  Such an image is stored as two
> collections: (1) all the straight lines (between two cartesian coordinates)
> and (2) all the curved lines (each having a cartesian coordinate for the
> centre of the circle, a radius, and a starting and finishing angle).  These
> are precisely the parameters I have to provide for VB's line-drawing
> methods, so that minimal processing is required when rendering the image.  I

These are precisely the type of curves supported by cairo, so that
should not give much trouble. Cairo also supports bezier curves.

> might need to repeatedly redraw the image while tracking a drag-and-drop
> operation, for example, and so I don't want to perform any more processing
> than necessary.  Imagine the application to be producing a map.  All the
> end-points of the roads can be calculated once, and the connections between
> them stored for future use.  If I need to rotate the map, pan across it, or
> zoom in and out, I simply redraw it but at the same time modifying its
> stored parameters to reflect the new X or Y offset, the viewing angle, and
> the scale factor.  The shape itself doesn't change, but the drawing methods
> are quite slow.  I'm sure that a performance improvement could be gained by
> rendering the image onto something like a Cairo surface, and the surface
> rotated or transformed as required.

This is certainly possible with cairo, although there's always a
performance/quality trade-off.

> The second type of image is more like the drawing of a physical object.  The
> shape is a collection of regions, each with a shape (like the shape used for
> the first image type) and a colour.  Alternatively, it may be a bitmap,
> perhaps because the user has taken a photograph of the object in question.
>  Using the map analogy again, these objects might represent fields or areas
> of water, or aerial photographs.  The bitmap-type image is rather difficult
> to scale or rotate using VB.  BitBlt and StretchBlt can be used from Windows
> GDI to achieve the translation and scaling, but the rotation is still
> difficult.  Once again, there appears to be an advantage in using Cairo,
> since the surface doesn't care what was used to generate the image, and the
> same code may be used for the final rendering of both types of image.
> Andy

There's at least one other member of the cairo community using it for
mapping purposes: Ian Britten. Perhaps he can be of more assistance.

Please ask some concrete questions about how to use cairo, so we can
answer them and remember that probably no one on the list has any VB6
experience.

The api manual http://cairographics.org/manual/ references C function,
but that should give you some hints on how to use cairo with the VB6
bindings.
Also have a look at http://cairographics.org/tutorial/

Maarten

>> Date: Sun, 14 Aug 2011 23:13:19 +0200
>> Subject: Re: [cairo] Help the struggling newby!
>> From: mkbosmans at gmail.com
>> To: andrewjellis at hotmail.com
>> CC: cairo at cairographics.org
>>
>> Hi Andrew,
>>
>> I doubt anyone on this list has any experience with Visual Basic using
>> Cairo.
>>
>> So what exactly are your problems? If you can show us some code and
>> describe what you are trying to achieve, we can probably suggest to
>> you how to use cairo to achieve your goal.
>>
>> That being said, how tied are you to VB6? Python is a really nice
>> language to develop apps quickly in and has good supported cairo
>> bindings. Another suggestion is to develop a .NET app in
>> VisualBasic.NET and use the Mono.Cairo bindings from the Mono project.
>>
>> Maarten
>>
>>
>> 2011/8/14 Andrew Ellis <andrewjellis at hotmail.com>:
>> > Hello all.
>> > I've joined this group in the hope that someone might give me some
>> > pointers
>> > to some documentation.  I'm developing a VB6 application, and need some
>> > better graphics capabilities...
>> > I was persuaded to buy into the idea of using Cairo by someone in one of
>> > the
>> > VB6 groups.  Someone named Olaf Schmidt.  He's produced a Cairo wrapper
>> > (dhcairo.dll) and several VB6 tutorial projects.  I've tried
>> > experimenting
>> > with the tutorials - altering lines of code to see what the new effect
>> > is,
>> > for example - but I don't understand why the thing behaves the way it
>> > does.
>> >  I don't have any fit-for-purpose documentation, specifically to tell me
>> > (1)
>> > what is available for my application to use, (2) in what order they
>> > should
>> > be called, and (3) what the various parameters mean.  His commentary is
>> > not
>> > very helpful - German translated into English, and not very well.  I
>> > can't
>> > make head or tail of it!
>> > I haven't been able to get a lot of support from Olaf, and this problem
>> > has
>> > been waiting for a solution for over a year.  I'm not vastly experienced
>> > in
>> > graphics work, as I said, I just need something better than the standard
>> > graphics calls in VB6.
>> > If you've used dhCairo, perhaps you know of some docs I can look at?
>> > Andy
>> > --
>> > cairo mailing list
>> > cairo at cairographics.org
>> > http://lists.cairographics.org/mailman/listinfo/cairo
>> >
>
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>


More information about the cairo mailing list