2
* Copyright (C) 2008 Alp Toker <alp@atoker.com>
3
* Copyright (C) 2010 Igalia S.L.
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public License
16
* along with this library; see the file COPYING.LIB. If not, write to
17
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
* Boston, MA 02110-1301, USA.
23
#include "FontCustomPlatformData.h"
25
#include "FontPlatformData.h"
26
#include "SharedBuffer.h"
27
#include "WOFFFileFormat.h"
33
static void releaseCustomFontData(void* data)
35
static_cast<SharedBuffer*>(data)->deref();
38
FontCustomPlatformData::FontCustomPlatformData(FT_Face freeTypeFace, SharedBuffer* buffer)
39
: m_freeTypeFace(freeTypeFace)
40
, m_fontFace(cairo_ft_font_face_create_for_ft_face(freeTypeFace, 0))
42
// FIXME Should we be setting some hinting options here?
44
buffer->ref(); // This is balanced by the buffer->deref() in releaseCustomFontData.
45
static cairo_user_data_key_t bufferKey;
46
cairo_font_face_set_user_data(m_fontFace, &bufferKey, buffer,
47
static_cast<cairo_destroy_func_t>(releaseCustomFontData));
49
// Cairo doesn't do FreeType reference counting, so we need to ensure that when
50
// this cairo_font_face_t is destroyed, it cleans up the FreeType face as well.
51
static cairo_user_data_key_t freeTypeFaceKey;
52
cairo_font_face_set_user_data(m_fontFace, &freeTypeFaceKey, freeTypeFace,
53
reinterpret_cast<cairo_destroy_func_t>(FT_Done_Face));
56
FontCustomPlatformData::~FontCustomPlatformData()
58
// m_freeTypeFace will be destroyed along with m_fontFace. See the constructor.
59
cairo_font_face_destroy(m_fontFace);
62
FontPlatformData FontCustomPlatformData::fontPlatformData(int size, bool bold, bool italic, FontOrientation, TextOrientation, FontWidthVariant, FontRenderingMode)
64
return FontPlatformData(m_fontFace, size, bold, italic);
67
FontCustomPlatformData* createFontCustomPlatformData(SharedBuffer* buffer)
69
ASSERT_ARG(buffer, buffer);
71
RefPtr<SharedBuffer> sfntBuffer;
74
if (!convertWOFFToSfnt(buffer, sfnt))
77
sfntBuffer = SharedBuffer::adoptVector(sfnt);
78
buffer = sfntBuffer.get();
81
static FT_Library library = 0;
82
if (!library && FT_Init_FreeType(&library)) {
88
if (FT_New_Memory_Face(library, reinterpret_cast<const FT_Byte*>(buffer->data()), buffer->size(), 0, &freeTypeFace))
90
return new FontCustomPlatformData(freeTypeFace, buffer);
93
bool FontCustomPlatformData::supportsFormat(const String& format)
95
return equalIgnoringCase(format, "truetype") || equalIgnoringCase(format, "opentype") || equalIgnoringCase(format, "woff");