Git Product home page Git Product logo

svgwrite's Introduction

svgwrite

This package is inactive! No new features will be added, there will be no change of behavior, just bugfixes will be merged.

Abstract

A Python library to create SVG drawings.

a simple example:

import svgwrite

dwg = svgwrite.Drawing('test.svg', profile='tiny')
dwg.add(dwg.line((0, 0), (10, 0), stroke=svgwrite.rgb(10, 10, 16, '%')))
dwg.add(dwg.text('Test', insert=(0, 0.2), fill='red'))
dwg.save()

for more examples see: examples.py

As the name svgwrite implies, svgwrite creates new SVG drawings, it does not read existing drawings and also does not import existing drawings, but you can always include other SVG drawings by the <image> entity.

svgwrite is a pure Python package and has no external dependencies.

Installation

with pip:

pip install svgwrite

or from source:

python setup.py install

Documentation

http://readthedocs.org/docs/svgwrite/

svgwrite can be found on GitHub.com at:

http://github.com/mozman/svgwrite.git

Contact

[email protected]

svgwrite's People

Contributors

cghanke avatar dbready avatar eumiro avatar florianfesti avatar jamadagni avatar jmahmood avatar mitar avatar mozman avatar nathan-muir avatar nathanwoody avatar natureshadow avatar normanrz avatar paulcordo avatar qbilius avatar resloved avatar shlomif avatar suriya avatar vojtechtrefny avatar wlouiskroeger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

svgwrite's Issues

Creating Inkscape layers with svgwrite

Hi,

This is not really an issue report but rather more of a comment, feel free to close it right away :)

In case someone needed to create Inkscape layers with svgwrite here is an InkscapeDrawing class which extends the validator to recognize the required attributes:
https://git.ao2.it/experiments/svgwrite_inkscape_drawing.git/blob/HEAD:/svgwrite_inkscape_drawing.py

My use case is to create some baseline svg file programmatically with svgwrite and then customize it in inkscape; and having objects grouped into layers makes the customization a little easier.

Thanks,
Antonio

No visible text in svgwrite.Drawing().textArea()

The code below writes out a file named no_textArea.svg which when rendered displays the text string but the textArea string is not displayed. What am I doing wrong?

import svgwrite  # pip install svgwrite

MAX_PIXELS = 1000

def make_drawing(filename="no_textArea.svg"):
    dwg = svgwrite.Drawing(filename, size=(MAX_PIXELS, MAX_PIXELS), profile="tiny")
    dwg.viewbox(0, 0, MAX_PIXELS, MAX_PIXELS)
    dwg.add(dwg.rect(size=('100%', '100%'), fill="lightgrey", class_='background'))

    dwg.add(dwg.text(text="Here is text", fill="darkblue", insert=("2%", "2%")))
    dwg.add(dwg.textArea(text="But no textArea\nDown below!", fill="darkblue",
                         insert=("2%", "20%"), size=("80%", "80%"), profile="tiny"))
    return dwg

make_drawing().save()

https://stackoverflow.com/questions/49449460/how-to-implement-svgwrite-textarea-in-python was the closest question that I could find on Stack Overflow but that did not get answered.

How to use rotation transform?

I am trying to add a rotation transform to a text. From the documentation it appears this should be possible via the Transformation.rotate mixin, but I cannot figure out how to use it. So far I was only able to do

drawing.text(text="foo", insert=(0, 0), transform="rotate(90, 0, 0)")

But constructing this string from data doesn't feel right ;).

Use <pageset> and <page>

I try to make some quiz forms for optical recognition with responder name preprinted.
I would like to generate one svg file with each form on a page than "print' it to a multipage pdf from Chrome.
Is there support for the <pageset> and <page> tags?
Couldn't find it in the docs.

Thank you for this great libray!

Invalid attribute 'textLength' for svg-element <text>

import svgwrite from svgwrite import cm, mm dwg = svgwrite.Drawing('test.svg', height=8*cm, width=8*cm, profile='tiny') dwg.add(dwg.ellipse(center=(5*cm, 5*cm), r=('4cm', '3cm'), stroke='red', fill='none', stroke_width='1mm')) dwg.add(dwg.text('91150100114153398C', insert=(2*cm, 6*cm), textLength='20', lengthAdjust='spacingAndGlyphs', fill='red', font_family='Arial', font_weight='bold', font_size='20', stroke_width='0.5')) dwg.save()

