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 rendersvg = 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) -> strRender several catalog shapes placed on one 24 x 24 canvas (params is ignored).
compose_shape
def compose_shape(parts: Sequence[Mapping[str, Any]]) -> ShapeThe 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) -> DecodedLeetRead 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) -> ScriptSorani 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) -> ShapeThe shape with this id; raises DeqError (UNKNOWN_SHAPE) with suggestions.
has_shape
def has_shape(shape_id: str) -> boolleet
def leet(text: str, options: Mapping[str, Any] | None = None) -> LeetResultWrite 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) -> LeetTableThe 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) -> NormalizedNormalise 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) -> PatternResultGenerate 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) -> PreparedValidate options for shape and expand its geometry.
render
def render(shape_id: str, options: Mapping[str, Any] | None = None) -> strRender 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) -> strRender 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) -> strRender a shape description (already validated) to an SVG string.
resolve_options
def resolve_options(options: Mapping[str, Any] | None = None) -> ResolvedOptionsValidate 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 = '') -> strWrite 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) -> strThe 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) -> strThe root <svg> with title and background for a width x height canvas.
Classes
Cell
class CellOne glyph placed in a scene; its 24 x 24 cell has its top left at (x, y).
x: floaty: floatglyph: Glyph
DecodedLeet
class DecodedLeetThe result of decode_leet.
text: str: The text; glyphs that are not basic glyphs read as U+FFFD.script: Scriptunmatched: 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 LeetResultThe 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: Scriptlevel: LeetLevelunknown: tuple[str, ...]: Input characters with no glyph, in first-seen order (they are left out).scene: Scene
PatternResult
class PatternResultThe 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 PreparedA shape ready to draw: resolved options and flat geometry in canvas units.
options: ResolvedOptionsitems: tuple[g.Flat, ...]layers: tuple[str, ...]: The layer ids of the shape, in declaration order.default_title: str: The title used whenoptions.titleis not set (the English name).
Random
class RandomA deterministic stream of unsigned 32-bit integers.
next() -> int: The next unsigned 32-bit integer.below(n: int) -> int: An integer in0 .. n - 1(n>= 1).pick(items: Sequence[_T]) -> _T: One element of a non-empty sequence.
ResolvedOptions
class ResolvedOptionsOptions after validation, with every default filled in.
size: float = 24color: str = 'currentColor'stroke_width: float = 2absolute_stroke_width: bool = Falsefill: str = 'none'fill_opacity: float = 1stroke_opacity: float = 1linecap: Literal['round', 'butt', 'square'] = 'round'linejoin: Literal['round', 'miter', 'bevel'] = 'round'dot_scale: float = 1rotation: float = 0flip_x: bool = Falseflip_y: bool = Falsepadding: float = 0background: str = 'none'layer_colors: Mapping[str, str] = field(default_factory=dict)title: str | None = Nonearia_label: str | None = Noneparams: Mapping[str, Any] = field(default_factory=dict)
Scene
class SceneGlyphs on a width x height canvas in grid units.
width: floatheight: floatcells: tuple[Cell, ...]
SvgHooks
class SvgHooksHooks 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 = 24Canvas 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 = 6Deepest nesting of generators and references.
MAX_FLAT
MAX_FLAT = 2000Most 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']Guhertoyeke nû ya vê malperê heye.