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

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1e04fcd
Initial progress with new SVG backend
mdboom Mar 31, 2011
8dd762e
More progress in new SVG backend. Now "passes" more regression tests…
mdboom Mar 31, 2011
f9b9a1d
More consise text spans.
mdboom Mar 31, 2011
5169061
Implement SVG path conversion in C
mdboom Apr 1, 2011
8ac828d
Initial progress with new SVG backend
mdboom Mar 31, 2011
21d72f0
More progress in new SVG backend. Now "passes" more regression tests…
mdboom Mar 31, 2011
a0e0387
Return ints, not strings, from mathtext to textpath so that high Unic…
mdboom Apr 12, 2011
582084b
Use hex for character code ids -- it's more consistent with how Unico…
mdboom Apr 12, 2011
cc28374
Fix comment about the XML writer
mdboom Apr 12, 2011
a784a15
Reduce size of SVG output. Fix some clip-path bugs.
mdboom Apr 12, 2011
da38a16
Prettify code. Fix buffer overrun bug in path-to-SVG path C code.
mdboom Apr 12, 2011
35e3b35
Update some of the SVG baseline tests to account for the improved acc…
mdboom Apr 12, 2011
de45432
More test updates.
mdboom Apr 12, 2011
b356d5b
Store "self.writer" in a local variable where it makes sense to do so.
mdboom Apr 12, 2011
ccd009c
Add basic support for SVG fonts -- supported by Chrome, Safari and Opera
mdboom Apr 12, 2011
bae72c0
Reduce amount of indentation.
mdboom Apr 12, 2011
b8b7201
Make indentation slightly faster.
mdboom Apr 15, 2011
3ab2830
Shouldn't simplify paths -- this is vector graphics after all.
mdboom Apr 15, 2011
1d1d039
Simplify paths again -- the other vector backends do this to reduce f…
mdboom May 9, 2011
d6c7c75
Fixes for text.usetex mode provided by Jae-Joon.
mdboom May 9, 2011
8ffff0b
Update tests to match the more accurate text rendering in the new SVG…
mdboom May 9, 2011
6d660ce
Deprecate svg.embed_char_paths in the standard way.
mdboom May 16, 2011
44d3cf8
Use 'with' statement to ensure all XML tags are closed.
mdboom May 16, 2011
File filter

Filter by extension

Filter by extension .py  (2) .template  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Prev Previous commit
Next Next commit
Add basic support for SVG fonts -- supported by Chrome, Safari and Opera
  • Loading branch information
mdboom committed May 9, 2011
commit ccd009c0702683c8d84ae70d72eb5047b5373109
51 changes: 49 additions & 2 deletions lib/matplotlib/backends/backend_svg.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def __init__(self, width, height, svgwriter, basename=None):
self._hatchd = {}
self._has_gouraud = False
self._n_gradients = 0
self._fonts = {}
self.mathtext_parser = MathTextParser('SVG')

RendererBase.__init__(self)
Expand All @@ -277,6 +278,7 @@ def __init__(self, width, height, svgwriter, basename=None):
self._write_default_style()

def finalize(self):
self._write_svgfonts()
self.writer.close(self._start_id)

def _write_default_style(self):
Expand Down Expand Up @@ -422,6 +424,40 @@ def _get_clip(self, gc):
self._clipd[dictkey] = oid
return oid

def _write_svgfonts(self):
if not rcParams['svg.fonttype'] == 'svgfont':
return

writer = self.writer
writer.start('defs')
for font_fname, chars in self._fonts.items():
font = FT2Font(font_fname)
font.set_size(72, 72)
sfnt = font.get_sfnt()
writer.start('font', id=sfnt[(1, 0, 0, 4)])
writer.element(
'font-face',
attrib={
'font-family': font.family_name,
'font-style': font.style_name,
'units-per-em': '72',
'bbox': ' '.join(str(x / 64.0) for x in font.bbox)})
for char in chars:
glyph = font.load_char(char, flags=LOAD_NO_HINTING)
verts, codes = font.get_path()
path = Path(verts, codes)
path_data = self._convert_path(path, None)
# name = font.get_glyph_name(char)
writer.element(
'glyph',
d=path_data,
attrib={
# 'glyph-name': name,
'unicode': unichr(char),
'horiz-adv-x': str(glyph.linearHoriAdvance / 65536.0)})
writer.end('font')
writer.end('defs')