ICC-colors

Is there support for using ICC-colors instead of sRGB colours, e.g., as part of a stroke specification of a line?

If not, is this a planned feature?

Is `debug` the best name for this parameter?

I'm curious about the naming of the debug parameter on subclasses of BaseElement. I helped a user this week with a somewhat mysterious slowdown of their SVG generation, which turned out to be solved by explicitly turning this validation behavior off.

The name debug to me suggests that this is opt-in behavior intended for diagnosing buggy behavior, so the default behavior of having this turned on is unintuitive to me. Would it make sense to perhaps rename this parameter to validate to better match its behavior?

Expose ElementTrees xml_declaration option

We are having a few problems because of SVG files not having a proper xml document header similar to this:
<?xml version="1.0" encoding="UTF-8" ?>

ElementTree (which I believe is what svgwrite is based on) apparently skips that if the encoding is UTF-8. There is a flag, though, that let's you force ElementTree.write() to always include it. It would be cool, if that flag were exposed by Drawing::save() and Drawing::saveAs(). That might also be a better way of manually adding the encoding in Drawing::write().

Use of parametric svg in parser

I want to parse parametric SVG and reproduce corresponding SVG file as user requirement. Can we use that fact and implement it using svgwrite.
Please let me know if you have any suggestions for the same.

Licensing issues

Hi, this is a very nice job. I would like to use this package but I need to be sure about the licensing: the LICENSE file is a clear MIT while the file svgwrite/shapes.py contains a clear GPL. Is this wanted? If not, could you pls correct it?

Another issue are the font files in the example... they have another different license. Is this also wanted?

Thank you!

save() is very slow

It feels like the save() function is a magnitude too slow:

import svgwrite
import time

size = 100
d = svgwrite.Drawing('example.svg', (size, size))

t1 = time.time()
for y in range(size):
    for x in range(size):
        d.add(d.path(d="M %d %d L %d %d" % (x, y, y, x),  stroke='#888'))
t2 = time.time()
d.save()
t3 = time.time()

print("create:", t2-t1)
print("save:", t3-t2)

The above example gives the following output (together with a ~400kB SVG file):

create: 0.5911922454833984
save: 22.79025411605835

When doing a profile of the code it seems the problem is etree.tostring() so I guess the issue should go there instead, but is it possible to do improve something about this in the svgwrite as well?

Utility function to compute the size of an element

Recursively. It looks like this is pretty useful when one wants to layout things, but it is also not trivial. It would be awesome if there would be an utility function to compute the size of whatever is given, respecting viewport, translations, all that stuff.

Simplify example code

Just a minor thing, I'm just having a look at this library, but I get the feeling the example is more intricate than it needs to. From the demo code:

import svgwrite

dwg = svgwrite.Drawing('test.svg', profile='tiny')
dwg.add(dwg.line((0, 0), (10, 0), stroke=svgwrite.rgb(10, 10, 16, '%')))
dwg.add(dwg.text('Test', insert=(0, 0.2), fill='red'))
dwg.save()

Why does a Drawing instance + calling dwg.add is required to create a line ?
It feels duplicate.

This version removes this duplicate behavior:

import svgwrite
from svgwrite.shapes import Line
from svgwrite.text import Text

dwg = svgwrite.Drawing('test.svg', profile='tiny')
dwg.add(Line((0, 0), (10, 0), stroke=svgwrite.rgb(10, 10, 16, '%')))
dwg.add(Text('Test', insert=(0, 0.2), fill='red'))
dwg.save()

Maybe it already does, but also it would be nice to group common SVG primitives under the root svgwrite namespace to simplify imports.

ValueError: Invalid children 'pattern' for svg-element <defs>.

I am attempting to recreate this SVG grid example in svgwrite

