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

Method render

barcode/writer.py:221–304  ·  view source on GitHub ↗

Renders the barcode to whatever the inheriting writer provides, using the registered callbacks. :parameters: code : List List consisting of a single string matching the writer spec (only contain 0 or 1 or G).

(self, code: list[str])

Source from the content-addressed store, hash-verified

219 c = 1
220
221 def render(self, code: list[str]):
222 """Renders the barcode to whatever the inheriting writer provides,
223 using the registered callbacks.
224
225 :parameters:
226 code : List
227 List consisting of a single string matching the writer spec
228 (only contain 0 or 1 or G).
229 """
230 if self._callbacks["initialize"] is not None:
231 self._callbacks["initialize"](code)
232 ypos = self.margin_top
233 base_height = self.module_height
234 if len(code) != 1:
235 raise NotImplementedError("Only one line of code is supported")
236 line = code[0]
237 # Left quiet zone is x startposition
238 xpos = self.quiet_zone
239 bxs = xpos # x start of barcode
240 text: InternalText = {
241 "start": [], # The x start of a guard
242 "end": [], # The x end of a guard
243 "xpos": [], # The x position where to write a text block
244 # Flag that indicates if the previous mod was part of an guard block:
245 "was_guard": False,
246 }
247 for mod, height_factor in self.packed(line):
248 if mod < 1:
249 color = self.background
250 else:
251 color = self.foreground
252
253 if text["was_guard"] and height_factor == 1:
254 # The current guard ended, store its x position
255 text["end"].append(xpos)
256 text["was_guard"] = False
257 elif not text["was_guard"] and height_factor != 1:
258 # A guard started, store its x position
259 text["start"].append(xpos)
260 text["was_guard"] = True
261
262 self.module_height = base_height * height_factor
263 # remove painting for background colored tiles?
264 self._callbacks["paint_module"](
265 xpos, ypos, self.module_width * abs(mod), color
266 )
267 xpos += self.module_width * abs(mod)
268 else:
269 if height_factor != 1:
270 text["end"].append(xpos)
271 self.module_height = base_height
272
273 bxe = xpos
274 ypos += self.module_height
275
276 if self.text and self._callbacks["paint_text"] is not None:
277 if not text["start"]:
278 # If we don't have any start value, print the entire ean

Callers

nothing calls this directly

Calls 2

packedMethod · 0.95
pt2mmFunction · 0.85

Tested by

no test coverage detected