LibreDWG / libredwg

Official mirror of libredwg. With CI hooks and nightly releases. PR's ok
https://savannah.gnu.org/projects/libredwg/
GNU General Public License v3.0
982 stars 233 forks source link

Issues with types in DWG -> JSON -> DWG conversion #1040

Open michal-josef-spacek opened 6 days ago

michal-josef-spacek commented 6 days ago

I found two issues with conversion:

1)

2384c2384
<     "minus_1": 4294967295,
---
>     "minus_1": 2147483647,

2)

8421c8421
<           4278190080
---
>           2147483647

which is XRECORD xdata item

...
        [
          102,
          "RTVSPost2010Prop51ColorRGB"
        ],
        [
          90, 
          2147483647
        ],
...

dwgread of them:

  xdata[99] type: 90 [RS]
xdata[99]: -16777216 [RL 90]
  xdata[100] type: 102 [RS]

and

xdata[98]: "RTVSPost2010Prop51ColorRGB" [TV 102]
  xdata[99] type: 90 [RS]
xdata[99]: 2147483647 [RL 90]
  xdata[100] type: 102 [RS]
michal-josef-spacek commented 6 days ago

I prepared fix for 1), but I don't see where is issue for 2)

michal-josef-spacek commented 6 days ago

Still issue 2)

michal-josef-spacek commented 5 days ago

Testing file: Circle_Original.dwg.gz Testing environment: Windows (tested on mingw version)

michal-josef-spacek commented 5 days ago

Structure (via dwgread):

xdata[98]: "RTVSPost2010Prop51ColorRGB" [TV 102]
  xdata[99] type: 90 [RS]
xdata[99]: -16777216 [RL 90]
  xdata[100] type: 102 [RS]

is in DXF:

102
RTVSPost2010Prop51ColorRGB
 90
-16777216

and JSON:

        [
          102,
          "RTVSPost2010Prop51ColorRGB"
        ],
        [
          90,
          4278190080
        ],

This means, that conversion from DWG to JSON is wrong.

michal-josef-spacek commented 5 days ago

btw: Conversion to DXF via LibreDWG dwg2dxf.exe is fine.

102
RTVSPost2010Prop51ColorRGB
 90
-16777216
michal-josef-spacek commented 5 days ago

Conversion from DWG to JSON is bad in Windows and Linux too (-16777216 → 4278190080).

michal-josef-spacek commented 5 days ago

When I change:

diff --git a/src/out_json.c b/src/out_json.c
index f2e63e24c..4a066d6b7 100644
--- a/src/out_json.c
+++ b/src/out_json.c
@@ -170,6 +170,7 @@ static char *_path_field (const char *path);
 #define VALUE_RC(value, dxf) VALUE (value, RC, dxf)
 #define VALUE_RS(value, dxf) VALUE (value, RS, dxf)
 #define VALUE_RL(value, dxf) VALUE (value, RL, dxf)
+#define VALUE_RLd(value, dxf) VALUE (value, RLd, dxf)
 #define VALUE_RLx(value, dxf) VALUE ((BITCODE_RL)value, RL, dxf)
 #define VALUE_RLL(value, dxf) VALUE (value, RLL, dxf)
 #ifdef IS_RELEASE
@@ -1184,7 +1185,7 @@ json_xdata (Bit_Chain *restrict dat, const Dwg_Object_XRECORD *restrict obj)
                      rbuf->type);
           break;
         case DWG_VT_INT32:
-          VALUE_RL (rbuf->value.i32, 0);
+          VALUE_RLd (rbuf->value.i32, 0);
           LOG_TRACE ("xdata[%u]: %d [RL %d]\n", i, (int)rbuf->value.i32,
                      rbuf->type);
           break;

Conversion on Linux is -16777216 →-16777216, but on Windows still -16777216 → 4278190080.