Changeset 47975 in webkit


Ignore:
Timestamp:
Sep 2, 2009 9:37:52 AM (15 years ago)
Author:
yong.li@torchmobile.com
Message:

2009-09-02 Yong Li <yong.li@torchmobile.com>

Reviewed by Adam Barth.

WINCE PORT: use shared buffer for custom font data
https://bugs.webkit.org/show_bug.cgi?id=27734

Refactored by Joe Mason <joe.mason@torchmobile.com>

  • loader/CachedFont.cpp: add WINCE to platforms using cached custom data
  • platform/graphics/opentype/OpenTypeUtilities.cpp: (WebCore::renameFont): implement for WinCE
  • platform/graphics/opentype/OpenTypeUtilities.h: build fixes
  • platform/graphics/wince/FontCustomPlatformData.cpp: (WebCore::setCustomFontCache): add accessor (WebCore::createFontCustomPlatformData): change param to SharedBuffer
  • platform/graphics/wince/FontCustomPlatformData.h: update function signatures
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r47974 r47975  
     12009-09-02 Yong Li <yong.li@torchmobile.com>
     2
     3        Reviewed by Adam Barth.
     4
     5        WINCE PORT: use shared buffer for custom font data
     6        https://bugs.webkit.org/show_bug.cgi?id=27734
     7
     8        Refactored by Joe Mason <joe.mason@torchmobile.com>
     9
     10        * loader/CachedFont.cpp:
     11        add WINCE to platforms using cached custom data
     12        * platform/graphics/opentype/OpenTypeUtilities.cpp:
     13        (WebCore::renameFont): implement for WinCE
     14        * platform/graphics/opentype/OpenTypeUtilities.h:
     15        build fixes
     16        * platform/graphics/wince/FontCustomPlatformData.cpp:
     17        (WebCore::setCustomFontCache): add accessor
     18        (WebCore::createFontCustomPlatformData): change param to SharedBuffer
     19        * platform/graphics/wince/FontCustomPlatformData.h:
     20        update function signatures
     21 
    1222009-09-02 Yong Li <yong.li@torchmobile.com>
    223
  • trunk/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp

    r42060 r47975  
    11/*
    22 * Copyright (C) 2008, 2009 Apple Inc.  All rights reserved.
     3 * Copyright (C) 2009 Torch Mobile, Inc.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    340341}
    341342
    342 HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName)
     343// code shared by renameFont and renameAndActivateFont
     344// adds fontName to the font table in fontData, and writes the new font table to rewrittenFontTable
     345// returns the size of the name table (which is used by renameAndActivateFont), or 0 on early abort
     346static size_t renameFontInternal(SharedBuffer* fontData, const String& fontName, Vector<char> &rewrittenFontData)
    343347{
    344348    size_t originalDataSize = fontData->size();
     
    358362    size_t nameTableSize = ((offsetof(nameTable, nameRecords) + nameRecordCount * sizeof(nameRecord) + fontName.length() * sizeof(UChar)) & ~3) + 4;
    359363
    360     Vector<char> rewrittenFontData(fontData->size() + nameTableSize);
     364    rewrittenFontData.resize(fontData->size() + nameTableSize);
    361365    char* data = rewrittenFontData.data();
    362366    memcpy(data, fontData->data(), originalDataSize);
     
    395399        rewrittenSfnt->tables[t].checkSum = rewrittenSfnt->tables[t].checkSum + reinterpret_cast<BigEndianULong*>(name)[i];
    396400
     401    return nameTableSize;
     402}
     403
     404#if PLATFORM(WINCE)
     405// AddFontMemResourceEx does not exist on WinCE, so we must handle the font data manually
     406// This function just renames the font and overwrites the old font data with the new
     407bool renameFont(SharedBuffer* fontData, const String& fontName)
     408{
     409    // abort if the data is too small to be a font header with a "tables" entry
     410    if (fontData->size() < offsetof(sfntHeader, tables))
     411        return false;
     412
     413    // abort if the data is too small to hold all the tables specified in the header
     414    const sfntHeader* header = reinterpret_cast<const sfntHeader*>(fontData->data());
     415    if (fontData->size() < offsetof(sfntHeader, tables) + header->numTables * sizeof(TableDirectoryEntry))
     416        return false;
     417
     418    Vector<char> rewrittenFontData;
     419    if (!renameFontInternal(fontData, fontName, rewrittenFontData))
     420        return false;
     421
     422    fontData->clear();
     423    fontData->append(rewrittenFontData.data(), rewrittenFontData.size());
     424    return true;
     425}
     426#else
     427// Rename the font and install the new font data into the system
     428HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName)
     429{
     430    Vector<char> rewrittenFontData;
     431    size_t nameTableSize = renameFontInternal(fontData, fontName, rewrittenFontData);
     432    if (!nameTableSize)
     433        return 0;
     434
    397435    DWORD numFonts = 0;
    398     HANDLE fontHandle = AddFontMemResourceEx(data, originalDataSize + nameTableSize, 0, &numFonts);
     436    HANDLE fontHandle = AddFontMemResourceEx(rewrittenFontData.data(), fontData->size() + nameTableSize, 0, &numFonts);
    399437
    400438    if (fontHandle && numFonts != 1) {
     
    405443    return fontHandle;
    406444}
    407 
    408 }
     445#endif
     446
     447}
  • trunk/WebCore/platform/graphics/opentype/OpenTypeUtilities.h

    r42060 r47975  
    11/*
    22 * Copyright (C) 2008, 2009 Apple Inc.  All rights reserved.
     3 * Copyright (C) 2009 Torch Mobile, Inc.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3637class SharedBuffer;
    3738
     39#if PLATFORM(WINCE)
     40typedef unsigned __int8 UInt8;
     41#endif
     42
    3843struct EOTHeader {
    3944    EOTHeader();
  • trunk/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp

    r46196 r47975  
    3434bool renameFont(SharedBuffer* fontData, const String& fontName);
    3535
     36void setCustomFontCache(CustomFontCache* cache)
     37{
     38    g_customFontCache = cache;
     39}
     40
    3641FontCustomPlatformData::~FontCustomPlatformData()
    3742{
     
    6772}
    6873
    69 FontCustomPlatformData* createFontCustomPlatformData(CachedFont* cachedFont)
     74FontCustomPlatformData* createFontCustomPlatformData(const SharedBuffer* buffer)
    7075{
    71     if (g_customFontCache && cachedFont->CachedResource::data()) {
     76    if (g_customFontCache) {
    7277        String fontName = createUniqueFontName();
    73         if (renameFont(cachedFont->CachedResource::data(), fontName) && g_customFontCache->registerFont(fontName, cachedFont))
     78        RefPtr<SharedBuffer> localBuffer = SharedBuffer::create(buffer->data(), buffer->size());
     79        if (renameFont(localBuffer.get(), fontName) && g_customFontCache->registerFont(fontName, localBuffer.get()))
    7480            return new FontCustomPlatformData(fontName);
    7581    }
  • trunk/WebCore/platform/graphics/wince/FontCustomPlatformData.h

    r46196 r47975  
    3333    class CustomFontCache {
    3434    public:
    35         virtual bool registerFont(const String& fontName, CachedFont*) = 0;
     35        virtual bool registerFont(const String& fontName, const SharedBuffer*) = 0;
    3636        virtual void unregisterFont(const String& fontName) = 0;
    3737    };
     
    4949    };
    5050
    51     FontCustomPlatformData* createFontCustomPlatformData(CachedFont*);
    52 
     51    FontCustomPlatformData* createFontCustomPlatformData(const SharedBuffer*);
     52    void setCustomFontCache(CustomFontCache*);
    5353}
    5454
Note: See TracChangeset for help on using the changeset viewer.