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

Side by Side Diff: skia/ext/SkFontHost_fontconfig.cpp

Issue 10837077: implement Serialize/Deserialize, so we can serialize pictures (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | « no previous file | 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 /* libs/graphics/ports/SkFontHost_fontconfig.cpp 1 /* libs/graphics/ports/SkFontHost_fontconfig.cpp
2 ** 2 **
3 ** Copyright 2008, Google Inc. 3 ** Copyright 2008, Google Inc.
4 ** 4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License. 6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at 7 ** You may obtain a copy of the License at
8 ** 8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** http://www.apache.org/licenses/LICENSE-2.0
10 ** 10 **
(...skipping 13 matching lines...) Expand all
24 // [1] http://fontconfig.org 24 // [1] http://fontconfig.org
25 // ----------------------------------------------------------------------------- 25 // -----------------------------------------------------------------------------
26 26
27 #include <map> 27 #include <map>
28 #include <string> 28 #include <string>
29 29
30 #include <sys/mman.h> 30 #include <sys/mman.h>
31 #include <sys/stat.h> 31 #include <sys/stat.h>
32 #include <unistd.h> 32 #include <unistd.h>
33 33
34 #include "../../src/ports/SkFontDescriptor.h"
alokp 2012/08/08 21:11:34 Is this allowed by style guide? you should replace
34 #include "SkFontHost.h" 35 #include "SkFontHost.h"
35 #include "SkStream.h" 36 #include "SkStream.h"
36 #include "SkFontHost_fontconfig_control.h" 37 #include "SkFontHost_fontconfig_control.h"
37 #include "SkFontHost_fontconfig_impl.h" 38 #include "SkFontHost_fontconfig_impl.h"
38 #include "SkFontHost_fontconfig_direct.h" 39 #include "SkFontHost_fontconfig_direct.h"
39 40
40 static FontConfigInterface* global_fc_impl = NULL; 41 static FontConfigInterface* global_fc_impl = NULL;
41 42
42 void SkiaFontConfigUseDirectImplementation() { 43 void SkiaFontConfigUseDirectImplementation() {
43 if (global_fc_impl) 44 if (global_fc_impl)
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 return typeface; 204 return typeface;
204 } 205 }
205 206
206 // static 207 // static
207 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) 208 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[])
208 { 209 {
209 SkASSERT(!"SkFontHost::CreateTypefaceFromFile unimplemented"); 210 SkASSERT(!"SkFontHost::CreateTypefaceFromFile unimplemented");
210 return NULL; 211 return NULL;
211 } 212 }
212 213
213 void SkFontHost::Serialize(const SkTypeface*, SkWStream*) {
214 SkASSERT(!"SkFontHost::Serialize unimplemented");
215 }
216
217 SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
218 SkASSERT(!"SkFontHost::Deserialize unimplemented");
219 return NULL;
220 }
221
222 // static
223 uint32_t SkFontHost::NextLogicalFont(SkFontID curr, SkFontID orig) { 214 uint32_t SkFontHost::NextLogicalFont(SkFontID curr, SkFontID orig) {
224 // We don't handle font fallback, WebKit does. 215 // webkit handles fallbacks, we don't
alokp 2012/08/08 21:11:34 unnecessary change.
225 return 0; 216 return 0;
226 } 217 }
227 218
228 /////////////////////////////////////////////////////////////////////////////// 219 ///////////////////////////////////////////////////////////////////////////////
220
221 // Serialize, Deserialize need to be compatible across platforms, hence the use
222 // of SkFontDescriptor.
223
224 void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) {
225 SkFontDescriptor desc(face->style());
226
227 std::string resolved_family_name;
228
229 const unsigned filefaceid = UniqueIdToFileFaceId(face->uniqueID());
230 if (GetFcImpl()->Match(&resolved_family_name, NULL,
231 true /* filefaceid valid */, filefaceid, "", NULL, 0, NULL, NULL))
232 desc.setFamilyName(resolved_family_name.c_str());
233 else
234 desc.setFamilyName("sans-serif");
235
236 // would also like other names (see SkFontDescriptor.h)
237
238 desc.serialize(stream);
239
240 // by convention, we also write out the actual sfnt data, preceeded by
241 // a packed-length. For now we skip that, so we just write the zero.
242 stream->writePackedUInt(0);
243 }
244
245 SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
246 SkFontDescriptor desc(stream);
247
248 // by convention, Serialize will have also written the actual sfnt data.
249 // for now, we just want to skip it.
250 size_t size = stream->readPackedUInt();
251 stream->skip(size);
252
253 return SkFontHost::CreateTypeface(NULL, desc.getFamilyName(),
254 desc.getStyle());
255 }
256
257 ///////////////////////////////////////////////////////////////////////////////
229 258
230 class SkFileDescriptorStream : public SkStream { 259 class SkFileDescriptorStream : public SkStream {
231 public: 260 public:
232 SkFileDescriptorStream(int fd) { 261 SkFileDescriptorStream(int fd) {
233 memory_ = NULL; 262 memory_ = NULL;
234 offset_ = 0; 263 offset_ = 0;
235 264
236 // this ensures that if we fail in the constructor, we will safely 265 // this ensures that if we fail in the constructor, we will safely
237 // ignore all subsequent calls to read() because we will always trim 266 // ignore all subsequent calls to read() because we will always trim
238 // the requested size down to 0 267 // the requested size down to 0
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 if (!path) 359 if (!path)
331 return 1; 360 return 1;
332 } 361 }
333 362
334 if (path) 363 if (path)
335 SkASSERT(!"SkFontHost::GetFileName does not support the font path " 364 SkASSERT(!"SkFontHost::GetFileName does not support the font path "
336 "retrieval."); 365 "retrieval.");
337 366
338 return 0; 367 return 0;
339 } 368 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698