MCPcopy Index your code
hub / github.com/WhyNotHugo/python-barcode / _init

Method _init

barcode/writer.py:324–352  ·  view source on GitHub ↗
(self, code: list[str])

Source from the content-addressed store, hash-verified

322 self._group: xml.dom.minidom.Element
323
324 def _init(self, code: list[str]):
325 if len(code) != 1:
326 raise NotImplementedError("Only one line of code is supported")
327 line = code[0]
328 width, height = self.calculate_size(len(line), 1)
329 self._document = create_svg_object(self.with_doctype)
330 self._root = self._document.documentElement
331 attributes = {
332 "width": SIZE.format(width),
333 "height": SIZE.format(height),
334 }
335 _set_attributes(self._root, **attributes)
336 if COMMENT:
337 self._root.appendChild(self._document.createComment(COMMENT))
338 # create group for easier handling in 3rd party software
339 # like corel draw, inkscape, ...
340 group = self._document.createElement("g")
341 attributes = {"id": "barcode_group"}
342 _set_attributes(group, **attributes)
343 self._group = self._root.appendChild(group)
344 if self.background is not None:
345 background = self._document.createElement("rect")
346 attributes = {
347 "width": "100%",
348 "height": "100%",
349 "style": f"fill:{self.background}",
350 }
351 _set_attributes(background, **attributes)
352 self._group.appendChild(background)
353
354 def _create_module(self, xpos, ypos, width, color):
355 # Background rect has been provided already, so skipping "spaces"

Callers

nothing calls this directly

Calls 3

create_svg_objectFunction · 0.85
_set_attributesFunction · 0.85
calculate_sizeMethod · 0.80

Tested by

no test coverage detected