Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Improved output of text in SVG and PDF #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ddale opened this issue Jun 20, 2011 · 4 comments
Closed

Improved output of text in SVG and PDF #353

ddale opened this issue Jun 20, 2011 · 4 comments

Comments

@ddale
Copy link
Contributor

ddale commented Jun 20, 2011

Original report at SourceForge, opened Mon Dec 15 05:08:09 2008

Text output to SVG is not preserved as pure text, but instead gets output as paths. This makes it very difficult to do adjustments afterwards in e.g. Inkscape. Text should be output as text.

In PDF-files, text is output as text, which is good. These files can be imported into Inkscape and edited, which makes it possible to go around the problem with SVG files. However, kerning is applied to all text, so there is extra spacing between each letter. This makes the text look bad and should, in my mind, be removed.

As far as possible, text objects should have sensible alignment. E.g. titles, x- and y-labels should be center-aligned, and when using fig.autofmt_xdate(), tick labels should be right-aligned. Currently, all text appears to be left-aligned.

SourceForge Comments

On Fri Jun 4 17:59:52 2010, leejjoon wrote:

I believe that this is a feature request rather than a bug in the current stage.
I'm moving this to a feature requests tracker.

-JJ

On Fri Dec 19 09:18:02 2008, mdboom wrote:

Text can be output as text only if the correct fonts are available on the machine on which the SVG is viewed/edited. Since a common use case of SVG is to share in a browser, embedded paths is often the best thing. The SVG font standard would be a much better way to solve this, but as of a year ago, last time I looked, none of Mozilla, Inkscape, or cairo-rsvg had SVG font support. Progress has been made in the intervening time, but until a release version of software supports it, it's not going to be very practical or useful. It's a bit of a chicken-and-egg problem. As John pointed out, though, the svg.embed_char_paths option allows the user to choose, as long as the viewer/editor has access to the same fonts as matplotlib.

As for your second point about text kerning in PDF files -- I suspect this is an issue in the PDF-to-SVG conversion, as the kerning looks fine in the original PDF, and is in fact required for the text to look correct, since we embed only a subset of the font. I'm trying to reproduce this, but my Inkscape (0.46) doesn't seem to have PDF import as an option (though it may just be a missing dependency). Can you file a separate bug for this and attach .pdf and .svg (converted from .pdf) that exhibits this problem?

Lastly, as for alignment, I think that's a reasonable goal, but is a reasonably large task. It will require refactoring all of the backends, which are currently completely ignorant of text alignment. Unfortunately, in the general case including math text, this is probably impossible -- we may only be able to support this for regular text.

As you can see, the emphasis has always been on output for display rather than editing (the latter is simply a lot harder to get right, as with any tool that generates code).

On Thu Dec 18 05:19:10 2008, malmjako wrote:

Thanks! Setting 'svg.embed_char_paths' False gave me plain text in the SVG. However, the text is not correctly aligned. Although the texts are qualitatively in the right place, center- and right-aligned texts are somewhat off, as it seems because the width is not correctly calculated for plain text output.

SVG text objects need to have the style attribute(s) 'text-anchor' and possibly 'text-align' correctly set (although changing the latter did not have any effect on how Inkscape rendered text objects), and the reference point set to the left, center or right point of the object, i.e. the position that the text should be aligned to. No width calculation would then be necessary, resulting in correctly aligned text when using plain text output. It would also make editing the text easier, because text would flow correctly without having to realign the text object.

I have matplotlib 0.98.3 from the Enthought Python Distribution for Windows. Please try with plain text output from 0.98.5 as well!
File Added: alignment_test_0.98.3_plaintext.svg

On Wed Dec 17 06:15:11 2008, jdh2358 wrote:

When I run the alignement_test, included below, all text appears to be aligned properly in svg. I am running 0.98.5 (what version are you running?)

You can control whether matplotlib embeds the character paths or the plain text using the rc paramter 'svg.embed_char_paths'. See http://matplotlib.sourceforge.net/users/customizing.html for info on how to set the rc paramters.

SourceForge History

  • On Fri Jun 4 17:59:52 2010, by leejjoon: data_type: 560723
  • On Fri Jun 4 17:59:52 2010, by leejjoon: resolution_id: 100
  • On Thu Dec 18 16:30:55 2008, by jdh2358: assigned_to: 395152
  • On Thu Dec 18 05:19:10 2008, by malmjako: File Added: 305825: alignment_test_0.98.3_plaintext.svg
  • On Wed Dec 17 06:16:01 2008, by jdh2358: File Added: 305696: alignment_test.svg
  • On Wed Dec 17 06:15:50 2008, by jdh2358: File Added: 305695: alignment_test.py
  • On Wed Dec 17 06:15:11 2008, by jdh2358: assigned_to: 100
@pelson
Copy link
Member

pelson commented Jun 7, 2012

@mdboom were you aware of this issue? I know you've been in this space the most lately and wonder if you are in a position to comment whether the feature described is fixed/not possible/desirable?

@mdboom
Copy link
Member

mdboom commented Jun 7, 2012

There's two issues combined here.

  1. On SVG text, we now have SVGFont support, (set rcParam svg.fonttype to svgfont) which makes editing easier. Unfortunately, the SVGFont standard is not supported everywhere, see this:

http://caniuse.com/#feat=svg-fonts

Opening an SVG file with SVGFonts seems to put Inkscape 0.48 into an infinite loop. I'm not sure whether the issue is on our end or theirs -- that's worth further investigation.

  1. We don't currently output the text alignment to vector formats, but instead do the alignment beforehand and everything ends up logically left justified. Fixing that is probably quite hairy, as that assumption permeates all layers of the stack. It would be worthwhile fixing it, however, ignoring mathtext, of course.

I would, perhaps, close this bug and create two. One for the fact that our svgfont support appears to wreak havoc with Inkscape, and another for the fact that text alignment in all of the vector output formats could be improved.

@mdboom
Copy link
Member

mdboom commented Jun 7, 2012

FYI: It appears that while Inkscape has an SVG font editor, it doesn't yet support the usage of SVG fonts from an SVG file.

@pwuertz
Copy link
Contributor

pwuertz commented Jul 1, 2012

Concerning (2).. I ran into the same problem when I tried to do proper alignment for my Pgf backend.

The documentation of the draw_text function

http://matplotlib.sourceforge.net/api/backend_bases_api.html#matplotlib.backend_bases.RendererBase.draw_text

states that the text is a text instance, but what I'm really getting is just a simple string. I made an attempt to iterate through all text elements of a figure from which I easily obtained position and alignment correctly.

Unfortunately I ran into some other difficulties because matplotlib has some additional logic in the drawing-chain for determining weather a text is to be drawn. This is rather painful to reproduce and will probably break whenever something changes in its behavior. It would be so much easier if matplotlib just gave me the real text instances in the drawing routine.

Is this an error of the documentation or did the developers decide to use strings instead of text instances at some point without updating the documentation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants