How to display labels on multiple line cells

I’m currently switching from GDI/GDI+ to VTK but a lot of things still confuse me.

I am trying hard to display labels on multiple line cells according to their orientation, as shown in the image below. Since the line direction and orientation determine the placement of each label, is there an easy way to solve this?

I’m asking for help from anyone who can give me a little advice, and if possible, please provide a sample code snippet.
I’m hoping for some code snippet in C++, but any language is welcome.
I would greatly appreciate any advice you can give me.

Thank you very much in advance.