FontCustomPlatformData.cpp [plain text]
#include "config.h"
#include "FontCustomPlatformData.h"
#include "FontPlatformData.h"
#include "OpenTypeSanitizer.h"
#include "SharedBuffer.h"
#include "WOFFFileFormat.h"
#include <ApplicationServices/ApplicationServices.h>
namespace WebCore {
FontCustomPlatformData::~FontCustomPlatformData()
{
CGFontRelease(m_cgFont);
}
FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, FontOrientation orientation, FontWidthVariant widthVariant, FontRenderingMode)
{
return FontPlatformData(m_cgFont, size, bold, italic, orientation, widthVariant);
}
FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
{
ASSERT_ARG(buffer, buffer);
#if USE(OPENTYPE_SANITIZER)
OpenTypeSanitizer sanitizer(buffer);
RefPtr<SharedBuffer> transcodeBuffer = sanitizer.sanitize();
if (!transcodeBuffer)
return 0; buffer = transcodeBuffer.get();
#else
RefPtr<SharedBuffer> sfntBuffer;
if (isWOFF(buffer)) {
Vector<char> sfnt;
if (!convertWOFFToSfnt(buffer, sfnt))
return 0;
sfntBuffer = SharedBuffer::adoptVector(sfnt);
buffer = sfntBuffer.get();
}
#endif
ATSFontContainerRef containerRef = 0;
RetainPtr<CFDataRef> bufferData = adoptCF(buffer->createCFData());
RetainPtr<CGDataProviderRef> dataProvider = adoptCF(CGDataProviderCreateWithCFData(bufferData.get()));
RetainPtr<CGFontRef> cgFontRef = adoptCF(CGFontCreateWithDataProvider(dataProvider.get()));
if (!cgFontRef)
return 0;
FontCustomPlatformData* fontCustomPlatformData = new FontCustomPlatformData(containerRef, cgFontRef.leakRef());
return fontCustomPlatformData;
}
bool FontCustomPlatformData::supportsFormat(const String& format)
{
return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "opentype") || equalIgnoringCase(format, "woff");
}
}