Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2009 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */ | |
| 9 | |
| 10 #include "google_font_file_buffering.h" | |
| 11 | |
| 12 #include "SkFontConfigInterfaceDirect.h" | |
| 13 #include "SkMutex.h" | |
| 14 #include "SkStream.h" | |
| 15 #include "SkString.h" | |
| 16 #include "SkTypes.h" | |
| 17 | |
| 18 #include <fontconfig/fontconfig.h> | |
| 19 | |
| 20 // Loads fonts using GoogleFt2ReadFontFromMemory. | |
| 21 class SkFontConfigInterfaceDirectGoogle3 : public SkFontConfigInterfaceDirect { | |
| 22 public: | |
| 23 SkFontConfigInterfaceDirectGoogle3() {} | |
| 24 ~SkFontConfigInterfaceDirectGoogle3() override {} | |
| 25 | |
| 26 SkStreamAsset* openStream(const FontIdentity&) override; | |
| 27 protected: | |
| 28 // Override isValidPattern to return true if the font is in the cache. | |
| 29 bool isValidPattern(FcPattern* pattern) override; | |
| 30 private: | |
| 31 typedef SkFontConfigInterfaceDirect INHERITED; | |
| 32 }; | |
| 33 | |
| 34 SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface(SkBase Mutex* mutex) { | |
|
bungeman-skia
2015/11/24 21:56:36
It would be nice if this were in
SkFontConfigInte
dogben
2015/11/30 17:15:31
Done. Required adding a .h.
| |
| 35 SkAutoMutexAcquire ac(mutex); | |
| 36 static SkFontConfigInterfaceDirectGoogle3* singleton = nullptr; | |
| 37 if (singleton == nullptr) { | |
| 38 singleton = new SkFontConfigInterfaceDirectGoogle3; | |
| 39 } | |
| 40 return singleton; | |
| 41 } | |
| 42 | |
| 43 bool SkFontConfigInterfaceDirectGoogle3::isValidPattern(FcPattern* pattern) { | |
| 44 #ifdef SK_FONT_CONFIG_ONLY_ALLOW_SCALABLE_FONTS | |
| 45 FcBool is_scalable; | |
| 46 if (FcPatternGetBool(pattern, FC_SCALABLE, 0, &is_scalable) != FcResultMatch | |
| 47 || !is_scalable) { | |
| 48 return false; | |
| 49 } | |
| 50 #endif | |
| 51 | |
| 52 const char* c_filename = INHERITED::GetName(pattern, FC_FILE); | |
| 53 if (!c_filename) { | |
| 54 return false; | |
| 55 } | |
| 56 // Check if this font has been pre-loaded into memory. | |
| 57 const char* unused; | |
| 58 if (GoogleFreeType::GoogleFt2ReadFontFromMemory(c_filename, &unused) >= 0) { | |
| 59 return true; | |
| 60 } | |
| 61 return this->INHERITED::valid_pattern(pattern); | |
| 62 } | |
| 63 | |
| 64 SkStreamAsset* SkFontConfigInterfaceDirectGoogle3::openStream(const FontIdentity & identity) { | |
| 65 const char* c_filename = identity.fString.c_str(); | |
| 66 // Read the system fonts from the fonts we've pre-loaded into memory. | |
| 67 const char* buffer; | |
| 68 int length = GoogleFreeType::GoogleFt2ReadFontFromMemory( | |
| 69 c_filename, &buffer); | |
| 70 if (length >= 0) return new SkMemoryStream(buffer, length); | |
| 71 return this->INHERITED::openStream(identity); | |
| 72 } | |
| OLD | NEW |