Gtk overlap labels

I want to avoid overlap with labels when I use cairo to draw circles IDS. Circles are also intersecting, that is ok. But, I don’t want labels (IDs) to sit on the top of each other. I can not write each label with a different displacement when labelling is done dynamically. if one label sits partially o the top of another, i want to removed the intersecting areas in the bottom label.
what is the best way to do that?
intersecting-labels

Thanks

Cairo supports clipping. When you use pango for text rendering, then pango has functions to get the bounding box of the displayed text. You can use that box for cairo clipping. For details you should consult the cairo and pango API docs. Mr Bassi suggested recently to use the cairo mailing list for cairo questions, but that list is not very active any more. Instead of cairo you may also consider using blend2d, which is more active, but has not that much documentation yet and not many bindings to languages other than C and C++.

Maybe one problem for you is, that you would need some form of inverted clipping for cairo. I think I never needed that myself, but Google points you to this message, which explains how you can do it:

https://lists.cairographics.org/archives/cairo/2009-September/018111.html

Follow the whole thread, there is one more message of Mr. Carl Worth:

https://lists.cairographics.org/archives/cairo/2009-September/018118.html

And the simplest solution is obviously to paint the text with a non transparent background color. Not very nice, as the text background would erase a part of your circles. A nicer solution may be to have all the text bounding boxes in a data structure like a RTree that allows fast nearest neighbor search, and then move the text position when nearest neighbor bounding box overlaps.

Thank you very much. I will try all the suggestions and get back.

Thanks,
Lalitha

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.