From 8b0a9275a88c0906641e86b36062efac6d257463 Mon Sep 17 00:00:00 2001 From: Tim Edwards Date: Tue, 15 Oct 2019 20:40:59 -0400 Subject: [PATCH] Fixed the value of property FIXED_BBOX when saving a file; it needs to be scaled down by "reducer" like all other values in the cell. Suggests a need to have property types other than string, so that a property type "rect" or "box" can be declared that is saved as a Rect and always scales without special hack handling of the specific string FIXED_BBOX. . . --- database/DBio.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/database/DBio.c b/database/DBio.c index 6389eb23..9afe30f3 100644 --- a/database/DBio.c +++ b/database/DBio.c @@ -2350,6 +2350,8 @@ DBCellWriteFile(cellDef, f) int reducer; char *estring; char lstring[256]; + char *propvalue; + bool propfound; #define FPRINTF(f,s)\ {\ @@ -2542,12 +2544,43 @@ DBCellWriteFile(cellDef, f) } /* And any properties */ + + /* NOTE: FIXED_BBOX is treated specially; values are database */ + /* values and should be divided by reducer. Easiest to do it */ + /* here and revert values after. */ + + propvalue = (char *)DBPropGet(cellDef, "FIXED_BBOX", &propfound); + if (propfound) + { + char *proporig, *propscaled; + Rect scalebox, bbox; + + proporig = StrDup((char **)NULL, propvalue); + propscaled = mallocMagic(strlen(propvalue) + 5); + if (sscanf(propvalue, "%d %d %d %d", &bbox.r_xbot, &bbox.r_ybot, + &bbox.r_xtop, &bbox.r_ytop) == 4) + { + scalebox.r_xbot = bbox.r_xbot / reducer; + scalebox.r_xtop = bbox.r_xtop / reducer; + scalebox.r_ybot = bbox.r_ybot / reducer; + scalebox.r_ytop = bbox.r_ytop / reducer; + sprintf(propscaled, "%d %d %d %d", + bbox.r_xbot / reducer, bbox.r_ybot / reducer, + bbox.r_xtop / reducer, bbox.r_ytop / reducer); + + DBPropPut(cellDef, "FIXED_BBOX", propscaled); + propvalue = proporig; + } + } + if (cellDef->cd_props != (ClientData)NULL) { FPRINTF(f, "<< properties >>\n"); DBPropEnum(cellDef, dbWritePropFunc, (ClientData)f); } + if (propfound) DBPropPut(cellDef, "FIXED_BBOX", propvalue); + FPRINTF(f, "<< end >>\n"); if (fflush(f) == EOF || ferror(f))