sl@0
|
1 |
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <gdi.h>
|
sl@0
|
17 |
#include "GDIPANIC.h"
|
sl@0
|
18 |
|
sl@0
|
19 |
_LIT(KGdiTZoomFactorPanicCategory,"TZoomFactor");
|
sl@0
|
20 |
|
sl@0
|
21 |
//
|
sl@0
|
22 |
// TZoomFactor
|
sl@0
|
23 |
//
|
sl@0
|
24 |
|
sl@0
|
25 |
|
sl@0
|
26 |
EXPORT_C TZoomFactor::TZoomFactor():
|
sl@0
|
27 |
iZoomFactor(EZoomOneToOne),
|
sl@0
|
28 |
iDevice(NULL)
|
sl@0
|
29 |
/** Constructs a default zoom factor object.
|
sl@0
|
30 |
|
sl@0
|
31 |
Note that a TZoomFactor object cannot be used until a CGraphicsDevice to which
|
sl@0
|
32 |
it is associated is specified (by SetGraphicsDeviceMap()). Therefore the other
|
sl@0
|
33 |
constructor is normally used for constructing TZoomFactors. The default constructor
|
sl@0
|
34 |
function is provided for use in TZoomFactor-derived classes. */
|
sl@0
|
35 |
{}
|
sl@0
|
36 |
|
sl@0
|
37 |
|
sl@0
|
38 |
EXPORT_C TZoomFactor::~TZoomFactor()
|
sl@0
|
39 |
/** Destructor.
|
sl@0
|
40 |
|
sl@0
|
41 |
Frees resources owned by the object, prior to its destruction. */
|
sl@0
|
42 |
{}
|
sl@0
|
43 |
|
sl@0
|
44 |
|
sl@0
|
45 |
EXPORT_C TInt TZoomFactor::ZoomFactor() const
|
sl@0
|
46 |
/** Gets the zoom factor.
|
sl@0
|
47 |
|
sl@0
|
48 |
@return The zoom factor */
|
sl@0
|
49 |
{
|
sl@0
|
50 |
return iZoomFactor;
|
sl@0
|
51 |
}
|
sl@0
|
52 |
|
sl@0
|
53 |
|
sl@0
|
54 |
EXPORT_C void TZoomFactor::SetZoomFactor(TInt aZoomFactor)
|
sl@0
|
55 |
/** Sets the zoom factor.
|
sl@0
|
56 |
|
sl@0
|
57 |
@param aZoomFactor The desired zoom factor. */
|
sl@0
|
58 |
{
|
sl@0
|
59 |
iZoomFactor=aZoomFactor;
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
|
sl@0
|
63 |
EXPORT_C void TZoomFactor::SetTwipToPixelMapping(const TSize& aSizeInPixels,const TSize& aSizeInTwips)
|
sl@0
|
64 |
// Ensure that aSizeInTwips fits inside aSizeInPixels when zoomed
|
sl@0
|
65 |
/** Sets the twips to pixels mapping for the graphics device with which the zoom
|
sl@0
|
66 |
factor is associated.
|
sl@0
|
67 |
|
sl@0
|
68 |
This setting is used by all the twips to pixels and pixels to twips conversion
|
sl@0
|
69 |
functions.
|
sl@0
|
70 |
|
sl@0
|
71 |
@param aSizeInPixels The size of the graphics device area in pixels.
|
sl@0
|
72 |
@param aSizeInTwips The size of the graphics device area in twips. */
|
sl@0
|
73 |
{
|
sl@0
|
74 |
GDI_ASSERT_ALWAYS_GENERAL(iDevice!=NULL,User::Panic(KGdiTZoomFactorPanicCategory,KErrNotFound));
|
sl@0
|
75 |
TInt devicepixelwidth=iDevice->HorizontalTwipsToPixels(aSizeInTwips.iWidth);
|
sl@0
|
76 |
TInt devicepixelheight=iDevice->VerticalTwipsToPixels(aSizeInTwips.iHeight);
|
sl@0
|
77 |
if(devicepixelwidth==0 || devicepixelheight==0)
|
sl@0
|
78 |
{
|
sl@0
|
79 |
iZoomFactor=0;
|
sl@0
|
80 |
return;
|
sl@0
|
81 |
}
|
sl@0
|
82 |
iZoomFactor = (1000*aSizeInPixels.iWidth+(devicepixelwidth/2))/devicepixelwidth;
|
sl@0
|
83 |
TInt temp = (1000*aSizeInPixels.iHeight+(devicepixelheight/2))/devicepixelheight;
|
sl@0
|
84 |
if (temp<iZoomFactor)
|
sl@0
|
85 |
iZoomFactor = temp;
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
EXPORT_C TInt TZoomFactor::HorizontalTwipsToPixels(TInt aTwipWidth) const
|
sl@0
|
89 |
/** Converts a horizontal dimension from twips to pixels on the graphics
|
sl@0
|
90 |
device.
|
sl@0
|
91 |
|
sl@0
|
92 |
This function implements the pure virtual function defined in
|
sl@0
|
93 |
MGraphicsDeviceMap::HorizontalTwipsToPixels() */
|
sl@0
|
94 |
{
|
sl@0
|
95 |
// iZoomFactor expressed in units of a thousandth
|
sl@0
|
96 |
// delegated conversion is done 8 times multiplied for 3 guard bits
|
sl@0
|
97 |
// hence result divided by 8
|
sl@0
|
98 |
GDI_ASSERT_ALWAYS_GENERAL(iDevice!=NULL,User::Panic(KGdiTZoomFactorPanicCategory,KErrNotFound));
|
sl@0
|
99 |
return (iDevice->HorizontalTwipsToPixels(((aTwipWidth*iZoomFactor)/125))+((aTwipWidth<0)?-4:4))/8;
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
|
sl@0
|
103 |
EXPORT_C TInt TZoomFactor::VerticalTwipsToPixels(TInt aTwipHeight) const
|
sl@0
|
104 |
/** Converts a vertical dimension from twips to pixels on the graphics
|
sl@0
|
105 |
device.
|
sl@0
|
106 |
|
sl@0
|
107 |
This function implements the pure virtual function defined in
|
sl@0
|
108 |
MGraphicsDeviceMap::VerticalTwipsToPixels() */
|
sl@0
|
109 |
{
|
sl@0
|
110 |
GDI_ASSERT_ALWAYS_GENERAL(iDevice!=NULL,User::Panic(KGdiTZoomFactorPanicCategory,KErrNotFound));
|
sl@0
|
111 |
return (iDevice->VerticalTwipsToPixels(((aTwipHeight*iZoomFactor)/125))+((aTwipHeight<0)?-4:4))/8;
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
|
sl@0
|
115 |
EXPORT_C TInt TZoomFactor::HorizontalPixelsToTwips(TInt aPixelWidth) const
|
sl@0
|
116 |
/** Converts a horizontal dimension from pixels to twips on the graphics
|
sl@0
|
117 |
device.
|
sl@0
|
118 |
|
sl@0
|
119 |
This function implements the pure virtual function defined in
|
sl@0
|
120 |
MGraphicsDeviceMap::HorizontalPixelsToTwips() */
|
sl@0
|
121 |
{
|
sl@0
|
122 |
GDI_ASSERT_ALWAYS_GENERAL(iDevice!=NULL,User::Panic(KGdiTZoomFactorPanicCategory,KErrNotFound));
|
sl@0
|
123 |
TInt temp = iDevice->HorizontalPixelsToTwips(aPixelWidth*8)*1000;
|
sl@0
|
124 |
temp+=(temp<0)?-(iZoomFactor*4):iZoomFactor*4;
|
sl@0
|
125 |
TInt eightTimesZoom=iZoomFactor*8;
|
sl@0
|
126 |
if(eightTimesZoom)
|
sl@0
|
127 |
return temp/eightTimesZoom;
|
sl@0
|
128 |
return(0);
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
EXPORT_C TInt TZoomFactor::VerticalPixelsToTwips(TInt aPixelHeight) const
|
sl@0
|
132 |
/** Converts a vertical dimension from pixels to twips on the graphics
|
sl@0
|
133 |
device.
|
sl@0
|
134 |
|
sl@0
|
135 |
This function implements the pure virtual function defined in
|
sl@0
|
136 |
MGraphicsDeviceMap::VerticalPixelsToTwips() */
|
sl@0
|
137 |
{
|
sl@0
|
138 |
GDI_ASSERT_ALWAYS_GENERAL(iDevice!=NULL,User::Panic(KGdiTZoomFactorPanicCategory,KErrNotFound));
|
sl@0
|
139 |
TInt temp = iDevice->VerticalPixelsToTwips(aPixelHeight*8)*1000;
|
sl@0
|
140 |
temp+=(temp<0)?-(iZoomFactor*4):iZoomFactor*4;
|
sl@0
|
141 |
TInt eightTimesZoom=iZoomFactor*8;
|
sl@0
|
142 |
if(eightTimesZoom)
|
sl@0
|
143 |
return temp/eightTimesZoom;
|
sl@0
|
144 |
return(0);
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
/**
|
sl@0
|
148 |
@publishedAll
|
sl@0
|
149 |
*/
|
sl@0
|
150 |
EXPORT_C TInt TZoomFactor::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
/**
|
sl@0
|
156 |
Gets the font which is the nearest to the given font specification.
|
sl@0
|
157 |
Matching to design height gives no guarantees on the actual physical size of the font.
|
sl@0
|
158 |
|
sl@0
|
159 |
@param aFont On return, contains a pointer to the nearest font.
|
sl@0
|
160 |
@param aFontSpec The specification of the font to be matched.
|
sl@0
|
161 |
@return KErrNone if successful; a system-wide error code otherwise.
|
sl@0
|
162 |
@publishedAll
|
sl@0
|
163 |
@released
|
sl@0
|
164 |
*/
|
sl@0
|
165 |
EXPORT_C TInt TZoomFactor::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
GDI_ASSERT_ALWAYS_GENERAL(iDevice, User::Panic(KGdiTZoomFactorPanicCategory, KErrNotFound));
|
sl@0
|
168 |
TFontSpec fontSpec = aFontSpec;
|
sl@0
|
169 |
fontSpec.iHeight = (fontSpec.iHeight * iZoomFactor + EZoomOneToOne / 2) / EZoomOneToOne;
|
sl@0
|
170 |
return (const_cast<MGraphicsDeviceMap*>(iDevice))->GetNearestFontToDesignHeightInTwips(aFont, fontSpec);
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
/**
|
sl@0
|
174 |
Gets the font which is the nearest to the given font specification.
|
sl@0
|
175 |
Matching to maximum height returns a font that will fit within the height specified.
|
sl@0
|
176 |
|
sl@0
|
177 |
@param aFont On return, contains a pointer to the nearest font.
|
sl@0
|
178 |
@param aFontSpec The specification of the font to be matched.
|
sl@0
|
179 |
@param aMaxHeight The maximum height within which the font must fit.
|
sl@0
|
180 |
This overrides the height specified in aFontSpec. If maximum height
|
sl@0
|
181 |
is greater than 1024 pixels, the function returns KErrTooBig. And
|
sl@0
|
182 |
returns KErrArgument if equals to 1 pixel.
|
sl@0
|
183 |
@return KErrNone if successful; a system-wide error code otherwise.
|
sl@0
|
184 |
@publishedAll
|
sl@0
|
185 |
@released
|
sl@0
|
186 |
*/
|
sl@0
|
187 |
EXPORT_C TInt TZoomFactor::GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight)
|
sl@0
|
188 |
{
|
sl@0
|
189 |
GDI_ASSERT_ALWAYS_GENERAL(iDevice, User::Panic(KGdiTZoomFactorPanicCategory, KErrNotFound));
|
sl@0
|
190 |
TFontSpec fontSpec = aFontSpec;
|
sl@0
|
191 |
fontSpec.iHeight = (fontSpec.iHeight * iZoomFactor + EZoomOneToOne / 2) / EZoomOneToOne;
|
sl@0
|
192 |
aMaxHeight = (aMaxHeight * iZoomFactor + EZoomOneToOne / 2) / EZoomOneToOne;
|
sl@0
|
193 |
return (const_cast<MGraphicsDeviceMap*>(iDevice))->GetNearestFontToMaxHeightInTwips(aFont, fontSpec, aMaxHeight);
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
/** Releases the specified font.
|
sl@0
|
197 |
|
sl@0
|
198 |
This function implements the pure virtual function defined in
|
sl@0
|
199 |
MGraphicsDeviceMap::ReleaseFont()
|
sl@0
|
200 |
@param aFont A pointer to the font to be released. */
|
sl@0
|
201 |
EXPORT_C void TZoomFactor::ReleaseFont(CFont* aFont)
|
sl@0
|
202 |
{
|
sl@0
|
203 |
GDI_ASSERT_ALWAYS_GENERAL(iDevice != NULL, User::Panic(KGdiTZoomFactorPanicCategory, KErrNotFound));
|
sl@0
|
204 |
((MGraphicsDeviceMap*)iDevice)->ReleaseFont(aFont);
|
sl@0
|
205 |
}
|