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 22 matching lines...) Expand all Loading... |
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 "platform/fonts/opentype/FontSettings.h" |
41 #include "third_party/skia/include/core/SkStream.h" | 41 #include "third_party/skia/include/core/SkStream.h" |
42 #include "third_party/skia/include/core/SkTypeface.h" | 42 #include "third_party/skia/include/core/SkTypeface.h" |
43 #if OS(WIN) | |
44 #include "third_party/skia/include/ports/SkFontMgr_empty.h" | |
45 #endif | |
46 #include "wtf/PtrUtil.h" | 43 #include "wtf/PtrUtil.h" |
47 | 44 |
48 namespace blink { | 45 namespace blink { |
49 | 46 |
50 FontCustomPlatformData::FontCustomPlatformData(sk_sp<SkTypeface> typeface, | 47 FontCustomPlatformData::FontCustomPlatformData(sk_sp<SkTypeface> typeface, |
51 size_t dataSize) | 48 size_t dataSize) |
52 : m_baseTypeface(std::move(typeface)), m_dataSize(dataSize) {} | 49 : m_baseTypeface(typeface), m_dataSize(dataSize) {} |
53 | 50 |
54 FontCustomPlatformData::~FontCustomPlatformData() {} | 51 FontCustomPlatformData::~FontCustomPlatformData() {} |
55 | 52 |
56 FontPlatformData FontCustomPlatformData::fontPlatformData( | 53 FontPlatformData FontCustomPlatformData::fontPlatformData( |
57 float size, | 54 float size, |
58 bool bold, | 55 bool bold, |
59 bool italic, | 56 bool italic, |
60 FontOrientation orientation, | 57 FontOrientation orientation, |
61 const FontVariationSettings* variationSettings) { | 58 const FontVariationSettings* variationSettings) { |
62 DCHECK(m_baseTypeface); | 59 DCHECK(m_baseTypeface); |
63 | 60 |
64 sk_sp<SkTypeface> returnTypeface = m_baseTypeface; | 61 sk_sp<SkTypeface> returnTypeface = m_baseTypeface; |
65 | 62 |
66 // Maximum axis count is maximum value for the OpenType USHORT, which is a | 63 // Maximum axis count is maximum value for the OpenType USHORT, which is a |
67 // 16bit unsigned. https://www.microsoft.com/typography/otspec/fvar.htm | 64 // 16bit unsigned. https://www.microsoft.com/typography/otspec/fvar.htm |
68 // Variation settings coming from CSS can have duplicate assignments and the | 65 // Variation settings coming from CSS can have duplicate assignments and the |
69 // list can be longer than UINT16_MAX, but ignoring this for now, going with a | 66 // list can be longer than UINT16_MAX, but ignoring this for now, going with a |
70 // reasonable upper limit and leaving the deduplication for TODO(drott), | 67 // reasonable upper limit and leaving the deduplication for TODO(drott), |
71 // crbug.com/674878 second duplicate value should supersede first.. | 68 // crbug.com/674878 second duplicate value should supersede first.. |
72 if (variationSettings && variationSettings->size() < UINT16_MAX) { | 69 if (variationSettings && variationSettings->size() < UINT16_MAX) { |
73 #if OS(WIN) | |
74 sk_sp<SkFontMgr> fm(SkFontMgr_New_Custom_Empty()); | |
75 #else | |
76 sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); | 70 sk_sp<SkFontMgr> fm(SkFontMgr::RefDefault()); |
77 #endif | |
78 Vector<SkFontMgr::FontParameters::Axis, 0> axes; | 71 Vector<SkFontMgr::FontParameters::Axis, 0> axes; |
79 axes.reserveCapacity(variationSettings->size()); | 72 axes.reserveCapacity(variationSettings->size()); |
80 for (size_t i = 0; i < variationSettings->size(); ++i) { | 73 for (size_t i = 0; i < variationSettings->size(); ++i) { |
81 SkFontMgr::FontParameters::Axis axis = { | 74 SkFontMgr::FontParameters::Axis axis = { |
82 atomicStringToFourByteTag(variationSettings->at(i).tag()), | 75 atomicStringToFourByteTag(variationSettings->at(i).tag()), |
83 SkFloatToScalar(variationSettings->at(i).value())}; | 76 SkFloatToScalar(variationSettings->at(i).value())}; |
84 axes.push_back(axis); | 77 axes.push_back(axis); |
85 } | 78 } |
86 | 79 |
87 sk_sp<SkTypeface> skVariationFont(fm->createFromStream( | 80 sk_sp<SkTypeface> skVariationFont(fm->createFromStream( |
(...skipping 30 matching lines...) Expand all Loading... |
118 new FontCustomPlatformData(std::move(typeface), decoder.decodedSize())); | 111 new FontCustomPlatformData(std::move(typeface), decoder.decodedSize())); |
119 } | 112 } |
120 | 113 |
121 bool FontCustomPlatformData::supportsFormat(const String& format) { | 114 bool FontCustomPlatformData::supportsFormat(const String& format) { |
122 return equalIgnoringCase(format, "truetype") || | 115 return equalIgnoringCase(format, "truetype") || |
123 equalIgnoringCase(format, "opentype") || | 116 equalIgnoringCase(format, "opentype") || |
124 WebFontDecoder::supportsFormat(format); | 117 WebFontDecoder::supportsFormat(format); |
125 } | 118 } |
126 | 119 |
127 } // namespace blink | 120 } // namespace blink |
OLD | NEW |