<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <pattern id="smallGrid" width="8" height="8" patternUnits="userSpaceOnUse">
      <path d="M 8 0 L 0 0 0 8" fill="none" stroke="gray" stroke-width="0.5"/>
    </pattern>
    <pattern id="grid" width="80" height="80" patternUnits="userSpaceOnUse">
      <rect width="80" height="80" fill="url(#smallGrid)"/>
      <path d="M 80 0 L 0 0 0 80" fill="none" stroke="gray" stroke-width="1"/>
    </pattern>
  </defs>

  <rect width="100%" height="100%" fill="url(#grid)" />
</svg>

I am getting an error when attempting to add the patterns to the defs section.

Here is my code.

import svgwrite
from svgwrite import pattern

dwg = svgwrite.Drawing('images/grid-patterns.svg', size=(u'100%', u'100%'), profile='tiny')

# <pattern id="smallGrid" width="8" height="8" patternUnits="userSpaceOnUse">
smallGrid = pattern.Pattern(size=(8, 8), patternUnits="userSpaceOnUse", id='smallGrid')

# <path d="M 8 0 L 0 0 0 8" fill="none" stroke="gray" stroke-width="0.5"/>
smallGrid.add( dwg.path(d="M 8 0 L 0 0 0 8", fill="none", stroke="gray", stroke_width="0.5"))

# debug
print(smallGrid.tostring())

# <pattern id="grid" width="80" height="80" patternUnits="userSpaceOnUse">
Grid = pattern.Pattern(size=(80, 80), patternUnits="userSpaceOnUse",id='grid')

# <rect width="80" height="80" fill="url(#smallGrid)"/>
Grid.add( dwg.rect(size=(80,80), fill="url(#smallGrid)"))

#<path d="M 80 0 L 0 0 0 80" fill="none" stroke="gray" stroke-width="1"/>
Grid.add( dwg.path(d="M 80 0 L 0 0 0 80", fill="none", stroke="gray", stroke_width="1"))

#debug
print(Grid.tostring())

# Add two patterns to defs
dwg.defs.add(smallGrid)
dwg.defs.add(Grid)

# <rect width="100%" height="100%" fill="url(#grid)" />
dwg.add(dwg.rect(size=("100%","100%"), fill="url(#grid)" ))

# write svg file to disk
dwg.save()

Here is the traceback

Traceback (most recent call last): 
...
  File "svg-grid-patterns.py", line 16, in <module>
    dwg.defs.add(smallGrid)
  File ".venv\lib\site-packages\svgwrite\base.py", line 173, in add
    self.validator.check_valid_children(self.elementname, element.elementname)
  File ".venv\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 'pattern' for svg-element <defs>.

I've also noticed that I cannot add the final rect without a specified x, y value. Is that possible?

Order of transformations

In the example below, I rotate then translate a square.
I am expecting a svg with "translate(50,0) rotate(45) " since in svg, the first transformation in on the right.
But svgwrite produces "rotate(45) translate(50,0)"

Am I doing it wrong? Is there a something to configure to have it in reversed order?
Attaching example:

import svgwrite

drw = svgwrite.Drawing(filename = "test-svgwrite.svg", size = (100, 100))

# Center black square at origin. rotate then translate to the right
# Expecting black square on y=0
# Expecting transform="translate(50,0) rotate(45)"
sq=drw.add(drw.rect(insert=(-10, -10), size = (20, 20), fill="black"))
sq.rotate(45)
sq.translate(50, 0)

# Center blue square at origin. translate to the right then rotate with center at origin
# Expecting blue square on y=x diagonal
# Expecting transform="rotate(45) translate(50,0)"
sq2=drw.add(drw.rect(insert=(-10, -10), size = (20, 20), fill="blue"))
sq2.translate(50, 0)
sq2.rotate(45)

# Black square is at position of blue one, and vice versa
drw.save()

tag 1.1.10

Please, add 1.1.10 into releases page.

Automatic generation of clipping path IDs and referencing them

Similar to how group IDs are automatically generated and once can then reference them by Python object in use, something similar could be done for clipping paths.

clip_path = drawing.clipPath()
drawing.defs.add(clip_path)
clip_path.add(drawing.rect(insert=(0, 0), size=(10, 10)))
drawing.circle((10, 10), 10, clip_path=clip_path)

