First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 _LIT(KGdiCPicturePanicCategory,"CPicture");
21 EXPORT_C TPictureHeader::TPictureHeader():
23 iPictureType(KNullUid),
25 /** Constructs a default picture header. */
28 EXPORT_C void TPictureHeader::DeletePicture()
29 /** Deletes the internalised picture.
31 The picture can only be deleted if the picture has been internalized. */
35 delete iPicture.AsPtr();
41 // Persist this object
42 // Does not take responsibility for storing the picture
44 EXPORT_C void TPictureHeader::ExternalizeL(RWriteStream& aStream)const
45 /** Externalises a picture header object to a write stream.
47 The presence of this function means that the standard templated stream operator<<()
48 is available to externalise objects of this class.
50 @param aStream The write stream. */
52 aStream<< iPictureType;
54 aStream.WriteInt32L(iSize.iWidth);
55 aStream.WriteInt32L(iSize.iHeight);
59 // Restore this object from the specified stream
60 // Does not take responsibility for restoring the picture
62 EXPORT_C void TPictureHeader::InternalizeL(RReadStream& aStream)
63 /** Internalises a picture header object from a read stream.
65 The presence of this function means that the standard templated stream operator>>()
66 is available to internalise objects of this class.
68 @param aStream The read stream. */
70 aStream>> iPictureType;
72 iSize.iWidth=aStream.ReadInt32L();
73 iSize.iHeight=aStream.ReadInt32L();
76 EXPORT_C CPicture::CPicture():
79 __DECLARE_NAME(_S("CPicture"));
82 EXPORT_C CPicture::~CPicture()
83 /** Frees all resources owned by the object prior to its destruction. */
86 EXPORT_C TPictureCapability CPicture::Capability() const
87 /** Gets the picture's capabilities.
89 These include whether it is scalable and croppable.
91 @return The capabilities of the picture. */
93 return TPictureCapability(TPictureCapability::ENotScaleable,EFalse);
96 // Assumes everything goes into the head stream.
97 // (Must be replaced by concrete pictures that have components)
99 EXPORT_C TStreamId CPicture::StoreL(CStreamStore& aStore) const
100 /** Stores the picture to the specified store.
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.
106 @param aStore The store.
107 @return The ID of the (head) stream used to store the picture. */
109 RStoreWriteStream stream;
110 TStreamId id=stream.CreateLC(aStore);
111 ExternalizeL(stream); // provided by the concrete picture stream.CommitL();
113 CleanupStack::PopAndDestroy();
117 EXPORT_C void CPicture::ResetToOriginal()
118 /** Resets the picture's scaling and cropping attributes to their original values. */
120 TMargins cropInTwips;
122 cropInTwips.iRight=0;
124 cropInTwips.iBottom=0;
125 SetCropInTwips(cropInTwips);
126 SetScaleFactor(1000,1000);
129 EXPORT_C void CPicture::GetSizeInPixels(MGraphicsDeviceMap* aMap,TSize& aSize) const
130 /** Gets the picture's size in pixels.
132 This is calculated from the original size of the picture, taking cropping
133 and scaling into account.
135 @param aMap The pixels to twips mapping interface of the graphics device
136 @param aSize The size of the picture, in pixels. */
138 GDI_ASSERT_ALWAYS_GENERAL(aMap!=NULL,User::Panic(KGdiCPicturePanicCategory,KErrNotFound));
140 GetSizeInTwips(size);
141 aSize.iWidth = aMap->HorizontalTwipsToPixels(size.iWidth);
142 aSize.iHeight = aMap->VerticalTwipsToPixels(size.iHeight);
145 EXPORT_C void CPicture::SetSizeInPixels(MGraphicsDeviceMap* aMap,const TSize& aSize)
146 /** Sets the picture's size in pixels.
148 @param aMap The pixels to twips mapping interface of the graphics device.
149 @param aSize The size of the picture, in pixels. */
151 GDI_ASSERT_ALWAYS_GENERAL(aMap!=NULL,User::Panic(KGdiCPicturePanicCategory,KErrNotFound));
153 size.iWidth = aMap->HorizontalPixelsToTwips(aSize.iWidth);
154 size.iHeight = aMap->VerticalPixelsToTwips(aSize.iHeight);
155 SetSizeInTwips(size);
158 EXPORT_C void CPicture::SetScaleFactor(TInt /*aScaleFactorWidth*/,TInt /*aScaleFactorHeight*/)
159 /** Sets the picture's scale factors.
161 @param aScaleFactorWidth The width scale factor, in percent.
162 @param aScaleFactorHeight The height scale factor, in percent. */
166 EXPORT_C TInt CPicture::ScaleFactorWidth() const
167 /** Gets the picture's width scale factor.
169 @return The width scale factor, in percent. */
171 return 1000; // no scaling
174 EXPORT_C TInt CPicture::ScaleFactorHeight() const
175 /** Gets the pictures height scale factor.
177 @return The height scale factor, in percent. */
179 return 1000; // no scaling
182 EXPORT_C void CPicture::GetCropInTwips(TMargins& aCrop) const
183 /** Gets the cropping margins of a picture in twips.
185 These margins are relative to the original unscaled size of the picture.
187 @param aMargins The cropping margins of the picture, in twips */
195 EXPORT_C void CPicture::SetCropInTwips(const TMargins& /*aMargins*/)
196 /** Sets the cropping margins of a picture in twips.
198 These are relative to the original unscaled size of the picture.
200 @param aMargins The cropping margins of the picture, in twips. */
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.
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.
211 This may be overridden for special types of pictures.
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. */
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. */
233 EXPORT_C void CPicture::GetSizeInTwips(TSize& aSize) const
234 /** Gets the picture's size, in twips.
236 This size is calculated from the original size of the picture, taking cropping
237 and scaling into account.
239 @param aSize The size of the picture, in twips. */
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;
249 EXPORT_C void CPicture::SetSizeInTwips(const TSize& aSize)
250 /** Sets the picture's size, in twips
252 @param aSize The size of the picture, in twips. */
254 TSize originalSizeInTwips;
255 GetOriginalSizeInTwips(originalSizeInTwips);
256 TMargins cropInTwips;
257 GetCropInTwips(cropInTwips);
259 size.iWidth = originalSizeInTwips.iWidth-cropInTwips.iLeft-cropInTwips.iRight;
260 size.iHeight = originalSizeInTwips.iHeight-cropInTwips.iTop-cropInTwips.iBottom;
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);
267 EXPORT_C void CPicture::AddCropInPixels(MGraphicsDeviceMap* aMap,const TMargins& aMargins)
268 /** Adds pixel cropping margins to the picture.
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. */
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)
279 cropInTwips.iLeft += (1000*aMap->HorizontalPixelsToTwips(aMargins.iLeft))/scaleFactorWidth;
280 cropInTwips.iRight += (1000*aMap->HorizontalPixelsToTwips(aMargins.iRight))/scaleFactorWidth;
282 TInt scaleFactorHeight=ScaleFactorHeight();
283 if(scaleFactorHeight!=0)
285 cropInTwips.iTop += (1000*aMap->VerticalPixelsToTwips(aMargins.iTop))/scaleFactorHeight;
286 cropInTwips.iBottom += (1000*aMap->VerticalPixelsToTwips(aMargins.iBottom))/scaleFactorHeight;
288 SetCropInTwips(cropInTwips);