sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include "GDIPANIC.h" sl@0: sl@0: _LIT(KGdiTZoomFactorPanicCategory,"TZoomFactor"); sl@0: sl@0: // sl@0: // TZoomFactor sl@0: // sl@0: sl@0: sl@0: EXPORT_C TZoomFactor::TZoomFactor(): sl@0: iZoomFactor(EZoomOneToOne), sl@0: iDevice(NULL) sl@0: /** Constructs a default zoom factor object. sl@0: sl@0: Note that a TZoomFactor object cannot be used until a CGraphicsDevice to which sl@0: it is associated is specified (by SetGraphicsDeviceMap()). Therefore the other sl@0: constructor is normally used for constructing TZoomFactors. The default constructor sl@0: function is provided for use in TZoomFactor-derived classes. */ sl@0: {} sl@0: sl@0: sl@0: EXPORT_C TZoomFactor::~TZoomFactor() sl@0: /** Destructor. sl@0: sl@0: Frees resources owned by the object, prior to its destruction. */ sl@0: {} sl@0: sl@0: sl@0: EXPORT_C TInt TZoomFactor::ZoomFactor() const sl@0: /** Gets the zoom factor. sl@0: sl@0: @return The zoom factor */ sl@0: { sl@0: return iZoomFactor; sl@0: } sl@0: sl@0: sl@0: EXPORT_C void TZoomFactor::SetZoomFactor(TInt aZoomFactor) sl@0: /** Sets the zoom factor. sl@0: sl@0: @param aZoomFactor The desired zoom factor. */ sl@0: { sl@0: iZoomFactor=aZoomFactor; sl@0: } sl@0: sl@0: sl@0: EXPORT_C void TZoomFactor::SetTwipToPixelMapping(const TSize& aSizeInPixels,const TSize& aSizeInTwips) sl@0: // Ensure that aSizeInTwips fits inside aSizeInPixels when zoomed sl@0: /** Sets the twips to pixels mapping for the graphics device with which the zoom sl@0: factor is associated. sl@0: sl@0: This setting is used by all the twips to pixels and pixels to twips conversion sl@0: functions. sl@0: sl@0: @param aSizeInPixels The size of the graphics device area in pixels. sl@0: @param aSizeInTwips The size of the graphics device area in twips. */ sl@0: { sl@0: GDI_ASSERT_ALWAYS_GENERAL(iDevice!=NULL,User::Panic(KGdiTZoomFactorPanicCategory,KErrNotFound)); sl@0: TInt devicepixelwidth=iDevice->HorizontalTwipsToPixels(aSizeInTwips.iWidth); sl@0: TInt devicepixelheight=iDevice->VerticalTwipsToPixels(aSizeInTwips.iHeight); sl@0: if(devicepixelwidth==0 || devicepixelheight==0) sl@0: { sl@0: iZoomFactor=0; sl@0: return; sl@0: } sl@0: iZoomFactor = (1000*aSizeInPixels.iWidth+(devicepixelwidth/2))/devicepixelwidth; sl@0: TInt temp = (1000*aSizeInPixels.iHeight+(devicepixelheight/2))/devicepixelheight; sl@0: if (tempHorizontalTwipsToPixels(((aTwipWidth*iZoomFactor)/125))+((aTwipWidth<0)?-4:4))/8; sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt TZoomFactor::VerticalTwipsToPixels(TInt aTwipHeight) const sl@0: /** Converts a vertical dimension from twips to pixels on the graphics sl@0: device. sl@0: sl@0: This function implements the pure virtual function defined in sl@0: MGraphicsDeviceMap::VerticalTwipsToPixels() */ sl@0: { sl@0: GDI_ASSERT_ALWAYS_GENERAL(iDevice!=NULL,User::Panic(KGdiTZoomFactorPanicCategory,KErrNotFound)); sl@0: return (iDevice->VerticalTwipsToPixels(((aTwipHeight*iZoomFactor)/125))+((aTwipHeight<0)?-4:4))/8; sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt TZoomFactor::HorizontalPixelsToTwips(TInt aPixelWidth) const sl@0: /** Converts a horizontal dimension from pixels to twips on the graphics sl@0: device. sl@0: sl@0: This function implements the pure virtual function defined in sl@0: MGraphicsDeviceMap::HorizontalPixelsToTwips() */ sl@0: { sl@0: GDI_ASSERT_ALWAYS_GENERAL(iDevice!=NULL,User::Panic(KGdiTZoomFactorPanicCategory,KErrNotFound)); sl@0: TInt temp = iDevice->HorizontalPixelsToTwips(aPixelWidth*8)*1000; sl@0: temp+=(temp<0)?-(iZoomFactor*4):iZoomFactor*4; sl@0: TInt eightTimesZoom=iZoomFactor*8; sl@0: if(eightTimesZoom) sl@0: return temp/eightTimesZoom; sl@0: return(0); sl@0: } sl@0: sl@0: EXPORT_C TInt TZoomFactor::VerticalPixelsToTwips(TInt aPixelHeight) const sl@0: /** Converts a vertical dimension from pixels to twips on the graphics sl@0: device. sl@0: sl@0: This function implements the pure virtual function defined in sl@0: MGraphicsDeviceMap::VerticalPixelsToTwips() */ sl@0: { sl@0: GDI_ASSERT_ALWAYS_GENERAL(iDevice!=NULL,User::Panic(KGdiTZoomFactorPanicCategory,KErrNotFound)); sl@0: TInt temp = iDevice->VerticalPixelsToTwips(aPixelHeight*8)*1000; sl@0: temp+=(temp<0)?-(iZoomFactor*4):iZoomFactor*4; sl@0: TInt eightTimesZoom=iZoomFactor*8; sl@0: if(eightTimesZoom) sl@0: return temp/eightTimesZoom; sl@0: return(0); sl@0: } sl@0: sl@0: /** sl@0: @publishedAll sl@0: */ sl@0: EXPORT_C TInt TZoomFactor::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec); sl@0: } sl@0: sl@0: /** sl@0: Gets the font which is the nearest to the given font specification. sl@0: Matching to design height gives no guarantees on the actual physical size of the font. sl@0: sl@0: @param aFont On return, contains a pointer to the nearest font. sl@0: @param aFontSpec The specification of the font to be matched. sl@0: @return KErrNone if successful; a system-wide error code otherwise. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt TZoomFactor::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: GDI_ASSERT_ALWAYS_GENERAL(iDevice, User::Panic(KGdiTZoomFactorPanicCategory, KErrNotFound)); sl@0: TFontSpec fontSpec = aFontSpec; sl@0: fontSpec.iHeight = (fontSpec.iHeight * iZoomFactor + EZoomOneToOne / 2) / EZoomOneToOne; sl@0: return (const_cast(iDevice))->GetNearestFontToDesignHeightInTwips(aFont, fontSpec); sl@0: } sl@0: sl@0: /** sl@0: Gets the font which is the nearest to the given font specification. sl@0: Matching to maximum height returns a font that will fit within the height specified. sl@0: sl@0: @param aFont On return, contains a pointer to the nearest font. sl@0: @param aFontSpec The specification of the font to be matched. sl@0: @param aMaxHeight The maximum height within which the font must fit. sl@0: This overrides the height specified in aFontSpec. If maximum height sl@0: is greater than 1024 pixels, the function returns KErrTooBig. And sl@0: returns KErrArgument if equals to 1 pixel. sl@0: @return KErrNone if successful; a system-wide error code otherwise. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt TZoomFactor::GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight) sl@0: { sl@0: GDI_ASSERT_ALWAYS_GENERAL(iDevice, User::Panic(KGdiTZoomFactorPanicCategory, KErrNotFound)); sl@0: TFontSpec fontSpec = aFontSpec; sl@0: fontSpec.iHeight = (fontSpec.iHeight * iZoomFactor + EZoomOneToOne / 2) / EZoomOneToOne; sl@0: aMaxHeight = (aMaxHeight * iZoomFactor + EZoomOneToOne / 2) / EZoomOneToOne; sl@0: return (const_cast(iDevice))->GetNearestFontToMaxHeightInTwips(aFont, fontSpec, aMaxHeight); sl@0: } sl@0: sl@0: /** Releases the specified font. sl@0: sl@0: This function implements the pure virtual function defined in sl@0: MGraphicsDeviceMap::ReleaseFont() sl@0: @param aFont A pointer to the font to be released. */ sl@0: EXPORT_C void TZoomFactor::ReleaseFont(CFont* aFont) sl@0: { sl@0: GDI_ASSERT_ALWAYS_GENERAL(iDevice != NULL, User::Panic(KGdiTZoomFactorPanicCategory, KErrNotFound)); sl@0: ((MGraphicsDeviceMap*)iDevice)->ReleaseFont(aFont); sl@0: }