This source file includes following definitions.
- m_typeface
- fontPlatformData
- create
- supportsFormat
#include "config.h"
#include "platform/fonts/FontCustomPlatformData.h"
#include "platform/SharedBuffer.h"
#include "platform/fonts/FontPlatformData.h"
#include "platform/fonts/opentype/OpenTypeSanitizer.h"
#include "third_party/skia/include/core/SkStream.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "wtf/PassOwnPtr.h"
#include <ApplicationServices/ApplicationServices.h>
namespace WebCore {
FontCustomPlatformData::FontCustomPlatformData(CGFontRef cgFont, PassRefPtr<SkTypeface> typeface)
: m_cgFont(AdoptCF, cgFont)
, m_typeface(typeface)
{
}
FontCustomPlatformData::~FontCustomPlatformData()
{
}
FontPlatformData FontCustomPlatformData::fontPlatformData(float size, bool bold, bool italic, FontOrientation orientation, FontWidthVariant widthVariant)
{
return FontPlatformData(m_cgFont.get(), size, bold, italic, orientation, widthVariant);
}
PassOwnPtr<FontCustomPlatformData> FontCustomPlatformData::create(SharedBuffer* buffer)
{
ASSERT_ARG(buffer, buffer);
OpenTypeSanitizer sanitizer(buffer);
RefPtr<SharedBuffer> transcodeBuffer = sanitizer.sanitize();
if (!transcodeBuffer)
return nullptr;
buffer = transcodeBuffer.get();
RetainPtr<CFDataRef> bufferData(AdoptCF, CFDataCreate(0, reinterpret_cast<const UInt8*>(buffer->data()), buffer->size()));
RetainPtr<CGDataProviderRef> dataProvider(AdoptCF, CGDataProviderCreateWithCFData(bufferData.get()));
RetainPtr<CGFontRef> cgFontRef(AdoptCF, CGFontCreateWithDataProvider(dataProvider.get()));
if (!cgFontRef)
return nullptr;
RefPtr<SkMemoryStream> stream = adoptRef(new SkMemoryStream(buffer->getAsSkData().get()));
RefPtr<SkTypeface> typeface = adoptRef(SkTypeface::CreateFromStream(stream.get()));
if (!typeface)
return nullptr;
return adoptPtr(new FontCustomPlatformData(cgFontRef.leakRef(), typeface.release()));
}
bool FontCustomPlatformData::supportsFormat(const String& format)
{
return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "opentype") || OpenTypeSanitizer::supportsFormat(format);
}
}