svgwrite icon indicating copy to clipboard operation
svgwrite copied to clipboard

embed_stylesheet error only when using profile 'tiny'

Open jotaf98 opened this issue 5 years ago • 0 comments

The following minimal code (taken from the ´using_fonts.py´ example) works, with the full profile, but not with the tiny profile:

import svgwrite

dwg = svgwrite.Drawing((800, 200), debug=True, profile='tiny')

# font data has to be downloaded to the local file system
dwg.embed_font(name="Indie Flower", filename='fonts/IndieFlower.ttf')
dwg.embed_stylesheet('.flower14 { font-family: "Indie Flower"; font-size: 14; }')
paragraph = dwg.add(dwg.g(class_="flower14", ))  # error here

paragraph.add(dwg.text("Font 'Indie Flower' embedded from local file system.", insert=(10, 40)))
dwg.save('test.svg')

(Using the latest version from pip.)

Apparently "style" is not a valid element of Defs, which doesn't seem right. If it's not supported, then I guess ´embed_stylesheet´ could warn early that the tiny profile is not supported:

  File "test_stylesheet.py", line 12, in <module>
    dwg.embed_font(name='Indie Flower', filename='fonts/IndieFlower.ttf')      
  File "C:\Program Files\Python37\lib\site-packages\svgwrite\container.py", line 151, in embed_font
    self._embed_font_data(name, data, font_mimetype(filename))       
  File "C:\Program Files\Python37\lib\site-packages\svgwrite\container.py", line 169, in _embed_font_data
    self.embed_stylesheet(content)
  File "C:\Program Files\Python37\lib\site-packages\svgwrite\container.py", line 142, in embed_stylesheet
    return self.defs.add(Style(content))
  File "C:\Program Files\Python37\lib\site-packages\svgwrite\base.py", line 177, in add
    self.validator.check_valid_children(self.elementname, element.elementname)
  File "C:\Program Files\Python37\lib\site-packages\svgwrite\validator2.py", line 135, in check_valid_children
    raise ValueError("Invalid children '%s' for svg-element <%s>." % 
(childrenname, elementname))
ValueError: Invalid children 'style' for svg-element <defs>.

jotaf98 avatar Mar 01 '20 12:03 jotaf98