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

Commit1670dde

Browse files
committed
Fix glyph positioning.
1 parentc274d14 commit1670dde

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

‎lib/matplotlib/mathtext.py

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -141,64 +141,80 @@ class MathtextBackendAgg(MathtextBackend):
141141
"""
142142
def__init__(self):
143143
MathtextBackend.__init__(self)
144-
self.bbox= [0,0,0,0]
144+
self._xmin=self._ymin=np.inf
145+
self._xmax=self._ymax=-np.inf
145146
self._glyphs= []
146147
self._rects= []
147148

148-
ox=property(cbook.deprecated("3.2")(lambdaself:0))
149-
oy=property(cbook.deprecated("3.2")(lambdaself:0))
150-
image=property(cbook.deprecated("3.2")(lambdaself:None))
151-
mode=property(cbook.deprecated("3.2")(lambdaself:"bbox"))
149+
@cbook.deprecated("3.2")
150+
@property
151+
defox(self):
152+
return0
153+
154+
@cbook.deprecated("3.2")
155+
@property
156+
defoy(self):
157+
return0
158+
159+
@cbook.deprecated("3.2")
160+
@property
161+
defbbox(self):
162+
return [self._xmin,self._ymin,self._xmax,self._ymax]
163+
164+
@cbook.deprecated("3.2")
165+
@property
166+
defmode(self):
167+
return"bbox"
152168

153-
def_update_bbox(self,x1,y1,x2,y2):
154-
self.bbox= [min(self.bbox[0],x1),
155-
min(self.bbox[1],y1),
156-
max(self.bbox[2],x2),
157-
max(self.bbox[3],y2)]
169+
@cbook.deprecated("3.2")
170+
@property
171+
defimage(self):
172+
returnNone
158173

159174
defrender_glyph(self,ox,oy,info):
160175
self._glyphs.append((ox,oy,info))
161-
self._update_bbox(ox+info.metrics.xmin,
162-
oy-info.metrics.ymax,
163-
ox+info.metrics.xmax,
164-
oy-info.metrics.ymin)
176+
metrics=info.metrics
177+
self._xmin=min(self._xmin,ox+metrics.xmin)
178+
self._ymin=min(self._ymin,self.height-oy+metrics.ymin)
179+
self._xmax=max(self._xmax,ox+metrics.xmax)
180+
self._ymax=max(self._ymax,self.height-oy+metrics.ymax)
165181

166182
defrender_rect_filled(self,x1,y1,x2,y2):
167183
self._rects.append((x1,y1,x2,y2))
168-
self._update_bbox(x1,y1,x2,y2)
184+
self._xmin=min(self._xmin,x1)
185+
self._xmax=max(self._xmax,x2)
186+
self._ymin=min(self._ymin,y1)
187+
self._ymax=max(self._ymax,y2)
169188

170189
defget_results(self,box,used_characters):
171190
orig_height=box.height
172-
orig_depth=box.depth
191+
orig_depth=box.depth
173192
ship(0,0,box)
174-
bbox=xmin,ymin,xmax,ymax= [self.bbox[0]-1,self.bbox[1]-1,
175-
self.bbox[2]+1,self.bbox[3]+1]
176-
self.set_canvas_size(
177-
xmax-xmin,
178-
ymax-ymin-orig_depth,
179-
ymax-ymin-orig_height)
180-
image=FT2Image(
181-
np.ceil(self.width),np.ceil(self.height+max(self.depth,0)))
193+
xmin=self._xmin-1
194+
xmax=self._xmax+1
195+
ymin=self._ymin-1
196+
ymax=self._ymax+1
197+
image=FT2Image(np.ceil(xmax-xmin),np.ceil(ymax-ymin))
182198

183199
forox,oy,infoinself._glyphs:
184200
info.font.draw_glyph_to_bitmap(
185-
image,ox-xmin,oy-info.metrics.iceberg-ymin,
201+
image,ox+1,oy-info.metrics.iceberg+1,
186202
info.glyph,antialiased=rcParams['text.antialiased'])
187203
forx1,y1,x2,y2inself._rects:
188-
x1-=xmin
189-
x2-=xmin
190-
y1-=ymin
191-
y2-=ymin
204+
x1+=1
205+
x2+=1
206+
y1+=1
207+
y2+=1
192208
height=max(int(y2-y1)-1,0)
193209
ifheight==0:
194-
center= (y2+y1)/2.0
195-
y=int(center- (height+1)/2.0)
210+
center= (y2+y1)/2
211+
y=int(center- (height+1)/2)
196212
else:
197213
y=int(y1)
198214
image.draw_rect_filled(int(x1),y,np.ceil(x2),y+height)
199215

200216
return (0,0,
201-
self.width,self.height+self.depth,self.depth,
217+
np.ceil(xmax-xmin),np.ceil(ymax-ymin),-ymin,
202218
image,
203219
used_characters)
204220

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp