OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkFontConfigInterface.h" | 8 #include "SkFontConfigInterface.h" |
9 #include "SkFontConfigTypeface.h" | 9 #include "SkFontConfigTypeface.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
11 #include "SkFontMgr.h" | 11 #include "SkFontMgr.h" |
12 #include "SkFontStyle.h" | 12 #include "SkFontStyle.h" |
13 #include "SkMutex.h" | 13 #include "SkMutex.h" |
14 #include "SkString.h" | 14 #include "SkString.h" |
15 #include "SkTypeface.h" | 15 #include "SkTypeface.h" |
16 #include "SkTypefaceCache.h" | 16 #include "SkTypefaceCache.h" |
17 #include "SkResourceCache.h" | 17 #include "SkResourceCache.h" |
18 | 18 |
19 SkStreamAsset* SkTypeface_FCI::onOpenStream(int* ttcIndex) const { | 19 SkStreamAsset* SkTypeface_FCI::onOpenStream(int* ttcIndex) const { |
20 *ttcIndex = this->getIdentity().fTTCIndex; | 20 *ttcIndex = this->getIdentity().fTTCIndex; |
21 | 21 |
22 SkStreamAsset* stream = this->getLocalStream(); | 22 if (fFontData) { |
23 if (stream) { | 23 SkStreamAsset* stream = fFontData->getStream(); |
| 24 if (!stream) { |
| 25 return nullptr; |
| 26 } |
24 return stream->duplicate(); | 27 return stream->duplicate(); |
25 } | 28 } |
26 | 29 |
27 return fFCI->openStream(this->getIdentity()); | 30 return fFCI->openStream(this->getIdentity()); |
28 } | 31 } |
29 | 32 |
| 33 SkFontData* SkTypeface_FCI::onCreateFontData() const { |
| 34 if (fFontData) { |
| 35 return new SkFontData(*fFontData.get()); |
| 36 } |
| 37 |
| 38 const SkFontConfigInterface::FontIdentity& id = this->getIdentity(); |
| 39 return new SkFontData( fFCI->openStream(id), id.fTTCIndex, nullptr, 0); |
| 40 } |
| 41 |
30 void SkTypeface_FCI::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocalSt
ream) const { | 42 void SkTypeface_FCI::onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocalSt
ream) const { |
31 SkString name; | 43 SkString name; |
32 this->getFamilyName(&name); | 44 this->getFamilyName(&name); |
33 desc->setFamilyName(name.c_str()); | 45 desc->setFamilyName(name.c_str()); |
34 desc->setStyle(this->fontStyle()); | 46 desc->setStyle(this->fontStyle()); |
35 *isLocalStream = SkToBool(this->getLocalStream()); | 47 *isLocalStream = SkToBool(fFontData); |
36 } | 48 } |
37 | 49 |
38 /////////////////////////////////////////////////////////////////////////////// | 50 /////////////////////////////////////////////////////////////////////////////// |
39 | 51 |
40 class SkFontStyleSet_FCI : public SkFontStyleSet { | 52 class SkFontStyleSet_FCI : public SkFontStyleSet { |
41 public: | 53 public: |
42 SkFontStyleSet_FCI() {} | 54 SkFontStyleSet_FCI() {} |
43 | 55 |
44 int count() override { return 0; } | 56 int count() override { return 0; } |
45 void getStyle(int index, SkFontStyle*, SkString* style) override { SkASSERT(
false); } | 57 void getStyle(int index, SkFontStyle*, SkString* style) override { SkASSERT(
false); } |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 const size_t length = stream->getLength(); | 203 const size_t length = stream->getLength(); |
192 if (!length) { | 204 if (!length) { |
193 return nullptr; | 205 return nullptr; |
194 } | 206 } |
195 if (length >= 1024 * 1024 * 1024) { | 207 if (length >= 1024 * 1024 * 1024) { |
196 return nullptr; // don't accept too large fonts (>= 1GB) for safety
. | 208 return nullptr; // don't accept too large fonts (>= 1GB) for safety
. |
197 } | 209 } |
198 | 210 |
199 // TODO should the caller give us the style or should we get it from fre
etype? | 211 // TODO should the caller give us the style or should we get it from fre
etype? |
200 SkFontStyle style; | 212 SkFontStyle style; |
201 bool isFixedWidth = false; | 213 bool isFixedPitch = false; |
202 if (!fScanner.scanFont(stream, 0, nullptr, &style, &isFixedWidth, nullpt
r)) { | 214 if (!fScanner.scanFont(stream, 0, nullptr, &style, &isFixedPitch, nullpt
r)) { |
203 return nullptr; | 215 return nullptr; |
204 } | 216 } |
205 | 217 |
206 return SkTypeface_FCI::Create(style, isFixedWidth, stream.release(), ttc
Index); | 218 std::unique_ptr<SkFontData> fontData(new SkFontData(stream.release(), tt
cIndex, |
| 219 nullptr, 0)); |
| 220 return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch); |
| 221 } |
| 222 |
| 223 SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& param
s) const override { |
| 224 using Scanner = SkTypeface_FreeType::Scanner; |
| 225 SkAutoTDelete<SkStreamAsset> stream(s); |
| 226 const size_t length = stream->getLength(); |
| 227 if (!length) { |
| 228 return nullptr; |
| 229 } |
| 230 if (length >= 1024 * 1024 * 1024) { |
| 231 return nullptr; // don't accept too large fonts (>= 1GB) for safety
. |
| 232 } |
| 233 |
| 234 bool isFixedPitch; |
| 235 SkFontStyle style; |
| 236 SkString name; |
| 237 Scanner::AxisDefinitions axisDefinitions; |
| 238 if (!fScanner.scanFont(stream, params.getCollectionIndex(), &name, &styl
e, &isFixedPitch, |
| 239 &axisDefinitions)) |
| 240 { |
| 241 return nullptr; |
| 242 } |
| 243 |
| 244 int paramAxisCount; |
| 245 const FontParameters::Axis* paramAxes = params.getAxes(¶mAxisCount); |
| 246 SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count()); |
| 247 Scanner::computeAxisValues(axisDefinitions, paramAxes, paramAxisCount, a
xisValues, name); |
| 248 |
| 249 std::unique_ptr<SkFontData> fontData(new SkFontData(stream.release(), |
| 250 params.getCollection
Index(), |
| 251 axisValues.get(), |
| 252 axisDefinitions.coun
t())); |
| 253 return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch); |
207 } | 254 } |
208 | 255 |
209 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ | 256 SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override
{ |
210 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); | 257 SkAutoTDelete<SkStreamAsset> stream(SkStream::NewFromFile(path)); |
211 return stream.get() ? this->createFromStream(stream.release(), ttcIndex)
: nullptr; | 258 return stream.get() ? this->createFromStream(stream.release(), ttcIndex)
: nullptr; |
212 } | 259 } |
213 | 260 |
214 SkTypeface* onLegacyCreateTypeface(const char requestedFamilyName[], | 261 SkTypeface* onLegacyCreateTypeface(const char requestedFamilyName[], |
215 SkFontStyle requestedStyle) const overrid
e | 262 SkFontStyle requestedStyle) const overrid
e |
216 { | 263 { |
(...skipping 27 matching lines...) Expand all Loading... |
244 fCache.add(face, request.release()); | 291 fCache.add(face, request.release()); |
245 | 292 |
246 return face; | 293 return face; |
247 } | 294 } |
248 }; | 295 }; |
249 | 296 |
250 SK_API SkFontMgr* SkFontMgr_New_FCI(SkFontConfigInterface* fci) { | 297 SK_API SkFontMgr* SkFontMgr_New_FCI(SkFontConfigInterface* fci) { |
251 SkASSERT(fci); | 298 SkASSERT(fci); |
252 return new SkFontMgr_FCI(fci); | 299 return new SkFontMgr_FCI(fci); |
253 } | 300 } |
OLD | NEW |