auto: 2026-08-31 14:38 (ESD_LAPTOP)
This commit is contained in:
@@ -11,6 +11,7 @@ A1 템플릿 기하(변환 시점 고정값): 전체 840x594, 하단 y17~47 표
|
||||
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
@@ -137,11 +138,28 @@ def usable_area() -> tuple[float, float]:
|
||||
)
|
||||
|
||||
|
||||
_PLACEHOLDER = re.compile(r"\{\{\s*([^}]+?)\s*\}\}")
|
||||
|
||||
|
||||
def _fill_placeholders(entities: list[dict[str, Any]], fields: dict[str, str]) -> None:
|
||||
"""도각 텍스트의 {{키}}를 값으로 바꾼다. 값이 없으면 빈칸 — 남의 값이 남지 않는다."""
|
||||
for entity in entities:
|
||||
if entity.get("type") != "Text":
|
||||
continue
|
||||
shape = entity.get("shapeData") or {}
|
||||
label = shape.get("label")
|
||||
if isinstance(label, str) and "{{" in label:
|
||||
shape["label"] = _PLACEHOLDER.sub(
|
||||
lambda match: str(fields.get(match.group(1), "")), label
|
||||
)
|
||||
|
||||
|
||||
def frame_entities(
|
||||
drawing_id: str,
|
||||
content_bbox: tuple[float, float, float, float],
|
||||
template_name: str = A1_TEMPLATE,
|
||||
fit: bool = True,
|
||||
fields: dict[str, str] | None = None,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""콘텐츠 bbox를 감싸는 도각 프레임 엔티티 목록(잠금 레이어). 템플릿 없으면 빈 목록.
|
||||
|
||||
@@ -173,7 +191,9 @@ def frame_entities(
|
||||
dx = (min_x + max_x) / 2.0 - (ix0 + ix1) / 2.0 * scale
|
||||
dy = (min_y + max_y) / 2.0 - (iy0 + iy1) / 2.0 * scale
|
||||
|
||||
return [
|
||||
placed = [
|
||||
_transform_entity(entity, f"{drawing_id}:frame:{index}", scale, dx, dy)
|
||||
for index, entity in enumerate(template.get("entities", []))
|
||||
]
|
||||
_fill_placeholders(placed, fields or {})
|
||||
return placed
|
||||
|
||||
Reference in New Issue
Block a user