One has to currently do:

drawing.circle((10, 10), 10, clip_path=clip_path.get_funciri())

Which is not documented either.

Adding Title to elements

How would one add a title to elements to create a tooltip?

edit: never mind found the set_desc method.

how to specify xlink attributes?

For the attributes that contain a hyphen I can specify using underscore. Is there a similar convention for specifying xlink attributes? i.e. xlink_title? I want to be able to specify the title for a hyperlink but I haven't been able to do so

<text> initialization method's x, y arguments don't accept decimals

Hi,

some_drawing_object.text(text = "hi", y = "21.838867") triggers the validator2 module error handler functions:
TypeError: '2 1 . 8 3 8 8 6 7' is not a valid value for attribute 'y' at svg-element <text>.

For some reason these spaces inbetween digits are added in the error message.
Using the update method on a text element to do the same thing works fine, however.

Using bold and changing the font type

Hi, Manfred!

Thank you very much for developing this Python library!

I would like to know if it is possible to write bold text and changing the font type (eg DejaVu Sans). I have been researching but I have not succeeded. If it is possible, I would appreciatel if you could give me an example of how to do it.

Thanks in advance.

Regards,
Daniel

svgwrite does not work when running script from cmd, Atom, or VS code

I installed svgwrite with pip running python 3.7.1 on win10x64 and i can only access the module directly from the python IDLE. From everywhere else, it doesn't seem to work. I have checked with other modules in the site-packages and they work, so it doesn't seem to be a PATH issue.

Setting `debug=False` does not reduce save times.

I was experiencing this issue and tried setting debug=False when calling svgwrite.Drawing() as suggested, yet it does not appear to have any noticeable effect on save times.

The slow time is definitely a result of calling tostring() during the save process.

Any help would be greatly appreciated.

alignment-baseline for <text>

I have the version 1.2.1

I can use text-anchor for <text>

        self.draw.add(self.draw.text(text=text, insert=[self.x(x), self.y(y)],
                                     text_anchor = anchorH, alignment_baseline = anchorV,
                                     stroke = stroke))

but with alignment-baseline I get the error

ValueError: Invalid attribute 'alignment-baseline' for svg-element <text>.

setup.py in branch develop broken

The function get_version() requires the package ezdxf installed in ezdxf/version.py

def get_version():
    v = {}
    # do not import ezdxf, because required packages may not installed yet
    for line in open('./ezdxf/version.py').readlines():

'auto' is not a valid value for attribute 'rotate' at svg-element <animateMotion>

Hi everybody,

like the topic already says: After having a line like this:
dwg.animateMotion(anim_path, dur='15s', rotate='auto')
I get a TypeError saying:
'auto' is not a valid value for attribute 'rotate' at svg-element <animateMotion>

While trying:
dwg.animateMotion(anim_path, dur='15s', rotate='5')
works just fine. I think validator2.py maybe sorting out strings? (just a guess)

The docs and the svg specs say that 'auto' should be a valid argument here.

Specifying height, width in constructor doesn't work

Code example from https://svgwrite.readthedocs.io/en/master/overview.html
Drawing(height='10cm', width='20cm') # drawing area of 10cm x 20cm
doesn't work correctly.
It produces <svg baseProfile="full" height="100%" version="1.1" width="100%" ...

I run pip install --upgrade svgwrite (is says 1.3.1)

I searched the docs and the only thing that worked for me is passing 'size' directly to init

dwg = svgwrite.Drawing(height='10cm', width='20cm')
dwg.saveas('test2.svg')

dwg = svgwrite.Drawing(size=('20cm', '10cm'))
dwg.saveas('test3.svg')

test3 has the correct height, width: <svg baseProfile="full" height="10cm" version="1.1" width="20cm"

paint-order attribute? SVG2?

#! /usr/bin/env python

import svgwrite

def main():
    """
    Run the program.
    """
    dwg = svgwrite.Drawing(profile='full', size=(1000, 1000), viewBox='-500 -500 1000 1000', debug=True)
    g = dwg.g()
    g['paint-order'] = "stroke full"

if __name__ == "__main__":
    main()

Running the above results in:

