GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — New svg by mdboom · Pull Request #82 · matplotlib/matplotlib

Conversation

@mdboom

@mdboom 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@WeatherGod

WeatherGod commented Apr 12, 2011

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?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mdboom

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mdboom

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@leejjoon

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)
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@leejjoon

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")
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mdboom

mdboom commented May 9, 2011

Copy link
Copy Markdown
Member Author

Thanks @leejjoon. This is now fixed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mdboom added 23 commits May 9, 2011 11:06
@mdboom
Initial progress with new SVG backend
1e04fcd
@mdboom
More progress in new SVG backend. Now "passes" more regression tests,…
8dd762e
… logically if not officially.
@mdboom
More consise text spans.
f9b9a1d
@mdboom
Implement SVG path conversion in C
5169061
@mdboom
Initial progress with new SVG backend
8ac828d
@mdboom
More progress in new SVG backend. Now "passes" more regression tests,…
21d72f0
… logically if not officially.
@mdboom
Return ints, not strings, from mathtext to textpath so that high Unic…
a0e0387
…ode characters (such as those used for STIX sans) work even on narrow-Unicode builds of Python.
@mdboom
Use hex for character code ids -- it's more consistent with how Unico…
582084b
…de code points are usually represented.
@mdboom
Fix comment about the XML writer
cc28374
@mdboom
Reduce size of SVG output. Fix some clip-path bugs.
a784a15
@mdboom
Prettify code. Fix buffer overrun bug in path-to-SVG path C code.
da38a16
@mdboom
Update some of the SVG baseline tests to account for the improved acc…
35e3b35
…uracy of text rendering in the new SVG backend.
@mdboom
More test updates.
de45432
@mdboom
Store "self.writer" in a local variable where it makes sense to do so.
b356d5b
@mdboom
Add basic support for SVG fonts -- supported by Chrome, Safari and Opera
ccd009c
@mdboom
Reduce amount of indentation.
bae72c0
@mdboom
Make indentation slightly faster.
b8b7201
@mdboom
Shouldn't simplify paths -- this is vector graphics after all.
3ab2830
@mdboom
Simplify paths again -- the other vector backends do this to reduce f…
1d1d039
…ile size.
@mdboom
Fixes for text.usetex mode provided by Jae-Joon.
d6c7c75
@mdboom
Update tests to match the more accurate text rendering in the new SVG…
8ffff0b
… backend.
@mdboom
Deprecate svg.embed_char_paths in the standard way.
6d660ce
@mdboom
Use 'with' statement to ensure all XML tags are closed.
44d3cf8
mdboom added a commit that referenced this pull request May 16, 2011
@mdboom
Merge pull request #82 from mdboom/new_svg
f2f58f1
New svg
@mdboom
mdboom merged commit f2f58f1 into matplotlib:master May 16, 2011
@richbwood richbwood mentioned this pull request Dec 19, 2012
test_pcolormesh hangs #1609
Closed
@mdboom
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
@fariza
Merge pull request matplotlib#82 from fariza/camera-spatial
167f648
adding dsnu prnu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@mdboom @WeatherGod @leejjoon
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.