| Differences between
and this patch
- a/WebCore/ChangeLog +25 lines
Lines 1-3 a/WebCore/ChangeLog_sec1
1
2009-08-07  Yong Li  <yong.li@torchmobile.com>
2
3
        WINCE PORT: use shared buffer for custom font data
4
        https://bugs.webkit.org/show_bug.cgi?id=27734
5
6
        Written by Yong Li  <yong.li@torchmobile.com>
7
        with style fixes by Joe Mason  <joe.mason@torchmobile.com>
8
9
        * loader/CachedFont.cpp:
10
          add WINCE to platforms using cached custom data
11
          change repeated list of platforms to a simple ifdef
12
        (WebCore::CachedFont::~CachedFont):
13
        (WebCore::CachedFont::ensureCustomFontData):
14
        (WebCore::CachedFont::platformDataFromCustomData):
15
        (WebCore::CachedFont::allClientsRemoved):
16
        * platform/graphics/opentype/OpenTypeUtilities.cpp:
17
        (WebCore::renameFont): implement for WinCE
18
        * platform/graphics/opentype/OpenTypeUtilities.h:
19
          build fixes
20
        * platform/graphics/wince/FontCustomPlatformData.cpp:
21
        (WebCore::setCustomFontCache): add accessor
22
        (WebCore::createFontCustomPlatformData): change param to SharedBuffer
23
        * platform/graphics/wince/FontCustomPlatformData.h:
24
          update function signatures
25
1
2009-08-06  Andras Becsi  <becsi.andras@stud.u-szeged.hu>
26
2009-08-06  Andras Becsi  <becsi.andras@stud.u-szeged.hu>
2
27
3
        Reviewed by Simon Hausmann.
28
        Reviewed by Simon Hausmann.
