steenzout.barcode.writer module¶
-
class
Base
(initialize=None, paint_module=None, paint_text=None, finish=None)[source]¶ Bases:
steenzout.object.Object
,steenzout.barcode.writer.Interface
Base class for all writers.
Initializes the basic writer options. Sub-classes can add more attributes and can set them directly or using self.set_options(option=value).
Parameters: - initialize (function) – Callback for initializing the inheriting writer. Is called: callback_initialize(raw_code)
- paint_module (function) – Callback for painting one barcode module. Is called: callback_paint_module(xpos, ypos, width, color)
- paint_text (function) – Callback for painting the text under the barcode. Is called: callback_paint_text(xpos, ypos) using self.text as text.
- finish (function) – Callback for doing something with the completely rendered output. Is called: return callback_finish() and must return the rendered output.
-
calculate_size
(modules_per_line, number_of_lines, dpi=300)[source]¶ Calculates the size of the barcode in pixel.
Parameters: - modules_per_line (int) – number of modules in one line.
- number_of_lines (int) – number of lines of the barcode.
- dpi (int) – DPI to calculate.
Returns: Width and height of the barcode in pixel.
Return type: (tuple[int, int])
-
register_callback
(action, callback)[source]¶ Register one of the three callbacks if not given at instance creation.
Parameters: - action (str) – One of ‘initialize’, ‘paint_module’, ‘paint_text’, ‘finish’.
- callback (function) – The callback function for the given action.
-
render
(code)[source]¶ Renders the barcode to whatever the inheriting writer provides, using the registered callbacks.
Parameters: code (list[str]) – list of strings matching the writer spec (only contain 0 or 1).
-
save
(filename, output)[source]¶ See
Interface.save()
.
-
class
ImageWriter
[source]¶ Bases:
steenzout.barcode.writer.Base
-
save
(filename, output)[source]¶ See
Interface.save()
.
-
-
class
SVG
[source]¶ Bases:
steenzout.barcode.writer.Base
-
save
(filename, content)[source]¶ See
Interface.save()
.
-
-
create_svg_object
()[source]¶ Returns a blank SVG document.
Returns: XML document. Return type: ( xml.dom.minidom.DocumentType
)