Source/WebCore/ChangeLog

 12012-04-01 Koji Ishii <kojiishi@gmail.com>
 2
 3 Cache support for OpenTypeVerticalData
 4 https://bugs.webkit.org/show_bug.cgi?id=81332
 5
 6 This patch adds FontCache to cache OpenTypeVerticalData class
 7 instances that was introduced in bug 81326.
 8
 9 We need one instance of the class per OpenType font file, and we don't
 10 have a class to hold such instances today.
 11
 12 ENABLE_OPENTYPE_VERTICAL isn't enabled for any platforms yet, so this
 13 patch isn't on any code path. Apple Windows port (bug 48459) is going
 14 to use this code, and probably Chromium (51450, 69282) as well.
 15
 16 "FIXME" comment in SimpleFontData.h will be implemented in 48459.
 17
 18 Reviewed by NOBODY (OOPS!).
 19
 20 No new tests are required. No behavior changes.
 21
 22 * platform/graphics/FontCache.cpp:
 23 (WebCore::FontCache::getCachedFontPlatformData): Ignore leading "@" on Windows to disable Windows feature for vertical flow.
 24 (WebCore):
 25 (WebCore::FontCache::getVerticalData): Get cached OpenTypeVerticalData from FontPlatformData, or crete one.
 26 (WebCore::FontCache::purgeInactiveFontData): Purge inactive OpenTypeVerticalData.
 27 * platform/graphics/FontCache.h:
 28 (WebCore):
 29 * platform/graphics/SimpleFontData.h:
 30 (SimpleFontData):
 31 (WebCore::SimpleFontData::verticalData): A dummy implementation for purgeInactiveFontData() to work.
 32 * platform/graphics/opentype/OpenTypeVerticalData.h: Added m_inFontCache for mark & sweep.
 33 (OpenTypeVerticalData):
 34
1352012-03-30 Koji Ishii <kojiishi@gmail.com>
236
337 Vertical alternate glyph (GSUB) support for OpenTypeVerticalData

Source/WebCore/platform/graphics/FontCache.cpp

3535#include "FontPlatformData.h"
3636#include "FontSelector.h"
3737#include "GlyphPageTreeNode.h"
 38#if ENABLE(OPENTYPE_VERTICAL)
 39#include "OpenTypeVerticalData.h"
 40#endif
3841#include "WebKitFontFamilyNames.h"
3942#include <wtf/HashMap.h>
4043#include <wtf/ListHashSet.h>
4144#include <wtf/StdLibExtras.h>
 45#include <wtf/text/AtomicStringHash.h>
4246#include <wtf/text/StringHash.h>
4347
4448using namespace WTF;

