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

Unified Diff: src/ports/SkFontMgr_custom.cpp

Issue 1184923002: Refactor SkFontHost_linux into SkFontMgr_custom. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Don't export embedded. Created 5 years, 6 months 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: src/ports/SkFontMgr_custom.cpp
diff --git a/src/ports/SkFontHost_linux.cpp b/src/ports/SkFontMgr_custom.cpp
similarity index 94%
rename from src/ports/SkFontHost_linux.cpp
rename to src/ports/SkFontMgr_custom.cpp
index b4404ca745eb30fa0389eefb4e94a289a67dd3e1..49744a1f6318b15831e19e072ab42f793480f9b0 100644
--- a/src/ports/SkFontHost_linux.cpp
+++ b/src/ports/SkFontMgr_custom.cpp
@@ -8,6 +8,7 @@
#include "SkFontHost_FreeType_common.h"
#include "SkFontDescriptor.h"
#include "SkFontMgr.h"
+#include "SkFontMgr_custom.h"
#include "SkDescriptor.h"
#include "SkOSFile.h"
#include "SkPaint.h"
@@ -87,13 +88,6 @@ private:
typedef SkTypeface_Custom INHERITED;
};
-// This configuration option is useful if we need to open and hold handles to
-// all found system font data (e.g., for skfiddle, where the application can't
-// access the filesystem to read fonts on demand)
-
-SK_CONF_DECLARE(bool, c_CustomTypefaceRetain, "fonts.customFont.retainAllData", false,
- "Retain the open stream for each found font on the system.");
-
/** The file SkTypeface implementation for the custom font manager. */
class SkTypeface_File : public SkTypeface_Custom {
public:
@@ -101,22 +95,16 @@ public:
const SkString familyName, const char path[], int index)
: INHERITED(style, isFixedPitch, sysFont, familyName, index)
, fPath(path)
- , fStream(c_CustomTypefaceRetain ? SkStream::NewFromFile(fPath.c_str()) : NULL)
{ }
protected:
SkStreamAsset* onOpenStream(int* ttcIndex) const override {
*ttcIndex = this->getIndex();
- if (fStream.get()) {
- return fStream->duplicate();
- } else {
- return SkStream::NewFromFile(fPath.c_str());
- }
+ return SkStream::NewFromFile(fPath.c_str());
}
private:
SkString fPath;
- const SkAutoTDelete<SkStreamAsset> fStream;
typedef SkTypeface_Custom INHERITED;
};
@@ -213,7 +201,7 @@ public:
virtual ~SystemFontLoader() { }
virtual void loadSystemFonts(const SkTypeface_FreeType::Scanner&, Families*) const = 0;
};
- explicit SkFontMgr_Custom(const SystemFontLoader& loader) {
+ explicit SkFontMgr_Custom(const SystemFontLoader& loader) : fDefaultFamily(NULL) {
loader.loadSystemFonts(fScanner, &fFamilies);
// Try to pick a default font.
@@ -440,6 +428,12 @@ private:
SkString fBaseDirectory;
};
+SK_API SkFontMgr* SkFontMgr_New_Custom_Directory(const char* dir) {
+ return new SkFontMgr_Custom(DirectorySystemFontLoader(dir));
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
struct SkEmbeddedResource { const uint8_t* data; size_t size; };
struct SkEmbeddedResourceHeader { const SkEmbeddedResource* entries; int count; };
@@ -515,20 +509,6 @@ private:
const SkEmbeddedResourceHeader* fHeader;
};
-#ifdef SK_EMBEDDED_FONTS
-
-extern "C" const SkEmbeddedResourceHeader SK_EMBEDDED_FONTS;
-SkFontMgr* SkFontMgr::Factory() {
- return new SkFontMgr_Custom(EmbeddedSystemFontLoader(&SK_EMBEDDED_FONTS));
-}
-
-#else
-
-#ifndef SK_FONT_FILE_PREFIX
-# define SK_FONT_FILE_PREFIX "/usr/share/fonts/"
-#endif
-SkFontMgr* SkFontMgr::Factory() {
- return new SkFontMgr_Custom(DirectorySystemFontLoader(SK_FONT_FILE_PREFIX));
+SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header) {
+ return new SkFontMgr_Custom(EmbeddedSystemFontLoader(header));
}
-
-#endif

Powered by Google App Engine
This is Rietveld 408576698