Permalink
Browse files

Fix #1810: Fix vertical text alignment in the Cairo and OS-X backends.

The renderer backends' draw_text method is now passed the location of
the text baseline, not the bottom of the text bounding box.
  • Loading branch information...
1 parent 1ccf29d commit 4aed809d4926051218bd9f118d022b3a09ea4102 @mdboom mdboom committed Apr 15, 2013
Showing with 2,821 additions and 2,046 deletions.
  1. +11 −0 doc/users/whats_new.rst
  2. +2 −2 lib/matplotlib/backend_bases.py
  3. +9 −3 lib/matplotlib/backends/backend_agg.py
  4. +7 −11 lib/matplotlib/backends/backend_pdf.py
  5. +1 −1 lib/matplotlib/backends/backend_pgf.py
  6. +1 −1 lib/matplotlib/backends/backend_ps.py
  7. +2 −7 lib/matplotlib/backends/backend_svg.py
  8. +5 −5 lib/matplotlib/mathtext.py
  9. BIN lib/matplotlib/tests/baseline_images/test_axes/axhspan_epoch.png
  10. BIN lib/matplotlib/tests/baseline_images/test_axes/const_xy.pdf
  11. BIN lib/matplotlib/tests/baseline_images/test_axes/const_xy.png
  12. +48 −48 lib/matplotlib/tests/baseline_images/test_axes/const_xy.svg
  13. BIN lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.pdf
  14. +167 −167 lib/matplotlib/tests/baseline_images/test_axes/contour_colorbar.svg
  15. BIN lib/matplotlib/tests/baseline_images/test_axes/errorbar_basic.pdf
  16. BIN lib/matplotlib/tests/baseline_images/test_axes/errorbar_basic.png
  17. BIN lib/matplotlib/tests/baseline_images/test_axes/errorbar_mixed.pdf
  18. BIN lib/matplotlib/tests/baseline_images/test_axes/errorbar_mixed.png
  19. +78 −78 lib/matplotlib/tests/baseline_images/test_axes/errorbar_mixed.svg
  20. BIN lib/matplotlib/tests/baseline_images/test_axes/fill_units.pdf
  21. BIN lib/matplotlib/tests/baseline_images/test_axes/fill_units.png
  22. +72 −72 lib/matplotlib/tests/baseline_images/test_axes/fill_units.svg
  23. BIN lib/matplotlib/tests/baseline_images/test_axes/formatter_large_small.pdf
  24. BIN lib/matplotlib/tests/baseline_images/test_axes/formatter_ticker_001.pdf
  25. BIN lib/matplotlib/tests/baseline_images/test_axes/formatter_ticker_002.pdf
  26. +21 −21 lib/matplotlib/tests/baseline_images/test_axes/formatter_ticker_002.svg
  27. BIN lib/matplotlib/tests/baseline_images/test_axes/formatter_ticker_003.pdf
  28. +21 −21 lib/matplotlib/tests/baseline_images/test_axes/formatter_ticker_003.svg
  29. BIN lib/matplotlib/tests/baseline_images/test_axes/formatter_ticker_004.pdf
  30. BIN lib/matplotlib/tests/baseline_images/test_axes/formatter_ticker_004.png
  31. +18 −18 lib/matplotlib/tests/baseline_images/test_axes/formatter_ticker_004.svg
  32. BIN lib/matplotlib/tests/baseline_images/test_axes/formatter_ticker_005.pdf
  33. BIN lib/matplotlib/tests/baseline_images/test_axes/formatter_ticker_005.png
  34. +18 −18 lib/matplotlib/tests/baseline_images/test_axes/formatter_ticker_005.svg
  35. BIN lib/matplotlib/tests/baseline_images/test_axes/hist_stacked_bar.pdf
  36. BIN lib/matplotlib/tests/baseline_images/test_axes/hist_stacked_bar.png
  37. +24 −24 lib/matplotlib/tests/baseline_images/test_axes/hist_stacked_bar.svg
  38. BIN lib/matplotlib/tests/baseline_images/test_axes/log_scales.pdf
  39. BIN lib/matplotlib/tests/baseline_images/test_axes/markevery.pdf
  40. BIN lib/matplotlib/tests/baseline_images/test_axes/markevery.png
  41. +15 −15 lib/matplotlib/tests/baseline_images/test_axes/markevery.svg
  42. BIN lib/matplotlib/tests/baseline_images/test_axes/markevery_line.pdf
  43. BIN lib/matplotlib/tests/baseline_images/test_axes/markevery_line.png
  44. +23 −23 lib/matplotlib/tests/baseline_images/test_axes/markevery_line.svg
  45. BIN lib/matplotlib/tests/baseline_images/test_axes/polar_axes.pdf
  46. +30 −30 lib/matplotlib/tests/baseline_images/test_axes/polar_axes.svg
  47. BIN lib/matplotlib/tests/baseline_images/test_axes/polar_rmin.pdf
  48. BIN lib/matplotlib/tests/baseline_images/test_axes/polar_rmin.png
  49. +34 −34 lib/matplotlib/tests/baseline_images/test_axes/polar_rmin.svg
  50. BIN lib/matplotlib/tests/baseline_images/test_axes/polar_theta_position.pdf
  51. +30 −30 lib/matplotlib/tests/baseline_images/test_axes/polar_theta_position.svg
  52. BIN lib/matplotlib/tests/baseline_images/test_axes/polar_units.pdf
  53. BIN lib/matplotlib/tests/baseline_images/test_axes/polar_units.png
  54. +35 −35 lib/matplotlib/tests/baseline_images/test_axes/polar_units.svg
  55. BIN lib/matplotlib/tests/baseline_images/test_axes/polar_units_2.pdf
  56. BIN lib/matplotlib/tests/baseline_images/test_axes/polar_units_2.png
  57. +36 −36 lib/matplotlib/tests/baseline_images/test_axes/polar_units_2.svg
  58. BIN lib/matplotlib/tests/baseline_images/test_axes/polar_wrap_180.pdf
  59. BIN lib/matplotlib/tests/baseline_images/test_axes/polar_wrap_180.png
  60. +33 −33 lib/matplotlib/tests/baseline_images/test_axes/polar_wrap_180.svg
  61. BIN lib/matplotlib/tests/baseline_images/test_axes/polar_wrap_360.pdf
  62. BIN lib/matplotlib/tests/baseline_images/test_axes/polar_wrap_360.png
  63. +35 −35 lib/matplotlib/tests/baseline_images/test_axes/polar_wrap_360.svg
  64. BIN lib/matplotlib/tests/baseline_images/test_axes/scatter.pdf
  65. BIN lib/matplotlib/tests/baseline_images/test_axes/shaped_data.pdf
  66. BIN lib/matplotlib/tests/baseline_images/test_axes/shaped_data.png
  67. +61 −61 lib/matplotlib/tests/baseline_images/test_axes/shaped_data.svg
  68. BIN lib/matplotlib/tests/baseline_images/test_axes/single_date.pdf
  69. BIN lib/matplotlib/tests/baseline_images/test_axes/single_date.png
  70. +33 −33 lib/matplotlib/tests/baseline_images/test_axes/single_date.svg
  71. BIN lib/matplotlib/tests/baseline_images/test_axes/single_point.pdf
  72. BIN lib/matplotlib/tests/baseline_images/test_axes/single_point.png
  73. +28 −28 lib/matplotlib/tests/baseline_images/test_axes/single_point.svg
  74. BIN lib/matplotlib/tests/baseline_images/test_axes/symlog.pdf
  75. BIN lib/matplotlib/tests/baseline_images/test_axes/symlog.png
  76. +15 −15 lib/matplotlib/tests/baseline_images/test_axes/symlog.svg
  77. BIN lib/matplotlib/tests/baseline_images/test_axes/twin_axis_locaters_formatters.pdf
  78. BIN lib/matplotlib/tests/baseline_images/test_axes/twin_axis_locaters_formatters.png
  79. +34 −34 lib/matplotlib/tests/baseline_images/test_axes/twin_axis_locaters_formatters.svg
  80. BIN lib/matplotlib/tests/baseline_images/test_bbox_tight/bbox_inches_tight.pdf
  81. BIN lib/matplotlib/tests/baseline_images/test_bbox_tight/bbox_inches_tight.png
  82. +18 −18 lib/matplotlib/tests/baseline_images/test_bbox_tight/bbox_inches_tight.svg
  83. BIN lib/matplotlib/tests/baseline_images/test_bbox_tight/bbox_inches_tight_suptile_legend.pdf
  84. BIN lib/matplotlib/tests/baseline_images/test_bbox_tight/bbox_inches_tight_suptile_legend.png
  85. +26 −26 lib/matplotlib/tests/baseline_images/test_bbox_tight/bbox_inches_tight_suptile_legend.svg
  86. BIN lib/matplotlib/tests/baseline_images/test_contour/contour_manual_labels.pdf
  87. BIN lib/matplotlib/tests/baseline_images/test_contour/contour_manual_labels.png
  88. +23 −23 lib/matplotlib/tests/baseline_images/test_contour/contour_manual_labels.svg
  89. BIN lib/matplotlib/tests/baseline_images/test_dates/DateFormatter_fractionalSeconds.pdf
  90. BIN lib/matplotlib/tests/baseline_images/test_dates/RRuleLocator_bounds.pdf
  91. BIN lib/matplotlib/tests/baseline_images/test_dates/RRuleLocator_bounds.png
  92. +16 −16 lib/matplotlib/tests/baseline_images/test_dates/RRuleLocator_bounds.svg
  93. BIN lib/matplotlib/tests/baseline_images/test_dates/date_axhline.pdf
  94. BIN lib/matplotlib/tests/baseline_images/test_dates/date_axhline.png
  95. BIN lib/matplotlib/tests/baseline_images/test_dates/date_axhspan.png
  96. BIN lib/matplotlib/tests/baseline_images/test_dates/date_axvline.pdf
  97. BIN lib/matplotlib/tests/baseline_images/test_dates/date_axvline.png
  98. +12 −12 lib/matplotlib/tests/baseline_images/test_dates/date_axvline.svg
  99. BIN lib/matplotlib/tests/baseline_images/test_dates/date_axvspan.pdf
  100. BIN lib/matplotlib/tests/baseline_images/test_dates/date_axvspan.png
  101. +20 −20 lib/matplotlib/tests/baseline_images/test_dates/date_axvspan.svg
  102. BIN lib/matplotlib/tests/baseline_images/test_dates/date_empty.png
  103. BIN lib/matplotlib/tests/baseline_images/test_figure/figure_today.pdf
  104. BIN lib/matplotlib/tests/baseline_images/test_image/image_clip.pdf
  105. +25 −25 lib/matplotlib/tests/baseline_images/test_image/image_clip.svg
  106. BIN lib/matplotlib/tests/baseline_images/test_image/image_interps.pdf
  107. BIN lib/matplotlib/tests/baseline_images/test_image/image_interps.png
  108. +33 −33 lib/matplotlib/tests/baseline_images/test_image/image_interps.svg
  109. BIN lib/matplotlib/tests/baseline_images/test_legend/fancy.pdf
  110. BIN lib/matplotlib/tests/baseline_images/test_legend/fancy.png
  111. +53 −53 lib/matplotlib/tests/baseline_images/test_legend/fancy.svg
  112. BIN lib/matplotlib/tests/baseline_images/test_legend/legend_auto2.pdf
  113. BIN lib/matplotlib/tests/baseline_images/test_legend/legend_auto3.pdf
  114. BIN lib/matplotlib/tests/baseline_images/test_legend/legend_auto3.png
  115. +22 −22 lib/matplotlib/tests/baseline_images/test_legend/legend_auto3.svg
  116. BIN lib/matplotlib/tests/baseline_images/test_legend/legend_expand.png
  117. BIN lib/matplotlib/tests/baseline_images/test_legend/scatter_rc1.pdf
  118. BIN lib/matplotlib/tests/baseline_images/test_legend/scatter_rc3.pdf
  119. BIN lib/matplotlib/tests/baseline_images/test_legend/scatter_rc3.png
  120. +10 −10 lib/matplotlib/tests/baseline_images/test_legend/scatter_rc3.svg
  121. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_cm_24.png
  122. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_cm_25.png
  123. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_cm_26.png
  124. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_cm_27.png
  125. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_cm_28.png
  126. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_cm_30.png
  127. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_cm_31.png
  128. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_cm_37.png
  129. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_cm_41.png
  130. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stix_24.png
  131. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stix_25.png
  132. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stix_26.png
  133. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stix_27.png
  134. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stix_28.png
  135. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stix_30.png
  136. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stix_31.png
  137. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stix_37.png
  138. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stix_41.png
  139. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stixsans_24.png
  140. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stixsans_25.png
  141. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stixsans_26.png
  142. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stixsans_27.png
  143. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stixsans_28.png
  144. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stixsans_30.png
  145. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stixsans_31.png
  146. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stixsans_37.png
  147. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathfont_stixsans_41.png
  148. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_05.pdf
  149. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_06.pdf
  150. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_20.pdf
  151. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_21.pdf
  152. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_22.pdf
  153. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_23.pdf
  154. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_27.pdf
  155. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_33.pdf
  156. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_34.pdf
  157. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_37.pdf
  158. +69 −69 lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_37.svg
  159. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_38.pdf
  160. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_40.png
  161. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_41.pdf
  162. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_47.pdf
  163. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_48.pdf
  164. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_50.pdf
  165. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_52.pdf
  166. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_53.pdf
  167. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_53.png
  168. +58 −58 lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_53.svg
  169. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_54.pdf
  170. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_cm_67.pdf
  171. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stix_34.pdf
  172. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stix_37.pdf
  173. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stix_47.pdf
  174. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stix_48.pdf
  175. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stix_52.pdf
  176. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stix_53.pdf
  177. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stix_53.png
  178. +58 −58 lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stix_53.svg
  179. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stix_67.pdf
  180. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stixsans_34.pdf
  181. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stixsans_47.pdf
  182. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stixsans_48.pdf
  183. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stixsans_52.pdf
  184. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stixsans_53.pdf
  185. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stixsans_53.png
  186. +58 −58 lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stixsans_53.svg
  187. BIN lib/matplotlib/tests/baseline_images/test_mathtext/mathtext_stixsans_67.pdf
  188. BIN lib/matplotlib/tests/baseline_images/test_spines/spines_axes_positions.pdf
  189. +17 −17 lib/matplotlib/tests/baseline_images/test_spines/spines_axes_positions.svg
  190. BIN lib/matplotlib/tests/baseline_images/test_streamplot/streamplot_colormap_test_image.pdf
  191. BIN lib/matplotlib/tests/baseline_images/test_subplots/subplots_offset_text.pdf
  192. BIN lib/matplotlib/tests/baseline_images/test_subplots/subplots_offset_text.png
  193. +42 −42 lib/matplotlib/tests/baseline_images/test_subplots/subplots_offset_text.svg
  194. BIN lib/matplotlib/tests/baseline_images/test_text/antialiased.png
  195. BIN lib/matplotlib/tests/baseline_images/test_text/text_alignment.pdf
  196. BIN lib/matplotlib/tests/baseline_images/test_text/text_alignment.png
  197. +742 −0 lib/matplotlib/tests/baseline_images/test_text/text_alignment.svg
  198. BIN lib/matplotlib/tests/baseline_images/test_text/text_contains.png
  199. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout1.pdf
  200. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout1.png
  201. +25 −25 lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout1.svg
  202. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout2.pdf
  203. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout2.png
  204. +106 −106 lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout2.svg
  205. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout3.pdf
  206. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout3.png
  207. +78 −78 lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout3.svg
  208. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout4.pdf
  209. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout4.png
  210. +100 −100 lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout4.svg
  211. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout5.pdf
  212. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout5.png
  213. +46 −46 lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout5.svg
  214. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout6.pdf
  215. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout6.png
  216. +147 −147 lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout6.svg
  217. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout7.pdf
  218. BIN lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout7.png
  219. +25 −25 lib/matplotlib/tests/baseline_images/test_tightlayout/tight_layout7.svg
  220. BIN lib/matplotlib/tests/baseline_images/test_triangulation/tripcolor1.pdf
  221. +1 −2 lib/matplotlib/tests/test_axes.py
  222. +1 −1 lib/matplotlib/tests/test_mathtext.py
  223. +36 −16 lib/matplotlib/tests/test_text.py
  224. +7 −1 lib/matplotlib/text.py
