From 2e73697bcca41830e0fbb7b50b0474e48da52238 Mon Sep 17 00:00:00 2001 From: Xiaowen Tang Date: Sat, 26 Jul 2014 13:33:07 +0800 Subject: [PATCH 1/3] SVG backend font-weight bug font-weight is not properly saved to the svg file. --- lib/matplotlib/backends/backend_svg.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index 89e4d5986fb8..8b636d2f05e7 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -1002,6 +1002,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None): style['font-size'] = six.text_type(fontsize) + 'px' style['font-family'] = six.text_type(fontfamily) style['font-style'] = prop.get_style().lower() + style['font-weight'] = prop.get_weight().lower() attrib['style'] = generate_css(style) if mtext and (angle == 0 or mtext.get_rotation_mode() == "anchor"): @@ -1070,7 +1071,8 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None): style = generate_css({ 'font-size': six.text_type(fontsize) + 'px', 'font-family': font.family_name, - 'font-style': font.style_name.lower()}) + 'font-style': font.style_name.lower(), + 'font-weight': font.style_name.lower()}) if thetext == 32: thetext = 0xa0 # non-breaking space spans.setdefault(style, []).append((new_x, -new_y, thetext)) From 4d36c45660c0c4d57c9c383ed37207c48b398c0b Mon Sep 17 00:00:00 2001 From: Xiaowen Tang Date: Wed, 6 Aug 2014 13:10:15 +0800 Subject: [PATCH 2/3] add a nose test --- .../test_backend_svg/bold_font_output.svg | 1124 +++++++++++++++++ lib/matplotlib/tests/test_backend_svg.py | 10 + 2 files changed, 1134 insertions(+) create mode 100644 lib/matplotlib/tests/baseline_images/test_backend_svg/bold_font_output.svg diff --git a/lib/matplotlib/tests/baseline_images/test_backend_svg/bold_font_output.svg b/lib/matplotlib/tests/baseline_images/test_backend_svg/bold_font_output.svg new file mode 100644 index 000000000000..e208a77877f5 --- /dev/null +++ b/lib/matplotlib/tests/baseline_images/test_backend_svg/bold_font_output.svg @@ -0,0 +1,1124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/matplotlib/tests/test_backend_svg.py b/lib/matplotlib/tests/test_backend_svg.py index 724e6c509498..11f8441e0163 100644 --- a/lib/matplotlib/tests/test_backend_svg.py +++ b/lib/matplotlib/tests/test_backend_svg.py @@ -72,6 +72,16 @@ def test_text_urls(): assert expected in buf +@image_comparison(baseline_images=['bold_font_output'], extensions=['svg']) +def test_bold_font_output(): + fig = plt.figure() + ax = fig.add_subplot(1, 1, 1) + ax.plot(np.arange(10), np.arange(10)) + ax.set_xlabel('nonbold-xlabel') + ax.set_ylabel('bold-ylabel',fontweight='bold') + ax.set_title('bold-title',fontweight='bold') + + if __name__ == '__main__': import nose nose.runmodule(argv=['-s', '--with-doctest'], exit=False) From 573033d5d4b60a11e99cb0d9a17f6a4a8416de47 Mon Sep 17 00:00:00 2001 From: Xiaowen Tang Date: Wed, 6 Aug 2014 21:59:56 +0800 Subject: [PATCH 3/3] modify code in order to conform to PEP8 --- lib/matplotlib/tests/test_backend_svg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_svg.py b/lib/matplotlib/tests/test_backend_svg.py index 11f8441e0163..4d2632bc3afa 100644 --- a/lib/matplotlib/tests/test_backend_svg.py +++ b/lib/matplotlib/tests/test_backend_svg.py @@ -78,8 +78,8 @@ def test_bold_font_output(): ax = fig.add_subplot(1, 1, 1) ax.plot(np.arange(10), np.arange(10)) ax.set_xlabel('nonbold-xlabel') - ax.set_ylabel('bold-ylabel',fontweight='bold') - ax.set_title('bold-title',fontweight='bold') + ax.set_ylabel('bold-ylabel', fontweight='bold') + ax.set_title('bold-title', fontweight='bold') if __name__ == '__main__':