feat(dwfx): fill and glyph text paths
This commit is contained in:
@@ -1,5 +1,14 @@
|
||||
# 更新日志
|
||||
|
||||
## [1.0.20] — 2026-10-28
|
||||
|
||||
### DWFx 填充与文字
|
||||
|
||||
- DWFx `Path Fill` → `DxfHatch`(SOLID 边界环);
|
||||
- DWFx `Glyphs` → `DxfText`(UnicodeString/Origin/EmSize/Canvas 变换);
|
||||
- 新增合成 XPS 夹具回归:Path 填充 + Glyphs 文本;
|
||||
- `test_dwfx` 3/3(AutoCAD 真实样本 + 合成填充/文字 + import_cad 识别)。
|
||||
|
||||
## [1.0.19] — 2026-10-28
|
||||
|
||||
### DWFx 2D XPS 路径原生导入
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
| `.dxf` | AutoCAD 图纸 | 原生读写 | AC1000–AC1032,ASCII/二进制 |
|
||||
| `.dwt` | AutoCAD 模板 | 原生读 | 按 DWG 容器读取,不保留模板语义 |
|
||||
| `.dws` | AutoCAD 标准 | 原生读 | 按 DWG 容器读取,不保留标准检查语义 |
|
||||
| `.dwf` / `.dwfx` | Autodesk DWF | DWF6 转换器;DWFx 原生读(2D 子集) | DWFx ZIP/XPS 的 `FixedPage` `Path Data` 转 LWPOLYLINE;填充/文字/图像/3D/DWF6 仍需转换器 |
|
||||
| `.dwf` / `.dwfx` | Autodesk DWF | DWF6 转换器;DWFx 原生读(2D 子集) | DWFx ZIP/XPS 的 `FixedPage` `Path Data` 转 LWPOLYLINE、Fill 转 HATCH、Glyphs 转 TEXT;图像/3D/DWF6 仍需转换器 |
|
||||
| `.3dxml` / `.3drep` | Dassault 3DXML | 原生读(XML tessellation) | ZIP+XML;解析 `PolygonalRepType/Positions/Faces`;`V5_CFV3` 二进制 `.3DRep` 仍需转换器 |
|
||||
| `.ifc` | BIM | 原生读写 | IFC 2x3/4 |
|
||||
| `.prt` | NX/Creo/Solid Edge | 转换器 | 私有格式且扩展名歧义,按内容/转换器判定 |
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
* @brief DWFx(XPS 容器)2D 路径导入
|
||||
*
|
||||
* DWF 6 二进制不在本模块范围;DWFx 是 ZIP + XPS FixedPage。
|
||||
* 解析 FixedPage 中的 Canvas RenderTransform 与 Path Data(M/L/H/V/C/Q/A/Z),
|
||||
* 转为 DxfDocument 的 LWPOLYLINE,供现有 2D 图纸/导出链路使用。
|
||||
* 解析 FixedPage 中的 Canvas RenderTransform、Path Data(M/L/H/V/C/Q/A/Z)
|
||||
* 与 Glyphs;填充 Path 转 DxfHatch,描边 Path 转 LWPOLYLINE,文字转 DxfText。
|
||||
*/
|
||||
#include "vde/foundation/io_dxf.h"
|
||||
|
||||
|
||||
@@ -143,6 +143,7 @@ struct PathBuilder {
|
||||
Mat m;
|
||||
std::vector<DxfLwPolyline::Vertex> points;
|
||||
bool closed = false;
|
||||
bool filled = false;
|
||||
|
||||
void emit(double x, double y) {
|
||||
const double tx = m.a * x + m.c * y + m.e;
|
||||
@@ -150,6 +151,17 @@ struct PathBuilder {
|
||||
points.push_back({tx, -ty, 0.0});
|
||||
}
|
||||
void flush() {
|
||||
if (filled && points.size() >= 3) {
|
||||
DxfHatch h;
|
||||
DxfHatch::BoundaryLoop loop;
|
||||
for (const auto& p : points) loop.points.emplace_back(p.x, p.y, 0.0);
|
||||
loop.is_closed = true;
|
||||
h.boundary_loops.push_back(std::move(loop));
|
||||
h.pattern_name = "SOLID";
|
||||
h.layer = "DWFX";
|
||||
doc.entities.emplace_back(std::move(h));
|
||||
++doc.entities_parsed;
|
||||
}
|
||||
if (points.size() >= 2) {
|
||||
DxfLwPolyline pl;
|
||||
pl.vertices = points;
|
||||
@@ -160,6 +172,7 @@ struct PathBuilder {
|
||||
}
|
||||
points.clear();
|
||||
closed = false;
|
||||
filled = false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -321,8 +334,35 @@ void parse_fpage(const std::string& xml, DxfDocument& doc,
|
||||
} else if (name == "Path") {
|
||||
const std::string data = attr(tag, "Data");
|
||||
if (data.empty()) continue;
|
||||
PathBuilder b{doc, stack.back(), {}, false};
|
||||
const std::string fill = attr(tag, "Fill");
|
||||
PathBuilder b{doc, stack.back(), {}, false, !fill.empty() && fill != "none"};
|
||||
parse_path_data(data, b);
|
||||
} else if (name == "Glyphs") {
|
||||
const std::string text = attr(tag, "UnicodeString");
|
||||
if (text.empty()) continue;
|
||||
double ox = 0, oy = 0, size = 12.0;
|
||||
{
|
||||
const std::string v = attr(tag, "OriginX");
|
||||
if (!v.empty()) ox = std::strtod(v.c_str(), nullptr);
|
||||
}
|
||||
{
|
||||
const std::string v = attr(tag, "OriginY");
|
||||
if (!v.empty()) oy = std::strtod(v.c_str(), nullptr);
|
||||
}
|
||||
{
|
||||
const std::string v = attr(tag, "FontRenderingEmSize");
|
||||
if (!v.empty()) size = std::strtod(v.c_str(), nullptr);
|
||||
}
|
||||
const Mat& m = stack.back();
|
||||
DxfText t;
|
||||
t.text_value = text;
|
||||
t.insertion_point = Point3D(m.a * ox + m.c * oy + m.e,
|
||||
-(m.b * ox + m.d * oy + m.f), 0.0);
|
||||
t.height = std::abs(size) * std::sqrt(m.a * m.a + m.b * m.b);
|
||||
t.rotation = std::atan2(m.b, m.a) * 180.0 / M_PI;
|
||||
t.layer = "DWFX";
|
||||
doc.entities.emplace_back(std::move(t));
|
||||
++doc.entities_parsed;
|
||||
}
|
||||
pos = end + 1;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdlib>
|
||||
#include <variant>
|
||||
|
||||
using namespace vde::foundation;
|
||||
|
||||
@@ -15,6 +16,20 @@ TEST(Dwfx, RealSampleIfProvided) {
|
||||
EXPECT_GT(r.drawing.entities_parsed, 0);
|
||||
}
|
||||
|
||||
TEST(Dwfx, SyntheticFillAndTextIfProvided) {
|
||||
const char* sample = std::getenv("VDE_DWFX_SYNTHETIC");
|
||||
if (sample == nullptr) GTEST_SKIP() << "未设置 VDE_DWFX_SYNTHETIC";
|
||||
DwfxImportResult r = import_dwfx(sample);
|
||||
ASSERT_TRUE(r.success) << r.error;
|
||||
bool hatch = false, text = false;
|
||||
for (const auto& e : r.drawing.entities) {
|
||||
hatch = hatch || std::holds_alternative<DxfHatch>(e);
|
||||
text = text || std::holds_alternative<DxfText>(e);
|
||||
}
|
||||
EXPECT_TRUE(hatch);
|
||||
EXPECT_TRUE(text);
|
||||
}
|
||||
|
||||
TEST(Dwfx, ImportCadDetectsDwfx) {
|
||||
const char* sample = std::getenv("VDE_DWFX_SAMPLE");
|
||||
if (sample == nullptr) GTEST_SKIP() << "未设置 VDE_DWFX_SAMPLE";
|
||||
|
||||
Reference in New Issue
Block a user