ValueError: Invalid attribute 'paint-order' for svg-element <g>.

This seems to be part of SVG2. Is SVG2 supported by svgwrite?

Read in SVG?

Sorry for cluttering the issues for this repo and thanks for creating this well documented resource.

Is it possible to read in an SVG from a directory with this library? I do not appear to see that feature, but just wanted to make absolutely sure.

Make Units extensible

Hello. Thank you for svgwrite!

I tried something like: unit = 0.75 * inch because my application uses this length as a unit, but it is not further possible to multiply this to denote 2 units 3 units etc. This is because doing 0.75 * inch creates a simple string and multiplying only lengthens the string. Something like the following in __init__.py would be much more preferable, which only converts to string at the last minute:

class Unit(object):
    """ Add units to values.
    """
    def __init__(self, unit='cm', multiplier=1):
        """ Unit constructor

        :param str unit: specify the unit string
        """
        self._unit = unit
        self._mul = multiplier

    def __rmul__(self, other):
        """ create new unit by multiplying current unit with 'other'. (e.g. 5*cm => '5cm') """
        return Unit(self._unit, self._mul * other)
    
    def __str__(self):
        """ create a string representing this unit """
        return "%s%s" % (self._mul, self._unit)

but I am unable to provide a PR because I do not know the other implications of this change including how to change __call__ in the same file, hence leave it to the developer.

Thank you!

Some svg files appear blank.

Hello there! Is there a known issue when viewing svg files? I have made a module which reads coordinates from an xml file and connects them using polylines and polygons in svgwrite. While some files are saved perfectly well and can be viewed on my browser, other files appear blank even though the .svg files contains the code that is required.

Thanks in advance.

encoding error when using pretty=True

Hi!

Great library.
I'm experiencing an encoding error on python 2.7 if I use pretty=True, though:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 214-216: ordinal not in range(128)

#!/usr/bin/env python

-- coding: utf-8 --

import svgwrite

dwg=svgwrite.Drawing()
dwg.add(dwg.text("•••", insert=(0,0)))
dwg.saveas('test' + ".svg", pretty=True)

any hints?
thanks in advance,
Roman

Load existing SVG

Is it possible to read an existing SVG file? It seems there is no loading functionality.

Tests failing

running test
running egg_info
creating svgwrite.egg-info
writing svgwrite.egg-info/PKG-INFO
writing dependency_links to svgwrite.egg-info/dependency_links.txt
writing requirements to svgwrite.egg-info/requires.txt
writing top-level names to svgwrite.egg-info/top_level.txt
writing manifest file 'svgwrite.egg-info/SOURCES.txt'
reading manifest file 'svgwrite.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'svgwrite.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
  File "setup.py", line 58, in <module>
    "Topic :: Software Development :: Libraries :: Python Modules",
  File "/usr/lib/python3.7/site-packages/setuptools/__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python3.7/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.7/distutils/dist.py", line 966, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.7/distutils/dist.py", line 985, in run_command
    cmd_obj.run()
  File "/usr/lib/python3.7/site-packages/setuptools/command/test.py", line 229, in run
    self.run_tests()
  File "/usr/lib/python3.7/site-packages/setuptools/command/test.py", line 251, in run_tests
    exit=False,
  File "/usr/lib/python3.7/unittest/main.py", line 100, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python3.7/unittest/main.py", line 124, in parseArgs
    self._do_discovery(argv[2:])
  File "/usr/lib/python3.7/unittest/main.py", line 244, in _do_discovery
    self.createTests(from_discovery=True, Loader=Loader)
  File "/usr/lib/python3.7/unittest/main.py", line 154, in createTests
    self.test = loader.discover(self.start, self.pattern, self.top)
  File "/usr/lib/python3.7/unittest/loader.py", line 349, in discover
    tests = list(self._find_tests(start_dir, pattern))
  File "/usr/lib/python3.7/unittest/loader.py", line 406, in _find_tests
    full_path, pattern, namespace)
  File "/usr/lib/python3.7/unittest/loader.py", line 483, in _find_test_path
    tests = self.loadTestsFromModule(package, pattern=pattern)
  File "/usr/lib/python3.7/site-packages/setuptools/command/test.py", line 55, in loadTestsFromModule
    tests.append(self.loadTestsFromName(submodule))
  File "/usr/lib/python3.7/unittest/loader.py", line 214, in loadTestsFromName
    raise TypeError("don't know how to make test from: %s" % obj)
