Chromium Code Reviews| Index: src/ports/SkFontConfigInterface_direct_google3.cpp |
| diff --git a/src/ports/SkFontConfigInterface_direct_google3.cpp b/src/ports/SkFontConfigInterface_direct_google3.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..23f2b52735d3b51e485dc413294f811ed52b3213 |
| --- /dev/null |
| +++ b/src/ports/SkFontConfigInterface_direct_google3.cpp |
| @@ -0,0 +1,72 @@ |
| +/* |
| + * Copyright 2009 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +/* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */ |
| + |
| +#include "google_font_file_buffering.h" |
| + |
| +#include "SkFontConfigInterfaceDirect.h" |
| +#include "SkMutex.h" |
| +#include "SkStream.h" |
| +#include "SkString.h" |
| +#include "SkTypes.h" |
| + |
| +#include <fontconfig/fontconfig.h> |
| + |
| +// Loads fonts using GoogleFt2ReadFontFromMemory. |
| +class SkFontConfigInterfaceDirectGoogle3 : public SkFontConfigInterfaceDirect { |
| +public: |
| + SkFontConfigInterfaceDirectGoogle3() {} |
| + ~SkFontConfigInterfaceDirectGoogle3() override {} |
| + |
| + SkStreamAsset* openStream(const FontIdentity&) override; |
| +protected: |
| + // Override isValidPattern to return true if the font is in the cache. |
| + bool isValidPattern(FcPattern* pattern) override; |
| +private: |
| + typedef SkFontConfigInterfaceDirect INHERITED; |
| +}; |
| + |
| +SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface(SkBaseMutex* 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.
|
| + SkAutoMutexAcquire ac(mutex); |
| + static SkFontConfigInterfaceDirectGoogle3* singleton = nullptr; |
| + if (singleton == nullptr) { |
| + singleton = new SkFontConfigInterfaceDirectGoogle3; |
| + } |
| + return singleton; |
| +} |
| + |
| +bool SkFontConfigInterfaceDirectGoogle3::isValidPattern(FcPattern* pattern) { |
| +#ifdef SK_FONT_CONFIG_ONLY_ALLOW_SCALABLE_FONTS |
| + FcBool is_scalable; |
| + if (FcPatternGetBool(pattern, FC_SCALABLE, 0, &is_scalable) != FcResultMatch |
| + || !is_scalable) { |
| + return false; |
| + } |
| +#endif |
| + |
| + const char* c_filename = INHERITED::GetName(pattern, FC_FILE); |
| + if (!c_filename) { |
| + return false; |
| + } |
| + // Check if this font has been pre-loaded into memory. |
| + const char* unused; |
| + if (GoogleFreeType::GoogleFt2ReadFontFromMemory(c_filename, &unused) >= 0) { |
| + return true; |
| + } |
| + return this->INHERITED::valid_pattern(pattern); |
| +} |
| + |
| +SkStreamAsset* SkFontConfigInterfaceDirectGoogle3::openStream(const FontIdentity& identity) { |
| + const char* c_filename = identity.fString.c_str(); |
| + // Read the system fonts from the fonts we've pre-loaded into memory. |
| + const char* buffer; |
| + int length = GoogleFreeType::GoogleFt2ReadFontFromMemory( |
| + c_filename, &buffer); |
| + if (length >= 0) return new SkMemoryStream(buffer, length); |
| + return this->INHERITED::openStream(identity); |
| +} |