Skip to content

Commit

Permalink
dxf: resolve empty BLOCK.name
Browse files Browse the repository at this point in the history
which is mandatory in DXF.
Fixes GH #999
  • Loading branch information
rurban committed Aug 16, 2024
1 parent 600455e commit 1aa183f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
40 changes: 32 additions & 8 deletions src/dwg.spec
Original file line number Diff line number Diff line change
Expand Up @@ -640,39 +640,63 @@ 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
= _ent->ownerhandle && _ent->ownerhandle->obj
? _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, ...
VALUE_3BD (nullpt, 10);
}
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
} else {
VALUE_TFF ("", 1);
}
}
#else
SINCE (R_13b1) {
BLOCK_NAME (name, 2) // special pre-R13 naming rules
COMMON_ENTITY_HANDLE_DATA;
}
#endif

DWG_ENTITY_END
Expand Down
12 changes: 10 additions & 2 deletions src/out_dxf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 1aa183f

Please sign in to comment.