1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/gdi/sgdi/PICTURE.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,290 @@
1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <gdi.h>
1.20 +#include "GDIPANIC.h"
1.21 +
1.22 +_LIT(KGdiCPicturePanicCategory,"CPicture");
1.23 +
1.24 +EXPORT_C TPictureHeader::TPictureHeader():
1.25 + iPicture(NULL),
1.26 + iPictureType(KNullUid),
1.27 + iSize()
1.28 +/** Constructs a default picture header. */
1.29 + {}
1.30 +
1.31 +EXPORT_C void TPictureHeader::DeletePicture()
1.32 +/** Deletes the internalised picture.
1.33 +
1.34 +The picture can only be deleted if the picture has been internalized. */
1.35 + {
1.36 + if (iPicture.IsPtr())
1.37 + {
1.38 + delete iPicture.AsPtr();
1.39 + iPicture=NULL;
1.40 + }
1.41 + }
1.42 +
1.43 +
1.44 +// Persist this object
1.45 +// Does not take responsibility for storing the picture
1.46 +//
1.47 +EXPORT_C void TPictureHeader::ExternalizeL(RWriteStream& aStream)const
1.48 +/** Externalises a picture header object to a write stream.
1.49 +
1.50 +The presence of this function means that the standard templated stream operator<<()
1.51 +is available to externalise objects of this class.
1.52 +
1.53 +@param aStream The write stream. */
1.54 + {
1.55 + aStream<< iPictureType;
1.56 + aStream<< iPicture;
1.57 + aStream.WriteInt32L(iSize.iWidth);
1.58 + aStream.WriteInt32L(iSize.iHeight);
1.59 + }
1.60 +
1.61 +
1.62 +// Restore this object from the specified stream
1.63 +// Does not take responsibility for restoring the picture
1.64 +//
1.65 +EXPORT_C void TPictureHeader::InternalizeL(RReadStream& aStream)
1.66 +/** Internalises a picture header object from a read stream.
1.67 +
1.68 +The presence of this function means that the standard templated stream operator>>()
1.69 +is available to internalise objects of this class.
1.70 +
1.71 +@param aStream The read stream. */
1.72 + {
1.73 + aStream>> iPictureType;
1.74 + aStream>> iPicture;
1.75 + iSize.iWidth=aStream.ReadInt32L();
1.76 + iSize.iHeight=aStream.ReadInt32L();
1.77 + }
1.78 +
1.79 +EXPORT_C CPicture::CPicture():
1.80 + CBase()
1.81 + {
1.82 + __DECLARE_NAME(_S("CPicture"));
1.83 + }
1.84 +
1.85 +EXPORT_C CPicture::~CPicture()
1.86 +/** Frees all resources owned by the object prior to its destruction. */
1.87 + {}
1.88 +
1.89 +EXPORT_C TPictureCapability CPicture::Capability() const
1.90 +/** Gets the picture's capabilities.
1.91 +
1.92 +These include whether it is scalable and croppable.
1.93 +
1.94 +@return The capabilities of the picture. */
1.95 + {
1.96 + return TPictureCapability(TPictureCapability::ENotScaleable,EFalse);
1.97 + }
1.98 +
1.99 +// Assumes everything goes into the head stream.
1.100 +// (Must be replaced by concrete pictures that have components)
1.101 +//
1.102 +EXPORT_C TStreamId CPicture::StoreL(CStreamStore& aStore) const
1.103 +/** Stores the picture to the specified store.
1.104 +
1.105 +The default implementation assumes that the content of the picture is externalized
1.106 +to a single stream. The implementation may need to be changed for those derived
1.107 +classes that have components.
1.108 +
1.109 +@param aStore The store.
1.110 +@return The ID of the (head) stream used to store the picture. */
1.111 + {
1.112 + RStoreWriteStream stream;
1.113 + TStreamId id=stream.CreateLC(aStore);
1.114 + ExternalizeL(stream); // provided by the concrete picture stream.CommitL();
1.115 + stream.CommitL();
1.116 + CleanupStack::PopAndDestroy();
1.117 + return id;
1.118 + }
1.119 +
1.120 +EXPORT_C void CPicture::ResetToOriginal()
1.121 +/** Resets the picture's scaling and cropping attributes to their original values. */
1.122 + {
1.123 + TMargins cropInTwips;
1.124 + cropInTwips.iLeft=0;
1.125 + cropInTwips.iRight=0;
1.126 + cropInTwips.iTop=0;
1.127 + cropInTwips.iBottom=0;
1.128 + SetCropInTwips(cropInTwips);
1.129 + SetScaleFactor(1000,1000);
1.130 + }
1.131 +
1.132 +EXPORT_C void CPicture::GetSizeInPixels(MGraphicsDeviceMap* aMap,TSize& aSize) const
1.133 +/** Gets the picture's size in pixels.
1.134 +
1.135 +This is calculated from the original size of the picture, taking cropping
1.136 +and scaling into account.
1.137 +
1.138 +@param aMap The pixels to twips mapping interface of the graphics device
1.139 +@param aSize The size of the picture, in pixels. */
1.140 + {
1.141 + GDI_ASSERT_ALWAYS_GENERAL(aMap!=NULL,User::Panic(KGdiCPicturePanicCategory,KErrNotFound));
1.142 + TSize size;
1.143 + GetSizeInTwips(size);
1.144 + aSize.iWidth = aMap->HorizontalTwipsToPixels(size.iWidth);
1.145 + aSize.iHeight = aMap->VerticalTwipsToPixels(size.iHeight);
1.146 + }
1.147 +
1.148 +EXPORT_C void CPicture::SetSizeInPixels(MGraphicsDeviceMap* aMap,const TSize& aSize)
1.149 +/** Sets the picture's size in pixels.
1.150 +
1.151 +@param aMap The pixels to twips mapping interface of the graphics device.
1.152 +@param aSize The size of the picture, in pixels. */
1.153 + {
1.154 + GDI_ASSERT_ALWAYS_GENERAL(aMap!=NULL,User::Panic(KGdiCPicturePanicCategory,KErrNotFound));
1.155 + TSize size;
1.156 + size.iWidth = aMap->HorizontalPixelsToTwips(aSize.iWidth);
1.157 + size.iHeight = aMap->VerticalPixelsToTwips(aSize.iHeight);
1.158 + SetSizeInTwips(size);
1.159 + }
1.160 +
1.161 +EXPORT_C void CPicture::SetScaleFactor(TInt /*aScaleFactorWidth*/,TInt /*aScaleFactorHeight*/)
1.162 +/** Sets the picture's scale factors.
1.163 +
1.164 + @param aScaleFactorWidth The width scale factor, in percent.
1.165 + @param aScaleFactorHeight The height scale factor, in percent. */
1.166 + {
1.167 + }
1.168 +
1.169 +EXPORT_C TInt CPicture::ScaleFactorWidth() const
1.170 +/** Gets the picture's width scale factor.
1.171 +
1.172 +@return The width scale factor, in percent. */
1.173 + {
1.174 + return 1000; // no scaling
1.175 + }
1.176 +
1.177 +EXPORT_C TInt CPicture::ScaleFactorHeight() const
1.178 +/** Gets the pictures height scale factor.
1.179 +
1.180 +@return The height scale factor, in percent. */
1.181 + {
1.182 + return 1000; // no scaling
1.183 + }
1.184 +
1.185 +EXPORT_C void CPicture::GetCropInTwips(TMargins& aCrop) const
1.186 +/** Gets the cropping margins of a picture in twips.
1.187 +
1.188 +These margins are relative to the original unscaled size of the picture.
1.189 +
1.190 +@param aMargins The cropping margins of the picture, in twips */
1.191 + {
1.192 + aCrop.iLeft=0;
1.193 + aCrop.iRight=0;
1.194 + aCrop.iTop=0;
1.195 + aCrop.iBottom=0;
1.196 + }
1.197 +
1.198 +EXPORT_C void CPicture::SetCropInTwips(const TMargins& /*aMargins*/)
1.199 +/** Sets the cropping margins of a picture in twips.
1.200 +
1.201 +These are relative to the original unscaled size of the picture.
1.202 +
1.203 +@param aMargins The cropping margins of the picture, in twips. */
1.204 + {
1.205 + }
1.206 +
1.207 +
1.208 +EXPORT_C TBool CPicture::LineBreakPossible(TUint /*aClass*/,TBool /*aBeforePicture*/,TBool /*aHaveSpaces*/) const
1.209 +/** States whether a line break is possible, either before or after a picture.
1.210 +
1.211 +The default implementation returns ETrue, implying that there is a break opportunity
1.212 +both before and after the picture, whether or not a space is present.
1.213 +
1.214 +This may be overridden for special types of pictures.
1.215 +
1.216 +@param aClass The line breaking class of the adjacent character. Line breaking
1.217 +classes are defined in the header file, tagma.h
1.218 +@param aBeforePicture ETrue, if the adjacent character is before the picture;
1.219 +EFalse, if the adjacent character is afterwards.
1.220 +@param aHaveSpaces ETrue, if spaces occur between the adjacent character and
1.221 +the picture; EFalse, otherwise.
1.222 +@return ETrue, if a line break is possible; EFalse, otherwise. */
1.223 + {
1.224 + return TRUE;
1.225 + }
1.226 +
1.227 +
1.228 +
1.229 +EXPORT_C TBool CPicture::NativePixelSize(TSize&)
1.230 +/** Derived classes might be implemented as bitmaps, in that case it might
1.231 +be interesting to now the native pixel size of the bitmap. */
1.232 + {
1.233 + return EFalse;
1.234 + }
1.235 +
1.236 +EXPORT_C void CPicture::GetSizeInTwips(TSize& aSize) const
1.237 +/** Gets the picture's size, in twips.
1.238 +
1.239 +This size is calculated from the original size of the picture, taking cropping
1.240 +and scaling into account.
1.241 +
1.242 +@param aSize The size of the picture, in twips. */
1.243 + {
1.244 + TSize originalSizeInTwips;
1.245 + GetOriginalSizeInTwips(originalSizeInTwips);
1.246 + TMargins cropInTwips;
1.247 + GetCropInTwips(cropInTwips);
1.248 + aSize.iWidth = (ScaleFactorWidth()*(originalSizeInTwips.iWidth-cropInTwips.iLeft-cropInTwips.iRight))/1000;
1.249 + aSize.iHeight = (ScaleFactorHeight()*(originalSizeInTwips.iHeight-cropInTwips.iTop-cropInTwips.iBottom))/1000;
1.250 + }
1.251 +
1.252 +EXPORT_C void CPicture::SetSizeInTwips(const TSize& aSize)
1.253 +/** Sets the picture's size, in twips
1.254 +
1.255 +@param aSize The size of the picture, in twips. */
1.256 + {
1.257 + TSize originalSizeInTwips;
1.258 + GetOriginalSizeInTwips(originalSizeInTwips);
1.259 + TMargins cropInTwips;
1.260 + GetCropInTwips(cropInTwips);
1.261 + TSize size;
1.262 + size.iWidth = originalSizeInTwips.iWidth-cropInTwips.iLeft-cropInTwips.iRight;
1.263 + size.iHeight = originalSizeInTwips.iHeight-cropInTwips.iTop-cropInTwips.iBottom;
1.264 + TSize scalefactor;
1.265 + if(size.iWidth!=0) scalefactor.iWidth=1000*aSize.iWidth/size.iWidth;
1.266 + if(size.iHeight!=0) scalefactor.iHeight=1000*aSize.iHeight/size.iHeight;
1.267 + SetScaleFactor(scalefactor.iWidth,scalefactor.iHeight);
1.268 + }
1.269 +
1.270 +EXPORT_C void CPicture::AddCropInPixels(MGraphicsDeviceMap* aMap,const TMargins& aMargins)
1.271 +/** Adds pixel cropping margins to the picture.
1.272 +
1.273 +@param aMap The pixels to twips mapping interface of the graphics device
1.274 +@param aMargins The additional pixel cropping margins for the picture, in pixels. */
1.275 + {
1.276 + GDI_ASSERT_ALWAYS_GENERAL(aMap!=NULL,User::Panic(KGdiCPicturePanicCategory,KErrNotFound));
1.277 + TMargins cropInTwips;
1.278 + GetCropInTwips(cropInTwips);
1.279 + TInt scaleFactorWidth=ScaleFactorWidth();
1.280 + if(scaleFactorWidth!=0)
1.281 + {
1.282 + cropInTwips.iLeft += (1000*aMap->HorizontalPixelsToTwips(aMargins.iLeft))/scaleFactorWidth;
1.283 + cropInTwips.iRight += (1000*aMap->HorizontalPixelsToTwips(aMargins.iRight))/scaleFactorWidth;
1.284 + }
1.285 + TInt scaleFactorHeight=ScaleFactorHeight();
1.286 + if(scaleFactorHeight!=0)
1.287 + {
1.288 + cropInTwips.iTop += (1000*aMap->VerticalPixelsToTwips(aMargins.iTop))/scaleFactorHeight;
1.289 + cropInTwips.iBottom += (1000*aMap->VerticalPixelsToTwips(aMargins.iBottom))/scaleFactorHeight;
1.290 + }
1.291 + SetCropInTwips(cropInTwips);
1.292 + }
1.293 +