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

Method calculate_size

barcode/writer.py:143–161  ·  view source on GitHub ↗

Calculates the size of the barcode in pixel. :param modules_per_line: Number of modules in one line. :param number_of_lines: Number of lines of the barcode. :returns: Width and height of the barcode in pixel.

(self, modules_per_line: int, number_of_lines: int)

Source from the content-addressed store, hash-verified

141 self.margin_bottom = 1
142
143 def calculate_size(self, modules_per_line: int, number_of_lines: int) -> tuple:
144 """Calculates the size of the barcode in pixel.
145
146 :param modules_per_line: Number of modules in one line.
147 :param number_of_lines: Number of lines of the barcode.
148
149 :returns: Width and height of the barcode in pixel.
150 """
151 width = 2 * self.quiet_zone + modules_per_line * self.module_width
152 height = (
153 self.margin_bottom + self.margin_top + self.module_height * number_of_lines
154 )
155 number_of_text_lines = len(self.text.splitlines())
156 if self.font_size and self.text:
157 height += (
158 pt2mm(self.font_size) / 2 * number_of_text_lines + self.text_distance
159 )
160 height += self.text_line_distance * (number_of_text_lines - 1)
161 return width, height
162
163 def save(self, filename: str, output) -> str:
164 """Saves the rendered output to `filename`.

Callers 2

_initMethod · 0.80
_initMethod · 0.80

Calls 1

pt2mmFunction · 0.85

Tested by

no test coverage detected