Shared types¶
Shared typing helpers for pyStrich encoders and renderers.
- class BarcodeRenderOptions[source]¶
Bases:
TypedDictOptional render-time tweaks for label-bearing 1D barcodes.
Currently used by
pystrich.code128.Code128Encoderandpystrich.code39.Code39Encoder. All keys are optional; omitted keys fall back to library defaults.- show_label: bool¶
Whether to render the human-readable label underneath the bars. Defaults to
True; set toFalseto suppress it.
- ttf_font: str¶
Absolute path to a TrueType font file used for the label in PNG output. Defaults to a bundled bitmap font if unset. SVG and EPS output always render the label using the bundled Courier Prime glyph paths and ignore this option.
- ttf_fontsize: int¶
Font size in points (PNG output only — SVG/EPS use the bundled Courier Prime glyph paths).
Matrix mark extraction shared by vector renderers (SVG, EPS, DXF).
- class MatrixMark(x: int, y: int, width: int, height: int)[source]¶
Bases:
NamedTupleA rectangular region of a matrix to be drawn as a single shape.
- class MarkShape(*values)[source]¶
Bases:
EnumHow marked cells are grouped and drawn in vector output.
Each value selects a grouping (one
MatrixMarkper cell, or one per horizontal run) and – where the renderer supports it – the drawing primitive used per mark.- HORIZONTAL_RUNS = 1¶
Maximal horizontal runs of matched cells, drawn as filled rectangles.
- SQUARE_CELLS = 2¶
One 1x1 region per matched cell, drawn as a filled rectangle.
- CIRCULAR_CELLS = 3¶
One 1x1 region per matched cell, drawn as a filled circle inscribed in the cell.
- iter_horizontal_runs(matrix: Sequence[Sequence[int | None]], *, mark_values_when: bool) Iterator[MatrixMark][source]¶
Yield each maximal horizontal run of cells whose truthiness equals
mark_values_when.mark_values_when=Truemarks the dark (truthy) cells;Falsemarks the light cells (0orNone). Each yielded mark hasheight=1.
- iter_cells(matrix: Sequence[Sequence[int | None]], *, mark_values_when: bool) Iterator[MatrixMark][source]¶
Yield a 1x1 mark for every cell whose truthiness equals
mark_values_when.
- iter_marks(matrix: Sequence[Sequence[int | None]], *, mark_values_when: bool, mark_shape: MarkShape) Iterator[MatrixMark][source]¶
Yield
MatrixMarkregions for the chosenmark_shape.
- class TextLabel(text: str, x: float, y: float, font_size: int, anchor: str = 'start')[source]¶
Bases:
NamedTupleA run of text to render below the bars in vector output.
Coordinates are in pixels (= user units for SVG/EPS at default DPI), and
yis the top edge of the text — matching the convention used byPIL.ImageDraw.text(xy, ...)for the corresponding raster path.anchorcontrols howxrelates to the text run:"start"is the left edge,"middle"the centre,"end"the right edge.
- class BarLayout(heights: Sequence[int], bar_width: int, quiet_left: int = 0, quiet_right: int = 0, quiet_top: int = 0, quiet_bottom: int = 0, labels: Sequence[TextLabel] = ())[source]¶
Bases:
NamedTuplePixel-precise layout of a 1D barcode for any output format.
All values are in pixels (= user units for SVG/EPS at default DPI).
heights[i]is the bar’s pixel height at columni(0is a gap). Each column isbar_widthpixels wide. The four quiet zones frame the symbol;quiet_leftandquiet_topshift the bars, whilequiet_rightandquiet_bottomonly enlarge the canvas.labelscarries the human-readable text drawn beneath the bars by SVG/EPS renderers; the PNG path renders text via PIL directly and ignores this field.
- iter_bar_marks(heights: Sequence[int], bar_width: int, *, quiet_left: int = 0, quiet_top: int = 0) Iterator[MatrixMark][source]¶
Yield a
MatrixMarkper maximal run of equal positive heights.Coordinates and dimensions are in pixels.
heights[i]is the bar’s pixel height at columni(0is a gap; positive values are bars sharing a top edge aty = quiet_top). Each column isbar_widthpixels wide. Adjacent columns with the same positive height collapse into one mark.Only
quiet_leftandquiet_topare accepted because they are the only offsets that affect mark coordinates; the right and bottom quiet zones are a renderer concern (canvas / viewBox sizing).