|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This file implements the decoder for the SVG presentation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "SVGConvert.h" |
|
20 #include <coemain.h> |
|
21 #include <imageconversion.h> |
|
22 #include <icl_uids.hrh> |
|
23 #include <102073d7_extra.rsg> |
|
24 #include <SvgCodecImageConstants.hrh> |
|
25 #include "SVGCodec.h" |
|
26 |
|
27 _LIT(KSVGPanicCategory, "SVGConvertPlugin"); |
|
28 const TInt KInitialFrameWidth = 1; |
|
29 const TInt KInitialFrameHeight = 1; |
|
30 |
|
31 // Number of bits per pixel used in ReadFormatL |
|
32 const TInt KSvgDecBitsPerPixel = 24; |
|
33 |
|
34 enum TIclPanic |
|
35 { |
|
36 EFrameNumberOutOfRange = 0x1 |
|
37 }; |
|
38 |
|
39 // Global panic function |
|
40 GLDEF_C void Panic(TIclPanic aError) |
|
41 { |
|
42 User::Panic(KSVGPanicCategory, aError); |
|
43 } |
|
44 |
|
45 // ============================ MEMBER FUNCTIONS =============================== |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CSvgDecoder::NewL |
|
49 // Static constructor. Returns the pointer to the CSvgDecoder |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CSvgDecoder* CSvgDecoder::NewL() |
|
53 { |
|
54 return new (ELeave) CSvgDecoder; |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CSvgDecoder::~CSvgDecoder |
|
59 // C++ destructor. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CSvgDecoder::~CSvgDecoder() |
|
63 { |
|
64 CImageDecoderPlugin::Cleanup(); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CSvgDecoder::ImageType |
|
69 // Returns the image type and sub-type for a given frame of the image that |
|
70 // has just been opened. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 void CSvgDecoder::ImageType(TInt aFrameNumber, TUid& aImageType, TUid& aImageSubType) const |
|
74 { |
|
75 __ASSERT_ALWAYS(aFrameNumber == 0, Panic( EFrameNumberOutOfRange )); |
|
76 aImageType = KImageTypeSVGUid; |
|
77 aImageSubType = KNullUid; |
|
78 } |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // Returns the codec specific frame information stored in resource files. |
|
82 // This is a virtual funtion that each individual plugin must implement. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CFrameInfoStrings* CSvgDecoder::FrameInfoStringsL( RFs& /*aFs*/, TInt /*aFrameNumber*/ ) |
|
86 { |
|
87 return NULL; |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CSvgDecoder::CSvgDecoder |
|
92 // C++ default constructor can NOT contain any code, that |
|
93 // might leave. |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 CSvgDecoder::CSvgDecoder() |
|
97 { |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // Invokes the ReadFrameHeadersL() method of the supplied plugin. |
|
102 // This is a virtual funtion that each individual plugin must implement. |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void CSvgDecoder::ScanDataL() |
|
106 { |
|
107 CSvgReadCodec* imageReadCodec = CSvgReadCodec::NewL( |
|
108 TSize(KInitialFrameWidth, KInitialFrameHeight) |
|
109 ); |
|
110 SetImageReadCodec( imageReadCodec ); |
|
111 |
|
112 ReadFormatL(); |
|
113 ReadFrameHeadersL(); |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // Reads the image header & data information |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CSvgDecoder::ReadFormatL() |
|
121 { |
|
122 ReadDataL(0, iFileData, KMaxTInt); |
|
123 SetDataLength( iFileData.Length() ); |
|
124 CSvgReadCodec* imageReadCodec = static_cast<CSvgReadCodec* >(ImageReadCodec()); |
|
125 imageReadCodec->SetFileDataL( iFileData ); |
|
126 |
|
127 imageReadCodec->PrepareEngine(); |
|
128 const TSize contentSize = imageReadCodec->ContentSize(); |
|
129 |
|
130 TFrameInfo imageInfo; |
|
131 imageInfo = ImageInfo(); |
|
132 imageInfo.iFrameCoordsInPixels.SetRect(TPoint(0, 0), contentSize ); |
|
133 imageInfo.iOverallSizeInPixels = contentSize; |
|
134 imageInfo.iBitsPerPixel = KSvgDecBitsPerPixel; |
|
135 imageInfo.iDelay = 0; |
|
136 imageInfo.iFlags = TFrameInfo::ECanDither | TFrameInfo::ETransparencyPossible; |
|
137 imageInfo.iFrameDisplayMode = EColor64K; |
|
138 imageInfo.iFrameSizeInTwips = ContentSizeInTwips(contentSize); |
|
139 |
|
140 SetImageInfo(imageInfo); |
|
141 SetStartPosition(0); |
|
142 } |
|
143 |
|
144 TSize CSvgDecoder::ContentSizeInTwips(const TSize aContentSizeInPixels) const |
|
145 { |
|
146 // Create zoom factor object |
|
147 TRect boxInTwips(TPoint(0,0), TSize(0,0)); |
|
148 CCoeEnv* coeEnv = CCoeEnv::Static(); |
|
149 if(coeEnv) |
|
150 { |
|
151 TZoomFactor deviceMap(CCoeEnv::Static()->ScreenDevice()); |
|
152 // Set zoom factor at 1 to 1 |
|
153 deviceMap.SetZoomFactor(TZoomFactor::EZoomOneToOne); |
|
154 const TRect boxInPixels(TPoint(0,0), aContentSizeInPixels); |
|
155 // convert rectangle co-ordinates into pixels |
|
156 boxInTwips = deviceMap.PixelsToTwips(boxInPixels); |
|
157 } |
|
158 return boxInTwips.Size(); |
|
159 } |
|
160 |
|
161 // End of File |
|
162 |