- Frame_Export: Table 갈래 table_parts(경계선 · 글 자리) · 정렬 MIDDLE_LEFT · CENTER · RIGHT · 높이 = 칸 → 표 글자 크기 · 전에는 Table 이 조용히 빠짐 - 짝 = openwebcad table-geometry.ts(두 파일 머리) · 거울 시험 test_b07_frame_export_table.py + helper_b07_table_geometry.cjs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UoSr2sqvYtBf1dtQdus88s
42 lines
1.6 KiB
JavaScript
42 lines
1.6 KiB
JavaScript
/* 표 기하(`openwebcad/src/helpers/table-geometry.ts`) 거울 헬퍼 — 서버 DXF `table_parts` 와 대조.
|
|
* stdin JSON [표 shapeData] → stdout JSON [{lines, texts}] (TS 규칙 그대로). */
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript"));
|
|
|
|
const file = path.join(
|
|
__dirname,
|
|
"..",
|
|
"..",
|
|
"B07_DesignDetail",
|
|
"openwebcad",
|
|
"src",
|
|
"helpers",
|
|
"table-geometry.ts",
|
|
);
|
|
const js = ts.transpileModule(fs.readFileSync(file, "utf8"), {
|
|
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 },
|
|
}).outputText;
|
|
const box = { exports: {} };
|
|
new Function("exports", "module", "require", js)(box.exports, box, require);
|
|
const g = box.exports;
|
|
|
|
const shapes = JSON.parse(fs.readFileSync(0, "utf8"));
|
|
const out = shapes.map((s) => {
|
|
const lines = g
|
|
.tableBorders(s.origin, s.columnWidths, s.rowHeights, s.cells)
|
|
.map((b) => [b.x1, b.y1, b.x2, b.y2]);
|
|
const padding = s.style?.padding ?? 1;
|
|
const texts = [];
|
|
for (let row = 0; row < s.rowHeights.length; row += 1)
|
|
for (let column = 0; column < s.columnWidths.length; column += 1) {
|
|
const cell = s.cells[row]?.[column];
|
|
if (!cell?.text) continue;
|
|
const rect = g.cellRect(s.origin, s.columnWidths, s.rowHeights, row, column, cell);
|
|
const at = g.cellTextAnchor(rect, cell.align, padding);
|
|
texts.push({ text: cell.text, x: at.x, y: at.y, align: cell.align ?? "center" });
|
|
}
|
|
return { lines, texts };
|
|
});
|
|
process.stdout.write(JSON.stringify(out));
|