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

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

Issue 21331003: adapt FontConfig to use SK_FONTHOST_USES_FONTMGR (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « src/ports/SkFontConfigTypeface.h ('k') | no next file » | 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 2008 Google Inc. 2 * Copyright 2008 Google Inc.
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 "SkFontConfigInterface.h" 8 #include "SkFontConfigInterface.h"
9 #include "SkFontConfigTypeface.h" 9 #include "SkFontConfigTypeface.h"
10 #include "SkFontDescriptor.h" 10 #include "SkFontDescriptor.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 SkTypeface::Style fStyle; 65 SkTypeface::Style fStyle;
66 }; 66 };
67 67
68 static bool find_proc(SkTypeface* face, SkTypeface::Style style, void* ctx) { 68 static bool find_proc(SkTypeface* face, SkTypeface::Style style, void* ctx) {
69 FontConfigTypeface* fci = (FontConfigTypeface*)face; 69 FontConfigTypeface* fci = (FontConfigTypeface*)face;
70 const FindRec* rec = (const FindRec*)ctx; 70 const FindRec* rec = (const FindRec*)ctx;
71 71
72 return rec->fStyle == style && fci->isFamilyName(rec->fFamilyName); 72 return rec->fStyle == style && fci->isFamilyName(rec->fFamilyName);
73 } 73 }
74 74
75 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, 75 SkTypeface* FontConfigTypeface::LegacyCreateTypeface(
76 const char familyName[], 76 const SkTypeface* familyFace,
77 SkTypeface::Style style) { 77 const char familyName[],
78 SkTypeface::Style style) {
78 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); 79 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI());
79 if (NULL == fci.get()) { 80 if (NULL == fci.get()) {
80 return NULL; 81 return NULL;
81 } 82 }
82 83
83 if (familyFace) { 84 if (familyFace) {
84 FontConfigTypeface* fct = (FontConfigTypeface*)familyFace; 85 FontConfigTypeface* fct = (FontConfigTypeface*)familyFace;
85 familyName = fct->getFamilyName(); 86 familyName = fct->getFamilyName();
86 } 87 }
87 88
(...skipping 12 matching lines...) Expand all
100 &indentity, &outFamilyName, &outStyle)) { 101 &indentity, &outFamilyName, &outStyle)) {
101 return NULL; 102 return NULL;
102 } 103 }
103 104
104 face = SkNEW_ARGS(FontConfigTypeface, (outStyle, indentity, outFamilyName)); 105 face = SkNEW_ARGS(FontConfigTypeface, (outStyle, indentity, outFamilyName));
105 SkTypefaceCache::Add(face, style); 106 SkTypefaceCache::Add(face, style);
106 // SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str() , face, face->getRefCnt()); 107 // SkDebugf("add face <%s> <%s> %p [%d]\n", familyName, outFamilyName.c_str() , face, face->getRefCnt());
107 return face; 108 return face;
108 } 109 }
109 110
111 #ifndef SK_FONTHOST_USES_FONTMGR
112
113 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
114 const char familyName[],
115 SkTypeface::Style style) {
116 return FontConfigTypeface::LegacyCreateTypeface(familyFace, familyName,
117 style);
118 }
119
110 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { 120 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) {
111 if (!stream) { 121 if (!stream) {
112 return NULL; 122 return NULL;
113 } 123 }
114 const size_t length = stream->getLength(); 124 const size_t length = stream->getLength();
115 if (!length) { 125 if (!length) {
116 return NULL; 126 return NULL;
117 } 127 }
118 if (length >= 1024 * 1024 * 1024) { 128 if (length >= 1024 * 1024 * 1024) {
119 return NULL; // don't accept too large fonts (>= 1GB) for safety. 129 return NULL; // don't accept too large fonts (>= 1GB) for safety.
120 } 130 }
121 131
122 // TODO should the caller give us the style? 132 // TODO should the caller give us the style?
123 SkTypeface::Style style = SkTypeface::kNormal; 133 SkTypeface::Style style = SkTypeface::kNormal;
124 SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, stream)); 134 SkTypeface* face = SkNEW_ARGS(FontConfigTypeface, (style, stream));
125 return face; 135 return face;
126 } 136 }
127 137
128 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { 138 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
129 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 139 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
130 return stream.get() ? CreateTypefaceFromStream(stream) : NULL; 140 return stream.get() ? CreateTypefaceFromStream(stream) : NULL;
131 } 141 }
132 142
143 #endif
144
133 /////////////////////////////////////////////////////////////////////////////// 145 ///////////////////////////////////////////////////////////////////////////////
134 146
135 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { 147 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const {
136 SkStream* stream = this->getLocalStream(); 148 SkStream* stream = this->getLocalStream();
137 if (stream) { 149 if (stream) {
138 // should have been provided by CreateFromStream() 150 // should have been provided by CreateFromStream()
139 *ttcIndex = 0; 151 *ttcIndex = 0;
140 152
141 SkAutoTUnref<SkStream> dupStream(stream->duplicate()); 153 SkAutoTUnref<SkStream> dupStream(stream->duplicate());
142 if (dupStream) { 154 if (dupStream) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 tag, offset, length, data) 201 tag, offset, length, data)
190 : 0; 202 : 0;
191 } 203 }
192 204
193 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc, 205 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
194 bool* isLocalStream) const { 206 bool* isLocalStream) const {
195 desc->setFamilyName(this->getFamilyName()); 207 desc->setFamilyName(this->getFamilyName());
196 *isLocalStream = SkToBool(this->getLocalStream()); 208 *isLocalStream = SkToBool(this->getLocalStream());
197 } 209 }
198 210
199 /////////////////////////////////////////////////////////////////////////////// 211 SkTypeface* FontConfigTypeface::onRefMatchingStyle(Style style) const {
212 return LegacyCreateTypeface(this, NULL, style);
213 }
214
215
OLDNEW
« no previous file with comments | « src/ports/SkFontConfigTypeface.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698