def open_group(self, s, gid=None):
"""
Open a grouping element with label *s*. If *gid* is given, use
Expand Down Expand Up @@ -867,6 +903,11 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath):
('rotate', (-angle,))])

writer.element('text', s, attrib=attrib)

if rcParams['svg.fonttype'] == 'svgfont':
fontset = self._fonts.setdefault(font.fname, set())
for c in s:
fontset.add(ord(c))
else:
writer.comment(s)

Expand Down Expand Up @@ -894,11 +935,17 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath):
for font, fontsize, thetext, new_x, new_y, metrics in svg_glyphs:
style = generate_css({
'font-size': str(fontsize),
'font-family': font.family_name})
'font-family': font.family_name,
'font-style': font.style_name})
if thetext == 32:
thetext = 0xa0 # non-breaking space
spans.setdefault(style, []).append((new_x, -new_y, thetext))

if rcParams['svg.fonttype'] == 'svgfont':
for font, fontsize, thetext, new_x, new_y, metrics in svg_glyphs:
fontset = self._fonts.setdefault(font.fname, set())
fontset.add(thetext)

for style, chars in spans.items():
chars.sort()

Expand Down Expand Up @@ -948,7 +995,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
self.writer.start(
'g', attrib={'clip-path': 'url(#%s)' % clipid})

if rcParams['svg.embed_char_paths']:
if rcParams['svg.fonttype'] == 'path':
self._draw_text_as_path(gc, x, y, s, prop, angle, ismath)
else:
self._draw_text_as_text(gc, x, y, s, prop, angle, ismath)
Expand Down
8 changes: 7 additions & 1 deletion lib/matplotlib/rcsetup.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ def validate_tkpythoninspect(s):
'center',
], ignorecase=True)

def deprecate_svg_embed_char_paths(value):
warnings.warn("svg.embed_char_paths is deprecated. Use svg.fonttype instead.")

validate_svg_fonttype = ValidateInStrings('fonttype', ['none', 'path', 'svgfont'])

class ValidateInterval:
"""
Value must be in interval
Expand Down Expand Up @@ -530,7 +535,8 @@ def __call__(self, s):
'pdf.fonttype' : [3, validate_fonttype], # 3 (Type3) or 42 (Truetype)
'svg.image_inline' : [True, validate_bool], # write raster image data directly into the svg file
'svg.image_noscale' : [False, validate_bool], # suppress scaling of raster data embedded in SVG
'svg.embed_char_paths' : [True, validate_bool], # True to save all characters as paths in the SVG
'svg.embed_char_paths' : [True, deprecate_svg_embed_char_paths], # True to save all characters as paths in the SVG
'svg.fonttype' : ['path', validate_svg_fonttype],

'docstring.hardcopy' : [False, validate_bool], # set this when you want to generate hardcopy docstring
'plugins.directory' : ['.matplotlib_plugins', str], # where plugin directory is locate
Expand Down
6 changes: 5 additions & 1 deletion matplotlibrc.template
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
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@ backend : %(backend)s
# svg backend params
#svg.image_inline : True # write raster image data directly into the svg file
#svg.image_noscale : False # suppress scaling of raster data embedded in SVG
#svg.embed_char_paths : True # embed character outlines in the SVG file
#svg.fonttype : 'path' # How to handle SVG fonts:
# 'none': Assume fonts are installed on the machine where the SVG will be viewed.
# 'path': Embed characters as paths -- supported by most SVG renderers
# 'svgfont': Embed characters as SVG fonts -- supported only by Chrome,
# Opera and Safari

# docstring params
#docstring.hardcopy = False # set this when you want to generate hardcopy docstring
Expand Down

Back | FazBrowse Home | New Git URL