|
1 // Copyright (c) 1999-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef __WMFCODEC_H__ |
|
17 #define __WMFCODEC_H__ |
|
18 |
|
19 #include <bitdev.h> |
|
20 #include <icl/imageprocessor.h> |
|
21 #include <icl/imagecodec.h> |
|
22 #include <icl/imagecodecdata.h> |
|
23 |
|
24 #include "WMFConvert.h" |
|
25 |
|
26 // Constants. |
|
27 // Record size (2 16-bit WORDS); Record identifier (1 16-bit WORD) |
|
28 const TInt KWmfMinRecordSizeInWords = 3; |
|
29 //Size of polyline, polygon and polypolygon records. Should be KWmfMinRecordSizeInWords + 1 |
|
30 //word for number of points in polyline or number of points in polygon or number of polygons in polypolygon. |
|
31 const TInt KWmfPolyRecordSizeInWords = 4; |
|
32 |
|
33 const TInt KWmfMaxGraphicsObjectCount = 256; |
|
34 const TInt KWmfTerminateFunction = 0; |
|
35 //KWmfMinRecordSizeInWords + 1 word each for string-length, Y-Position, X-Position |
|
36 const TInt KMinTextoutRecordSizeInWords = KWmfMinRecordSizeInWords + 3; |
|
37 |
|
38 const TInt KWmfGraphicsObjectPen = 0; |
|
39 const TInt KWmfGraphicsObjectBrush = 1; |
|
40 const TInt KWmfGraphicsObjectPatternBrush = 2; |
|
41 const TInt KWmfGraphicsObjectFont = 3; |
|
42 const TInt KWmfGraphicsObjectRegion = 4; |
|
43 const TInt KWmfGraphicsObjectPalette = 5; |
|
44 const TInt KWmfGraphicsObjectDummyBrush = 6; |
|
45 |
|
46 |
|
47 // Helper classes. |
|
48 class CPen; |
|
49 class CBrush; |
|
50 class CPatternBrush; |
|
51 class CFbsBitGcWrapper : public CBase |
|
52 { |
|
53 public: |
|
54 static CFbsBitGcWrapper* NewL(CFbsDevice& aDevice, CFbsBitGcWrapper* aGc = NULL); |
|
55 ~CFbsBitGcWrapper(); |
|
56 |
|
57 const CFbsFont* CurrentFont(); |
|
58 |
|
59 virtual void SetPen(const CPen& aPen); |
|
60 virtual void SetBrush(CBrush& aBrush); |
|
61 virtual void RestorePenAndBrush(); |
|
62 virtual void DrawPolygonL(const TPoint* aPointList,TInt aNumPoints,CGraphicsContext::TFillRule aFillRule); |
|
63 |
|
64 virtual void Clear(); |
|
65 virtual void SetUnderlineStyle(TFontUnderline aUnderlineStyle); |
|
66 virtual void SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle); |
|
67 virtual void UseFont(const CFbsFont* aFont); |
|
68 virtual void SetClippingRegion(const TRegion* aRect); |
|
69 virtual void SetCharJustification(TInt aExcessWidth, TInt aNumGaps); |
|
70 virtual void SetWordJustification(TInt aExcessWidth, TInt aNumChars); |
|
71 virtual void DrawLineTo(const TPoint& aPoint); |
|
72 virtual void MoveTo(const TPoint& aPoint); |
|
73 virtual void DrawPolyLine(const TPoint* aPointList, TInt aNumPoints); |
|
74 virtual void DrawEllipse(const TRect& aRect); |
|
75 virtual void DrawRect(const TRect& aRect); |
|
76 virtual void DrawRoundRect(const TRect& aRect, const TSize& aEllipse); |
|
77 virtual void SetPenStyle(CGraphicsContext::TPenStyle aPenStyle); |
|
78 virtual void SetBrushStyle(CGraphicsContext::TBrushStyle aBrushStyle); |
|
79 virtual void SetBrushColor(const TRgb& aColor); |
|
80 virtual void SetDrawMode(CGraphicsContext::TDrawMode aDrawMode); |
|
81 virtual void SetPenColor(const TRgb& aColor); |
|
82 virtual void SetTextPenColor(); |
|
83 virtual void Plot(const TPoint& aPoint); |
|
84 virtual void SetPenSize(const TSize& aSize); |
|
85 virtual void DrawArc(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd); |
|
86 virtual void DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd); |
|
87 virtual void DrawBitmap(const TRect& aDestRect, const CFbsBitmap* aSource, const TRect& aSourceRect); |
|
88 virtual void DrawText(const TDesC& aText,const TPoint& aPosition); |
|
89 |
|
90 virtual void UseBrushPattern(const CFbsBitmap* aPatternBitmap); |
|
91 virtual void SetTextColor(TRgb aTextColor); |
|
92 virtual void SetBackgroundColor(TRgb aBackgroundColor); |
|
93 virtual void RealizeBrush(); |
|
94 |
|
95 protected: |
|
96 CFbsBitGcWrapper(); |
|
97 void ConstructL(CFbsDevice& aDevice, CFbsBitGcWrapper* aGc); |
|
98 |
|
99 protected: |
|
100 TRgb iBrushColor; |
|
101 CGraphicsContext::TBrushStyle iBrushStyle; |
|
102 |
|
103 TRgb iPenColor; |
|
104 CGraphicsContext::TPenStyle iPenStyle; |
|
105 TSize iPenSize; |
|
106 |
|
107 TRgb iTextColor; |
|
108 TRgb iBackgroundColor; |
|
109 CPatternBrush* iPatternBrush; |
|
110 |
|
111 private: |
|
112 CFbsBitGc* iGc; |
|
113 CFbsBitGc* iPolygonGc; |
|
114 |
|
115 const CFbsFont* iCurrentFont; // Not owned. |
|
116 }; |
|
117 |
|
118 class CFbsBitGcMaskWrapper : public CFbsBitGcWrapper |
|
119 { |
|
120 public: |
|
121 static CFbsBitGcMaskWrapper* NewL(CFbsDevice& aDevice, CFbsDevice& aMaskDevice, CFbsBitGcMaskWrapper* aGc = NULL); |
|
122 ~CFbsBitGcMaskWrapper(); |
|
123 |
|
124 // From CFbsBitGcWrapper |
|
125 void SetPen(const CPen& aPen); |
|
126 void SetBrush(CBrush& aBrush); |
|
127 void DrawPolygonL(const TPoint* aPointList,TInt aNumPoints,CGraphicsContext::TFillRule aFillRule); |
|
128 |
|
129 void Clear(); |
|
130 void SetUnderlineStyle(TFontUnderline aUnderlineStyle); |
|
131 void SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle); |
|
132 void UseFont(const CFbsFont* aFont); |
|
133 void SetClippingRegion(const TRegion* aRect); |
|
134 void SetCharJustification(TInt aExcessWidth, TInt aNumGaps); |
|
135 void SetWordJustification(TInt aExcessWidth, TInt aNumChars); |
|
136 void DrawLineTo(const TPoint& aPoint); |
|
137 void MoveTo(const TPoint& aPoint); |
|
138 void DrawPolyLine(const TPoint* aPointList, TInt aNumPoints); |
|
139 void DrawEllipse(const TRect& aRect); |
|
140 void DrawRect(const TRect& aRect); |
|
141 void DrawRoundRect(const TRect& aRect, const TSize& aEllipse); |
|
142 void SetPenStyle(CGraphicsContext::TPenStyle aPenStyle); |
|
143 void SetBrushStyle(CGraphicsContext::TBrushStyle aBrushStyle); |
|
144 void SetDrawMode(CGraphicsContext::TDrawMode aDrawMode); |
|
145 void Plot(const TPoint& aPoint); |
|
146 void SetPenSize(const TSize& aSize); |
|
147 void DrawArc(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd); |
|
148 void DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd); |
|
149 void DrawBitmap(const TRect& aDestRect, const CFbsBitmap* aSource, const TRect& aSourceRect); |
|
150 void DrawText(const TDesC& aText,const TPoint& aPosition); |
|
151 void UseBrushPattern(const CFbsBitmap* aPatternBitmap, TBool aHatchedBrush); |
|
152 |
|
153 private: |
|
154 CFbsBitGcMaskWrapper(); |
|
155 void ConstructL(CFbsDevice& aDevice, CFbsDevice& aMaskDevice, CFbsBitGcMaskWrapper* aGc); |
|
156 |
|
157 CFbsBitGc* iMaskGc; |
|
158 CFbsBitGc* iPolygonMaskGc; |
|
159 }; |
|
160 |
|
161 |
|
162 class CGraphicsObject : public CBase |
|
163 { |
|
164 public: |
|
165 virtual void Apply(CFbsBitGcWrapper* aGc) = 0; |
|
166 virtual TInt Type() const = 0; |
|
167 }; |
|
168 |
|
169 class CPen : public CGraphicsObject |
|
170 { |
|
171 public: |
|
172 virtual void Apply(CFbsBitGcWrapper* aGc); |
|
173 virtual TInt Type() const; |
|
174 public: |
|
175 CGraphicsContext::TPenStyle iStyle; |
|
176 TSize iSize; |
|
177 TRgb iColor; |
|
178 }; |
|
179 |
|
180 class CDummyBrush : public CGraphicsObject |
|
181 { |
|
182 public: |
|
183 virtual void Apply(CFbsBitGcWrapper* aGc); |
|
184 virtual TInt Type() const; |
|
185 }; |
|
186 |
|
187 class CBrush : public CGraphicsObject |
|
188 { |
|
189 public: |
|
190 virtual void Apply(CFbsBitGcWrapper* aGc); |
|
191 virtual TInt Type() const; |
|
192 public: |
|
193 CGraphicsContext::TBrushStyle iStyle; |
|
194 TRgb iColor; |
|
195 }; |
|
196 |
|
197 class CPatternBrush : public CBrush |
|
198 { |
|
199 public: |
|
200 static CPatternBrush* NewL(); |
|
201 ~CPatternBrush(); |
|
202 |
|
203 virtual void Apply(CFbsBitGcWrapper* aGc); |
|
204 virtual TInt Type() const; |
|
205 |
|
206 void SetBitmapBits(TUint8* aBitmapBits); |
|
207 void RealizeBrush(TRgb aTextColor, TRgb aBackgroundColor); |
|
208 |
|
209 CFbsBitmap* Bitmap(); |
|
210 |
|
211 private: |
|
212 CPatternBrush(); |
|
213 void ConstructL(); |
|
214 |
|
215 private: |
|
216 CFbsBitmap* iBitmap; |
|
217 TUint8* iBitmapBits; |
|
218 |
|
219 TRgb iTextColor; |
|
220 TRgb iBackgroundColor; |
|
221 }; |
|
222 |
|
223 class CFontObject : public CGraphicsObject |
|
224 { |
|
225 public: |
|
226 CFontObject(CFbsDevice& aDevice,CFbsFont& aFont,TBool aUnderline,TBool aStrikeOut); |
|
227 ~CFontObject(); |
|
228 virtual void Apply(CFbsBitGcWrapper* aGc); |
|
229 virtual TInt Type() const; |
|
230 private: |
|
231 CFbsDevice& iDevice; |
|
232 CFbsFont& iFont; |
|
233 TFontUnderline iUnderline; |
|
234 TFontStrikethrough iStrikeOut; |
|
235 }; |
|
236 |
|
237 class CRectRegion : public CGraphicsObject |
|
238 { |
|
239 public: |
|
240 CRectRegion(CFbsDevice& aDevice, TRegion& aClipRegion, TInt aLeft, TInt aTop, TInt aRight, TInt aBottom); |
|
241 virtual void Apply(CFbsBitGcWrapper* aGc); |
|
242 virtual TInt Type() const; |
|
243 public: |
|
244 TRect iRect; |
|
245 |
|
246 private: |
|
247 CFbsDevice& iDevice; |
|
248 TRegion& iClipRegion; |
|
249 }; |
|
250 |
|
251 class CPaletteObject : public CGraphicsObject |
|
252 { |
|
253 public: |
|
254 virtual void Apply(CFbsBitGcWrapper* aGc); |
|
255 virtual TInt Type() const; |
|
256 }; |
|
257 |
|
258 |
|
259 // Read codec. |
|
260 class CWmfDecoder; |
|
261 class CWmfReadCodec : public CImageReadCodec |
|
262 { |
|
263 public: |
|
264 //From CImageReadCodec |
|
265 virtual void InitFrameL(TFrameInfo& aFrameInfo, CFrameImageData& aFrameImageData, TBool aDisableErrorDiffusion, CFbsBitmap& aBitmap, CFbsBitmap* aDestinationMask); |
|
266 |
|
267 static CWmfReadCodec* NewL(TInt aWordsExpected); |
|
268 TFrameState ProcessFrameL(TBufPtr8& aSrc); |
|
269 TInt ReducedSize(const TSize& aOriginalSize,TInt aReductionFactor, TSize& aReducedSize) const; |
|
270 TInt ReductionFactor(const TSize& aOriginalSize, const TSize& aReducedSize) const; |
|
271 void SetIgnoreViewportMetaData(TBool aIgnoreViewportMetaData); |
|
272 protected: |
|
273 ~CWmfReadCodec(); |
|
274 virtual void DoProcessL(TUint16*& aDataPtr,const TUint16* aDataPtrLimit); |
|
275 void DoProcess00L(TInt aFunction,TUint16* aArgPtr); |
|
276 void DoProcess01L(TInt aFunction,TUint16* aArgPtr); |
|
277 void DoProcess10L(TInt aFunction,TUint16* aArgPtr); |
|
278 void DoProcess11L(TInt aFunction,TUint16* aArgPtr); |
|
279 void DoProcess0000L(TInt aFunction,TUint16* aArgPtr); |
|
280 void DoProcess0001L(TInt aFunction,TUint16* aArgPtr); |
|
281 void DoProcess0010L(TInt aFunction,TUint16* aArgPtr); |
|
282 void DoProcess0011L(TInt aFunction,TUint16* aArgPtr); |
|
283 void DoProcess0100L(TInt aFunction,TUint16* aArgPtr); |
|
284 void DoProcess0101L(TInt aFunction,TUint16* aArgPtr); |
|
285 void DoProcess0110L(TInt aFunction,TUint16* aArgPtr); |
|
286 void DoProcess0111L(TInt aFunction,TUint16* aArgPtr); |
|
287 void DoProcess1000L(TInt aFunction,TUint16* aArgPtr); |
|
288 void DoProcess1001L(TInt aFunction,TUint16* aArgPtr); |
|
289 void DoProcess1010L(TInt aFunction,TUint16* aArgPtr); |
|
290 void DoProcess1011L(TInt aFunction,TUint16* aArgPtr); |
|
291 void DoProcess1100L(TInt aFunction,TUint16* aArgPtr); |
|
292 void DoProcess1101L(TInt aFunction,TUint16* aArgPtr); |
|
293 void DoProcess1110L(TInt aFunction,TUint16* aArgPtr); |
|
294 void DoProcess1111L(TInt aFunction,TUint16* aArgPtr); |
|
295 void DrawTextL(const TDesC8& aText, const TPoint& aPos, CFbsBitGcWrapper* aGc); |
|
296 void AddGraphicsObject(CGraphicsObject* aObject); |
|
297 CGraphicsObject* GraphicsObject(TInt aHandle); |
|
298 void RemoveGraphicsObject(TInt aHandle); |
|
299 CFbsBitGcWrapper* CloneGcL(); |
|
300 TInt LogicalCoordToDeviceCoord(TInt aLogicalCoord,TBool aHorizontal); |
|
301 TInt LogicalSizeToDeviceSize(TInt aLogicalSize,TBool aHorizontal); |
|
302 void SetROP(CFbsBitGcWrapper* aGc, TInt aROP); |
|
303 void SetROP3(CFbsBitGcWrapper* aGc, TInt aROP); |
|
304 TRgb ExtractColor(const TUint16* aArgPtr); |
|
305 TPoint ExtractPoint(const TUint16* aArgPtr,TBool aXYOrder); |
|
306 TRect ExtractRect(const TUint16* aArgPtr); |
|
307 TInt ExtractDib(const TUint16* aArgPtr, CFbsBitmap* aBitmap); |
|
308 TInt ExtractDib(const TUint16* aArgPtr, CPatternBrush* aPatternBrush); |
|
309 protected: |
|
310 enum TMapMode |
|
311 { |
|
312 EMapModeTEXT = 1, |
|
313 EMapModeLOMETRIC = 2, |
|
314 EMapModeHIMETRIC = 3, |
|
315 EMapModeLOENGLISH = 4, |
|
316 EMapModeHIENGLISH = 5, |
|
317 EMapModeTWIPS = 6, |
|
318 EMapModeISOTROPIC = 7, |
|
319 EMapModeANISOTROPIC = 8 |
|
320 }; |
|
321 private: |
|
322 CWmfReadCodec(TInt aWordsExpected); |
|
323 void ConstructL(); |
|
324 |
|
325 private: |
|
326 TInt iWordsProcessed; |
|
327 TInt iWordsExpected; |
|
328 TBool iIgnoreViewportMetaData; |
|
329 |
|
330 CFbsBitmapDevice* iDevice; |
|
331 CFbsBitmapDevice* iMaskDevice; |
|
332 CFbsBitGcWrapper* iGc; |
|
333 |
|
334 RPointerArray<CFbsBitGcWrapper> iSavedGcStack; |
|
335 TBool iBkModeOpaque; |
|
336 TMapMode iMapMode; |
|
337 TPoint iWindowOrg; |
|
338 TSize iWindowExt; |
|
339 TPoint iViewportOrg; |
|
340 TSize iViewportExt; |
|
341 CGraphicsObject* iGraphicsObject[KWmfMaxGraphicsObjectCount]; |
|
342 |
|
343 CPen* iDefaultPen; |
|
344 CBrush* iDefaultBrush; |
|
345 TRegionFix<1> iClipRegion; |
|
346 TRegionFix<1> iIntersectRegion; |
|
347 |
|
348 CGraphicsContext::TFillRule iFillRule; |
|
349 TPoint* iPointArray; |
|
350 TInt iPointArrayEntries; |
|
351 TUint32 iTextAlignFlags; |
|
352 |
|
353 // Record related information |
|
354 TUint16* iAccumulator; |
|
355 TUint16* iAccumulatorPtr; |
|
356 TInt iAccumulatorSizeInWords; |
|
357 TBool iLookingForRecord; |
|
358 TInt iRecordSizeInWords; |
|
359 TInt iFunction; |
|
360 TInt iWordsToRead; |
|
361 TBool iFinished; |
|
362 }; |
|
363 |
|
364 |
|
365 #endif // __WMFCODEC_H__ |
|
366 |