OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Computer, Inc. | 2 * Copyright (C) 2007 Apple Computer, Inc. |
3 * Copyright (c) 2007, 2008, 2009, Google Inc. All rights reserved. | 3 * Copyright (c) 2007, 2008, 2009, Google Inc. All rights reserved. |
4 * Copyright (C) 2010 Company 100, Inc. | 4 * Copyright (C) 2010 Company 100, Inc. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
8 * met: | 8 * met: |
9 * | 9 * |
10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
(...skipping 19 matching lines...) Expand all Loading... | |
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 */ | 31 */ |
32 | 32 |
33 #include "platform/fonts/FontCustomPlatformData.h" | 33 #include "platform/fonts/FontCustomPlatformData.h" |
34 | 34 |
35 #include "platform/LayoutTestSupport.h" | 35 #include "platform/LayoutTestSupport.h" |
36 #include "platform/SharedBuffer.h" | 36 #include "platform/SharedBuffer.h" |
37 #include "platform/fonts/FontCache.h" | 37 #include "platform/fonts/FontCache.h" |
38 #include "platform/fonts/FontPlatformData.h" | 38 #include "platform/fonts/FontPlatformData.h" |
39 #include "platform/fonts/WebFontDecoder.h" | 39 #include "platform/fonts/WebFontDecoder.h" |
40 #include "platform/fonts/opentype/FontSettings.h" | |
40 #include "third_party/skia/include/core/SkStream.h" | 41 #include "third_party/skia/include/core/SkStream.h" |
41 #include "third_party/skia/include/core/SkTypeface.h" | 42 #include "third_party/skia/include/core/SkTypeface.h" |
42 #include "wtf/PtrUtil.h" | 43 #include "wtf/PtrUtil.h" |
43 #include <memory> | 44 #include <memory> |
44 | 45 |
45 namespace blink { | 46 namespace blink { |
46 | 47 |
47 FontCustomPlatformData::FontCustomPlatformData(sk_sp<SkTypeface> typeface, | 48 FontCustomPlatformData::FontCustomPlatformData(sk_sp<SkTypeface> typeface, |
48 size_t dataSize) | 49 size_t dataSize) |
49 : m_typeface(typeface), m_dataSize(dataSize) {} | 50 : m_baseTypeface(typeface), m_dataSize(dataSize) {} |
50 | 51 |
51 FontCustomPlatformData::~FontCustomPlatformData() {} | 52 FontCustomPlatformData::~FontCustomPlatformData() {} |
52 | 53 |
54 SkFourByteTag atomicStringToFourByteTag(AtomicString tag) { | |
55 return SkSetFourByteTag(tag[0], tag[1], tag[2], tag[3]); | |
eae
2016/12/16 18:48:27
DCHECK(tag.size() == 4);
actually, as the tags ca
drott
2016/12/19 14:12:34
Added the DCHECK. Generally the feature tags can o
| |
56 } | |
57 | |
53 FontPlatformData FontCustomPlatformData::fontPlatformData( | 58 FontPlatformData FontCustomPlatformData::fontPlatformData( |
54 float size, | 59 float size, |
55 bool bold, | 60 bool bold, |
56 bool italic, | 61 bool italic, |
57 FontOrientation orientation) { | 62 FontOrientation orientation, |
58 ASSERT(m_typeface); | 63 FontVariationSettings* variationSettings) { |
59 return FontPlatformData(m_typeface, "", size, bold && !m_typeface->isBold(), | 64 DCHECK(m_baseTypeface); |
60 italic && !m_typeface->isItalic(), orientation); | 65 |
66 sk_sp<SkTypeface> returnTypeface = m_baseTypeface; | |
67 | |
68 if (variationSettings && variationSettings->size() < UINT16_MAX) { | |
eae
2016/12/16 18:48:27
I'm guessing the size < UINT16_MAX check is a secu
drott
2016/12/19 14:12:34
Explained in new comment.
| |
69 // TODO, crbug.com/674878 second duplicate value should supersede first. | |
70 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); | |
71 Vector<SkFontMgr::FontParameters::Axis, 0> axes; | |
72 axes.reserveCapacity(variationSettings->size()); | |
73 for (size_t i = 0; i < variationSettings->size(); ++i) { | |
74 SkFontMgr::FontParameters::Axis axis = { | |
75 atomicStringToFourByteTag(variationSettings->at(i).tag()), | |
76 SkFloatToScalar(variationSettings->at(i).value())}; | |
77 axes.append(axis); | |
78 } | |
79 | |
80 sk_sp<SkTypeface> skVariationFont(fm->createFromStream( | |
81 m_baseTypeface->openStream(nullptr)->duplicate(), | |
82 SkFontMgr::FontParameters().setAxes(axes.data(), axes.size()))); | |
83 | |
84 if (skVariationFont) { | |
85 returnTypeface = skVariationFont; | |
86 } else { | |
87 SkString familyName; | |
88 m_baseTypeface->getFamilyName(&familyName); | |
89 // TODO: Surface this as a console message? | |
90 LOG(ERROR) << "Unable for apply variation axis properties for font: " | |
91 << familyName.c_str(); | |
92 } | |
93 } | |
94 | |
95 return FontPlatformData(returnTypeface, "", size, | |
96 bold && !m_baseTypeface->isBold(), | |
97 italic && !m_baseTypeface->isItalic(), orientation); | |
61 } | 98 } |
62 | 99 |
63 std::unique_ptr<FontCustomPlatformData> FontCustomPlatformData::create( | 100 std::unique_ptr<FontCustomPlatformData> FontCustomPlatformData::create( |
64 SharedBuffer* buffer, | 101 SharedBuffer* buffer, |
65 String& otsParseMessage) { | 102 String& otsParseMessage) { |
66 DCHECK(buffer); | 103 DCHECK(buffer); |
67 WebFontDecoder decoder; | 104 WebFontDecoder decoder; |
68 sk_sp<SkTypeface> typeface = decoder.decode(buffer); | 105 sk_sp<SkTypeface> typeface = decoder.decode(buffer); |
69 if (!typeface) { | 106 if (!typeface) { |
70 otsParseMessage = decoder.getErrorString(); | 107 otsParseMessage = decoder.getErrorString(); |
71 return nullptr; | 108 return nullptr; |
72 } | 109 } |
73 return WTF::wrapUnique( | 110 return WTF::wrapUnique( |
74 new FontCustomPlatformData(std::move(typeface), decoder.decodedSize())); | 111 new FontCustomPlatformData(std::move(typeface), decoder.decodedSize())); |
75 } | 112 } |
76 | 113 |
77 bool FontCustomPlatformData::supportsFormat(const String& format) { | 114 bool FontCustomPlatformData::supportsFormat(const String& format) { |
78 return equalIgnoringCase(format, "truetype") || | 115 return equalIgnoringCase(format, "truetype") || |
79 equalIgnoringCase(format, "opentype") || | 116 equalIgnoringCase(format, "opentype") || |
80 WebFontDecoder::supportsFormat(format); | 117 WebFontDecoder::supportsFormat(format); |
81 } | 118 } |
82 | 119 |
83 } // namespace blink | 120 } // namespace blink |
OLD | NEW |