Biçe naverokê

Ev werger bi alîkariya AI hatiye amadekirin û divê axêverekî zikmakî lê binêre.

deq-shapes (Python)

Ev naverok hêj bi zimanê te tune.

The Deq shapes for Python.

A port of the @0xdolan/deq-core reference renderer that produces the same SVG byte for byte (ADR 0008), plus the core export formats and the deq command line tool.

from deq_shapes import render
svg = render("roj-half-sun", {"size": 48, "color": "#ED2024", "params": {"rays": 9}})

Source: python/deq-shapes. Install with pip install deq-shapes; every name below is importable from deq_shapes.

Functions

compose

def compose(parts: Sequence[Mapping[str, Any]], options: Mapping[str, Any] | None = None) -> str

Render several catalog shapes placed on one 24 x 24 canvas (params is ignored).

compose_shape

def compose_shape(parts: Sequence[Mapping[str, Any]]) -> Shape

The shape description of a composition: one use per part, each on its own layer.

decode_leet

def decode_leet(svg: str, options: Mapping[str, Any] | None = None) -> DecodedLeet

Read the text back from Leet SVG written by leet at the basic level.

options must be the render options used to write it. The SVG is treated as text and only matched against what leet writes.

Raises DeqError: INVALID_OPTIONS when the input is not Deq Leet SVG, or LIMIT_EXCEEDED (input over MAX_DECODE_INPUT, more than MAX_GLYPHS glyphs).

detect_script

def detect_script(text: str) -> Script

Sorani when text has Arabic-script letters, else Latin.

expand

def expand(shape_id: str, params: Mapping[str, Any] | None = None) -> list[g.Flat]

Expand the catalog shape shape_id into flat geometry.

expand_shape

def expand_shape(shape: Shape, params: Mapping[str, Any] | None = None) -> list[g.Flat]

Expand shape into flat geometry with the given parameter values.

flag_size

def flag_size(variant: FlagVariant, width: int) -> tuple[int, int]

The pixel size of the flag at width px for a variant.

get_shape

def get_shape(shape_id: str) -> Shape

The shape with this id; raises DeqError (UNKNOWN_SHAPE) with suggestions.

has_shape

def has_shape(shape_id: str) -> bool

leet

def leet(text: str, options: Mapping[str, Any] | None = None) -> LeetResult

Write text with Deq glyphs.

The input is plain text: length-capped, normalised and never parsed as markup. Characters without a glyph are left out and listed in unknown; Sorani runs right to left. Options are level, script, seed, letterSpacing, lineSpacing, align, colors and the render options except the per-shape ones.

Raises DeqError: INVALID_OPTIONS (also when nothing is left to draw) or LIMIT_EXCEEDED.

leet_table

def leet_table(script: Script) -> LeetTable

The table of script.

list_categories

def list_categories() -> list[str]

Category ids in catalog order.

list_flag_variants

def list_flag_variants() -> list[str]

Variant ids in spec order.

list_shapes

def list_shapes(category: str | None = None) -> list[Shape]

Every shape in catalog order, optionally only one category.

normalize

def normalize(text: str, script: Script) -> Normalized

Normalise text for script: NFC, LF, no joiners or tatweel, upper case, aliases.

Raises DeqError: LIMIT_EXCEEDED for input over MAX_INPUT, more than MAX_GLYPHS glyphs or more than MAX_LINES lines.

pattern

def pattern(options: Mapping[str, Any] | None = None) -> PatternResult

Generate a pattern of Deq motifs.

band repeats motifs in a row (alternating or mirrored), grid lays a checkerboard, rosette rings petals round a centre and border frames a rectangle. Options are kind, seed, motifs, count, cols, rows, petals, spacing, colors and the render options except the per-shape ones.

Raises DeqError: INVALID_OPTIONS, UNKNOWN_SHAPE or LIMIT_EXCEEDED.

prepare

def prepare(shape: Shape, options: Mapping[str, Any] | None = None) -> Prepared

Validate options for shape and expand its geometry.

render

def render(shape_id: str, options: Mapping[str, Any] | None = None) -> str

Render the catalog shape shape_id as a standalone SVG string.

svg = render("roj-half-sun", {"size": 48, "color": "#ED2024", "params": {"rays": 9}})

render_flag

def render_flag(options: Mapping[str, Any] | None = None) -> str

Render the Kurdish flag as a standalone SVG string.

Options: variant (default full-color), width in px (default 900) and title (default “Flag of Kurdistan”; "" marks the image decorative).

render_shape_data

def render_shape_data(shape: Shape, options: Mapping[str, Any] | None = None) -> str

Render a shape description (already validated) to an SVG string.

resolve_options

def resolve_options(options: Mapping[str, Any] | None = None) -> ResolvedOptions

