Changeset 46885 in webkit


Ignore:
Timestamp:
Aug 6, 2009 10:39:44 PM (15 years ago)
Author:
abarth@webkit.org
Message:

2009-08-06 Yusuke Sato <yusukes@chromium.org>

Reviewed by David Levin.

Chromium Linux: add support for @font-face
https://bugs.webkit.org/show_bug.cgi?id=28015

  • loader/CachedFont.cpp: (WebCore::CachedFont::~CachedFont): (WebCore::CachedFont::ensureCustomFontData): (WebCore::CachedFont::platformDataFromCustomData): (WebCore::CachedFont::allClientsRemoved):

Modified #ifdefs so that chromium linux can load remote fonts.

  • platform/graphics/chromium/FontCustomPlatformData.cpp: (WebCore::FontCustomPlatformData::~FontCustomPlatformData): (WebCore::FontCustomPlatformData::fontPlatformData): (WebCore::createFontCustomPlatformData):

Create SkTypeface for a web font by calling SkTypeface::CreateFromStream function.

(WebCore::RemoteFontStream::RemoteFontStream):
(WebCore::RemoteFontStream::~RemoteFontStream):
(WebCore::RemoteFontStream::rewind):
(WebCore::RemoteFontStream::read):

New class that implements SkStream interface and wraps wtf's SharedBuffer.

  • platform/graphics/chromium/FontCustomPlatformData.h: (WebCore::FontCustomPlatformData::FontCustomPlatformData):

Added member variables for Linux.

