From 1aa183fd828c0456166b9c8834bfeb5618ef6911 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Fri, 16 Aug 2024 13:18:47 +0200 Subject: [PATCH] dxf: resolve empty BLOCK.name which is mandatory in DXF. Fixes GH #999 --- src/dwg.spec | 40 ++++++++++++++++++++++++++++++++-------- src/out_dxf.c | 12 ++++++++++-- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/dwg.spec b/src/dwg.spec index b3042fa17..a2ec9d58c 100644 --- a/src/dwg.spec +++ b/src/dwg.spec @@ -640,11 +640,8 @@ DWG_ENTITY (BLOCK) } } #endif - SINCE (R_13b1) { - BLOCK_NAME (name, 2) // special pre-R13 naming rules - COMMON_ENTITY_HANDLE_DATA; - } #ifdef IS_DXF + SINCE (R_13b1) { Dwg_Object_BLOCK_HEADER *_hdr = NULL; Dwg_Object *hdr @@ -652,7 +649,25 @@ DWG_ENTITY (BLOCK) ? _ent->ownerhandle->obj : NULL; if (!hdr) hdr = dwg_ref_object (dwg, _ent->ownerhandle); - if (!hdr || hdr->fixedtype != DWG_TYPE_BLOCK_HEADER) + if (hdr && hdr->fixedtype == DWG_TYPE_BLOCK_HEADER) + _hdr = hdr->tio.object->tio.BLOCK_HEADER; + else if (_ent->entmode == 2) { + hdr = dwg_model_space_object (dwg); + _hdr = hdr ? hdr->tio.object->tio.BLOCK_HEADER : NULL; + } + else if (_ent->entmode == 1) { + hdr = dwg_paper_space_object (dwg); + _hdr = hdr ? hdr->tio.object->tio.BLOCK_HEADER : NULL; + } + if (_hdr && (bit_empty_T (dat, _obj->name) || bit_eq_T (dat, _obj->name, "*"))) { + VALUE_T (_hdr->name, 2); // from BLOCK_HEADER + } + else { + BLOCK_NAME (name, 2); + } + COMMON_ENTITY_HANDLE_DATA; + + if (!_hdr) { Dwg_Bitcode_3RD nullpt = { 0.0, 0.0, 0.0 }; VALUE_BL (0, 70); // flags: anon, has_attribs, is_xref, is_overlaid, ... @@ -660,12 +675,16 @@ DWG_ENTITY (BLOCK) } else { - _hdr = hdr->tio.object->tio.BLOCK_HEADER; VALUE_BL (_hdr->flag & 0x3f, 70); VALUE_3BD (_hdr->base_pt, 10); } - SINCE (R_13) - BLOCK_NAME (name, 3); // for entget() from BLOCK_HEADER + SINCE (R_13) { + if (_hdr && (bit_empty_T (dat, _obj->name) || bit_eq_T (dat, _obj->name, "*"))) { + VALUE_T (_hdr->name, 3); // from BLOCK_HEADER + } else { + BLOCK_NAME (name, 3); // for entget() from BLOCK_HEADER + } + } if (_hdr) { VALUE_T (_hdr->xref_pname, 1); // from BLOCK_HEADER VALUE_T0 (_hdr->description, 4); // from BLOCK_HEADER @@ -673,6 +692,11 @@ DWG_ENTITY (BLOCK) VALUE_TFF ("", 1); } } +#else + SINCE (R_13b1) { + BLOCK_NAME (name, 2) // special pre-R13 naming rules + COMMON_ENTITY_HANDLE_DATA; + } #endif DWG_ENTITY_END diff --git a/src/out_dxf.c b/src/out_dxf.c index ebc7be3fe..8fea0d4c3 100644 --- a/src/out_dxf.c +++ b/src/out_dxf.c @@ -1622,15 +1622,23 @@ dxf_cvt_tablerecord (Bit_Chain *restrict dat, const Dwg_Object *restrict obj, static void dxf_cvt_blockname (Bit_Chain *restrict dat, char *restrict name, const int dxf) { + static int gensym = 0; if (!name) { - fprintf (dat->fh, "%3i\r\n\r\n", dxf); + fprintf (dat->fh, "%3i\r\n*U%i\r\n", dxf, gensym++); return; } if (IS_FROM_TU (dat)) // r2007+ unicode names { name = bit_convert_TU ((BITCODE_TU)name); } + if (!name || !*name) + { + fprintf (dat->fh, "%3i\r\n*U%i\r\n", dxf, gensym++); + if (IS_FROM_TU (dat)) + free (name); + return; + } if (dat->version == dat->from_version) // no conversion { fprintf (dat->fh, "%3i\r\n%s\r\n", dxf, name); @@ -1648,7 +1656,7 @@ dxf_cvt_blockname (Bit_Chain *restrict dat, char *restrict name, const int dxf) else fprintf (dat->fh, "%3i\r\n%s\r\n", dxf, name); } - else if (dat->version >= R_13b1 && dat->from_version < R_13b1) // to newer + else if (dat->version >= R_13b1) // to newer { if (strlen (name) < 10) fprintf (dat->fh, "%3i\r\n%s\r\n", dxf, name);