webengine/osswebengine/WebCore/platform/symbian/FontCacheSymbian.cpp
changeset 0 dd21522fd290
child 5 10e98eab6f85
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "config.h"
       
    21 #include "FontCache.h"
       
    22 #include "FontPlatformData.h"
       
    23 #include "Font.h"
       
    24 #include "StaticObjectsContainer.h"
       
    25 #include "PlatformFontCache.h"
       
    26 #include <../bidi.h>            // work around for multiple bidi.h files
       
    27 #include "ZoomFactor.h"
       
    28 #include <e32base.h>
       
    29 #include <e32std.h>
       
    30 #include <w32std.h>
       
    31 #include <COEMAIN.H>
       
    32 #include <fbs.h>
       
    33 #include <FeatMgr.h>
       
    34 #include <Languages.hrh>
       
    35 
       
    36 #include <AknFontAccess.h>
       
    37 #include <AknUtils.h>
       
    38 #include <AknLayoutFont.h>
       
    39 #include <AknFontSpecification.h>
       
    40 
       
    41 // CONSTANTS
       
    42 _LIT( KPlatformDefaultFontFamily,   "S60 WebKit" ); 
       
    43 
       
    44 namespace WebCore
       
    45 {
       
    46 
       
    47 void FontCache::platformInit()
       
    48 {
       
    49     // don't support Glphy caching in S60, so force to use the complex path
       
    50     Font::setCodePath( Font::Complex );
       
    51     StaticObjectsContainer::instance()->fontCache()->Initialize();
       
    52 }
       
    53 
       
    54 const FontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length)
       
    55 {
       
    56     // this function shouldn't be called.
       
    57     __ASSERT_ALWAYS( 0, User::Panic(_L("FontCache:"), 0) );
       
    58     return 0;
       
    59 }
       
    60 
       
    61 FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font)
       
    62 {
       
    63     return 0;
       
    64 }
       
    65 
       
    66 FontPlatformData* FontCache::getLastResortFallbackFont(const Font& font)
       
    67 {
       
    68    // the default fallback font
       
    69    return getCachedFontPlatformData(font.fontDescription(), StaticObjectsContainer::instance()->fontCache()->DeviceDefaultFontFamilies());
       
    70 }
       
    71 
       
    72 FontPlatformData* FontCache::getDeviceDefaultFont(float size)
       
    73 {
       
    74     FontDescription fd;
       
    75     fd.setComputedSize(size);
       
    76     return getCachedFontPlatformData(fd, StaticObjectsContainer::instance()->fontCache()->DeviceDefaultFontFamilies());
       
    77 }
       
    78 
       
    79 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
       
    80 {
       
    81     PlatformFontCache* platformCache = StaticObjectsContainer::instance()->fontCache();
       
    82     return new FontPlatformData(platformCache->zoomedFont(fontDescription, 100));
       
    83 }
       
    84 
       
    85 const AtomicString& FontCache::systemFontFamilyName( const AtomicString& familyName )
       
    86 {
       
    87     return StaticObjectsContainer::instance()->fontCache()->SystemFontFamily( familyName );
       
    88 }
       
    89 
       
    90 void PlatformFontCache::Initialize()
       
    91     {
       
    92     iScreenDevice = CCoeEnv::Static()->ScreenDevice();
       
    93     iFontCache.clear();
       
    94 
       
    95     // search for scalable fonts only to make lookups faster
       
    96     TInt count(iScreenDevice->NumTypefaces());
       
    97     for (TInt n=0; n<count; ++n)
       
    98         {
       
    99         TTypefaceSupport typeface;
       
   100         iScreenDevice->TypefaceSupport(typeface, n);
       
   101         if (typeface.iIsScalable)
       
   102             {
       
   103             // count the scalable typefaces
       
   104             ++iTypefaceCount;
       
   105             }
       
   106         }
       
   107 
       
   108     // populate typeface array
       
   109     TInt i=0;
       
   110     iSupportedNames = new AtomicString[iTypefaceCount];
       
   111 
       
   112     for (TInt n=0; n<count; ++n)
       
   113         {
       
   114         TTypefaceSupport typeface;
       
   115         iScreenDevice->TypefaceSupport(typeface, n);
       
   116         if (typeface.iIsScalable)
       
   117             {
       
   118             iSupportedNames[i] = typeface.iTypeface.iName;
       
   119             ++i;
       
   120             }
       
   121 
       
   122         }
       
   123 
       
   124 }
       
   125 
       
   126 PlatformFontCache::~PlatformFontCache()
       
   127 {
       
   128     Vector<ZoomedSpec>::iterator it = iFontCache.begin();
       
   129     Vector<ZoomedSpec>::iterator end = iFontCache.end();
       
   130     for(;it != end; ++it) {
       
   131         ReleaseFont( it->m_font );
       
   132         it->m_font = 0;
       
   133     }        
       
   134     iFontCache.clear();
       
   135     delete [] iSupportedNames;
       
   136 }
       
   137 
       
   138 const AtomicString& PlatformFontCache::SystemFontFamily( const AtomicString& familyName )
       
   139 {
       
   140     // first check if we support this font
       
   141     for (TInt n=0; n<iTypefaceCount; ++n)
       
   142     {
       
   143         if (iSupportedNames[n] == familyName )
       
   144         {
       
   145             return iSupportedNames[n];
       
   146         }
       
   147     }
       
   148 
       
   149     return DeviceDefaultFontFamilies();
       
   150 }
       
   151 
       
   152 const AtomicString& PlatformFontCache::DeviceDefaultFontFamilies()
       
   153     {
       
   154     TPtrC font(KPlatformDefaultFontFamily);
       
   155     iDeviceDefaultFont = font;
       
   156     return iDeviceDefaultFont;
       
   157     }
       
   158 
       
   159 CFont* PlatformFontCache::CreateFont(const ZoomedSpec& spec)
       
   160 {    
       
   161     CFont* font = 0;
       
   162     
       
   163     Vector<ZoomedSpec>::const_iterator it = iFontCache.begin();
       
   164     Vector<ZoomedSpec>::const_iterator end = iFontCache.end();
       
   165     for (;it != end; ++it) {
       
   166         if ((*it) == spec) {
       
   167             font = it->m_font; 
       
   168             return font;
       
   169         }
       
   170     }
       
   171     
       
   172     
       
   173     if (spec.m_spec.iTypeface.iName == KPlatformDefaultFontFamily) { 
       
   174         // fall back to platform default fonts by using TAknFontFamily 
       
   175         font = AknFontAccess::GetClosestFont(*iScreenDevice, spec.m_spec.iFontStyle, spec.m_spec.iHeight * spec.m_zoom/100, (AknFontAccess::TAknFontFamily)0); 
       
   176     } 
       
   177     else { 
       
   178         font = AknFontAccess::GetClosestFont(*iScreenDevice, spec.m_spec.iFontStyle, spec.m_spec.iHeight * spec.m_zoom/100, spec.m_spec.iTypeface.iName); 
       
   179     } 
       
   180         
       
   181     
       
   182     if (font) {
       
   183         ZoomedSpec newSpec(spec);
       
   184         newSpec.m_font = font;
       
   185         iFontCache.append(newSpec);
       
   186     }   
       
   187 	 
       
   188     return font;
       
   189 }
       
   190 
       
   191 void PlatformFontCache::ReleaseFont(CFont* font)
       
   192 {
       
   193     iScreenDevice->ReleaseFont(font);
       
   194 }
       
   195 
       
   196 void PlatformFontCache::setFontZoomFactor(int zoom)
       
   197 {
       
   198     // adjust the zoom factor based on fonts
       
   199     iFontZoomFactor = zoom;
       
   200 }
       
   201 
       
   202 TFontSpec PlatformFontCache::fontSpecInTwips(const FontDescription& fontDescription)
       
   203 {    
       
   204     TInt fSize = fontDescription.computedPixelSize();
       
   205 
       
   206     if (fSize == 0) fSize = 12;
       
   207     TInt twipSize = iScreenDevice->VerticalPixelsToTwips(fSize);
       
   208 
       
   209     // convert to platform-supported font family
       
   210     TPtrC fPtr( SystemFontFamily( fontDescription.family().family() ) );
       
   211     
       
   212 
       
   213     TFontSpec fontSpec(fPtr, twipSize);
       
   214     fontSpec.iFontStyle.SetStrokeWeight(fontDescription.bold() ? EStrokeWeightBold : EStrokeWeightNormal);
       
   215     fontSpec.iFontStyle.SetPosture(fontDescription.italic() ? EPostureItalic : EPostureUpright);
       
   216     fontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap); // enable anti-aliasing
       
   217     
       
   218     if (fontDescription.bold() && fPtr==KPlatformDefaultFontFamily) {
       
   219         fontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
       
   220     }
       
   221 
       
   222     return fontSpec;
       
   223 }
       
   224 
       
   225 
       
   226 CFont* PlatformFontCache::zoomedFont(const FontDescription& fontDescription, int zoom)
       
   227 {
       
   228     ZoomedSpec spec(fontSpecInTwips(fontDescription), zoom, 0);
       
   229     return CreateFont(spec);
       
   230 }
       
   231 
       
   232 }
       
   233