Published by breki on 19 Mar 2009 at 09:08 am
Welcome To Cairo!

photo credit: The Library of Congress
No, I’m not going to Egypt. Cairo I’m referring to is an open source 2D graphics library, used by GTK+, Mono, Mozilla Firefox and many others.
As part of my source code spring cleaning effort I started modeling Kosmos mapping library from scratch. The idea is to separate pure map-rendering stuff from the Kosmos application and infrastructure logic. Then this map rendering code could be reused in other applications.
The effort already bore some fruit: the new model has a much cleaner separation of the drawing engine from the rest of the code:
{
void BeginPainting ();
void Clear ();
void DrawLines (int[] coords);
void DrawPoint (int x, int y);
void EndPainting ();
void PaintCurve (PaintOperation operation, int[] coords);
void PaintPolygon (PaintOperation operation, int[] coords);
void PaintRectangle (PaintOperation operation, int x, int y, int width, int height);
void SetHighQualityLevel (bool highQuality);
void SetStyle (PaintingStyle style);
}
This is all there is to the drawing (well maybe a few methods like drawing text are missing, but you get the idea). So there are no GDI+ primitives (like Points, Colors, Pens etc) in the interface. Which means I can start playing with other drawing libraries, like Cairo:
The two images represent a collection of GPS traces: the left one was drawing using GDI+ implementation of the IPainter interface, the right one using Cairo. Alpha-transparency is used to get the effect of area most covered by traces (the dark color) against those only visited once (the lightest color). As you can see, there are some differences in the coloring between GDI+ and Cairo’s renderings – these are probably because of the quality settings I specified for GDI+, which could not be replicated in Cairo. Also, Cairo is on average twice as slow in rendering compared to GDI+. I’m not sure why, but I’ll try to improve this.
All in all, I’m very pleased with the result, especially considering that I only started this redesign few days ago. And the main point why I’m playing with Cairo is the fact that you can produce SVG output using the same code. This means that Kosmos will be able to produce vector maps in the future, which can then be manually post-processed to fix any rendering problems (like label-placing).
The main issue I always have in my mind is to keep the performance of map rendering the same with this new design. This was a big concern for me before starting, but now I think the new design is so much better that it will actually be a performance improvement, at least memory-wise, if not speed-wise.




Alex on 03 Apr 2009 at 23:54 #
Excellent, I would really love to get SVG output from Kosmos. Can I be cheeky and make a feature request? I’d love to be able to use a CSS-like text-tranform rule in Kosmos stylesheets, to be able to have text in uppercase.
Keep up the good work!
breki on 05 Apr 2009 at 16:37 #
@Alex,
Yes, that will be one of the features I intend to add to Kosmos, once I finish the new rendering engine.
Alex on 05 Apr 2009 at 23:31 #
That’s fantastic. Do you accept donations towards Kosmos development?
Alex on 05 Apr 2009 at 23:32 #
Sorry for double post, I just found your donations form. That’ll teach me to look before asking silly questions!
breki on 06 Apr 2009 at 5:10 #
Alex, thanks
Alex on 09 Apr 2009 at 23:10 #
You’re welcome.
Wish I could have given more. Bloody useful software.
igorbrejc.net » Kosmos v2.5 And GroundTruth And Some Developer’s Musings on 05 Jul 2009 at 19:41 #
[...] the more reason for me to continue on my effort of rewriting the critical parts from scratch. But that’s a story for some other blog [...]