View
@@ -110,6 +110,17 @@ used, which, in the case of straight contours was sometimes quite distant
from the requested location. Much more precise label positioning is now
possible.
+Better vertical text alignment
+------------------------------
+
+The vertical alignment of text is now consistent across backends. You
+may see small differences in text placement, particularly with rotated
+text.
+
+If you are using a custom backend, note that the `draw_text` renderer
+method is now passed the location of the baseline, not the location of
+the bottom of the text bounding box.
+
.. _whats-new-1-2-2:
new in matplotlib 1.2.2
@@ -475,7 +475,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
the x location of the text in display coords
*y*
- the y location of the text in display coords
+ the y location of the text baseline in display coords
*s*
the text string
@@ -497,7 +497,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
if 0: bbox_artist(self, renderer)
- to if 1, and then the actual bounding box will be blotted along with
+ to if 1, and then the actual bounding box will be plotted along with
your text.
"""
@@ -154,8 +154,10 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
ox, oy, width, height, descent, font_image, used_characters = \
self.mathtext_parser.parse(s, self.dpi, prop)
- x = np.round(x + ox)
- y = np.round(y - oy)
+ xd = descent * np.sin(angle / (180.0 * np.pi))
+ yd = descent * np.cos(angle / (180.0 * np.pi))
+ x = np.round(x + ox - xd)
+ y = np.round(y - oy + yd)
self._renderer.draw_text_image(font_image, x, y + 1, angle, gc)
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
@@ -177,10 +179,14 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
# space) in the following call to draw_text_image).
font.set_text(s, 0, flags=flags)
font.draw_glyphs_to_bitmap(antialiased=rcParams['text.antialiased'])
+ d = font.get_descent() / 64.0
+ # The descent needs to be adjusted for the angle
+ xd = d * np.sin(angle / (180.0 * np.pi))
+ yd = d * np.cos(angle / (180.0 * np.pi))
#print x, y, int(x), int(y), s
self._renderer.draw_text_image(
- font.get_image(), np.round(x), np.round(y) + 1, angle, gc)
+ font.get_image(), np.round(x - xd), np.round(y + yd) + 1, angle, gc)
def get_text_width_height_descent(self, s, prop, ismath):
"""
@@ -1622,15 +1622,15 @@ def draw_gouraud_triangles(self, gc, points, colors, trans):
self.check_gc(gc)
self.file.output(name, Op.shading)
- def _setup_textpos(self, x, y, descent, angle, oldx=0, oldy=0, olddescent=0, oldangle=0):
+ def _setup_textpos(self, x, y, angle, oldx=0, oldy=0, oldangle=0):
if angle == oldangle == 0:
- self.file.output(x - oldx, (y + descent) - (oldy + olddescent), Op.textpos)
+ self.file.output(x - oldx, y - oldy, Op.textpos)
else:
angle = angle / 180.0 * pi
self.file.output( cos(angle), sin(angle),
-sin(angle), cos(angle),
x, y, Op.textmatrix)
- self.file.output(0, descent, Op.textpos)
+ self.file.output(0, 0, Op.textpos)
def draw_mathtext(self, gc, x, y, s, prop, angle):
# TODO: fix positioning and encoding
@@ -1660,7 +1660,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
fonttype = global_fonttype
if fonttype == 42 or num <= 255:
- self._setup_textpos(ox, oy, 0, 0, oldx, oldy)
+ self._setup_textpos(ox, oy, 0, oldx, oldy)
oldx, oldy = ox, oy
if (fontname, fontsize) != prev_font:
self.file.output(self.file.fontName(fontname), fontsize,
@@ -1762,7 +1762,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
self.file.output(elt[1], elt[2], Op.selectfont)
elif elt[0] == 'text':
curx, cury = mytrans.transform((elt[1], elt[2]))
- self._setup_textpos(curx, cury, 0, angle, oldx, oldy)
+ self._setup_textpos(curx, cury, angle, oldx, oldy)
oldx, oldy = curx, cury
if len(elt[3]) == 1:
self.file.output(elt[3][0], Op.show)
@@ -1811,13 +1811,11 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
if rcParams['pdf.use14corefonts']:
font = self._get_font_afm(prop)
l, b, w, h = font.get_str_bbox(s)
- descent = -b * fontsize / 1000
fonttype = 1
else:
font = self._get_font_ttf(prop)
self.track_characters(font, s)
font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
- descent = font.get_descent() / 64.0
fonttype = rcParams['pdf.fonttype']
@@ -1857,7 +1855,7 @@ def draw_text_simple():
self.file.fontName(prop),
fontsize,
Op.selectfont)
- self._setup_textpos(x, y, descent, angle)
+ self._setup_textpos(x, y, angle)
self.file.output(self.encode_string(s, fonttype), Op.show, Op.end_text)
def draw_text_woven(chunks):
@@ -1878,7 +1876,6 @@ def draw_text_woven(chunks):
# output all the 2-byte characters.
for mode in (1, 2):
newx = oldx = 0
- olddescent = 0
# Output a 1-byte character chunk
if mode == 1:
self.file.output(Op.begin_text,
@@ -1888,10 +1885,9 @@ def draw_text_woven(chunks):
for chunk_type, chunk in chunks:
if mode == 1 and chunk_type == 1:
- self._setup_textpos(newx, 0, descent, 0, oldx, 0, olddescent, 0)
+ self._setup_textpos(newx, 0, 0, oldx, 0, 0)
self.file.output(self.encode_string(chunk, fonttype), Op.show)
oldx = newx
- olddescent = descent
lastgind = None
for c in chunk:
@@ -636,7 +636,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
text_args.append("x=%fin" % (x * f))
text_args.append("y=%fin" % (y * f))
text_args.append("left")
- text_args.append("bottom")
+ text_args.append("base")
if angle != 0:
text_args.append("rotate=%f" % angle)
@@ -755,7 +755,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
#print 'text', s
lines = []
thisx = 0
- thisy = font.get_descent() / 64.0
+ thisy = 0
for c in s:
ccode = ord(c)
gind = cmap.get(ccode)
@@ -852,8 +852,6 @@ def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath, mtext=None):
_glyphs = text2path.get_glyphs_with_font(
font, s, glyph_map=glyph_map, return_new_glyphs_only=True)
glyph_info, glyph_map_new, rects = _glyphs
- y -= ((font.get_descent() / 64.0) *
- (prop.get_size_in_points() / text2path.FONT_SCALE))
if glyph_map_new:
writer.start(u'defs')
@@ -953,8 +951,6 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
if not ismath:
font = self._get_font(prop)
font.set_text(s, 0.0, flags=LOAD_NO_HINTING)
- descent = font.get_descent() / 64.0
- y -= descent
fontsize = prop.get_size_in_points()
@@ -982,10 +978,9 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
# to the anchor point manually for now.
angle_rad = angle * np.pi / 180.
dir_vert = np.array([np.sin(angle_rad), np.cos(angle_rad)])
- y += descent # Undo inappropriate text descent handling
v_offset = np.dot(dir_vert, [(x - ax), (y - ay)])
- ax = ax + (v_offset - descent) * dir_vert[0]
- ay = ay + (v_offset - descent) * dir_vert[1]
+ ax = ax + v_offset * dir_vert[0]
+ ay = ay + v_offset * dir_vert[1]
ha_mpl_to_svg = {'left': 'start', 'right': 'end',
'center': 'middle'}
View
@@ -261,7 +261,7 @@ def render_rect_filled(self, x1, y1, x2, y2):
self.pswriter.write(ps)
def get_results(self, box, used_characters):
- ship(0, -self.depth, box)
+ ship(0, 0, box)
return (self.width,
self.height + self.depth,
self.depth,
@@ -288,7 +288,7 @@ def render_rect_filled(self, x1, y1, x2, y2):
self.rects.append((x1, self.height - y2, x2 - x1, y2 - y1))
def get_results(self, box, used_characters):
- ship(0, -self.depth, box)
+ ship(0, 0, box)
return (self.width,
self.height + self.depth,
self.depth,
@@ -316,7 +316,7 @@ def render_rect_filled(self, x1, y1, x2, y2):
(x1, self.height - y1 + 1, x2 - x1, y2 - y1))
def get_results(self, box, used_characters):
- ship(0, -self.depth, box)
+ ship(0, 0, box)
svg_elements = Bunch(svg_glyphs = self.svg_glyphs,
svg_rects = self.svg_rects)
return (self.width,
@@ -346,7 +346,7 @@ def render_rect_filled(self, x1, y1, x2, y2):
(x1, self.height-y2 , x2 - x1, y2 - y1))
def get_results(self, box, used_characters):
- ship(0, -self.depth, box)
+ ship(0, 0, box)
return (self.width,
self.height + self.depth,
self.depth,
@@ -374,7 +374,7 @@ def render_rect_filled(self, x1, y1, x2, y2):
(x1, y1 - self.height, x2 - x1, y2 - y1))
def get_results(self, box, used_characters):
- ship(0, -self.depth, box)
+ ship(0, 0, box)
return (self.width,
self.height + self.depth,
self.depth,
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 4aed809

Please sign in to comment.