@linkiez/dxf-renew 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +17 -0
- package/.eslintrc.json +61 -0
- package/.gitattributes +4 -0
- package/.github/instructions/project-en_US.instructions.md +352 -0
- package/.github/workflows/release.yml +110 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +1 -0
- package/.prettierignore +1 -0
- package/.prettierrc.json +6 -0
- package/.releaserc.json +76 -0
- package/.travis.yml +6 -0
- package/.yarn/install-state.gz +0 -0
- package/.yarnrc.yml +1 -0
- package/CHANGELOG.md +134 -0
- package/CONTRIBUTING.md +271 -0
- package/LICENSE +21 -0
- package/PLAN.md +517 -0
- package/README.md +306 -0
- package/build.mjs +66 -0
- package/commitlint.config.js +25 -0
- package/dist/dxf.js +7234 -0
- package/docs/CODE_PATTERNS.md +182 -0
- package/docs/DIMENSION_SUMMARY.md +248 -0
- package/docs/DIMENSION_SUMMARY.pt-BR.md +248 -0
- package/docs/IMPLEMENTED-2D-ENTITIES.md +54 -0
- package/docs/IMPLEMENTED-2D-ENTITIES.pt-BR.md +54 -0
- package/docs/TEXT-MTEXT-DIMENSION-SUPPORT.md +241 -0
- package/docs/TEXT-MTEXT-DIMENSION-SUPPORT.pt-BR.md +169 -0
- package/docs/autocad_2012_pdf_dxf-reference_enu.md +8272 -0
- package/examples/dxf.html +36 -0
- package/examples/example.es5.js +30 -0
- package/examples/example.es6.js +30 -0
- package/examples/text-dimension-viewer.html +133 -0
- package/lib/Helper.cjs +89 -0
- package/lib/Helper.cjs.map +7 -0
- package/lib/Helper.js +59 -0
- package/lib/Helper.js.map +7 -0
- package/lib/applyTransforms.cjs +59 -0
- package/lib/applyTransforms.cjs.map +7 -0
- package/lib/applyTransforms.js +39 -0
- package/lib/applyTransforms.js.map +7 -0
- package/lib/cli.cjs +53 -0
- package/lib/cli.cjs.map +7 -0
- package/lib/cli.js +29 -0
- package/lib/cli.js.map +7 -0
- package/lib/config.cjs +30 -0
- package/lib/config.cjs.map +7 -0
- package/lib/config.js +10 -0
- package/lib/config.js.map +7 -0
- package/lib/constants.cjs +39 -0
- package/lib/constants.cjs.map +7 -0
- package/lib/constants.js +15 -0
- package/lib/constants.js.map +7 -0
- package/lib/denormalise.cjs +148 -0
- package/lib/denormalise.cjs.map +7 -0
- package/lib/denormalise.js +118 -0
- package/lib/denormalise.js.map +7 -0
- package/lib/dimensionToSVG.cjs +307 -0
- package/lib/dimensionToSVG.cjs.map +7 -0
- package/lib/dimensionToSVG.js +273 -0
- package/lib/dimensionToSVG.js.map +7 -0
- package/lib/entityToPolyline.cjs +248 -0
- package/lib/entityToPolyline.cjs.map +7 -0
- package/lib/entityToPolyline.js +213 -0
- package/lib/entityToPolyline.js.map +7 -0
- package/lib/getRGBForEntity.cjs +53 -0
- package/lib/getRGBForEntity.cjs.map +7 -0
- package/lib/getRGBForEntity.js +23 -0
- package/lib/getRGBForEntity.js.map +7 -0
- package/lib/groupEntitiesByLayer.cjs +34 -0
- package/lib/groupEntitiesByLayer.cjs.map +7 -0
- package/lib/groupEntitiesByLayer.js +14 -0
- package/lib/groupEntitiesByLayer.js.map +7 -0
- package/lib/handlers/blocks.cjs +93 -0
- package/lib/handlers/blocks.cjs.map +7 -0
- package/lib/handlers/blocks.js +63 -0
- package/lib/handlers/blocks.js.map +7 -0
- package/lib/handlers/entities.cjs +118 -0
- package/lib/handlers/entities.cjs.map +7 -0
- package/lib/handlers/entities.js +88 -0
- package/lib/handlers/entities.js.map +7 -0
- package/lib/handlers/entity/arc.cjs +82 -0
- package/lib/handlers/entity/arc.cjs.map +7 -0
- package/lib/handlers/entity/arc.js +47 -0
- package/lib/handlers/entity/arc.js.map +7 -0
- package/lib/handlers/entity/attdef.cjs +318 -0
- package/lib/handlers/entity/attdef.cjs.map +7 -0
- package/lib/handlers/entity/attdef.js +282 -0
- package/lib/handlers/entity/attdef.js.map +7 -0
- package/lib/handlers/entity/attrib.cjs +52 -0
- package/lib/handlers/entity/attrib.cjs.map +7 -0
- package/lib/handlers/entity/attrib.js +27 -0
- package/lib/handlers/entity/attrib.js.map +7 -0
- package/lib/handlers/entity/circle.cjs +73 -0
- package/lib/handlers/entity/circle.cjs.map +7 -0
- package/lib/handlers/entity/circle.js +38 -0
- package/lib/handlers/entity/circle.js.map +7 -0
- package/lib/handlers/entity/common.cjs +83 -0
- package/lib/handlers/entity/common.cjs.map +7 -0
- package/lib/handlers/entity/common.js +63 -0
- package/lib/handlers/entity/common.js.map +7 -0
- package/lib/handlers/entity/dimension.cjs +203 -0
- package/lib/handlers/entity/dimension.cjs.map +7 -0
- package/lib/handlers/entity/dimension.js +168 -0
- package/lib/handlers/entity/dimension.js.map +7 -0
- package/lib/handlers/entity/ellipse.cjs +88 -0
- package/lib/handlers/entity/ellipse.cjs.map +7 -0
- package/lib/handlers/entity/ellipse.js +53 -0
- package/lib/handlers/entity/ellipse.js.map +7 -0
- package/lib/handlers/entity/hatch.cjs +470 -0
- package/lib/handlers/entity/hatch.cjs.map +7 -0
- package/lib/handlers/entity/hatch.js +435 -0
- package/lib/handlers/entity/hatch.js.map +7 -0
- package/lib/handlers/entity/insert.cjs +106 -0
- package/lib/handlers/entity/insert.cjs.map +7 -0
- package/lib/handlers/entity/insert.js +71 -0
- package/lib/handlers/entity/insert.js.map +7 -0
- package/lib/handlers/entity/line.cjs +84 -0
- package/lib/handlers/entity/line.cjs.map +7 -0
- package/lib/handlers/entity/line.js +49 -0
- package/lib/handlers/entity/line.js.map +7 -0
- package/lib/handlers/entity/lwpolyline.cjs +82 -0
- package/lib/handlers/entity/lwpolyline.cjs.map +7 -0
- package/lib/handlers/entity/lwpolyline.js +47 -0
- package/lib/handlers/entity/lwpolyline.js.map +7 -0
- package/lib/handlers/entity/mtext.cjs +121 -0
- package/lib/handlers/entity/mtext.cjs.map +7 -0
- package/lib/handlers/entity/mtext.js +85 -0
- package/lib/handlers/entity/mtext.js.map +7 -0
- package/lib/handlers/entity/ole2Frame.cjs +98 -0
- package/lib/handlers/entity/ole2Frame.cjs.map +7 -0
- package/lib/handlers/entity/ole2Frame.js +63 -0
- package/lib/handlers/entity/ole2Frame.js.map +7 -0
- package/lib/handlers/entity/point.cjs +73 -0
- package/lib/handlers/entity/point.cjs.map +7 -0
- package/lib/handlers/entity/point.js +38 -0
- package/lib/handlers/entity/point.js.map +7 -0
- package/lib/handlers/entity/polyline.cjs +70 -0
- package/lib/handlers/entity/polyline.cjs.map +7 -0
- package/lib/handlers/entity/polyline.js +35 -0
- package/lib/handlers/entity/polyline.js.map +7 -0
- package/lib/handlers/entity/solid.cjs +101 -0
- package/lib/handlers/entity/solid.cjs.map +7 -0
- package/lib/handlers/entity/solid.js +66 -0
- package/lib/handlers/entity/solid.js.map +7 -0
- package/lib/handlers/entity/spline.cjs +109 -0
- package/lib/handlers/entity/spline.cjs.map +7 -0
- package/lib/handlers/entity/spline.js +74 -0
- package/lib/handlers/entity/spline.js.map +7 -0
- package/lib/handlers/entity/text.cjs +85 -0
- package/lib/handlers/entity/text.cjs.map +7 -0
- package/lib/handlers/entity/text.js +49 -0
- package/lib/handlers/entity/text.js.map +7 -0
- package/lib/handlers/entity/threeDFace.cjs +98 -0
- package/lib/handlers/entity/threeDFace.cjs.map +7 -0
- package/lib/handlers/entity/threeDFace.js +63 -0
- package/lib/handlers/entity/threeDFace.js.map +7 -0
- package/lib/handlers/entity/vertex.cjs +78 -0
- package/lib/handlers/entity/vertex.cjs.map +7 -0
- package/lib/handlers/entity/vertex.js +53 -0
- package/lib/handlers/entity/vertex.js.map +7 -0
- package/lib/handlers/entity/viewport.cjs +153 -0
- package/lib/handlers/entity/viewport.cjs.map +7 -0
- package/lib/handlers/entity/viewport.js +118 -0
- package/lib/handlers/entity/viewport.js.map +7 -0
- package/lib/handlers/header.cjs +92 -0
- package/lib/handlers/header.cjs.map +7 -0
- package/lib/handlers/header.js +72 -0
- package/lib/handlers/header.js.map +7 -0
- package/lib/handlers/objects.cjs +170 -0
- package/lib/handlers/objects.cjs.map +7 -0
- package/lib/handlers/objects.js +150 -0
- package/lib/handlers/objects.js.map +7 -0
- package/lib/handlers/tables.cjs +587 -0
- package/lib/handlers/tables.cjs.map +7 -0
- package/lib/handlers/tables.js +557 -0
- package/lib/handlers/tables.js.map +7 -0
- package/lib/index.cjs +60 -0
- package/lib/index.cjs.map +7 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +7 -0
- package/lib/parseString.cjs +118 -0
- package/lib/parseString.cjs.map +7 -0
- package/lib/parseString.js +88 -0
- package/lib/parseString.js.map +7 -0
- package/lib/toPolylines.cjs +69 -0
- package/lib/toPolylines.cjs.map +7 -0
- package/lib/toPolylines.js +39 -0
- package/lib/toPolylines.js.map +7 -0
- package/lib/toSVG.cjs +395 -0
- package/lib/toSVG.cjs.map +7 -0
- package/lib/toSVG.js +361 -0
- package/lib/toSVG.js.map +7 -0
- package/lib/types/arc-entity.cjs +17 -0
- package/lib/types/arc-entity.cjs.map +7 -0
- package/lib/types/arc-entity.js +1 -0
- package/lib/types/arc-entity.js.map +7 -0
- package/lib/types/base-entity.cjs +17 -0
- package/lib/types/base-entity.cjs.map +7 -0
- package/lib/types/base-entity.js +1 -0
- package/lib/types/base-entity.js.map +7 -0
- package/lib/types/circle-entity.cjs +17 -0
- package/lib/types/circle-entity.cjs.map +7 -0
- package/lib/types/circle-entity.js +1 -0
- package/lib/types/circle-entity.js.map +7 -0
- package/lib/types/common.cjs +17 -0
- package/lib/types/common.cjs.map +7 -0
- package/lib/types/common.js +1 -0
- package/lib/types/common.js.map +7 -0
- package/lib/types/dimension-entity.cjs +17 -0
- package/lib/types/dimension-entity.cjs.map +7 -0
- package/lib/types/dimension-entity.js +1 -0
- package/lib/types/dimension-entity.js.map +7 -0
- package/lib/types/dxf.cjs +17 -0
- package/lib/types/dxf.cjs.map +7 -0
- package/lib/types/dxf.js +1 -0
- package/lib/types/dxf.js.map +7 -0
- package/lib/types/ellipse-entity.cjs +17 -0
- package/lib/types/ellipse-entity.cjs.map +7 -0
- package/lib/types/ellipse-entity.js +1 -0
- package/lib/types/ellipse-entity.js.map +7 -0
- package/lib/types/entity.cjs +17 -0
- package/lib/types/entity.cjs.map +7 -0
- package/lib/types/entity.js +1 -0
- package/lib/types/entity.js.map +7 -0
- package/lib/types/handler-internal.cjs +17 -0
- package/lib/types/handler-internal.cjs.map +7 -0
- package/lib/types/handler-internal.js +1 -0
- package/lib/types/handler-internal.js.map +7 -0
- package/lib/types/handler.cjs +17 -0
- package/lib/types/handler.cjs.map +7 -0
- package/lib/types/handler.js +1 -0
- package/lib/types/handler.js.map +7 -0
- package/lib/types/hatch-entity.cjs +17 -0
- package/lib/types/hatch-entity.cjs.map +7 -0
- package/lib/types/hatch-entity.js +1 -0
- package/lib/types/hatch-entity.js.map +7 -0
- package/lib/types/helper.cjs +17 -0
- package/lib/types/helper.cjs.map +7 -0
- package/lib/types/helper.js +1 -0
- package/lib/types/helper.js.map +7 -0
- package/lib/types/index.cjs +77 -0
- package/lib/types/index.cjs.map +7 -0
- package/lib/types/index.js +29 -0
- package/lib/types/index.js.map +7 -0
- package/lib/types/insert-entity.cjs +17 -0
- package/lib/types/insert-entity.cjs.map +7 -0
- package/lib/types/insert-entity.js +1 -0
- package/lib/types/insert-entity.js.map +7 -0
- package/lib/types/layer-groups.cjs +17 -0
- package/lib/types/layer-groups.cjs.map +7 -0
- package/lib/types/layer-groups.js +1 -0
- package/lib/types/layer-groups.js.map +7 -0
- package/lib/types/line-entity.cjs +17 -0
- package/lib/types/line-entity.cjs.map +7 -0
- package/lib/types/line-entity.js +1 -0
- package/lib/types/line-entity.js.map +7 -0
- package/lib/types/mtext-entity.cjs +17 -0
- package/lib/types/mtext-entity.cjs.map +7 -0
- package/lib/types/mtext-entity.js +1 -0
- package/lib/types/mtext-entity.js.map +7 -0
- package/lib/types/ole2frame-entity.cjs +17 -0
- package/lib/types/ole2frame-entity.cjs.map +7 -0
- package/lib/types/ole2frame-entity.js +1 -0
- package/lib/types/ole2frame-entity.js.map +7 -0
- package/lib/types/options.cjs +17 -0
- package/lib/types/options.cjs.map +7 -0
- package/lib/types/options.js +1 -0
- package/lib/types/options.js.map +7 -0
- package/lib/types/point-entity.cjs +17 -0
- package/lib/types/point-entity.cjs.map +7 -0
- package/lib/types/point-entity.js +1 -0
- package/lib/types/point-entity.js.map +7 -0
- package/lib/types/polyline-entity.cjs +17 -0
- package/lib/types/polyline-entity.cjs.map +7 -0
- package/lib/types/polyline-entity.js +1 -0
- package/lib/types/polyline-entity.js.map +7 -0
- package/lib/types/polylines.cjs +17 -0
- package/lib/types/polylines.cjs.map +7 -0
- package/lib/types/polylines.js +1 -0
- package/lib/types/polylines.js.map +7 -0
- package/lib/types/solid-entity.cjs +17 -0
- package/lib/types/solid-entity.cjs.map +7 -0
- package/lib/types/solid-entity.js +1 -0
- package/lib/types/solid-entity.js.map +7 -0
- package/lib/types/spline-entity.cjs +17 -0
- package/lib/types/spline-entity.cjs.map +7 -0
- package/lib/types/spline-entity.js +1 -0
- package/lib/types/spline-entity.js.map +7 -0
- package/lib/types/svg.cjs +17 -0
- package/lib/types/svg.cjs.map +7 -0
- package/lib/types/svg.js +1 -0
- package/lib/types/svg.js.map +7 -0
- package/lib/types/tables.cjs +17 -0
- package/lib/types/tables.cjs.map +7 -0
- package/lib/types/tables.js +1 -0
- package/lib/types/tables.js.map +7 -0
- package/lib/types/text-entity.cjs +17 -0
- package/lib/types/text-entity.cjs.map +7 -0
- package/lib/types/text-entity.js +1 -0
- package/lib/types/text-entity.js.map +7 -0
- package/lib/types/util-types.cjs +17 -0
- package/lib/types/util-types.cjs.map +7 -0
- package/lib/types/util-types.js +1 -0
- package/lib/types/util-types.js.map +7 -0
- package/lib/types/vecks.d.cjs +2 -0
- package/lib/types/vecks.d.cjs.map +7 -0
- package/lib/types/vecks.d.js +1 -0
- package/lib/types/vecks.d.js.map +7 -0
- package/lib/types/viewport-entity.cjs +17 -0
- package/lib/types/viewport-entity.cjs.map +7 -0
- package/lib/types/viewport-entity.js +1 -0
- package/lib/types/viewport-entity.js.map +7 -0
- package/lib/types.cjs +23 -0
- package/lib/types.cjs.map +7 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +7 -0
- package/lib/util/bSpline.cjs +95 -0
- package/lib/util/bSpline.cjs.map +7 -0
- package/lib/util/bSpline.js +65 -0
- package/lib/util/bSpline.js.map +7 -0
- package/lib/util/colors.cjs +283 -0
- package/lib/util/colors.cjs.map +7 -0
- package/lib/util/colors.js +263 -0
- package/lib/util/colors.js.map +7 -0
- package/lib/util/createArcForLWPolyline.cjs +84 -0
- package/lib/util/createArcForLWPolyline.cjs.map +7 -0
- package/lib/util/createArcForLWPolyline.js +64 -0
- package/lib/util/createArcForLWPolyline.js.map +7 -0
- package/lib/util/dxfColorToRGB.cjs +115 -0
- package/lib/util/dxfColorToRGB.cjs.map +7 -0
- package/lib/util/dxfColorToRGB.js +90 -0
- package/lib/util/dxfColorToRGB.js.map +7 -0
- package/lib/util/insertKnot.cjs +77 -0
- package/lib/util/insertKnot.cjs.map +7 -0
- package/lib/util/insertKnot.js +57 -0
- package/lib/util/insertKnot.js.map +7 -0
- package/lib/util/logger.cjs +53 -0
- package/lib/util/logger.cjs.map +7 -0
- package/lib/util/logger.js +23 -0
- package/lib/util/logger.js.map +7 -0
- package/lib/util/rgbToColorAttribute.cjs +32 -0
- package/lib/util/rgbToColorAttribute.cjs.map +7 -0
- package/lib/util/rgbToColorAttribute.js +12 -0
- package/lib/util/rgbToColorAttribute.js.map +7 -0
- package/lib/util/rotate.cjs +30 -0
- package/lib/util/rotate.cjs.map +7 -0
- package/lib/util/rotate.js +10 -0
- package/lib/util/rotate.js.map +7 -0
- package/lib/util/round10.cjs +38 -0
- package/lib/util/round10.cjs.map +7 -0
- package/lib/util/round10.js +18 -0
- package/lib/util/round10.js.map +7 -0
- package/lib/util/toPiecewiseBezier.cjs +90 -0
- package/lib/util/toPiecewiseBezier.cjs.map +7 -0
- package/lib/util/toPiecewiseBezier.js +54 -0
- package/lib/util/toPiecewiseBezier.js.map +7 -0
- package/lib/util/transformBoundingBoxAndElement.cjs +80 -0
- package/lib/util/transformBoundingBoxAndElement.cjs.map +7 -0
- package/lib/util/transformBoundingBoxAndElement.js +60 -0
- package/lib/util/transformBoundingBoxAndElement.js.map +7 -0
- package/package.json +127 -0
- package/src/Helper.ts +71 -0
- package/src/applyTransforms.ts +54 -0
- package/src/cli.ts +41 -0
- package/src/config.ts +10 -0
- package/src/constants.ts +14 -0
- package/src/denormalise.ts +153 -0
- package/src/dimensionToSVG.ts +427 -0
- package/src/entityToPolyline.ts +338 -0
- package/src/getRGBForEntity.ts +28 -0
- package/src/groupEntitiesByLayer.ts +14 -0
- package/src/handlers/blocks.ts +65 -0
- package/src/handlers/entities.ts +111 -0
- package/src/handlers/entity/arc.ts +61 -0
- package/src/handlers/entity/attdef.ts +284 -0
- package/src/handlers/entity/attrib.ts +29 -0
- package/src/handlers/entity/circle.ts +47 -0
- package/src/handlers/entity/common.ts +79 -0
- package/src/handlers/entity/dimension.ts +217 -0
- package/src/handlers/entity/ellipse.ts +55 -0
- package/src/handlers/entity/hatch.ts +471 -0
- package/src/handlers/entity/insert.ts +73 -0
- package/src/handlers/entity/line.ts +56 -0
- package/src/handlers/entity/lwpolyline.ts +54 -0
- package/src/handlers/entity/mtext.ts +150 -0
- package/src/handlers/entity/ole2Frame.ts +64 -0
- package/src/handlers/entity/point.ts +47 -0
- package/src/handlers/entity/polyline.ts +49 -0
- package/src/handlers/entity/solid.ts +73 -0
- package/src/handlers/entity/spline.ts +103 -0
- package/src/handlers/entity/text.ts +83 -0
- package/src/handlers/entity/threeDFace.ts +69 -0
- package/src/handlers/entity/vertex.ts +55 -0
- package/src/handlers/entity/viewport.ts +119 -0
- package/src/handlers/header.ts +73 -0
- package/src/handlers/objects.ts +152 -0
- package/src/handlers/tables.ts +581 -0
- package/src/index.ts +19 -0
- package/src/parseString.ts +97 -0
- package/src/toPolylines.ts +47 -0
- package/src/toSVG.ts +518 -0
- package/src/types/README.md +91 -0
- package/src/types/arc-entity.ts +10 -0
- package/src/types/base-entity.ts +25 -0
- package/src/types/circle-entity.ts +8 -0
- package/src/types/common.ts +37 -0
- package/src/types/dimension-entity.ts +23 -0
- package/src/types/dxf.ts +64 -0
- package/src/types/ellipse-entity.ts +13 -0
- package/src/types/entity.ts +32 -0
- package/src/types/handler-internal.ts +51 -0
- package/src/types/handler.ts +10 -0
- package/src/types/hatch-entity.ts +127 -0
- package/src/types/helper.ts +12 -0
- package/src/types/index.ts +53 -0
- package/src/types/insert-entity.ts +19 -0
- package/src/types/layer-groups.ts +8 -0
- package/src/types/line-entity.ts +10 -0
- package/src/types/mtext-entity.ts +35 -0
- package/src/types/ole2frame-entity.ts +35 -0
- package/src/types/options.ts +17 -0
- package/src/types/point-entity.ts +7 -0
- package/src/types/polyline-entity.ts +20 -0
- package/src/types/polylines.ts +22 -0
- package/src/types/solid-entity.ts +9 -0
- package/src/types/spline-entity.ts +12 -0
- package/src/types/svg.ts +31 -0
- package/src/types/tables.ts +414 -0
- package/src/types/text-entity.ts +23 -0
- package/src/types/util-types.ts +27 -0
- package/src/types/vecks.d.ts +29 -0
- package/src/types/viewport-entity.ts +81 -0
- package/src/types.ts +5 -0
- package/src/util/bSpline.ts +97 -0
- package/src/util/colors.ts +266 -0
- package/src/util/createArcForLWPolyline.ts +93 -0
- package/src/util/diagram.png +0 -0
- package/src/util/dxfColorToRGB.ts +106 -0
- package/src/util/insertKnot.ts +69 -0
- package/src/util/logger.ts +23 -0
- package/src/util/rgbToColorAttribute.ts +14 -0
- package/src/util/rotate.ts +14 -0
- package/src/util/round10.ts +24 -0
- package/src/util/toPiecewiseBezier.ts +70 -0
- package/src/util/transformBoundingBoxAndElement.ts +74 -0
- package/tsconfig.json +34 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { Box2 } from 'vecks'
|
|
2
|
+
|
|
3
|
+
import colors from './util/colors'
|
|
4
|
+
|
|
5
|
+
import type { DimensionEntity } from './types'
|
|
6
|
+
import type { DimStyleTable } from './types/dxf'
|
|
7
|
+
import type { BoundsAndElement } from './types/svg'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Convert DXF color number to SVG color string
|
|
11
|
+
*/
|
|
12
|
+
function colorNumberToSVG(colorNumber?: number): string {
|
|
13
|
+
if (colorNumber === undefined || colorNumber < 0) {
|
|
14
|
+
return 'currentColor'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// DXF color 0 is ByBlock, 256 is ByLayer, 7 is white/black (depends on bg)
|
|
18
|
+
if (colorNumber === 0 || colorNumber === 256) {
|
|
19
|
+
return 'currentColor'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Get RGB from color table
|
|
23
|
+
const rgb = colors[colorNumber]
|
|
24
|
+
if (!rgb) {
|
|
25
|
+
return 'currentColor'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return `rgb(${rgb[0]},${rgb[1]},${rgb[2]})`
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get dimension colors and weights from DIMSTYLE with defaults
|
|
33
|
+
*/
|
|
34
|
+
function getDimensionColors(dimStyle?: DimStyleTable): {
|
|
35
|
+
dimLineColor: string
|
|
36
|
+
extLineColor: string
|
|
37
|
+
textColor: string
|
|
38
|
+
dimLineWeight: number
|
|
39
|
+
extLineWeight: number
|
|
40
|
+
} {
|
|
41
|
+
return {
|
|
42
|
+
dimLineColor: colorNumberToSVG(dimStyle?.dimClrd),
|
|
43
|
+
extLineColor: colorNumberToSVG(dimStyle?.dimClre),
|
|
44
|
+
textColor: colorNumberToSVG(dimStyle?.dimClrt),
|
|
45
|
+
dimLineWeight: dimStyle?.dimLwd ?? 0.5,
|
|
46
|
+
extLineWeight: dimStyle?.dimLwe ?? 0.5,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Render DIMENSION entity to SVG with proper DIMSTYLE support
|
|
52
|
+
*/
|
|
53
|
+
export default function dimensionToSVG(
|
|
54
|
+
entity: DimensionEntity,
|
|
55
|
+
dimStyle?: DimStyleTable,
|
|
56
|
+
): BoundsAndElement {
|
|
57
|
+
// Dispatch to appropriate renderer based on dimension type
|
|
58
|
+
switch (entity.dimensionType) {
|
|
59
|
+
case 0: // Rotated, horizontal, or vertical
|
|
60
|
+
case 1: // Aligned
|
|
61
|
+
return renderLinearDimension(entity, dimStyle)
|
|
62
|
+
case 2: // Angular
|
|
63
|
+
return renderAngularDimension(entity, dimStyle)
|
|
64
|
+
case 3: // Diameter
|
|
65
|
+
return renderDiameterDimension(entity, dimStyle)
|
|
66
|
+
case 4: // Radius
|
|
67
|
+
return renderRadialDimension(entity, dimStyle)
|
|
68
|
+
case 6: // Ordinate
|
|
69
|
+
return renderOrdinateDimension(entity, dimStyle)
|
|
70
|
+
default:
|
|
71
|
+
// Fallback to simple line rendering
|
|
72
|
+
return renderFallbackDimension(entity)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Create SVG marker definition for dimension arrows
|
|
78
|
+
*/
|
|
79
|
+
export function createArrowMarker(
|
|
80
|
+
id: string,
|
|
81
|
+
size: number,
|
|
82
|
+
color: string,
|
|
83
|
+
): string {
|
|
84
|
+
const arrowPath = `M 0 0 L ${size} ${size / 2} L 0 ${size} z`
|
|
85
|
+
return `<marker id="${id}" markerWidth="${size}" markerHeight="${size}" refX="${size}" refY="${size / 2}" orient="auto" markerUnits="strokeWidth">
|
|
86
|
+
<path d="${arrowPath}" fill="${color}" />
|
|
87
|
+
</marker>`
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Render linear dimension (rotated, horizontal, vertical, or aligned)
|
|
92
|
+
*/
|
|
93
|
+
function renderLinearDimension(
|
|
94
|
+
entity: DimensionEntity,
|
|
95
|
+
dimStyle?: DimStyleTable,
|
|
96
|
+
): BoundsAndElement {
|
|
97
|
+
const bbox = new Box2()
|
|
98
|
+
const elements: string[] = []
|
|
99
|
+
const markers: string[] = []
|
|
100
|
+
|
|
101
|
+
// Get dimension style properties with defaults
|
|
102
|
+
const arrowSize = dimStyle?.dimAsz ?? 2.5
|
|
103
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5
|
|
104
|
+
const extLineOffset = dimStyle?.dimExo ?? 0.625
|
|
105
|
+
const extLineExtension = dimStyle?.dimExe ?? 1.25
|
|
106
|
+
const { dimLineColor, extLineColor, textColor, dimLineWeight, extLineWeight } = getDimensionColors(dimStyle)
|
|
107
|
+
|
|
108
|
+
// Extract dimension geometry
|
|
109
|
+
const defPoint1X = entity.measureStart?.x ?? 0
|
|
110
|
+
const defPoint1Y = entity.measureStart?.y ?? 0
|
|
111
|
+
const defPoint2X = entity.measureEnd?.x ?? 0
|
|
112
|
+
const defPoint2Y = entity.measureEnd?.y ?? 0
|
|
113
|
+
const dimLineY = entity.start?.y ?? 0
|
|
114
|
+
const textX = entity.textMidpoint?.x ?? (defPoint1X + defPoint2X) / 2
|
|
115
|
+
const textY = entity.textMidpoint?.y ?? (defPoint1Y + defPoint2Y) / 2
|
|
116
|
+
|
|
117
|
+
// Calculate dimension line angle
|
|
118
|
+
const angle = Math.atan2(defPoint2Y - defPoint1Y, defPoint2X - defPoint1X)
|
|
119
|
+
const perpAngle = angle + Math.PI / 2
|
|
120
|
+
|
|
121
|
+
// Calculate dimension line endpoints
|
|
122
|
+
const dimLine1X = defPoint1X + Math.cos(perpAngle) * (dimLineY - defPoint1Y)
|
|
123
|
+
const dimLine1Y = defPoint1Y + Math.sin(perpAngle) * (dimLineY - defPoint1Y)
|
|
124
|
+
const dimLine2X = defPoint2X + Math.cos(perpAngle) * (dimLineY - defPoint2Y)
|
|
125
|
+
const dimLine2Y = defPoint2Y + Math.sin(perpAngle) * (dimLineY - defPoint2Y)
|
|
126
|
+
|
|
127
|
+
// Expand bounding box
|
|
128
|
+
bbox.expandByPoint({ x: defPoint1X, y: defPoint1Y })
|
|
129
|
+
bbox.expandByPoint({ x: defPoint2X, y: defPoint2Y })
|
|
130
|
+
bbox.expandByPoint({ x: dimLine1X, y: dimLine1Y })
|
|
131
|
+
bbox.expandByPoint({ x: dimLine2X, y: dimLine2Y })
|
|
132
|
+
bbox.expandByPoint({ x: textX, y: textY })
|
|
133
|
+
|
|
134
|
+
// Create unique marker IDs for arrows
|
|
135
|
+
const markerId1 = `dim-arrow-start-${Date.now()}`
|
|
136
|
+
const markerId2 = `dim-arrow-end-${Date.now()}`
|
|
137
|
+
|
|
138
|
+
// Create arrow markers with dimension line color
|
|
139
|
+
markers.push(
|
|
140
|
+
createArrowMarker(markerId1, arrowSize, dimLineColor),
|
|
141
|
+
createArrowMarker(markerId2, arrowSize, dimLineColor),
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
// Draw extension lines
|
|
145
|
+
const extLine1StartX = defPoint1X + Math.cos(perpAngle) * extLineOffset
|
|
146
|
+
const extLine1StartY = defPoint1Y + Math.sin(perpAngle) * extLineOffset
|
|
147
|
+
const extLine1EndX = dimLine1X + Math.cos(perpAngle) * extLineExtension
|
|
148
|
+
const extLine1EndY = dimLine1Y + Math.sin(perpAngle) * extLineExtension
|
|
149
|
+
|
|
150
|
+
const extLine2StartX = defPoint2X + Math.cos(perpAngle) * extLineOffset
|
|
151
|
+
const extLine2StartY = defPoint2Y + Math.sin(perpAngle) * extLineOffset
|
|
152
|
+
const extLine2EndX = dimLine2X + Math.cos(perpAngle) * extLineExtension
|
|
153
|
+
const extLine2EndY = dimLine2Y + Math.sin(perpAngle) * extLineExtension
|
|
154
|
+
|
|
155
|
+
elements.push(
|
|
156
|
+
`<line x1="${extLine1StartX}" y1="${extLine1StartY}" x2="${extLine1EndX}" y2="${extLine1EndY}" stroke="${extLineColor}" stroke-width="${extLineWeight}" />`,
|
|
157
|
+
`<line x1="${extLine2StartX}" y1="${extLine2StartY}" x2="${extLine2EndX}" y2="${extLine2EndY}" stroke="${extLineColor}" stroke-width="${extLineWeight}" />`,
|
|
158
|
+
`<line x1="${dimLine1X}" y1="${dimLine1Y}" x2="${dimLine2X}" y2="${dimLine2Y}" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" marker-start="url(#${markerId1})" marker-end="url(#${markerId2})" />`,
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
// Add dimension text
|
|
162
|
+
if (entity.text) {
|
|
163
|
+
const textRotation = (angle * 180) / Math.PI
|
|
164
|
+
elements.push(
|
|
165
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${entity.text}</text>`,
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
bbox,
|
|
171
|
+
element: `<defs>${markers.join('')}</defs><g>${elements.join('')}</g>`,
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Render angular dimension
|
|
177
|
+
*/
|
|
178
|
+
function renderAngularDimension(
|
|
179
|
+
entity: DimensionEntity,
|
|
180
|
+
dimStyle?: DimStyleTable,
|
|
181
|
+
): BoundsAndElement {
|
|
182
|
+
const bbox = new Box2()
|
|
183
|
+
const elements: string[] = []
|
|
184
|
+
const markers: string[] = []
|
|
185
|
+
|
|
186
|
+
// Get dimension style properties
|
|
187
|
+
const arrowSize = dimStyle?.dimAsz ?? 2.5
|
|
188
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5
|
|
189
|
+
const { dimLineColor, extLineColor, textColor, dimLineWeight, extLineWeight } = getDimensionColors(dimStyle)
|
|
190
|
+
|
|
191
|
+
// Extract points
|
|
192
|
+
const centerX = entity.start?.x ?? 0
|
|
193
|
+
const centerY = entity.start?.y ?? 0
|
|
194
|
+
const x1 = entity.measureStart?.x ?? 0
|
|
195
|
+
const y1 = entity.measureStart?.y ?? 0
|
|
196
|
+
const x2 = entity.measureEnd?.x ?? 0
|
|
197
|
+
const y2 = entity.measureEnd?.y ?? 0
|
|
198
|
+
const textX = entity.textMidpoint?.x ?? centerX
|
|
199
|
+
const textY = entity.textMidpoint?.y ?? centerY
|
|
200
|
+
|
|
201
|
+
bbox.expandByPoint({ x: centerX, y: centerY })
|
|
202
|
+
bbox.expandByPoint({ x: x1, y: y1 })
|
|
203
|
+
bbox.expandByPoint({ x: x2, y: y2 })
|
|
204
|
+
bbox.expandByPoint({ x: textX, y: textY })
|
|
205
|
+
|
|
206
|
+
// Create arrow markers
|
|
207
|
+
const markerId1 = `dim-angular-arrow-start-${Date.now()}`
|
|
208
|
+
const markerId2 = `dim-angular-arrow-end-${Date.now()}`
|
|
209
|
+
markers.push(
|
|
210
|
+
createArrowMarker(markerId1, arrowSize, dimLineColor),
|
|
211
|
+
createArrowMarker(markerId2, arrowSize, dimLineColor),
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
// Draw extension lines from center to definition points
|
|
215
|
+
elements.push(
|
|
216
|
+
`<line x1="${centerX}" y1="${centerY}" x2="${x1}" y2="${y1}" stroke="${extLineColor}" stroke-width="${extLineWeight}" />`,
|
|
217
|
+
`<line x1="${centerX}" y1="${centerY}" x2="${x2}" y2="${y2}" stroke="${extLineColor}" stroke-width="${extLineWeight}" />`,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
// Calculate arc radius (distance from center to text midpoint)
|
|
221
|
+
const radius = Math.hypot(textX - centerX, textY - centerY)
|
|
222
|
+
const startAngle = Math.atan2(y1 - centerY, x1 - centerX)
|
|
223
|
+
const endAngle = Math.atan2(y2 - centerY, x2 - centerX)
|
|
224
|
+
|
|
225
|
+
// Draw arc for angular dimension
|
|
226
|
+
const largeArcFlag = Math.abs(endAngle - startAngle) > Math.PI ? 1 : 0
|
|
227
|
+
const arcStartX = centerX + radius * Math.cos(startAngle)
|
|
228
|
+
const arcStartY = centerY + radius * Math.sin(startAngle)
|
|
229
|
+
const arcEndX = centerX + radius * Math.cos(endAngle)
|
|
230
|
+
const arcEndY = centerY + radius * Math.sin(endAngle)
|
|
231
|
+
|
|
232
|
+
elements.push(
|
|
233
|
+
`<path d="M ${arcStartX} ${arcStartY} A ${radius} ${radius} 0 ${largeArcFlag} 1 ${arcEndX} ${arcEndY}" fill="none" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" marker-start="url(#${markerId1})" marker-end="url(#${markerId2})" />`,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
// Add dimension text
|
|
237
|
+
if (entity.text) {
|
|
238
|
+
const midAngle = (startAngle + endAngle) / 2
|
|
239
|
+
const textRotation = (midAngle * 180) / Math.PI
|
|
240
|
+
|
|
241
|
+
elements.push(
|
|
242
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${entity.text}</text>`,
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
bbox,
|
|
248
|
+
element: `<defs>${markers.join('')}</defs><g>${elements.join('')}</g>`,
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Render diameter dimension
|
|
254
|
+
*/
|
|
255
|
+
function renderDiameterDimension(
|
|
256
|
+
entity: DimensionEntity,
|
|
257
|
+
dimStyle?: DimStyleTable,
|
|
258
|
+
): BoundsAndElement {
|
|
259
|
+
const bbox = new Box2()
|
|
260
|
+
const elements: string[] = []
|
|
261
|
+
const markers: string[] = []
|
|
262
|
+
|
|
263
|
+
// Get dimension style properties
|
|
264
|
+
const arrowSize = dimStyle?.dimAsz ?? 2.5
|
|
265
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5
|
|
266
|
+
const { dimLineColor, textColor, dimLineWeight } = getDimensionColors(dimStyle)
|
|
267
|
+
|
|
268
|
+
// Extract geometry
|
|
269
|
+
const x1 = entity.measureStart?.x ?? 0
|
|
270
|
+
const y1 = entity.measureStart?.y ?? 0
|
|
271
|
+
const x2 = entity.measureEnd?.x ?? 0
|
|
272
|
+
const y2 = entity.measureEnd?.y ?? 0
|
|
273
|
+
const textX = entity.textMidpoint?.x ?? (x1 + x2) / 2
|
|
274
|
+
const textY = entity.textMidpoint?.y ?? (y1 + y2) / 2
|
|
275
|
+
|
|
276
|
+
bbox.expandByPoint({ x: x1, y: y1 })
|
|
277
|
+
bbox.expandByPoint({ x: x2, y: y2 })
|
|
278
|
+
bbox.expandByPoint({ x: textX, y: textY })
|
|
279
|
+
|
|
280
|
+
// Create arrow markers
|
|
281
|
+
const markerId = `dim-diameter-arrow-${Date.now()}`
|
|
282
|
+
markers.push(createArrowMarker(markerId, arrowSize, dimLineColor))
|
|
283
|
+
|
|
284
|
+
// Create diameter line with arrow at the end
|
|
285
|
+
elements.push(
|
|
286
|
+
`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" marker-end="url(#${markerId})" />`,
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
// Add dimension text with diameter symbol
|
|
290
|
+
const diameterText = entity.text ? `⌀${entity.text}` : '⌀'
|
|
291
|
+
const angle = Math.atan2(y2 - y1, x2 - x1)
|
|
292
|
+
const textRotation = (angle * 180) / Math.PI
|
|
293
|
+
|
|
294
|
+
elements.push(
|
|
295
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${diameterText}</text>`,
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
return {
|
|
299
|
+
bbox,
|
|
300
|
+
element: `<defs>${markers.join('')}</defs><g>${elements.join('')}</g>`,
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Render radial dimension
|
|
306
|
+
*/
|
|
307
|
+
function renderRadialDimension(
|
|
308
|
+
entity: DimensionEntity,
|
|
309
|
+
dimStyle?: DimStyleTable,
|
|
310
|
+
): BoundsAndElement {
|
|
311
|
+
const bbox = new Box2()
|
|
312
|
+
const elements: string[] = []
|
|
313
|
+
const markers: string[] = []
|
|
314
|
+
|
|
315
|
+
// Get dimension style properties
|
|
316
|
+
const arrowSize = dimStyle?.dimAsz ?? 2.5
|
|
317
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5
|
|
318
|
+
const { dimLineColor, textColor, dimLineWeight } = getDimensionColors(dimStyle)
|
|
319
|
+
|
|
320
|
+
// Extract geometry
|
|
321
|
+
const x1 = entity.measureStart?.x ?? 0
|
|
322
|
+
const y1 = entity.measureStart?.y ?? 0
|
|
323
|
+
const x2 = entity.measureEnd?.x ?? 0
|
|
324
|
+
const y2 = entity.measureEnd?.y ?? 0
|
|
325
|
+
const textX = entity.textMidpoint?.x ?? (x1 + x2) / 2
|
|
326
|
+
const textY = entity.textMidpoint?.y ?? (y1 + y2) / 2
|
|
327
|
+
|
|
328
|
+
bbox.expandByPoint({ x: x1, y: y1 })
|
|
329
|
+
bbox.expandByPoint({ x: x2, y: y2 })
|
|
330
|
+
bbox.expandByPoint({ x: textX, y: textY })
|
|
331
|
+
|
|
332
|
+
// Create arrow markers
|
|
333
|
+
const markerId = `dim-radius-arrow-${Date.now()}`
|
|
334
|
+
markers.push(createArrowMarker(markerId, arrowSize, dimLineColor))
|
|
335
|
+
|
|
336
|
+
// Create radius line with arrow at the end
|
|
337
|
+
elements.push(
|
|
338
|
+
`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" marker-end="url(#${markerId})" />`,
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
// Add dimension text with radius symbol
|
|
342
|
+
const radiusText = entity.text ? `R${entity.text}` : 'R'
|
|
343
|
+
const angle = Math.atan2(y2 - y1, x2 - x1)
|
|
344
|
+
const textRotation = (angle * 180) / Math.PI
|
|
345
|
+
|
|
346
|
+
elements.push(
|
|
347
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${radiusText}</text>`,
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
return {
|
|
351
|
+
bbox,
|
|
352
|
+
element: `<defs>${markers.join('')}</defs><g>${elements.join('')}</g>`,
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Render ordinate dimension
|
|
358
|
+
*/
|
|
359
|
+
function renderOrdinateDimension(
|
|
360
|
+
entity: DimensionEntity,
|
|
361
|
+
dimStyle?: DimStyleTable,
|
|
362
|
+
): BoundsAndElement {
|
|
363
|
+
const bbox = new Box2()
|
|
364
|
+
const elements: string[] = []
|
|
365
|
+
|
|
366
|
+
// Get dimension style properties
|
|
367
|
+
const textHeight = dimStyle?.dimTxt ?? 2.5
|
|
368
|
+
const { dimLineColor, textColor, dimLineWeight } = getDimensionColors(dimStyle)
|
|
369
|
+
|
|
370
|
+
// Extract geometry
|
|
371
|
+
const x1 = entity.measureStart?.x ?? 0
|
|
372
|
+
const y1 = entity.measureStart?.y ?? 0
|
|
373
|
+
const x2 = entity.start?.x ?? 0
|
|
374
|
+
const y2 = entity.start?.y ?? 0
|
|
375
|
+
const textX = entity.textMidpoint?.x ?? x2
|
|
376
|
+
const textY = entity.textMidpoint?.y ?? y2
|
|
377
|
+
|
|
378
|
+
bbox.expandByPoint({ x: x1, y: y1 })
|
|
379
|
+
bbox.expandByPoint({ x: x2, y: y2 })
|
|
380
|
+
bbox.expandByPoint({ x: textX, y: textY })
|
|
381
|
+
|
|
382
|
+
// Create leader line (no arrow for ordinate dimensions)
|
|
383
|
+
elements.push(
|
|
384
|
+
`<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="${dimLineColor}" stroke-width="${dimLineWeight}" />`,
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
// Add dimension text
|
|
388
|
+
if (entity.text) {
|
|
389
|
+
const angle = Math.atan2(y2 - y1, x2 - x1)
|
|
390
|
+
const textRotation = (angle * 180) / Math.PI
|
|
391
|
+
|
|
392
|
+
elements.push(
|
|
393
|
+
`<text x="${textX}" y="${textY}" font-size="${textHeight}" fill="${textColor}" text-anchor="middle" transform="rotate(${-textRotation} ${textX} ${textY}) scale(1,-1) translate(0 ${-2 * textY})">${entity.text}</text>`,
|
|
394
|
+
)
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
return {
|
|
398
|
+
bbox,
|
|
399
|
+
element: `<g>${elements.join('')}</g>`,
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Fallback renderer for unsupported dimension types
|
|
405
|
+
*/
|
|
406
|
+
function renderFallbackDimension(entity: DimensionEntity): BoundsAndElement {
|
|
407
|
+
const bbox = new Box2()
|
|
408
|
+
const elements: string[] = []
|
|
409
|
+
|
|
410
|
+
// Just render text at midpoint
|
|
411
|
+
if (entity.textMidpoint) {
|
|
412
|
+
const textX = entity.textMidpoint.x ?? 0
|
|
413
|
+
const textY = entity.textMidpoint.y ?? 0
|
|
414
|
+
bbox.expandByPoint({ x: textX, y: textY })
|
|
415
|
+
|
|
416
|
+
if (entity.text) {
|
|
417
|
+
elements.push(
|
|
418
|
+
`<text x="${textX}" y="${textY}" font-size="2.5" text-anchor="middle" transform="scale(1,-1) translate(0 ${-2 * textY})">${entity.text}</text>`,
|
|
419
|
+
)
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return {
|
|
424
|
+
bbox,
|
|
425
|
+
element: `<g>${elements.join('')}</g>`,
|
|
426
|
+
}
|
|
427
|
+
}
|