Refactor SkFontHost_linux into SkFontMgr_custom.
Review URL: https://codereview.chromium.org/1184923002
This commit is contained in:
parent
109a23d64f
commit
5cf19498f9
@ -32,9 +32,11 @@
|
||||
'../src/fonts/SkFontMgr_indirect.cpp',
|
||||
'../src/fonts/SkRemotableFontMgr.cpp',
|
||||
'../src/ports/SkFontHost_win.cpp',
|
||||
'../src/ports/SkFontMgr_default_gdi.cpp',
|
||||
'../src/ports/SkFontMgr_default_dw.cpp',
|
||||
'../src/ports/SkFontMgr_custom_directory_factory.cpp',
|
||||
'../src/ports/SkFontMgr_custom_embedded_factory.cpp',
|
||||
'../src/ports/SkFontMgr_win_dw.cpp',
|
||||
'../src/ports/SkFontMgr_win_dw_factory.cpp',
|
||||
'../src/ports/SkFontMgr_win_gdi_factory.cpp',
|
||||
'../src/ports/SkRemotableFontMgr_win_dw.cpp',
|
||||
'../src/ports/SkScalerContext_win_dw.cpp',
|
||||
'../src/ports/SkScalerContext_win_dw.h',
|
||||
@ -57,6 +59,9 @@
|
||||
'../include/ports/SkFontMgr_indirect.h',
|
||||
'../include/ports/SkRemotableFontMgr.h',
|
||||
],
|
||||
'sources/': [
|
||||
['exclude', 'SkFontMgr_.+_factory\\.cpp$'],
|
||||
],
|
||||
'conditions': [
|
||||
[ 'skia_os in ["linux", "freebsd", "openbsd", "solaris", "chromeos", "android"]', {
|
||||
'sources': [
|
||||
@ -82,8 +87,10 @@
|
||||
],
|
||||
},
|
||||
'sources': [
|
||||
'../src/ports/SkFontHost_linux.cpp',
|
||||
'../include/ports/SkFontMgr_custom.h',
|
||||
'../src/ports/SkFontMgr_custom.cpp',
|
||||
],
|
||||
'sources/': [['include', '../src/ports/SkFontMgr_custom_embedded_factory.cpp']],
|
||||
'actions': [{
|
||||
'action_name': 'generate_embedded_font_data',
|
||||
'inputs': [
|
||||
@ -112,8 +119,10 @@
|
||||
],
|
||||
},
|
||||
'sources': [
|
||||
'../src/ports/SkFontHost_linux.cpp',
|
||||
'../include/ports/SkFontMgr_custom.h',
|
||||
'../src/ports/SkFontMgr_custom.cpp',
|
||||
],
|
||||
'sources/': [['include', '../src/ports/SkFontMgr_custom_directory_factory.cpp']],
|
||||
}, {
|
||||
'link_settings': {
|
||||
'libraries': [
|
||||
@ -168,21 +177,15 @@
|
||||
'conditions': [
|
||||
# when we build for win, we only want one of these default files
|
||||
[ 'skia_gdi', {
|
||||
'sources!': [
|
||||
'../src/ports/SkFontMgr_default_dw.cpp',
|
||||
],
|
||||
'sources/': [['include', '../src/ports/SkFontMgr_win_gdi_factory.cpp']],
|
||||
}, { # normally default to direct write
|
||||
'sources!': [
|
||||
'../src/ports/SkFontMgr_default_gdi.cpp',
|
||||
],
|
||||
'sources/': [['include', '../src/ports/SkFontMgr_win_dw_factory.cpp']],
|
||||
}],
|
||||
],
|
||||
}, { # else !win
|
||||
'sources!': [
|
||||
'../src/ports/SkDebug_win.cpp',
|
||||
'../src/ports/SkFontHost_win.cpp',
|
||||
'../src/ports/SkFontMgr_default_gdi.cpp',
|
||||
'../src/ports/SkFontMgr_default_dw.cpp',
|
||||
'../src/ports/SkFontMgr_win_dw.cpp',
|
||||
'../src/ports/SkOSFile_win.cpp',
|
||||
'../src/ports/SkRemotableFontMgr_win_dw.cpp',
|
||||
|
18
include/ports/SkFontMgr_custom.h
Normal file
18
include/ports/SkFontMgr_custom.h
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkFontMgr_custom_DEFINED
|
||||
#define SkFontMgr_custom_DEFINED
|
||||
|
||||
#include "SkTypes.h"
|
||||
|
||||
class SkFontMgr;
|
||||
|
||||
/** Create a custom font manager which scans a given directory for font files. */
|
||||
SK_API SkFontMgr* SkFontMgr_New_Custom_Directory(const char* dir);
|
||||
|
||||
#endif // SkFontMgr_custom_DEFINED
|
@ -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));
|
||||
SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header) {
|
||||
return new SkFontMgr_Custom(EmbeddedSystemFontLoader(header));
|
||||
}
|
||||
|
||||
#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));
|
||||
}
|
||||
|
||||
#endif
|
17
src/ports/SkFontMgr_custom_directory_factory.cpp
Normal file
17
src/ports/SkFontMgr_custom_directory_factory.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkFontMgr.h"
|
||||
#include "SkFontMgr_custom.h"
|
||||
|
||||
#ifndef SK_FONT_FILE_PREFIX
|
||||
# define SK_FONT_FILE_PREFIX "/usr/share/fonts/"
|
||||
#endif
|
||||
|
||||
SkFontMgr* SkFontMgr::Factory() {
|
||||
return SkFontMgr_New_Custom_Directory(SK_FONT_FILE_PREFIX);
|
||||
}
|
17
src/ports/SkFontMgr_custom_embedded_factory.cpp
Normal file
17
src/ports/SkFontMgr_custom_embedded_factory.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkFontMgr.h"
|
||||
|
||||
struct SkEmbeddedResource { const uint8_t* data; size_t size; };
|
||||
struct SkEmbeddedResourceHeader { const SkEmbeddedResource* entries; int count; };
|
||||
SkFontMgr* SkFontMgr_New_Custom_Embedded(const SkEmbeddedResourceHeader* header);
|
||||
|
||||
extern "C" const SkEmbeddedResourceHeader SK_EMBEDDED_FONTS;
|
||||
SkFontMgr* SkFontMgr::Factory() {
|
||||
return SkFontMgr_New_Custom_Embedded(&SK_EMBEDDED_FONTS);
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
#include "SkFontMgr.h"
|
||||
#include "SkTypeface_win.h"
|
||||
|
||||
SkFontMgr* SkFontMgr::Factory() {
|
||||
return SkFontMgr_New_DirectWrite();
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
#include "SkFontMgr.h"
|
||||
#include "SkTypeface_win.h"
|
||||
|
||||
SkFontMgr* SkFontMgr::Factory() {
|
||||
return SkFontMgr_New_GDI();
|
||||
}
|
13
src/ports/SkFontMgr_win_dw_factory.cpp
Normal file
13
src/ports/SkFontMgr_win_dw_factory.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkFontMgr.h"
|
||||
#include "SkTypeface_win.h"
|
||||
|
||||
SkFontMgr* SkFontMgr::Factory() {
|
||||
return SkFontMgr_New_DirectWrite();
|
||||
}
|
13
src/ports/SkFontMgr_win_gdi_factory.cpp
Normal file
13
src/ports/SkFontMgr_win_gdi_factory.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkFontMgr.h"
|
||||
#include "SkTypeface_win.h"
|
||||
|
||||
SkFontMgr* SkFontMgr::Factory() {
|
||||
return SkFontMgr_New_GDI();
|
||||
}
|
Loading…
Reference in New Issue
Block a user