Validate options and fill in defaults. Raises DeqError (INVALID_OPTIONS).

resolve_params

def resolve_params(shape: Shape, overrides: Mapping[str, Any] | None = None) -> dict[str, Any]

Parameter defaults merged with overrides, type- and range-checked.

scene_svg

def scene_svg(scene: Scene, options: Mapping[str, Any] | None = None, title: str = '', root_attrs: str = '') -> str

Write scene as SVG, one <g data-layer="cN" transform="translate(x y)"> per cell.

suggest

def suggest(shape_id: str) -> list[str]

Up to 3 known ids close to shape_id (also matching aliases and substrings).

svg_document

def svg_document(p: Prepared, hooks: SvgHooks | None = None) -> str

The SVG document for prepared geometry; with no hooks exactly what render gives.

svg_root

def svg_root(o: ResolvedOptions, default_title: str, hooks: SvgHooks | None = None, width: float = CANVAS, height: float = CANVAS) -> str

The root <svg> with title and background for a width x height canvas.

Classes

Cell

class Cell

One glyph placed in a scene; its 24 x 24 cell has its top left at (x, y).

  • x: float
  • y: float
  • glyph: Glyph

DecodedLeet

class DecodedLeet

The result of decode_leet.

  • text: str: The text; glyphs that are not basic glyphs read as U+FFFD.
  • script: Script
  • unmatched: int: How many glyph groups were not basic glyphs of the table.

DeqError

class DeqError(Exception)

Why an operation failed. code is stable; the message is for people.

LeetResult

class LeetResult

The result of leet.

  • svg: str: The SVG document, one <g data-layer="cN"> per glyph in reading order.
  • text: str: The normalised text that was drawn.
  • script: Script
  • level: LeetLevel
  • unknown: tuple[str, ...]: Input characters with no glyph, in first-seen order (they are left out).
  • scene: Scene

PatternResult

class PatternResult

The result of pattern.

  • svg: str: The SVG document, one <g data-layer="cN"> per motif.
  • motifs: tuple[str, ...]: The motifs chosen, in the order the pattern uses them.
  • scene: Scene

Prepared

class Prepared

A shape ready to draw: resolved options and flat geometry in canvas units.

  • options: ResolvedOptions
  • items: tuple[g.Flat, ...]
  • layers: tuple[str, ...]: The layer ids of the shape, in declaration order.
  • default_title: str: The title used when options.title is not set (the English name).

Random

class Random

A deterministic stream of unsigned 32-bit integers.

  • next() -> int: The next unsigned 32-bit integer.
  • below(n: int) -> int: An integer in 0 .. n - 1 (n >= 1).
  • pick(items: Sequence[_T]) -> _T: One element of a non-empty sequence.

ResolvedOptions

class ResolvedOptions

Options after validation, with every default filled in.

  • size: float = 24
  • color: str = 'currentColor'
  • stroke_width: float = 2
  • absolute_stroke_width: bool = False
  • fill: str = 'none'
  • fill_opacity: float = 1
  • stroke_opacity: float = 1
  • linecap: Literal['round', 'butt', 'square'] = 'round'
  • linejoin: Literal['round', 'miter', 'bevel'] = 'round'
  • dot_scale: float = 1
  • rotation: float = 0
  • flip_x: bool = False
  • flip_y: bool = False
  • padding: float = 0
  • background: str = 'none'
  • layer_colors: Mapping[str, str] = field(default_factory=dict)
  • title: str | None = None
  • aria_label: str | None = None
  • params: Mapping[str, Any] = field(default_factory=dict)

Scene

class Scene

Glyphs on a width x height canvas in grid units.

  • width: float
  • height: float
  • cells: tuple[Cell, ...]

SvgHooks

class SvgHooks

Hooks for svg_document, used by exporters that need named layer groups.

  • root_attrs: str = '': Extra attributes on the root <svg>, starting with a space.
  • layer_attrs: Callable[[str], str] | None = None: Extra attributes for the group of a layer, starting with a space. When given, every layer gets its own group and the rotation/flip transform moves onto each group.

Constants

CANVAS

CANVAS = 24

Canvas size in grid units.

DEFAULT_OPTIONS

DEFAULT_OPTIONS = ResolvedOptions()

The documented default of every option.

DISTRIBUTION_NAME

DISTRIBUTION_NAME: Final = 'deq-shapes'

MAX_DEPTH

MAX_DEPTH = 6

Deepest nesting of generators and references.

MAX_FLAT

MAX_FLAT = 2000

Most flat items one render may produce.

__version__

__version__: Final = '1.0.0'

Types

DeqErrorCode

DeqErrorCode = Literal['UNKNOWN_SHAPE', 'INVALID_OPTIONS', 'INVALID_PARAMETER', 'INVALID_SHAPE', 'LIMIT_EXCEEDED']