[webkit-dev] FontPlatformData, FontCache and HashMap

Stephan Assmus superstippi at gmx.de
Sun Feb 21 01:06:40 PST 2010

On 2010-02-21 at 06:02:01 [+0100], n179911 <n179911 at gmail.com> wrote:
> I have a related question about SimpleFontData and FontPlatformData.
> When does Webkit create a FontPlatformData and SimpleFontData?
> I too put debug printfs in these classes constructors. And I see
> Webkit creates different FontPlatformData and SimpleFontData for same
> font family and same font size.

It's all in FontCache.cpp. There is two levels of caching, that's why you see 
two FontPlatformData objects being created. One is created via the 
createFontPlatformData() that you have to implement. This object is placed in 
the hash map gFontPlatformDataCache in the method 
FontCache::getCachedFontPlatformData(). SimpleFontData objects are created in 
FontCache::getCachedFontData, which use the previously created 
FontPlatformData in the FontPlatformData copy constructor that you have to 
write, for the SimpleFontData member m_platformData. This SimpleFontData gets 
put into the gFontDataCache hash map and from it you will later retrieve the 
native font.

FontPlatformData should to be implemented such that it maintains an internal 
object which wraps your platform native font with reference counting, so that 
copy consructor, operator=() and operator==() become cheap operations. The Qt 
implementation makes it clear how this has to work. What is also important is 
that you generate the same hash value for two different instances of your 
private native font wrapper which present the same logical font.

Best regards,

More information about the webkit-dev mailing list