Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Figure out how to pass Text to Renderer.draw_text always #30282

Open
@QuLogic

Description

@QuLogic

For font features/languages, I ran into an issue in that theText object is only supplied toRenderer.draw_text if the string is not multiline:

mtext=selfiflen(info)==1elseNone

I tried a small change:

diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.pyindex 3b0de58814..b255a93c52 100644--- a/lib/matplotlib/text.py+++ b/lib/matplotlib/text.py@@ -800,9 +800,7 @@ class Text(Artist):              angle = self.get_rotation()              for line, wh, x, y in info:--                mtext = self if len(info) == 1 else None                 x = x + posx                 y = y + posy                 if renderer.flipy():@@ -816,14 +814,19 @@ class Text(Artist):                 else:                     textrenderer = renderer-                if self.get_usetex():-                    textrenderer.draw_tex(gc, x, y, clean_line,-                                          self._fontproperties, angle,-                                          mtext=mtext)-                else:-                    textrenderer.draw_text(gc, x, y, clean_line,-                                           self._fontproperties, angle,-                                           ismath=ismath, mtext=mtext)+                xt, yt = self.get_transform().inverted().transform((x, y))+                with cbook._setattr_cm(self, _x=xt, _y=yt, _text=clean_line,+                                       convert_xunits=lambda x: x,+                                       convert_yunits=lambda y: y,+                                       _horizontalalignment='left', _verticalalignment='bottom'):+                    if self.get_usetex():+                        textrenderer.draw_tex(gc, x, y, clean_line,+                                              self._fontproperties, angle,+                                              mtext=self)+                    else:+                        textrenderer.draw_text(gc, x, y, clean_line,+                                               self._fontproperties, angle,+                                               ismath=ismath, mtext=self)          gc.restore()         renderer.close_group('text')

AFAICT, only the PGF backend usesmtext and under certain conditions will place the text using the original position and alignment instead of thex/y passed todraw_text. Unfortunately, these don't seem to match (I assume the x/y passed in accounts for the descenders and other flourishes), so this breaks the PGF tests. I wonder if there's a better condition to be put in here:

ifmtextand (
(angle==0or
mtext.get_rotation_mode()=="anchor")and
mtext.get_verticalalignment()!="center_baseline"):

Originally posted by@QuLogic in#29695 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Waiting for other PR

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp