@@ -610,35 +610,37 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
610610 If the text is a math expression it will be rendered using a
611611 MathText parser.
612612 '''
613- if mtext and mtext .get_rotation_mode () == "anchor" :
614- # Get anchor coordinates.
613+ if mtext :
615614 transform = mtext .get_transform ()
616615 ax , ay = transform .transform_point (mtext .get_position ())
617- ay = self .widget .height - ay
618616
619- angle_rad = angle * np .pi / 180.
617+ angle_rad = mtext . get_rotation () * np .pi / 180.
620618 dir_vert = np .array ([np .sin (angle_rad ), np .cos (angle_rad )])
621- v_offset = np .dot (dir_vert , [(x - ax ), (y - ay )])
622- ax = ax + v_offset * dir_vert [0 ]
623- ay = ay + v_offset * dir_vert [1 ]
624- x = ax
625- y = ay
619+
620+ if mtext .get_rotation_mode () == "anchor" :
621+ # if anchor mode, rotation is undone first
622+ v_offset = np .dot (dir_vert , [(x - ax ), (y - ay )])
623+ ax = ax + v_offset * dir_vert [0 ]
624+ ay = ay + v_offset * dir_vert [1 ]
626625
627626 w , h , d = self .get_text_width_height_descent (s , prop , ismath )
628- ha = mtext .get_ha ()
627+ ha , va = mtext .get_ha (), mtext . get_va ()
629628 if ha == "center" :
630- x -= w / 2
629+ ax -= w / 2
631630 elif ha == "right" :
632- x -= w
633- elif ha == "left" :
634- x += w
635- va = mtext .get_va ()
631+ ax -= w
636632 if va == "top" :
637- y -= h
633+ ay -= h
638634 elif va == "center" :
639- y -= h / 2
640- elif va == "bottom" :
641- y += h
635+ ay -= h / 2
636+
637+ if mtext .get_rotation_mode () != "anchor" :
638+ # if not anchor mode, rotation is undone last
639+ v_offset = np .dot (dir_vert , [(x - ax ), (y - ay )])
640+ ax = ax + v_offset * dir_vert [0 ]
641+ ay = ay + v_offset * dir_vert [1 ]
642+
643+ x , y = ax , ay
642644
643645 x += self .widget .x
644646 y += self .widget .y
0 commit comments