Chromium Code Reviews| Index: third_party/WebKit/Source/platform/fonts/FontCustomPlatformData.cpp |
| diff --git a/third_party/WebKit/Source/platform/fonts/FontCustomPlatformData.cpp b/third_party/WebKit/Source/platform/fonts/FontCustomPlatformData.cpp |
| index 67a56fe7176bc960e2cb2102fa6f6e1400038ffc..a11ff8e083f014514dca25a103add905ce13ed7b 100644 |
| --- a/third_party/WebKit/Source/platform/fonts/FontCustomPlatformData.cpp |
| +++ b/third_party/WebKit/Source/platform/fonts/FontCustomPlatformData.cpp |
| @@ -37,6 +37,7 @@ |
| #include "platform/fonts/FontCache.h" |
| #include "platform/fonts/FontPlatformData.h" |
| #include "platform/fonts/WebFontDecoder.h" |
| +#include "platform/fonts/opentype/FontSettings.h" |
| #include "third_party/skia/include/core/SkStream.h" |
| #include "third_party/skia/include/core/SkTypeface.h" |
| #include "wtf/PtrUtil.h" |
| @@ -46,18 +47,54 @@ namespace blink { |
| FontCustomPlatformData::FontCustomPlatformData(sk_sp<SkTypeface> typeface, |
| size_t dataSize) |
| - : m_typeface(typeface), m_dataSize(dataSize) {} |
| + : m_baseTypeface(typeface), m_dataSize(dataSize) {} |
| FontCustomPlatformData::~FontCustomPlatformData() {} |
| +SkFourByteTag atomicStringToFourByteTag(AtomicString tag) { |
| + 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
|
| +} |
| + |
| FontPlatformData FontCustomPlatformData::fontPlatformData( |
| float size, |
| bool bold, |
| bool italic, |
| - FontOrientation orientation) { |
| - ASSERT(m_typeface); |
| - return FontPlatformData(m_typeface, "", size, bold && !m_typeface->isBold(), |
| - italic && !m_typeface->isItalic(), orientation); |
| + FontOrientation orientation, |
| + FontVariationSettings* variationSettings) { |
| + DCHECK(m_baseTypeface); |
| + |
| + sk_sp<SkTypeface> returnTypeface = m_baseTypeface; |
| + |
| + 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.
|
| + // TODO, crbug.com/674878 second duplicate value should supersede first. |
| + RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); |
| + Vector<SkFontMgr::FontParameters::Axis, 0> axes; |
| + axes.reserveCapacity(variationSettings->size()); |
| + for (size_t i = 0; i < variationSettings->size(); ++i) { |
| + SkFontMgr::FontParameters::Axis axis = { |
| + atomicStringToFourByteTag(variationSettings->at(i).tag()), |
| + SkFloatToScalar(variationSettings->at(i).value())}; |
| + axes.append(axis); |
| + } |
| + |
| + sk_sp<SkTypeface> skVariationFont(fm->createFromStream( |
| + m_baseTypeface->openStream(nullptr)->duplicate(), |
| + SkFontMgr::FontParameters().setAxes(axes.data(), axes.size()))); |
| + |
| + if (skVariationFont) { |
| + returnTypeface = skVariationFont; |
| + } else { |
| + SkString familyName; |
| + m_baseTypeface->getFamilyName(&familyName); |
| + // TODO: Surface this as a console message? |
| + LOG(ERROR) << "Unable for apply variation axis properties for font: " |
| + << familyName.c_str(); |
| + } |
| + } |
| + |
| + return FontPlatformData(returnTypeface, "", size, |
| + bold && !m_baseTypeface->isBold(), |
| + italic && !m_baseTypeface->isItalic(), orientation); |
| } |
| std::unique_ptr<FontCustomPlatformData> FontCustomPlatformData::create( |