Location:
trunk/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r46884 r46885  
     12009-08-06  Yusuke Sato  <yusukes@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        Chromium Linux: add support for @font-face
     6        https://bugs.webkit.org/show_bug.cgi?id=28015
     7       
     8        * loader/CachedFont.cpp:
     9        (WebCore::CachedFont::~CachedFont):
     10        (WebCore::CachedFont::ensureCustomFontData):
     11        (WebCore::CachedFont::platformDataFromCustomData):
     12        (WebCore::CachedFont::allClientsRemoved):
     13
     14        Modified #ifdefs so that chromium linux can load remote fonts.
     15       
     16        * platform/graphics/chromium/FontCustomPlatformData.cpp:
     17        (WebCore::FontCustomPlatformData::~FontCustomPlatformData):
     18        (WebCore::FontCustomPlatformData::fontPlatformData):
     19        (WebCore::createFontCustomPlatformData):
     20
     21        Create SkTypeface for a web font by calling SkTypeface::CreateFromStream function.
     22       
     23        (WebCore::RemoteFontStream::RemoteFontStream):
     24        (WebCore::RemoteFontStream::~RemoteFontStream):
     25        (WebCore::RemoteFontStream::rewind):
     26        (WebCore::RemoteFontStream::read):
     27
     28        New class that implements SkStream interface and wraps wtf's SharedBuffer.
     29       
     30        * platform/graphics/chromium/FontCustomPlatformData.h:
     31        (WebCore::FontCustomPlatformData::FontCustomPlatformData):
     32
     33        Added member variables for Linux.
     34       
    1352009-08-06  Yong Li  <yong.li@torchmobile.com>
    236
  • trunk/WebCore/loader/CachedFont.cpp

    r44749 r46885  
    3232#include "DOMImplementation.h"
    3333#include "FontPlatformData.h"
    34 #if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && PLATFORM(WIN_OS))
     34#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && (PLATFORM(WIN_OS) || PLATFORM(LINUX)))
    3535#include "FontCustomPlatformData.h"
    3636#endif
     
    6161CachedFont::~CachedFont()
    6262{
    63 #if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && PLATFORM(WIN_OS))
     63#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && (PLATFORM(WIN_OS) || PLATFORM(LINUX)))
    6464    delete m_fontData;
    6565#endif
     
    9999bool CachedFont::ensureCustomFontData()
    100100{
    101 #if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && PLATFORM(WIN_OS))
     101#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && (PLATFORM(WIN_OS) || PLATFORM(LINUX)))
    102102#if ENABLE(SVG_FONTS)
    103103    ASSERT(!m_isSVGFont);
     
    118118        return FontPlatformData(size, bold, italic);
    119119#endif
    120 #if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && PLATFORM(WIN_OS))
     120#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && (PLATFORM(WIN_OS) || PLATFORM(LINUX)))
    121121    ASSERT(m_fontData);
    122122    return m_fontData->fontPlatformData(static_cast<int>(size), bold, italic, renderingMode);
     
    174174void CachedFont::allClientsRemoved()
    175175{
    176 #if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && PLATFORM(WIN_OS))
     176#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(GTK) || (PLATFORM(CHROMIUM) && (PLATFORM(WIN_OS) || PLATFORM(LINUX)))
    177177    if (m_fontData) {
    178178        delete m_fontData;
  • trunk/WebCore/platform/graphics/chromium/FontCustomPlatformData.cpp

    r42060 r46885  
    3737#include "ChromiumBridge.h"
    3838#include "OpenTypeUtilities.h"
     39#elif PLATFORM(LINUX)
     40#include "SkStream.h"
    3941#endif
    4042
     
    4749#include <t2embapi.h>
    4850#pragma comment(lib, "t2embed")
     51#elif PLATFORM(LINUX)
     52#include <cstring>
    4953#endif
    5054
     
    6165            RemoveFontMemResourceEx(m_fontReference);
    6266    }
     67#elif PLATFORM(LINUX)
     68    if (m_fontReference)
     69        m_fontReference->unref();
    6370#endif
    6471}
     
    103110    HFONT hfont = CreateFontIndirect(&logFont);
    104111    return FontPlatformData(hfont, size);
     112#elif PLATFORM(LINUX)
     113    ASSERT(m_fontReference);
     114    return FontPlatformData(m_fontReference, size, bold && !m_fontReference->isBold(), italic && !m_fontReference->isItalic());
    105115#else
    106116    notImplemented();
     
    187197#endif
    188198
     199#if PLATFORM(LINUX)
     200class RemoteFontStream : public SkStream {
     201public:
     202    explicit RemoteFontStream(PassRefPtr<SharedBuffer> buffer)
     203        : m_buffer(buffer)
     204        , m_offset(0)
     205    {
     206    }
     207
     208    virtual ~RemoteFontStream()
     209    {
     210    }
     211
     212    virtual bool rewind()
     213    {
     214        m_offset = 0;
     215        return true;
     216    }
     217
     218    virtual size_t read(void* buffer, size_t size)
     219    {
     220        if (!buffer && !size) {
     221            // This is request for the length of the stream.
     222            return m_buffer->size();
     223        }
     224        if (!buffer) {
     225            // This is a request to skip bytes. This operation is not supported.
     226            return 0;
     227        }
     228        // This is a request to read bytes.
     229        if (!m_buffer->data() || !m_buffer->size())
     230            return 0;
     231        size_t left = m_buffer->size() - m_offset;
     232        size_t toRead = (left > size) ? size : left;
     233        std::memcpy(buffer, m_buffer->data() + m_offset, toRead);
     234        m_offset += toRead;
     235        return toRead;
     236    }
     237
     238private:
     239    RefPtr<SharedBuffer> m_buffer;
     240    size_t m_offset;
     241};
     242#endif
     243
    189244FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
    190245{
     
    224279
    225280    return new FontCustomPlatformData(fontReference, fontName);
     281#elif PLATFORM(LINUX)
     282    RemoteFontStream stream(buffer);
     283    SkTypeface* typeface = SkTypeface::CreateFromStream(&stream);
     284    if (!typeface)
     285        return 0;
     286    return new FontCustomPlatformData(typeface);
    226287#else
    227     notImplemented();;
     288    notImplemented();
    228289    return 0;
    229290#endif
  • trunk/WebCore/platform/graphics/chromium/FontCustomPlatformData.h

    r39875 r46885  
    3333#define FontCustomPlatformData_h
    3434
     35#include "FontRenderingMode.h"
    3536#include <wtf/Noncopyable.h>
    3637
    3738#if PLATFORM(WIN_OS)
    38 #include "FontRenderingMode.h"
    3939#include "PlatformString.h"
    4040#include <windows.h>
     41#elif PLATFORM(LINUX)
     42#include "SkTypeface.h"
    4143#endif
    4244
     
    5254        , m_name(name)
    5355    {}
     56#elif PLATFORM(LINUX)
     57    explicit FontCustomPlatformData(SkTypeface* typeface)
     58        : m_fontReference(typeface)
     59    {}
    5460#endif
    5561
     
    6268    HANDLE m_fontReference;
    6369    String m_name;
     70#elif PLATFORM(LINUX)
     71    SkTypeface* m_fontReference;
    6472#endif
    6573};
Note: See TracChangeset for help on using the changeset viewer.