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

Side by Side Diff: src/ports/SkFontHost_linux.cpp

Issue 1057413005: Remove filename from SkFontDescriptor. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add file name to assert. Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « src/fonts/SkTestScalerContext.cpp ('k') | src/ports/SkFontMgr_android.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkFontHost_FreeType_common.h" 8 #include "SkFontHost_FreeType_common.h"
9 #include "SkFontDescriptor.h" 9 #include "SkFontDescriptor.h"
10 #include "SkFontMgr.h" 10 #include "SkFontMgr.h"
(...skipping 14 matching lines...) Expand all
25 class SkTypeface_Custom : public SkTypeface_FreeType { 25 class SkTypeface_Custom : public SkTypeface_FreeType {
26 public: 26 public:
27 SkTypeface_Custom(const SkFontStyle& style, bool isFixedPitch, 27 SkTypeface_Custom(const SkFontStyle& style, bool isFixedPitch,
28 bool sysFont, const SkString familyName, int index) 28 bool sysFont, const SkString familyName, int index)
29 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) 29 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch)
30 , fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index) 30 , fIsSysFont(sysFont), fFamilyName(familyName), fIndex(index)
31 { } 31 { }
32 32
33 bool isSysFont() const { return fIsSysFont; } 33 bool isSysFont() const { return fIsSysFont; }
34 34
35 virtual const char* getUniqueString() const = 0;
36
37 protected: 35 protected:
38 void onGetFamilyName(SkString* familyName) const override { 36 void onGetFamilyName(SkString* familyName) const override {
39 *familyName = fFamilyName; 37 *familyName = fFamilyName;
40 } 38 }
41 39
42 void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const overri de { 40 void onGetFontDescriptor(SkFontDescriptor* desc, bool* isLocal) const overri de {
43 desc->setFamilyName(fFamilyName.c_str()); 41 desc->setFamilyName(fFamilyName.c_str());
44 desc->setFontFileName(this->getUniqueString());
45 desc->setFontIndex(fIndex); 42 desc->setFontIndex(fIndex);
46 *isLocal = !this->isSysFont(); 43 *isLocal = !this->isSysFont();
47 } 44 }
48 45
49 int getIndex() const { return fIndex; } 46 int getIndex() const { return fIndex; }
50 47
51 private: 48 private:
52 const bool fIsSysFont; 49 const bool fIsSysFont;
53 const SkString fFamilyName; 50 const SkString fFamilyName;
54 const int fIndex; 51 const int fIndex;
55 52
56 typedef SkTypeface_FreeType INHERITED; 53 typedef SkTypeface_FreeType INHERITED;
57 }; 54 };
58 55
59 /** The empty SkTypeface implementation for the custom font manager. 56 /** The empty SkTypeface implementation for the custom font manager.
60 * Used as the last resort fallback typeface. 57 * Used as the last resort fallback typeface.
61 */ 58 */
62 class SkTypeface_Empty : public SkTypeface_Custom { 59 class SkTypeface_Empty : public SkTypeface_Custom {
63 public: 60 public:
64 SkTypeface_Empty() : INHERITED(SkFontStyle(), false, true, SkString(), 0) {} 61 SkTypeface_Empty() : INHERITED(SkFontStyle(), false, true, SkString(), 0) {}
65 62
66 const char* getUniqueString() const override { return NULL; }
67
68 protected: 63 protected:
69 SkStreamAsset* onOpenStream(int*) const override { return NULL; } 64 SkStreamAsset* onOpenStream(int*) const override { return NULL; }
70 65
71 private: 66 private:
72 typedef SkTypeface_Custom INHERITED; 67 typedef SkTypeface_Custom INHERITED;
73 }; 68 };
74 69
75 /** The stream SkTypeface implementation for the custom font manager. */ 70 /** The stream SkTypeface implementation for the custom font manager. */
76 class SkTypeface_Stream : public SkTypeface_Custom { 71 class SkTypeface_Stream : public SkTypeface_Custom {
77 public: 72 public:
78 SkTypeface_Stream(const SkFontStyle& style, bool isFixedPitch, bool sysFont, 73 SkTypeface_Stream(const SkFontStyle& style, bool isFixedPitch, bool sysFont,
79 const SkString familyName, SkStreamAsset* stream, int inde x) 74 const SkString familyName, SkStreamAsset* stream, int inde x)
80 : INHERITED(style, isFixedPitch, sysFont, familyName, index) 75 : INHERITED(style, isFixedPitch, sysFont, familyName, index)
81 , fStream(stream) 76 , fStream(stream)
82 { } 77 { }
83 78
84 const char* getUniqueString() const override { return NULL; }
85
86 protected: 79 protected:
87 SkStreamAsset* onOpenStream(int* ttcIndex) const override { 80 SkStreamAsset* onOpenStream(int* ttcIndex) const override {
88 *ttcIndex = this->getIndex(); 81 *ttcIndex = this->getIndex();
89 return fStream->duplicate(); 82 return fStream->duplicate();
90 } 83 }
91 84
92 private: 85 private:
93 const SkAutoTDelete<const SkStreamAsset> fStream; 86 const SkAutoTDelete<const SkStreamAsset> fStream;
94 87
95 typedef SkTypeface_Custom INHERITED; 88 typedef SkTypeface_Custom INHERITED;
96 }; 89 };
97 90
98 // This configuration option is useful if we need to open and hold handles to 91 // This configuration option is useful if we need to open and hold handles to
99 // all found system font data (e.g., for skfiddle, where the application can't 92 // all found system font data (e.g., for skfiddle, where the application can't
100 // access the filesystem to read fonts on demand) 93 // access the filesystem to read fonts on demand)
101 94
102 SK_CONF_DECLARE(bool, c_CustomTypefaceRetain, "fonts.customFont.retainAllData", false, 95 SK_CONF_DECLARE(bool, c_CustomTypefaceRetain, "fonts.customFont.retainAllData", false,
103 "Retain the open stream for each found font on the system."); 96 "Retain the open stream for each found font on the system.");
104 97
105 /** The file SkTypeface implementation for the custom font manager. */ 98 /** The file SkTypeface implementation for the custom font manager. */
106 class SkTypeface_File : public SkTypeface_Custom { 99 class SkTypeface_File : public SkTypeface_Custom {
107 public: 100 public:
108 SkTypeface_File(const SkFontStyle& style, bool isFixedPitch, bool sysFont, 101 SkTypeface_File(const SkFontStyle& style, bool isFixedPitch, bool sysFont,
109 const SkString familyName, const char path[], int index) 102 const SkString familyName, const char path[], int index)
110 : INHERITED(style, isFixedPitch, sysFont, familyName, index) 103 : INHERITED(style, isFixedPitch, sysFont, familyName, index)
111 , fPath(path) 104 , fPath(path)
112 , fStream(c_CustomTypefaceRetain ? SkStream::NewFromFile(fPath.c_str()) : NULL) 105 , fStream(c_CustomTypefaceRetain ? SkStream::NewFromFile(fPath.c_str()) : NULL)
113 { } 106 { }
114 107
115 const char* getUniqueString() const override {
116 const char* str = strrchr(fPath.c_str(), '/');
117 if (str) {
118 str += 1; // skip the '/'
119 }
120 return str;
121 }
122
123 protected: 108 protected:
124 SkStreamAsset* onOpenStream(int* ttcIndex) const override { 109 SkStreamAsset* onOpenStream(int* ttcIndex) const override {
125 *ttcIndex = this->getIndex(); 110 *ttcIndex = this->getIndex();
126 if (fStream.get()) { 111 if (fStream.get()) {
127 return fStream->duplicate(); 112 return fStream->duplicate();
128 } else { 113 } else {
129 return SkStream::NewFromFile(fPath.c_str()); 114 return SkStream::NewFromFile(fPath.c_str());
130 } 115 }
131 } 116 }
132 117
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 #else 526 #else
542 527
543 #ifndef SK_FONT_FILE_PREFIX 528 #ifndef SK_FONT_FILE_PREFIX
544 # define SK_FONT_FILE_PREFIX "/usr/share/fonts/" 529 # define SK_FONT_FILE_PREFIX "/usr/share/fonts/"
545 #endif 530 #endif
546 SkFontMgr* SkFontMgr::Factory() { 531 SkFontMgr* SkFontMgr::Factory() {
547 return new SkFontMgr_Custom(DirectorySystemFontLoader(SK_FONT_FILE_PREFIX)); 532 return new SkFontMgr_Custom(DirectorySystemFontLoader(SK_FONT_FILE_PREFIX));
548 } 533 }
549 534
550 #endif 535 #endif
OLDNEW
« no previous file with comments | « src/fonts/SkTestScalerContext.cpp ('k') | src/ports/SkFontMgr_android.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698