ThinkGeo.com    |     Documentation    |     Premium Support

DrawingTextAlignment not working correctly

Hi Ben,

I’m trying to mimic AutoCAD’s text alignments in ThinkGeo.
From an AutoCAD drawing, I extract information for each text string, including the font, height, rotation, and text alignment (justification).

This is the source from AutoCAD. The red crosses indicate the insertion points. The justification type is noted next to each text string.

I created a RotatedPointStyle class that inherits from PointStyle .
In this class, I override the DrawCore method to calculate screen coordinates, determine the text height based on the font and height, and use canvas.DrawText to render the text.

    Case "left"
        canvas.DrawText(text, font, New GeoSolidBrush(_Color), New GeoPen(), textPathInScreen, DrawingLevel.LabelLevel, 0, 0, DrawingTextAlignment.Left, 0)
    Case "center"
        canvas.DrawText(text, font, New GeoSolidBrush(_Color), New GeoPen(), textPathInScreen, DrawingLevel.LabelLevel, 0, 0, DrawingTextAlignment.Center, 0)
    Case "right"
        canvas.DrawText(text, font, New GeoSolidBrush(_Color), New GeoPen(), textPathInScreen, DrawingLevel.LabelLevel, 0, 0, DrawingTextAlignment.Right, 0)

However, as shown in the image below, all texts—whether horizontal or rotated—are being drawn as centered.

Any help or suggestions to fix this issue would be greatly appreciated.

Regards,
Guido van den Boom

Hi Guido,

DrawingTextAlignment is for the alignment of multi lines, like following:

DrawingTextAlignment.Center
image
DrawingTextAlignment.Left
image
DrawingTextAlignment.Right
image

For your case though, you can use MeasureText() to get the size of a label, calculate the corresponding OffsetX for different cases, and then pass it into the canvas.DrawText. The OffsetX is 0 by default meaning the point will be at the center of the label.

Just FYI, we do have textStyle.TextPlacement to modify the position for all the labels in the layer.

Thanks,
Ben

Hi Ben,

Is this a change with the introductoin of the multiline texts?
I’m prety sure I could set the alignment for a single text in the past.
But if this is the case I’ll have to try and calculate the conversions from autocad to thinkgeo myself.

Regards,
Guido

Guido,

It’s been like this from the very beginning. You can set the alignment with TextStyle.TextPlacement instead. You can do the conversion yourself or like I said, create a TextStyle for the labels, and use TextStyle.MeasureText() to get the size of a label.

Thanks,
Ben

Ben,

Every label in the autocad drawing can be different with fonts, sizes, alignments and rotations.
So one TextStyle is not going to work. Autocad is also a bit weird, with mixes of horizontal (left, right, center) in combination with vertical (top, bottom center) alignments.

I’m going to give it a try.

Thanks,
Guido

I see. Anyway, just let us know if you need any help!