#!/usr/bin/env python3 """Generate matching Mermaid and accessible SVG diagrams without network tools.""" from html import escape from pathlib import Path ROOT = Path(__file__).resolve().parent # Coordinates affect SVG layout only. Nodes and connections also generate Mermaid. DIAGRAMS = { "responsibilities": { "title": "VDD·Privacy의 구성요소와 책임", "description": "같은 Windows EXE가 사용자 앱, 호스팅, 화면 관리와 복구를 맡는다. Ubuntu는 연결 관리와 빌드를 맡는다.", "size": (1080, 670), "nodes": [ ("console", 360, 30, 350, 68, ["Ubuntu 연결 관리 서버", "등록·접속 관리·앱 게시"], "neutral"), ("client", 30, 155, 290, 78, ["접속하는 Windows PC", "동일 notparsec.exe · 영상·입력"], "neutral"), ("host", 410, 155, 390, 78, ["원격 Windows 호스트 · 동일 EXE", "설정·인증·캡처·인코딩"], "normal"), ("session", 410, 300, 390, 78, ["화면 관리 프로세스", "가상 출력 소유·Privacy 전환"], "normal"), ("recovery", 30, 430, 300, 94, ["서비스 소유 독립 화면 복구", "host Job 종료 뒤 생존·정리 확인", "실제 Privacy 차단 후 복원은 미검증"], "pending"), ("driver", 410, 430, 390, 94, ["notParsec VDD · UMDF / IddCx", "IOCTL · 모니터 생성·제거", "Microsoft 샘플 DLL과 구분"], "normal"), ("windows", 410, 585, 390, 60, ["Windows · PnP / CCD / DXGI"], "neutral"), ], "edges": [ ("console", "host", "등록·접속", [(605, 98), (605, 155)], (660, 130)), ("client", "host", "인증된 연결", [(320, 194), (410, 194)], (365, 177)), ("host", "session", "화면 요청", [(605, 233), (605, 300)], (658, 270)), ("session", "driver", "호환 ABI", [(605, 378), (605, 430)], (660, 409)), ("session", "recovery", "복구 준비·종료 감시", [(410, 338), (180, 338), (180, 430)], (250, 326)), ("recovery", "driver", "복제된 소유 핸들", [(330, 477), (410, 477)], (370, 556)), ("driver", "windows", "출력 등록·프레임 처리", [(605, 524), (605, 585)], (735, 558)), ], }, "display-decision": { "title": "가상 화면 필요 여부와 준비 상태 판단", "description": "화면 조회 오류, 명시적 가상 화면 요청, 실제 화면 없는 fallback을 서로 구분한다.", "size": (1100, 745), "nodes": [ ("query", 360, 25, 350, 64, ["입력 데스크톱 연결 → CCD 조회"], "normal"), ("error", 20, 135, 290, 74, ["조회 오류 보존", "모니터 0개로 바꾸지 않음"], "failure"), ("request", 360, 135, 350, 74, ["Privacy 또는 Virtual Displays > 0?"], "normal"), ("virtual", 785, 260, 290, 84, ["가상 화면 수 결정", "명시 요청: max(설정값, 1)", "화면 없음 + fallback: 1"], "normal"), ("physical", 360, 260, 350, 84, ["CCD 활성 target가 존재하는가?"], "normal"), ("existing", 20, 390, 290, 74, ["기존 활성 화면 사용", "Fallback On만으로 VDD 요구 안 함"], "success"), ("fallback", 360, 390, 350, 74, ["Fallback To Virtual Display On?"], "normal"), ("nooutput", 360, 550, 350, 74, ["활성 화면 없음 오류"], "failure"), ("ready", 785, 440, 290, 90, ["장치·인터페이스·ABI·용량 확인", "호환 응답과 유휴 상태 확보"], "normal"), ("create", 785, 630, 290, 80, ["가상 출력 생성·캡처 확인", "Privacy는 추가 복구 조건 필요"], "pending"), ], "edges": [ ("query", "error", "조회 실패", [(360, 57), (165, 57), (165, 135)], (257, 47)), ("query", "request", "조회 성공", [(535, 89), (535, 135)], (592, 115)), ("request", "virtual", "예", [(710, 172), (930, 172), (930, 260)], (811, 158)), ("request", "physical", "아니오", [(535, 209), (535, 260)], (590, 237)), ("physical", "existing", "있음", [(360, 302), (165, 302), (165, 390)], (271, 290)), ("physical", "fallback", "0개", [(535, 344), (535, 390)], (574, 371)), ("fallback", "virtual", "예", [(710, 427), (749, 427), (749, 302), (785, 302)], (745, 356)), ("fallback", "nooutput", "아니오", [(535, 464), (535, 550)], (590, 513)), ("virtual", "ready", "자체 VDD만 검사", [(930, 344), (930, 440)], (992, 400)), ("ready", "create", "Ready일 때만 진행", [(930, 530), (930, 630)], (994, 586)), ], }, "privacy-lifetime": { "title": "Privacy 시작·종료·실패 복구의 요구 순서", "description": "복구 준비와 실제 가상 화면 캡처를 확인한 뒤 물리 출력을 끈다. 종료에는 잠금 확인, 배치 복원, 가상 화면 제거가 필요하다.", "size": (1100, 795), "nodes": [ ("request", 50, 35, 420, 60, ["Privacy 요청 · 변경 전 배치 보관"], "normal"), ("guard", 50, 155, 420, 76, ["서비스의 독립 복구 준비 확인", "007: host Job 종료 뒤 생존·정리 통과"], "normal"), ("capture", 50, 300, 420, 78, ["자체 가상 출력에서 캡처·인코딩 확인"], "normal"), ("active", 50, 455, 420, 80, ["물리 출력 비활성화·상태 확인", "Privacy 영상 실행 · 실제 GPU 시험 필요"], "pending"), ("rollback", 620, 155, 420, 76, ["시작 실패 · 실패 단계 기록", "물리 배치 유지 또는 변경분 복원"], "failure"), ("lock", 620, 360, 420, 80, ["정상 종료·연결 단절·제어 프로세스 충돌", "복구 주체가 Windows 잠금 완료 확인"], "normal"), ("restore", 620, 545, 420, 78, ["변경 전 물리 배치 복원", "실패하면 복구 상태 유지·재시도"], "normal"), ("release", 620, 700, 420, 64, ["가상 화면 제거 → 복구 감시 해제"], "success"), ], "edges": [ ("request", "guard", "", [(260, 95), (260, 155)], None), ("guard", "capture", "준비 성공", [(260, 231), (260, 300)], (319, 269)), ("guard", "rollback", "준비 실패", [(470, 193), (620, 193)], (545, 177)), ("capture", "rollback", "캡처 실패", [(470, 338), (545, 338), (545, 211), (620, 211)], (546, 284)), ("capture", "active", "유효 프레임 확인", [(260, 378), (260, 455)], (338, 419)), ("active", "lock", "종료 또는 장애", [(470, 495), (545, 495), (545, 400), (620, 400)], (547, 466)), ("lock", "restore", "실제 잠금 확인", [(830, 440), (830, 545)], (902, 497)), ("restore", "release", "복원 확인", [(830, 623), (830, 700)], (889, 663)), ], }, } COLORS = { "normal": ("#eef4ff", "#2f5fa2"), "neutral": ("#f4f5f7", "#536172"), "success": ("#e9f7ef", "#27704a"), "failure": ("#fff0ef", "#ad463d"), "pending": ("#fff7df", "#94701c"), } def render(name, diagram): width, height = diagram["size"] svg = [f'', f'{escape(diagram["title"])}', f'{escape(diagram["description"])}', '', f'', ''] mermaid = ["%% Generated by render.py; edit the diagram definitions there.", "flowchart TD"] for identifier, x, y, w, h, lines, style in diagram["nodes"]: fill, stroke = COLORS[style] svg.append(f'') top = y + h / 2 - (len(lines) - 1) * 11 + 5 for i, line in enumerate(lines): svg.append(f'{escape(line)}') label = "
".join(lines) mermaid.append(f' {identifier}["{label}"]') for source, target, label, points, position in diagram["edges"]: path = "M " + " L ".join(f"{x} {y}" for x, y in points) svg.append(f'') if label: x, y = position svg.append(f'{escape(label)}') mermaid.append(f' {source} -->|"{label}"| {target}' if label else f' {source} --> {target}') svg.extend(["", ""]) (ROOT / f"{name}.svg").write_text("\n".join(svg) + "\n", encoding="utf-8") (ROOT / f"{name}.mmd").write_text("\n".join(mermaid) + "\n", encoding="utf-8") if __name__ == "__main__": for diagram_name, definition in DIAGRAMS.items(): render(diagram_name, definition)