@@FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& fo
183187 const AtomicString& familyName,
184188 bool checkingAlternateName)
185189{
 190#if OS(WINDOWS) && ENABLE(OPENTYPE_VERTICAL)
 191 // Leading "@" in the font name enables Windows vertical flow flag for the font.
 192 // Because we do vertical flow by ourselves, we don't want to use the Windows feature.
 193 // IE disregards "@" regardless of the orientatoin, so we follow the behavior.
 194 if (!familyName.isEmpty() && familyName[0] == '@')
 195 return getCachedFontPlatformData(fontDescription, AtomicString(familyName.impl()->substring(1)), checkingAlternateName);
 196#endif
 197
186198 if (!gFontPlatformDataCache) {
187199 gFontPlatformDataCache = new FontPlatformDataCache;
188200 platformInit();

@@FontPlatformData* FontCache::getCachedFontPlatformData(const FontDescription& fo
216228 return result;
217229}
218230
 231#if ENABLE(OPENTYPE_VERTICAL)
 232typedef HashMap<AtomicString, OpenTypeVerticalData*> FontVerticalDataCache;
 233
 234static FontVerticalDataCache* gFontVerticalDataCache = 0;
 235
 236OpenTypeVerticalData* FontCache::getVerticalData(const AtomicString& key, const FontPlatformData& platformData)
 237{
 238 if (key.isEmpty())
 239 return 0;
 240
 241 if (gFontVerticalDataCache) {
 242 FontVerticalDataCache::iterator result = gFontVerticalDataCache->find(key);
 243 if (result != gFontVerticalDataCache->end())
 244 return result.get()->second;
 245 } else
 246 gFontVerticalDataCache = new FontVerticalDataCache;
 247
 248 OpenTypeVerticalData* verticalData = new OpenTypeVerticalData(platformData);
 249 if (!verticalData->isOpenType()) {
 250 delete verticalData;
 251 verticalData = 0; // Put 0 in cache to mark that this isn't an OpenType font.
 252 }
 253 gFontVerticalDataCache->set(key, verticalData);
 254 return verticalData;
 255}
 256#endif
 257
219258struct FontDataCacheKeyHash {
220259 static unsigned hash(const FontPlatformData& platformData)
221260 {

@@void FontCache::purgeInactiveFontData(int count)
381420 delete gFontPlatformDataCache->take(keysToRemove[i]);
382421 }
383422
 423#if ENABLE(OPENTYPE_VERTICAL)
 424 if (gFontVerticalDataCache) {
 425 // Mark & sweep unused verticalData
 426 FontVerticalDataCache::iterator verticalDataEnd = gFontVerticalDataCache->end();
 427 for (FontVerticalDataCache::iterator verticalData = gFontVerticalDataCache->begin(); verticalData != verticalDataEnd; ++verticalData) {
 428 if (verticalData->second)
 429 verticalData->second->m_inFontCache = false;
 430 }
 431 FontDataCache::iterator fontDataEnd = gFontDataCache->end();
 432 for (FontDataCache::iterator fontData = gFontDataCache->begin(); fontData != fontDataEnd; ++fontData) {
 433 OpenTypeVerticalData* verticalData = const_cast<OpenTypeVerticalData*>(fontData->second.first->verticalData());
 434 if (verticalData)
 435 verticalData->m_inFontCache = true;
 436 }
 437 Vector<AtomicString> keysToRemove;
 438 keysToRemove.reserveInitialCapacity(gFontVerticalDataCache->size());
 439 for (FontVerticalDataCache::iterator verticalData = gFontVerticalDataCache->begin(); verticalData != verticalDataEnd; ++verticalData) {
 440 if (!verticalData->second || !verticalData->second->m_inFontCache)
 441 keysToRemove.append(verticalData->first);
 442 }
 443 for (size_t i = 0, count = keysToRemove.size(); i < count; ++i)
 444 delete gFontVerticalDataCache->take(keysToRemove[i]);
 445 }
 446#endif
 447
384448 isPurging = false;
385449}
386450

Source/WebCore/platform/graphics/FontCache.h

@@class FontPlatformData;
4949class FontData;
5050class FontDescription;
5151class FontSelector;
 52#if ENABLE(OPENTYPE_VERTICAL)
 53class OpenTypeVerticalData;
 54#endif
5255class SimpleFontData;
5356
5457class FontCache {

@@public:
104107 SimpleFontData* fontDataFromDescriptionAndLogFont(const FontDescription&, ShouldRetain, const LOGFONT& font, wchar_t* outFontFamilyName);
105108#endif
106109
 110#if ENABLE(OPENTYPE_VERTICAL)
 111 OpenTypeVerticalData* getVerticalData(const AtomicString&, const FontPlatformData&);
 112#endif
 113
107114private:
108115 FontCache();
109116 ~FontCache();

Source/WebCore/platform/graphics/SimpleFontData.h

3131#include "FloatRect.h"
3232#include "GlyphMetricsMap.h"
3333#include "GlyphPageTreeNode.h"
 34#if ENABLE(OPENTYPE_VERTICAL)
 35#include "OpenTypeVerticalData.h"
 36#endif
3437#include "TypesettingFeatures.h"
3538#include <wtf/OwnPtr.h>
3639#include <wtf/PassOwnPtr.h>

@@public:
8891 virtual ~SimpleFontData();
8992
9093 const FontPlatformData& platformData() const { return m_platformData; }
 94#if ENABLE(OPENTYPE_VERTICAL)
 95 const OpenTypeVerticalData* verticalData() const { return 0; } // FIXME: implement
 96#endif
9197
9298 SimpleFontData* smallCapsFontData(const FontDescription&) const;
9399 SimpleFontData* emphasisMarkFontData(const FontDescription&) const;

Source/WebCore/platform/graphics/opentype/OpenTypeVerticalData.h

@@private:
5656 Vector<int16_t> m_topSideBearings;
5757 int16_t m_defaultVertOriginY;
5858 HashMap<Glyph, int16_t> m_vertOriginY;
 59
 60 friend class FontCache;
 61 bool m_inFontCache : 1;
5962};
6063
6164} // namespace WebCore