WP2LaTeX sources.
Revision | 6d09b5fe105812fe7466fd5af91481415036469f (tree) |
---|---|
Zeit | 2022-08-20 19:13:59 |
Autor | Fojtik |
Commiter | Fojtik |
Added reference counting for vector attributes.
@@ -12,6 +12,7 @@ | ||
12 | 12 | #ifndef __Safe_strchr |
13 | 13 | |
14 | 14 | #ifdef __Strict_Const_Procs |
15 | + | |
15 | 16 | const char *StrChr(const char *s, int c) |
16 | 17 | { |
17 | 18 | if(s==NULL) return(NULL); |
@@ -166,7 +166,14 @@ | ||
166 | 166 | |
167 | 167 | class VectorAttribute |
168 | 168 | { |
169 | -public: | |
169 | +protected: | |
170 | + mutable int RefCounter; | |
171 | + | |
172 | +public: | |
173 | + void AddRef(void) {RefCounter++;} | |
174 | + void Release(void) {if(--RefCounter<=0) delete this;} | |
175 | + | |
176 | + VectorAttribute() {RefCounter=1;} | |
170 | 177 | virtual ~VectorAttribute() {} |
171 | 178 | virtual void prepExport(PS_State *PSS) const = 0; |
172 | 179 | virtual int getAttribType(void) const {return ATTR_NONE;}; |
@@ -79,8 +79,8 @@ | ||
79 | 79 | WORD pidx; /* index down password */ |
80 | 80 | BYTE xmask; /* XOR mask */ |
81 | 81 | DWORD len; |
82 | -DWORD pos=ftell(Encrypted); | |
83 | -DWORD fsize=filesize(Encrypted); | |
82 | +DWORD pos = ftell(Encrypted); | |
83 | +DWORD fsize = filesize(Encrypted); | |
84 | 84 | |
85 | 85 | if(ErrorFile==NULL) ErrorFile=stderr; |
86 | 86 | if((buf=(char *)malloc(4096))==NULL) return; |
@@ -89,14 +89,14 @@ | ||
89 | 89 | pidx = 0; /* start of password */ |
90 | 90 | xmask = length(PassWord)+1; /* start at password length+1 */ |
91 | 91 | |
92 | - if (Verbosing >= 1) printf(_("\nDecrypting ...\n\n")); | |
92 | + if(Verbosing >= 1) printf(_("\nDecrypting ...\n\n")); | |
93 | 93 | |
94 | - while( pos<fsize ) | |
94 | + while(pos<fsize) | |
95 | 95 | { |
96 | - if( fsize-pos > 4096 ) len = 4096; | |
97 | - else len = fsize-pos; | |
96 | + if(fsize-pos > 4096) len = 4096; | |
97 | + else len = fsize-pos; | |
98 | 98 | |
99 | - if( fread( buf, 1, len, Encrypted ) !=len ) | |
99 | + if(fread( buf, 1, len, Encrypted ) !=len) | |
100 | 100 | { |
101 | 101 | fprintf(ErrorFile,_("\nError: Unexpected end of the input file.")); |
102 | 102 | break; |
@@ -108,9 +108,9 @@ | ||
108 | 108 | if( pidx == length(PassWord) ) pidx = 0; |
109 | 109 | } |
110 | 110 | |
111 | - if( Decrypted ) | |
111 | + if(Decrypted) | |
112 | 112 | { |
113 | - if( fwrite( buf, 1, len, Decrypted ) !=len ) | |
113 | + if(fwrite( buf, 1, len, Decrypted ) !=len) | |
114 | 114 | { |
115 | 115 | fprintf(ErrorFile,_("\nError: Couldn't write %lu bytes to the temporary file.\n"), (long unsigned)len); |
116 | 116 | break; |
@@ -132,19 +132,19 @@ | ||
132 | 132 | WORD encryption; |
133 | 133 | string temp_filename; |
134 | 134 | DWORD DocumentStart; /* position in file */ |
135 | -FILE *DecryptedFile=NULL; | |
135 | +FILE *DecryptedFile = NULL; | |
136 | 136 | BYTE SmallBuf[16]; |
137 | 137 | TconvertedPass1 *cqPass1; |
138 | 138 | int RetVal=0; |
139 | 139 | |
140 | - cqPass1=GetConverter("WP5.x"); | |
140 | + cqPass1 = GetConverter("WP5.x"); | |
141 | 141 | if(cqPass1==NULL) |
142 | 142 | { |
143 | 143 | RunError(0x202,"WP5.x"); /* unsupported module wp5 */ |
144 | 144 | return(-1); |
145 | 145 | } |
146 | 146 | |
147 | - DocumentStart=ftell(wpd); | |
147 | + DocumentStart = ftell(wpd); | |
148 | 148 | fseek(wpd,12,SEEK_SET); //check for encrypted documents |
149 | 149 | |
150 | 150 | RdWORD_HiEnd(&encryption, wpd); |
@@ -218,7 +218,7 @@ | ||
218 | 218 | TconvertedPass1 *cqPass1; |
219 | 219 | int RetVal=0; |
220 | 220 | |
221 | - cqPass1=GetConverter("WP3.x"); | |
221 | + cqPass1 = GetConverter("WP3.x"); | |
222 | 222 | if(cqPass1==NULL) |
223 | 223 | { |
224 | 224 | RunError(0x202,"WP3.x"); /* unsupported module wp3 */ |
@@ -173,7 +173,8 @@ | ||
173 | 173 | VectorAttribute **Attributes; |
174 | 174 | unsigned Count; |
175 | 175 | |
176 | - ObjectTable() {Count=0; Attributes=NULL;} | |
176 | + ObjectTable() {Count=0; Attributes=NULL;} | |
177 | + ObjectTable(ObjectTable &OT); | |
177 | 178 | ~ObjectTable(); |
178 | 179 | |
179 | 180 | void AddObject(VectorAttribute *NewAttr); |
@@ -182,6 +183,25 @@ | ||
182 | 183 | }; |
183 | 184 | |
184 | 185 | |
186 | +ObjectTable::ObjectTable(ObjectTable &OT) | |
187 | +{ | |
188 | + if(OT.Count==0 || OT.Attributes==NULL) | |
189 | + { | |
190 | + Attributes = NULL; | |
191 | +AllocationError: | |
192 | + Count = 0; | |
193 | + return; | |
194 | + } | |
195 | + Attributes = (VectorAttribute**)malloc(OT.Count*sizeof(VectorAttribute*)); | |
196 | + if(Attributes==NULL) goto AllocationError; | |
197 | + for(Count=0; Count<OT.Count; Count++) | |
198 | + { | |
199 | + Attributes[Count] = OT.Attributes[Count]; | |
200 | + if(Attributes[Count]!=NULL) Attributes[Count]->AddRef(); | |
201 | + } | |
202 | +} | |
203 | + | |
204 | + | |
185 | 205 | ObjectTable::~ObjectTable() |
186 | 206 | { |
187 | 207 | if(Count>0) |
@@ -190,7 +210,7 @@ | ||
190 | 210 | { |
191 | 211 | for(unsigned i=0; i<Count; i++) |
192 | 212 | { |
193 | - delete Attributes[i]; | |
213 | + Attributes[i]->Release(); | |
194 | 214 | Attributes[i] = NULL; |
195 | 215 | } |
196 | 216 | free(Attributes); |
@@ -210,7 +230,7 @@ | ||
210 | 230 | Attributes = (VectorAttribute**)malloc(sizeof(VectorAttribute*)); |
211 | 231 | if(Attributes==NULL) |
212 | 232 | { |
213 | - delete NewAttr; | |
233 | + NewAttr->Release(); | |
214 | 234 | return; |
215 | 235 | } |
216 | 236 | Attributes[0] = NewAttr; |
@@ -239,7 +259,7 @@ | ||
239 | 259 | void ObjectTable::DeleteObject(unsigned ObjectIndex) |
240 | 260 | { |
241 | 261 | if(ObjectIndex>=Count || Attributes==NULL) return; |
242 | - delete Attributes[ObjectIndex]; | |
262 | + Attributes[ObjectIndex]->Release(); | |
243 | 263 | Attributes[ObjectIndex] = NULL; |
244 | 264 | } |
245 | 265 |
@@ -2267,6 +2287,7 @@ | ||
2267 | 2287 | void parse_PolyPolygon16(VectorList &VectList); |
2268 | 2288 | void parse_PolyPolyLine16(VectorList &VectList); |
2269 | 2289 | void parse_Rectangle(VectorList &VectList); |
2290 | + void parse_SaveDC(void); | |
2270 | 2291 | void parse_SelectObject(void); |
2271 | 2292 | void parse_SelectPalette(void); |
2272 | 2293 | void parse_SetBkColor(void); |
@@ -3714,6 +3735,23 @@ | ||
3714 | 3735 | } |
3715 | 3736 | |
3716 | 3737 | |
3738 | +void TconvertedPass1_EMF::parse_SaveDC(void) | |
3739 | +{ | |
3740 | +#ifdef DEBUG | |
3741 | + fprintf(log,"\n#TconvertedPass1_EMF::parse_SaveDC() ");fflush(log); | |
3742 | +#endif | |
3743 | +static const char ObjName[] = "!SAVEDC"; | |
3744 | + | |
3745 | + if(EmfRec.Size < 8) | |
3746 | + { | |
3747 | + strcpy(ObjType,ObjName); | |
3748 | + return; | |
3749 | + } | |
3750 | + | |
3751 | + strcpy(ObjType,ObjName); | |
3752 | +} | |
3753 | + | |
3754 | + | |
3717 | 3755 | void TconvertedPass1_EMF::parse_SetTextColor(void) |
3718 | 3756 | { |
3719 | 3757 | #ifdef DEBUG |
@@ -3942,7 +3980,7 @@ | ||
3942 | 3980 | case EMR_INTERSECTCLIPRECT: strcpy(ObjType,"!INTERSECTCLIPRECT"); break; // 0x0000001E |
3943 | 3981 | case EMR_SCALEVIEWPORTEXTEX: strcpy(ObjType,"!SCALEVIEWPORTEXTEX"); break; // 0x0000001F |
3944 | 3982 | case EMR_SCALEWINDOWEXTEX: strcpy(ObjType,"!SCALEWINDOWEXTEX"); break; // 0x00000020 |
3945 | - case EMR_SAVEDC: strcpy(ObjType,"!SAVEDC"); break; // 0x00000021 | |
3983 | + case EMR_SAVEDC: parse_SaveDC(); break; // 0x00000021 | |
3946 | 3984 | case EMR_RESTOREDC: strcpy(ObjType,"!RESTOREDC"); break; // 0x00000022 |
3947 | 3985 | case EMR_SETWORLDTRANSFORM: parse_SetWorldTransform(); break; // 0x00000023 |
3948 | 3986 | case EMR_MODIFYWORLDTRANSFORM: parse_ModifyWorldTransform(); break; // 0x00000024 |