Changeset 88081 in webkit


Ignore:
Timestamp:
Jun 3, 2011 5:22:09 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-06-03 Cary Clark <caryclark@google.com>

Reviewed by Eric Seidel.

Support FontCustomPlatformData on Skia-Mac-Chrome variant
https://bugs.webkit.org/show_bug.cgi?id=62040

Canvas text is only recognized by Skia if it is registered
by creating a new SkTypeface. Skia uses CGFont to measure
and render the glyphs, then takes care of managing the glyph
cache.

Skia on Mac Chrome is not yet enabled, so this change
does not affect existing code, and requires no new tests.

  • platform/graphics/mac/FontCustomPlatformData.cpp: (WebCore::RemoteFontStream::RemoteFontStream): (WebCore::RemoteFontStream::~RemoteFontStream): (WebCore::RemoteFontStream::rewind): (WebCore::RemoteFontStream::read): Turn the buffer into a stream. This is identical to the implementation in skia/FontCustomPlatformData.cpp. While that file could be modified instead of this one, it was simpler to add SkTypeface streaming to this instead of adding all CGFont support to the skia platform file.

(WebCore::FontCustomPlatformData::~FontCustomPlatformData):
Release the SkTypeface reference.

(WebCore::createFontCustomPlatformData):
Associate the buffer stream with a SkTypeface so Skia
can find the custom font data.

  • platform/graphics/mac/FontCustomPlatformData.h: (WebCore::FontCustomPlatformData::FontCustomPlatformData): Add a slot to hold the SkTypeface.
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r88080 r88081  
     12011-06-03  Cary Clark  <caryclark@google.com>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Support FontCustomPlatformData on Skia-Mac-Chrome variant
     6        https://bugs.webkit.org/show_bug.cgi?id=62040
     7
     8        Canvas text is only recognized by Skia if it is registered
     9        by creating a new SkTypeface. Skia uses CGFont to measure
     10        and render the glyphs, then takes care of managing the glyph
     11        cache.
     12
     13        Skia on Mac Chrome is not yet enabled, so this change
     14        does not affect existing code, and requires no new tests.
     15
     16        * platform/graphics/mac/FontCustomPlatformData.cpp:
     17        (WebCore::RemoteFontStream::RemoteFontStream):
     18        (WebCore::RemoteFontStream::~RemoteFontStream):
     19        (WebCore::RemoteFontStream::rewind):
     20        (WebCore::RemoteFontStream::read):
     21        Turn the buffer into a stream. This is identical to
     22        the implementation in skia/FontCustomPlatformData.cpp.
     23        While that file could be modified instead of this one,
     24        it was simpler to add SkTypeface streaming to this instead
     25        of adding all CGFont support to the skia platform file.
     26
     27        (WebCore::FontCustomPlatformData::~FontCustomPlatformData):
     28        Release the SkTypeface reference.
     29
     30        (WebCore::createFontCustomPlatformData):
     31        Associate the buffer stream with a SkTypeface so Skia
     32        can find the custom font data.
     33
     34        * platform/graphics/mac/FontCustomPlatformData.h:
     35        (WebCore::FontCustomPlatformData::FontCustomPlatformData):
     36        Add a slot to hold the SkTypeface.
     37
    1382011-06-03  Steve Falkenburg  <sfalken@apple.com>
    239
  • trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp

    r85036 r88081  
    2828#include <ApplicationServices/ApplicationServices.h>
    2929
     30#if USE(SKIA_ON_MAC_CHROME)
     31#include "SkStream.h"
     32#include "SkTypeface.h"
     33#endif
     34
    3035namespace WebCore {
     36
     37#if USE(SKIA_ON_MAC_CHROME)
     38class RemoteFontStream : public SkStream {
     39public:
     40    explicit RemoteFontStream(PassRefPtr<SharedBuffer> buffer)
     41        : m_buffer(buffer)
     42        , m_offset(0)
     43    {
     44    }
     45
     46    virtual ~RemoteFontStream()
     47    {
     48    }
     49
     50    virtual bool rewind()
     51    {
     52        m_offset = 0;
     53        return true;
     54    }
     55
     56    virtual size_t read(void* buffer, size_t size)
     57    {
     58        if (!buffer && !size) {
     59            // This is request for the length of the stream.
     60            return m_buffer->size();
     61        }
     62        // This is a request to read bytes or skip bytes (when buffer is 0).
     63        if (!m_buffer->data() || !m_buffer->size())
     64            return 0;
     65        size_t left = m_buffer->size() - m_offset;
     66        size_t bytesToConsume = std::min(left, size);
     67        if (buffer)
     68            std::memcpy(buffer, m_buffer->data() + m_offset, bytesToConsume);
     69        m_offset += bytesToConsume;
     70        return bytesToConsume;
     71    }
     72
     73private:
     74    RefPtr<SharedBuffer> m_buffer;
     75    size_t m_offset;
     76};
     77#endif
    3178
    3279FontCustomPlatformData::~FontCustomPlatformData()
     
    3582    if (m_atsContainer)
    3683        ATSFontDeactivate(m_atsContainer, NULL, kATSOptionFlagsDefault);
     84#endif
     85#if USE(SKIA_ON_MAC_CHROME)
     86    SkSafeUnref(m_typeface);
    3787#endif
    3888    CGFontRelease(m_cgFont);
     
    110160#endif // !defined(BUILDING_ON_LEOPARD)
    111161
    112     return new FontCustomPlatformData(containerRef, cgFontRef.releaseRef());
     162    FontCustomPlatformData* fontCustomPlatformData = new FontCustomPlatformData(containerRef, cgFontRef.releaseRef());
     163#if USE(SKIA_ON_MAC_CHROME)
     164    RemoteFontStream* stream = new RemoteFontStream(buffer);
     165    fontCustomPlatformData->m_typeface = SkTypeface::CreateFromStream(stream);
     166#endif
     167    return fontCustomPlatformData;
    113168}
    114169
  • trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.h

    r80582 r88081  
    3434typedef UInt32 ATSFontRef;
    3535
     36#if USE(SKIA_ON_MAC_CHROME)
     37struct SkTypeface;
     38#endif
     39
    3640namespace WebCore {
    3741
     
    4549        : m_atsContainer(container)
    4650        , m_cgFont(cgFont)
     51#if USE(SKIA_ON_MAC_CHROME)
     52        , m_typeface(0)
     53#endif
    4754    {
    4855    }
     
    5663    ATSFontContainerRef m_atsContainer;
    5764    CGFontRef m_cgFont;
     65#if USE(SKIA_ON_MAC_CHROME)
     66    SkTypeface* m_typeface;
     67#endif
    5868};
    5969
Note: See TracChangeset for help on using the changeset viewer.