|
1 // Copyright (c) 1998-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 #include <gdi.h> |
|
17 #include "GDIPANIC.h" |
|
18 |
|
19 _LIT(KGdiCPicturePanicCategory,"CPicture"); |
|
20 |
|
21 EXPORT_C TPictureHeader::TPictureHeader(): |
|
22 iPicture(NULL), |
|
23 iPictureType(KNullUid), |
|
24 iSize() |
|
25 /** Constructs a default picture header. */ |
|
26 {} |
|
27 |
|
28 EXPORT_C void TPictureHeader::DeletePicture() |
|
29 /** Deletes the internalised picture. |
|
30 |
|
31 The picture can only be deleted if the picture has been internalized. */ |
|
32 { |
|
33 if (iPicture.IsPtr()) |
|
34 { |
|
35 delete iPicture.AsPtr(); |
|
36 iPicture=NULL; |
|
37 } |
|
38 } |
|
39 |
|
40 |
|
41 // Persist this object |
|
42 // Does not take responsibility for storing the picture |
|
43 // |
|
44 EXPORT_C void TPictureHeader::ExternalizeL(RWriteStream& aStream)const |
|
45 /** Externalises a picture header object to a write stream. |
|
46 |
|
47 The presence of this function means that the standard templated stream operator<<() |
|
48 is available to externalise objects of this class. |
|
49 |
|
50 @param aStream The write stream. */ |
|
51 { |
|
52 aStream<< iPictureType; |
|
53 aStream<< iPicture; |
|
54 aStream.WriteInt32L(iSize.iWidth); |
|
55 aStream.WriteInt32L(iSize.iHeight); |
|
56 } |
|
57 |
|
58 |
|
59 // Restore this object from the specified stream |
|
60 // Does not take responsibility for restoring the picture |
|
61 // |
|
62 EXPORT_C void TPictureHeader::InternalizeL(RReadStream& aStream) |
|
63 /** Internalises a picture header object from a read stream. |
|
64 |
|
65 The presence of this function means that the standard templated stream operator>>() |
|
66 is available to internalise objects of this class. |
|
67 |
|
68 @param aStream The read stream. */ |
|
69 { |
|
70 aStream>> iPictureType; |
|
71 aStream>> iPicture; |
|
72 iSize.iWidth=aStream.ReadInt32L(); |
|
73 iSize.iHeight=aStream.ReadInt32L(); |
|
74 } |
|
75 |
|
76 EXPORT_C CPicture::CPicture(): |
|
77 CBase() |
|
78 { |
|
79 __DECLARE_NAME(_S("CPicture")); |
|
80 } |
|
81 |
|
82 EXPORT_C CPicture::~CPicture() |
|
83 /** Frees all resources owned by the object prior to its destruction. */ |
|
84 {} |
|
85 |
|
86 EXPORT_C TPictureCapability CPicture::Capability() const |
|
87 /** Gets the picture's capabilities. |
|
88 |
|
89 These include whether it is scalable and croppable. |
|
90 |
|
91 @return The capabilities of the picture. */ |
|
92 { |
|
93 return TPictureCapability(TPictureCapability::ENotScaleable,EFalse); |
|
94 } |
|
95 |
|
96 // Assumes everything goes into the head stream. |
|
97 // (Must be replaced by concrete pictures that have components) |
|
98 // |
|
99 EXPORT_C TStreamId CPicture::StoreL(CStreamStore& aStore) const |
|
100 /** Stores the picture to the specified store. |
|
101 |
|
102 The default implementation assumes that the content of the picture is externalized |
|
103 to a single stream. The implementation may need to be changed for those derived |
|
104 classes that have components. |
|
105 |
|
106 @param aStore The store. |
|
107 @return The ID of the (head) stream used to store the picture. */ |
|
108 { |
|
109 RStoreWriteStream stream; |
|
110 TStreamId id=stream.CreateLC(aStore); |
|
111 ExternalizeL(stream); // provided by the concrete picture stream.CommitL(); |
|
112 stream.CommitL(); |
|
113 CleanupStack::PopAndDestroy(); |
|
114 return id; |
|
115 } |
|
116 |
|
117 EXPORT_C void CPicture::ResetToOriginal() |
|
118 /** Resets the picture's scaling and cropping attributes to their original values. */ |
|
119 { |
|
120 TMargins cropInTwips; |
|
121 cropInTwips.iLeft=0; |
|
122 cropInTwips.iRight=0; |
|
123 cropInTwips.iTop=0; |
|
124 cropInTwips.iBottom=0; |
|
125 SetCropInTwips(cropInTwips); |
|
126 SetScaleFactor(1000,1000); |
|
127 } |
|
128 |
|
129 EXPORT_C void CPicture::GetSizeInPixels(MGraphicsDeviceMap* aMap,TSize& aSize) const |
|
130 /** Gets the picture's size in pixels. |
|
131 |
|
132 This is calculated from the original size of the picture, taking cropping |
|
133 and scaling into account. |
|
134 |
|
135 @param aMap The pixels to twips mapping interface of the graphics device |
|
136 @param aSize The size of the picture, in pixels. */ |
|
137 { |
|
138 GDI_ASSERT_ALWAYS_GENERAL(aMap!=NULL,User::Panic(KGdiCPicturePanicCategory,KErrNotFound)); |
|
139 TSize size; |
|
140 GetSizeInTwips(size); |
|
141 aSize.iWidth = aMap->HorizontalTwipsToPixels(size.iWidth); |
|
142 aSize.iHeight = aMap->VerticalTwipsToPixels(size.iHeight); |
|
143 } |
|
144 |
|
145 EXPORT_C void CPicture::SetSizeInPixels(MGraphicsDeviceMap* aMap,const TSize& aSize) |
|
146 /** Sets the picture's size in pixels. |
|
147 |
|
148 @param aMap The pixels to twips mapping interface of the graphics device. |
|
149 @param aSize The size of the picture, in pixels. */ |
|
150 { |
|
151 GDI_ASSERT_ALWAYS_GENERAL(aMap!=NULL,User::Panic(KGdiCPicturePanicCategory,KErrNotFound)); |
|
152 TSize size; |
|
153 size.iWidth = aMap->HorizontalPixelsToTwips(aSize.iWidth); |
|
154 size.iHeight = aMap->VerticalPixelsToTwips(aSize.iHeight); |
|
155 SetSizeInTwips(size); |
|
156 } |
|
157 |
|
158 EXPORT_C void CPicture::SetScaleFactor(TInt /*aScaleFactorWidth*/,TInt /*aScaleFactorHeight*/) |
|
159 /** Sets the picture's scale factors. |
|
160 |
|
161 @param aScaleFactorWidth The width scale factor, in percent. |
|
162 @param aScaleFactorHeight The height scale factor, in percent. */ |
|
163 { |
|
164 } |
|
165 |
|
166 EXPORT_C TInt CPicture::ScaleFactorWidth() const |
|
167 /** Gets the picture's width scale factor. |
|
168 |
|
169 @return The width scale factor, in percent. */ |
|
170 { |
|
171 return 1000; // no scaling |
|
172 } |
|
173 |
|
174 EXPORT_C TInt CPicture::ScaleFactorHeight() const |
|
175 /** Gets the pictures height scale factor. |
|
176 |
|
177 @return The height scale factor, in percent. */ |
|
178 { |
|
179 return 1000; // no scaling |
|
180 } |
|
181 |
|
182 EXPORT_C void CPicture::GetCropInTwips(TMargins& aCrop) const |
|
183 /** Gets the cropping margins of a picture in twips. |
|
184 |
|
185 These margins are relative to the original unscaled size of the picture. |
|
186 |
|
187 @param aMargins The cropping margins of the picture, in twips */ |
|
188 { |
|
189 aCrop.iLeft=0; |
|
190 aCrop.iRight=0; |
|
191 aCrop.iTop=0; |
|
192 aCrop.iBottom=0; |
|
193 } |
|
194 |
|
195 EXPORT_C void CPicture::SetCropInTwips(const TMargins& /*aMargins*/) |
|
196 /** Sets the cropping margins of a picture in twips. |
|
197 |
|
198 These are relative to the original unscaled size of the picture. |
|
199 |
|
200 @param aMargins The cropping margins of the picture, in twips. */ |
|
201 { |
|
202 } |
|
203 |
|
204 |
|
205 EXPORT_C TBool CPicture::LineBreakPossible(TUint /*aClass*/,TBool /*aBeforePicture*/,TBool /*aHaveSpaces*/) const |
|
206 /** States whether a line break is possible, either before or after a picture. |
|
207 |
|
208 The default implementation returns ETrue, implying that there is a break opportunity |
|
209 both before and after the picture, whether or not a space is present. |
|
210 |
|
211 This may be overridden for special types of pictures. |
|
212 |
|
213 @param aClass The line breaking class of the adjacent character. Line breaking |
|
214 classes are defined in the header file, tagma.h |
|
215 @param aBeforePicture ETrue, if the adjacent character is before the picture; |
|
216 EFalse, if the adjacent character is afterwards. |
|
217 @param aHaveSpaces ETrue, if spaces occur between the adjacent character and |
|
218 the picture; EFalse, otherwise. |
|
219 @return ETrue, if a line break is possible; EFalse, otherwise. */ |
|
220 { |
|
221 return TRUE; |
|
222 } |
|
223 |
|
224 |
|
225 |
|
226 EXPORT_C TBool CPicture::NativePixelSize(TSize&) |
|
227 /** Derived classes might be implemented as bitmaps, in that case it might |
|
228 be interesting to now the native pixel size of the bitmap. */ |
|
229 { |
|
230 return EFalse; |
|
231 } |
|
232 |
|
233 EXPORT_C void CPicture::GetSizeInTwips(TSize& aSize) const |
|
234 /** Gets the picture's size, in twips. |
|
235 |
|
236 This size is calculated from the original size of the picture, taking cropping |
|
237 and scaling into account. |
|
238 |
|
239 @param aSize The size of the picture, in twips. */ |
|
240 { |
|
241 TSize originalSizeInTwips; |
|
242 GetOriginalSizeInTwips(originalSizeInTwips); |
|
243 TMargins cropInTwips; |
|
244 GetCropInTwips(cropInTwips); |
|
245 aSize.iWidth = (ScaleFactorWidth()*(originalSizeInTwips.iWidth-cropInTwips.iLeft-cropInTwips.iRight))/1000; |
|
246 aSize.iHeight = (ScaleFactorHeight()*(originalSizeInTwips.iHeight-cropInTwips.iTop-cropInTwips.iBottom))/1000; |
|
247 } |
|
248 |
|
249 EXPORT_C void CPicture::SetSizeInTwips(const TSize& aSize) |
|
250 /** Sets the picture's size, in twips |
|
251 |
|
252 @param aSize The size of the picture, in twips. */ |
|
253 { |
|
254 TSize originalSizeInTwips; |
|
255 GetOriginalSizeInTwips(originalSizeInTwips); |
|
256 TMargins cropInTwips; |
|
257 GetCropInTwips(cropInTwips); |
|
258 TSize size; |
|
259 size.iWidth = originalSizeInTwips.iWidth-cropInTwips.iLeft-cropInTwips.iRight; |
|
260 size.iHeight = originalSizeInTwips.iHeight-cropInTwips.iTop-cropInTwips.iBottom; |
|
261 TSize scalefactor; |
|
262 if(size.iWidth!=0) scalefactor.iWidth=1000*aSize.iWidth/size.iWidth; |
|
263 if(size.iHeight!=0) scalefactor.iHeight=1000*aSize.iHeight/size.iHeight; |
|
264 SetScaleFactor(scalefactor.iWidth,scalefactor.iHeight); |
|
265 } |
|
266 |
|
267 EXPORT_C void CPicture::AddCropInPixels(MGraphicsDeviceMap* aMap,const TMargins& aMargins) |
|
268 /** Adds pixel cropping margins to the picture. |
|
269 |
|
270 @param aMap The pixels to twips mapping interface of the graphics device |
|
271 @param aMargins The additional pixel cropping margins for the picture, in pixels. */ |
|
272 { |
|
273 GDI_ASSERT_ALWAYS_GENERAL(aMap!=NULL,User::Panic(KGdiCPicturePanicCategory,KErrNotFound)); |
|
274 TMargins cropInTwips; |
|
275 GetCropInTwips(cropInTwips); |
|
276 TInt scaleFactorWidth=ScaleFactorWidth(); |
|
277 if(scaleFactorWidth!=0) |
|
278 { |
|
279 cropInTwips.iLeft += (1000*aMap->HorizontalPixelsToTwips(aMargins.iLeft))/scaleFactorWidth; |
|
280 cropInTwips.iRight += (1000*aMap->HorizontalPixelsToTwips(aMargins.iRight))/scaleFactorWidth; |
|
281 } |
|
282 TInt scaleFactorHeight=ScaleFactorHeight(); |
|
283 if(scaleFactorHeight!=0) |
|
284 { |
|
285 cropInTwips.iTop += (1000*aMap->VerticalPixelsToTwips(aMargins.iTop))/scaleFactorHeight; |
|
286 cropInTwips.iBottom += (1000*aMap->VerticalPixelsToTwips(aMargins.iBottom))/scaleFactorHeight; |
|
287 } |
|
288 SetCropInTwips(cropInTwips); |
|
289 } |
|
290 |