Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(659)

Unified Diff: third_party/WebKit/Source/platform/fonts/mac/FontPlatformDataMac.mm

Issue 2581083003: Initial OpenType Font Variations Support (Closed)
Patch Set: Fix Windows compilation by avoiding VLA Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/fonts/mac/FontPlatformDataMac.mm
diff --git a/third_party/WebKit/Source/platform/fonts/mac/FontPlatformDataMac.mm b/third_party/WebKit/Source/platform/fonts/mac/FontPlatformDataMac.mm
index 27a754ddbf36f18ad235eea62e32adda3205eda3..e1f88c4660ad0ad27e223cc7f3574b027834bb77 100644
--- a/third_party/WebKit/Source/platform/fonts/mac/FontPlatformDataMac.mm
+++ b/third_party/WebKit/Source/platform/fonts/mac/FontPlatformDataMac.mm
@@ -25,6 +25,7 @@
#import "platform/LayoutTestSupport.h"
#import "platform/fonts/Font.h"
+#import "platform/fonts/opentype/FontSettings.h"
#import "platform/fonts/shaping/HarfBuzzFace.h"
#import "platform/graphics/skia/SkiaUtils.h"
#import "public/platform/Platform.h"
@@ -159,11 +160,16 @@ void FontPlatformData::setupPaint(SkPaint* paint,
paint->setHinting(SkPaint::kNo_Hinting);
}
+static SkFourByteTag atomicStringToFourByteTag(AtomicString tag) {
eae 2016/12/16 18:48:27 Given that we probably want a couple of checks in
drott 2016/12/19 14:12:34 Moved to FontSettings.h and cleared of Skia types
+ return SkSetFourByteTag(tag[0], tag[1], tag[2], tag[3]);
+}
+
FontPlatformData::FontPlatformData(NSFont* nsFont,
float size,
bool syntheticBold,
bool syntheticItalic,
- FontOrientation orientation)
+ FontOrientation orientation,
+ FontVariationSettings* variationSettings)
: m_textSize(size),
m_syntheticBold(syntheticBold),
m_syntheticItalic(syntheticItalic),
@@ -178,6 +184,21 @@ FontPlatformData::FontPlatformData(NSFont* nsFont,
// and ~/Library Fonts, see crbug.com/72727 or crbug.com/108645.
m_typeface = loadFromBrowserProcess(nsFont, size);
}
+
+ if (variationSettings && variationSettings->size() < UINT16_MAX) {
+ SkFontMgr::FontParameters::Axis axes[variationSettings->size()];
+ for (size_t i = 0; i < variationSettings->size(); ++i) {
+ AtomicString featureTag = variationSettings->at(i).tag();
+ axes[i] = {atomicStringToFourByteTag(featureTag),
+ SkFloatToScalar(variationSettings->at(i).value())};
+ }
+ RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault());
+ // TODO crbug.com/670246: Refactor this to a future Skia API that acccepts
+ // axis parameters on system fonts directly.
+ m_typeface = sk_sp<SkTypeface>(fm->createFromStream(
+ m_typeface->openStream(nullptr)->duplicate(),
+ SkFontMgr::FontParameters().setAxes(axes, variationSettings->size())));
+ }
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698