- a/WebCore/loader/CachedFont.cpp -5 / +10 lines
Lines 1-5 a/WebCore/loader/CachedFont.cpp_sec1
1
/*
1
/*
2
 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
2
 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3
 * Copyright (C) 2009 Torch Mobile, Inc.
3
 *
4
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
Lines 26-37 a/WebCore/loader/CachedFont.cpp_sec2
26
#include "config.h"
27
#include "config.h"
27
#include "CachedFont.h"
28
#include "CachedFont.h"
28
29
30
#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && PLATFORM(WIN_OS)) || PLATFORM(WINCE)
31
#define STORE_FONT_CUSTOM_PLATFORM_DATA
32
#endif
33
29
#include "Cache.h"
34
#include "Cache.h"
30
#include "CachedResourceClient.h"
35
#include "CachedResourceClient.h"
31
#include "CachedResourceClientWalker.h"
36
#include "CachedResourceClientWalker.h"
32
#include "DOMImplementation.h"
37
#include "DOMImplementation.h"
33
#include "FontPlatformData.h"
38
#include "FontPlatformData.h"
34
#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && PLATFORM(WIN_OS))
39
#ifdef STORE_FONT_CUSTOM_PLATFORM_DATA
35
#include "FontCustomPlatformData.h"
40
#include "FontCustomPlatformData.h"
36
#endif
41
#endif
37
#include "TextResourceDecoder.h"
42
#include "TextResourceDecoder.h"
Lines 60-66 CachedFont::CachedFont(const String &url) a/WebCore/loader/CachedFont.cpp_sec3
60
65
61
CachedFont::~CachedFont()
66
CachedFont::~CachedFont()
62
{
67
{
63
#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && PLATFORM(WIN_OS))
68
#ifdef STORE_FONT_CUSTOM_PLATFORM_DATA
64
    delete m_fontData;
69
    delete m_fontData;
65
#endif
70
#endif
66
}
71
}
Lines 98-104 void CachedFont::beginLoadIfNeeded(DocLoader* dl) a/WebCore/loader/CachedFont.cpp_sec4
98
103
99
bool CachedFont::ensureCustomFontData()
104
bool CachedFont::ensureCustomFontData()
100
{
105
{
101
#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && PLATFORM(WIN_OS))
106
#ifdef STORE_FONT_CUSTOM_PLATFORM_DATA
102
#if ENABLE(SVG_FONTS)
107
#if ENABLE(SVG_FONTS)
103
    ASSERT(!m_isSVGFont);
108
    ASSERT(!m_isSVGFont);
104
#endif
109
#endif
Lines 117-123 FontPlatformData CachedFont::platformDataFromCustomData(float size, bool bold, b a/WebCore/loader/CachedFont.cpp_sec5
117
    if (m_externalSVGDocument)
122
    if (m_externalSVGDocument)
118
        return FontPlatformData(size, bold, italic);
123
        return FontPlatformData(size, bold, italic);
119
#endif
124
#endif
120
#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && PLATFORM(WIN_OS))
125
#ifdef STORE_FONT_CUSTOM_PLATFORM_DATA
121
    ASSERT(m_fontData);
126
    ASSERT(m_fontData);
122
    return m_fontData->fontPlatformData(static_cast<int>(size), bold, italic, renderingMode);
127
    return m_fontData->fontPlatformData(static_cast<int>(size), bold, italic, renderingMode);
123
#else
128
#else
Lines 173-179 SVGFontElement* CachedFont::getSVGFontById(const String& fontName) const a/WebCore/loader/CachedFont.cpp_sec6
173
178
174
void CachedFont::allClientsRemoved()
179
void CachedFont::allClientsRemoved()
175
{
180
{
176
#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && PLATFORM(WIN_OS))
181
#ifdef STORE_FONT_CUSTOM_PLATFORM_DATA
177
    if (m_fontData) {
182
    if (m_fontData) {
178
        delete m_fontData;
183
        delete m_fontData;
179
        m_fontData = 0;
184
        m_fontData = 0;
- a/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp -1 / +73 lines
Lines 1-5 a/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp_sec1
1
/*
1
/*
2
 * Copyright (C) 2008, 2009 Apple Inc.  All rights reserved.
2
 * Copyright (C) 2008, 2009 Apple Inc.  All rights reserved.
3
 * Copyright (C) 2009 Torch Mobile, Inc.
3
 *
4
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
Lines 69-75 struct TableDirectoryEntry { a/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp_sec2
69
    BigEndianULong length;
70
    BigEndianULong length;
70
};
71
};
71
72
72
#if !PLATFORM(CG)
73
#if PLATFORM(WINCE)
74
// Need to use #define instead of typedef due to conflict
75
#define Fixed int32_t
76
#elif !PLATFORM(CG)
73
// Fixed type is not defined on non-CG platforms. |version| in sfntHeader
77
// Fixed type is not defined on non-CG platforms. |version| in sfntHeader
74
// and headTable and |fontRevision| in headTable are of Fixed, but they're
78
// and headTable and |fontRevision| in headTable are of Fixed, but they're
75
// not actually refered to anywhere. Therefore, we just have to match
79
// not actually refered to anywhere. Therefore, we just have to match
Lines 339-344 bool getEOTHeader(SharedBuffer* fontData, EOTHeader& eotHeader, size_t& overlayD a/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp_sec3
339
    return true;
343
    return true;
340
}
344
}
341
345
346
#if PLATFORM(WINCE)
347
bool renameFont(SharedBuffer* fontData, const String& fontName)
348
{
349
    size_t originalDataSize = fontData->size();
350
    if (originalDataSize < offsetof(sfntHeader, tables))
351
        return false;
352
353
    const sfntHeader* sfnt = reinterpret_cast<const sfntHeader*>(fontData->data());
354
355
    if (originalDataSize < offsetof(sfntHeader, tables) + sfnt->numTables * sizeof(TableDirectoryEntry))
356
        return false;
357
358
    unsigned t;
359
    for (t = 0; t < sfnt->numTables; ++t) {
360
        if (sfnt->tables[t].tag == 'name')
361
            break;
362
    }
363
    if (t == sfnt->numTables)
364
        return false;
365
366
    const int nameRecordCount = 5;
367
368
    // Rounded up to a multiple of 4 to simplify the checksum calculation.
369
    size_t nameTableSize = ((offsetof(nameTable, nameRecords) + nameRecordCount * sizeof(nameRecord) + fontName.length() * sizeof(UChar)) & ~3) + 4;
370
371
    Vector<char> rewrittenFontData(fontData->size() + nameTableSize);
372
    char* data = rewrittenFontData.data();
373
    memcpy(data, fontData->data(), originalDataSize);
374
375
    // Make the table directory entry point to the new 'name' table.
376
    sfntHeader* rewrittenSfnt = reinterpret_cast<sfntHeader*>(data);
377
    rewrittenSfnt->tables[t].length = nameTableSize;
378
    rewrittenSfnt->tables[t].offset = originalDataSize;
379
380
    // Write the new 'name' table after the original font data.
381
    nameTable* name = reinterpret_cast<nameTable*>(data + originalDataSize);
382
    name->format = 0;
383
    name->count = nameRecordCount;
384
    name->stringOffset = offsetof(nameTable, nameRecords) + nameRecordCount * sizeof(nameRecord);
385
    for (unsigned i = 0; i < nameRecordCount; ++i) {
386
        name->nameRecords[i].platformID = 3;
387
        name->nameRecords[i].encodingID = 1;
388
        name->nameRecords[i].languageID = 0x0409;
389
        name->nameRecords[i].offset = 0;
390
        name->nameRecords[i].length = fontName.length() * sizeof(UChar);
391
    }
392
393
    // The required 'name' record types: Family, Style, Unique, Full and PostScript.
394
    name->nameRecords[0].nameID = 1;
395
    name->nameRecords[1].nameID = 2;
396
    name->nameRecords[2].nameID = 3;
397
    name->nameRecords[3].nameID = 4;
398
    name->nameRecords[4].nameID = 6;
399
400
    for (unsigned i = 0; i < fontName.length(); ++i)
401
        reinterpret_cast<BigEndianUShort*>(data + originalDataSize + name->stringOffset)[i] = fontName[i];
402
403
    // Update the table checksum in the directory entry.
404
    rewrittenSfnt->tables[t].checkSum = 0;
405
    for (unsigned i = 0; i * sizeof(BigEndianULong) < nameTableSize; ++i)
406
        rewrittenSfnt->tables[t].checkSum = rewrittenSfnt->tables[t].checkSum + reinterpret_cast<BigEndianULong*>(name)[i];
407
408
    fontData->clear();
409
    fontData->append(rewrittenFontData.data(), rewrittenFontData.size());
410
    return true;
411
}
412
#else
342
HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName)
413
HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName)
343
{
414
{
344
    size_t originalDataSize = fontData->size();
415
    size_t originalDataSize = fontData->size();
Lines 404-408 HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName) a/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp_sec4
404
475
405
    return fontHandle;
476
    return fontHandle;
406
}
477
}
478
#endif
407
479
408
}
480
}
- a/WebCore/platform/graphics/opentype/OpenTypeUtilities.h +7 lines
Lines 1-5 a/WebCore/platform/graphics/opentype/OpenTypeUtilities.h_sec1
1
/*
1
/*
2
 * Copyright (C) 2008, 2009 Apple Inc.  All rights reserved.
2
 * Copyright (C) 2008, 2009 Apple Inc.  All rights reserved.
3
 * Copyright (C) 2009 Torch Mobile, Inc.
3
 *
4
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
Lines 27-33 a/WebCore/platform/graphics/opentype/OpenTypeUtilities.h_sec2
27
#define OpenTypeUtilities_h
28
#define OpenTypeUtilities_h
28
29
29
#include "PlatformString.h"
30
#include "PlatformString.h"
31
#if !PLATFORM(WINCE)
30
#include <wtf/Forward.h>
32
#include <wtf/Forward.h>
33
#endif
31
34
32
namespace WebCore {
35
namespace WebCore {
33
36
Lines 35-40 struct BigEndianUShort; a/WebCore/platform/graphics/opentype/OpenTypeUtilities.h_sec3
35
struct EOTPrefix;
38
struct EOTPrefix;
36
class SharedBuffer;
39
class SharedBuffer;
37
40
41
#if PLATFORM(WINCE)
42
typedef unsigned __int8 UInt8;
43
#endif
44
38
struct EOTHeader {
45
struct EOTHeader {
39
    EOTHeader();
46
    EOTHeader();
40
47
- a/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp -3 / +9 lines
Lines 33-38 static CustomFontCache* g_customFontCache = 0; a/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp_sec1
33
33
34
bool renameFont(SharedBuffer* fontData, const String& fontName);
34
bool renameFont(SharedBuffer* fontData, const String& fontName);
35
35
36
void setCustomFontCache(CustomFontCache* cache)
37
{
38
    g_customFontCache = cache;
39
}
40
36
FontCustomPlatformData::~FontCustomPlatformData()
41
FontCustomPlatformData::~FontCustomPlatformData()
37
{
42
{
38
    if (g_customFontCache && !m_name.isEmpty())
43
    if (g_customFontCache && !m_name.isEmpty())
Lines 66-76 static String createUniqueFontName() a/WebCore/platform/graphics/wince/FontCustomPlatformData.cpp_sec2
66
    return fontName.replace('/', '_');
71
    return fontName.replace('/', '_');
67
}
72
}
68
73
69
FontCustomPlatformData* createFontCustomPlatformData(CachedFont* cachedFont)
74
FontCustomPlatformData* createFontCustomPlatformData(const SharedBuffer* buffer)
70
{
75
{
71
    if (g_customFontCache && cachedFont->CachedResource::data()) {
76
    if (g_customFontCache) {
72
        String fontName = createUniqueFontName();
77
        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()))
74
            return new FontCustomPlatformData(fontName);
80
            return new FontCustomPlatformData(fontName);
75
    }
81
    }
76
    return 0;
82
    return 0;
- a/WebCore/platform/graphics/wince/FontCustomPlatformData.h -3 / +3 lines
Lines 32-38 namespace WebCore { a/WebCore/platform/graphics/wince/FontCustomPlatformData.h_sec1
32
32
33
    class CustomFontCache {
33
    class CustomFontCache {
34
    public:
34
    public:
35
        virtual bool registerFont(const String& fontName, CachedFont*) = 0;
35
        virtual bool registerFont(const String& fontName, const SharedBuffer*) = 0;
36
        virtual void unregisterFont(const String& fontName) = 0;
36
        virtual void unregisterFont(const String& fontName) = 0;
37
    };
37
    };
38
38
Lines 48-55 namespace WebCore { a/WebCore/platform/graphics/wince/FontCustomPlatformData.h_sec2
48
        String m_name;
48
        String m_name;
49
    };
49
    };
50
50
51
    FontCustomPlatformData* createFontCustomPlatformData(CachedFont*);
51
    FontCustomPlatformData* createFontCustomPlatformData(const SharedBuffer*);
52
52
    void setCustomFontCache(CustomFontCache*);
53
}
53
}
54
54
55
#endif
55
#endif

Return to Bug 27734