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

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

Issue 12676024: Force all font backends to override onGetFontDescriptor, so we can (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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
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 "SkFontDescriptor.h" 9 #include "SkFontDescriptor.h"
10 #include "SkFontHost.h" 10 #include "SkFontHost.h"
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 bool isFamilyName(const char* name) const { 82 bool isFamilyName(const char* name) const {
83 return fFamilyName.equals(name); 83 return fFamilyName.equals(name);
84 } 84 }
85 85
86 protected: 86 protected:
87 friend class SkFontHost; // hack until we can make public versions 87 friend class SkFontHost; // hack until we can make public versions
88 88
89 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE; 89 virtual int onGetTableTags(SkFontTableTag tags[]) const SK_OVERRIDE;
90 virtual size_t onGetTableData(SkFontTableTag, size_t offset, 90 virtual size_t onGetTableData(SkFontTableTag, size_t offset,
91 size_t length, void* data) const SK_OVERRIDE; 91 size_t length, void* data) const SK_OVERRIDE;
92 virtual void onGetFontDescriptor(SkFontDescriptor*) const SK_OVERRIDE; 92 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE ;
93 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE; 93 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE;
94 94
95 private: 95 private:
96 typedef SkTypeface_FreeType INHERITED; 96 typedef SkTypeface_FreeType INHERITED;
97 }; 97 };
98 98
99 /////////////////////////////////////////////////////////////////////////////// 99 ///////////////////////////////////////////////////////////////////////////////
100 100
101 struct FindRec { 101 struct FindRec {
102 FindRec(const char* name, SkTypeface::Style style) 102 FindRec(const char* name, SkTypeface::Style style)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 /////////////////////////////////////////////////////////////////////////////// 176 ///////////////////////////////////////////////////////////////////////////////
177 177
178 // DEPRECATED 178 // DEPRECATED
179 SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID curr, SkFontID orig) { 179 SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID curr, SkFontID orig) {
180 // We don't handle font fallback. 180 // We don't handle font fallback.
181 return NULL; 181 return NULL;
182 } 182 }
183 183
184 /////////////////////////////////////////////////////////////////////////////// 184 ///////////////////////////////////////////////////////////////////////////////
185 185
186 // Serialize, Deserialize need to be compatible across platforms, hence the use
187 // of SkFontDescriptor.
188
189 void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) {
190 FontConfigTypeface* fct = (FontConfigTypeface*)face;
191
192 SkFontDescriptor desc;
193 fct->onGetFontDescriptor(&desc);
194 desc.serialize(stream);
195
196 // by convention, we also write out the actual sfnt data, preceeded by
197 // a packed-length. For now we skip that, so we just write the zero.
198 stream->writePackedUInt(0);
199 }
200
201 SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
202 SkFontDescriptor descriptor(stream);
203 const char* familyName = descriptor.getFamilyName();
204 const SkTypeface::Style style = descriptor.getStyle();
205
206 size_t length = stream->readPackedUInt();
207 if (length > 0) {
208 void* addr = sk_malloc_flags(length, 0);
209 if (addr) {
210 SkAutoTUnref<SkStream> localStream(SkNEW_ARGS(SkMemoryStream,
211 (addr, length, false)));
212 return SkFontHost::CreateTypefaceFromStream(localStream.get());
213 }
214 // failed to allocate, so just skip and create-from-name
215 stream->skip(length);
216 }
217
218 return SkFontHost::CreateTypeface(NULL, familyName, style);
219 }
220
221 ///////////////////////////////////////////////////////////////////////////////
222
223 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const { 186 SkStream* FontConfigTypeface::onOpenStream(int* ttcIndex) const {
224 SkStream* stream = this->getLocalStream(); 187 SkStream* stream = this->getLocalStream();
225 if (stream) { 188 if (stream) {
226 // TODO: fix issue 1176. 189 // TODO: fix issue 1176.
227 // As of now open_stream will return a stream and unwind it, but the 190 // As of now open_stream will return a stream and unwind it, but the
228 // SkStream is not thread safe, and if two threads use the stream they 191 // SkStream is not thread safe, and if two threads use the stream they
229 // may collide and print preview for example could still fail, 192 // may collide and print preview for example could still fail,
230 // or there could be some failures in rendering if this stream is used 193 // or there could be some failures in rendering if this stream is used
231 // there. 194 // there.
232 stream->rewind(); 195 stream->rewind();
(...skipping 22 matching lines...) Expand all
255 size_t FontConfigTypeface::onGetTableData(SkFontTableTag tag, size_t offset, 218 size_t FontConfigTypeface::onGetTableData(SkFontTableTag tag, size_t offset,
256 size_t length, void* data) const { 219 size_t length, void* data) const {
257 int ttcIndex; 220 int ttcIndex;
258 SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex)); 221 SkAutoTUnref<SkStream> stream(this->openStream(&ttcIndex));
259 return stream.get() 222 return stream.get()
260 ? SkFontStream::GetTableData(stream, ttcIndex, 223 ? SkFontStream::GetTableData(stream, ttcIndex,
261 tag, offset, length, data) 224 tag, offset, length, data)
262 : 0; 225 : 0;
263 } 226 }
264 227
265 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const { 228 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
266 desc->setStyle(this->style()); 229 bool* isLocalStream) const {
267 desc->setFamilyName(this->getFamilyName()); 230 desc->setFamilyName(this->getFamilyName());
231 *isLocalStream = SkToBool(this->getLocalStream());
268 } 232 }
233
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698