Home | History | Annotate | Download | only in graphics
      1 /*
      2  * Copyright (C) 2006, 2008 Apple Computer, Inc.  All rights reserved.
      3  * Copyright (C) 2007-2008 Torch Mobile, Inc.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  *
      9  * 1.  Redistributions of source code must retain the above copyright
     10  *     notice, this list of conditions and the following disclaimer.
     11  * 2.  Redistributions in binary form must reproduce the above copyright
     12  *     notice, this list of conditions and the following disclaimer in the
     13  *     documentation and/or other materials provided with the distribution.
     14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
     15  *     its contributors may be used to endorse or promote products derived
     16  *     from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #ifndef FontCache_h
     31 #define FontCache_h
     32 
     33 #include <limits.h>
     34 #include <wtf/Forward.h>
     35 #include <wtf/Vector.h>
     36 #include <wtf/unicode/Unicode.h>
     37 
     38 #if PLATFORM(WIN)
     39 #include <objidl.h>
     40 #include <mlang.h>
     41 #endif
     42 
     43 namespace WebCore
     44 {
     45 
     46 class Font;
     47 class FontPlatformData;
     48 class FontData;
     49 class FontDescription;
     50 class FontSelector;
     51 class SimpleFontData;
     52 
     53 class FontCache {
     54     WTF_MAKE_NONCOPYABLE(FontCache); WTF_MAKE_FAST_ALLOCATED;
     55 public:
     56     friend FontCache* fontCache();
     57 
     58     const FontData* getFontData(const Font&, int& familyIndex, FontSelector*);
     59     void releaseFontData(const SimpleFontData*);
     60 
     61     // This method is implemented by the platform.
     62     // FIXME: Font data returned by this method never go inactive because callers don't track and release them.
     63     const SimpleFontData* getFontDataForCharacters(const Font&, const UChar* characters, int length);
     64 
     65     // Also implemented by the platform.
     66     void platformInit();
     67 
     68 #if OS(WINCE) && !PLATFORM(QT)
     69 #if defined(IMLANG_FONT_LINK) && (IMLANG_FONT_LINK == 2)
     70     IMLangFontLink2* getFontLinkInterface();
     71 #else
     72     IMLangFontLink* getFontLinkInterface();
     73 #endif
     74     static void comInitialize();
     75     static void comUninitialize();
     76     static IMultiLanguage* getMultiLanguageInterface();
     77 #elif PLATFORM(WIN)
     78     IMLangFontLink2* getFontLinkInterface();
     79 #endif
     80 
     81     void getTraitsInFamily(const AtomicString&, Vector<unsigned>&);
     82 
     83     SimpleFontData* getCachedFontData(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName = false);
     84     SimpleFontData* getLastResortFallbackFont(const FontDescription&);
     85 
     86     void addClient(FontSelector*);
     87     void removeClient(FontSelector*);
     88 
     89     unsigned generation();
     90     void invalidate();
     91 
     92     size_t fontDataCount();
     93     size_t inactiveFontDataCount();
     94     void purgeInactiveFontData(int count = INT_MAX);
     95 
     96 private:
     97     FontCache();
     98     ~FontCache();
     99 
    100     // FIXME: This method should eventually be removed.
    101     FontPlatformData* getCachedFontPlatformData(const FontDescription&, const AtomicString& family, bool checkingAlternateName = false);
    102 
    103     // These methods are implemented by each platform.
    104     SimpleFontData* getSimilarFontPlatformData(const Font&);
    105     FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
    106 
    107     SimpleFontData* getCachedFontData(const FontPlatformData*);
    108 
    109     friend class SimpleFontData; // For getCachedFontData(const FontPlatformData*)
    110     friend class FontFallbackList;
    111 };
    112 
    113 // Get the global fontCache.
    114 FontCache* fontCache();
    115 
    116 }
    117 
    118 #endif
    119