FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

New svg by mdboom · Pull Request #82 · matplotlib/matplotlib · GitHub

Repository navigation

New svg - #82

Merged
mdboom merged 23 commits into
matplotlib:masterfrom
mdboom:new_svg
May 16, 2011
Merged

mdboom merged 23 commits into
matplotlib:masterfrom
mdboom:new_svg

Conversation

mdboom commented Apr 12, 2011

Copy link
Copy Markdown
Member

Refactoring of the SVG backend to pave the way for an interactive SVG backend down the road. Uses an XMLWriter class to keep the code simpler and more likely to produce valid XML. Numerical precision of text placement is much better. Paths are now generated in C, resulting in a significant speed-up. All text (math and otherwise) is produced using the textpath.py module.

Copy link
Copy Markdown
Member

I know this was an issue with PS and PDF backends, but will SVG have textual data stored as entered, or are the letters broken up and set individually?

mdboom commented Apr 12, 2011

Copy link
Copy Markdown
Member Author

It depends on the value of rcParam "svg.embed_char_paths". Embedding the character paths makes the file portable to other machines without the necessary fonts. Not embedding the character paths makes the file editable, but if the fonts aren't installed, ugliness is very likely to ensue. SVG fonts, or CSS @font-face may be a way around this -- neither was very well supported by renderers last time I looked -- the situation may be better now. But this pull request doesn't really change the status quo of what the SVG backend was capable of previously in that regard.

mdboom commented Apr 12, 2011

Copy link
Copy Markdown
Member Author

Based on WeatherGod's comment, this commit adds support for writing out SVG fonts. These are supported in Chrome, Opera and Safari (see here: http://caniuse.com/svg-fonts).

This isn't quite the holy grail we want it to be, of course, since I'm not aware of any editors (eg. Inkscape) that support SVG fonts, so the difference between this and the chars-as-paths version (which is supported in all SVG-supporting browsers) is pretty academic.

leejjoon commented May 9, 2011

Copy link
Copy Markdown
Contributor

The backend fails when text.ustex=True (w/ svg.fonttype="path"). Here are some quick fixes.

diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/ba
index ec17053..d606855 100644
--- a/lib/matplotlib/backends/backend_svg.py
+++ b/lib/matplotlib/backends/backend_svg.py
@@ -986,7 +986,12 @@ class RendererSVG(RendererBase):
             writer.end('g')
 
     def draw_tex(self, gc, x, y, s, prop, angle):
-        self.draw_text_as_path(gc, x, y, s, prop, angle, ismath="TeX")
+        if rcParams['svg.fonttype'] == 'path':
+            self._draw_text_as_path(gc, x, y, s, prop, angle, ismath="TeX")
+        else:
+            self._draw_text_as_text(gc, x, y, s, prop, angle, ismath="TeX")
 
     def draw_text(self, gc, x, y, s, prop, angle, ismath):
         clipid = self._get_clip(gc)
diff --git a/lib/matplotlib/textpath.py b/lib/matplotlib/textpath.py
index a353a2b..6955b95 100644
--- a/lib/matplotlib/textpath.py
+++ b/lib/matplotlib/textpath.py
@@ -76,7 +76,7 @@ class TextToPath(object):
             texmanager = self.get_texmanager()
             fontsize = prop.get_size_in_points()
             w, h, d = texmanager.get_text_width_height_descent(s, fontsize,
-                                                               renderer=self)
+                                                               renderer=None)
             return w, h, d
 
         fontsize = prop.get_size_in_points()
@@ -130,7 +130,7 @@ class TextToPath(object):
 
         for glyph_id, xposition, yposition, scale in glyph_info:
             verts1, codes1 = glyph_map[glyph_id]
-            if verts1:
+            if len(verts1):
                 verts1 = np.array(verts1)*scale + [xposition, yposition]
             verts.extend(verts1)
             codes.extend(codes1)

leejjoon commented May 9, 2011

Copy link
Copy Markdown
Contributor

Since _draw_text_as_text does not seem to support ismath="TeX", we may simply do

def draw_tex(self, gc, x, y, s, prop, angle):
    self._draw_text_as_path(gc, x, y, s, prop, angle, ismath="TeX")

mdboom commented May 9, 2011

Copy link
Copy Markdown
Member Author

Thanks @leejjoon. This is now fixed.

mdboom added 23 commits May 9, 2011 11:06
…ode characters (such as those used for STIX sans) work even on narrow-Unicode builds of Python.
mdboom added a commit that referenced this pull request May 16, 2011
mdboom merged commit f2f58f1 into matplotlib:master May 16, 2011
richbwood mentioned this pull request Dec 19, 2012
mdboom deleted the new_svg branch March 3, 2015 18:44
fariza added a commit to fariza/matplotlib that referenced this pull request Sep 22, 2016
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL