sl@0: // Copyright (c) 1995-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 sl@0: #include "UTILS.H" sl@0: #include sl@0: #include "FbsMessage.H" sl@0: sl@0: GLREF_C void Panic(TFbsPanic aPanic); sl@0: sl@0: CFbsTypefaceStore::CFbsTypefaceStore(CGraphicsDevice* aDevice): sl@0: CTypefaceStore(), sl@0: iDevice(aDevice), sl@0: iTwipsCache(NULL) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C CFbsTypefaceStore::~CFbsTypefaceStore() sl@0: { sl@0: if(iTwipsCache) sl@0: { sl@0: ReleaseTwipsCache(); sl@0: delete iTwipsCache; sl@0: } sl@0: } sl@0: sl@0: /** Allocates and constructs a CFbsTypefaceStore, specifying a graphics device. sl@0: @param aDevice A pointer to a graphics device. sl@0: @return A pointer to the newly created typeface store. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C CFbsTypefaceStore* CFbsTypefaceStore::NewL(CGraphicsDevice* aDevice) sl@0: { sl@0: CFbsTypefaceStore* thisptr=new(ELeave) CFbsTypefaceStore(aDevice); sl@0: CleanupStack::PushL(thisptr); sl@0: thisptr->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return(thisptr); sl@0: } sl@0: sl@0: sl@0: void CFbsTypefaceStore::ConstructL() sl@0: { sl@0: // get the session info from the Tls sl@0: iFbs = RFbsSession::GetSession(); sl@0: if (!iFbs) sl@0: { sl@0: User::Leave(KErrCouldNotConnect); sl@0: } sl@0: CTypefaceStore::ConstructL(); sl@0: iTwipsCache = new(ELeave) CFontCache; sl@0: } sl@0: sl@0: sl@0: /** Installs a font store file into the typeface store. sl@0: All the fonts in added and installed font files are available to the sl@0: GetNearestFont...() family of functions. sl@0: Additionally Bitmap Fonts are also available to GetFontById(). sl@0: sl@0: Installed files remain in the typeface store even after the client which added sl@0: them is destroyed. They can be removed using RemoveFile(). sl@0: @param aName The name of the file to be installed. sl@0: @param aId On return, contains the id of the installed file. sl@0: @return KErrNone if successful, otherwise another of the system-wide error sl@0: codes. sl@0: @see AddFile() sl@0: @see RemoveFile() sl@0: @see GetFontById() sl@0: @see GetNearestFontToDesignHeightInTwips() sl@0: @see GetNearestFontToDesignHeightInPixels() sl@0: @see GetNearestFontToMaxHeightInTwips() sl@0: @see GetNearestFontToMaxHeightInPixels() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::InstallFile(const TDesC& aName,TInt& aId) sl@0: { sl@0: TPckgBuf ip; sl@0: aId=0; sl@0: TIpcArgs args(&aName,aName.Length(),&ip); sl@0: TInt ret=iFbs->SendCommand(EFbsMessInstallFontStoreFile,args); sl@0: if(ret==KErrNone) sl@0: aId=ip().iInt; sl@0: return(ret); sl@0: } sl@0: sl@0: /** Adds a font store file to the typeface store. sl@0: All the fonts in added and installed font files are available to the sl@0: GetNearestFont...() family of functions. sl@0: Additionally Bitmap Fonts are also available to GetFontById(). sl@0: sl@0: This function adds the typeface to a reference counted list of fonts. Each sl@0: client that adds the typeface to the store increases the reference count. sl@0: The count is decremented when a client using the typeface is destroyed or sl@0: calls the RemoveFile() function. The typeface is removed from the store only sl@0: when the the reference count is zero (it is not being used by any clients). sl@0: The InstallFile() function is similar, except that the typeface is not reference sl@0: counted, and is hence not removed when all the clients using it are destroyed. sl@0: @param aName A descriptor containing the filename of the typeface store sl@0: @param aId On return, contains the id of the typeface. sl@0: @return KErrNone if successful, otherwise another of the system-wide error sl@0: codes. sl@0: @see InstallFile() sl@0: @see RemoveFile() sl@0: @see GetFontById() sl@0: @see GetNearestFontToDesignHeightInTwips() sl@0: @see GetNearestFontToDesignHeightInPixels() sl@0: @see GetNearestFontToMaxHeightInTwips() sl@0: @see GetNearestFontToMaxHeightInPixels() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::AddFile(const TDesC& aName,TInt& aId) sl@0: { sl@0: TPckgBuf ip; sl@0: aId=0; sl@0: TIpcArgs args(&aName,aName.Length(),&ip); sl@0: TInt ret=iFbs->SendCommand(EFbsMessAddFontStoreFile,args); sl@0: if(ret==KErrNone) sl@0: aId=ip().iInt; sl@0: return(ret); sl@0: } sl@0: sl@0: /** Decrements the reference count of a file which was added using sl@0: AddFile(), and removes it from the store if the reference count reaches zero. sl@0: If the font was not found in the list of reference-counted files (see AddFile()) sl@0: it is assumed to be an installed file (see InstallFile()) and an attempt is sl@0: made to remove it anyway. sl@0: sl@0: If the id given is 0, an attempt is made to remove all font objects from the sl@0: font store provided none of the fonts in the store are currently accessed, sl@0: otherwise it has no effect. sl@0: sl@0: Note: sl@0: The id passed to this function has a different meaning depending on whether sl@0: or not the file is a Symbian-format bitmap file. If it is a Symbian-format sl@0: bitmap file the id is a UID, and is the same from one session to the next. sl@0: If it is an Open Font System file (e.g., a TrueType file) the id is an arbitrary sl@0: number. Consequently the id may vary from one session to the next, and should sl@0: not be saved in a file: however it may be kept and used by a client as sl@0: long as the client is running. sl@0: sl@0: @param aId The id of the file to be removed/decremented, set by AddFile() sl@0: or InstallFile(). sl@0: @see AddFile() sl@0: @see InstallFile() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsTypefaceStore::RemoveFile(TInt aId) sl@0: { sl@0: iFbs->SendCommand(EFbsMessRemoveFontStoreFile,aId); sl@0: } sl@0: sl@0: /** Gets the number of typefaces supported by this store. sl@0: @return The number of supported typefaces. sl@0: @see CTypefaceStore::NumTypefaces() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::NumTypefaces() const sl@0: { sl@0: return(iFbs->SendCommand(EFbsMessNumTypefaces)); sl@0: } sl@0: sl@0: /** sl@0: Gets the font which is the nearest to the given font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInTwips() sl@0: yielding (virtually) the same result. However clients are strongly encouraged to use the new sl@0: @c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every sl@0: character within any given text string will fit within the given amount of twips, whereas the design sl@0: height is an aesthetic unit decided by the font designer without strict physical meaning, which sl@0: may result in cropped characters. sl@0: sl@0: Chooses from the fonts loaded at system startup or through the AddFile() sl@0: or InstallFile() APIs. 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: @see GetNearestFontToDesignHeightInTwips() sl@0: @see GetNearestFontToMaxHeightInTwips() sl@0: @see AddFile() sl@0: @see InstallFile() sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::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: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInPixels() sl@0: yielding (virtually) the same result. However clients are strongly encouraged to use the new sl@0: @c GetNearestFontToMaxHeightInPixels() function instead. This will guarantee that every sl@0: character within any given text string will fit within the given amount of pixels, whereas the design sl@0: height is an aesthetic unit decided by the font designer without strict physical meaning, which sl@0: may result in cropped characters. sl@0: sl@0: Chooses from the fonts loaded at system startup or through the AddFile() sl@0: or InstallFile() APIs. 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: @deprecated Use GetNearestFontToDesignHeightInPixels sl@0: @see GetNearestFontToDesignHeightInPixels() sl@0: @see GetNearestFontToMaxHeightInPixels() sl@0: @see AddFile() sl@0: @see InstallFile() sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::GetNearestFontInPixels(CFont*& aFont,const TFontSpec& aFontSpec) sl@0: { sl@0: return GetNearestFontToDesignHeightInPixels(aFont, aFontSpec); sl@0: } sl@0: sl@0: TInt CFbsTypefaceStore::GetNearestFontInTwipsAndCreateFont( sl@0: CFont*& aFont, sl@0: TInt aFbsMessage, // a TFbsMessage sl@0: const TFontSpec& aFontSpec, sl@0: TInt aMaxHeight) sl@0: { sl@0: aFont = iTwipsCache->Search(aFontSpec); sl@0: if (aFont) sl@0: { sl@0: if (IncrementFontCount(aFont)) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: Panic(EFbsTypefaceStoreError); sl@0: } sl@0: sl@0: TInt ret = SendGetNearestFontCommandNCreateFont( sl@0: aFont, aFbsMessage, aFontSpec, aMaxHeight); sl@0: if (KErrNone != ret) sl@0: { sl@0: return ret; sl@0: } sl@0: sl@0: CFont* discard = NULL; sl@0: /* We are deliberately storing in the cache the TFontSpec requested by the client sl@0: * and not the REAL TFontSpec of the font returned by the font matcher. sl@0: * We are doing this for performance reasons: to use the Font Cache as much as possible. sl@0: * Unless the requested font spec is really complete, including all the different flags sl@0: * and sub fields, there is only a very small chance that the TFontSpec requested sl@0: * by the client would be exactly the same as the best match returned by the server. sl@0: * Since some flags (iFontStyle.iFlags and iTypeFace.iFlags) are quite complex and sl@0: * in general the client don't set up all of them perfectly. sl@0: * So in order to decrease the number of entries in the cache AND also the requests sl@0: * to the server, it's better to associate the TFontSpec asked for by the client sl@0: * with the CFont found so that next time we ask for it, it will be in the cache. sl@0: * sl@0: * If we request 2 different font specs that both have the same real font as their sl@0: * best match then each will appear in the cache but the CFont pointer in both entries sl@0: * will point to the same real CFont (no copies) sl@0: * sl@0: * PS: a problem is known because of doing this: sl@0: * if we try to get a Font which is not in the system, we obtain the best match sl@0: * then if we add this Font in the system (AddFile) and ask again for this Font, sl@0: * we will still have the previous one which is in the Cache and not the one added. sl@0: * This problem is the result of "bad" programming/testing, in general when we use a Font, sl@0: * we know it's here... sl@0: */ sl@0: TRAP(ret, discard = iTwipsCache->AddEntryL(aFont,aFontSpec)); sl@0: if (KErrNone == ret) sl@0: { sl@0: // Font has been added to cache. Increment reference count, so that this font sl@0: // will only be destroyed once all client handles to it are released, AND it can sl@0: // not fit in the cache. Even if no clients have a handle to this font, the object sl@0: // will still persist until other fonts force it out of the cache. sl@0: IncrementFontCount(aFont); sl@0: } sl@0: if (discard) sl@0: { // a font was bumped out of the cache sl@0: ReleaseFont(discard); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: /** sl@0: get pixel size in Twips * 1000 sl@0: @internalComponent sl@0: */ sl@0: void CFbsTypefaceStore::GetPixelSizeInTwips(TSize& aSize) const sl@0: { sl@0: if(iDevice) sl@0: { sl@0: aSize.iWidth = iDevice->HorizontalPixelsToTwips(1000); sl@0: aSize.iHeight = iDevice->VerticalPixelsToTwips(1000); sl@0: } sl@0: if(aSize.iWidth==0 || aSize.iHeight==0) sl@0: { sl@0: TMachineInfoV1Buf mibuf; sl@0: UserHal::MachineInfo(mibuf); sl@0: TSize twipsize = mibuf().iPhysicalScreenSize; sl@0: TSize pixelsize = mibuf().iDisplaySizeInPixels; sl@0: aSize.iWidth = twipsize.iWidth*1000 / pixelsize.iWidth; sl@0: aSize.iHeight = twipsize.iHeight*1000 / pixelsize.iHeight; sl@0: } sl@0: } sl@0: sl@0: sl@0: TInt CFbsTypefaceStore::SendGetNearestFontCommandNCreateFont( sl@0: CFont*& aFont, sl@0: TInt aFbsMessage, // a TFbsMessage sl@0: const TFontSpec& aFontSpec, sl@0: TInt aMaxHeight) sl@0: { sl@0: TPckgBuf pckgFontSpec(aFontSpec); sl@0: TSize pixelSize; sl@0: GetPixelSizeInTwips(pixelSize); sl@0: TSizeInfo info(aMaxHeight, pixelSize); sl@0: TPckgBuf pckgMaxHeight(info); sl@0: TPckgBuf pckgFontInfo; sl@0: TIpcArgs args(&pckgFontSpec, &pckgFontInfo, &pckgMaxHeight); sl@0: const TInt ret = iFbs->SendCommand(aFbsMessage, args); sl@0: if (KErrNone != ret) sl@0: { sl@0: return ret; sl@0: } sl@0: return CreateFont(aFont, pckgFontInfo()); sl@0: } sl@0: sl@0: /** sl@0: Gets the font which is the nearest to the given font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: This new function replaces the deprecated @c GetNearestFontInTwips() yielding (virtually) the sl@0: same result. However clients are strongly encouraged to use the new sl@0: @c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every sl@0: character within any given text string will fit within the given amount of twips, whereas the design sl@0: height is an aesthetic unit decided by the font designer without strict physical meaning, which sl@0: may result in cropped characters. sl@0: sl@0: Chooses from the fonts loaded at system startup or through the AddFile() sl@0: or InstallFile() APIs. 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: @see GetNearestFontToMaxHeightInTwips() sl@0: @see AddFile() sl@0: @see InstallFile() sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: return GetNearestFontInTwipsAndCreateFont(aFont, EFbsMessGetNearestFontToDesignHeightInTwips, aFontSpec); sl@0: } sl@0: sl@0: /** sl@0: Gets the font which is the nearest to the given font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: This new function replaces the deprecated @c GetNearestFontInPixels() yielding (virtually) the sl@0: same result. However clients are strongly encouraged to use the new sl@0: @c GetNearestFontToMaxHeightInPixels() function instead. This will guarantee that every sl@0: character within any given text string will fit within the given amount of pixels, whereas the design sl@0: height is an aesthetic unit decided by the font designer without strict physical meaning, which sl@0: may result in cropped characters. sl@0: sl@0: Chooses from the fonts loaded at system startup or through the AddFile() sl@0: or InstallFile() APIs. 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: @see GetNearestFontToMaxHeightInPixels() sl@0: @see AddFile() sl@0: @see InstallFile() sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::GetNearestFontToDesignHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: return SendGetNearestFontCommandNCreateFont(aFont, EFbsMessGetNearestFontToDesignHeightInPixels, aFontSpec); sl@0: } sl@0: sl@0: /** sl@0: Gets the font which is the nearest to the given font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: The font and bitmap server returns a pointer to the nearest matching font sl@0: from those available. Matches to max height of font - this does its best sl@0: to return a font that will fit within the maximum height specified (but sl@0: note that variations due to hinting algorithms may rarely result in this sl@0: height being exceeded by up to one pixel). Problems can also be sl@0: encountered with bitmap fonts where the typeface exists but doesn't have sl@0: a font small enough. sl@0: sl@0: Chooses from the fonts loaded at system startup or through the AddFile() sl@0: or InstallFile() APIs. 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. sl@0: @return KErrNone if successful; a system-wide error code otherwise. sl@0: @publishedAll sl@0: @released sl@0: @see GetNearestFontToDesignHeightInTwips() sl@0: @see AddFile() sl@0: @see InstallFile() sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight) sl@0: { sl@0: return GetNearestFontInTwipsAndCreateFont(aFont, EFbsMessGetNearestFontToMaxHeightInTwips, aFontSpec, aMaxHeight); sl@0: } sl@0: sl@0: /** sl@0: Gets the font which is the nearest to the given font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: The font and bitmap server returns a pointer to the nearest matching font sl@0: from those available. Matches to max height of font - this does its best sl@0: to return a font that will fit within the maximum height specified (but sl@0: note that variations due to hinting algorithms may rarely result in this sl@0: height being exceeded by up to one pixel). Problems can also be sl@0: encountered with bitmap fonts where the typeface exists but doesn't have sl@0: a font small enough. sl@0: sl@0: Chooses from the fonts loaded at system startup or through the AddFile() sl@0: or InstallFile() APIs. 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. sl@0: @return KErrNone if successful; a system-wide error code otherwise. sl@0: @publishedAll sl@0: @released sl@0: @see GetNearestFontToDesignHeightInPixels() sl@0: @see AddFile() sl@0: @see InstallFile() sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight) sl@0: { sl@0: return SendGetNearestFontCommandNCreateFont(aFont, EFbsMessGetNearestFontToMaxHeightInPixels, aFontSpec, aMaxHeight); sl@0: } sl@0: sl@0: /** Gets a Bitmap Font by unique identifier and algorithmic drawing style. sl@0: Chooses from the Bitmap fonts loaded at system startup or through the AddFile() sl@0: or InstallFile() APIs. sl@0: sl@0: @param aFont On return, contains a pointer to the retrieved font. sl@0: @param aUid The unique identifier of the font to be retrieved. sl@0: @param aAlgStyle Algorithmic style to be applied. e.g. Sets things like algorithmic sl@0: bolding, or slant for pseudo-italics. sl@0: @return KErrNone if successful, otherwise another of the system-wide error sl@0: codes. sl@0: @publishedAll sl@0: @released sl@0: @see GetNearestFontToMaxHeightInTwips() sl@0: @see GetNearestFontToDesignHeightInTwips() sl@0: @see GetNearestFontToMaxHeightInPixels() sl@0: @see GetNearestFontToDesignHeightInPixels() sl@0: @see AddFile() sl@0: @see InstallFile() sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::GetFontById(CFont*& aFont,TUid aUid,const TAlgStyle& aAlgStyle) sl@0: { sl@0: TPckgBuf tfpckg; sl@0: TSize pixelSize; sl@0: GetPixelSizeInTwips(pixelSize); sl@0: TPckgBuf sizePkg(pixelSize); sl@0: TPckgBuf stylepckg(aAlgStyle); sl@0: TIpcArgs args(&tfpckg,&stylepckg,aUid.iUid, &sizePkg); sl@0: TInt ret=iFbs->SendCommand(EFbsMessGetFontById,args); sl@0: if(ret!=KErrNone) return(ret); sl@0: return(CreateFont(aFont,tfpckg())); sl@0: } sl@0: sl@0: TInt CFbsTypefaceStore::CreateFont(CFont*& aFont, const TFontInfo& aFontInfo) sl@0: { sl@0: if (!aFontInfo.iHandle) sl@0: { sl@0: Panic(EFbsFontCreateFailed); sl@0: } sl@0: if (IsFontLoaded(aFont, aFontInfo)) sl@0: { sl@0: // By now, a new server-side font object has been created for the requested sl@0: // TFontSpec. However IsFontLoaded() is true, meaning the client already has a sl@0: // font at this address. This can happen if a closely matching (but not exact, sl@0: // otherwise it would be found in the twipscache already) TFontSpec is sent to sl@0: // the server. sl@0: // This means the new server-side font is a duplicate another server-side font. sl@0: // Therefore tell the server to destroy the one just created, and return the sl@0: // font that was already created. sl@0: iFbs->SendCommand(EFbsMessClose, aFontInfo.iHandle); sl@0: return KErrNone; sl@0: } sl@0: sl@0: CFbsFont* font = new CFbsFont; sl@0: if (!font) sl@0: { sl@0: iFbs->SendCommand(EFbsMessClose, aFontInfo.iHandle); sl@0: return KErrNoMemory; sl@0: } sl@0: font->iHandle = aFontInfo.iHandle; sl@0: font->iServerHandle = aFontInfo.iServerHandle; sl@0: font->iAddressPointer = (CBitmapFont*)(iFbs->HeapBase() + aFontInfo.iAddressOffset); sl@0: TRAPD(ret, AddFontL(font)); sl@0: if (KErrNone == ret) sl@0: { sl@0: aFont = font; sl@0: } sl@0: else sl@0: { sl@0: delete font; sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: TBool CFbsTypefaceStore::IsFontLoaded(CFont*& aFont, const TFontInfo& aFontInfo) const sl@0: /** sl@0: @see CFontStore::IsFontLoaded sl@0: @see CPdrTypefaceStore::IsFontLoaded sl@0: */ sl@0: { sl@0: const TInt count = iFontAccess->Count(); sl@0: for (TInt i = 0; i < count; i++) sl@0: { sl@0: CFont* font = (*iFontAccess)[i].iFont; sl@0: if (((CFbsFont*)font)->iAddressPointer == sl@0: (CBitmapFont*)(iFbs->HeapBase() + aFontInfo.iAddressOffset)) sl@0: { sl@0: (*iFontAccess)[i].iAccessCount++; sl@0: aFont = font; sl@0: return ETrue; sl@0: } sl@0: } sl@0: return EFalse; sl@0: } sl@0: sl@0: /** Gets typeface information for a specified typeface index. sl@0: This information is returned in aTypefaceSupport, and includes the typeface sl@0: name and typeface attributes, the number of font heights, the maximum and sl@0: minimum font heights, and whether it is a scaleable typeface. sl@0: sl@0: Returns benignly with an empty TTypefaceSupport if the index is too high; sl@0: this can happen if another process removes a typeface after the first process sl@0: has already got the number of typefaces. However, if the aTypefaceIndex<0 sl@0: the function panics with EFbsTypefaceIndexOutOfRange. sl@0: sl@0: @param aTypefaceSupport On return, if the function executed successfully, sl@0: this object contains the typeface information. sl@0: @param aTypefaceIndex A typeface index number, in the range: zero to (NumTypefaces() - 1). sl@0: @see CTypefaceStore::TypefaceSupport() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsTypefaceStore::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const sl@0: { sl@0: __ASSERT_ALWAYS( aTypefaceIndex >= 0, Panic(EFbsTypefaceIndexOutOfRange) ); sl@0: TSize pixelSize; sl@0: GetPixelSizeInTwips(pixelSize); sl@0: TPckgBuf sizePkg(pixelSize); sl@0: TPckgBuf tfi; sl@0: TIpcArgs args(aTypefaceIndex,&tfi, &sizePkg); sl@0: iFbs->SendCommand(EFbsMessTypefaceSupport,args); sl@0: aTypefaceSupport=tfi(); sl@0: } sl@0: sl@0: /** Gets the height of the font with specified height and typeface indices, in sl@0: twips. sl@0: The value returned is rounded up or down to the nearest font height in twips. sl@0: sl@0: If aTypefaceIndex<0 the function panics with EFbsTypefaceIndexOutOfRange. sl@0: If aTypefaceIndex is greater than the number of typefaces or aHeightIndex<0 sl@0: then the function returns 0. If aHeightIndex is greater than the number of sl@0: heights then the function returns the biggest height. sl@0: sl@0: @param aTypefaceIndex A typeface index number, in the range: 0 to (NumTypefaces() - 1). sl@0: @param aHeightIndex A font height index number, in the range: 0 to (TTypefaceSupport::iNumHeights - 1). sl@0: Note: TTypefaceSupport::iNumHeights is returned by TypefaceSupport(). sl@0: @return The height of the font, in twips. sl@0: @see CTypefaceStore::FontHeightInTwips() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const sl@0: { sl@0: return FontHeight(aTypefaceIndex,aHeightIndex,EFbsMessFontHeightInTwips); sl@0: } sl@0: sl@0: /** Gets the height of the font with specified height and typeface indices, in sl@0: pixels. sl@0: The value returned is rounded up or down to the nearest font height in pixels. sl@0: sl@0: If aTypefaceIndex<0 the function panics with EFbsTypefaceIndexOutOfRange. sl@0: If aTypefaceIndex is greater than the number of typefaces or aHeightIndex<0 sl@0: then the function returns 0. If aHeightIndex is greater than the number of sl@0: heights then the function returns the biggest height. sl@0: sl@0: @param aTypefaceIndex A typeface index number, in the range: 0 to (NumTypefaces() - 1). sl@0: @param aHeightIndex A font height index number, in the range: 0 to (TTypefaceSupport::iNumHeights - 1). sl@0: Note: TTypefaceSupport::iNumHeights is returned by TypefaceSupport(). sl@0: @return The height of the font, in pixels. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const sl@0: { sl@0: return FontHeight(aTypefaceIndex,aHeightIndex,EFbsMessFontHeightInPixels); sl@0: } sl@0: sl@0: TInt CFbsTypefaceStore::FontHeight(TInt aTypefaceIndex,TInt aHeightIndex,TInt aMessage) const sl@0: { sl@0: __ASSERT_ALWAYS( aTypefaceIndex >= 0, Panic(EFbsTypefaceIndexOutOfRange) ); sl@0: TSize pixelSize; sl@0: GetPixelSizeInTwips(pixelSize); sl@0: TPckgBuf sizePkg(pixelSize); sl@0: TIpcArgs args(aTypefaceIndex, aHeightIndex, &sizePkg); sl@0: return iFbs->SendCommand(aMessage, args); sl@0: } sl@0: sl@0: /** Gets the default anti-aliasing setting for scalable fonts. sl@0: @return Indicates whether or not scalable fonts should be drawn using sl@0: anti-aliasing. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C TGlyphBitmapType CFbsTypefaceStore::DefaultBitmapType() const sl@0: { sl@0: return (TGlyphBitmapType)iFbs->SendCommand(EFbsMessGetDefaultGlyphBitmapType); sl@0: } sl@0: sl@0: /** Sets the default anti-aliasing setting for scalable fonts. Unless this sl@0: default setting is overridden so that a font is explicitly requested with sl@0: anti-aliasing turned on or off, (see TOpenFontSpec::SetBitmapType() or sl@0: TFontStyle::SetBitmapType()), fonts will use the default setting. The default sl@0: setting would typically only be changed via the Control Panel. The new setting sl@0: affects fonts requested after the change has been made. sl@0: There is currently no anti-aliasing support for bitmapped fonts. sl@0: @param aType Indicates whether or not scalable fonts should be drawn using sl@0: anti-aliasing. sl@0: @see TOpenFontSpec::SetBitmapType() sl@0: @see TFontStyle::SetBitmapType() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsTypefaceStore::SetDefaultBitmapType(TGlyphBitmapType aType) const sl@0: { sl@0: iFbs->SendCommand(EFbsMessSetDefaultGlyphBitmapType,aType); sl@0: } sl@0: sl@0: /** Sets an alias for a font name. sl@0: sl@0: If a requested font cannot be found and its name occurs in the alias list sl@0: then it will be searched for again using the font name corresponding to sl@0: that alias. If an empty font name is passed then the alias will be removed sl@0: the list. sl@0: @param TDesC& The font name alias to set. sl@0: @param TDesC& The actual font name to use for this alias. May be empty. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: EXPORT_C void CFbsTypefaceStore::SetFontNameAliasL(const TDesC& aFontAlias,const TDesC& aFontName) const sl@0: { sl@0: TIpcArgs args(&aFontAlias,aFontAlias.Length(),&aFontName,aFontName.Length()); sl@0: User::LeaveIfError(iFbs->SendCommand(EFbsMessFontNameAlias,args)); sl@0: } sl@0: sl@0: /** Specifies the default language with which font metrics calculation will be based on. sl@0: The default language will be used if none is set on the font specification. sl@0: @publishedAll sl@0: @released sl@0: @see TFontSpec::SetScriptTypeForMetrics sl@0: */ sl@0: EXPORT_C void CFbsTypefaceStore::SetDefaultLanguageForMetrics(TLanguage aLanguage) const sl@0: { sl@0: iFbs->SendCommand(EFbsMessDefaultLanguageForMetrics, aLanguage); sl@0: } sl@0: sl@0: /** sl@0: Unload all fonts loaded from RAM or removable media sl@0: @internalTechnology sl@0: @deprecated sl@0: */ sl@0: EXPORT_C void CFbsTypefaceStore::RemoveFontFileLocksL() sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: /** sl@0: Unload all fonts (of specified type) loaded from named drive sl@0: @internalTechnology sl@0: */ sl@0: EXPORT_C void CFbsTypefaceStore::RemoveFontFileLocksL(const TDesC& /*aDrive*/, TBool /*aAllFonts*/) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: /** sl@0: Unload the named font file sl@0: @internalTechnology sl@0: */ sl@0: EXPORT_C void CFbsTypefaceStore::RemoveFontFileLocksL(const TDesC& /*aFileName*/) sl@0: { sl@0: User::Leave(KErrNotSupported); sl@0: } sl@0: sl@0: /** Reset the twips cache. sl@0: sl@0: The Typeface Store remembers font matches found through GetNearestFont...InTwips() family sl@0: of functions in a cache for quicker matching. This function empties the cache, and should be sl@0: called after the screen mode is changed as the Twips to pixels relationship may have changed. sl@0: @publishedAll sl@0: */ sl@0: EXPORT_C void CFbsTypefaceStore::ReleaseTwipsCache() sl@0: { sl@0: if(iTwipsCache) sl@0: { sl@0: CFont* font=iTwipsCache->RemoveFirstEntry(); sl@0: while(font!=NULL) sl@0: { sl@0: ReleaseFont(font); sl@0: font=iTwipsCache->RemoveFirstEntry(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Sets the system default font typeface. This font will be used when finding the nearest font and the font specified is sl@0: an empty descriptor. sl@0: If the system default font is not set, then the default behaviour is to find the nearest match. sl@0: sl@0: @capability WriteDeviceData sl@0: @param aFontTypefacename is the font typeface to use as the system default. A font alias cannot be used. sl@0: */ sl@0: EXPORT_C void CFbsTypefaceStore::SetSystemDefaultTypefaceNameL(const TDesC& aFontTypefaceName) sl@0: { sl@0: if (aFontTypefaceName.Length() <= KMaxTypefaceNameLength) sl@0: { sl@0: TIpcArgs args(&aFontTypefaceName); sl@0: User::LeaveIfError(iFbs->SendCommand(EFbsSetSystemDefaultTypefaceName, args)); sl@0: } sl@0: else sl@0: User::Leave(KErrTooBig); // Typeface name is too large sl@0: } sl@0: sl@0: /** sl@0: Function to add a CLinkedTypefaceSpecification to the font and bitmap server typeface store. sl@0: @capability ECapabilityWriteDeviceData sl@0: @publishedPartner sl@0: @released sl@0: @param aLinkedTypefaceSpec The typeface specification to be added. Ownership is not transferred. sl@0: @param aId A unique identifier sl@0: @return A global error code sl@0: @see CLinkedTypefaceSpecification sl@0: @deprecated sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::RegisterLinkedTypeface(const CLinkedTypefaceSpecification& /*aLinkedTypefaceSpec*/, TInt& /*aId*/) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: /** sl@0: Function to add a CLinkedTypefaceSpecification to the font and bitmap server typeface store. sl@0: @capability ECapabilityWriteDeviceData sl@0: @publishedPartner sl@0: @released sl@0: @param aLinkedTypefaceSpec. The typeface specification to be added. Ownership is not transferred. sl@0: @return a global error code sl@0: @see CLinkedTypefaceSpecification sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::RegisterLinkedTypeface(const CLinkedTypefaceSpecification& aLinkedTypefaceSpec) sl@0: { sl@0: __ASSERT_ALWAYS(iFbs,Panic(EFbsPanicNoConnection)); sl@0: sl@0: // send the name sl@0: TPckgBuf pckgbuf; sl@0: TLinkedTypefaceSpecificationArgs &typefaceArgs=pckgbuf(); sl@0: sl@0: typefaceArgs = aLinkedTypefaceSpec; sl@0: sl@0: TIpcArgs args(&pckgbuf,sizeof(TPckgBuf )); sl@0: sl@0: return iFbs->SendCommand(EFbsMessRegisterLinkedTypeface,args); sl@0: } sl@0: /** sl@0: Function to retrieve a linked typeface specification from the installed rasterizer. sl@0: If there is not a rasterizer present supporting font linking then KErrNotSupported will be returned. sl@0: The rasterizer is name specified within the passed specification and fills in the elements and sl@0: groups if the typeface exists. sl@0: sl@0: @param CLinkedTypefaceSpecificaion& The typeface Specification with the name set to be the typeface to be retrieved. sl@0: sl@0: @leave KErrNoMemory if there is insufficient memory available sl@0: @leave KErrServerTerminated if the server no longer present sl@0: @leave KErrServerBusy if there are no message slots available sl@0: */ sl@0: EXPORT_C void CFbsTypefaceStore::GetLinkedTypefaceL(CLinkedTypefaceSpecification& aLinkedTypefaceSpec) sl@0: { sl@0: TBuf linkedName = aLinkedTypefaceSpec.Name(); sl@0: sl@0: TLinkedTypefaceSpecificationArgs returnSpec; sl@0: TPckgBuf specPkg; sl@0: sl@0: TIpcArgs args; sl@0: args.Set(0,&linkedName); sl@0: args.Set(2,&specPkg); sl@0: sl@0: User::LeaveIfError(iFbs->SendCommand(EFbsMessFetchLinkedTypeface, args)); sl@0: sl@0: aLinkedTypefaceSpec.Clear(); sl@0: returnSpec = specPkg(); sl@0: sl@0: TInt i; sl@0: for (i = 0 ; i < returnSpec.iGroupSize ; i++) sl@0: { sl@0: CLinkedTypefaceGroup* grp = CLinkedTypefaceGroup::NewLC(returnSpec.iGroups[i].iGroupId); sl@0: grp->SetBaselineShift(returnSpec.iGroups[i].iBaselineShift); sl@0: grp->SetScalingOption(returnSpec.iGroups[i].iScalingOption); sl@0: grp->SetBoldnessPercentage(returnSpec.iGroups[i].iBoldnessPercentage); sl@0: grp->SetItalicAngle(returnSpec.iGroups[i].iItalicAngle); sl@0: aLinkedTypefaceSpec.AddLinkedTypefaceGroupL(*grp); sl@0: CleanupStack::Pop(grp); sl@0: } sl@0: for (i = 0 ; i < returnSpec.iSize ; i++) sl@0: { sl@0: CLinkedTypefaceElementSpec* ele = CLinkedTypefaceElementSpec::NewLC(returnSpec.iTypefaces[i].iName, returnSpec.iTypefaces[i].iGroupId); sl@0: ele->SetCanonical(returnSpec.iTypefaces[i].iIsCanonical); sl@0: aLinkedTypefaceSpec.AddTypefaceAtBackL(*ele); sl@0: CleanupStack::Pop(ele); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Function to update an existing linked typeface with a new specification. If successful a temporary file is generated and this will replace the sl@0: linked font after a reboot. Calls to FetchLinkedTypefaceSpecificationL will return the currently loaded linked font spec and not the sl@0: updated specification. sl@0: sl@0: @param aLinkedTypefaceSpec A new linked font specification to replace an existing file sl@0: sl@0: @panic EFbsPanicNoConnection There is no connection to FontBitmap Server sl@0: sl@0: @return TInt One of the system wide error codes sl@0: */ sl@0: EXPORT_C TInt CFbsTypefaceStore::UpdateLinkedTypeface(const CLinkedTypefaceSpecification& aLinkedTypefaceSpec) sl@0: { sl@0: __ASSERT_ALWAYS(iFbs,Panic(EFbsPanicNoConnection)); sl@0: sl@0: TPckgBuf pckgbuf; sl@0: TLinkedTypefaceSpecificationArgs &typefaceArgs=pckgbuf(); sl@0: sl@0: typefaceArgs = aLinkedTypefaceSpec; sl@0: sl@0: TIpcArgs args(&pckgbuf,sizeof(TPckgBuf )); sl@0: sl@0: return iFbs->SendCommand(EFbsMessUpdateLinkedTypeface,args); sl@0: } sl@0: