Skip to content

Commit ea30ac9

Browse files
author
Hugo Osvaldo Barrera
authored
Merge pull request #136 from timsat/main
[#135] Optimized SVG output by removing redundant geometry
2 parents c6ff5d2 + d70b80e commit ea30ac9

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

barcode/writer.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,18 @@ def _init(self, code):
328328
self._group.appendChild(background)
329329

330330
def _create_module(self, xpos, ypos, width, color):
331-
element = self._document.createElement("rect")
332-
attributes = {
333-
"x": SIZE.format(xpos),
334-
"y": SIZE.format(ypos),
335-
"width": SIZE.format(width),
336-
"height": SIZE.format(self.module_height),
337-
"style": f"fill:{color};",
338-
}
339-
_set_attributes(element, **attributes)
340-
self._group.appendChild(element)
331+
# Background rect has been provided already, so skipping "spaces"
332+
if color != self.background:
333+
element = self._document.createElement("rect")
334+
attributes = {
335+
"x": SIZE.format(xpos),
336+
"y": SIZE.format(ypos),
337+
"width": SIZE.format(width),
338+
"height": SIZE.format(self.module_height),
339+
"style": f"fill:{color};",
340+
}
341+
_set_attributes(element, **attributes)
342+
self._group.appendChild(element)
341343

342344
def _create_text(self, xpos, ypos):
343345
# check option to override self.text with self.human (barcode as

0 commit comments

Comments
 (0)