lafagnosticuifoundation/uigraphicsutils/gulsrc/GULFONT.CPP
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 1997-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <barsread.h>
       
    17 #include <gulfont.hrh>
       
    18 #include <gulfont.h>
       
    19 #include <gulutil.h>
       
    20 
       
    21 //
       
    22 // class TLogicalFont
       
    23 //
       
    24 
       
    25 EXPORT_C TLogicalFont::TLogicalFont()
       
    26 	: iFontId(KNullUid), iCategory(TLogicalFont::EView), iStyle(TLogicalFont::ENormal)
       
    27 /** The default constructor. 
       
    28 
       
    29 This initialises iFontId to KNullUid, iCategory to EView, iStyle to ENormal 
       
    30 and iZoomFactor to a default zoom factor. */
       
    31 	{
       
    32 	iZoomFactor=TZoomFactor();
       
    33 	}
       
    34 
       
    35 EXPORT_C TLogicalFont::TLogicalFont(TUid aId)
       
    36 	: iFontId(aId), iCategory(TLogicalFont::EView), iStyle(TLogicalFont::ENormal)
       
    37 /** Constructor with a logical font ID.
       
    38 
       
    39 The other member data is initialised as for the default constructor.
       
    40 
       
    41 @param aId The logical font ID. */
       
    42 	{
       
    43 	iZoomFactor=TZoomFactor();
       
    44 	}
       
    45 
       
    46 EXPORT_C TLogicalFont::TLogicalFont(TFontCategory aCategory,TFontStyle aStyle,const TZoomFactor& aZoomFactor)
       
    47 	: iFontId(KNullUid), iCategory(aCategory), iStyle(aStyle), iZoomFactor(aZoomFactor)
       
    48 /** Constructor with a logical font category, style and zoom factor.
       
    49 
       
    50 iFontId is initialised to KNullUid.
       
    51 
       
    52 @param aCategory The logical font category.
       
    53 @param aStyle The font style.
       
    54 @param aZoomFactor The zoom factor. */
       
    55 	{}
       
    56 
       
    57 EXPORT_C TLogicalFont::TLogicalFont(TUid aId,TLogicalFont::TFontCategory aCategory,
       
    58 										TLogicalFont::TFontStyle aStyle,const TZoomFactor& aZoomFactor)
       
    59 	: iFontId(aId), iCategory(aCategory), iStyle(aStyle), iZoomFactor(aZoomFactor)
       
    60 /** Constructs a logical font, specifying its logical font ID, logical font category, 
       
    61 style and zoom factor.
       
    62 
       
    63 @param aId The logical font ID.
       
    64 @param aCategory The logical font category.
       
    65 @param aStyle The font style.
       
    66 @param aZoomFactor The zoom factor. */
       
    67 	{}
       
    68 
       
    69 //
       
    70 // class CCleanupStackableFont
       
    71 //
       
    72 
       
    73 EXPORT_C CCleanupStackableFont* CCleanupStackableFont::NewByNameL(TResourceReader& aReader,CWsScreenDevice& aScreenDevice)
       
    74 /** Allocates and constructs a new CCleanupStackableFont. 
       
    75 
       
    76 aReader should be initialised to read a resource of type NAMED_FONT.
       
    77 
       
    78 @param aReader The resource reader to use.
       
    79 @param aScreenDevice The screen device.
       
    80 @return Pointer to the CCleanupStackableFont object. */
       
    81 	{
       
    82 	CCleanupStackableFont* font=NewLC(EFalse, aReader, aScreenDevice); // also pushes on to CleanupStack
       
    83 	CleanupStack::Pop();
       
    84 	return font;
       
    85 	}
       
    86 
       
    87 EXPORT_C CCleanupStackableFont* CCleanupStackableFont::NewByNameLC(TResourceReader& aReader,CWsScreenDevice& aScreenDevice)
       
    88 /** Allocates and constructs a new CCleanupStackableFont, leaving it on the cleanup 
       
    89 stack. 
       
    90 
       
    91 aReader should be initialised to read a resource of type NAMED_FONT.
       
    92 
       
    93 @param aReader The resource reader to use.
       
    94 @param aScreenDevice The screen device.
       
    95 @return Pointer to the CCleanupStackableFont object. */
       
    96 	{
       
    97 	return CCleanupStackableFont::NewLC(EFalse, aReader, aScreenDevice);
       
    98 	}
       
    99 
       
   100 EXPORT_C CCleanupStackableFont* CCleanupStackableFont::NewL(TResourceReader& aReader,CWsScreenDevice& aScreenDevice)
       
   101 /** Allocates and constructs a new CCleanupStackableFont. 
       
   102 
       
   103 aReader should be initialised to read a resource of type FONT.
       
   104 
       
   105 @param aReader The resource reader to use.
       
   106 @param aScreenDevice The screen device.
       
   107 @return The CCleanupStackableFont object. */
       
   108 	{
       
   109 	CCleanupStackableFont* font=NewLC(ETrue, aReader, aScreenDevice); // also pushes on to CleanupStack
       
   110 	CleanupStack::Pop();
       
   111 	return font;
       
   112 	}
       
   113 
       
   114 EXPORT_C CCleanupStackableFont* CCleanupStackableFont::NewLC(TResourceReader& aReader,CWsScreenDevice& aScreenDevice)
       
   115 /** Allocates and constructs a new CCleanupStackableFont, leaving it on the cleanup 
       
   116 stack. 
       
   117 
       
   118 aReader should be initialised to read a resource of type FONT. 
       
   119 
       
   120 @param aReader The resource reader to use.
       
   121 @param aScreenDevice The screen device.
       
   122 @return Pointer to the CCleanupStackableFont object. */
       
   123 	{
       
   124 	return CCleanupStackableFont::NewLC(ETrue, aReader, aScreenDevice);
       
   125 	}
       
   126 
       
   127 EXPORT_C CCleanupStackableFont::~CCleanupStackableFont()
       
   128 /** Destructor.
       
   129 
       
   130 This releases the font. The font is only deleted if its access count is zero 
       
   131 (so that no client is using it). */
       
   132 	{
       
   133 	iScreenDevice.ReleaseFont(iFont); // N.B. do not do "delete iFont"
       
   134 	}
       
   135 
       
   136 EXPORT_C CFbsFont& CCleanupStackableFont::Font() const
       
   137 /** Gets the font stored in this object.
       
   138 
       
   139 The caller does not take ownership.
       
   140 
       
   141 @return The font. */
       
   142 	{
       
   143 	return *iFont;
       
   144 	}
       
   145 
       
   146 EXPORT_C CFbsFont* CCleanupStackableFont::TakeOwnershipOfFont()
       
   147 /** Gets the font stored in this object.
       
   148 
       
   149 The caller takes ownership of the returned font.
       
   150 
       
   151 @return The font. */
       
   152 	{
       
   153 	CFbsFont* font=iFont;
       
   154 	iFont=NULL;
       
   155 	return font;
       
   156 	}
       
   157 
       
   158 CCleanupStackableFont::CCleanupStackableFont(CWsScreenDevice& aScreenDevice)
       
   159 	:iScreenDevice(aScreenDevice)
       
   160 	{
       
   161 	__DECLARE_NAME(_S("CCleanupStackableFont"));
       
   162 	}
       
   163 
       
   164 CCleanupStackableFont* CCleanupStackableFont::NewLC(TBool aByUid,TResourceReader& aReader, CWsScreenDevice& aScreenDevice)
       
   165 	{ //static	
       
   166 	CCleanupStackableFont* font=new(ELeave) CCleanupStackableFont(aScreenDevice);
       
   167 	CleanupStack::PushL(font);
       
   168 	if(aByUid)
       
   169 		font->iFont=ResourceUtils::CreateScreenFontL(aReader,aScreenDevice);
       
   170 	else
       
   171 		font->iFont=ResourceUtils::CreateNamedScreenFontInPixelsL(aReader,aScreenDevice);
       
   172 	return font;
       
   173 	}