Skip to content

Commit

Permalink
encode: add convert_LTYPE_strings_area
Browse files Browse the repository at this point in the history
for 256/512 byte conversions.
See GH #910
  • Loading branch information
rurban committed Dec 31, 2023
1 parent dfe3e19 commit 6960ff2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion include/dwg.h
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,7 @@ typedef struct _dwg_object_LTYPE
Dwg_LTYPE_dash* dashes;
BITCODE_RD dashes_r11[12];
BITCODE_B has_strings_area; /* if some shape_flag & 4 (ODA bug) */
BITCODE_TF strings_area;
BITCODE_TF strings_area; /* 256 or 512 byte since r2007 */
BITCODE_RC unknown_r11;
} Dwg_Object_LTYPE;

Expand Down
4 changes: 4 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ void dwg_log_proxyflag (const int _loglevel, const int maxlevel,
const BITCODE_BS flag);
void dwg_log_dataflags (const int _loglevel, const int maxlevel,
const BITCODE_RC flag);
// in encode, but also in dwg.spec
void
dwg_convert_LTYPE_strings_area (const Dwg_Data *restrict dwg,
Dwg_Object_LTYPE *restrict _obj) __nonnull_all;

// in the public API, but we don't use that for most internal modules
#if !defined _DWG_API_H_ && !defined _DWG_API_C && !defined DYNAPI_TEST_C \
Expand Down
2 changes: 1 addition & 1 deletion src/dwg.c
Original file line number Diff line number Diff line change
Expand Up @@ -3524,7 +3524,7 @@ EXPORT int dwg_supports_eed (const Dwg_Data *dwg)

EXPORT int
dwg_supports_obj (const Dwg_Data *restrict dwg,
const Dwg_Object *restrict obj)
const Dwg_Object *restrict obj)
{
const Dwg_Object_Type type = obj->fixedtype;
Dwg_Version_Type ver;
Expand Down
10 changes: 10 additions & 0 deletions src/dwg.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3971,6 +3971,11 @@ DWG_TABLE (LTYPE)
END_REPEAT (dashes);

UNTIL (R_2004) {
// downconvert from 512
ENCODER {
if (dwg->header.from_version > R_2004)
dwg_convert_LTYPE_strings_area (dwg, _obj);
}
FIELD_BINARY (strings_area, 256, 0);
DECODER {
unsigned int dash_i = 0;
Expand All @@ -3994,6 +3999,11 @@ DWG_TABLE (LTYPE)
}
LATER_VERSIONS {
if (FIELD_VALUE (has_strings_area)) {
// upconvert from 256
ENCODER {
if (dwg->header.from_version <= R_2004)
dwg_convert_LTYPE_strings_area (dwg, _obj);
}
FIELD_BINARY (strings_area, 512, 0);
DECODER {
BITCODE_RS dash_i = 0;
Expand Down
31 changes: 31 additions & 0 deletions src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -7403,4 +7403,35 @@ downconvert_DIMSTYLE (Bit_Chain *restrict dat, Dwg_Object *restrict obj)
}
}

// up or downconvert from/to 256/512 bytes
void
dwg_convert_LTYPE_strings_area (const Dwg_Data *restrict dwg,
Dwg_Object_LTYPE *restrict _obj)
{
if (dwg->header.from_version <= R_2004 && dwg->header.version > R_2004)
{
// upconvert to 512
BITCODE_TF old = _obj->strings_area;
_obj->strings_area = calloc (1, 512);
if (!_obj->strings_area || !old)
return;
for (int i = 0; i < 256; i++)
{
_obj->strings_area[i * 2] = old[i];
}
}
else if (dwg->header.from_version > R_2004 && dwg->header.version <= R_2004)
{
// downconvert to 256
BITCODE_TF old = _obj->strings_area;
_obj->strings_area = calloc (1, 256);
if (!_obj->strings_area || !old)
return;
for (int i = 0; i < 256; i++)
{
_obj->strings_area[i] = old[i * 2];
}
}
}

#undef IS_ENCODER
1 change: 1 addition & 0 deletions src/encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ bool dwg_encode_unknown_bits (Bit_Chain *restrict dat,
Dwg_Object *restrict obj);
void downconvert_TABLESTYLE (Dwg_Object *restrict obj);


#endif

0 comments on commit 6960ff2

Please sign in to comment.