Skip to content

Commit 3c4ff78

Browse files
authored
Add option to disable the SVG doctype
If you use the SVG as an inline object inside of a HTML document the extra doctype can lead to issues in rendering to prevent this there is no an extra option for the SVGWriter to disable the doctype. reference: https://stackoverflow.com/a/38172170/548558 Fixes #60
1 parent 0328810 commit 3c4ff78

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

barcode/writer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ def _set_attributes(element, **attributes):
3131
element.setAttribute(key, value)
3232

3333

34-
def create_svg_object():
34+
def create_svg_object(with_doctype):
3535
imp = xml.dom.getDOMImplementation()
3636
doctype = imp.createDocumentType(
3737
'svg', '-//W3C//DTD SVG 1.1//EN',
3838
'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'
3939
)
40-
document = imp.createDocument(None, 'svg', doctype)
40+
document = imp.createDocument(None, 'svg', doctype if with_doctype else None)
4141
_set_attributes(
4242
document.documentElement,
4343
version='1.1',
@@ -235,13 +235,14 @@ def __init__(self):
235235
)
236236
self.compress = False
237237
self.dpi = 25.4
238+
self.with_doctype = True
238239
self._document = None
239240
self._root = None
240241
self._group = None
241242

242243
def _init(self, code):
243244
width, height = self.calculate_size(len(code[0]), len(code), self.dpi)
244-
self._document = create_svg_object()
245+
self._document = create_svg_object(self.with_doctype)
245246
self._root = self._document.documentElement
246247
attributes = {
247248
'width': SIZE.format(width),

0 commit comments

Comments
 (0)