Use "= default" to denote default constructor or destructor
[WebKit-https.git] / Source / WebCore / platform / graphics / mac / FontCustomPlatformData.cpp
1 /*
2  * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20
21 #include "config.h"
22 #include "FontCustomPlatformData.h"
23
24 #include "FontCache.h"
25 #include "FontDescription.h"
26 #include "FontPlatformData.h"
27 #include "SharedBuffer.h"
28 #include <CoreGraphics/CoreGraphics.h>
29 #include <CoreText/CoreText.h>
30
31 namespace WebCore {
32
33 FontCustomPlatformData::~FontCustomPlatformData() = default;
34
35 FontPlatformData FontCustomPlatformData::fontPlatformData(const FontDescription& fontDescription, bool bold, bool italic, const FontFeatureSettings& fontFaceFeatures, const FontVariantSettings& fontFaceVariantSettings, FontSelectionSpecifiedCapabilities fontFaceCapabilities)
36 {
37     int size = fontDescription.computedPixelSize();
38     FontOrientation orientation = fontDescription.orientation();
39     FontWidthVariant widthVariant = fontDescription.widthVariant();
40     RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(m_fontDescriptor.get(), size, nullptr));
41     font = preparePlatformFont(font.get(), fontDescription, &fontFaceFeatures, &fontFaceVariantSettings, fontFaceCapabilities, fontDescription.computedSize());
42     ASSERT(font);
43     return FontPlatformData(font.get(), size, bold, italic, orientation, widthVariant, fontDescription.textRenderingMode());
44 }
45
46 std::unique_ptr<FontCustomPlatformData> createFontCustomPlatformData(SharedBuffer& buffer)
47 {
48     RetainPtr<CFDataRef> bufferData = buffer.createCFData();
49
50     RetainPtr<CTFontDescriptorRef> fontDescriptor = adoptCF(CTFontManagerCreateFontDescriptorFromData(bufferData.get()));
51     if (!fontDescriptor)
52         return nullptr;
53
54     return std::make_unique<FontCustomPlatformData>(fontDescriptor.get());
55 }
56
57 bool FontCustomPlatformData::supportsFormat(const String& format)
58 {
59     return equalLettersIgnoringASCIICase(format, "truetype")
60         || equalLettersIgnoringASCIICase(format, "opentype")
61 #if PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200)
62         || equalLettersIgnoringASCIICase(format, "woff2")
63 #if ENABLE(VARIATION_FONTS)
64         || equalLettersIgnoringASCIICase(format, "woff2-variations")
65 #endif
66 #endif
67 #if ENABLE(VARIATION_FONTS)
68         || equalLettersIgnoringASCIICase(format, "woff-variations")
69         || equalLettersIgnoringASCIICase(format, "truetype-variations")
70         || equalLettersIgnoringASCIICase(format, "opentype-variations")
71 #endif
72         || equalLettersIgnoringASCIICase(format, "woff");
73 }
74
75 }