TypeError: not all arguments converted during string formatting

Include bitmap image as base64 encoded

Hello,

I would like to include an image in a SVG file as base64 encoded.

I should get something like

  <image
     width="231"
     height="443"
     preserveAspectRatio="none"
     xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOcAAAG7CAIAAAC3rRVPAAAAAXNSR0IArs4c6QAAQABJREFUeAHs 3XegdUV1NvAopPfmZyHyvoCCIk0DSH+pCgICAUMXwQgooKKIIhISFAtFBTGAElBAUESCICpNQFEj Cmo0SiSQotFU03vC9zv3IcP2tHvuOfu0++75Y9/ZM2vWrPXMM2tml7PvYx5++OEfatLqisD//u// PmYhBYD/+Z//USL96I/+6CxD8thZNq6xrUGgKwJrdi1tClcTBMTZqqdOH/vYOQhkj2l2CNVhW53z VSa0sXnWYGli7ayNyBTsKXydcbIWaJpYW6BoMnODwBxsYuYGy8bQSSHQsHZSSDf91IdAw9r6sGw0 TQqBhrWTQrrppz4EGtbWh2WjaVIINKydFNJNP/Uh0LC2PiwbTZNCoGHtpJBu+qkPgYa19WHZaJoU Ag1rJ4V00099CDSsrQ/LR
...
Jzs9eJNkKYCZtkMys0baZnonOz14l2D2EmbCKE Lf1ocrdktokmAv8D6M4XLBxaA6kAAAAASUVORK5CYII= "
     id="image4832"
     x="0"
     y="0" />

Is there an easy way to do it with svgwrite?

Kind regards

animateColor will removed from SVG2 and animateColor doesn't run in many browsers

animateColor without a future - see: https://www.w3.org/2014/01/16-svg-minutes.html#item01

so i think it should be replaced by a common "<animate ... />" element.

In gecko browsers the following code don't work:
<text id="text" x="150" y="30"> here some text <animateColor attributeName="fill" attributeType="XML" id="text" repeatCount="indefinite" dur="20s" from="green" to="red"/> </text>

But this runs:
<text id="text" x="150" y="30"> here some text <animate id="text" attributeName="fill" attributeType="XML" begin="0;graphics.click" dur="20s" values="gray;darkred;red;cyan;lightcyan;green;purple;gray" calcMode="linear" /> </text>

Load svg data

It would be a nice option to import/load an SVG file (if you want to modify an existing file).

svgwrite does not accept `values' for `fill'/`stroke' in `animate'

The following code

animate.Animate('fill', dur = '1.7s', begin = '2s', fill = 'freeze',
  values = '#000000;#0000ff;#00ff00;#ff0000',
  keyTimes = '0;0.2;0.4;1')

does not pass svgwrite's type check. After removing the type check, the svg file generated works as expected in Chrome and Firefox.

allow white spaces in attributes

I am trying to add multiple classes to my elements, to style via CSS, but get an error when doing so. It seems you cannot have white spaces in the attributes. Example:

mycircle['class'] = "class1 class2"

This throws an error. The workaround is to use groups, but a) that's harder and b) this still limits styling flexibility. So, I suggest allowing spaces.

Text centered vertically and horizontally

Hello,

I'm using svgwrite to draw ruler as SVG file (similar to this PDF ruler)

Unfortunatelly I'm facing a problem to center text (both horizontally and vertically).

I'd like to have text centered precisely on a point but I can't find a method to do this.

Ideally I would like to also add (temporarily) border around that text to be sure text is correctly placed.

My input data are:

  • insert point coordinates (ie x, y) and
  • cell size (w, h).

I have found this StackOverflow post https://stackoverflow.com/questions/5546346/how-to-place-and-center-text-in-an-svg-rectangle

According SO answer I need to add rect and text elements inside a svg element (which is also include in my svg document).

Some help will be great.

Kind regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.