summaryrefslogtreecommitdiffstats
path: root/src/libuemf
diff options
context:
space:
mode:
authorLiam P. White <inkscapebronyat-signgmaildotcom>2014-03-26 01:54:08 +0000
committerLiam P. White <inkscapebronyat-signgmaildotcom>2014-03-26 01:54:08 +0000
commite80a86b84d1e5cd64139df6aee147795067cb938 (patch)
tree53fb3e0050a406d48dd4c869997db4ff92832bc1 /src/libuemf
parentUpdate to trunk (diff)
parentPatch for several issues in libuemf. (diff)
downloadinkscape-e80a86b84d1e5cd64139df6aee147795067cb938.tar.gz
inkscape-e80a86b84d1e5cd64139df6aee147795067cb938.zip
Update to trunk
(bzr r13090.1.32)
Diffstat (limited to 'src/libuemf')
-rw-r--r--src/libuemf/uemf.c6
-rw-r--r--src/libuemf/uemf_endian.c6
-rw-r--r--src/libuemf/uemf_utf.c72
-rw-r--r--src/libuemf/upmf.c68
-rw-r--r--src/libuemf/upmf_print.c7
-rw-r--r--src/libuemf/uwmf.c101
-rw-r--r--src/libuemf/uwmf.h23
-rw-r--r--src/libuemf/uwmf_print.c8
8 files changed, 187 insertions, 104 deletions
diff --git a/src/libuemf/uemf.c b/src/libuemf/uemf.c
index 55388cf53..069cf901b 100644
--- a/src/libuemf/uemf.c
+++ b/src/libuemf/uemf.c
@@ -16,8 +16,8 @@
/*
File: uemf.c
-Version: 0.0.25
-Date: 15-JAN-2014
+Version: 0.0.26
+Date: 24-MAR-2014
Author: David Mathog, Biology Division, Caltech
email: mathog@caltech.edu
Copyright: 2014 David Mathog and California Institute of Technology (Caltech)
@@ -660,7 +660,6 @@ int RGBA_to_DIB(
bs = colortype/8;
if(bs<1){
- bs=1;
usedbytes = (w*colortype + 7)/8; // width of line in fully and partially occupied bytes
}
else {
@@ -956,7 +955,6 @@ int DIB_to_RGBA(
cbRgba_px = stride * h;
bs = colortype/8;
if(bs<1){
- bs=1;
usedbytes = (w*colortype + 7)/8; // width of line in fully and partially occupied bytes
}
else {
diff --git a/src/libuemf/uemf_endian.c b/src/libuemf/uemf_endian.c
index f5dcf829a..8f2be57da 100644
--- a/src/libuemf/uemf_endian.c
+++ b/src/libuemf/uemf_endian.c
@@ -19,8 +19,8 @@
/*
File: uemf_endian.c
-Version: 0.0.14
-Date: 15-JAN-2014
+Version: 0.0.15
+Date: 24-MAR-2014
Author: David Mathog, Biology Division, Caltech
email: mathog@caltech.edu
Copyright: 2014 David Mathog and California Institute of Technology (Caltech)
@@ -1193,10 +1193,8 @@ void U_EMREXTSELECTCLIPRGN_swap(char *record, int torev){
int nextroff=0;
int limit=0;
PU_EMREXTSELECTCLIPRGN pEmr = (PU_EMREXTSELECTCLIPRGN) (record);
- roff = 0;
if(torev){
limit = pEmr->emr.nSize;
- nextroff = 0;
}
core5_swap(record, torev);
if(!torev){
diff --git a/src/libuemf/uemf_utf.c b/src/libuemf/uemf_utf.c
index 0c07148a4..0159d51cd 100644
--- a/src/libuemf/uemf_utf.c
+++ b/src/libuemf/uemf_utf.c
@@ -239,8 +239,13 @@ uint16_t *U_Utf32leToUtf16le(
iconv_t conv = iconv_open("UTF-16LE", "UTF-32LE");
status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen);
iconv_close(conv);
- if(status == (size_t) -1)return(NULL);
- if(len)*len=wchar16len((uint16_t *)dst2);
+ if(status == (size_t) -1){
+ free(dst2);
+ dst2 = NULL;
+ }
+ else if(len){
+ *len=wchar16len((uint16_t *)dst2);
+ }
return((uint16_t *)dst2);
}
@@ -270,8 +275,13 @@ uint32_t *U_Utf16leToUtf32le(
if ( conv == (iconv_t)-1)return(NULL);
status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen);
iconv_close(conv);
- if(status == (size_t) -1)return(NULL);
- if(len)*len=wchar32len((uint32_t *)dst2);
+ if(status == (size_t) -1){
+ free(dst2);
+ dst2 = NULL;
+ }
+ else if(len){
+ *len=wchar32len((uint32_t *)dst2);
+ }
return((uint32_t *) dst2);
}
@@ -307,8 +317,13 @@ uint32_t *U_Latin1ToUtf32le(
if ( conv == (iconv_t) -1)return(NULL);
status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen);
iconv_close(conv);
- if(status == (size_t) -1)return(NULL);
- if(len)*len=wchar32len((uint32_t *)dst2);
+ if(status == (size_t) -1){
+ free(dst2);
+ dst2 = NULL;
+ }
+ else if(len){
+ *len=wchar32len((uint32_t *)dst2);
+ }
return((uint32_t *) dst2);
}
@@ -338,8 +353,13 @@ uint32_t *U_Utf8ToUtf32le(
if ( conv == (iconv_t) -1)return(NULL);
status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen);
iconv_close(conv);
- if(status == (size_t) -1)return(NULL);
- if(len)*len=wchar32len((uint32_t *)dst2);
+ if(status == (size_t) -1){
+ free(dst2);
+ dst2 = NULL;
+ }
+ else if(len){
+ *len=wchar32len((uint32_t *)dst2);
+ }
return((uint32_t *) dst2);
}
@@ -369,8 +389,13 @@ char *U_Utf32leToUtf8(
if ( conv == (iconv_t)-1)return(NULL);
status = iconv(conv, ICONV_CAST &src2, &srclen, &dst, &dstlen);
iconv_close(conv);
- if(status == (size_t) -1)return(NULL);
- if(len)*len=strlen(dst2);
+ if(status == (size_t) -1){
+ free(dst2);
+ dst2 = NULL;
+ }
+ else if(len){
+ *len=strlen(dst2);
+ }
return(dst2);
}
@@ -400,8 +425,13 @@ uint16_t *U_Utf8ToUtf16le(
if (conv == (iconv_t) -1)return(NULL);
status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen);
iconv_close(conv);
- if(status == (size_t) -1)return(NULL);
- if(len)*len=wchar16len((uint16_t *)dst2);
+ if(status == (size_t) -1){
+ free(dst2);
+ dst2 = NULL;
+ }
+ else if(len){
+ *len=wchar16len((uint16_t *)dst2);
+ }
return((uint16_t *)dst2);
}
@@ -514,8 +544,13 @@ char *U_Utf8ToLatin1(
if ( conv == (iconv_t) -1)return(NULL);
status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen);
iconv_close(conv);
- if(status == (size_t) -1)return(NULL);
- if(len)*len=strlen(dst2);
+ if(status == (size_t) -1){
+ free(dst2);
+ dst2 = NULL;
+ }
+ else if(len){
+ *len=strlen(dst2);
+ }
return((char *) dst2);
}
@@ -546,8 +581,13 @@ char *U_Latin1ToUtf8(
if ( conv == (iconv_t) -1)return(NULL);
status = iconv(conv, ICONV_CAST &src, &srclen, &dst, &dstlen);
iconv_close(conv);
- if(status == (size_t) -1)return(NULL);
- if(len)*len=strlen(dst2);
+ if(status == (size_t) -1){
+ free(dst2);
+ dst2 = NULL;
+ }
+ else if(len){
+ *len=strlen(dst2);
+ }
return((char *) dst2);
}
diff --git a/src/libuemf/upmf.c b/src/libuemf/upmf.c
index 742b8b0f7..a7a5e42b5 100644
--- a/src/libuemf/upmf.c
+++ b/src/libuemf/upmf.c
@@ -21,11 +21,11 @@
/*
File: upmf.c
-Version: 0.0.4
-Date: 27-NOV-2013
+Version: 0.0.5
+Date: 24-MAR-2014
Author: David Mathog, Biology Division, Caltech
email: mathog@caltech.edu
-Copyright: 2013 David Mathog and California Institute of Technology (Caltech)
+Copyright: 2014 David Mathog and California Institute of Technology (Caltech)
*/
#ifdef __cplusplus
@@ -608,7 +608,7 @@ int U_PO_free(U_PSEUDO_OBJ **po){
Data fields: an array of a basic type of Units bytes repeated Reps times with the target byte order
described in TE.
- Ptrs: Address of the first byte of the data fields.
+ Ptrs: Address of the first byte of the data fields.
Units: Number of bytes of in each data field unit
@@ -1303,8 +1303,9 @@ uint8_t *U_LOAD_GUID(char *string){
if(3 != sscanf(string + 0,"%8X",&Data1) +
sscanf(string + 8,"%4X",&tData2) +
sscanf(string + 12,"%4X",&tData3)){
- free(lf);
- return(NULL);
+ free(hold);
+ hold = NULL;
+ goto bye;
}
Data2=tData2;
Data3=tData3;
@@ -1318,12 +1319,14 @@ uint8_t *U_LOAD_GUID(char *string){
/* remainder is converted byte by byte and stored in that order */
for(i=0;i<8;i++,Data4+=2,lf++){
if(1 != sscanf(Data4,"%2X",&tByte)){
- free(lf);
- return(NULL);
+ free(hold);
+ hold = NULL;
+ goto bye;
}
*lf=tByte;
}
}
+bye:
return(hold);
}
@@ -1767,7 +1770,7 @@ U_PSEUDO_OBJ *U_PMF_PEN_set(uint32_t Version, const U_PSEUDO_OBJ *PenData, const
EMF+ manual 2.2.1.8, Microsoft name: EmfPlusRegion Object
*/
U_PSEUDO_OBJ *U_PMF_REGION_set(uint32_t Version, uint32_t Count, const U_PSEUDO_OBJ *Nodes){
- if(Nodes->Type != U_PMF_REGIONNODE_OID)return(NULL);
+ if(!Nodes || Nodes->Type != U_PMF_REGIONNODE_OID)return(NULL);
const U_SERIAL_DESC List[] = {
{&Version, 4, 1, U_LE},
{&Count, 4, 1, U_LE},
@@ -1787,6 +1790,7 @@ U_PSEUDO_OBJ *U_PMF_REGION_set(uint32_t Version, uint32_t Count, const U_PSEUDO_
EMF+ manual 2.2.1.9, Microsoft name: EmfPlusStringFormat Object
*/
U_PSEUDO_OBJ *U_PMF_STRINGFORMAT_set(U_PMF_STRINGFORMAT *Sfs, const U_PSEUDO_OBJ *Sfd){
+ if(!Sfs){ return(NULL); }
if(Sfd){
if((!Sfs->TabStopCount && !Sfs->RangeCount) || (Sfd->Type != U_PMF_STRINGFORMATDATA_OID))return(NULL);
}
@@ -1901,6 +1905,7 @@ U_PMF_ARGB U_PMF_ARGBOBJ_set(uint8_t Alpha, uint8_t Red, uint8_t Green, uint8_t
EMF+ manual 2.2.2.2, Microsoft name: EmfPlusBitmap Object
*/
U_PSEUDO_OBJ *U_PMF_BITMAP_set(const U_PMF_BITMAP *Bs, const U_PSEUDO_OBJ *Bm){
+ if(!Bs)return(NULL);
if(Bm->Type != U_PMF_BITMAPDATA_OID &&
Bm->Type != U_PMF_COMPRESSEDIMAGE_OID )return(NULL);
uint32_t Pad = UP4(Bm->Used) - Bm->Used; /* undocumented padding, must be present for at least PNG */
@@ -1925,6 +1930,7 @@ U_PSEUDO_OBJ *U_PMF_BITMAP_set(const U_PMF_BITMAP *Bs, const U_PSEUDO_OBJ *Bm){
*/
U_PSEUDO_OBJ *U_PMF_BITMAPDATA_set( const U_PSEUDO_OBJ *Ps, int cbBm, const char *Bm){
if(Ps && (Ps->Type != U_PMF_PALETTE_OID))return(NULL);
+ if(!Bm && cbBm)return(NULL);
const U_SERIAL_DESC List[] = {
{(Ps ? Ps->Data : NULL), (Ps ? Ps->Used : 0), (Ps ? 1 : 0), U_LE},
{Bm, cbBm, 1, U_XE},
@@ -2020,7 +2026,7 @@ U_PSEUDO_OBJ *U_PMF_BLENDCOLORS_linear_set(uint32_t Elements, U_PMF_ARGB StartCo
\return Pointer to PseudoObject, NULL on error
\param Elements members in each array
\param Positions positions along gradient line. The first position MUST be 0.0 and the last MUST be 1.0.
- \param Factors blending factors, 0.0->1.0 values, inclusiv
+ \param Factors blending factors, 0.0->1.0 values, inclusive
EMF+ manual 2.2.2.5, Microsoft name: EmfPlusBlendFactors Object
*/
@@ -2088,7 +2094,7 @@ U_PSEUDO_OBJ *U_PMF_BLENDFACTORS_linear_set(uint32_t Elements, U_FLOAT StartFact
EMF+ manual 2.2.2.6, Microsoft name: EmfPlusBoundaryPathData Object
*/
U_PSEUDO_OBJ *U_PMF_BOUNDARYPATHDATA_set(const U_PSEUDO_OBJ *Path){
- if(Path->Type != U_PMF_PATH_OID)return(NULL);
+ if(!Path || Path->Type != U_PMF_PATH_OID)return(NULL);
/* PO Used is size_t, might be 8 bytes, value in record must be 4 bytes */
uint32_t Used = Path->Used;
const U_SERIAL_DESC List[] = {
@@ -2183,7 +2189,7 @@ U_PSEUDO_OBJ *U_PMF_COMPRESSEDIMAGE_set(int32_t cbImage, const char *Image){
EMF+ manual 2.2.2.11, Microsoft name: EmfPlusCustomEndCapData Object
*/
U_PSEUDO_OBJ *U_PMF_CUSTOMENDCAPDATA_set(const U_PSEUDO_OBJ *Clc){
- if(Clc->Type != U_PMF_CUSTOMLINECAP_OID)return(NULL);
+ if(!Clc || Clc->Type != U_PMF_CUSTOMLINECAP_OID)return(NULL);
/* PO Used is size_t, might be 8 bytes, value in record must be 4 bytes */
uint32_t Used = Clc->Used;
const U_SERIAL_DESC List[] = {
@@ -2252,7 +2258,7 @@ U_PSEUDO_OBJ *U_PMF_CUSTOMLINECAPDATA_set(uint32_t Flags, uint32_t Cap,
uint32_t Join, U_FLOAT MiterLimit, U_FLOAT WidthScale,
const U_PSEUDO_OBJ *Clcod
){
- if(Clcod->Type != U_PMF_CUSTOMLINECAPOPTIONALDATA_OID)return(NULL);
+ if(!Clcod || Clcod->Type != U_PMF_CUSTOMLINECAPOPTIONALDATA_OID)return(NULL);
const U_SERIAL_DESC List[] = {
{&Flags, 4, 1, U_LE},
{&Cap, 4, 1, U_LE},
@@ -2282,8 +2288,8 @@ U_PSEUDO_OBJ *U_PMF_CUSTOMLINECAPOPTIONALDATA_set(const U_PSEUDO_OBJ *Fill, cons
if(Fill && (Fill->Type != U_PMF_FILLPATHOBJ_OID))return(NULL);
if(Line && (Line->Type != U_PMF_LINEPATH_OID))return(NULL);
const U_SERIAL_DESC List[] = {
- {Fill->Data, Fill->Used, 1, U_XE},
- {Line->Data, Line->Used, 1, U_XE},
+ {(Fill ? Fill->Data : NULL), (Fill ? Fill->Used : 0), 1, U_XE},
+ {(Line ? Line->Data : NULL), (Line ? Line->Used : 0), 1, U_XE},
{NULL,0,0,U_XX}
};
U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_CUSTOMLINECAPOPTIONALDATA_OID, List);
@@ -2298,7 +2304,7 @@ U_PSEUDO_OBJ *U_PMF_CUSTOMLINECAPOPTIONALDATA_set(const U_PSEUDO_OBJ *Fill, cons
EMF+ manual 2.2.2.15, Microsoft name: EmfPlusCustomStartCapData Object
*/
U_PSEUDO_OBJ *U_PMF_CUSTOMSTARTCAPDATA_set(const U_PSEUDO_OBJ *Clc){
- if(Clc && (Clc->Type != U_PMF_CUSTOMLINECAP_OID))return(NULL);
+ if(!Clc || Clc->Type != U_PMF_CUSTOMLINECAP_OID)return(NULL);
const U_SERIAL_DESC List[] = {
{Clc->Data, Clc->Used, 1, U_XE},
{NULL,0,0,U_XX}
@@ -2464,7 +2470,7 @@ U_PSEUDO_OBJ *U_PMF_DASHEDLINEDATA_set3(U_FLOAT Unit, uint32_t BitPat){
EMF+ manual 2.2.2.17, Microsoft name: EmfPlusFillPath Object
*/
U_PSEUDO_OBJ *U_PMF_FILLPATHOBJ_set(const U_PSEUDO_OBJ *Path){
- if(Path && (Path->Type != U_PMF_PATH_OID))return(NULL);
+ if(!Path || (Path->Type != U_PMF_PATH_OID))return(NULL);
const U_SERIAL_DESC List[] = {
{Path->Data, Path->Used, 1, U_XE},
{NULL,0,0,U_XX}
@@ -2642,10 +2648,10 @@ U_PSEUDO_OBJ *U_PMF_LINEARGRADIENTBRUSHDATA_set(const U_PMF_LINEARGRADIENTBRUSHD
\brief Create and set a U_PMF_LINEARGRADIENTBRUSHOPTIONALDATA PseudoObject
\return Pointer to PseudoObject, NULL on error
\param Flags Bits are set that indicate which of the following were included. The caller must clear before passing it in.
- \param Tm U_PSEUDO_OBJ containing a U_PMF_TRANSFORMMATRIX object
- \param Bc U_PSEUDO_OBJ containing a U_PMF_BLENDCOLORS object or NULL
- \param BfH U_PSEUDO_OBJ containing a U_PMF_BLENDFACTORS (H) object or NULL
- \param BfV U_PSEUDO_OBJ containing a U_PMF_BLENDFACTORS (V) object or NULL (WARNING, GDI+ defines this field but does not render it. DO NOT USE.)
+ \param Tm (optional) U_PSEUDO_OBJ containing a U_PMF_TRANSFORMMATRIX object
+ \param Bc (optional) U_PSEUDO_OBJ containing a U_PMF_BLENDCOLORS object or NULL
+ \param BfH (optional) U_PSEUDO_OBJ containing a U_PMF_BLENDFACTORS (H) object or NULL
+ \param BfV (optional) U_PSEUDO_OBJ containing a U_PMF_BLENDFACTORS (V) object or NULL (WARNING, GDI+ defines this field but does not render it. DO NOT USE.)
EMF+ manual 2.2.2.25, Microsoft name: EmfPlusLinearGradientBrushOptionalData Object
@@ -2746,7 +2752,7 @@ U_PSEUDO_OBJ *U_PMF_PATHGRADIENTBRUSHDATA_set(uint32_t Flags, int32_t WrapMode,
const U_PSEUDO_OBJ *Gradient, const U_PSEUDO_OBJ *Boundary, const U_PSEUDO_OBJ *Data){
if( (Flags & U_BD_Path) && (!Boundary || (Boundary->Type != U_PMF_BOUNDARYPATHDATA_OID)))return(NULL);
if(!(Flags & U_BD_Path) && (!Boundary || (Boundary->Type != U_PMF_BOUNDARYPOINTDATA_OID)))return(NULL);
- if(!(Gradient) || (Gradient->Type != (U_PMF_ARGB_OID | U_PMF_ARRAY_OID)))return(NULL);
+ if(!Gradient || (Gradient->Type != (U_PMF_ARGB_OID | U_PMF_ARRAY_OID)))return(NULL);
if(!(Flags & U_BD_Transform) &&
!(Flags & U_BD_PresetColors) &&
!(Flags & U_BD_BlendFactorsH) &&
@@ -2925,7 +2931,7 @@ U_PSEUDO_OBJ *U_PMF_PENOPTIONALDATA_set(uint32_t Flags, U_PSEUDO_OBJ *Tm, int32_
if((Flags & U_PD_DLData) && (!DLData || (DLData->Type != U_PMF_DASHEDLINEDATA_OID)) )return(NULL);
if((Flags & U_PD_CLData) && (!CmpndLineData || (CmpndLineData->Type != U_PMF_COMPOUNDLINEDATA_OID)) )return(NULL);
if((Flags & U_PD_CustomStartCap) && (!CSCapData || (CSCapData->Type != U_PMF_CUSTOMSTARTCAPDATA_OID)))return(NULL);
- if((Flags & U_PD_CustomEndCap) &&(!CECapData || (CECapData->Type != U_PMF_CUSTOMENDCAPDATA_OID)) )return(NULL);
+ if((Flags & U_PD_CustomEndCap) && (!CECapData || (CECapData->Type != U_PMF_CUSTOMENDCAPDATA_OID)) )return(NULL);
/* prepend the Flags field to the PseudoObject proper */
const U_SERIAL_DESC List[] = {
@@ -3092,13 +3098,15 @@ U_PSEUDO_OBJ *U_PMF_RECT_set(U_PMF_RECT *Rect){
U_PSEUDO_OBJ *U_PMF_RECTN_set(uint32_t Elements, U_PMF_RECT *Rects){
if(!Rects){ return(NULL); }
uint32_t count = Elements;
- U_SERIAL_DESC *Lptr = (U_SERIAL_DESC *) malloc(4 + (Elements * 2 * 4) + 4);
- U_SERIAL_DESC *List = List;
+ U_SERIAL_DESC *List = (U_SERIAL_DESC *) malloc((Elements + 2) * sizeof(U_SERIAL_DESC));
+ U_SERIAL_DESC *Lptr = List;
if(!List){ return(NULL); }
*Lptr++ = (U_SERIAL_DESC){&Elements, 4, 1, U_LE};
- for(; count; count--, Lptr++, Rects++){ *Lptr = (U_SERIAL_DESC){Rects, 2, 4, U_LE}; }
+ for(; count; count--, Lptr++, Rects++){
+ *Lptr = (U_SERIAL_DESC){Rects, 2, 4, U_LE};
+ }
*Lptr = (U_SERIAL_DESC){NULL,0,0,U_XX};
- U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_RECTF_OID | U_PMF_ARRAY_OID, List);
+ U_PSEUDO_OBJ *po = U_PMF_SERIAL_set(U_PMF_RECT_OID | U_PMF_ARRAY_OID, List);
free(List);
return(po);
}
@@ -3777,6 +3785,7 @@ U_PSEUDO_OBJ *U_PMR_SETCLIPREGION_set(uint32_t PathID, uint32_t CMenum){
*/
U_PSEUDO_OBJ *U_PMR_COMMENT_set(size_t cbData, const void *Data){
if(UP4(cbData) != cbData){ return(NULL); }
+ if(cbData && !Data){ return(NULL); }
int Size=cbData;
U_PSEUDO_OBJ *ph = U_PMR_CMN_HDR_set(U_PMR_COMMENT,0,Size);
@@ -4365,6 +4374,7 @@ U_PSEUDO_OBJ *U_PMR_DRAWSTRING_set(uint32_t FontID, const U_PSEUDO_OBJ *BrushID,
int btype;
if(FontID>63){ return(NULL); }
if(!Length){ return(NULL); }
+ else if (!Text){ return(NULL); }
if(!Rect || Rect->Type != U_PMF_RECTF_OID){ return(NULL); }
if(BrushID){
if( BrushID->Used != 4){ return(NULL); }
@@ -4668,6 +4678,7 @@ U_PSEUDO_OBJ *U_PMR_FILLREGION_set(uint32_t RgnID, const U_PSEUDO_OBJ *BrushID){
\param Po U_PSEUDO_OBJ containing an object type that may be stored in the EMF+ object table
*/
U_PSEUDO_OBJ *U_PMR_OBJECT_PO_set(uint32_t ObjID, U_PSEUDO_OBJ *Po){
+ if(!Po){ return(NULL); }
int otype = U_OID_To_OT(Po->Type); /* This will return 0 if the type is not valid for an object */
if(!otype){ return(NULL); }
U_PSEUDO_OBJ *po = U_PMR_OBJECT_set(ObjID, otype, 0, 0, Po->Used, Po->Data); /* 0,0 = rec. not continued, TSize value (ignored) */
@@ -4703,6 +4714,7 @@ U_PSEUDO_OBJ *U_PMR_OBJECT_set(uint32_t ObjID, int otype, int ntype, uint32_t TS
int Pad = UP4(TSize) - TSize;
if((otype < U_OT_Brush) || (otype > U_OT_CustomLineCap)){ return(NULL); }
if(ntype && (cbData > U_OBJRECLIM)){ return(NULL); }
+ if(!Data){ return(NULL); }
U_PSEUDO_OBJ *po;
if(!ntype && !TSize && (cbData > U_OBJRECLIM)){
@@ -6268,11 +6280,11 @@ int U_PMF_POINTR_get(const char **contents, U_FLOAT *X, U_FLOAT *Y){
\param Points Caller must free. Array of U_PMF_POINTF coordinates.
*/
int U_PMF_VARPOINTS_get(const char **contents, uint16_t Flags, int Elements, U_PMF_POINTF **Points){
+ if(!contents || !*contents || !Points || !Elements){ return(0); }
U_PMF_POINTF *pts = (U_PMF_POINTF *)malloc(Elements * sizeof(U_PMF_POINTF));
U_FLOAT XF, YF;
U_FLOAT XFS, YFS;
- if(!contents || !*contents || !Points){ return(0); }
*Points = pts;
for(XFS = YFS = 0.0; Elements; Elements--, pts++){
if(Flags & U_PPF_P){
diff --git a/src/libuemf/upmf_print.c b/src/libuemf/upmf_print.c
index f446d6caf..13bbfade8 100644
--- a/src/libuemf/upmf_print.c
+++ b/src/libuemf/upmf_print.c
@@ -6,11 +6,11 @@
/*
File: upmf_print.c
-Version: 0.0.2
-Date: 17-OCT-2013
+Version: 0.0.3
+Date: 24-MAR-2014
Author: David Mathog, Biology Division, Caltech
email: mathog@caltech.edu
-Copyright: 2013 David Mathog and California Institute of Technology (Caltech)
+Copyright: 2014 David Mathog and California Institute of Technology (Caltech)
*/
/* compiler options:
@@ -790,7 +790,6 @@ int U_PMF_BLENDCOLORS_print(const char *contents){
const char *Colors;
int status = U_PMF_BLENDCOLORS_get(contents, &Elements, &Positions, &Colors);
if(status){
- status = 0;
printf(" + BlendColors: Entries:%d (entry,pos,color): ", Elements);
for(i=0; i<Elements; i++){
printf(" (%d,%f,", i, Positions[i]);
diff --git a/src/libuemf/uwmf.c b/src/libuemf/uwmf.c
index be1feadea..82be9f324 100644
--- a/src/libuemf/uwmf.c
+++ b/src/libuemf/uwmf.c
@@ -19,8 +19,8 @@
/*
File: uwmf.c
-Version: 0.0.13
-Date: 30-JAN-2014
+Version: 0.0.14
+Date: 24-MAR-2014
Author: David Mathog, Biology Division, Caltech
email: mathog@caltech.edu
Copyright: 2014 David Mathog and California Institute of Technology (Caltech)
@@ -327,9 +327,9 @@ uint32_t U_wmr_values(int idx){
\param idx WMR record type.
*/
-char *U_wmr_names(int idx){
+const char *U_wmr_names(int idx){
int ret;
- static char *U_WMR_NAMES[257]={
+ static const char *U_WMR_NAMES[257]={
"U_WMR_EOF",
"U_WMR_SETBKCOLOR",
"U_WMR_SETBKMODE",
@@ -597,8 +597,8 @@ char *U_wmr_names(int idx){
\return name of the WMR record, "UNKNOWN_ESCAPE" if out of range.
\param idx Escape record type.
*/
-char *U_wmr_escnames(int idx){
- char *name;
+const char *U_wmr_escnames(int idx){
+ const char *name;
if(idx>=0 && idx <= 0x0023){
switch(idx){
case 0x0001: name = "NEWFRAME"; break;
@@ -1461,6 +1461,7 @@ int wmf_start(
wtl->chunk = chunksize;
wtl->largest = 0; /* only used by WMF */
wtl->sumObjects = 0; /* only used by WMF */
+ (void) wmf_highwater(U_HIGHWATER_CLEAR);
*wt=wtl;
return(0);
}
@@ -1480,6 +1481,7 @@ int wmf_free(
free(wtl->buf);
free(wtl);
*wt=NULL;
+ (void)wmf_highwater(U_HIGHWATER_CLEAR);
return(0);
}
@@ -1509,8 +1511,9 @@ int wmf_finish(
memcpy(record + offsetof(U_WMRHEADER,Sizew), &tmp, 4); /* 16 bit words in file. not aligned */
tmp = (wt->largest)/2;
memcpy(record + offsetof(U_WMRHEADER,maxSize), &tmp, 4); /* 16 bit words in largest record, not aligned */
- if(wt->sumObjects > UINT16_MAX)return(3);
- tmp16 = wt->sumObjects;
+ uint32_t maxobj = wmf_highwater(U_HIGHWATER_READ);
+ if(maxobj > UINT16_MAX)return(3);
+ tmp16 = maxobj;
memcpy(record + offsetof(U_WMRHEADER,nObjects), &tmp16, 2); /* Total number of brushes, pens, and other graphics objects defined in this file */
#if U_BYTE_SWAP
@@ -1654,6 +1657,28 @@ int wmf_header_append(
}
/**
+ \brief Keep track of the largest number used.
+ \return The largest object number used.
+ \param setval U_HIGHWATER_READ only return value, U_HIGHWATER_CLEAR also set value to 0, anything else, set to this if higher than stored.
+*/
+int wmf_highwater(uint32_t setval){
+ static uint32_t value=0;
+ uint32_t retval;
+ if(setval == U_HIGHWATER_READ){
+ retval = value;
+ }
+ else if(setval == U_HIGHWATER_CLEAR){
+ retval = value;
+ value = 0;
+ }
+ else {
+ if(setval > value)value = setval;
+ retval = value;
+ }
+ return(retval);
+}
+
+/**
\brief Create a handle table. Entries filled with 0 are empty, entries >0 hold a handle.
\return 0 for success, >=1 for failure.
\param initsize Initialize with space for this number of handles
@@ -1736,8 +1761,13 @@ int wmf_htable_insert(
}
*ih = wht->lolimit; // handle that is inserted in first available slot
wht->table[*ih] = *ih; // handle goes into preexisting (but zero) slot in table, handle number is the same as the slot number
- if(*ih > wht->hilimit){ wht->hilimit = *ih; }
- if(*ih > wht->peak){ wht->peak = *ih; }
+ if(*ih > wht->hilimit){
+ wht->hilimit = *ih;
+ (void) wmf_highwater(wht->hilimit);
+ }
+ if(*ih > wht->peak){
+ wht->peak = *ih;
+ }
/* Find the next available slot, it will be at least one higher than the present position, and will have a zero in it. */
wht->lolimit++;
while(wht->lolimit<= wht->hilimit && wht->table[wht->lolimit]){ wht->lolimit++; }
@@ -2034,7 +2064,7 @@ char *U_WMRCORE_PALETTE_set(
off = U_SIZE_METARECORD;
memcpy(record+off, &Palette->Start, 2); off+=2;
memcpy(record+off, &Palette->NumEntries, 2); off+=2;
- memcpy(record+off, &Palette->PalEntries, nPE); off+=2;
+ memcpy(record+off, &Palette->PalEntries, nPE);
}
return(record);
}
@@ -2157,9 +2187,9 @@ char *wcreatedibpatternbrush_srcdib_set(
}
/**
- \brief Allocate and construct a U_WMRCREATEPATTERNBRUSH record from a U_BITMAP16 object.
- Use this function instead of calling U_WMRCREATEPATTERNBRUSH_set() directly.
- \return pointer to the U_WMRCREATEPATTERNBRUSH record, or NULL on error.
+ \brief Allocate and construct a U_WMRDIBCREATEPATTERNBRUSH record from a U_BITMAP16 object.
+ Use this function instead of calling U_WMRDIBCREATEPATTERNBRUSH_set() directly.
+ \return pointer to the U_WMRDIBCREATEPATTERNBRUSH record, or NULL on error.
\param ihBrush handle to be used by new object
\param wht WMF handle table
\param iUsage DIBColors enumeration
@@ -2179,7 +2209,8 @@ char *wcreatedibpatternbrush_srcbm16_set(
/**
\brief Allocate and construct a U_WMRCREATEPATTERNBRUSH record, create a handle and returns it
Use this function instead of calling U_WMRCREATEPATTERNBRUSH_set() directly.
- Warning - application support for U_WMRCREATEPATTERNBRUSH is spotty, better to use U_WMRDIBCREATEPATTERNBRUSH.
+ WARNING - U_WMRCREATEPATTERNBRUSH has been declared obsolete and application support is spotty -
+ use U_WMRDIBCREATEPATTERNBRUSH instead.
\return pointer to the U_WMRCREATEPATTERNBRUSH record, or NULL on error.
\param ihBrush handle to be used by new object
\param wht WMF handle table
@@ -2804,13 +2835,13 @@ char *U_WMRTEXTOUT_set(U_POINT16 Dst, char *string){
if(record){
U_WMRCORE_SETRECHEAD(record,irecsize,U_WMR_TEXTOUT);
off = U_SIZE_METARECORD;
- memcpy(record+off,&Length,2); off+=2;
- memcpy(record+off,string,Length); off+=Length;
+ memcpy(record+off,&Length,2); off+=2;
+ memcpy(record+off,string,Length); off+=Length;
if(Length!=L2){
- memset(record+off,0,1); off+=1;
+ memset(record+off,0,1); off+=1;
}
- memcpy(record+off,&Dst.y,2); off+=2;
- memcpy(record+off,&Dst.x,2); off+=2;
+ memcpy(record+off,&Dst.y,2); off+=2;
+ memcpy(record+off,&Dst.x,2);
}
return(record);
}
@@ -3427,7 +3458,7 @@ char *U_WMRDIBCREATEPATTERNBRUSH_set(
if(cbBm164 - cbBm16)memset(record+off,0,cbBm164 - cbBm16);
}
}
- else if(Bmi){
+ else if(Bmi && Px){
SET_CB_FROM_PXBMI(Px,Bmi,cbImage,cbImage4,cbBmi,cbPx);
irecsize = U_SIZE_WMRDIBCREATEPATTERNBRUSH + cbBmi + cbImage4;
record = malloc(irecsize);
@@ -4257,7 +4288,8 @@ char *U_WMRF8_set(void){
/**
\brief Allocate and construct a U_WMRCREATEPATTERNBRUSH record.
- Warning - application support for U_WMRCREATEPATTERNBRUSH is spotty, better to use U_WMRDIBCREATEPATTERNBRUSH.
+ WARNING - U_WMRCREATEPATTERNBRUSH has been declared obsolete and application support is spotty -
+ use U_WMRDIBCREATEPATTERNBRUSH instead.
\return pointer to the U_WMRCREATEPATTERNBRUSH record, or NULL on error.
\param Bm16 Pointer to a Bitmap16 Object, only the first 10 bytes are used.
\param Pattern byte array pattern, described by Bm16, for brush
@@ -4450,23 +4482,17 @@ int U_WMRCORE_RECSAFE_get(
/* records like U_WMRFLOODFILL and others. all args are optional, Color is not */
int U_WMRCORE_1U16_CRF_2U16_get(
const char *contents,
- int minsize,
uint16_t *arg1,
U_COLORREF *Color,
uint16_t *arg2,
uint16_t *arg3
){
- int size = U_WMRCORE_RECSAFE_get(contents, minsize);
- int irecsize,off;
- irecsize = U_SIZE_METARECORD + U_SIZE_COLORREF;
- if(arg1)irecsize+=2;
- if(arg2)irecsize+=2;
- if(arg3)irecsize+=2;
- off = U_SIZE_METARECORD;
- if(arg1){ memcpy(arg1, contents + off, 2); off+=2; }
- memcpy(Color, contents + off, 4); off+=4;
- if(arg2){ memcpy(arg2, contents + off, 2); off+=2; }
- if(arg3){ memcpy(arg3, contents + off, 2); off+=2; }
+ int size = 0;
+ int off = U_SIZE_METARECORD;
+ if(arg1){ memcpy(arg1, contents + off, 2); off+=2; size+=2;}
+ memcpy(Color, contents + off, 4); off+=4; size+=4;
+ if(arg2){ memcpy(arg2, contents + off, 2); off+=2; size+=2;}
+ if(arg3){ memcpy(arg3, contents + off, 2); size+=2;}
return(size);
}
@@ -5191,7 +5217,6 @@ int U_WMRFLOODFILL_get(
){
return U_WMRCORE_1U16_CRF_2U16_get(
contents,
- (U_SIZE_WMRFLOODFILL),
Mode,
Color,
U_P16(coord->y),
@@ -5321,7 +5346,6 @@ int U_WMRSETPIXEL_get(
U_POINT16 *Coord){
return U_WMRCORE_1U16_CRF_2U16_get(
contents,
- (U_SIZE_WMRSETPIXEL),
NULL,
Color,
U_P16(Coord->y),
@@ -5366,7 +5390,7 @@ int U_WMRTEXTOUT_get(
if(L2 & 1)L2++;
off = U_SIZE_METARECORD + 2 + L2;
memcpy(&Dst->y, contents + off, 2); off+=2;
- memcpy(&Dst->x, contents + off, 2); off+=2;
+ memcpy(&Dst->x, contents + off, 2);
return(size);
}
@@ -5982,6 +6006,8 @@ int U_WMRDIBSTRETCHBLT_get(
/**
\brief Get data from a U_WMRDIBCREATEPATTERNBRUSH record.
Returns an image as either a DIB (Bmi/CbPx/Px defined) or a Bitmap16 (Bm16 defined).
+ WARNING - U_WMRCREATEPATTERNBRUSH has been declared obsolete and application support is spotty -
+ this function is still valid though, for those instances where old WMF input files are encountered.
\return length of the U_WMRDIBCREATEPATTERNBRUSH record in bytes, or 0 on error
\param contents record to extract data from
\param Style BrushStyle Enumeration
@@ -6096,7 +6122,6 @@ int U_WMREXTFLOODFILL_get(
){
return U_WMRCORE_1U16_CRF_2U16_get(
contents,
- (U_SIZE_WMREXTFLOODFILL),
Mode,
Color,
U_P16(coord->y),
diff --git a/src/libuemf/uwmf.h b/src/libuemf/uwmf.h
index 65424cad1..54f7f36fe 100644
--- a/src/libuemf/uwmf.h
+++ b/src/libuemf/uwmf.h
@@ -36,11 +36,11 @@
/*
File: uwmf.h
-Version: 0.0.8
-Date: 27-FEB-2013
+Version: 0.0.10
+Date: 24-MAR-2014
Author: David Mathog, Biology Division, Caltech
email: mathog@caltech.edu
-Copyright: 2013 David Mathog and California Institute of Technology (Caltech)
+Copyright: 2014 David Mathog and California Institute of Technology (Caltech)
*/
#ifndef _UWMF_
@@ -60,6 +60,13 @@ extern "C" {
#include "uwmf_endian.h"
+/** HighWater Enumeration not in WMF manual
+ @{
+*/
+#define U_HIGHWATER_READ 0x00000000 //!< nondestructive read of highwater value
+#define U_HIGHWATER_CLEAR 0xFFFFFFFF //!< destructive read, value is reset to 0
+/** @} */
+
@@ -1959,6 +1966,9 @@ typedef struct {
/* Index F9 U_WMRCREATEPATTERNBRUSH WMF manual 2.3.4.4 */
/** WMF manual 2.3.4.4
+ WARNING - U_WMRCREATEPATTERNBRUSH has been declared obsolete and application support is spotty -
+ use U_WMRDIBCREATEPATTERNBRUSH instead.
+
This record is peculiar...
After the core structure there is:
@@ -2040,7 +2050,7 @@ typedef struct {
uint32_t chunk; //!< Number of bytes to add when more space is needed
char *buf; //!< Buffer for constructing the EMF in memory
uint32_t largest; //!< Largest record size, in bytes (used by WMF, not by EMF)
- uint32_t sumObjects; //!< Number of objects created (used by WMF, not by EMF)
+ uint32_t sumObjects; //!< Number of objects appended (used by WMF, not by EMF) [ also see wmf_highwater() ]
} WMFTRACK;
/**
@@ -2072,6 +2082,7 @@ int wmf_append(U_METARECORD *rec, WMFTRACK *wt, int freerec);
int wmf_header_append(U_METARECORD *rec,WMFTRACK *et, int freerec);
int wmf_readdata(const char *filename, char **contents, size_t*length);
#define wmf_fopen emf_fopen
+int wmf_highwater(uint32_t setval);
int wmf_htable_create(uint32_t initsize, uint32_t chunksize, WMFHANDLES **wht);
int wmf_htable_delete(uint32_t *ih, WMFHANDLES *wht);
int wmf_htable_insert(uint32_t *ih, WMFHANDLES *wht);
@@ -2082,8 +2093,8 @@ uint32_t U_wmr_properties(uint32_t type);
uint32_t U_wmr_size(const U_METARECORD *record);
uint32_t U_wmr_values(int idx);
-char *U_wmr_names(int idx);
-char *U_wmr_escnames(int idx);
+const char *U_wmr_names(int idx);
+const char *U_wmr_escnames(int idx);
void U_sanerect16(U_RECT16 rc, double *left, double *top, double *right, double *bottom);
diff --git a/src/libuemf/uwmf_print.c b/src/libuemf/uwmf_print.c
index d120a2da0..0e089a5cd 100644
--- a/src/libuemf/uwmf_print.c
+++ b/src/libuemf/uwmf_print.c
@@ -6,11 +6,11 @@
/*
File: uwmf_print.c
-Version: 0.0.3
-Date: 17-OCT-2013
+Version: 0.0.4
+Date: 05-FEB-2014
Author: David Mathog, Biology Division, Caltech
email: mathog@caltech.edu
-Copyright: 2012 David Mathog and California Institute of Technology (Caltech)
+Copyright: 2014 David Mathog and California Institute of Technology (Caltech)
*/
#ifdef __cplusplus
@@ -715,7 +715,7 @@ void U_WMRTEXTOUT_print(const char *contents){
U_POINT16 Dst;
int size = U_WMRTEXTOUT_get(contents, &Dst, &Length, &string);
if(size > 0){
- printf(" X,Y:{%d,%d}\n", Dst.y,Dst.x); /* y/x order in record is reversed, fix that here */
+ printf(" X,Y:{%d,%d}\n", Dst.x,Dst.y);
printf(" Length:%d\n", Length);
printf(" String:<%.*s>\n", Length, string); /* May not be null terminated */
}