Skip to content

Commit e83083c

Browse files
committed
encode: fix dwg_set_dataflags
oops, critical encoder bug! dataflags are reverse, if a bit is absent then the field needs to be used. also the default with_factor is 1.0 thanks to Erfan Sadigh Nejati for finding this bug. Fixes GH #1164
1 parent aabc03c commit e83083c

File tree

1 file changed

+25
-51
lines changed

1 file changed

+25
-51
lines changed

src/encode.c

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7309,66 +7309,40 @@ dwg_set_dataflags (Dwg_Object *obj)
73097309
if (obj->fixedtype == DWG_TYPE_TEXT)
73107310
{
73117311
Dwg_Entity_TEXT *_obj = obj->tio.entity->tio.TEXT;
7312-
if (_obj->elevation != 0.0)
7313-
_obj->dataflags |= 1;
7314-
if (_obj->alignment_pt.x != _obj->ins_pt.x
7315-
|| _obj->alignment_pt.y != _obj->ins_pt.y)
7316-
_obj->dataflags |= 2;
7317-
if (_obj->oblique_angle != 0.0)
7318-
_obj->dataflags |= 4;
7319-
if (_obj->rotation != 0.0)
7320-
_obj->dataflags |= 8;
7321-
if (_obj->width_factor != 0.0)
7322-
_obj->dataflags |= 0x10;
7323-
if (_obj->generation != 0)
7324-
_obj->dataflags |= 0x20;
7325-
if (_obj->horiz_alignment != 0)
7326-
_obj->dataflags |= 0x40;
7327-
if (_obj->vert_alignment != 0)
7328-
_obj->dataflags |= 0x80;
7312+
7313+
#define _SET_DATAFLAGS \
7314+
_obj->dataflags = 0xff; \
7315+
if (_obj->elevation != 0.0) \
7316+
_obj->dataflags &= ~1; \
7317+
if (_obj->alignment_pt.x != _obj->ins_pt.x \
7318+
|| _obj->alignment_pt.y != _obj->ins_pt.y) \
7319+
_obj->dataflags &= ~2; \
7320+
if (_obj->oblique_angle != 0.0) \
7321+
_obj->dataflags &= ~4; \
7322+
if (_obj->rotation != 0.0) \
7323+
_obj->dataflags &= ~8; \
7324+
if (_obj->width_factor != 1.0) \
7325+
_obj->dataflags &= ~0x10; \
7326+
if (_obj->generation != 0) \
7327+
_obj->dataflags &= ~0x20; \
7328+
if (_obj->horiz_alignment != 0) \
7329+
_obj->dataflags &= ~0x40; \
7330+
if (_obj->vert_alignment != 0) \
7331+
_obj->dataflags &= ~0x80
7332+
7333+
_SET_DATAFLAGS;
73297334
}
73307335
else if (obj->fixedtype == DWG_TYPE_ATTRIB)
73317336
{
73327337
Dwg_Entity_ATTRIB *_obj = obj->tio.entity->tio.ATTRIB;
7333-
if (_obj->elevation != 0.0)
7334-
_obj->dataflags |= 1;
7335-
if (_obj->alignment_pt.x != _obj->ins_pt.x
7336-
|| _obj->alignment_pt.y != _obj->ins_pt.y)
7337-
_obj->dataflags |= 2;
7338-
if (_obj->oblique_angle != 0.0)
7339-
_obj->dataflags |= 4;
7340-
if (_obj->rotation != 0.0)
7341-
_obj->dataflags |= 8;
7342-
if (_obj->width_factor != 0.0)
7343-
_obj->dataflags |= 0x10;
7344-
if (_obj->generation != 0)
7345-
_obj->dataflags |= 0x20;
7346-
if (_obj->horiz_alignment != 0)
7347-
_obj->dataflags |= 0x40;
7348-
if (_obj->vert_alignment != 0)
7349-
_obj->dataflags |= 0x80;
7338+
_SET_DATAFLAGS;
73507339
}
73517340
else if (obj->fixedtype == DWG_TYPE_ATTDEF)
73527341
{
73537342
Dwg_Entity_ATTDEF *_obj = obj->tio.entity->tio.ATTDEF;
7354-
if (_obj->elevation != 0.0)
7355-
_obj->dataflags |= 1;
7356-
if (_obj->alignment_pt.x != _obj->ins_pt.x
7357-
|| _obj->alignment_pt.y != _obj->ins_pt.y)
7358-
_obj->dataflags |= 2;
7359-
if (_obj->oblique_angle != 0.0)
7360-
_obj->dataflags |= 4;
7361-
if (_obj->rotation != 0.0)
7362-
_obj->dataflags |= 8;
7363-
if (_obj->width_factor != 0.0)
7364-
_obj->dataflags |= 0x10;
7365-
if (_obj->generation != 0)
7366-
_obj->dataflags |= 0x20;
7367-
if (_obj->horiz_alignment != 0)
7368-
_obj->dataflags |= 0x40;
7369-
if (_obj->vert_alignment != 0)
7370-
_obj->dataflags |= 0x80;
7343+
_SET_DATAFLAGS;
73717344
}
7345+
#undef _SET_DATAFLAGS
73727346
}
73737347

73747348
#if 0

0 commit comments

Comments
 (0)