1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicsdeviceinterface/gdi/sgdi/GDIMAIN.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,444 @@
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 <bidi.h>
1.21 +#include "GDIPANIC.h"
1.22 +#include "gdistructs.h"
1.23 +#include "gdiconsts.h"
1.24 +
1.25 +
1.26 +// Global panic function
1.27 +
1.28 +_LIT(KGdiPanicCategory,"GDI");
1.29 +
1.30 +void Panic(TGdiPanic aError)
1.31 + {
1.32 + User::Panic(KGdiPanicCategory,aError);
1.33 + }
1.34 +
1.35 +_LIT(KGDIPanicDesc1, "Gdi internal Panic %S, in file %S @ line %i");
1.36 +_LIT(KGDIPanicDesc2, "Assert condition = \"%S\"");
1.37 +_LIT(KGDIPanicDesc3, "Gdi internal %S, in file %S @ line %i");
1.38 +
1.39 +void PanicWithCondAndInfo(TGdiPanic aError, const TDesC& aCondition, const TDesC& aFileName, const TDesC& aPanicName, TInt aLine)
1.40 + {
1.41 + TBuf<256> buf;
1.42 + buf.Format(KGDIPanicDesc1, &aPanicName, &aFileName, aLine);
1.43 + RDebug::Print(buf);
1.44 +
1.45 + buf.Format(KGDIPanicDesc2, &aCondition);
1.46 + RDebug::Print(buf);
1.47 + Panic(aError);
1.48 + }
1.49 +
1.50 +void PanicLogWithInfo(const TDesC& aCommand, const TDesC& aCondition, const TDesC& aFileName, TInt aLine)
1.51 + {
1.52 + TBuf<256> buf;
1.53 + buf.Format(KGDIPanicDesc3, &aCommand, &aFileName, aLine);
1.54 + RDebug::Print(buf);
1.55 +
1.56 + buf.Format(KGDIPanicDesc2, &aCondition);
1.57 + RDebug::Print(buf);
1.58 + }
1.59 +
1.60 +
1.61 +//
1.62 +// MGraphicsDeviceMap
1.63 +//
1.64 +
1.65 +
1.66 +EXPORT_C MGraphicsDeviceMap::MGraphicsDeviceMap()
1.67 +/** Default constructor. */
1.68 + {}
1.69 +
1.70 +
1.71 +EXPORT_C MGraphicsDeviceMap::~MGraphicsDeviceMap()
1.72 +/** Destructor. */
1.73 + {}
1.74 +
1.75 +
1.76 +EXPORT_C TPoint MGraphicsDeviceMap::TwipsToPixels(const TPoint& aTwipPoint) const
1.77 +/** Converts a point in twips to a point in pixels.
1.78 +
1.79 +@param aTwipPoint A point on the graphics device in twips.
1.80 +@return A point on the graphics device in pixels. */
1.81 + {
1.82 + return TPoint(HorizontalTwipsToPixels(aTwipPoint.iX),VerticalTwipsToPixels(aTwipPoint.iY));
1.83 + }
1.84 +
1.85 +
1.86 +EXPORT_C TRect MGraphicsDeviceMap::TwipsToPixels(const TRect& aTwipRect) const
1.87 +/** Converts a rectangle in twips to a rectangle in pixels.
1.88 +
1.89 +@param aTwipRect A rectangle on the graphics device in twips
1.90 +@return A rectangle on the graphics device in pixels. */
1.91 + {
1.92 + return TRect(TwipsToPixels(aTwipRect.iTl),TwipsToPixels(aTwipRect.iBr));
1.93 + }
1.94 +
1.95 +
1.96 +EXPORT_C TPoint MGraphicsDeviceMap::PixelsToTwips(const TPoint& aPixelPoint) const
1.97 +/** Converts a point in pixels to a point in twips.
1.98 +
1.99 +@param aPixelPoint A point on the graphics device in pixels.
1.100 +@return A point on the graphics device in twips. */
1.101 + {
1.102 + return TPoint(HorizontalPixelsToTwips(aPixelPoint.iX),VerticalPixelsToTwips(aPixelPoint.iY));
1.103 + }
1.104 +
1.105 +
1.106 +EXPORT_C TRect MGraphicsDeviceMap::PixelsToTwips(const TRect& aPixelRect) const
1.107 +/** Converts a rectangle in pixels to a rectangle in twips.
1.108 +
1.109 +@param aPixelRect A rectangle on the graphics device in pixels.
1.110 +@return A rectangle on the graphics device in twips. */
1.111 + {
1.112 + return TRect(PixelsToTwips(aPixelRect.iTl),PixelsToTwips(aPixelRect.iBr));
1.113 + }
1.114 +
1.115 +//
1.116 +// CGraphicsContext
1.117 +//
1.118 +
1.119 +EXPORT_C TInt CGraphicsContext::JustificationInPixels(TInt aExcessPixels,TInt aTotalUnits,TInt aFirstUnit,TInt aNumUnits)
1.120 +/** Gets the amount of space in pixels by which to adjust letter or word spacing,
1.121 +given the total number of words and spaces, a start space, and the number
1.122 +of units to be adjusted.
1.123 +
1.124 +The first two arguments are the number of pixels (character groups) and the
1.125 +number of units (word spaces) over which justification is to occur. The third
1.126 +argument specifies the current character group or word space, while the final
1.127 +argument specifies the number of units that are to be adjusted.
1.128 +
1.129 +A panic occurs if aExcessPixels is 0, aTotalUnits is not greater than 0, or
1.130 +aFirstUnit is not less than aTotalUnits.
1.131 +
1.132 +@param aExcessPixels The number of pixels by which the width of the text is
1.133 +to be changed. It may be positive, in which case the text is stretched, or
1.134 +negative, in which case it is shrunk.
1.135 +@param aTotalUnits The number of word spaces over which the change in width
1.136 +is to be distributed.
1.137 +@param aFirstUnit The current unit — the character group or word space we
1.138 +are 'on'.
1.139 +@param aNumUnits The number of units that are to be adjusted — starting
1.140 +at aFirstUnit.
1.141 +@return The number of pixels to be added to the width of the current unit.
1.142 +@see SetWordJustification()
1.143 +@see SetCharJustification() */
1.144 + {
1.145 + if(aExcessPixels==0 || aTotalUnits<=0 || aFirstUnit>=aTotalUnits)
1.146 + return(0);
1.147 + TInt noExtra=Abs(aExcessPixels%aTotalUnits);
1.148 + TInt extraPixel=aExcessPixels/Abs(aExcessPixels);
1.149 + GDI_ASSERT_DEBUG_GENERAL( aFirstUnit>=0 , User::Panic(KGdiPanicCategory,KErrArgument) ) ;
1.150 + GDI_ASSERT_DEBUG_GENERAL( aNumUnits>=0 , User::Panic(KGdiPanicCategory,KErrArgument) ) ;
1.151 + if(aFirstUnit+aNumUnits>aTotalUnits)
1.152 + aNumUnits=aTotalUnits-aFirstUnit;
1.153 + TInt clip=aNumUnits*(aExcessPixels/aTotalUnits);
1.154 + if(aFirstUnit>=noExtra)
1.155 + return(clip);
1.156 + if(aFirstUnit+aNumUnits>noExtra)
1.157 + aNumUnits=noExtra-aFirstUnit;
1.158 + return(clip+aNumUnits*extraPixel);
1.159 + }
1.160 +
1.161 +
1.162 +EXPORT_C TInt CGraphicsContext::JustificationInPixels(TInt& aExcessPixels,TInt& aTotalUnits)
1.163 +/** Gets the amount of space in pixels by which to adjust the current letter or
1.164 +word spacing, and also retrieves the number of excess pixels and word spaces
1.165 +remaining after the adjustment is performed.
1.166 +
1.167 +The arguments are the number of remaining pixels (character groups) and units
1.168 +(word spaces) over which justification is to occur. The function can be called
1.169 +repetitively until the number of units is zero, and hence justification is
1.170 +complete. A panic occurs if the number of units is less than one or the amount
1.171 +of pixels is zero.
1.172 +
1.173 +@param aExcessPixels The number of pixels by which the width of the text is
1.174 +to be changed. It may be positive, in which case the text is stretched, or
1.175 +negative, in which case it is shrunk. On return, this is equal to its old
1.176 +value minus the return value.
1.177 +@param aTotalUnits The number of word spaces over which the change in width
1.178 +is to be distributed. On return, this is reduced by one.
1.179 +@return The number of pixels to be added to the width of the current unit.
1.180 +@see SetWordJustification()
1.181 +@see SetCharJustification() */
1.182 + {
1.183 + GDI_ASSERT_DEBUG_GENERAL(aExcessPixels!=0,User::Panic(KGdiPanicCategory,KErrArgument));
1.184 + GDI_ASSERT_DEBUG_GENERAL(aTotalUnits>0,User::Panic(KGdiPanicCategory,KErrArgument));
1.185 + TInt justification=aExcessPixels/aTotalUnits;
1.186 + if(aExcessPixels%aTotalUnits)
1.187 + {
1.188 + if(aExcessPixels>0)
1.189 + justification++;
1.190 + else
1.191 + justification--;
1.192 + }
1.193 + aTotalUnits--;
1.194 + aExcessPixels-=justification;
1.195 + return(justification);
1.196 + }
1.197 +
1.198 +
1.199 +EXPORT_C TInt CGraphicsContext::DrawTextExtended(const TDesC& aText,const TPoint& aPosition,
1.200 + const TDrawTextExtendedParam& aParam)
1.201 +/** Draws text, optionally changing its direction (right-to-left / left-to-right).
1.202 +
1.203 +Apart from reordering the text, the function is the same as the two parameter
1.204 +variant of DrawText(), described above.
1.205 +
1.206 +@param aText The text string to be drawn, optionally changing its direction
1.207 +(right-to-left / left-to-right).
1.208 +@param aPosition A point specifying the position of the left end of the text.
1.209 +@param aParam Indicates whether the text should be drawn from right-to-left
1.210 +(for scripts like Arabic and Hebrew) or left-to-right.
1.211 +@return KErrNoMemory indicates there was an OOM error when reordering the text;
1.212 +KErrNone if the reordering was successful. */
1.213 + {
1.214 + // Reorder the text bidirectionally.
1.215 + TText* reordered_text = NULL;
1.216 + int error = TBidirectionalState::ReorderText(aText.Ptr(),aText.Length(),aParam.iParRightToLeft,reordered_text);
1.217 + TPtrC p(reordered_text,aText.Length());
1.218 + DrawText(p,aPosition,aParam);
1.219 + if (reordered_text != aText.Ptr())
1.220 + delete [] reordered_text;
1.221 + return error;
1.222 + }
1.223 +
1.224 +
1.225 +EXPORT_C void CGraphicsContext::DrawText(const TDesC& aText,const TPoint& aPosition,const TDrawTextParam& /*aParam*/)
1.226 +/** Draws the specified text at the given position using the parameters supplied.
1.227 +
1.228 +@param aText The text to be drawn.
1.229 +@param aPosition The position to draw the text at.
1.230 +@param aParam Parameters to use for text drawing. */
1.231 + {
1.232 + DrawText(aText,aPosition);
1.233 + }
1.234 +
1.235 +/*
1.236 +Can be used to find out the top and bottom of an underline for the active font.
1.237 +This allows correct calculation of the area required in which to draw text with underline.
1.238 +
1.239 +@param TInt& aTop The top of the underline position
1.240 +@param TInt& aBottom The bottom of the underline position
1.241 +@return TInt KErrNone if successful, else a standard system wide error value.
1.242 +*/
1.243 +EXPORT_C TInt CGraphicsContext::GetUnderlineMetrics(TInt& aTop,TInt& aBottom)
1.244 + {
1.245 +
1.246 + TTwoTInt outputPackage;
1.247 + TTwoTInt* outputPtr = &outputPackage;
1.248 + TInt err = APIExtension(KGetUnderlineMetrics, (TAny*&) outputPtr, NULL);
1.249 + aTop = outputPackage.iTop;
1.250 + aBottom = outputPackage.iBottom;
1.251 + return err;
1.252 + }
1.253 +
1.254 +EXPORT_C TInt CGraphicsContext::SetShadowColor(const TRgb& aShadowColor)
1.255 + {
1.256 + TRgb shadowColor = aShadowColor;
1.257 + TInt *dummy = NULL;
1.258 + return APIExtension(KSetShadowColor, (TAny*&)dummy, (TAny*)&shadowColor);
1.259 + }
1.260 +
1.261 +EXPORT_C TInt CGraphicsContext::GetShadowColor(TRgb& aShadowColor)
1.262 + {
1.263 + TRgb* shadowColor = &aShadowColor;
1.264 + return APIExtension(KGetShadowColor, (TAny*&)shadowColor, NULL);
1.265 + }
1.266 +
1.267 +EXPORT_C TBool CGraphicsContext::IsFbsBitGc() const
1.268 + {
1.269 + TBool isFbsBitGc=EFalse;
1.270 + TBool* isFbsBitGcPtr=&isFbsBitGc;
1.271 +
1.272 + //Have a non const this since want the published API to be const
1.273 + CGraphicsContext *nonConstThis = const_cast<CGraphicsContext*>(this);
1.274 +
1.275 + //The API extension function is non-const, and this is const function
1.276 + TInt err= nonConstThis->APIExtension(KUidIsFbsBitmapGc, (TAny*&)isFbsBitGcPtr, NULL);
1.277 +
1.278 + //on error, return EFalse
1.279 + return (!err ? isFbsBitGc : EFalse);
1.280 + }
1.281 +
1.282 +EXPORT_C void CGraphicsContext::DrawText(const TDesC& aText,const TTextParameters* iParam,const TPoint& aPosition)
1.283 + {
1.284 + TInt *dummy = NULL;
1.285 +
1.286 + TDrawTextInContextInternal context;
1.287 + TDrawTextInContextInternal* contextPtr = &context;
1.288 + contextPtr->iText.Set(aText);
1.289 + contextPtr->iPosition.SetXY(0,0);
1.290 + contextPtr->iPosition += aPosition;
1.291 + contextPtr->iParam.iStart = iParam->iStart;
1.292 + contextPtr->iParam.iEnd = iParam->iEnd;
1.293 + if (KErrNotSupported == APIExtension(KDrawTextInContextUid, (TAny*&)dummy, (TAny*)contextPtr))
1.294 + {
1.295 + DrawText(aText,aPosition);
1.296 + }
1.297 + }
1.298 +
1.299 +EXPORT_C void CGraphicsContext::DrawText(const TDesC& aText,const TTextParameters* iParam,const TRect& aBox,TInt aBaselineOffset,TTextAlign aHrz,TInt aMargin)
1.300 + {
1.301 + TInt *dummy = NULL;
1.302 +
1.303 + TDrawTextInContextInternal context;
1.304 + TDrawTextInContextInternal* contextPtr = &context;
1.305 + contextPtr->iText.Set(aText);
1.306 + contextPtr->iBox.SetRect(aBox.iTl, aBox.iBr);
1.307 + contextPtr->iBaselineOffset = aBaselineOffset;
1.308 + contextPtr->iAlign = aHrz;
1.309 + contextPtr->iMargin = aMargin;
1.310 + contextPtr->iParam.iStart = iParam->iStart;
1.311 + contextPtr->iParam.iEnd = iParam->iEnd;
1.312 + if (KErrNotSupported == APIExtension(KDrawBoxTextInContextUid, (TAny*&)dummy, (TAny*)contextPtr))
1.313 + {
1.314 + DrawText(aText,aBox,aBaselineOffset,aHrz,aMargin);
1.315 + }
1.316 + }
1.317 +
1.318 +EXPORT_C void CGraphicsContext::DrawText(const TDesC& aText,const TTextParameters* iParam,const TPoint& aPosition,const TDrawTextParam& /*aParam*/)
1.319 + {
1.320 + TInt *dummy = NULL;
1.321 +
1.322 + TDrawTextInContextInternal context;
1.323 + TDrawTextInContextInternal* contextPtr = &context;
1.324 + contextPtr->iText.Set(aText);
1.325 + contextPtr->iPosition.SetXY(0,0);
1.326 + contextPtr->iPosition += aPosition;
1.327 + contextPtr->iParam.iStart = iParam->iStart;
1.328 + contextPtr->iParam.iEnd = iParam->iEnd;
1.329 + if (KErrNotSupported == APIExtension(KDrawTextInContextUid, (TAny*&)dummy, (TAny*)contextPtr))
1.330 + {
1.331 + DrawText(aText,aPosition);
1.332 + }
1.333 + }
1.334 +
1.335 +EXPORT_C void CGraphicsContext::DrawTextVertical(const TDesC& aText,const TTextParameters* iParam,const TPoint& aPos,TBool aUp)
1.336 + {
1.337 + TInt *dummy = NULL;
1.338 +
1.339 + TDrawTextInContextInternal context;
1.340 + TDrawTextInContextInternal* contextPtr = &context;
1.341 + contextPtr->iText.Set(aText);
1.342 + contextPtr->iPosition.SetXY(0,0);
1.343 + contextPtr->iPosition += aPos;
1.344 + contextPtr->iUp = aUp;
1.345 + contextPtr->iParam.iStart = iParam->iStart;
1.346 + contextPtr->iParam.iEnd = iParam->iEnd;
1.347 + if (KErrNotSupported == APIExtension(KDrawTextInContextVerticalUid, (TAny*&)dummy, (TAny*)contextPtr))
1.348 + {
1.349 + DrawTextVertical(aText,aPos,aUp);
1.350 + }
1.351 + }
1.352 +
1.353 +EXPORT_C void CGraphicsContext::DrawTextVertical(const TDesC& aText,const TTextParameters* iParam,const TRect& aBox,TInt aBaselineOffset,TBool aUp,TTextAlign aVert,TInt aMargin)
1.354 + {
1.355 + TInt *dummy = NULL;
1.356 +
1.357 + TDrawTextInContextInternal context;
1.358 + TDrawTextInContextInternal* contextPtr = &context;
1.359 + contextPtr->iText.Set(aText);
1.360 + contextPtr->iBox.SetRect(aBox.iTl, aBox.iBr);
1.361 + contextPtr->iBaselineOffset = aBaselineOffset;
1.362 + contextPtr->iAlign = aVert;
1.363 + contextPtr->iMargin = aMargin;
1.364 + contextPtr->iUp = aUp;
1.365 + contextPtr->iParam.iStart = iParam->iStart;
1.366 + contextPtr->iParam.iEnd = iParam->iEnd;
1.367 + if (KErrNotSupported == APIExtension(KDrawBoxTextInContextVerticalUid, (TAny*&)dummy, (TAny*)contextPtr))
1.368 + {
1.369 + DrawTextVertical(aText,aBox,aBaselineOffset,aUp,aVert,aMargin);
1.370 + }
1.371 + }
1.372 +
1.373 +EXPORT_C TInt CGraphicsContext::DrawTextExtended(const TDesC& aText,const TTextParameters* aTextParam,const TPoint& aPosition,
1.374 + const TDrawTextExtendedParam& aParam)
1.375 +/** Draws text, optionally changing its direction (right-to-left / left-to-right).
1.376 +
1.377 +Apart from reordering the text, the function is the same as the two parameter
1.378 +variant of DrawText(), described above.
1.379 +
1.380 +@param aText The text string to be drawn, optionally changing its direction
1.381 +(right-to-left / left-to-right).
1.382 +@param aPosition A point specifying the position of the left end of the text.
1.383 +@param aParam Indicates whether the text should be drawn from right-to-left
1.384 +(for scripts like Arabic and Hebrew) or left-to-right.
1.385 +@return KErrNoMemory indicates there was an OOM error when reordering the text;
1.386 +KErrNone if the reordering was successful. */
1.387 + {
1.388 + // Reorder the text bidirectionally.
1.389 + TText* reordered_text = NULL;
1.390 + int error = TBidirectionalState::ReorderText(aText.Ptr(),aText.Length(),aParam.iParRightToLeft,reordered_text);
1.391 + TPtrC p(reordered_text,aText.Length());
1.392 + DrawText(p,aTextParam,aPosition,aParam);
1.393 + if (reordered_text != aText.Ptr())
1.394 + delete [] reordered_text;
1.395 + return error;
1.396 + }
1.397 +EXPORT_C void CGraphicsContext::Reserved()
1.398 +/**Reserved function for future use. */
1.399 + {
1.400 + }
1.401 +
1.402 +/**
1.403 +An API extension for CGraphics context replacing a reserved virtual method.
1.404 +Effectively allows multiple methods to use just one ordinal number.
1.405 +
1.406 +@param TUid aUid A unique identifier for the internal method required
1.407 +@param TAny*& aOutput The output parameter
1.408 +@param TAny* aInput The input argument. Notably not const.
1.409 +@return KErrNone If a successful derived function is found, if the
1.410 +default is used then KErrNotSupported is returned.
1.411 +*/
1.412 +EXPORT_C TInt CGraphicsContext::APIExtension(TUid /*aUid*/, TAny*& /*aOutput*/, TAny* /*aInput*/)
1.413 + {
1.414 + return KErrNotSupported;
1.415 + }
1.416 +
1.417 +//Default implementation of reserved virtual
1.418 +EXPORT_C void CGraphicsContext::Reserved_CGraphicsContext_2()
1.419 + {
1.420 + }
1.421 +
1.422 +EXPORT_C TInt CBitmapContext::APIExtension(TUid aUid, TAny*& aOutput, TAny* aInput)
1.423 + {
1.424 + return CGraphicsContext::APIExtension(aUid, aOutput, aInput);
1.425 + }
1.426 +
1.427 +//Default implementation of reserved virtual
1.428 +EXPORT_C void CBitmapContext::Reserved_CGraphicsContext_2()
1.429 + {
1.430 + CGraphicsContext::Reserved_CGraphicsContext_2();
1.431 + }
1.432 +
1.433 +//Default implementation of reserved virtual
1.434 +EXPORT_C void CBitmapContext::Reserved_CBitmapContext_1()
1.435 + {
1.436 + }
1.437 +
1.438 +//Default implementation of reserved virtual
1.439 +EXPORT_C void CBitmapContext::Reserved_CBitmapContext_2()
1.440 + {
1.441 + }
1.442 +
1.443 +//Default implementation of reserved virtual
1.444 +EXPORT_C void CBitmapContext::Reserved_CBitmapContext_3()
1.445 + {
1.446 + }
1.447 +