Conversions between twips, pixels, and millimeters using Symbian C++
Article Metadata
Tested with
Devices(s): S60 (All)
Compatibility
Platform(s): S60
Article
Keywords: TwipsToPixels, PixelsToTwips
Created: User:Technical writer 1
(10 Mar 2009)
Last edited: hamishwillee
(16 Aug 2012)
Overview
The screen device in Symbian OS provides helper functions to convert a number of pixels to how much physical screen area they occupy (in twips, 1/1440 inches), and vice versa.
Detailed description
Information about how many pixels are required to draw a shape of a certain size in each device is especially useful in touch-enabled UIs, where icons and controls need to have a proper size for use with fingers.
Solution
The following methods convert between pixels and millimeters.
#define KTwipInMillimeters 0.0176389
// Returns the number of pixels corresponding
// to millimeters (x,y) passed as parameter
TPoint MillimetersToPixels( const TPoint& aMm ) const
{
TReal twipsX = (TReal)aMm.iX / KTwipInMillimeters;
TReal twipsY = (TReal)aMm.iY / KTwipInMillimeters;
return iEikonEnv->ScreenDevice()->TwipsToPixels( TPoint((TInt)twipsX,
(TInt)twipsY) );
}
// Returns the number of millimeters corresponding
// to pixels (x,y) passed as parameter
TPoint PixelsToMillimeters( const TPoint& aPixels ) const
{
TPoint twips = iEikonEnv->ScreenDevice()->PixelsToTwips(aPixels);
TReal mmX = (TReal)twips.iX * KTwipInMillimeters;
TReal mmY = (TReal)twips.iY * KTwipInMillimeters;
return TPoint((TInt)mmX, (TInt)mmY);
}
Note that all currently available devices have square pixel aspect ratio.


(no comments yet)