Update contrib.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 /** Constructs a TRgb initialised to KRgbWhite.*/
25 inline TRgb::TRgb(TUint32 aValue):
26 iValue(((aValue & 0xff0000) >> 16) | (aValue & 0x00ff00) | ((aValue & 0x0000ff) << 16) | (0xff000000 - (aValue & 0xff000000)))
27 /** Constructs a TRgb directly from a single 32-bit integer.
29 The integer is of the form 0xaabbggrr, where bb is the hex number for blue,
30 gg is the hex number for green, rr is the hex number for red, and aa is the hex number for
31 "transparency" alpha (0 means opaque, 255 means transparent).
33 This constructor is deprecated. The byte order of Red ,Green and Blue
34 does not match other constructors and methods in this class,
35 and the meaning of alpha is reversed compared to current convention.
37 For example, TRgb(0x00080402) using this constructor
38 can be replaced with the 3 colour constructor TRgb(2,4,8).
39 The equivalent explicit alpha constructors are TRgb(0x020408,0xff) and TRgb(2,4,8,255).
40 The equivalent call to SetInternal is SetInternal(0xff020408).
42 This constructor is deprecated. Use other constructors or SetInternal() instead.
44 @param aValue Integer representing colour value. Takes form 0x00bbggrr.
48 inline TRgb::TRgb(TUint32 aInternalValue, TInt aAlpha) :
49 iValue((aInternalValue & 0x00ffffff) | (aAlpha << 24))
50 /** Constructs a TRgb from a 32-bit integer (which corresponds to a colour) and from an alpha value.
52 The first parameter is of the form 0x00rrggbb, where rr is the hex number for red,
53 gg is the hex number for green, and bb is the hex number for blue.
55 The second parameter corresponds to an alpha channel (0 means transparent, 255 means opaque).
57 For example, TRgb(2,4,8,255) using the 3 colour+alpha constructor is equal to TRgb(0x00020408, 255) using
60 This constructor, which implements alpha in the conventional way,
61 replaces TRgb( TUint32 aValue ) which is deprecated.
63 @param aInternalValue Integer representing a colour value, which takes the form 0x00rrggbb.
64 @param aAlpha Alpha component of the colour (0 - 255).*/
68 inline TRgb::TRgb(TInt aRed,TInt aGreen,TInt aBlue):
69 iValue(aRed<<16|aGreen<<8|aBlue|0xff000000)
70 /** Constructs a TRgb from its three component colours.
72 Each colour has a value between 0 and 255.
73 The alpha component is always set to opaque (255)
75 @param aRed Red component of the colour (0 - 255).
76 @param aGreen Green component of the colour (0 - 255).
77 @param aBlue Blue component of the colour (0 - 255). */
80 /** Constructs a TRgb from its three colour components and alpha component.
82 Each component has a value between 0 and 255.
83 The fourth parameter corresponds to an alpha channel (0 means transparent, 255 means opaque).
85 This constructor, which implements alpha in the conventional way,
86 replaces TRgb( TUint32 aValue ) which is deprecated.
88 @param aRed Red component of the colour (0 - 255).
89 @param aGreen Green component of the colour (0 - 255).
90 @param aBlue Blue component of the colour (0 - 255).
91 @param aAlpha Alpha component of the colour (0 - 255).*/
92 inline TRgb::TRgb(TInt aRed,TInt aGreen,TInt aBlue, TInt aAlpha):
93 iValue(aRed<<16|aGreen<<8|aBlue|aAlpha<<24)
97 inline TInt TRgb::Red() const
98 /** Gets the red component.
100 @return The red component (0 - 255). */
101 {return((iValue&0xff0000)>>16);}
104 inline TInt TRgb::Green() const
105 /** Gets the green component.
107 @return The green component (0 - 255). */
108 {return((iValue&0xff00)>>8);}
111 inline TInt TRgb::Blue() const
112 /** Gets the blue component.
114 @return The blue component (0 - 255). */
115 {return(iValue&0xff);}
118 inline TBool TRgb::operator==(const TRgb& aColor) const
119 /** Compares this colour with the specified colour for equality.
121 For two colours to be equal, their red, green and blue components must all
124 @param aColor Colour to be compared.
125 @return ETrue. if the colours are equal; EFalse, otherwise. */
127 {return(iValue==aColor.iValue);}
130 inline TBool TRgb::operator!=(const TRgb& aColor) const
131 /** Compares this colour with the specified colour for inequality.
133 Two colours are unequal if one at least one of their red, green and blue components
136 @param aColor Colour to be compared.
137 @return ETrue, if the colours are not equal; EFalse, otherwise.
139 {return(!(*this==aColor));}
141 inline TRgb& TRgb::operator&=(const TRgb& aColor)
142 /** Logical AND assignment operator.
144 The operator ANDs the first operand with the second and then assigns the result
145 back to the first operand.
149 This operates in the TRgb domain. Graphics defines logical operations for
150 drawing primitives which operate in the device colour domain.
152 @param aColor Colour to be compared.
153 @return First operand-contains result of logical AND. */
154 {iValue&=aColor.iValue;return(*this);}
156 inline TRgb& TRgb::operator|=(const TRgb& aColor)
157 /** Logical OR assignment operator.
159 The operator ORs the first operand with the second and then assigns the result
160 back to the first operand.
164 This operates in the TRgb domain. Graphics defines logical operations for
165 drawing primitives which operate in the device colour domain.
167 @param aColor Colour to be compared.
168 @return First operand- contains result of logical OR. */
169 {iValue|=aColor.iValue;return(*this);}
172 inline TRgb& TRgb::operator^=(const TRgb& aColor)
173 /** Logical EXCLUSIVE OR assignment operator.
175 The operator Exclusive ORs the first operand with the second and then assigns
176 the result back to the first operand.
180 This operates in the TRgb domain. Graphics defines logical operations for
181 drawing primitives which operate in the device colour domain.
183 @param aColor Colour to be compared.
184 @return First operand contains result of logical Exclusive OR. */
185 {iValue^=aColor.iValue;iValue^=0xff000000; return(*this);}
188 inline TUint32 TRgb::Value() const
189 /** Gets the 32-bit value of the TRgb as an integer.
190 This function is deprecated. Use Internal() instead.
191 Note: the order of Red, Green and Blue components returned by this method
192 is reversed compared to all other methods. The alpha value is also reversed in meaning
193 compared to current convention, such that 0 represents opaque and 0xff represents transparent.
195 @return The 32 bit value of the TRgb. Has the form 0xaabbggrr, where bb is the hex number for blue,
196 gg is the hex number for green, rr is the hex number for red, and aa is the hex number for
197 "transparency" alpha (0 means opaque, 255 means transparent).
200 {return (((iValue & 0xff0000) >> 16) | (iValue & 0x00ff00) | ((iValue & 0x0000ff) << 16) | (0xff000000 - (iValue & 0xff000000)));}
202 inline TUint32 TRgb::Internal() const
203 /** Gets the 32-bit value of the TRgb as an integer.
205 @return The 32 bit value of the TRgb. Has the form 0xaarrggbb. */
208 inline void TRgb::SetInternal(TUint32 aInternal)
209 /** Sets the 32-bit value of the TRgb as a 32-bit integer.
210 @param aInternal Colour internal representation. Has the form 0xaarrggbb.
212 {iValue = aInternal;}
214 inline TRgb TRgb::operator~() const
215 /** Bitwise logical inversion operator.
217 @return Contains results of logical inversion. */
218 {TRgb rgb; rgb.SetInternal(iValue^0x00ffffff); return rgb;}
221 inline TRgb TRgb::operator&(const TRgb& aColor)
222 /** Bitwise logical AND operator.
224 @param aColor Colour to be compared.
225 @return Contains results of logical AND. */
226 {TRgb rgb; rgb.SetInternal(iValue&aColor.iValue); return rgb;}
229 inline TRgb TRgb::operator|(const TRgb& aColor)
230 /** Bitwise logical OR operator.
232 @param aColor Colour to be compared.
233 @return Contains results of logical OR. */
234 {TRgb rgb; rgb.SetInternal(iValue|aColor.iValue); return rgb;}
237 inline TRgb TRgb::operator^(const TRgb& aColor)
238 /** Bitwise EXCLUSIVE OR operator
240 @param aColor Colour to be compared.
241 @return Contains results of logical EXCLUSIVE OR. */
242 {TRgb rgb; rgb.SetInternal(iValue^aColor.iValue); return rgb;}
245 /** Gets TRgb from 2 level grayscale.
247 The function takes a grayscale argument and return a TRgb whose red, green
248 and blue values are set to an appropriate level.
250 @param aGray2 Grayscale value to be converted.
251 @return Equivalent 24 bit colour. Gray2 has only 2 levels (black and white),
252 the function returns r=g=b=0 or r=g=b=255. */
253 inline TRgb TRgb::_Gray2(TInt aGray2)
255 if(aGray2) return(TRgb(0xffffff, 0xff));
256 return(TRgb(0, 0xff));
259 /** Gets TRgb from 4 level grayscale.
261 The function takes a grayscale argument and return a TRgb whose red, green
262 and blue values are set to an appropriate level.
264 @param aGray4 Grayscale value to be converted.
265 @return Equivalent 24 bit colour. Gray4 has 4 levels- the function returns
266 r=g=b=85*c, where c=0,1,2, or 3. */
267 inline TRgb TRgb::_Gray4(TInt aGray4)
272 return(TRgb(aGray4,aGray4,aGray4));
275 /** Gets TRgb from 16 level grayscale.
277 The function takes a grayscale argument and return a TRgb whose red, green
278 and blue values are set to an appropriate level.
280 @param aGray16 Grayscale value to be converted.
281 @return Equivalent 24 bit colour. Gray16 has 16 levels - the function returns
282 r=g=b=17*c, where c=0, 1, ... 15. */
283 inline TRgb TRgb::_Gray16(TInt aGray16)
287 return(TRgb(aGray16,aGray16,aGray16));
290 /** Gets TRgb from 256 level grayscale.
292 The function takes a grayscale argument and return a TRgb whose red, green
293 and blue values are set to an appropriate level.
295 @param aGray256 Grayscale value to be converted.
296 @return Equivalent 24 bit colour. Gray256 has 256 levels- the function
297 returns r=g=b=c, where c=0, 1, ... 255. */
298 inline TRgb TRgb::_Gray256(TInt aGray256)
301 return(TRgb(aGray256,aGray256,aGray256));
304 /** Gets TRgb from 4K colour index.
306 The function takes a 12 bit index into a colour palette and returns a TRgb
307 whose red, green and blue values are set to an appropriate level.
309 @param aColor4K 12 bit index into a colour palette
310 @return Equivalent 24 bit colour. */
311 inline TRgb TRgb::_Color4K(TInt aColor4K)
313 TUint32 value = (aColor4K & 0xf00) << 8;
314 value |= (aColor4K & 0x0f0) << 4;
315 value |= (aColor4K & 0x00f);
316 return TRgb(value | (value << 4), 0xff);
319 /** Gets TRgb from 64K colour index.
321 The function takes a 16 bit index into a colour palette and returns a TRgb
322 whose red, green and blue values are set to an appropriate level.
324 @param aColor64K 16 bit index into a colour palette
325 @return Equivalent 24 bit colour. */
326 inline TRgb TRgb::_Color64K(TInt aColor64K)
328 TInt red = (aColor64K&0xF800)>>8;
330 TInt green = (aColor64K&0x07E0)>>3;
332 TInt blue = (aColor64K&0x001F)<<3;
334 return TRgb(red,green,blue);
337 /** Gets TRgb from 16M colour index.
339 The function takes a 24 bit index into a colour palette and returns the TRgb
340 whose red, green and blue values represent it exactly.
342 @param a0RGB 24 bit index into a colour palette
343 @return The TRgb which represents the index exactly. */
344 inline TRgb TRgb::_Color16M(TInt a0RGB)
346 return TRgb(a0RGB, 0xff);
349 /** Gets TRgb from 16MU colour index.
350 The function takes a 24 bit colour value with eight bits for each
351 component, blue in the low byte, and returns the TRgb
352 whose red, green and blue values represent it exactly.
353 @param a0RGB The color - 0, R, G, B bytes. / BGR0 - little endian format /
354 @return The TRgb which represents the index exactly. */
355 inline TRgb TRgb::_Color16MU(TInt a0RGB)
357 return TRgb(a0RGB, 0xff);
360 /** Gets the index of the closest TRgb value to this,
361 based on the matching display mode.
363 @return The index (0 - 1) representing the nearest TRgb. */
364 inline TInt TRgb::_Gray2() const
366 return(Gray256()>>7);
369 /**Gets the index of the closest TRgb value to this,
370 based on the matching display mode.
372 @return The index (0 - 3) representing the nearest TRgb. */
373 inline TInt TRgb::_Gray4() const
375 return(Gray256()>>6);
378 /** Gets the index of the closest TRgb value to this,
379 based on the matching display mode.
381 @return The index (0 - 15) representing the nearest TRgb.*/
382 inline TInt TRgb::_Gray16() const
384 return(Gray256()>>4);
387 /** Gets the index of the closest TRgb value to this,
388 based on the matching display mode.
390 @return The index (0 - 255) representing the nearest TRgb.*/
391 inline TInt TRgb::_Gray256() const
393 return(((Red()<<1)+Green()+(Green()<<2)+Blue())>>3);
396 /** Gets the index of the closest TRgb value to this,
397 based on the matching display mode.
399 @return The index (0 - 4095) representing the nearest TRgb. */
400 inline TInt TRgb::_Color4K() const
402 TInt color4K = (iValue & 0x0000f0) >> 4;
403 color4K |= (iValue & 0x00f000) >> 8;
404 color4K |= (iValue & 0xf00000) >> 12;
408 /** Gets the index of the closest TRgb value to this,
409 based on the matching display mode.
411 @return The index (0 - 65535) representing the nearest TRgb.*/
412 inline TInt TRgb::_Color64K() const
414 TInt color64K = (iValue & 0x0000f8) >> 3;
415 color64K |= (iValue & 0x00fc00) >> 5;
416 color64K |= (iValue & 0xf80000) >> 8;
420 /** Gets the index of the closest TRgb value to this,
421 based on the matching display mode.
423 @return The index (0 - 16777215) representing the nearest TRgb.*/
424 inline TInt TRgb::_Color16M() const
426 return (iValue & 0xffffff);
430 /** Gets the index of the closest TRgb value to this, based on the matching display mode.
431 @return The index (0 - 16777215) representing the nearest TRgb. */
432 inline TInt TRgb::_Color16MU() const
434 return (iValue & 0xffffff);
439 /** Gets the alpha component.
440 @return The alpha component (0 - 255). */
441 inline TInt TRgb::Alpha() const
442 {return (iValue >> 24);}
445 /** Gets TRgb from 16MA colour index.
446 The function takes a 32 bit colour value with eight bits for each
447 component, blue in the low byte, and returns the TRgb
448 whose red, green, blue and alpha values represent it exactly.
449 @param aARGB The color - A, R, G, B bytes. / BGR0 - little endian format /
450 @return The TRgb which represents the index exactly. */
451 inline TRgb TRgb::_Color16MA(TUint aARGB)
453 TRgb col; col.SetInternal(aARGB);
457 /** Gets the index of the closest TRgb value to this, based on the matching display mode.
458 @return The index (0 - 16777215) representing the nearest TRgb. */
459 inline TUint TRgb::_Color16MA() const
469 inline TInt CPalette::Entries() const
470 /** Gets the number of entries in the palette
472 @return The number of entries in the palette. */
473 {return(iNumEntries);}
480 inline TRgb TColor256Util::Color256(TInt aColor256) const
481 /** Gets the TRgb value of the entry at the specified index in the colour lookup
484 @param aColor256 The index into the colour lookup table.
485 @return The TRgb value of the entry at the specified index. */
486 { return TRgb(iColorTable[aColor256]); }
491 inline TGlyphBitmapType TFontStyle::BitmapType() const
492 /** Gets the anti-aliasing setting for the font, as set by SetBitmapType().
494 @return Indicates whether or not this font should be drawn using anti-aliasing. */
496 return (TGlyphBitmapType)(iFlags >> 16);
500 inline void TFontStyle::SetBitmapType(TGlyphBitmapType aBitmapType)
501 /** Sets whether the font should be drawn using anti-aliasing. If set, this value
502 overrides the default setting (set by CFbsTypefaceStore::SetDefaultBitmapType())
505 Anti-aliasing can only be used for scalable fonts. There is currently no anti-aliasing
506 support for bitmapped fonts.
508 @param aBitmapType Indicates whether or not this font should be drawn using
512 iFlags |= (aBitmapType << 16);
520 inline TInt CBitmapDevice::CreateBitmapContext(CBitmapContext*& aGC)
521 /** Creates a bitmap context for this bitmap device.
523 @param aGC On return, holds a pointer to the created bitmap context.
524 @return KErrNone, if successful; otherwise, another of the system-wide error
526 {return(CreateContext((CGraphicsContext*&)aGC));} // relies on CBitmapContext deriving _only_ from CGraphicsContext
529 // TPictureCapability
532 inline TPictureCapability::TPictureCapability(TScalingType aScalingType,TBool aCroppable):
533 iScalingType(aScalingType),iIsCroppable(aCroppable)
534 /** Constructs the object setting the scaling-type and croppability properties.
536 @param aScalingType Whether or not the picture is scalable.
537 @param aCroppable Whether or not the picture is croppable. */
545 inline TZoomFactor::TZoomFactor(const MGraphicsDeviceMap* aDevice):
546 iZoomFactor(TZoomFactor::EZoomOneToOne),
548 /** Constructs a zoom factor object for a specific graphics device map.
550 The graphics map is either directly associated with a particular graphics
551 device itself, or is associated with a hierarchy of device maps whose root
552 map is associated with a particular graphics device.
554 @param aDevice The graphics device map with which the zoom factor is associated. */
557 inline TZoomFactor::TZoomFactor(const TZoomFactor* aDevice):
560 iZoomFactor=aDevice->iZoomFactor;
564 inline void TZoomFactor::SetGraphicsDeviceMap(const MGraphicsDeviceMap* aDevice)
565 /** Sets the graphics device map for this zoom factor object.
567 @param aDevice The graphics device map for this TZoomFactor. */
571 inline const MGraphicsDeviceMap* TZoomFactor::GraphicsDeviceMap() const
572 /** Gets the graphics device map of this zoom factor object.
574 @return The graphics device map of the TZoomFactor. */
579 /** Gets the ascent of an ANSI capital letter in the font whether or not
580 there are any ANSI capitals in the font.
581 @return The positive distance from the font baseline to the top of a
582 standard ANSI capital letter
586 inline TInt CFont::FontCapitalAscent() const
588 return ExtendedFunction(KFontCapitalAscent);
591 /** Gets the max ascent of any pre-composed glyph in the font. This will
592 include accents or diacritics that form part of pre-composed glyphs. It is
593 not guaranteed to cover the max ascent of composite glyphs that have to be
594 created by a layout engine. This is also the recommended distance between
595 the top of a text box and the baseline of the first line of text.
596 @return The positive distance from the font baseline to the top of the
597 highest pre-composed glyph (including accents) above the baseline
601 inline TInt CFont::FontMaxAscent() const
603 return ExtendedFunction(KFontMaxAscent);
606 /** Gets the descent of an ANSI descending character in the font.
607 Whether or not there are any ANSI descenders in the font.
608 @return The positive distance from the font baseline to the bottom of the
609 lowest ANSI descender
613 inline TInt CFont::FontStandardDescent() const
615 return ExtendedFunction(KFontStandardDescent);
618 /** Gets the max descent of any pre-composed glyph in the font. This will
619 include accents or diacritics that form part of pre-composed glyphs. It is
620 not guaranteed to cover the max descent of composite glyphs that have to be
621 created by a layout engine.
622 @return The positive distance from the font baseline to the bottom of the
623 lowest pre-composed glyph (including accents) below the baseline
627 inline TInt CFont::FontMaxDescent() const
629 return ExtendedFunction(KFontMaxDescent);
632 /** Gets the suggested line gap for the font. This is the recommended
633 baseline to baseline distance between successive lines of text in the font.
634 @return The positive recommended gap between successive lines
638 inline TInt CFont::FontLineGap() const
640 return ExtendedFunction(KFontLineGap);
644 Gets the (positive) maximum height in pixels of the font.
645 This may differ from the design height.
647 @return The maximum height of the font.
651 inline TInt CFont::FontMaxHeight() const
653 return FontMaxAscent() + FontMaxDescent();