From ea93bca48a63ddf70f7df017f2c21f38469a83af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Josef=20=C5=A0pa=C4=8Dek?= Date: Mon, 2 Dec 2024 16:34:55 +0100 Subject: [PATCH] Fix BLOCKSTRETCHACTION situation after handles Last fix was wrong. Each handle could have zero, one or more indexes. Fixes GH#1053 --- doc/dynapi.texi | 10 +++++----- include/dwg.h | 8 ++++---- src/dwg.spec | 5 +++-- src/dynapi.c | 10 +++++----- src/in_dxf.c | 27 ++++++++++++++++---------- test/unit-testing/blockstretchaction.c | 6 +++--- 6 files changed, 37 insertions(+), 29 deletions(-) diff --git a/doc/dynapi.texi b/doc/dynapi.texi index 372876969..f35990b15 100644 --- a/doc/dynapi.texi +++ b/doc/dynapi.texi @@ -13814,10 +13814,10 @@ BL, DXF 94 struct _dwg_object_BLOCKSTRETCHACTION* @item hdl H, DXF 331 -@item bs74 +@item num_indexes BS, DXF 74 -@item bl94 -BL, DXF 94 +@item indexes +BL* @end vtable @end indentedblock @@ -14559,9 +14559,9 @@ BL, DXF 97 @item fitpts 2RD* @item start_tangent -2RD +2RD, DXF 12 @item end_tangent -2RD +2RD, DXF 13 @end vtable @end indentedblock diff --git a/include/dwg.h b/include/dwg.h index a504cfd61..5d3127684 100644 --- a/include/dwg.h +++ b/include/dwg.h @@ -7799,9 +7799,9 @@ typedef struct _dwg_object_BLOCKSCALEACTION typedef struct _dwg_BLOCKSTRETCHACTION_handles { struct _dwg_object_BLOCKSTRETCHACTION *parent; - BITCODE_H hdl; // 331 - BITCODE_BS bs74; // 74 - BITCODE_BL bl94; // 94 + BITCODE_H hdl; // 331 + BITCODE_BS num_indexes; // 74 + BITCODE_BL *indexes; // 94 } Dwg_BLOCKSTRETCHACTION_handles; typedef struct _dwg_BLOCKSTRETCHACTION_codes { @@ -7819,7 +7819,7 @@ typedef struct _dwg_object_BLOCKSTRETCHACTION BITCODE_BL num_pts; // 72 BITCODE_2RD *pts; // 10 BITCODE_BL num_hdls; // 72 - Dwg_BLOCKSTRETCHACTION_handles *hdls; /*!< DXF 331, 74, 94, 94 */ + Dwg_BLOCKSTRETCHACTION_handles *hdls; /*!< DXF 331, 74, 94 */ BITCODE_BL num_codes; // 75 Dwg_BLOCKSTRETCHACTION_codes *codes; /*!< DXF 95, 76, 94 */ BLOCKACTION_doubles_fields; diff --git a/src/dwg.spec b/src/dwg.spec index 3b21b5f58..c30110a00 100644 --- a/src/dwg.spec +++ b/src/dwg.spec @@ -12427,8 +12427,9 @@ DWG_OBJECT (BLOCKSTRETCHACTION) REPEAT (num_hdls, hdls, Dwg_BLOCKSTRETCHACTION_handles) REPEAT_BLOCK SUB_FIELD_HANDLE (hdls[rcount1], hdl, 0, 331); - SUB_FIELD_BS (hdls[rcount1], bs74, 74); - SUB_FIELD_BL (hdls[rcount1], bl94, 94); + SUB_FIELD_BS (hdls[rcount1], num_indexes, 74); + SUB_FIELD_VALUE (hdls[rcount1], indexes) = (BITCODE_BL *)calloc (_obj->hdls[rcount1].num_indexes, sizeof (BITCODE_BL)); + SUB_FIELD_VECTOR_INL (hdls[rcount1], indexes, BL, _obj->hdls[rcount1].num_indexes, 94); SET_PARENT_OBJ (hdls[rcount1]); END_REPEAT_BLOCK END_REPEAT (hdls) diff --git a/src/dynapi.c b/src/dynapi.c index 4d52adf22..9e1d99886 100644 --- a/src/dynapi.c +++ b/src/dynapi.c @@ -11254,10 +11254,10 @@ static const Dwg_DYNAPI_field _dwg_BLOCKSTRETCHACTION_handles_fields[] = { 1,1,0, 0 }, { "hdl", "H", sizeof (BITCODE_H), OFF (struct _dwg_BLOCKSTRETCHACTION_handles, hdl), 1,0,0, 331 }, - { "bs74", "BS", sizeof (BITCODE_BS), OFF (struct _dwg_BLOCKSTRETCHACTION_handles, bs74), + { "num_indexes", "BS", sizeof (BITCODE_BS), OFF (struct _dwg_BLOCKSTRETCHACTION_handles, num_indexes), 0,0,0, 74 }, - { "bl94", "BL", sizeof (BITCODE_BL), OFF (struct _dwg_BLOCKSTRETCHACTION_handles, bl94), - 0,0,0, 94 }, + { "indexes", "BL*", sizeof (BITCODE_BL*), OFF (struct _dwg_BLOCKSTRETCHACTION_handles, indexes), + 1,1,0, 0 }, {NULL, NULL, 0, 0, 0,0,0, 0}, }; /* from typedef struct _dwg_BLOCKVISIBILITYPARAMETER_state: (sorted by offset) */ @@ -11819,9 +11819,9 @@ static const Dwg_DYNAPI_field _dwg_HATCH_PathSeg_fields[] = { { "fitpts", "2RD*", sizeof (BITCODE_2RD*), OFF (struct _dwg_HATCH_PathSeg, fitpts), 1,1,0, 0 }, { "start_tangent", "2RD", sizeof (BITCODE_2RD), OFF (struct _dwg_HATCH_PathSeg, start_tangent), - 1,0,0, 0 }, + 1,0,0, 12 }, { "end_tangent", "2RD", sizeof (BITCODE_2RD), OFF (struct _dwg_HATCH_PathSeg, end_tangent), - 1,0,0, 0 }, + 1,0,0, 13 }, {NULL, NULL, 0, 0, 0,0,0, 0}, }; /* from typedef struct _dwg_HATCH_PolylinePath: (sorted by offset) */ diff --git a/src/in_dxf.c b/src/in_dxf.c index 222305459..21cd2781c 100644 --- a/src/in_dxf.c +++ b/src/in_dxf.c @@ -7867,18 +7867,25 @@ add_AcDbBlockStretchAction (Dwg_Object *restrict obj, Bit_Chain *restrict dat) dxf_free_pair (pair); pair = dxf_read_pair (dat); - EXPECT_DXF (obj->name, o->hdls[i].bs74, 74); - o->hdls[i].bs74 = pair->value.i; - LOG_TRACE ("%s.hdls[%d].bs74 = %u [BS 74]\n", obj->name, i, - (unsigned)o->hdls[i].bs74); + EXPECT_DXF (obj->name, o->hdls[i].num_indexes, 74); + o->hdls[i].num_indexes = pair->value.i; + LOG_TRACE ("%s.hdls[%d].num_indexes = %u [BS 74]\n", obj->name, i, + (unsigned)o->hdls[i].num_indexes); dxf_free_pair (pair); - pair = dxf_read_pair (dat); - EXPECT_DXF (obj->name, o->hdls[i].bl94, 94); - o->hdls[i].bl94 = pair->value.u; - LOG_TRACE ("%s.hdls[%d].bl94 = %u [BL 94]\n", obj->name, i, - (unsigned)o->hdls[i].bl94); - dxf_free_pair (pair); + if (o->hdls[i].num_indexes) + { + for (unsigned j = 0; j < o->hdls[i].num_indexes; j++) + { + pair = dxf_read_pair (dat); + EXPECT_DXF (obj->name, o->hdls[i].indexes[j], 94); + o->hdls[i].indexes[j] = pair->value.u; + LOG_TRACE ("%s.hdls[%d].indexes[%d] = %u [BL 94]\n", obj->name, i, j, + (unsigned)o->hdls[i].indexes[j]); + dxf_free_pair (pair); + } + } + } } diff --git a/test/unit-testing/blockstretchaction.c b/test/unit-testing/blockstretchaction.c index 9e20871af..162e3bf7e 100644 --- a/test/unit-testing/blockstretchaction.c +++ b/test/unit-testing/blockstretchaction.c @@ -6,7 +6,7 @@ void api_process (dwg_object *obj) { int error, isnew; - BITCODE_BL i; + BITCODE_BL i, j; BLOCKACTION_fields; BITCODE_BL num_pts; BITCODE_2RD *pts; @@ -40,8 +40,8 @@ api_process (dwg_object *obj) for (i = 0; i < num_hdls; i++) { CHK_SUBCLASS_H (_obj->hdls[i], BLOCKSTRETCHACTION_handles, hdl); - CHK_SUBCLASS_TYPE (_obj->hdls[i], BLOCKSTRETCHACTION_handles, bs74, BS); - CHK_SUBCLASS_TYPE (_obj->hdls[i], BLOCKSTRETCHACTION_handles, bl94, BL); + CHK_SUBCLASS_TYPE (_obj->hdls[i], BLOCKSTRETCHACTION_handles, num_indexes, BS); + CHK_SUBCLASS_VECTOR_TYPE (_obj->hdls[i], BLOCKSTRETCHACTION_handles, indexes, _obj->hdls[i].num_indexes, BL); } CHK_ENTITY_TYPE (_obj, BLOCKSTRETCHACTION, num_codes, BL); for (i = 0; i < num_codes; i++)