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

Side by Side Diff: src/ports/SkFontHost_linux.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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkFontHost.h" 10 #include "SkFontHost.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 remove_from_names(family); 254 remove_from_names(family);
255 detach_and_delete_family(family); 255 detach_and_delete_family(family);
256 } 256 }
257 } 257 }
258 258
259 bool isSysFont() const { return fIsSysFont; } 259 bool isSysFont() const { return fIsSysFont; }
260 FamilyRec* getFamily() const { return fFamilyRec; } 260 FamilyRec* getFamily() const { return fFamilyRec; }
261 261
262 virtual const char* getUniqueString() const = 0; 262 virtual const char* getUniqueString() const = 0;
263 263
264 protected:
265 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE ;
266
264 private: 267 private:
265 FamilyRec* fFamilyRec; // we don't own this, just point to it 268 FamilyRec* fFamilyRec; // we don't own this, just point to it
266 bool fIsSysFont; 269 bool fIsSysFont;
267 270
268 typedef SkTypeface_FreeType INHERITED; 271 typedef SkTypeface_FreeType INHERITED;
269 }; 272 };
270 273
271 /////////////////////////////////////////////////////////////////////////////// 274 ///////////////////////////////////////////////////////////////////////////////
272 275
273 /* This subclass is just a place holder for when we have no fonts available. 276 /* This subclass is just a place holder for when we have no fonts available.
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 } 453 }
451 if (NULL == gDefaultNormal) { 454 if (NULL == gDefaultNormal) {
452 sk_throw(); 455 sk_throw();
453 } 456 }
454 gFallBackTypeface = gDefaultNormal; 457 gFallBackTypeface = gDefaultNormal;
455 gDefaultFamily = find_family(gDefaultNormal); 458 gDefaultFamily = find_family(gDefaultNormal);
456 } 459 }
457 460
458 /////////////////////////////////////////////////////////////////////////////// 461 ///////////////////////////////////////////////////////////////////////////////
459 462
460 void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) { 463 void FamilyTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
461 464 bool* isLocalStream) const {
462 SkFontDescriptor descriptor; 465 desc->setFamilyName(find_family_name(this));
463 descriptor.setFamilyName(find_family_name(face)); 466 desc->setFontFileName(this->getUniqueString());
464 descriptor.setStyle(face->style()); 467 *isLocalStream = !this->isSysFont();
465 descriptor.setFontFileName(((FamilyTypeface*)face)->getUniqueString());
466
467 descriptor.serialize(stream);
468
469 const bool isCustomFont = !((FamilyTypeface*)face)->isSysFont();
470 if (isCustomFont) {
471 // store the entire font in the fontData
472 SkStream* fontStream = face->openStream(NULL);
473 const uint32_t length = fontStream->getLength();
474
475 stream->writePackedUInt(length);
476 stream->writeStream(fontStream, length);
477
478 fontStream->unref();
479 } else {
480 stream->writePackedUInt(0);
481 }
482 }
483
484 SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
485 load_system_fonts();
486
487 SkFontDescriptor descriptor(stream);
488 const char* familyName = descriptor.getFamilyName();
489 const SkTypeface::Style style = descriptor.getStyle();
490
491 const uint32_t customFontDataLength = stream->readPackedUInt();
492 if (customFontDataLength > 0) {
493
494 // generate a new stream to store the custom typeface
495 SkMemoryStream* fontStream = new SkMemoryStream(customFontDataLength - 1 );
496 stream->read((void*)fontStream->getMemoryBase(), customFontDataLength - 1);
497
498 SkTypeface* face = CreateTypefaceFromStream(fontStream);
499
500 fontStream->unref();
501 return face;
502 }
503
504 return SkFontHost::CreateTypeface(NULL, familyName, style);
505 } 468 }
506 469
507 /////////////////////////////////////////////////////////////////////////////// 470 ///////////////////////////////////////////////////////////////////////////////
508 471
509 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, 472 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
510 const char familyName[], 473 const char familyName[],
511 SkTypeface::Style style) { 474 SkTypeface::Style style) {
512 load_system_fonts(); 475 load_system_fonts();
513 476
514 SkAutoMutexAcquire ac(gFamilyMutex); 477 SkAutoMutexAcquire ac(gFamilyMutex);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream, isFixedWi dth)); 514 return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream, isFixedWi dth));
552 } else { 515 } else {
553 return NULL; 516 return NULL;
554 } 517 }
555 } 518 }
556 519
557 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { 520 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) {
558 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 521 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
559 return stream.get() ? CreateTypefaceFromStream(stream) : NULL; 522 return stream.get() ? CreateTypefaceFromStream(stream) : NULL;
560 } 523 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698