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

Side by Side Diff: src/ports/SkFontHost_android.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 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.h" 8 #include "SkFontHost.h"
9 #include "SkFontHost_FreeType_common.h" 9 #include "SkFontHost_FreeType_common.h"
10 #include "SkFontDescriptor.h" 10 #include "SkFontDescriptor.h"
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 remove_from_names(family); 309 remove_from_names(family);
310 detach_and_delete_family(family); 310 detach_and_delete_family(family);
311 } 311 }
312 } 312 }
313 313
314 bool isSysFont() const { return fIsSysFont; } 314 bool isSysFont() const { return fIsSysFont; }
315 315
316 virtual const char* getUniqueString() const = 0; 316 virtual const char* getUniqueString() const = 0;
317 virtual const char* getFilePath() const = 0; 317 virtual const char* getFilePath() const = 0;
318 318
319 protected:
320 virtual void onGetFontDescriptor(SkFontDescriptor*, bool*) const SK_OVERRIDE ;
321
319 private: 322 private:
320 bool fIsSysFont; 323 bool fIsSysFont;
321 324
322 typedef SkTypeface_FreeType INHERITED; 325 typedef SkTypeface_FreeType INHERITED;
323 }; 326 };
324 327
325 /////////////////////////////////////////////////////////////////////////////// 328 ///////////////////////////////////////////////////////////////////////////////
326 329
327 class StreamTypeface : public FamilyTypeface { 330 class StreamTypeface : public FamilyTypeface {
328 public: 331 public:
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 init_system_fonts(); 733 init_system_fonts();
731 } else if (strncmp(locale.language, prevLocale.language, 2) || 734 } else if (strncmp(locale.language, prevLocale.language, 2) ||
732 strncmp(locale.region, prevLocale.region, 2)) { 735 strncmp(locale.region, prevLocale.region, 2)) {
733 prevLocale = locale; 736 prevLocale = locale;
734 reload_fallback_fonts(); 737 reload_fallback_fonts();
735 } 738 }
736 } 739 }
737 740
738 /////////////////////////////////////////////////////////////////////////////// 741 ///////////////////////////////////////////////////////////////////////////////
739 742
740 void SkFontHost::Serialize(const SkTypeface* face, SkWStream* stream) { 743 void FamilyTypeface::onGetFontDescriptor(SkFontDescriptor* desc,
741 744 bool* isLocalStream) const {
742 SkFontDescriptor descriptor;
743 { 745 {
744 SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); 746 SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex);
745 descriptor.setFamilyName(find_family_name(face)); 747 desc->setFamilyName(find_family_name(this));
746 descriptor.setStyle(face->style()); 748 desc->setFontFileName(this->getUniqueString());
747 descriptor.setFontFileName(((FamilyTypeface*)face)->getUniqueString());
748 } 749 }
749 750 *isLocalStream = !this->isSysFont();
750 descriptor.serialize(stream);
751
752 const bool isCustomFont = !((FamilyTypeface*)face)->isSysFont();
753 if (isCustomFont) {
754 // store the entire font in the fontData
755 SkStream* fontStream = face->openStream(NULL);
756 const uint32_t length = fontStream->getLength();
757
758 stream->writePackedUInt(length);
759 stream->writeStream(fontStream, length);
760
761 fontStream->unref();
762 } else {
763 stream->writePackedUInt(0);
764 }
765 } 751 }
766 752
753 #if 0 // do we need this different name lookup for Deserialize?
bungeman-skia 2013/03/22 21:04:05 Should we ask djsollen about this?
reed1 2013/03/25 12:26:27 Done.
767 SkTypeface* SkFontHost::Deserialize(SkStream* stream) { 754 SkTypeface* SkFontHost::Deserialize(SkStream* stream) {
768 { 755 ...
769 SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex);
770 load_system_fonts();
771 }
772
773 SkFontDescriptor descriptor(stream);
774 const char* familyName = descriptor.getFamilyName();
775 const char* fontFileName = descriptor.getFontFileName();
776 const SkTypeface::Style style = descriptor.getStyle();
777
778 const uint32_t customFontDataLength = stream->readPackedUInt();
779 if (customFontDataLength > 0) {
780
781 // generate a new stream to store the custom typeface
782 SkMemoryStream* fontStream = new SkMemoryStream(customFontDataLength - 1 );
783 stream->read((void*)fontStream->getMemoryBase(), customFontDataLength - 1);
784
785 SkTypeface* face = CreateTypefaceFromStream(fontStream);
786
787 fontStream->unref();
788 return face;
789 }
790
791 if (NULL != fontFileName && 0 != *fontFileName) { 756 if (NULL != fontFileName && 0 != *fontFileName) {
792 const FontInitRec* rec = gSystemFonts; 757 const FontInitRec* rec = gSystemFonts;
793 for (size_t i = 0; i < gNumSystemFonts; i++) { 758 for (size_t i = 0; i < gNumSystemFonts; i++) {
794 if (strcmp(rec[i].fFileName, fontFileName) == 0) { 759 if (strcmp(rec[i].fFileName, fontFileName) == 0) {
795 // backup until we hit the fNames 760 // backup until we hit the fNames
796 for (int j = i; j >= 0; --j) { 761 for (int j = i; j >= 0; --j) {
797 if (rec[j].fNames != NULL) { 762 if (rec[j].fNames != NULL) {
798 return SkFontHost::CreateTypeface(NULL, 763 return SkFontHost::CreateTypeface(NULL,
799 rec[j].fNames[0], style); 764 rec[j].fNames[0], style);
800 } 765 }
801 } 766 }
802 } 767 }
803 } 768 }
804 } 769 }
805 770 ...
806 return SkFontHost::CreateTypeface(NULL, familyName, style);
807 } 771 }
772 #endif
808 773
809 /////////////////////////////////////////////////////////////////////////////// 774 ///////////////////////////////////////////////////////////////////////////////
810 775
811 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, 776 SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace,
812 const char familyName[], 777 const char familyName[],
813 SkTypeface::Style style) { 778 SkTypeface::Style style) {
814 SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); 779 SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex);
815 780
816 load_system_fonts(); 781 load_system_fonts();
817 782
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 const char* fontsdir) { 1056 const char* fontsdir) {
1092 gTestMainConfigFile = mainconf; 1057 gTestMainConfigFile = mainconf;
1093 gTestFallbackConfigFile = fallbackconf; 1058 gTestFallbackConfigFile = fallbackconf;
1094 gTestFontFilePrefix = fontsdir; 1059 gTestFontFilePrefix = fontsdir;
1095 SkASSERT(gTestMainConfigFile); 1060 SkASSERT(gTestMainConfigFile);
1096 SkASSERT(gTestFallbackConfigFile); 1061 SkASSERT(gTestFallbackConfigFile);
1097 SkASSERT(gTestFontFilePrefix); 1062 SkASSERT(gTestFontFilePrefix);
1098 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", 1063 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s",
1099 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix) ); 1064 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix) );
1100 } 1065 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698