44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
|
|
"""
|
||
|
|
Datenmodell für ein geladenes Logo.
|
||
|
|
Hält sowohl das Originalbild als auch die extrahierten Vektorpfade.
|
||
|
|
"""
|
||
|
|
from __future__ import annotations
|
||
|
|
from dataclasses import dataclass, field
|
||
|
|
from pathlib import Path
|
||
|
|
from typing import Optional
|
||
|
|
|
||
|
|
import numpy as np
|
||
|
|
from svgpathtools import Path as SvgPath
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class GlyphGroup:
|
||
|
|
"""Ein erkannter Buchstabe / eine zusammenhängende Pfadgruppe."""
|
||
|
|
label: str
|
||
|
|
paths: list[SvgPath] = field(default_factory=list)
|
||
|
|
bbox: tuple[float, float, float, float] = (0, 0, 0, 0) # x, y, w, h
|
||
|
|
offset_x: float = 0.0
|
||
|
|
offset_y: float = 0.0
|
||
|
|
stroke_width_factor: float = 1.0
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class LogoProject:
|
||
|
|
"""Gesamtes Logo-Projekt mit allen Metadaten."""
|
||
|
|
source_path: Optional[Path] = None
|
||
|
|
original_pixels: Optional[np.ndarray] = None
|
||
|
|
width: int = 0
|
||
|
|
height: int = 0
|
||
|
|
glyphs: list[GlyphGroup] = field(default_factory=list)
|
||
|
|
global_letter_spacing: float = 0.0
|
||
|
|
global_stroke_width: float = 1.0
|
||
|
|
zoom: float = 1.0
|
||
|
|
|
||
|
|
@property
|
||
|
|
def has_image(self) -> bool:
|
||
|
|
return self.original_pixels is not None
|
||
|
|
|
||
|
|
@property
|
||
|
|
def has_vectors(self) -> bool:
|
||
|
|
return len(self.glyphs) > 0
|