Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <vcl/graph.hxx>
22 : #include <tools/poly.hxx>
23 : #include <vcl/virdev.hxx>
24 : #include <vcl/lineinfo.hxx>
25 :
26 : #include <math.h>
27 :
28 : class FilterConfigItem;
29 :
30 : // MT: NOOLDSV, someone should change the code...
31 : enum PenStyle { PEN_NULL, PEN_SOLID, PEN_DOT, PEN_DASH, PEN_DASHDOT };
32 :
33 :
34 : //============================== defines ===================================
35 :
36 : #define OOODEBUG(str,Num) //InfoBox(NULL,String(str)+String(" ")+String(Num)).Execute();
37 :
38 : // -----------------------------Feld-Typen-------------------------------
39 :
40 : #define BegDocumnMagic 0xA8A8 /* Begin Document */
41 : #define EndDocumnMagic 0xA8A9 /* End Document */
42 :
43 : #define BegResGrpMagic 0xC6A8 /* Begin Resource Group */
44 : #define EndResGrpMagic 0xC6A9 /* End Resource Group */
45 :
46 : #define BegColAtrMagic 0x77A8 /* Begin Color Attribute Table */
47 : #define EndColAtrMagic 0x77A9 /* End Color Attribute Table */
48 : #define BlkColAtrMagic 0x77B0 /* Color Attribute Table */
49 : #define MapColAtrMagic 0x77AB /* Map Color Attribute Table */
50 :
51 : #define BegImgObjMagic 0xFBA8 /* Begin Image Object */
52 : #define EndImgObjMagic 0xFBA9 /* End Image Object */
53 : #define DscImgObjMagic 0xFBA6 /* Image Data Descriptor */
54 : #define DatImgObjMagic 0xFBEE /* Image Picture Data */
55 :
56 : #define BegObEnv1Magic 0xC7A8 /* Begin Object Environment Group */
57 : #define EndObEnv1Magic 0xC7A9 /* End Object Environment Group */
58 :
59 : #define BegGrfObjMagic 0xBBA8 /* Begin Graphics Object */
60 : #define EndGrfObjMagic 0xBBA9 /* End Graphics Object */
61 : #define DscGrfObjMagic 0xBBA6 /* Graphics Data Descritor */
62 : #define DatGrfObjMagic 0xBBEE /* Graphics Data */
63 :
64 : #define MapCodFntMagic 0x8AAB /* Map Coded Font */
65 : #define MapDatResMagic 0xC3AB /* Map Data Resource */
66 :
67 : // -----------------------------Order-Typen-------------------------------
68 :
69 : #define GOrdGivArc 0xC6 /* 1 Arc at given position */
70 : #define GOrdCurArc 0x86 /* 1 Arc at current position */
71 : #define GOrdGivBzr 0xE5 /* 1 Beziercurve at given position */
72 : #define GOrdCurBzr 0xA5 /* 1 Beziercurve at current position */
73 : #define GOrdGivBox 0xC0 /* 1 Box at given position */
74 : #define GOrdCurBox 0x80 /* 1 Box at current position */
75 : #define GOrdGivFil 0xC5 /* 1 Fillet at given position */
76 : #define GOrdCurFil 0x85 /* 1 Fillet at current position */
77 : #define GOrdGivCrc 0xC7 /* 1 Full arc (circle) at given position */
78 : #define GOrdCurCrc 0x87 /* 1 Full arc (circle) at current position */
79 : #define GOrdGivLin 0xC1 /* 1 Line at given position */
80 : #define GOrdCurLin 0x81 /* 1 Line at current position */
81 : #define GOrdGivMrk 0xC2 /* 1 Marker at given position */
82 : #define GOrdCurMrk 0x82 /* 1 Marker at current position */
83 : #define GOrdGivArP 0xE3 /* 1 Partial arc at given position */
84 : #define GOrdCurArP 0xA3 /* 1 Partial arc at current position */
85 : #define GOrdGivRLn 0xE1 /* 1 Relative line at given position */
86 : #define GOrdCurRLn 0xA1 /* 1 Relative line at current position */
87 : #define GOrdGivSFl 0xE4 /* 1 Sharp fillet at given position */
88 : #define GOrdCurSFl 0xA4 /* 1 Sharp fillet at current position */
89 :
90 : #define GOrdGivStM 0xF1 /* 1 Character string move at given position */
91 : #define GOrdCurStM 0xB1 /* 1 Character string move at current position */
92 : #define GOrdGivStr 0xC3 /* 1 Character string at given position */
93 : #define GOrdCurStr 0x83 /* 1 Character string at current position */
94 : #define GOrdGivStx 0xFEF0 /* 2 Character string extended at given position */
95 : #define GOrdCurStx 0xFEB0 /* 2 Character string extended at current position */
96 :
97 : #define GOrdGivImg 0xD1 /* 1 Begin Image at given position */
98 : #define GOrdCurImg 0x91 /* 1 Begin Image at current position */
99 : #define GOrdImgDat 0x92 /* 1 Image data */
100 : #define GOrdEndImg 0x93 /* 1 End Image */
101 : #define GOrdBegAra 0x68 /* 0 1 Begin area */
102 : #define GOrdEndAra 0x60 /* 1 End area */
103 : #define GOrdBegElm 0xD2 /* 1 Begin element */
104 : #define GOrdEndElm 0x49 /* 0 1 End element */
105 :
106 : #define GOrdBegPth 0xD0 /* 1 Begin path */
107 : #define GOrdEndPth 0x7F /* 0 1 End path */
108 : #define GOrdFilPth 0xD7 /* 1 Fill path */
109 : #define GOrdModPth 0xD8 /* 1 Modify path */
110 : #define GOrdOutPth 0xD4 /* 1 Outline path */
111 : #define GOrdSClPth 0xB4 /* 1 Set clip path */
112 :
113 : #define GOrdNopNop 0x00 /* 0 0 No operation */
114 : #define GOrdRemark 0x01 /* 1 Comment */
115 : #define GOrdSegLab 0xD3 /* 1 Label */
116 : #define GOrdBitBlt 0xD6 /* 1 Bitblt */
117 : #define GOrdCalSeg 0x07 /* 1 Call Segment */
118 : #define GOrdSSgBnd 0x32 /* 1 Set segment boundary */
119 : #define GOrdSegChr 0x04 /* 1 Segment characteristics */
120 : #define GOrdCloFig 0x7D /* 0 1 Close Figure */
121 : #define GOrdEndSym 0xFF /* 0 0 End of symbol definition */
122 : #define GOrdEndPlg 0x3E /* 0 1 End prolog */
123 : #define GOrdEscape 0xD5 /* 1 Escape */
124 : #define GOrdExtEsc 0xFED5 /* 2 Extended Escape */
125 : #define GOrdPolygn 0xF3 /* 2 Polygons */
126 :
127 : #define GOrdStkPop 0x3F /* 0 1 Pop */
128 :
129 : #define GOrdSIvAtr 0x14 /* 1 Set individual attribute */
130 : #define GOrdPIvAtr 0x54 /* 1 Push and set individual attribute */
131 : #define GOrdSColor 0x0A /* 0 1 Set color */
132 : #define GOrdPColor 0x4A /* 0 1 Push and set color */
133 : #define GOrdSIxCol 0xA6 /* 1 Set indexed color */
134 : #define GOrdPIxCol 0xE6 /* 1 Push and set indexed color */
135 : #define GOrdSXtCol 0x26 /* 1 Set extended color */
136 : #define GOrdPXtCol 0x66 /* 1 Push and set extended color */
137 : #define GOrdSBgCol 0x25 /* 1 Set background color */
138 : #define GOrdPBgCol 0x65 /* 1 Push and set background color */
139 : #define GOrdSBxCol 0xA7 /* 1 Set background indexed color */
140 : #define GOrdPBxCol 0xE7 /* 1 Push and set background indexed color */
141 : #define GOrdSMixMd 0x0C /* 0 1 Set mix */
142 : #define GOrdPMixMd 0x4C /* 0 1 Push and set mix */
143 : #define GOrdSBgMix 0x0D /* 0 1 Set background mix */
144 : #define GOrdPBgMix 0x4D /* 0 1 Push and set background mix */
145 :
146 : #define GOrdSPtSet 0x08 /* 0 1 Set pattern set */
147 : #define GOrdPPtSet 0x48 /* 0 1 Push and set pattern set */
148 : #define GOrdSPtSym 0x28 /* 0 1 Set pattern symbol */
149 : #define GOrdPPtSym 0x09 /* 0 1 Push and set pattern symbol */
150 : #define GOrdSPtRef 0xA0 /* 1 Set model pattern reference */
151 : #define GOrdPPtRef 0xE0 /* 1 Push and set pattern reference point */
152 :
153 : #define GOrdSLnEnd 0x1A /* 0 1 Set line end */
154 : #define GOrdPLnEnd 0x5A /* 0 1 Push and set line end */
155 : #define GOrdSLnJoi 0x1B /* 0 1 Set line join */
156 : #define GOrdPLnJoi 0x5B /* 0 1 Push and set line join */
157 : #define GOrdSLnTyp 0x18 /* 0 1 Set line type */
158 : #define GOrdPLnTyp 0x58 /* 0 1 Push and set line type */
159 : #define GOrdSLnWdt 0x19 /* 0 1 Set line width */
160 : #define GOrdPLnWdt 0x59 /* 0 1 Push and set line width */
161 : #define GOrdSFrLWd 0x11 /* 1 Set fractional line width */
162 : #define GOrdPFrLWd 0x51 /* 1 Push and set fractional line width */
163 : #define GOrdSStLWd 0x15 /* 1 Set stroke line width */
164 : #define GOrdPStLWd 0x55 /* 1 Push and set stroke line width */
165 :
166 : #define GOrdSChDir 0x3A /* 0 1 Set character direction */
167 : #define GOrdPChDir 0x7A /* 0 1 Push and set character direction */
168 : #define GOrdSChPrc 0x39 /* 0 1 Set character precision */
169 : #define GOrdPChPrc 0x79 /* 0 1 Push and set character precision */
170 : #define GOrdSChSet 0x38 /* 0 1 Set character set */
171 : #define GOrdPChSet 0x78 /* 0 1 Push and set character set */
172 : #define GOrdSChAng 0x34 /* 1 Set character angle */
173 : #define GOrdPChAng 0x74 /* 1 Push and set character angle */
174 : #define GOrdSChBrx 0x05 /* 1 Set character break extra */
175 : #define GOrdPChBrx 0x45 /* 1 Push and set character break extra */
176 : #define GOrdSChCel 0x33 /* 1 Set character cell */
177 : #define GOrdPChCel 0x03 /* 1 Push and set character cell */
178 : #define GOrdSChXtr 0x17 /* 1 Set character extra */
179 : #define GOrdPChXtr 0x57 /* 1 Push and set character extra */
180 : #define GOrdSChShr 0x35 /* 1 Set character shear */
181 : #define GOrdPChShr 0x75 /* 1 Push and set character shear */
182 : #define GOrdSTxAlg 0x36 /* 0 2 Set text allingment */
183 : #define GOrdPTxAlg 0x76 /* 0 2 Push and set text allingment */
184 :
185 : #define GOrdSMkPrc 0x3B /* 0 1 Set marker precision */
186 : #define GOrdPMkPrc 0x7B /* 0 1 Push and set marker precision */
187 : #define GOrdSMkSet 0x3C /* 0 1 Set marker set */
188 : #define GOrdPMkSet 0x7C /* 0 1 Push and set marker set */
189 : #define GOrdSMkSym 0x29 /* 0 1 Set marker symbol */
190 : #define GOrdPMkSym 0x69 /* 0 1 Push and set marker symbol */
191 : #define GOrdSMkCel 0x37 /* 1 Set marker cell */
192 : #define GOrdPMkCel 0x77 /* 1 Push and set marker cell */
193 :
194 : #define GOrdSArcPa 0x22 /* 1 Set arc parameters */
195 : #define GOrdPArcPa 0x62 /* 1 Push and set arc parameters */
196 :
197 : #define GOrdSCrPos 0x21 /* 1 Set current position */
198 : #define GOrdPCrPos 0x61 /* 1 Push and set current position */
199 :
200 : #define GOrdSMdTrn 0x24 /* 1 Set model transform */
201 : #define GOrdPMdTrn 0x64 /* 1 Push and set model transform */
202 : #define GOrdSPkIdn 0x43 /* 1 Set pick identifier */
203 : #define GOrdPPkIdn 0x23 /* 1 Push and set pick identifier */
204 : #define GOrdSVwTrn 0x31 /* 1 Set viewing transform */
205 : #define GOrdSVwWin 0x27 /* 1 Set viewing window */
206 : #define GOrdPVwWin 0x67 /* 1 Push and set viewing window */
207 :
208 : //============================ OS2METReader ==================================
209 :
210 : struct OSPalette {
211 : OSPalette * pSucc;
212 : sal_uInt32 * p0RGB; // May be NULL!
213 : sal_uInt16 nSize;
214 : };
215 :
216 : struct OSArea {
217 : OSArea * pSucc;
218 : sal_uInt8 nFlags;
219 : PolyPolygon aPPoly;
220 : sal_Bool bClosed;
221 : Color aCol;
222 : Color aBgCol;
223 : RasterOp eMix;
224 : RasterOp eBgMix;
225 : sal_Bool bFill;
226 0 : OSArea(){} ~OSArea(){}
227 : };
228 :
229 : struct OSPath
230 : {
231 : OSPath* pSucc;
232 : sal_uInt32 nID;
233 : PolyPolygon aPPoly;
234 : sal_Bool bClosed;
235 : sal_Bool bStroke;
236 :
237 0 : OSPath(){}
238 0 : ~OSPath(){}
239 : };
240 :
241 : struct OSFont {
242 : OSFont * pSucc;
243 : sal_uLong nID;
244 : Font aFont;
245 0 : OSFont(){} ~OSFont(){}
246 : };
247 :
248 : struct OSBitmap {
249 : OSBitmap * pSucc;
250 : sal_uLong nID;
251 : Bitmap aBitmap;
252 :
253 : // required during reading of the bitmap:
254 : SvStream * pBMP; // pointer to temporary Windows-BMP file or NULL
255 : sal_uInt32 nWidth, nHeight;
256 : sal_uInt16 nBitsPerPixel;
257 : sal_uLong nMapPos;
258 0 : OSBitmap(){} ~OSBitmap(){}
259 : };
260 :
261 : struct OSAttr {
262 : OSAttr * pSucc;
263 : sal_uInt16 nPushOrder;
264 : sal_uInt8 nIvAttrA, nIvAttrP; // special variables for the Order "GOrdPIvAtr"
265 :
266 : Color aLinCol;
267 : Color aLinBgCol;
268 : RasterOp eLinMix;
269 : RasterOp eLinBgMix;
270 : Color aChrCol;
271 : Color aChrBgCol;
272 : RasterOp eChrMix;
273 : RasterOp eChrBgMix;
274 : Color aMrkCol;
275 : Color aMrkBgCol;
276 : RasterOp eMrkMix;
277 : RasterOp eMrkBgMix;
278 : Color aPatCol;
279 : Color aPatBgCol;
280 : RasterOp ePatMix;
281 : RasterOp ePatBgMix;
282 : Color aImgCol;
283 : Color aImgBgCol;
284 : RasterOp eImgMix;
285 : RasterOp eImgBgMix;
286 : long nArcP, nArcQ, nArcR, nArcS;
287 : short nChrAng;
288 : // long nChrBreakExtra;
289 : Size aChrCellSize;
290 : // sal_uInt8 nChrDir;
291 : // long nChrExtra;
292 : // sal_uInt8 nChrPrec;
293 : sal_uLong nChrSet;
294 : // Size aChrShear;
295 : Point aCurPos;
296 : // long nFracLinWidth;
297 : // sal_uInt8 nLinEnd;
298 : // sal_uInt8 nLinJoin;
299 : PenStyle eLinStyle;
300 : sal_uInt16 nLinWidth;
301 : Size aMrkCellSize;
302 : sal_uInt8 nMrkPrec;
303 : sal_uInt8 nMrkSet;
304 : sal_uInt8 nMrkSymbol;
305 : // //... aModTransform;
306 : // Point aPatRef;
307 : // sal_uInt8 nPatSet;
308 : sal_Bool bFill;
309 : // sal_uLong nPickId;
310 : // //... aSegBound;
311 : sal_uInt16 nStrLinWidth;
312 : // sal_uInt8 nTxtAlignHor,nTxtAlignVer;
313 : // //... aViewTransform;
314 : // //... aViewWindow;
315 0 : OSAttr(){} ~OSAttr(){}
316 : };
317 :
318 : class OS2METReader {
319 :
320 : private:
321 :
322 : long ErrorCode;
323 :
324 : SvStream * pOS2MET; // Die einzulesende OS2MET-Datei
325 : VirtualDevice * pVirDev; // here the drawing methods are being called
326 : // Dabei findet ein Recording in das GDIMetaFile
327 : // statt.
328 : sal_uLong nOrigPos; // Anfaengliche Position in pOS2MET
329 : sal_uInt16 nOrigNumberFormat; // Anfaengliches Nummern-Format von pOS2MET
330 : Rectangle aBoundingRect; // Boundingrectangle wie in Datei angegeben
331 : Rectangle aCalcBndRect; // selbst ermitteltes Boundingrectangle
332 : MapMode aGlobMapMode; // resolution of the picture
333 : sal_Bool bCoord32;
334 :
335 : OSPalette * pPaletteStack;
336 :
337 : LineInfo aLineInfo;
338 :
339 : OSArea * pAreaStack; // Areas that are being worked on
340 :
341 : OSPath * pPathStack; // Paths that are being worked on
342 : OSPath * pPathList; // finished Paths
343 :
344 : OSFont * pFontList;
345 :
346 : OSBitmap * pBitmapList;
347 :
348 : OSAttr aDefAttr;
349 : OSAttr aAttr;
350 : OSAttr * pAttrStack;
351 :
352 : SvStream * pOrdFile;
353 :
354 : sal_Bool Callback(sal_uInt16 nPercent);
355 :
356 : void AddPointsToPath(const Polygon & rPoly);
357 : void AddPointsToArea(const Polygon & rPoly);
358 : void CloseFigure();
359 : void PushAttr(sal_uInt16 nPushOrder);
360 : void PopAttr();
361 :
362 : void ChangeBrush( const Color& rPatColor, const Color& rBGColor, sal_Bool bFill );
363 : void SetPen( const Color& rColor, sal_uInt16 nStrLinWidth = 0, PenStyle ePenStyle = PEN_SOLID );
364 : void SetRasterOp(RasterOp eROP);
365 :
366 : void SetPalette0RGB(sal_uInt16 nIndex, sal_uLong nCol);
367 : sal_uInt32 GetPalette0RGB(sal_uInt32 nIndex);
368 : // gets color from palette, or, if it doesn't exist,
369 : // interprets nIndex as immediate RGB value.
370 : Color GetPaletteColor(sal_uInt32 nIndex);
371 :
372 :
373 : sal_Bool IsLineInfo();
374 : void DrawPolyLine( const Polygon& rPolygon );
375 : void DrawPolygon( const Polygon& rPolygon );
376 : void DrawPolyPolygon( const PolyPolygon& rPolygon );
377 : sal_uInt16 ReadBigEndianWord();
378 : sal_uLong ReadBigEndian3BytesLong();
379 : sal_uLong ReadLittleEndian3BytesLong();
380 : long ReadCoord(sal_Bool b32);
381 : Point ReadPoint( const sal_Bool bAdjustBoundRect = sal_True );
382 : RasterOp OS2MixToRasterOp(sal_uInt8 nMix);
383 : void ReadLine(sal_Bool bGivenPos, sal_uInt16 nOrderLen);
384 : void ReadRelLine(sal_Bool bGivenPos, sal_uInt16 nOrderLen);
385 : void ReadBox(sal_Bool bGivenPos);
386 : void ReadBitBlt();
387 : void ReadChrStr(sal_Bool bGivenPos, sal_Bool bMove, sal_Bool bExtra, sal_uInt16 nOrderLen);
388 : void ReadArc(sal_Bool bGivenPos);
389 : void ReadFullArc(sal_Bool bGivenPos, sal_uInt16 nOrderSize);
390 : void ReadPartialArc(sal_Bool bGivenPos, sal_uInt16 nOrderSize);
391 : void ReadPolygons();
392 : void ReadBezier(sal_Bool bGivenPos, sal_uInt16 nOrderLen);
393 : void ReadFillet(sal_Bool bGivenPos, sal_uInt16 nOrderLen);
394 : void ReadFilletSharp(sal_Bool bGivenPos, sal_uInt16 nOrderLen);
395 : void ReadMarker(sal_Bool bGivenPos, sal_uInt16 nOrderLen);
396 : void ReadOrder(sal_uInt16 nOrderID, sal_uInt16 nOrderLen);
397 : void ReadDsc(sal_uInt16 nDscID, sal_uInt16 nDscLen);
398 : void ReadImageData(sal_uInt16 nDataID, sal_uInt16 nDataLen);
399 : void ReadFont(sal_uInt16 nFieldSize);
400 : void ReadField(sal_uInt16 nFieldType, sal_uInt16 nFieldSize);
401 :
402 : public:
403 :
404 : OS2METReader();
405 : ~OS2METReader();
406 :
407 : void ReadOS2MET( SvStream & rStreamOS2MET, GDIMetaFile & rGDIMetaFile );
408 : // Reads from the stream a OS2MET file und and fills up the GDIMetaFile
409 :
410 : };
411 :
412 : //=================== Methods of OS2METReader ==============================
413 :
414 0 : sal_Bool OS2METReader::Callback(sal_uInt16 /*nPercent*/)
415 : {
416 0 : return sal_False;
417 : }
418 :
419 0 : OS2METReader::OS2METReader()
420 : {
421 0 : }
422 :
423 0 : OS2METReader::~OS2METReader()
424 : {
425 0 : }
426 :
427 0 : sal_Bool OS2METReader::IsLineInfo()
428 : {
429 0 : return ( ! ( aLineInfo.IsDefault() || ( aLineInfo.GetStyle() == LINE_NONE ) || ( pVirDev->GetLineColor() == COL_TRANSPARENT ) ) );
430 : }
431 :
432 0 : void OS2METReader::DrawPolyLine( const Polygon& rPolygon )
433 : {
434 0 : if ( aLineInfo.GetStyle() == LINE_DASH || ( aLineInfo.GetWidth() > 1 ) )
435 0 : pVirDev->DrawPolyLine( rPolygon, aLineInfo );
436 : else
437 0 : pVirDev->DrawPolyLine( rPolygon );
438 0 : }
439 :
440 0 : void OS2METReader::DrawPolygon( const Polygon& rPolygon )
441 : {
442 0 : if ( IsLineInfo() )
443 : {
444 0 : pVirDev->Push( PUSH_LINECOLOR );
445 0 : pVirDev->SetLineColor( COL_TRANSPARENT );
446 0 : pVirDev->DrawPolygon( rPolygon );
447 0 : pVirDev->Pop();
448 0 : pVirDev->DrawPolyLine( rPolygon, aLineInfo );
449 : }
450 : else
451 0 : pVirDev->DrawPolygon( rPolygon );
452 0 : }
453 :
454 0 : void OS2METReader::DrawPolyPolygon( const PolyPolygon& rPolyPolygon )
455 : {
456 0 : if ( IsLineInfo() )
457 : {
458 0 : pVirDev->Push( PUSH_LINECOLOR );
459 0 : pVirDev->SetLineColor( COL_TRANSPARENT );
460 0 : pVirDev->DrawPolyPolygon( rPolyPolygon );
461 0 : pVirDev->Pop();
462 0 : for ( sal_uInt16 i = 0; i < rPolyPolygon.Count(); i++ )
463 0 : pVirDev->DrawPolyLine( rPolyPolygon.GetObject( i ), aLineInfo );
464 : }
465 : else
466 0 : pVirDev->DrawPolyPolygon( rPolyPolygon );
467 0 : }
468 :
469 0 : void OS2METReader::AddPointsToArea(const Polygon & rPoly)
470 : {
471 : sal_uInt16 nOldSize, nNewSize,i;
472 :
473 0 : if (pAreaStack==NULL || rPoly.GetSize()==0) return;
474 0 : PolyPolygon * pPP=&(pAreaStack->aPPoly);
475 0 : if (pPP->Count()==0 || pAreaStack->bClosed==sal_True) pPP->Insert(rPoly);
476 : else {
477 0 : Polygon aLastPoly(pPP->GetObject(pPP->Count()-1));
478 0 : nOldSize=aLastPoly.GetSize();
479 0 : if (aLastPoly.GetPoint(nOldSize-1)==rPoly.GetPoint(0)) nOldSize--;
480 0 : nNewSize=nOldSize+rPoly.GetSize();
481 0 : aLastPoly.SetSize(nNewSize);
482 0 : for (i=nOldSize; i<nNewSize; i++) {
483 0 : aLastPoly.SetPoint(rPoly.GetPoint(i-nOldSize),i);
484 : }
485 0 : pPP->Replace(aLastPoly,pPP->Count()-1);
486 : }
487 0 : pAreaStack->bClosed=sal_False;
488 : }
489 :
490 0 : void OS2METReader::AddPointsToPath(const Polygon & rPoly)
491 : {
492 : sal_uInt16 nOldSize, nNewSize,i;
493 :
494 0 : if (pPathStack==NULL || rPoly.GetSize()==0) return;
495 0 : PolyPolygon * pPP=&(pPathStack->aPPoly);
496 0 : if (pPP->Count()==0 /*|| pPathStack->bClosed==sal_True*/) pPP->Insert(rPoly);
497 : else {
498 0 : Polygon aLastPoly(pPP->GetObject(pPP->Count()-1));
499 0 : nOldSize=aLastPoly.GetSize();
500 0 : if (aLastPoly.GetPoint(nOldSize-1)!=rPoly.GetPoint(0)) pPP->Insert(rPoly);
501 : else {
502 0 : nOldSize--;
503 0 : nNewSize=nOldSize+rPoly.GetSize();
504 0 : aLastPoly.SetSize(nNewSize);
505 0 : for (i=nOldSize; i<nNewSize; i++) {
506 0 : aLastPoly.SetPoint(rPoly.GetPoint(i-nOldSize),i);
507 : }
508 0 : pPP->Replace(aLastPoly,pPP->Count()-1);
509 0 : }
510 : }
511 0 : pPathStack->bClosed=sal_False;
512 : }
513 :
514 0 : void OS2METReader::CloseFigure()
515 : {
516 0 : if (pAreaStack!=NULL) pAreaStack->bClosed=sal_True;
517 0 : else if (pPathStack!=NULL) pPathStack->bClosed=sal_True;
518 0 : }
519 :
520 0 : void OS2METReader::PushAttr(sal_uInt16 nPushOrder)
521 : {
522 : OSAttr * p;
523 0 : p=new OSAttr;
524 0 : *p=aAttr;
525 0 : p->pSucc=pAttrStack; pAttrStack=p;
526 0 : p->nPushOrder=nPushOrder;
527 0 : }
528 :
529 0 : void OS2METReader::PopAttr()
530 : {
531 0 : OSAttr * p=pAttrStack;
532 :
533 0 : if (p==NULL) return;
534 0 : switch (p->nPushOrder) {
535 :
536 : case GOrdPIvAtr:
537 0 : switch (p->nIvAttrA) {
538 0 : case 1: switch (p->nIvAttrP) {
539 0 : case 1: aAttr.aLinCol=p->aLinCol; break;
540 0 : case 2: aAttr.aChrCol=p->aChrCol; break;
541 0 : case 3: aAttr.aMrkCol=p->aMrkCol; break;
542 0 : case 4: aAttr.aPatCol=p->aPatCol; break;
543 0 : case 5: aAttr.aImgCol=p->aImgCol; break;
544 0 : } break;
545 0 : case 2: switch (p->nIvAttrP) {
546 0 : case 1: aAttr.aLinBgCol=p->aLinBgCol; break;
547 0 : case 2: aAttr.aChrBgCol=p->aChrBgCol; break;
548 0 : case 3: aAttr.aMrkBgCol=p->aMrkBgCol; break;
549 0 : case 4: aAttr.aPatBgCol=p->aPatBgCol; break;
550 0 : case 5: aAttr.aImgBgCol=p->aImgBgCol; break;
551 0 : } break;
552 0 : case 3: switch (p->nIvAttrP) {
553 0 : case 1: aAttr.eLinMix=p->eLinMix; break;
554 0 : case 2: aAttr.eChrMix=p->eChrMix; break;
555 0 : case 3: aAttr.eMrkMix=p->eMrkMix; break;
556 0 : case 4: aAttr.ePatMix=p->ePatMix; break;
557 0 : case 5: aAttr.eImgMix=p->eImgMix; break;
558 0 : } break;
559 0 : case 4: switch (p->nIvAttrP) {
560 0 : case 1: aAttr.eLinBgMix=p->eLinBgMix; break;
561 0 : case 2: aAttr.eChrBgMix=p->eChrBgMix; break;
562 0 : case 3: aAttr.eMrkBgMix=p->eMrkBgMix; break;
563 0 : case 4: aAttr.ePatBgMix=p->ePatBgMix; break;
564 0 : case 5: aAttr.eImgBgMix=p->eImgBgMix; break;
565 0 : } break;
566 : }
567 0 : break;
568 :
569 0 : case GOrdPLnTyp: aAttr.eLinStyle=p->eLinStyle; break;
570 :
571 0 : case GOrdPLnWdt: aAttr.nLinWidth=p->nLinWidth; break;
572 :
573 0 : case GOrdPStLWd: aAttr.nStrLinWidth=p->nStrLinWidth; break;
574 :
575 0 : case GOrdPChSet: aAttr.nChrSet=p->nChrSet; break;
576 :
577 0 : case GOrdPChAng: aAttr.nChrAng=p->nChrAng; break;
578 :
579 : case GOrdPMixMd:
580 0 : aAttr.eLinMix=p->eLinMix;
581 0 : aAttr.eChrMix=p->eChrMix;
582 0 : aAttr.eMrkMix=p->eMrkMix;
583 0 : aAttr.ePatMix=p->ePatMix;
584 0 : aAttr.eImgMix=p->eImgMix;
585 0 : break;
586 :
587 : case GOrdPBgMix:
588 0 : aAttr.eLinBgMix=p->eLinBgMix;
589 0 : aAttr.eChrBgMix=p->eChrBgMix;
590 0 : aAttr.eMrkBgMix=p->eMrkBgMix;
591 0 : aAttr.ePatBgMix=p->ePatBgMix;
592 0 : aAttr.eImgBgMix=p->eImgBgMix;
593 0 : break;
594 :
595 0 : case GOrdPPtSym: aAttr.bFill = p->bFill; break;
596 :
597 : case GOrdPColor:
598 : case GOrdPIxCol:
599 : case GOrdPXtCol:
600 0 : aAttr.aLinCol=p->aLinCol;
601 0 : aAttr.aChrCol=p->aChrCol;
602 0 : aAttr.aMrkCol=p->aMrkCol;
603 0 : aAttr.aPatCol=p->aPatCol;
604 0 : aAttr.aImgCol=p->aImgCol;
605 0 : break;
606 :
607 : case GOrdPBgCol:
608 : case GOrdPBxCol:
609 0 : aAttr.aLinBgCol=p->aLinBgCol;
610 0 : aAttr.aChrBgCol=p->aChrBgCol;
611 0 : aAttr.aMrkBgCol=p->aMrkBgCol;
612 0 : aAttr.aPatBgCol=p->aPatBgCol;
613 0 : aAttr.aImgBgCol=p->aImgBgCol;
614 0 : break;
615 :
616 0 : case GOrdPMkPrc: aAttr.nMrkPrec=aDefAttr.nMrkPrec; break;
617 :
618 0 : case GOrdPMkSet: aAttr.nMrkSet=aDefAttr.nMrkSet; break;
619 :
620 0 : case GOrdPMkSym: aAttr.nMrkSymbol=aDefAttr.nMrkSymbol; break;
621 :
622 0 : case GOrdPMkCel: aAttr.aMrkCellSize=aDefAttr.aMrkCellSize; break;
623 :
624 : case GOrdPArcPa:
625 0 : aAttr.nArcP=p->nArcP; aAttr.nArcQ=p->nArcQ;
626 0 : aAttr.nArcR=p->nArcR; aAttr.nArcS=p->nArcS;
627 0 : break;
628 :
629 : case GOrdPCrPos:
630 0 : aAttr.aCurPos=p->aCurPos;
631 0 : break;
632 : }
633 0 : pAttrStack=p->pSucc;
634 0 : delete p;
635 : }
636 :
637 0 : void OS2METReader::ChangeBrush(const Color& rPatColor, const Color& /*rBGColor*/, sal_Bool bFill )
638 : {
639 0 : Color aColor;
640 :
641 0 : if( bFill )
642 0 : aColor = rPatColor;
643 : else
644 0 : aColor = Color( COL_TRANSPARENT );
645 :
646 0 : if( pVirDev->GetFillColor() != aColor )
647 0 : pVirDev->SetFillColor( aColor );
648 0 : }
649 :
650 0 : void OS2METReader::SetPen( const Color& rColor, sal_uInt16 nLineWidth, PenStyle ePenStyle )
651 : {
652 0 : LineStyle eLineStyle( LINE_SOLID );
653 :
654 0 : if ( pVirDev->GetLineColor() != rColor )
655 0 : pVirDev->SetLineColor( rColor );
656 0 : aLineInfo.SetWidth( nLineWidth );
657 :
658 0 : sal_uInt16 nDotCount = 0;
659 0 : sal_uInt16 nDashCount = 0;
660 0 : switch ( ePenStyle )
661 : {
662 : case PEN_NULL :
663 0 : eLineStyle = LINE_NONE;
664 0 : break;
665 : case PEN_DASHDOT :
666 0 : nDashCount++;
667 : case PEN_DOT :
668 0 : nDotCount++;
669 0 : nDashCount--;
670 : case PEN_DASH :
671 0 : nDashCount++;
672 0 : aLineInfo.SetDotCount( nDotCount );
673 0 : aLineInfo.SetDashCount( nDashCount );
674 0 : aLineInfo.SetDistance( nLineWidth );
675 0 : aLineInfo.SetDotLen( nLineWidth );
676 0 : aLineInfo.SetDashLen( nLineWidth << 2 );
677 0 : eLineStyle = LINE_DASH;
678 0 : break;
679 : case PEN_SOLID:
680 0 : break; // -Wall not handled...
681 : }
682 0 : aLineInfo.SetStyle( eLineStyle );
683 0 : }
684 :
685 0 : void OS2METReader::SetRasterOp(RasterOp eROP)
686 : {
687 0 : if (pVirDev->GetRasterOp()!=eROP) pVirDev->SetRasterOp(eROP);
688 0 : }
689 :
690 :
691 0 : void OS2METReader::SetPalette0RGB(sal_uInt16 nIndex, sal_uLong nCol)
692 : {
693 0 : if (pPaletteStack==NULL) {
694 0 : pPaletteStack=new OSPalette;
695 0 : pPaletteStack->pSucc=NULL;
696 0 : pPaletteStack->p0RGB=NULL;
697 0 : pPaletteStack->nSize=0;
698 : }
699 0 : if (pPaletteStack->p0RGB==NULL || nIndex>=pPaletteStack->nSize) {
700 0 : sal_uInt32 * pOld0RGB=pPaletteStack->p0RGB;
701 0 : sal_uInt16 i,nOldSize=pPaletteStack->nSize;
702 0 : if (pOld0RGB==NULL) nOldSize=0;
703 0 : pPaletteStack->nSize=2*(nIndex+1);
704 0 : if (pPaletteStack->nSize<256) pPaletteStack->nSize=256;
705 0 : pPaletteStack->p0RGB = new sal_uInt32[pPaletteStack->nSize];
706 0 : for (i=0; i<pPaletteStack->nSize; i++) {
707 0 : if (i<nOldSize) pPaletteStack->p0RGB[i]=pOld0RGB[i];
708 0 : else if (i==0) pPaletteStack->p0RGB[i]=0x00ffffff;
709 0 : else pPaletteStack->p0RGB[i]=0;
710 : }
711 0 : if (pOld0RGB!=NULL) delete[] pOld0RGB;
712 : }
713 0 : pPaletteStack->p0RGB[nIndex]=nCol;
714 0 : }
715 :
716 0 : sal_uInt32 OS2METReader::GetPalette0RGB(sal_uInt32 nIndex)
717 : {
718 0 : if (pPaletteStack!=NULL && pPaletteStack->p0RGB!=NULL &&
719 0 : pPaletteStack->nSize>nIndex) nIndex=pPaletteStack->p0RGB[nIndex];
720 0 : return nIndex;
721 : }
722 :
723 0 : Color OS2METReader::GetPaletteColor(sal_uInt32 nIndex)
724 : {
725 0 : nIndex=GetPalette0RGB(nIndex);
726 0 : return Color(sal::static_int_cast< sal_uInt8 >((nIndex>>16)&0xff),
727 0 : sal::static_int_cast< sal_uInt8 >((nIndex>>8)&0xff),
728 0 : sal::static_int_cast< sal_uInt8 >(nIndex&0xff));
729 : }
730 :
731 :
732 0 : sal_uInt16 OS2METReader::ReadBigEndianWord()
733 : {
734 : sal_uInt8 nLo,nHi;
735 0 : *pOS2MET >> nHi >> nLo;
736 0 : return (((sal_uInt16)nHi)<<8)|(((sal_uInt16)nLo)&0x00ff);
737 : }
738 :
739 0 : sal_uLong OS2METReader::ReadBigEndian3BytesLong()
740 : {
741 : sal_uInt16 nLo;
742 : sal_uInt8 nHi;
743 0 : *pOS2MET >> nHi;
744 0 : nLo=ReadBigEndianWord();
745 0 : return ((((sal_uLong)nHi)<<16)&0x00ff0000)|((sal_uLong)nLo);
746 : }
747 :
748 0 : sal_uLong OS2METReader::ReadLittleEndian3BytesLong()
749 : {
750 : sal_uInt8 nHi,nMed,nLo;
751 :
752 0 : *pOS2MET >> nLo >> nMed >> nHi;
753 0 : return ((((sal_uLong)nHi)&0xff)<<16)|((((sal_uLong)nMed)&0xff)<<8)|(((sal_uLong)nLo)&0xff);
754 : }
755 :
756 0 : long OS2METReader::ReadCoord(sal_Bool b32)
757 : {
758 : sal_Int32 l;
759 :
760 0 : if (b32) *pOS2MET >> l;
761 0 : else { short s;*pOS2MET >> s; l=(sal_Int32)s; }
762 0 : return l;
763 : }
764 :
765 0 : Point OS2METReader::ReadPoint( const sal_Bool bAdjustBoundRect )
766 : {
767 : long x,y;
768 :
769 0 : x=ReadCoord(bCoord32);
770 0 : y=ReadCoord(bCoord32);
771 0 : x=x-aBoundingRect.Left();
772 0 : y=aBoundingRect.Bottom()-y;
773 :
774 0 : if ( bAdjustBoundRect )
775 0 : aCalcBndRect.Union(Rectangle(x,y,x+1,y+1));
776 :
777 0 : return Point(x,y);
778 : }
779 :
780 0 : RasterOp OS2METReader::OS2MixToRasterOp(sal_uInt8 nMix)
781 : {
782 0 : switch (nMix) {
783 0 : case 0x0c: return ROP_INVERT;
784 0 : case 0x04: return ROP_XOR;
785 0 : case 0x0b: return ROP_XOR;
786 0 : default: return ROP_OVERPAINT;
787 : }
788 : }
789 :
790 0 : void OS2METReader::ReadLine(sal_Bool bGivenPos, sal_uInt16 nOrderLen)
791 : {
792 : sal_uInt16 i,nPolySize;
793 :
794 0 : if (bCoord32) nPolySize=nOrderLen/8; else nPolySize=nOrderLen/4;
795 0 : if (!bGivenPos) nPolySize++;
796 0 : if (nPolySize==0) return;
797 0 : Polygon aPolygon(nPolySize);
798 0 : for (i=0; i<nPolySize; i++) {
799 0 : if (i==0 && !bGivenPos) aPolygon.SetPoint(aAttr.aCurPos,i);
800 0 : else aPolygon.SetPoint(ReadPoint(),i);
801 : }
802 0 : aAttr.aCurPos=aPolygon.GetPoint(nPolySize-1);
803 0 : if (pAreaStack!=NULL) AddPointsToArea(aPolygon);
804 0 : else if (pPathStack!=NULL) AddPointsToPath(aPolygon);
805 : else
806 : {
807 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
808 0 : SetRasterOp(aAttr.eLinMix);
809 0 : DrawPolyLine( aPolygon );
810 0 : }
811 : }
812 :
813 0 : void OS2METReader::ReadRelLine(sal_Bool bGivenPos, sal_uInt16 nOrderLen)
814 : {
815 : sal_uInt16 i,nPolySize;
816 0 : Point aP0;
817 :
818 :
819 0 : if (bGivenPos) {
820 0 : aP0=ReadPoint();
821 0 : if (bCoord32) nOrderLen-=8; else nOrderLen-=4;
822 : }
823 0 : else aP0=aAttr.aCurPos;
824 0 : nPolySize=nOrderLen/2;
825 0 : if (nPolySize==0) return;
826 0 : Polygon aPolygon(nPolySize);
827 0 : for (i=0; i<nPolySize; i++) {
828 : #if defined SOLARIS && defined PPC
829 : sal_uInt8 nunsignedbyte;
830 : *pOS2MET >> nunsignedbyte; aP0.X()+=(sal_Int8)nunsignedbyte;
831 : *pOS2MET >> nunsignedbyte; aP0.Y()+=(sal_Int8)nunsignedbyte;
832 : #else
833 : sal_Int8 nsignedbyte;
834 0 : *pOS2MET >> nsignedbyte; aP0.X()+=(long)nsignedbyte;
835 0 : *pOS2MET >> nsignedbyte; aP0.Y()-=(long)nsignedbyte;
836 : #endif
837 0 : aCalcBndRect.Union(Rectangle(aP0,Size(1,1)));
838 0 : aPolygon.SetPoint(aP0,i);
839 : }
840 0 : aAttr.aCurPos=aPolygon.GetPoint(nPolySize-1);
841 0 : if (pAreaStack!=NULL) AddPointsToArea(aPolygon);
842 0 : else if (pPathStack!=NULL) AddPointsToPath(aPolygon);
843 : else
844 : {
845 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
846 0 : SetRasterOp(aAttr.eLinMix);
847 0 : DrawPolyLine( aPolygon );
848 0 : }
849 : }
850 :
851 0 : void OS2METReader::ReadBox(sal_Bool bGivenPos)
852 : {
853 : sal_uInt8 nFlags;
854 0 : Point P0;
855 : long nHRound,nVRound;
856 :
857 0 : *pOS2MET >> nFlags;
858 0 : pOS2MET->SeekRel(1);
859 :
860 0 : if ( bGivenPos )
861 0 : P0 = ReadPoint();
862 : else
863 0 : P0 = aAttr.aCurPos;
864 :
865 0 : aAttr.aCurPos=ReadPoint();
866 0 : nHRound=ReadCoord(bCoord32);
867 0 : nVRound=ReadCoord(bCoord32);
868 :
869 0 : Rectangle aBoxRect( P0, aAttr.aCurPos );
870 :
871 0 : if ( pAreaStack )
872 0 : AddPointsToArea( Polygon( aBoxRect ) );
873 0 : else if ( pPathStack )
874 0 : AddPointsToPath( Polygon( aBoxRect ) );
875 : else
876 : {
877 0 : if ( nFlags & 0x20 )
878 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
879 : else
880 0 : SetPen( COL_TRANSPARENT );
881 :
882 0 : if ( nFlags & 0x40 )
883 : {
884 0 : ChangeBrush(aAttr.aPatCol,aAttr.aPatBgCol,aAttr.bFill);
885 0 : SetRasterOp(aAttr.ePatMix);
886 : }
887 : else
888 : {
889 0 : ChangeBrush( Color( COL_TRANSPARENT ), Color( COL_TRANSPARENT ), sal_False );
890 0 : SetRasterOp(aAttr.eLinMix);
891 : }
892 :
893 0 : if ( IsLineInfo() )
894 : {
895 0 : Polygon aPolygon( aBoxRect, nHRound, nVRound );
896 0 : if ( nFlags & 0x40 )
897 : {
898 0 : pVirDev->Push( PUSH_LINECOLOR );
899 0 : pVirDev->SetLineColor( COL_TRANSPARENT );
900 0 : pVirDev->DrawRect( aBoxRect, nHRound, nVRound );
901 0 : pVirDev->Pop();
902 : }
903 0 : pVirDev->DrawPolyLine( aPolygon, aLineInfo );
904 : }
905 : else
906 0 : pVirDev->DrawRect( aBoxRect, nHRound, nVRound );
907 : }
908 0 : }
909 :
910 0 : void OS2METReader::ReadBitBlt()
911 : {
912 0 : Point aP1,aP2;
913 0 : Size aSize;
914 : sal_uInt32 nID;
915 : OSBitmap * pB;
916 : long nt;
917 :
918 0 : pOS2MET->SeekRel(4);
919 0 : *pOS2MET >> nID;
920 0 : pOS2MET->SeekRel(4);
921 0 : aP1=ReadPoint(); aP2=ReadPoint();
922 0 : if (aP1.X() > aP2.X()) { nt=aP1.X(); aP1.X()=aP2.X(); aP2.X()=nt; }
923 0 : if (aP1.Y() > aP2.Y()) { nt=aP1.Y(); aP1.Y()=aP2.Y(); aP2.Y()=nt; }
924 0 : aSize=Size(aP2.X()-aP1.X(),aP2.Y()-aP1.Y());
925 :
926 0 : pB=pBitmapList;
927 0 : while (pB!=NULL && pB->nID!=nID) pB=pB->pSucc;
928 0 : if (pB!=NULL) {
929 0 : SetRasterOp(aAttr.ePatMix);
930 0 : pVirDev->DrawBitmap(aP1,aSize,pB->aBitmap);
931 : }
932 0 : }
933 :
934 0 : void OS2METReader::ReadChrStr(sal_Bool bGivenPos, sal_Bool bMove, sal_Bool bExtra, sal_uInt16 nOrderLen)
935 : {
936 0 : Point aP0;
937 : sal_uInt16 i, nLen;
938 : char * pChr;
939 : OSFont * pF;
940 0 : Font aFont;
941 0 : Size aSize;
942 :
943 0 : pF = pFontList;
944 0 : while (pF!=NULL && pF->nID!=aAttr.nChrSet) pF=pF->pSucc;
945 0 : if (pF!=NULL)
946 0 : aFont = pF->aFont;
947 0 : aFont.SetColor(aAttr.aChrCol);
948 0 : aFont.SetSize(Size(0,aAttr.aChrCellSize.Height()));
949 0 : if ( aAttr.nChrAng != 0 )
950 0 : aFont.SetOrientation(aAttr.nChrAng);
951 :
952 0 : if (bGivenPos)
953 0 : aP0 = ReadPoint();
954 : else
955 0 : aP0 = aAttr.aCurPos;
956 0 : if (bExtra)
957 : {
958 0 : pOS2MET->SeekRel(2);
959 0 : ReadPoint( sal_False );
960 0 : ReadPoint( sal_False );
961 0 : *pOS2MET >> nLen;
962 : }
963 : else
964 : {
965 0 : if ( !bGivenPos )
966 0 : nLen = nOrderLen;
967 0 : else if ( bCoord32 )
968 0 : nLen = nOrderLen-8;
969 : else
970 0 : nLen = nOrderLen-4;
971 : }
972 0 : pChr = new char[nLen+1];
973 0 : for (i=0; i<nLen; i++)
974 0 : *pOS2MET >> pChr[i];
975 0 : pChr[nLen] = 0;
976 0 : String aStr( (const sal_Char*)pChr, osl_getThreadTextEncoding() );
977 0 : SetRasterOp(aAttr.eChrMix);
978 0 : if (pVirDev->GetFont()!=aFont)
979 0 : pVirDev->SetFont(aFont);
980 0 : pVirDev->DrawText(aP0,aStr);
981 :
982 0 : aSize = Size( pVirDev->GetTextWidth(aStr), pVirDev->GetTextHeight() );
983 0 : if ( aAttr.nChrAng == 0 )
984 : {
985 0 : aCalcBndRect.Union(Rectangle( Point(aP0.X(),aP0.Y()-aSize.Height()),
986 0 : Size(aSize.Width(),aSize.Height()*2)));
987 0 : if (bMove)
988 0 : aAttr.aCurPos = Point( aP0.X() + aSize.Width(), aP0.Y());
989 : }
990 : else
991 : {
992 0 : Polygon aDummyPoly(4);
993 :
994 0 : aDummyPoly.SetPoint( Point( aP0.X(), aP0.Y() ), 0); // TOP LEFT
995 0 : aDummyPoly.SetPoint( Point( aP0.X(), aP0.Y() - aSize.Height() ), 1); // BOTTOM LEFT
996 0 : aDummyPoly.SetPoint( Point( aP0.X() + aSize.Width(), aP0.Y() ), 2); // TOP RIGHT
997 0 : aDummyPoly.SetPoint( Point( aP0.X() + aSize.Width(), aP0.Y() - aSize.Height() ), 3);// BOTTOM RIGHT
998 0 : aDummyPoly.Rotate( aP0, (short)aAttr.nChrAng );
999 0 : if ( bMove )
1000 0 : aAttr.aCurPos = aDummyPoly.GetPoint( 0 );
1001 0 : aCalcBndRect.Union( Rectangle( aDummyPoly.GetPoint( 0 ), aDummyPoly.GetPoint( 3 ) ) );
1002 0 : aCalcBndRect.Union( Rectangle( aDummyPoly.GetPoint( 1 ), aDummyPoly.GetPoint( 2 ) ) );
1003 : }
1004 0 : delete[] pChr;
1005 0 : }
1006 :
1007 0 : void OS2METReader::ReadArc(sal_Bool bGivenPos)
1008 : {
1009 0 : Point aP1, aP2, aP3;
1010 : double x1,y1,x2,y2,x3,y3,p,q,cx,cy,ncx,ncy,r,rx,ry,w1,w3;
1011 0 : if (bGivenPos) aP1=ReadPoint(); else aP1=aAttr.aCurPos;
1012 0 : aP2=ReadPoint(); aP3=ReadPoint();
1013 0 : aAttr.aCurPos=aP3;
1014 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
1015 0 : SetRasterOp(aAttr.eLinMix);
1016 : // OK, gegeben sind 3 Punkte der Ellipse, und das Verhaeltnis
1017 : // Breite zu Hoehe (als p zu q):
1018 0 : x1=aP1.X(); y1=aP1.Y();
1019 0 : x2=aP2.X(); y2=aP2.Y();
1020 0 : x3=aP3.X(); y3=aP3.Y();
1021 0 : p=aAttr.nArcP;q=aAttr.nArcQ;
1022 : // Berechnet wird der Mittelpunkt cx,cy der Ellipse:
1023 0 : ncy=2*p*p*((y3-y1)*(x2-x1)-(y1-y2)*(x1-x3));
1024 0 : ncx=2*q*q*(x2-x1);
1025 0 : if ( (ncx<0.001 && ncx>-0.001) || (ncy<0.001 && ncy>-0.001) ) {
1026 : // Berechnung nicht moeglich, Punkte liegen auf einer Linie
1027 0 : pVirDev->DrawLine(aP1,aP2);
1028 0 : pVirDev->DrawLine(aP2,aP3);
1029 0 : return;
1030 : }
1031 : cy=( q*q*((x3*x3-x1*x1)*(x2-x1)+(x2*x2-x1*x1)*(x1-x3)) +
1032 0 : p*p*((y3*y3-y1*y1)*(x2-x1)+(y2*y2-y1*y1)*(x1-x3)) ) / ncy;
1033 0 : cx=( q*q*(x2*x2-x1*x1)+p*p*(y2*y2-y1*y1)+cy*2*p*p*(y1-y2) ) / ncx;
1034 : // now we still need the radius in x and y direction:
1035 0 : r=sqrt(q*q*(x1-cx)*(x1-cx)+p*p*(y1-cy)*(y1-cy));
1036 0 : rx=r/q; ry=r/p;
1037 : // Jetzt stellt sich "nur noch" die Frage, wie Start- und Endpunkt
1038 : // gewaehlt werden muessen, damit Punkt Nr. 2 innerhalb des
1039 : // gezeichneten Bogens liegt:
1040 0 : w1=fmod((atan2(x1-cx,y1-cy)-atan2(x2-cx,y2-cy)),6.28318530718); if (w1<0) w1+=6.28318530718;
1041 0 : w3=fmod((atan2(x3-cx,y3-cy)-atan2(x2-cx,y2-cy)),6.28318530718); if (w3<0) w3+=6.28318530718;
1042 0 : if (w3<w1) {
1043 : pVirDev->DrawArc(Rectangle((long)(cx-rx),(long)(cy-ry),
1044 0 : (long)(cx+rx),(long)(cy+ry)),aP1,aP3);
1045 : }
1046 : else {
1047 : pVirDev->DrawArc(Rectangle((long)(cx-rx),(long)(cy-ry),
1048 0 : (long)(cx+rx),(long)(cy+ry)),aP3,aP1);
1049 : }
1050 : }
1051 :
1052 0 : void OS2METReader::ReadFullArc(sal_Bool bGivenPos, sal_uInt16 nOrderSize)
1053 : {
1054 0 : Point aCenter;
1055 : long nP,nQ,nR,nS;
1056 0 : Rectangle aRect;
1057 : sal_uInt32 nMul; sal_uInt16 nMulS;
1058 :
1059 0 : if (bGivenPos) {
1060 0 : aCenter=ReadPoint();
1061 0 : if (bCoord32) nOrderSize-=8; else nOrderSize-=4;
1062 : }
1063 0 : else aCenter=aAttr.aCurPos;
1064 :
1065 0 : nP=aAttr.nArcP; nQ=aAttr.nArcQ; nR=aAttr.nArcR; nS=aAttr.nArcS;
1066 0 : if (nP<0) nP=-nP;
1067 0 : if (nQ<0) nQ=-nQ;
1068 0 : if (nR<0) nR=-nR;
1069 0 : if (nS<0) nS=-nS;
1070 0 : if (nOrderSize>=4) *pOS2MET >> nMul;
1071 0 : else { *pOS2MET >> nMulS; nMul=((sal_uLong)nMulS)<<8; }
1072 0 : if (nMul!=0x00010000) {
1073 0 : nP=(nP*nMul)>>16;
1074 0 : nQ=(nQ*nMul)>>16;
1075 0 : nR=(nR*nMul)>>16;
1076 0 : nS=(nS*nMul)>>16;
1077 : }
1078 :
1079 0 : aRect=Rectangle(aCenter.X()-nP,aCenter.Y()-nQ,
1080 0 : aCenter.X()+nP,aCenter.Y()+nQ);
1081 0 : aCalcBndRect.Union(aRect);
1082 :
1083 0 : if (pAreaStack!=NULL) {
1084 0 : ChangeBrush(aAttr.aPatCol,aAttr.aPatBgCol,aAttr.bFill);
1085 0 : SetRasterOp(aAttr.ePatMix);
1086 0 : if ((pAreaStack->nFlags&0x40)!=0)
1087 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
1088 : else
1089 0 : SetPen( COL_TRANSPARENT, 0, PEN_NULL );
1090 : }
1091 : else
1092 : {
1093 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
1094 0 : ChangeBrush(Color( COL_TRANSPARENT ),Color( COL_TRANSPARENT ),sal_False);
1095 0 : SetRasterOp(aAttr.eLinMix);
1096 : }
1097 0 : pVirDev->DrawEllipse(aRect);
1098 0 : }
1099 :
1100 0 : void OS2METReader::ReadPartialArc(sal_Bool bGivenPos, sal_uInt16 nOrderSize)
1101 : {
1102 0 : Point aP0, aCenter,aPStart,aPEnd;
1103 : sal_Int32 nP,nQ,nR,nS,nStart, nSweep;
1104 0 : Rectangle aRect;
1105 : sal_uInt32 nMul; sal_uInt16 nMulS;
1106 : double fStart, fEnd;
1107 :
1108 0 : if (bGivenPos) {
1109 0 : aP0=ReadPoint();
1110 0 : if (bCoord32) nOrderSize-=8; else nOrderSize-=4;
1111 : }
1112 0 : else aP0=aAttr.aCurPos;
1113 0 : aCenter=ReadPoint();
1114 :
1115 0 : nP=aAttr.nArcP; nQ=aAttr.nArcQ; nR=aAttr.nArcR; nS=aAttr.nArcS;
1116 0 : if (nP<0) nP=-nP;
1117 0 : if (nQ<0) nQ=-nQ;
1118 0 : if (nR<0) nR=-nR;
1119 0 : if (nS<0) nS=-nS;
1120 0 : if (nOrderSize>=12) *pOS2MET >> nMul;
1121 0 : else { *pOS2MET >> nMulS; nMul=((sal_uLong)nMulS)<<8; }
1122 0 : if (nMul!=0x00010000) {
1123 0 : nP=(nP*nMul)>>16;
1124 0 : nQ=(nQ*nMul)>>16;
1125 0 : nR=(nR*nMul)>>16;
1126 0 : nS=(nS*nMul)>>16;
1127 : }
1128 :
1129 0 : *pOS2MET >> nStart >> nSweep;
1130 0 : fStart=((double)nStart)/65536.0/180.0*3.14159265359;
1131 0 : fEnd=fStart+((double)nSweep)/65536.0/180.0*3.14159265359;
1132 0 : aPStart=Point(aCenter.X()+(sal_Int32)( cos(fStart)*nP),
1133 0 : aCenter.Y()+(sal_Int32)(-sin(fStart)*nQ));
1134 0 : aPEnd= Point(aCenter.X()+(sal_Int32)( cos(fEnd)*nP),
1135 0 : aCenter.Y()+(sal_Int32)(-sin(fEnd)*nQ));
1136 :
1137 0 : aRect=Rectangle(aCenter.X()-nP,aCenter.Y()-nQ,
1138 0 : aCenter.X()+nP,aCenter.Y()+nQ);
1139 0 : aCalcBndRect.Union(aRect);
1140 :
1141 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
1142 0 : SetRasterOp(aAttr.eLinMix);
1143 :
1144 0 : pVirDev->DrawLine(aP0,aPStart);
1145 0 : pVirDev->DrawArc(aRect,aPStart,aPEnd);
1146 0 : aAttr.aCurPos=aPEnd;
1147 0 : }
1148 :
1149 0 : void OS2METReader::ReadPolygons()
1150 : {
1151 : sal_uInt32 i,j,nNumPolys, nNumPoints;
1152 0 : PolyPolygon aPolyPoly;
1153 0 : Polygon aPoly;
1154 0 : Point aPoint;
1155 : sal_uInt8 nFlags;
1156 :
1157 0 : *pOS2MET >> nFlags >> nNumPolys;
1158 0 : for (i=0; i<nNumPolys; i++) {
1159 0 : *pOS2MET >> nNumPoints;
1160 0 : if (i==0) nNumPoints++;
1161 0 : aPoly.SetSize((short)nNumPoints);
1162 0 : for (j=0; j<nNumPoints; j++) {
1163 0 : if (i==0 && j==0) aPoint=aAttr.aCurPos;
1164 0 : else aPoint=ReadPoint();
1165 0 : aPoly.SetPoint(aPoint,(short)j);
1166 0 : if (i==nNumPolys-1 && j==nNumPoints-1) aAttr.aCurPos=aPoint;
1167 : }
1168 0 : aPolyPoly.Insert(aPoly);
1169 : }
1170 :
1171 0 : ChangeBrush(aAttr.aPatCol,aAttr.aPatBgCol,aAttr.bFill);
1172 0 : SetRasterOp(aAttr.ePatMix);
1173 0 : if ((nFlags&0x01)!=0)
1174 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
1175 : else
1176 0 : SetPen( COL_TRANSPARENT, 0, PEN_NULL );
1177 0 : DrawPolyPolygon( aPolyPoly );
1178 0 : }
1179 :
1180 0 : void OS2METReader::ReadBezier(sal_Bool bGivenPos, sal_uInt16 nOrderLen)
1181 : {
1182 0 : sal_uInt16 i, nNumPoints = nOrderLen / ( bCoord32 ? 8 : 4 );
1183 :
1184 0 : if( !bGivenPos )
1185 0 : nNumPoints++;
1186 :
1187 0 : if( !nNumPoints )
1188 0 : return;
1189 :
1190 0 : Polygon aPolygon( nNumPoints );
1191 :
1192 0 : for( i=0; i < nNumPoints; i++ )
1193 : {
1194 0 : if( i==0 && !bGivenPos)
1195 0 : aPolygon.SetPoint( aAttr.aCurPos, i );
1196 : else
1197 0 : aPolygon.SetPoint( ReadPoint(), i );
1198 : }
1199 :
1200 0 : if( !( nNumPoints % 4 ) )
1201 : {
1202 : // create bezier polygon
1203 0 : const sal_uInt16 nSegPoints = 25;
1204 0 : const sal_uInt16 nSegments = aPolygon.GetSize() >> 2;
1205 0 : Polygon aBezPoly( nSegments * nSegPoints );
1206 :
1207 : sal_uInt16 nSeg, nBezPos, nStartPos;
1208 0 : for( nSeg = 0, nBezPos = 0, nStartPos = 0; nSeg < nSegments; nSeg++, nStartPos += 4 )
1209 : {
1210 0 : const Polygon aSegPoly( aPolygon[ nStartPos ], aPolygon[ nStartPos + 1 ],
1211 0 : aPolygon[ nStartPos + 3 ], aPolygon[ nStartPos + 2 ],
1212 0 : nSegPoints );
1213 :
1214 0 : for( sal_uInt16 nSegPos = 0; nSegPos < nSegPoints; )
1215 0 : aBezPoly[ nBezPos++ ] = aSegPoly[ nSegPos++ ];
1216 0 : }
1217 :
1218 0 : nNumPoints = nBezPos;
1219 :
1220 0 : if( nNumPoints != aBezPoly.GetSize() )
1221 0 : aBezPoly.SetSize( nNumPoints );
1222 :
1223 0 : aPolygon = aBezPoly;
1224 : }
1225 :
1226 0 : aAttr.aCurPos = aPolygon[ nNumPoints - 1 ];
1227 :
1228 0 : if (pAreaStack!=NULL)
1229 0 : AddPointsToArea(aPolygon);
1230 0 : else if (pPathStack!=NULL)
1231 0 : AddPointsToPath(aPolygon);
1232 : else
1233 : {
1234 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
1235 0 : SetRasterOp(aAttr.eLinMix);
1236 0 : DrawPolyLine( aPolygon );
1237 0 : }
1238 : }
1239 :
1240 0 : void OS2METReader::ReadFillet(sal_Bool bGivenPos, sal_uInt16 nOrderLen)
1241 : {
1242 : sal_uInt16 i,nNumPoints;
1243 :
1244 0 : if (bCoord32) nNumPoints=nOrderLen/8; else nNumPoints=nOrderLen/4;
1245 0 : if (!bGivenPos) nNumPoints++;
1246 0 : if (nNumPoints==0) return;
1247 0 : Polygon aPolygon(nNumPoints);
1248 0 : for (i=0; i<nNumPoints; i++) {
1249 0 : if (i==0 && !bGivenPos) aPolygon.SetPoint(aAttr.aCurPos,i);
1250 0 : else aPolygon.SetPoint(ReadPoint(),i);
1251 : }
1252 0 : aAttr.aCurPos=aPolygon.GetPoint(nNumPoints-1);
1253 0 : if (pAreaStack!=NULL) AddPointsToArea(aPolygon);
1254 0 : else if (pPathStack!=NULL) AddPointsToPath(aPolygon);
1255 : else {
1256 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
1257 0 : SetRasterOp(aAttr.eLinMix);
1258 0 : DrawPolyLine( aPolygon );
1259 0 : }
1260 : }
1261 :
1262 0 : void OS2METReader::ReadFilletSharp(sal_Bool bGivenPos, sal_uInt16 nOrderLen)
1263 : {
1264 : sal_uInt16 i,nNumPoints;
1265 :
1266 0 : if (bGivenPos) {
1267 0 : aAttr.aCurPos=ReadPoint();
1268 0 : if (bCoord32) nOrderLen-=8; else nOrderLen-=4;
1269 : }
1270 0 : if (bCoord32) nNumPoints=1+nOrderLen/10;
1271 0 : else nNumPoints=1+nOrderLen/6;
1272 0 : Polygon aPolygon(nNumPoints);
1273 0 : aPolygon.SetPoint(aAttr.aCurPos,0);
1274 0 : for (i=1; i<nNumPoints; i++) aPolygon.SetPoint(ReadPoint(),i);
1275 0 : aAttr.aCurPos=aPolygon.GetPoint(nNumPoints-1);
1276 0 : if (pAreaStack!=NULL) AddPointsToArea(aPolygon);
1277 0 : else if (pPathStack!=NULL) AddPointsToPath(aPolygon);
1278 : else
1279 : {
1280 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
1281 0 : SetRasterOp(aAttr.eLinMix);
1282 0 : DrawPolyLine( aPolygon );
1283 0 : }
1284 0 : }
1285 :
1286 0 : void OS2METReader::ReadMarker(sal_Bool bGivenPos, sal_uInt16 nOrderLen)
1287 : {
1288 : sal_uInt16 i,nNumPoints;
1289 : long x,y;
1290 :
1291 0 : SetPen( aAttr.aMrkCol );
1292 0 : SetRasterOp(aAttr.eMrkMix);
1293 0 : if (aAttr.nMrkSymbol>=5 && aAttr.nMrkSymbol<=9)
1294 : {
1295 0 : ChangeBrush(aAttr.aMrkCol,aAttr.aMrkCol,sal_True);
1296 : }
1297 : else
1298 : {
1299 0 : ChangeBrush(Color(COL_TRANSPARENT),Color(COL_TRANSPARENT),sal_False);
1300 : }
1301 0 : if (bCoord32) nNumPoints=nOrderLen/8; else nNumPoints=nOrderLen/4;
1302 0 : if (!bGivenPos) nNumPoints++;
1303 0 : for (i=0; i<nNumPoints; i++) {
1304 0 : if (i!=0 || bGivenPos) aAttr.aCurPos=ReadPoint();
1305 0 : x=aAttr.aCurPos.X(); y=aAttr.aCurPos.Y();
1306 0 : aCalcBndRect.Union(Rectangle(x-5,y-5,x+5,y+5));
1307 0 : switch (aAttr.nMrkSymbol) {
1308 : case 2: // PLUS
1309 0 : pVirDev->DrawLine(Point(x-4,y),Point(x+4,y));
1310 0 : pVirDev->DrawLine(Point(x,y-4),Point(x,y+4));
1311 0 : break;
1312 : case 3: // DIAMOND
1313 : case 7: { // SOLIDDIAMOND
1314 0 : Polygon aPoly(4);
1315 0 : aPoly.SetPoint(Point(x,y+4),0);
1316 0 : aPoly.SetPoint(Point(x+4,y),1);
1317 0 : aPoly.SetPoint(Point(x,y-4),2);
1318 0 : aPoly.SetPoint(Point(x-4,y),3);
1319 0 : pVirDev->DrawPolygon(aPoly);
1320 0 : break;
1321 : }
1322 : case 4: // SQARE
1323 : case 8: { // SOLIDSUARE
1324 0 : Polygon aPoly(4);
1325 0 : aPoly.SetPoint(Point(x+4,y+4),0);
1326 0 : aPoly.SetPoint(Point(x+4,y-4),1);
1327 0 : aPoly.SetPoint(Point(x-4,y-4),2);
1328 0 : aPoly.SetPoint(Point(x-4,y+4),3);
1329 0 : pVirDev->DrawPolygon(aPoly);
1330 0 : break;
1331 : }
1332 : case 5: { // SIXPOINTSTAR
1333 0 : Polygon aPoly(12);
1334 0 : aPoly.SetPoint(Point(x ,y-4),0);
1335 0 : aPoly.SetPoint(Point(x+2,y-2),1);
1336 0 : aPoly.SetPoint(Point(x+4,y-2),2);
1337 0 : aPoly.SetPoint(Point(x+2,y ),3);
1338 0 : aPoly.SetPoint(Point(x+4,y+2),4);
1339 0 : aPoly.SetPoint(Point(x+2,y+2),5);
1340 0 : aPoly.SetPoint(Point(x ,y+4),6);
1341 0 : aPoly.SetPoint(Point(x-2,y+2),7);
1342 0 : aPoly.SetPoint(Point(x-4,y+2),8);
1343 0 : aPoly.SetPoint(Point(x-2,y ),9);
1344 0 : aPoly.SetPoint(Point(x-4,y-2),10);
1345 0 : aPoly.SetPoint(Point(x-2,y-2),11);
1346 0 : pVirDev->DrawPolygon(aPoly);
1347 0 : break;
1348 : }
1349 : case 6: { // EIGHTPOINTSTAR
1350 0 : Polygon aPoly(16);
1351 0 : aPoly.SetPoint(Point(x ,y-4),0);
1352 0 : aPoly.SetPoint(Point(x+1,y-2),1);
1353 0 : aPoly.SetPoint(Point(x+3,y-3),2);
1354 0 : aPoly.SetPoint(Point(x+2,y-1),3);
1355 0 : aPoly.SetPoint(Point(x+4,y ),4);
1356 0 : aPoly.SetPoint(Point(x+2,y+1),5);
1357 0 : aPoly.SetPoint(Point(x+3,y+3),6);
1358 0 : aPoly.SetPoint(Point(x+1,y+2),7);
1359 0 : aPoly.SetPoint(Point(x ,y+4),8);
1360 0 : aPoly.SetPoint(Point(x-1,y+2),9);
1361 0 : aPoly.SetPoint(Point(x-3,y+3),10);
1362 0 : aPoly.SetPoint(Point(x-2,y+1),11);
1363 0 : aPoly.SetPoint(Point(x-4,y ),12);
1364 0 : aPoly.SetPoint(Point(x-2,y-1),13);
1365 0 : aPoly.SetPoint(Point(x-3,y-3),14);
1366 0 : aPoly.SetPoint(Point(x-1,y-2),15);
1367 0 : pVirDev->DrawPolygon(aPoly);
1368 0 : break;
1369 : }
1370 : case 9: // DOT
1371 0 : pVirDev->DrawEllipse(Rectangle(x-1,y-1,x+1,y+1));
1372 0 : break;
1373 : case 10: // SMALLCIRCLE
1374 0 : pVirDev->DrawEllipse(Rectangle(x-2,y-2,x+2,y+2));
1375 0 : break;
1376 : case 64: // BLANK
1377 0 : break;
1378 : default: // (=1) CROSS
1379 0 : pVirDev->DrawLine(Point(x-4,y-4),Point(x+4,y+4));
1380 0 : pVirDev->DrawLine(Point(x-4,y+4),Point(x+4,y-4));
1381 0 : break;
1382 : }
1383 : }
1384 0 : }
1385 :
1386 0 : void OS2METReader::ReadOrder(sal_uInt16 nOrderID, sal_uInt16 nOrderLen)
1387 : {
1388 0 : switch (nOrderID) {
1389 :
1390 0 : case GOrdGivArc: ReadArc(sal_True); break;
1391 0 : case GOrdCurArc: ReadArc(sal_False); break;
1392 :
1393 0 : case GOrdGivBzr: ReadBezier(sal_True,nOrderLen); break;
1394 0 : case GOrdCurBzr: ReadBezier(sal_False,nOrderLen); break;
1395 :
1396 0 : case GOrdGivBox: ReadBox(sal_True); break;
1397 0 : case GOrdCurBox: ReadBox(sal_False); break;
1398 :
1399 0 : case GOrdGivFil: ReadFillet(sal_True,nOrderLen); break;
1400 0 : case GOrdCurFil: ReadFillet(sal_False,nOrderLen); break;
1401 :
1402 0 : case GOrdGivCrc: ReadFullArc(sal_True,nOrderLen); break;
1403 0 : case GOrdCurCrc: ReadFullArc(sal_False,nOrderLen); break;
1404 :
1405 0 : case GOrdGivLin: ReadLine(sal_True, nOrderLen); break;
1406 0 : case GOrdCurLin: ReadLine(sal_False, nOrderLen); break;
1407 :
1408 0 : case GOrdGivMrk: ReadMarker(sal_True, nOrderLen); break;
1409 0 : case GOrdCurMrk: ReadMarker(sal_False, nOrderLen); break;
1410 :
1411 0 : case GOrdGivArP: ReadPartialArc(sal_True,nOrderLen); break;
1412 0 : case GOrdCurArP: ReadPartialArc(sal_False,nOrderLen); break;
1413 :
1414 0 : case GOrdGivRLn: ReadRelLine(sal_True,nOrderLen); break;
1415 0 : case GOrdCurRLn: ReadRelLine(sal_False,nOrderLen); break;
1416 :
1417 0 : case GOrdGivSFl: ReadFilletSharp(sal_True,nOrderLen); break;
1418 0 : case GOrdCurSFl: ReadFilletSharp(sal_False,nOrderLen); break;
1419 :
1420 0 : case GOrdGivStM: ReadChrStr(sal_True , sal_True , sal_False, nOrderLen); break;
1421 0 : case GOrdCurStM: ReadChrStr(sal_False, sal_True , sal_False, nOrderLen); break;
1422 0 : case GOrdGivStr: ReadChrStr(sal_True , sal_False, sal_False, nOrderLen); break;
1423 0 : case GOrdCurStr: ReadChrStr(sal_False, sal_False, sal_False, nOrderLen); break;
1424 0 : case GOrdGivStx: ReadChrStr(sal_True , sal_False, sal_True , nOrderLen); break;
1425 0 : case GOrdCurStx: ReadChrStr(sal_False, sal_False, sal_True , nOrderLen); break;
1426 :
1427 : case GOrdGivImg: OOODEBUG("GOrdGivImg",0);
1428 0 : break;
1429 : case GOrdCurImg: OOODEBUG("GOrdCurImg",0);
1430 0 : break;
1431 : case GOrdImgDat: OOODEBUG("GOrdImgDat",0);
1432 0 : break;
1433 : case GOrdEndImg: OOODEBUG("GOrdEndImg",0);
1434 0 : break;
1435 :
1436 : case GOrdBegAra: {
1437 0 : OSArea * p=new OSArea;
1438 0 : p->bClosed=sal_False;
1439 0 : p->pSucc=pAreaStack; pAreaStack=p;
1440 0 : *pOS2MET >> (p->nFlags);
1441 0 : p->aCol=aAttr.aPatCol;
1442 0 : p->aBgCol=aAttr.aPatBgCol;
1443 0 : p->eMix=aAttr.ePatMix;
1444 0 : p->eBgMix=aAttr.ePatBgMix;
1445 0 : p->bFill=aAttr.bFill;
1446 0 : break;
1447 : }
1448 : case GOrdEndAra:
1449 : {
1450 0 : OSArea * p=pAreaStack;
1451 0 : if ( p )
1452 : {
1453 0 : pAreaStack = p->pSucc;
1454 0 : if ( pPathStack )
1455 : {
1456 0 : for ( sal_uInt16 i=0; i<p->aPPoly.Count(); i++ )
1457 : {
1458 0 : AddPointsToPath( p->aPPoly.GetObject( i ) );
1459 0 : CloseFigure();
1460 : }
1461 : }
1462 : else
1463 : {
1464 0 : if ( ( p->nFlags & 0x40 ) == 0 )
1465 0 : SetPen( COL_TRANSPARENT, 0, PEN_NULL );
1466 : else
1467 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
1468 :
1469 0 : ChangeBrush(p->aCol,p->aBgCol,p->bFill);
1470 0 : SetRasterOp(p->eMix);
1471 0 : DrawPolyPolygon( p->aPPoly );
1472 : }
1473 0 : delete p;
1474 : }
1475 : }
1476 0 : break;
1477 :
1478 : case GOrdBegElm:// OOODEBUG("GOrdBegElm",0);
1479 0 : break;
1480 : case GOrdEndElm:// OOODEBUG("GOrdEndElm",0);
1481 0 : break;
1482 :
1483 : case GOrdBegPth: {
1484 0 : OSPath * p=new OSPath;
1485 0 : p->pSucc=pPathStack; pPathStack=p;
1486 0 : pOS2MET->SeekRel(2);
1487 0 : *pOS2MET >> p->nID;
1488 0 : p->bClosed=sal_False;
1489 0 : p->bStroke=sal_False;
1490 0 : break;
1491 : }
1492 : case GOrdEndPth: {
1493 : OSPath * p, * pprev, * psucc;
1494 0 : if (pPathStack==NULL) break;
1495 0 : p=pPathList; pprev=NULL;
1496 0 : while (p!=NULL) {
1497 0 : psucc=p->pSucc;
1498 0 : if (p->nID==pPathStack->nID) {
1499 0 : if (pprev==NULL) pPathList=psucc; else pprev->pSucc=psucc;
1500 0 : delete p;
1501 : }
1502 0 : else pprev=p;
1503 0 : p=psucc;
1504 : }
1505 0 : p=pPathStack;
1506 0 : pPathStack=p->pSucc;
1507 0 : p->pSucc=pPathList; pPathList=p;
1508 0 : break;
1509 : }
1510 : case GOrdFilPth:
1511 : {
1512 : sal_uInt32 nID;
1513 : sal_uInt16 nDummy;
1514 0 : OSPath* p = pPathList;
1515 :
1516 0 : *pOS2MET >> nDummy
1517 0 : >> nID;
1518 :
1519 0 : if ( ! ( nDummy & 0x20 ) ) // #30933# i do not know the exact meaning of this bit,
1520 : { // but if set it seems to be better not to fill this path
1521 0 : while( p && p->nID != nID )
1522 0 : p = p->pSucc;
1523 :
1524 0 : if( p )
1525 : {
1526 0 : if( p->bStroke )
1527 : {
1528 0 : SetPen( aAttr.aPatCol, aAttr.nStrLinWidth, PEN_SOLID );
1529 0 : ChangeBrush(Color(COL_TRANSPARENT),Color(COL_TRANSPARENT),sal_False);
1530 0 : SetRasterOp( aAttr.ePatMix );
1531 0 : if ( IsLineInfo() )
1532 : {
1533 0 : for ( sal_uInt16 i = 0; i < p->aPPoly.Count(); i++ )
1534 0 : pVirDev->DrawPolyLine( p->aPPoly.GetObject( i ), aLineInfo );
1535 : }
1536 : else
1537 0 : pVirDev->DrawPolyPolygon( p->aPPoly );
1538 : }
1539 : else
1540 : {
1541 0 : SetPen( COL_TRANSPARENT, 0, PEN_NULL );
1542 0 : ChangeBrush( aAttr.aPatCol, aAttr.aPatBgCol, aAttr.bFill );
1543 0 : SetRasterOp( aAttr.ePatMix );
1544 0 : pVirDev->DrawPolyPolygon( p->aPPoly );
1545 : }
1546 : }
1547 : }
1548 : }
1549 0 : break;
1550 :
1551 : case GOrdModPth:
1552 : {
1553 0 : OSPath* p = pPathList;
1554 :
1555 0 : while( p && p->nID != 1 )
1556 0 : p = p->pSucc;
1557 :
1558 0 : if( p )
1559 0 : p->bStroke = sal_True;
1560 : }
1561 0 : break;
1562 :
1563 : case GOrdOutPth:
1564 : {
1565 : sal_uInt32 nID;
1566 : sal_uInt16 i,nC;
1567 0 : OSPath* p=pPathList;
1568 0 : pOS2MET->SeekRel(2);
1569 0 : *pOS2MET >> nID;
1570 0 : while (p!=NULL && p->nID!=nID)
1571 0 : p=p->pSucc;
1572 :
1573 0 : if( p!=NULL )
1574 : {
1575 0 : SetPen( aAttr.aLinCol, aAttr.nStrLinWidth, aAttr.eLinStyle );
1576 0 : SetRasterOp(aAttr.eLinMix);
1577 0 : ChangeBrush(Color(COL_TRANSPARENT),Color(COL_TRANSPARENT),sal_False);
1578 0 : nC=p->aPPoly.Count();
1579 0 : for (i=0; i<nC; i++)
1580 : {
1581 0 : if (i+1<nC || p->bClosed==sal_True)
1582 0 : DrawPolygon( p->aPPoly.GetObject( i ) );
1583 : else
1584 0 : DrawPolyLine( p->aPPoly.GetObject( i ) );
1585 : }
1586 : }
1587 : break;
1588 : }
1589 : case GOrdSClPth: { OOODEBUG("GOrdSClPth",0);
1590 : sal_uInt32 nID;
1591 0 : OSPath * p=pPathList;
1592 0 : pOS2MET->SeekRel(2);
1593 0 : *pOS2MET >> nID;
1594 0 : if (nID==0) p=NULL;
1595 0 : while (p!=NULL && p->nID!=nID) p=p->pSucc;
1596 0 : if (p!=NULL) pVirDev->SetClipRegion(Region(p->aPPoly));
1597 0 : else pVirDev->SetClipRegion();
1598 : break;
1599 : }
1600 : case GOrdNopNop:
1601 0 : break;
1602 : case GOrdRemark: //OOODEBUG("GOrdRemark",0);
1603 0 : break;
1604 : case GOrdSegLab: OOODEBUG("GOrdSegLab",0);
1605 0 : break;
1606 :
1607 0 : case GOrdBitBlt: ReadBitBlt(); break;
1608 :
1609 : case GOrdCalSeg: OOODEBUG("GOrdCalSeg",0);
1610 0 : break;
1611 : case GOrdSSgBnd: OOODEBUG("GOrdSSgBnd",0);
1612 0 : break;
1613 : case GOrdSegChr: OOODEBUG("GOrdSegChr",0);
1614 0 : break;
1615 : case GOrdCloFig:
1616 0 : CloseFigure();
1617 0 : break;
1618 : case GOrdEndSym: OOODEBUG("GOrdEndSym",0);
1619 0 : break;
1620 : case GOrdEndPlg: OOODEBUG("GOrdEndPlg",0);
1621 0 : break;
1622 : case GOrdEscape: OOODEBUG("GOrdEscape",0);
1623 0 : break;
1624 : case GOrdExtEsc: OOODEBUG("GOrdExtEsc",0);
1625 0 : break;
1626 :
1627 0 : case GOrdPolygn: ReadPolygons(); break;
1628 :
1629 0 : case GOrdStkPop: PopAttr(); break;
1630 :
1631 0 : case GOrdPIvAtr: PushAttr(nOrderID);
1632 : case GOrdSIvAtr: {
1633 : sal_uInt8 nA, nP, nFlags, nMix;
1634 : sal_uLong nVal;
1635 0 : Color aCol;
1636 : RasterOp eROP;
1637 0 : *pOS2MET >> nA >> nP >> nFlags;
1638 0 : if (nOrderID==GOrdPIvAtr) {
1639 0 : pAttrStack->nIvAttrA=nA;
1640 0 : pAttrStack->nIvAttrP=nP;
1641 : }
1642 0 : if (nA<=2) {
1643 0 : if ((nFlags&0x80)!=0) {
1644 0 : if (nA==1) switch (nP) {
1645 0 : case 1: aAttr.aLinCol=aDefAttr.aLinCol; break;
1646 0 : case 2: aAttr.aChrCol=aDefAttr.aChrCol; break;
1647 0 : case 3: aAttr.aMrkCol=aDefAttr.aMrkCol; break;
1648 0 : case 4: aAttr.aPatCol=aDefAttr.aPatCol; break;
1649 0 : case 5: aAttr.aImgCol=aDefAttr.aImgCol; break;
1650 : }
1651 0 : else switch (nP) {
1652 0 : case 1: aAttr.aLinBgCol=aDefAttr.aLinBgCol; break;
1653 0 : case 2: aAttr.aChrBgCol=aDefAttr.aChrBgCol; break;
1654 0 : case 3: aAttr.aMrkBgCol=aDefAttr.aMrkBgCol; break;
1655 0 : case 4: aAttr.aPatBgCol=aDefAttr.aPatBgCol; break;
1656 0 : case 5: aAttr.aImgBgCol=aDefAttr.aImgBgCol; break;
1657 : }
1658 : }
1659 : else {
1660 0 : nVal=ReadLittleEndian3BytesLong();
1661 0 : if ((nFlags&0x40)!=0 && nVal==1) aCol=Color(COL_BLACK);
1662 0 : else if ((nFlags&0x40)!=0 && nVal==2) aCol=Color(COL_WHITE);
1663 0 : else if ((nFlags&0x40)!=0 && nVal==4) aCol=Color(COL_WHITE);
1664 0 : else if ((nFlags&0x40)!=0 && nVal==5) aCol=Color(COL_BLACK);
1665 0 : else aCol=GetPaletteColor(nVal);
1666 0 : if (nA==1) switch (nP) {
1667 0 : case 1: aAttr.aLinCol=aCol; break;
1668 0 : case 2: aAttr.aChrCol=aCol; break;
1669 0 : case 3: aAttr.aMrkCol=aCol; break;
1670 0 : case 4: aAttr.aPatCol=aCol; break;
1671 0 : case 5: aAttr.aImgCol=aCol; break;
1672 : }
1673 0 : else switch (nP) {
1674 0 : case 1: aAttr.aLinBgCol=aCol; break;
1675 0 : case 2: aAttr.aChrBgCol=aCol; break;
1676 0 : case 3: aAttr.aMrkBgCol=aCol; break;
1677 0 : case 4: aAttr.aPatBgCol=aCol; break;
1678 0 : case 5: aAttr.aImgBgCol=aCol; break;
1679 : }
1680 : }
1681 : }
1682 : else {
1683 0 : *pOS2MET >> nMix;
1684 0 : if (nMix==0) {
1685 0 : if (nA==1) switch (nP) {
1686 0 : case 1: aAttr.eLinMix=aDefAttr.eLinMix; break;
1687 0 : case 2: aAttr.eChrMix=aDefAttr.eChrMix; break;
1688 0 : case 3: aAttr.eMrkMix=aDefAttr.eMrkMix; break;
1689 0 : case 4: aAttr.ePatMix=aDefAttr.ePatMix; break;
1690 0 : case 5: aAttr.eImgMix=aDefAttr.eImgMix; break;
1691 : }
1692 0 : else switch (nP) {
1693 0 : case 1: aAttr.eLinBgMix=aDefAttr.eLinBgMix; break;
1694 0 : case 2: aAttr.eChrBgMix=aDefAttr.eChrBgMix; break;
1695 0 : case 3: aAttr.eMrkBgMix=aDefAttr.eMrkBgMix; break;
1696 0 : case 4: aAttr.ePatBgMix=aDefAttr.ePatBgMix; break;
1697 0 : case 5: aAttr.eImgBgMix=aDefAttr.eImgBgMix; break;
1698 : }
1699 : }
1700 : else {
1701 0 : eROP=OS2MixToRasterOp(nMix);
1702 0 : if (nA==1) switch (nP) {
1703 0 : case 1: aAttr.eLinMix=eROP; break;
1704 0 : case 2: aAttr.eChrMix=eROP; break;
1705 0 : case 3: aAttr.eMrkMix=eROP; break;
1706 0 : case 4: aAttr.ePatMix=eROP; break;
1707 0 : case 5: aAttr.eImgMix=eROP; break;
1708 : }
1709 0 : else switch (nP) {
1710 0 : case 1: aAttr.eLinBgMix=eROP; break;
1711 0 : case 2: aAttr.eChrBgMix=eROP; break;
1712 0 : case 3: aAttr.eMrkBgMix=eROP; break;
1713 0 : case 4: aAttr.ePatBgMix=eROP; break;
1714 0 : case 5: aAttr.eImgBgMix=eROP; break;
1715 : }
1716 : }
1717 : }
1718 : break;
1719 : }
1720 0 : case GOrdPIxCol: PushAttr(nOrderID);
1721 : case GOrdSIxCol: {
1722 : sal_uInt8 nFlags;
1723 : sal_uLong nVal;
1724 0 : Color aCol;
1725 0 : *pOS2MET >> nFlags;
1726 0 : if ((nFlags&0x80)!=0) {
1727 0 : aAttr.aLinCol=aDefAttr.aLinCol;
1728 0 : aAttr.aChrCol=aDefAttr.aChrCol;
1729 0 : aAttr.aMrkCol=aDefAttr.aMrkCol;
1730 0 : aAttr.aPatCol=aDefAttr.aPatCol;
1731 0 : aAttr.aImgCol=aDefAttr.aImgCol;
1732 : }
1733 : else {
1734 0 : nVal=ReadLittleEndian3BytesLong();
1735 0 : if ((nFlags&0x40)!=0 && nVal==1) aCol=Color(COL_BLACK);
1736 0 : else if ((nFlags&0x40)!=0 && nVal==2) aCol=Color(COL_WHITE);
1737 0 : else if ((nFlags&0x40)!=0 && nVal==4) aCol=Color(COL_WHITE);
1738 0 : else if ((nFlags&0x40)!=0 && nVal==5) aCol=Color(COL_BLACK);
1739 0 : else aCol=GetPaletteColor(nVal);
1740 : aAttr.aLinCol = aAttr.aChrCol = aAttr.aMrkCol = aAttr.aPatCol =
1741 0 : aAttr.aImgCol = aCol;
1742 : }
1743 : break;
1744 : }
1745 :
1746 : case GOrdPColor:
1747 0 : case GOrdPXtCol: PushAttr(nOrderID);
1748 : case GOrdSColor:
1749 : case GOrdSXtCol: {
1750 : sal_uInt8 nbyte;
1751 : sal_uInt16 nVal;
1752 0 : Color aCol;
1753 0 : if (nOrderID==GOrdPColor || nOrderID==GOrdSColor) {
1754 0 : *pOS2MET >> nbyte; nVal=((sal_uInt16)nbyte)|0xff00;
1755 : }
1756 0 : else *pOS2MET >> nVal;
1757 0 : if (nVal==0x0000 || nVal==0xff00) {
1758 0 : aAttr.aLinCol=aDefAttr.aLinCol;
1759 0 : aAttr.aChrCol=aDefAttr.aChrCol;
1760 0 : aAttr.aMrkCol=aDefAttr.aMrkCol;
1761 0 : aAttr.aPatCol=aDefAttr.aPatCol;
1762 0 : aAttr.aImgCol=aDefAttr.aImgCol;
1763 : }
1764 : else {
1765 0 : if (nVal==0x0007) aCol=Color(COL_WHITE);
1766 0 : else if (nVal==0x0008) aCol=Color(COL_BLACK);
1767 0 : else if (nVal==0xff08) aCol=GetPaletteColor(1);
1768 0 : else aCol=GetPaletteColor(((sal_uLong)nVal) & 0x000000ff);
1769 : aAttr.aLinCol = aAttr.aChrCol = aAttr.aMrkCol = aAttr.aPatCol =
1770 0 : aAttr.aImgCol = aCol;
1771 : }
1772 : break;
1773 : }
1774 :
1775 0 : case GOrdPBgCol: PushAttr(nOrderID);
1776 : case GOrdSBgCol: {
1777 : sal_uInt16 nVal;
1778 0 : Color aCol;
1779 0 : *pOS2MET >> nVal;
1780 0 : if (nVal==0x0000 || nVal==0xff00) {
1781 0 : aAttr.aLinBgCol=aDefAttr.aLinBgCol;
1782 0 : aAttr.aChrBgCol=aDefAttr.aChrBgCol;
1783 0 : aAttr.aMrkBgCol=aDefAttr.aMrkBgCol;
1784 0 : aAttr.aPatBgCol=aDefAttr.aPatBgCol;
1785 0 : aAttr.aImgBgCol=aDefAttr.aImgBgCol;
1786 : }
1787 : else {
1788 0 : if (nVal==0x0007) aCol=Color(COL_WHITE);
1789 0 : else if (nVal==0x0008) aCol=Color(COL_BLACK);
1790 0 : else if (nVal==0xff08) aCol=GetPaletteColor(0);
1791 0 : else aCol=GetPaletteColor(((sal_uLong)nVal) & 0x000000ff);
1792 : aAttr.aLinBgCol = aAttr.aChrBgCol = aAttr.aMrkBgCol =
1793 0 : aAttr.aPatBgCol = aAttr.aImgBgCol = aCol;
1794 : }
1795 : break;
1796 : }
1797 0 : case GOrdPBxCol: PushAttr(nOrderID);
1798 : case GOrdSBxCol: {
1799 : sal_uInt8 nFlags;
1800 : sal_uLong nVal;
1801 0 : Color aCol;
1802 0 : *pOS2MET >> nFlags;
1803 0 : if ((nFlags&0x80)!=0) {
1804 0 : aAttr.aLinBgCol=aDefAttr.aLinBgCol;
1805 0 : aAttr.aChrBgCol=aDefAttr.aChrBgCol;
1806 0 : aAttr.aMrkBgCol=aDefAttr.aMrkBgCol;
1807 0 : aAttr.aPatBgCol=aDefAttr.aPatBgCol;
1808 0 : aAttr.aImgBgCol=aDefAttr.aImgBgCol;
1809 : }
1810 : else {
1811 0 : nVal=ReadLittleEndian3BytesLong();
1812 0 : if ((nFlags&0x40)!=0 && nVal==1) aCol=Color(COL_BLACK);
1813 0 : else if ((nFlags&0x40)!=0 && nVal==2) aCol=Color(COL_WHITE);
1814 0 : else if ((nFlags&0x40)!=0 && nVal==4) aCol=Color(COL_WHITE);
1815 0 : else if ((nFlags&0x40)!=0 && nVal==5) aCol=Color(COL_BLACK);
1816 0 : else aCol=GetPaletteColor(nVal);
1817 : aAttr.aLinBgCol = aAttr.aChrBgCol = aAttr.aMrkBgCol =
1818 0 : aAttr.aPatBgCol = aAttr.aImgBgCol = aCol;
1819 : }
1820 : break;
1821 : }
1822 :
1823 0 : case GOrdPMixMd: PushAttr(nOrderID);
1824 : case GOrdSMixMd: {
1825 : sal_uInt8 nMix;
1826 0 : *pOS2MET >> nMix;
1827 0 : if (nMix==0) {
1828 0 : aAttr.eLinMix=aDefAttr.eLinMix;
1829 0 : aAttr.eChrMix=aDefAttr.eChrMix;
1830 0 : aAttr.eMrkMix=aDefAttr.eMrkMix;
1831 0 : aAttr.ePatMix=aDefAttr.ePatMix;
1832 0 : aAttr.eImgMix=aDefAttr.eImgMix;
1833 : }
1834 : else {
1835 : aAttr.eLinMix = aAttr.eChrMix = aAttr.eMrkMix =
1836 0 : aAttr.ePatMix = aAttr.eImgMix = OS2MixToRasterOp(nMix);
1837 : }
1838 : break;
1839 : }
1840 0 : case GOrdPBgMix: PushAttr(nOrderID);
1841 : case GOrdSBgMix: {
1842 : sal_uInt8 nMix;
1843 0 : *pOS2MET >> nMix;
1844 0 : if (nMix==0) {
1845 0 : aAttr.eLinBgMix=aDefAttr.eLinBgMix;
1846 0 : aAttr.eChrBgMix=aDefAttr.eChrBgMix;
1847 0 : aAttr.eMrkBgMix=aDefAttr.eMrkBgMix;
1848 0 : aAttr.ePatBgMix=aDefAttr.ePatBgMix;
1849 0 : aAttr.eImgBgMix=aDefAttr.eImgBgMix;
1850 : }
1851 : else {
1852 : aAttr.eLinBgMix = aAttr.eChrBgMix = aAttr.eMrkBgMix =
1853 0 : aAttr.ePatBgMix = aAttr.eImgBgMix = OS2MixToRasterOp(nMix);
1854 : }
1855 : break;
1856 : }
1857 0 : case GOrdPPtSet: PushAttr(nOrderID);
1858 : case GOrdSPtSet: OOODEBUG("GOrdSPtSet",0);
1859 0 : break;
1860 :
1861 0 : case GOrdPPtSym: PushAttr(nOrderID);
1862 : case GOrdSPtSym: {
1863 : sal_uInt8 nPatt;
1864 0 : *pOS2MET >> nPatt;
1865 0 : aAttr.bFill = ( nPatt != 0x0f );
1866 : break;
1867 : }
1868 :
1869 0 : case GOrdPPtRef: PushAttr(nOrderID);
1870 : case GOrdSPtRef: OOODEBUG("GOrdSPtRef",0);
1871 0 : break;
1872 :
1873 0 : case GOrdPLnEnd: PushAttr(nOrderID);
1874 : case GOrdSLnEnd:
1875 0 : break;
1876 :
1877 0 : case GOrdPLnJoi: PushAttr(nOrderID);
1878 : case GOrdSLnJoi:
1879 0 : break;
1880 :
1881 0 : case GOrdPLnTyp: PushAttr(nOrderID);
1882 : case GOrdSLnTyp: {
1883 : sal_uInt8 nType;
1884 0 : *pOS2MET >> nType;
1885 0 : switch (nType) {
1886 0 : case 0: aAttr.eLinStyle=aDefAttr.eLinStyle; break;
1887 0 : case 1: case 4: aAttr.eLinStyle=PEN_DOT; break;
1888 0 : case 2: case 5: aAttr.eLinStyle=PEN_DASH; break;
1889 0 : case 3: case 6: aAttr.eLinStyle=PEN_DASHDOT; break;
1890 0 : case 8: aAttr.eLinStyle=PEN_NULL; break;
1891 0 : default: aAttr.eLinStyle=PEN_SOLID;
1892 : }
1893 : break;
1894 : }
1895 0 : case GOrdPLnWdt: PushAttr(nOrderID);
1896 : case GOrdSLnWdt: {
1897 : sal_uInt8 nbyte;
1898 0 : *pOS2MET >> nbyte;
1899 0 : if (nbyte==0) aAttr.nLinWidth=aDefAttr.nLinWidth;
1900 0 : else aAttr.nLinWidth=(sal_uInt16)nbyte-1;
1901 : break;
1902 : }
1903 0 : case GOrdPFrLWd: PushAttr(nOrderID);
1904 : case GOrdSFrLWd:
1905 0 : break;
1906 :
1907 0 : case GOrdPStLWd: PushAttr(nOrderID);
1908 : case GOrdSStLWd :
1909 : {
1910 : sal_uInt8 nFlags;
1911 :
1912 0 : *pOS2MET >> nFlags;
1913 0 : if ( nFlags & 0x80 )
1914 0 : aAttr.nStrLinWidth = aDefAttr.nStrLinWidth;
1915 : else
1916 : {
1917 0 : pOS2MET->SeekRel( 1 );
1918 0 : long nWd = ReadCoord( bCoord32 );
1919 0 : if ( nWd < 0 )
1920 0 : nWd = -nWd;
1921 0 : aAttr.nStrLinWidth = (sal_uInt16)nWd;
1922 : }
1923 : break;
1924 : }
1925 0 : case GOrdPChDir: PushAttr(nOrderID);
1926 : case GOrdSChDir:
1927 0 : break;
1928 :
1929 0 : case GOrdPChPrc: PushAttr(nOrderID);
1930 : case GOrdSChPrc:
1931 0 : break;
1932 :
1933 0 : case GOrdPChSet: PushAttr(nOrderID);
1934 : case GOrdSChSet: {
1935 0 : sal_uInt8 nbyte; *pOS2MET >> nbyte;
1936 0 : aAttr.nChrSet=((sal_uLong)nbyte)&0xff;
1937 : break;
1938 : }
1939 0 : case GOrdPChAng: PushAttr(nOrderID);
1940 : case GOrdSChAng: {
1941 : long nX,nY;
1942 0 : nX=ReadCoord(bCoord32); nY=ReadCoord(bCoord32);
1943 0 : if (nX>=0 && nY==0) aAttr.nChrAng=0;
1944 : else {
1945 0 : aAttr.nChrAng=(short)(atan2((double)nY,(double)nX)/3.1415926539*1800.0);
1946 0 : while (aAttr.nChrAng<0) aAttr.nChrAng+=3600;
1947 0 : aAttr.nChrAng%=3600;
1948 : }
1949 0 : break;
1950 : }
1951 0 : case GOrdPChBrx: PushAttr(nOrderID);
1952 : case GOrdSChBrx:
1953 0 : break;
1954 :
1955 0 : case GOrdPChCel: PushAttr(nOrderID);
1956 : case GOrdSChCel: {
1957 : sal_uInt8 nbyte;
1958 0 : sal_uInt16 nLen=nOrderLen;
1959 0 : aAttr.aChrCellSize.Width()=ReadCoord(bCoord32);
1960 0 : aAttr.aChrCellSize.Height()=ReadCoord(bCoord32);
1961 0 : if (bCoord32) nLen-=8; else nLen-=4;
1962 0 : if (nLen>=4) {
1963 0 : pOS2MET->SeekRel(4); nLen-=4;
1964 : }
1965 0 : if (nLen>=2) {
1966 0 : *pOS2MET >> nbyte;
1967 0 : if ((nbyte&0x80)==0 && aAttr.aChrCellSize==Size(0,0))
1968 0 : aAttr.aChrCellSize=aDefAttr.aChrCellSize;
1969 : }
1970 : break;
1971 : }
1972 0 : case GOrdPChXtr: PushAttr(nOrderID);
1973 : case GOrdSChXtr:
1974 0 : break;
1975 :
1976 0 : case GOrdPChShr: PushAttr(nOrderID);
1977 : case GOrdSChShr:
1978 0 : break;
1979 :
1980 0 : case GOrdPTxAlg: PushAttr(nOrderID);
1981 : case GOrdSTxAlg: OOODEBUG("GOrdSTxAlg",0);
1982 0 : break;
1983 :
1984 0 : case GOrdPMkPrc: PushAttr(nOrderID);
1985 : case GOrdSMkPrc: {
1986 : sal_uInt8 nbyte;
1987 0 : *pOS2MET >> nbyte;
1988 0 : if (nbyte==0) aAttr.nMrkPrec=aDefAttr.nMrkPrec;
1989 0 : else aAttr.nMrkPrec=nbyte;
1990 : break;
1991 : }
1992 :
1993 0 : case GOrdPMkSet: PushAttr(nOrderID);
1994 : case GOrdSMkSet: {
1995 : sal_uInt8 nbyte;
1996 0 : *pOS2MET >> nbyte;
1997 0 : if (nbyte==0) aAttr.nMrkSet=aDefAttr.nMrkSet;
1998 0 : else aAttr.nMrkSet=nbyte;
1999 : break;
2000 : }
2001 :
2002 0 : case GOrdPMkSym: PushAttr(nOrderID);
2003 : case GOrdSMkSym: {
2004 : sal_uInt8 nbyte;
2005 0 : *pOS2MET >> nbyte;
2006 0 : if (nbyte==0) aAttr.nMrkSymbol=aDefAttr.nMrkSymbol;
2007 0 : else aAttr.nMrkSymbol=nbyte;
2008 : break;
2009 : }
2010 :
2011 0 : case GOrdPMkCel: PushAttr(nOrderID);
2012 : case GOrdSMkCel: {
2013 : sal_uInt8 nbyte;
2014 0 : sal_uInt16 nLen=nOrderLen;
2015 0 : aAttr.aMrkCellSize.Width()=ReadCoord(bCoord32);
2016 0 : aAttr.aMrkCellSize.Height()=ReadCoord(bCoord32);
2017 0 : if (bCoord32) nLen-=8; else nLen-=4;
2018 0 : if (nLen>=2) {
2019 0 : *pOS2MET >> nbyte;
2020 0 : if ((nbyte&0x80)==0 && aAttr.aMrkCellSize==Size(0,0))
2021 0 : aAttr.aMrkCellSize=aDefAttr.aMrkCellSize;
2022 : }
2023 : break;
2024 : }
2025 :
2026 0 : case GOrdPArcPa: PushAttr(nOrderID);
2027 : case GOrdSArcPa:
2028 0 : aAttr.nArcP=ReadCoord(bCoord32);
2029 0 : aAttr.nArcQ=ReadCoord(bCoord32);
2030 0 : aAttr.nArcR=ReadCoord(bCoord32);
2031 0 : aAttr.nArcS=ReadCoord(bCoord32);
2032 0 : break;
2033 :
2034 0 : case GOrdPCrPos: PushAttr(nOrderID);
2035 : case GOrdSCrPos:
2036 0 : aAttr.aCurPos=ReadPoint();
2037 0 : break;
2038 :
2039 0 : case GOrdPMdTrn: PushAttr(nOrderID);
2040 : case GOrdSMdTrn: OOODEBUG("GOrdSMdTrn",0);
2041 0 : break;
2042 :
2043 0 : case GOrdPPkIdn: PushAttr(nOrderID);
2044 : case GOrdSPkIdn: OOODEBUG("GOrdSPkIdn",0);
2045 0 : break;
2046 :
2047 : case GOrdSVwTrn: OOODEBUG("GOrdSVwTrn",0);
2048 0 : break;
2049 :
2050 0 : case GOrdPVwWin: PushAttr(nOrderID);
2051 : case GOrdSVwWin: OOODEBUG("GOrdSVwWin",0);
2052 0 : break;
2053 : default: OOODEBUG("Order unbekannt:",nOrderID);
2054 : }
2055 0 : }
2056 :
2057 0 : void OS2METReader::ReadDsc(sal_uInt16 nDscID, sal_uInt16 /*nDscLen*/)
2058 : {
2059 0 : switch (nDscID) {
2060 : case 0x00f7: { // 'Specify GVM Subset'
2061 : sal_uInt8 nbyte;
2062 0 : pOS2MET->SeekRel(6);
2063 0 : *pOS2MET >> nbyte;
2064 0 : if (nbyte==0x05) bCoord32=sal_True;
2065 0 : else if (nbyte==0x04) bCoord32=sal_False;
2066 : else {
2067 0 : pOS2MET->SetError(SVSTREAM_FILEFORMAT_ERROR);
2068 0 : ErrorCode=1;
2069 : }
2070 : break;
2071 : }
2072 : case 0x00f6:
2073 : {
2074 : // 'Set Picture Descriptor'
2075 : sal_Bool b32;
2076 : sal_uInt8 nbyte,nUnitType;
2077 : long x1,y1,x2,y2,nt,xr,yr;
2078 :
2079 0 : pOS2MET->SeekRel(2);
2080 0 : *pOS2MET >> nbyte;
2081 :
2082 0 : if (nbyte==0x05)
2083 0 : b32=sal_True;
2084 0 : else if(nbyte==0x04)
2085 0 : b32=sal_False;
2086 : else
2087 : {
2088 0 : b32 = sal_False; // -Wall added the case.
2089 0 : pOS2MET->SetError(SVSTREAM_FILEFORMAT_ERROR);
2090 0 : ErrorCode=2;
2091 : }
2092 :
2093 0 : *pOS2MET >> nUnitType;
2094 :
2095 0 : xr=ReadCoord(b32);
2096 0 : yr=ReadCoord(b32);
2097 :
2098 0 : ReadCoord(b32);
2099 :
2100 0 : if (nUnitType==0x00 && xr>0 && yr>0)
2101 0 : aGlobMapMode=MapMode(MAP_INCH,Point(0,0),Fraction(10,xr),Fraction(10,yr));
2102 0 : else if (nUnitType==0x01 && xr>0 && yr>0)
2103 0 : aGlobMapMode=MapMode(MAP_CM,Point(0,0),Fraction(10,xr),Fraction(10,yr));
2104 : else
2105 0 : aGlobMapMode=MapMode();
2106 :
2107 0 : x1=ReadCoord(b32);
2108 0 : x2=ReadCoord(b32);
2109 0 : y1=ReadCoord(b32);
2110 0 : y2=ReadCoord(b32);
2111 :
2112 0 : if (x1>x2)
2113 : {
2114 0 : nt=x1;
2115 0 : x1=x2;
2116 0 : x2=nt;
2117 : }
2118 :
2119 0 : if (y1>y2)
2120 : {
2121 0 : nt=y1;
2122 0 : y1=y2;
2123 0 : y2=nt;
2124 : }
2125 :
2126 0 : aBoundingRect.Left() = x1;
2127 0 : aBoundingRect.Right() = x2;
2128 0 : aBoundingRect.Top() = y1;
2129 0 : aBoundingRect.Bottom() = y2;
2130 :
2131 : // no output beside this bounding rect
2132 0 : pVirDev->IntersectClipRegion( Rectangle( Point(), aBoundingRect.GetSize() ) );
2133 :
2134 : break;
2135 : }
2136 : case 0x0021: // 'Set Current Defaults'
2137 0 : break;
2138 : }
2139 0 : }
2140 :
2141 0 : void OS2METReader::ReadImageData(sal_uInt16 nDataID, sal_uInt16 nDataLen)
2142 : {
2143 0 : OSBitmap * p=pBitmapList; if (p==NULL) return;
2144 :
2145 0 : switch (nDataID) {
2146 :
2147 : case 0x0070: // Begin Segment
2148 0 : break;
2149 :
2150 : case 0x0091: // Begin Image Content
2151 0 : break;
2152 :
2153 : case 0x0094: // Image Size
2154 0 : pOS2MET->SeekRel(5);
2155 0 : p->nHeight=ReadBigEndianWord();
2156 0 : p->nWidth=ReadBigEndianWord();
2157 0 : break;
2158 :
2159 : case 0x0095: // Image Encoding
2160 0 : break;
2161 :
2162 : case 0x0096: { // Image IDE-Size
2163 : sal_uInt8 nbyte;
2164 0 : *pOS2MET >> nbyte; p->nBitsPerPixel=nbyte;
2165 : break;
2166 : }
2167 :
2168 : case 0x0097: // Image LUT-ID
2169 0 : break;
2170 :
2171 : case 0x009b: // IDE Structure
2172 0 : break;
2173 :
2174 : case 0xfe92: { // Image Data
2175 : // Spaetestens jetzt brauchen wir die temporaere BMP-Datei
2176 : // und darin mindestens den Header + Palette.
2177 0 : if (p->pBMP==NULL) {
2178 0 : p->pBMP=new SvMemoryStream();
2179 0 : p->pBMP->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
2180 0 : if (p->nWidth==0 || p->nHeight==0 || p->nBitsPerPixel==0) {
2181 0 : pOS2MET->SetError(SVSTREAM_FILEFORMAT_ERROR);
2182 0 : ErrorCode=3;
2183 0 : return;
2184 : }
2185 : // write (Windows-)BITMAPINFOHEADER:
2186 0 : *(p->pBMP) << ((sal_uInt32)40) << p->nWidth << p->nHeight;
2187 0 : *(p->pBMP) << ((sal_uInt16)1) << p->nBitsPerPixel;
2188 0 : *(p->pBMP) << ((sal_uInt32)0) << ((sal_uInt32)0) << ((sal_uInt32)0) << ((sal_uInt32)0);
2189 0 : *(p->pBMP) << ((sal_uInt32)0) << ((sal_uInt32)0);
2190 : // write color table:
2191 0 : if (p->nBitsPerPixel<=8) {
2192 0 : sal_uInt16 i, nColTabSize=1<<(p->nBitsPerPixel);
2193 0 : for (i=0; i<nColTabSize; i++) *(p->pBMP) << GetPalette0RGB(i);
2194 : }
2195 : }
2196 : // OK, nun werden die Map-Daten ruebergeschoben. Leider haben OS2 und
2197 : // BMP eine unterschiedliche Reihenfolge von RGB bei 24-Bit.
2198 0 : sal_uInt8 * pBuf=new sal_uInt8[nDataLen];
2199 0 : pOS2MET->Read(pBuf,nDataLen);
2200 0 : if (p->nBitsPerPixel==24) {
2201 : sal_uLong i, j, nAlign, nBytesPerLine;
2202 : sal_uInt8 nTemp;
2203 0 : nBytesPerLine=(p->nWidth*3+3)&0xfffffffc;
2204 0 : nAlign=p->nMapPos-(p->nMapPos % nBytesPerLine);
2205 0 : i=0;
2206 0 : while (nAlign+i+2<p->nMapPos+nDataLen) {
2207 0 : if (nAlign+i>=p->nMapPos) {
2208 0 : j=nAlign+i-p->nMapPos;
2209 0 : nTemp=pBuf[j]; pBuf[j]=pBuf[j+2]; pBuf[j+2]=nTemp;
2210 : }
2211 0 : i+=3; if (i+2>=nBytesPerLine) {
2212 0 : nAlign+=nBytesPerLine;
2213 0 : i=0;
2214 : }
2215 : }
2216 : }
2217 0 : p->pBMP->Write(pBuf,nDataLen);
2218 0 : p->nMapPos+=nDataLen;
2219 0 : delete[] pBuf;
2220 0 : break;
2221 : }
2222 : case 0x0093: // End Image Content
2223 0 : break;
2224 :
2225 : case 0x0071: // End Segment
2226 0 : break;
2227 : }
2228 : }
2229 :
2230 0 : void OS2METReader::ReadFont(sal_uInt16 nFieldSize)
2231 : {
2232 : sal_uLong nPos, nMaxPos;
2233 : sal_uInt16 nLen;
2234 : sal_uInt8 nByte, nTripType, nTripType2;
2235 0 : OSFont * pF=new OSFont;
2236 0 : pF->pSucc=pFontList; pFontList=pF;
2237 0 : pF->nID=0;
2238 0 : pF->aFont.SetTransparent(sal_True);
2239 0 : pF->aFont.SetAlign(ALIGN_BASELINE);
2240 :
2241 0 : nPos=pOS2MET->Tell();
2242 0 : nMaxPos=nPos+(sal_uLong)nFieldSize;
2243 0 : pOS2MET->SeekRel(2); nPos+=2;
2244 0 : while (nPos<nMaxPos && pOS2MET->GetError()==0) {
2245 0 : *pOS2MET >> nByte; nLen =((sal_uInt16)nByte) & 0x00ff;
2246 0 : *pOS2MET >> nTripType;
2247 0 : switch (nTripType) {
2248 : case 0x02:
2249 0 : *pOS2MET >> nTripType2;
2250 0 : switch (nTripType2) {
2251 : case 0x84: // Font name
2252 0 : break;
2253 : case 0x08: { // Font Typeface
2254 : char str[33];
2255 0 : pOS2MET->SeekRel(1);
2256 0 : pOS2MET->Read( &str, 32 );
2257 0 : str[ 32 ] = 0;
2258 0 : String aStr( (const sal_Char*)str, osl_getThreadTextEncoding() );
2259 0 : if ( aStr.CompareIgnoreCaseToAscii( "Helv" ) == COMPARE_EQUAL )
2260 0 : aStr = rtl::OUString("Helvetica");
2261 0 : pF->aFont.SetName( aStr );
2262 0 : break;
2263 : }
2264 : }
2265 0 : break;
2266 : case 0x24: // Icid
2267 0 : *pOS2MET >> nTripType2;
2268 0 : switch (nTripType2) {
2269 : case 0x05: //Icid
2270 0 : *pOS2MET >> nByte;
2271 0 : pF->nID=((sal_uLong)nByte)&0xff;
2272 0 : break;
2273 : }
2274 0 : break;
2275 : case 0x20: // Font Binary GCID
2276 0 : break;
2277 : case 0x1f: { // Font Attributes
2278 : FontWeight eWeight;
2279 : sal_uInt8 nbyte;
2280 0 : *pOS2MET >> nbyte;
2281 0 : switch (nbyte) {
2282 0 : case 1: eWeight=WEIGHT_THIN; break;
2283 0 : case 2: eWeight=WEIGHT_ULTRALIGHT; break;
2284 0 : case 3: eWeight=WEIGHT_LIGHT; break;
2285 0 : case 4: eWeight=WEIGHT_SEMILIGHT; break;
2286 0 : case 5: eWeight=WEIGHT_NORMAL; break;
2287 0 : case 6: eWeight=WEIGHT_SEMIBOLD; break;
2288 0 : case 7: eWeight=WEIGHT_BOLD; break;
2289 0 : case 8: eWeight=WEIGHT_ULTRABOLD; break;
2290 0 : case 9: eWeight=WEIGHT_BLACK; break;
2291 0 : default: eWeight=WEIGHT_DONTKNOW;
2292 : }
2293 0 : pF->aFont.SetWeight(eWeight);
2294 : break;
2295 : }
2296 : }
2297 0 : nPos+=nLen; pOS2MET->Seek(nPos);
2298 : }
2299 0 : }
2300 :
2301 0 : void OS2METReader::ReadField(sal_uInt16 nFieldType, sal_uInt16 nFieldSize)
2302 : {
2303 0 : switch (nFieldType) {
2304 : case BegDocumnMagic:
2305 0 : break;
2306 : case EndDocumnMagic:
2307 0 : break;
2308 : case BegResGrpMagic:
2309 0 : break;
2310 : case EndResGrpMagic:
2311 0 : break;
2312 : case BegColAtrMagic:
2313 0 : break;
2314 : case EndColAtrMagic:
2315 0 : break;
2316 : case BlkColAtrMagic: {
2317 : sal_uLong nPos, nMaxPos;
2318 : sal_uInt8 nbyte;
2319 : sal_uLong nCol;
2320 : sal_uInt16 nStartIndex, nEndIndex, i, nElemLen, nBytesPerCol;
2321 :
2322 0 : nPos=pOS2MET->Tell();
2323 0 : nMaxPos=nPos+(sal_uLong)nFieldSize;
2324 0 : pOS2MET->SeekRel(3); nPos+=3;
2325 0 : while (nPos<nMaxPos && pOS2MET->GetError()==0) {
2326 0 : *pOS2MET >> nbyte; nElemLen=((sal_uInt16)nbyte) & 0x00ff;
2327 0 : if (nElemLen>11) {
2328 0 : pOS2MET->SeekRel(4);
2329 0 : nStartIndex=ReadBigEndianWord();
2330 0 : pOS2MET->SeekRel(3);
2331 0 : *pOS2MET >> nbyte; nBytesPerCol=((sal_uInt16)nbyte) & 0x00ff;
2332 0 : nEndIndex=nStartIndex+(nElemLen-11)/nBytesPerCol;
2333 0 : for (i=nStartIndex; i<nEndIndex; i++) {
2334 0 : if (nBytesPerCol > 3) pOS2MET->SeekRel(nBytesPerCol-3);
2335 0 : nCol=ReadBigEndian3BytesLong();
2336 0 : SetPalette0RGB(i,nCol);
2337 : }
2338 : }
2339 0 : else if (nElemLen<10) {
2340 0 : pOS2MET->SetError(SVSTREAM_FILEFORMAT_ERROR);
2341 0 : ErrorCode=4;
2342 : }
2343 0 : nPos+=(sal_uLong)nElemLen;
2344 0 : pOS2MET->Seek(nPos);
2345 : }
2346 : break;
2347 : }
2348 : case MapColAtrMagic:
2349 0 : break;
2350 : case BegImgObjMagic: {
2351 : // neue Bitmap schonmal herstellen: (wird spaeter gefuellt)
2352 0 : OSBitmap * pB=new OSBitmap;
2353 0 : pB->pSucc=pBitmapList; pBitmapList=pB;
2354 0 : pB->pBMP=NULL; pB->nWidth=0; pB->nHeight=0; pB->nBitsPerPixel=0;
2355 0 : pB->nMapPos=0;
2356 : // determine ID of the bitmap:
2357 : sal_uInt8 i,nbyte,nbyte2;
2358 0 : pB->nID=0;
2359 0 : for (i=0; i<4; i++) {
2360 0 : *pOS2MET >> nbyte >> nbyte2;
2361 0 : nbyte=((nbyte-0x30)<<4)|(nbyte2-0x30);
2362 0 : pB->nID=(pB->nID>>8)|(((sal_uLong)nbyte)<<24);
2363 : }
2364 : // neue Palette auf den Paletten-Stack bringen: (wird spaeter gefuellt)
2365 0 : OSPalette * pP=new OSPalette;
2366 0 : pP->pSucc=pPaletteStack; pPaletteStack=pP;
2367 0 : pP->p0RGB=NULL; pP->nSize=0;
2368 : break;
2369 : }
2370 : case EndImgObjMagic: {
2371 : // Temporaere Windows-BMP-Datei auslesen:
2372 0 : if (pBitmapList==NULL || pBitmapList->pBMP==NULL ||
2373 0 : pBitmapList->pBMP->GetError()!=0) {
2374 0 : pOS2MET->SetError(SVSTREAM_FILEFORMAT_ERROR);
2375 0 : ErrorCode=5;
2376 0 : return;
2377 : }
2378 0 : pBitmapList->pBMP->Seek(0);
2379 :
2380 0 : pBitmapList->aBitmap.Read( *( pBitmapList->pBMP ), sal_False );
2381 :
2382 0 : if (pBitmapList->pBMP->GetError()!=0) {
2383 0 : pOS2MET->SetError(SVSTREAM_FILEFORMAT_ERROR);
2384 0 : ErrorCode=6;
2385 : }
2386 0 : delete pBitmapList->pBMP; pBitmapList->pBMP=NULL;
2387 : // kill palette from stack:
2388 0 : OSPalette * pP=pPaletteStack;
2389 0 : if (pP!=NULL) {
2390 0 : pPaletteStack=pP->pSucc;
2391 0 : if (pP->p0RGB!=NULL) delete[] pP->p0RGB;
2392 0 : delete pP;
2393 : }
2394 0 : break;
2395 : }
2396 : case DscImgObjMagic:
2397 0 : break;
2398 : case DatImgObjMagic: {
2399 : sal_uInt16 nDataID, nDataLen;
2400 : sal_uInt8 nbyte;
2401 : sal_uLong nPos, nMaxPos;
2402 :
2403 0 : nPos=pOS2MET->Tell();
2404 0 : nMaxPos=nPos+(sal_uLong)nFieldSize;
2405 0 : while (nPos<nMaxPos && pOS2MET->GetError()==0) {
2406 0 : *pOS2MET >> nbyte; nDataID=((sal_uInt16)nbyte)&0x00ff;
2407 0 : if (nDataID==0x00fe) {
2408 0 : *pOS2MET >> nbyte;
2409 0 : nDataID=(nDataID<<8)|(((sal_uInt16)nbyte)&0x00ff);
2410 0 : nDataLen=ReadBigEndianWord();
2411 0 : nPos+=4;
2412 : }
2413 : else {
2414 0 : *pOS2MET >> nbyte; nDataLen=((sal_uInt16)nbyte)&0x00ff;
2415 0 : nPos+=2;
2416 : }
2417 0 : ReadImageData(nDataID, nDataLen);
2418 0 : nPos+=(sal_uLong)nDataLen;
2419 0 : pOS2MET->Seek(nPos);
2420 : }
2421 : break;
2422 : }
2423 :
2424 : case BegObEnv1Magic:
2425 0 : break;
2426 : case EndObEnv1Magic:
2427 0 : break;
2428 : case BegGrfObjMagic:
2429 0 : break;
2430 : case EndGrfObjMagic: {
2431 : SvStream * pSave;
2432 : sal_uLong nPos, nMaxPos;
2433 : sal_uInt16 nOrderID, nOrderLen;
2434 : sal_uInt8 nbyte;
2435 :
2436 0 : if (pOrdFile==NULL) break;
2437 :
2438 : // in pOrdFile wurden alle "DatGrfObj"-Felder gesammelt, so
2439 : // dass die darin enthaltnen "Orders" zusammenhangend und nicht durch
2440 : // "Fields" segmentiert sind. Um sie aus dem MemoryStream auszulesen,
2441 : // ohne grosse Umstaende deswegen zu haben (frueher wurden die "Orders"
2442 : // direkt aus pOS2MET gelesen), hier ein kleiner Trick:
2443 0 : pSave=pOS2MET;
2444 0 : pOS2MET=pOrdFile; //(!)
2445 0 : nMaxPos=pOS2MET->Tell();
2446 0 : pOS2MET->Seek(0);
2447 :
2448 : // "Segment header":
2449 0 : *pOS2MET >> nbyte;
2450 0 : if (nbyte==0x70) { // header exists
2451 0 : pOS2MET->SeekRel(15); // but we don't need it
2452 : }
2453 0 : else pOS2MET->SeekRel(-1); // no header, go back one byte
2454 :
2455 : // loop through Order:
2456 0 : while (pOS2MET->Tell()<nMaxPos && pOS2MET->GetError()==0) {
2457 0 : *pOS2MET >> nbyte; nOrderID=((sal_uInt16)nbyte) & 0x00ff;
2458 0 : if (nOrderID==0x00fe) {
2459 0 : *pOS2MET >> nbyte;
2460 0 : nOrderID=(nOrderID << 8) | (((sal_uInt16)nbyte) & 0x00ff);
2461 : }
2462 0 : if (nOrderID>0x00ff || nOrderID==GOrdPolygn) {
2463 : // ooo: Laut OS2-Doku sollte die Orderlaenge nun als Big-Endian-Word
2464 : // gegeben sein (Zitat: "Highorder byte precedes loworder byte").
2465 : // Tatsaechlich gibt es aber Dateien, die die Laenge als
2466 : // Little-Endian-Word angeben (zu mindestens fuer nOrderID==GOrdPolygn).
2467 : // Also werfen wir eine Muenze oder was ?
2468 0 : *pOS2MET >> nbyte; nOrderLen=(sal_uInt16)nbyte&0x00ff;
2469 0 : *pOS2MET >> nbyte; if (nbyte!=0) nOrderLen=nOrderLen<<8|(((sal_uInt16)nbyte)&0x00ff);
2470 : }
2471 0 : else if (nOrderID==GOrdSTxAlg || nOrderID==GOrdPTxAlg) nOrderLen=2;
2472 0 : else if ((nOrderID&0xff88)==0x0008) nOrderLen=1;
2473 0 : else if (nOrderID==0x0000 || nOrderID==0x00ff) nOrderLen=0;
2474 0 : else { *pOS2MET >> nbyte; nOrderLen=((sal_uInt16)nbyte) & 0x00ff; }
2475 0 : nPos=pOS2MET->Tell();
2476 0 : ReadOrder(nOrderID, nOrderLen);
2477 0 : if (nPos+nOrderLen < pOS2MET->Tell()) {
2478 : OOODEBUG("Order shorter than he assumes! OrderID:",nOrderID);
2479 : OOODEBUG("...und zwar bei Position (Parameteranfang):",nPos);
2480 : }
2481 0 : else if (nPos+nOrderLen != pOS2MET->Tell()) {
2482 : OOODEBUG(String(nOrderID)+String(" Order nicht alles gelesen! bei:"),nPos);
2483 : }
2484 0 : pOS2MET->Seek(nPos+nOrderLen);
2485 : }
2486 :
2487 0 : pOS2MET=pSave;
2488 0 : if (pOrdFile->GetError()) {
2489 0 : pOS2MET->SetError(SVSTREAM_FILEFORMAT_ERROR);
2490 0 : ErrorCode=10;
2491 : }
2492 0 : delete pOrdFile; pOrdFile=NULL;
2493 : break;
2494 : }
2495 : case DscGrfObjMagic: {
2496 : sal_uLong nPos, nMaxPos;
2497 : sal_uInt16 nDscID, nDscLen;
2498 : sal_uInt8 nbyte;
2499 :
2500 0 : nMaxPos=pOS2MET->Tell()+(sal_uLong)nFieldSize;
2501 0 : while (pOS2MET->Tell()<nMaxPos && pOS2MET->GetError()==0) {
2502 0 : *pOS2MET >> nbyte; nDscID =((sal_uInt16)nbyte) & 0x00ff;
2503 0 : *pOS2MET >> nbyte; nDscLen=((sal_uInt16)nbyte) & 0x00ff;
2504 0 : nPos=pOS2MET->Tell();
2505 0 : ReadDsc(nDscID, nDscLen);
2506 0 : pOS2MET->Seek(nPos+nDscLen);
2507 : }
2508 : break;
2509 : }
2510 : case DatGrfObjMagic: {
2511 0 : if (pOrdFile==NULL) {
2512 0 : pOrdFile = new SvMemoryStream;
2513 0 : pOrdFile->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
2514 : }
2515 0 : sal_uInt8 * pBuf; pBuf = new sal_uInt8[nFieldSize];
2516 0 : pOS2MET->Read(pBuf,nFieldSize);
2517 0 : pOrdFile->Write(pBuf,nFieldSize);
2518 0 : delete[] pBuf;
2519 0 : break;
2520 : }
2521 : case MapCodFntMagic:
2522 0 : ReadFont(nFieldSize);
2523 0 : break;
2524 :
2525 : case MapDatResMagic:
2526 0 : break;
2527 : }
2528 : }
2529 :
2530 0 : void OS2METReader::ReadOS2MET( SvStream & rStreamOS2MET, GDIMetaFile & rGDIMetaFile )
2531 : {
2532 : sal_uInt16 nFieldSize;
2533 : sal_uInt16 nFieldType;
2534 : sal_uLong nPos, nStartPos, nEndPos, nPercent, nLastPercent;
2535 : sal_uInt8 nMagicByte;
2536 :
2537 0 : ErrorCode=0;
2538 :
2539 0 : pOS2MET = &rStreamOS2MET;
2540 0 : nOrigPos = pOS2MET->Tell();
2541 0 : nOrigNumberFormat = pOS2MET->GetNumberFormatInt();
2542 :
2543 0 : bCoord32 = sal_True;
2544 0 : pPaletteStack=NULL;
2545 0 : pAreaStack=NULL;
2546 0 : pPathStack=NULL;
2547 0 : pPathList=NULL;
2548 0 : pFontList=NULL;
2549 0 : pBitmapList=NULL;
2550 0 : pAttrStack=NULL;
2551 :
2552 0 : aDefAttr.aLinCol =Color(COL_BLACK);
2553 0 : aDefAttr.aLinBgCol =Color(COL_WHITE);
2554 0 : aDefAttr.eLinMix =ROP_OVERPAINT;
2555 0 : aDefAttr.eLinBgMix =ROP_OVERPAINT;
2556 0 : aDefAttr.aChrCol =Color(COL_BLACK);
2557 0 : aDefAttr.aChrBgCol =Color(COL_WHITE);
2558 0 : aDefAttr.eChrMix =ROP_OVERPAINT;
2559 0 : aDefAttr.eChrBgMix =ROP_OVERPAINT;
2560 0 : aDefAttr.aMrkCol =Color(COL_BLACK);
2561 0 : aDefAttr.aMrkBgCol =Color(COL_WHITE);
2562 0 : aDefAttr.eMrkMix =ROP_OVERPAINT;
2563 0 : aDefAttr.eMrkBgMix =ROP_OVERPAINT;
2564 0 : aDefAttr.aPatCol =Color(COL_BLACK);
2565 0 : aDefAttr.aPatBgCol =Color(COL_WHITE);
2566 0 : aDefAttr.ePatMix =ROP_OVERPAINT;
2567 0 : aDefAttr.ePatBgMix =ROP_OVERPAINT;
2568 0 : aDefAttr.aImgCol =Color(COL_BLACK);
2569 0 : aDefAttr.aImgBgCol =Color(COL_WHITE);
2570 0 : aDefAttr.eImgMix =ROP_OVERPAINT;
2571 0 : aDefAttr.eImgBgMix =ROP_OVERPAINT;
2572 0 : aDefAttr.nArcP =1;
2573 0 : aDefAttr.nArcQ =1;
2574 0 : aDefAttr.nArcR =0;
2575 0 : aDefAttr.nArcS =0;
2576 0 : aDefAttr.nChrAng =0;
2577 0 : aDefAttr.aChrCellSize=Size(12,12);
2578 0 : aDefAttr.nChrSet =0;
2579 0 : aDefAttr.aCurPos =Point(0,0);
2580 0 : aDefAttr.eLinStyle =PEN_SOLID;
2581 0 : aDefAttr.nLinWidth =0;
2582 0 : aDefAttr.aMrkCellSize=Size(10,10);
2583 0 : aDefAttr.nMrkPrec =0x01;
2584 0 : aDefAttr.nMrkSet =0xff;
2585 0 : aDefAttr.nMrkSymbol =0x01;
2586 0 : aDefAttr.bFill =sal_True;
2587 0 : aDefAttr.nStrLinWidth=0;
2588 :
2589 0 : aAttr=aDefAttr;
2590 :
2591 0 : pOrdFile=NULL;
2592 :
2593 0 : pVirDev = new VirtualDevice();
2594 0 : pVirDev->EnableOutput(sal_False);
2595 0 : rGDIMetaFile.Record(pVirDev);
2596 :
2597 0 : pOS2MET->SetNumberFormatInt(NUMBERFORMAT_INT_LITTLEENDIAN);
2598 :
2599 0 : nStartPos=pOS2MET->Tell();
2600 0 : nEndPos=pOS2MET->Seek(STREAM_SEEK_TO_END); pOS2MET->Seek(nStartPos);
2601 0 : Callback(0); nLastPercent=0;
2602 :
2603 0 : nPos=pOS2MET->Tell();
2604 0 : if ( nStartPos == nEndPos )
2605 : {
2606 0 : nEndPos = 100;
2607 0 : nStartPos = 0;
2608 : }
2609 :
2610 0 : for (;;) {
2611 :
2612 0 : nPercent=(nPos-nStartPos)*100/(nEndPos-nStartPos);
2613 0 : if (nLastPercent+4<=nPercent) {
2614 0 : if (Callback((sal_uInt16)nPercent)==sal_True) break;
2615 0 : nLastPercent=nPercent;
2616 : }
2617 :
2618 0 : nFieldSize=ReadBigEndianWord();
2619 :
2620 0 : *pOS2MET >> nMagicByte;
2621 0 : if (nMagicByte!=0xd3) {
2622 0 : pOS2MET->SetError(SVSTREAM_FILEFORMAT_ERROR);
2623 0 : ErrorCode=7;
2624 0 : break;
2625 : }
2626 0 : *pOS2MET >> nFieldType;
2627 :
2628 0 : pOS2MET->SeekRel(3);
2629 0 : nPos+=8; nFieldSize-=8;
2630 :
2631 0 : if (pOS2MET->GetError()) break;
2632 0 : if (pOS2MET->IsEof()) {
2633 0 : pOS2MET->SetError(SVSTREAM_FILEFORMAT_ERROR);
2634 0 : ErrorCode=8;
2635 0 : break;
2636 : }
2637 :
2638 0 : if (nFieldType==EndDocumnMagic) break;
2639 :
2640 0 : ReadField(nFieldType, nFieldSize);
2641 :
2642 0 : nPos+=(sal_uLong)nFieldSize;
2643 0 : if (pOS2MET->Tell()>nPos) {
2644 0 : pOS2MET->SetError(SVSTREAM_FILEFORMAT_ERROR);
2645 0 : ErrorCode=9;
2646 0 : break;
2647 : }
2648 0 : pOS2MET->Seek(nPos);
2649 : }
2650 :
2651 0 : rGDIMetaFile.Stop();
2652 0 : delete pVirDev;
2653 :
2654 0 : rGDIMetaFile.SetPrefMapMode( aGlobMapMode );
2655 :
2656 0 : if( aBoundingRect.GetWidth() && aBoundingRect.GetHeight() )
2657 0 : rGDIMetaFile.SetPrefSize( aBoundingRect.GetSize() );
2658 : else
2659 : {
2660 0 : if( aCalcBndRect.Left() || aCalcBndRect.Top() )
2661 0 : rGDIMetaFile.Move( -aCalcBndRect.Left(), -aCalcBndRect.Top() );
2662 :
2663 0 : rGDIMetaFile.SetPrefSize( aCalcBndRect.GetSize() );
2664 : }
2665 :
2666 0 : if (pOrdFile!=NULL) delete pOrdFile;
2667 :
2668 0 : while (pAreaStack!=NULL) {
2669 0 : OSArea * p=pAreaStack;
2670 0 : pAreaStack=p->pSucc;
2671 0 : delete p;
2672 : }
2673 :
2674 0 : while (pPathStack!=NULL) {
2675 0 : OSPath * p=pPathStack;
2676 0 : pPathStack=p->pSucc;
2677 0 : delete p;
2678 : }
2679 :
2680 0 : while (pPathList!=NULL) {
2681 0 : OSPath * p=pPathList;
2682 0 : pPathList=p->pSucc;
2683 0 : delete p;
2684 : }
2685 :
2686 0 : while (pFontList!=NULL) {
2687 0 : OSFont * p=pFontList;
2688 0 : pFontList=p->pSucc;
2689 0 : delete p;
2690 : }
2691 :
2692 0 : while (pBitmapList!=NULL) {
2693 0 : OSBitmap * p=pBitmapList;
2694 0 : pBitmapList=p->pSucc;
2695 0 : if (p->pBMP!=NULL) delete p->pBMP;
2696 0 : delete p;
2697 : }
2698 :
2699 0 : while (pAttrStack!=NULL) {
2700 0 : OSAttr * p=pAttrStack;
2701 0 : pAttrStack=p->pSucc;
2702 0 : delete p;
2703 : }
2704 :
2705 0 : while (pPaletteStack!=NULL) {
2706 0 : OSPalette * p=pPaletteStack;
2707 0 : pPaletteStack=p->pSucc;
2708 0 : if (p->p0RGB!=NULL) delete[] p->p0RGB;
2709 0 : delete p;
2710 : }
2711 :
2712 0 : pOS2MET->SetNumberFormatInt(nOrigNumberFormat);
2713 :
2714 0 : if (pOS2MET->GetError()) {
2715 : OOODEBUG("Fehler Nr.:",ErrorCode);
2716 0 : pOS2MET->Seek(nOrigPos);
2717 : }
2718 0 : }
2719 :
2720 : //================== GraphicImport - die exportierte Funktion ================
2721 :
2722 : #ifdef DISABLE_DYNLOADING
2723 : #define GraphicImport imeGraphicImport
2724 : #endif
2725 :
2726 : extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL
2727 0 : GraphicImport(SvStream & rStream, Graphic & rGraphic, FilterConfigItem*, sal_Bool)
2728 : {
2729 0 : OS2METReader aOS2METReader;
2730 0 : GDIMetaFile aMTF;
2731 0 : sal_Bool bRet = sal_False;
2732 :
2733 0 : aOS2METReader.ReadOS2MET( rStream, aMTF );
2734 :
2735 0 : if ( !rStream.GetError() )
2736 : {
2737 0 : rGraphic=Graphic( aMTF );
2738 0 : bRet = sal_True;
2739 : }
2740 :
2741 0 : return bRet;
2742 : }
2743 :
2744 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|