From 6016962f7237058eb196987ec0e74a50210eee37 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Mon, 14 Mar 2011 15:08:44 +0000 Subject: use system font path when building on the mac git-svn-id: http://skia.googlecode.com/svn/trunk@931 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/ports/SkFontHost_simple.cpp | 77 +++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 33 deletions(-) (limited to 'src/ports/SkFontHost_simple.cpp') diff --git a/src/ports/SkFontHost_simple.cpp b/src/ports/SkFontHost_simple.cpp index 6df6c44cd8..60334e7856 100644 --- a/src/ports/SkFontHost_simple.cpp +++ b/src/ports/SkFontHost_simple.cpp @@ -26,9 +26,14 @@ #define FONT_CACHE_MEMORY_BUDGET (768 * 1024) -#define SK_FONT_FILE_PREFIX "/skimages/" +#ifdef SK_BUILD_FOR_MAC + #define SK_FONT_FILE_PREFIX "/Library/Fonts/" +#else + #define SK_FONT_FILE_PREFIX "/skimages/" +#endif -SkTypeface::Style find_name_and_style(SkStream* stream, SkString* name); +SkTypeface::Style find_name_and_attributes(SkStream* stream, SkString* name, + bool* isFixedWidth); static void GetFullPathForSysFonts(SkString* full, const char name[]) { full->set(SK_FONT_FILE_PREFIX); @@ -47,7 +52,7 @@ struct FamilyRec; struct NameFamilyPair { const char* fName; // we own this FamilyRec* fFamily; // we don't own this, we just reference it - + void construct(const char name[], FamilyRec* family) { fName = strdup(name); fFamily = family; // we don't own this, so just record the referene @@ -70,7 +75,7 @@ static SkTDArray gNameList; struct FamilyRec { FamilyRec* fNext; SkTypeface* fFaces[4]; - + FamilyRec() { fNext = gFamilyHead; @@ -143,7 +148,7 @@ static FamilyRec* remove_from_family(const SkTypeface* face) { FamilyRec* family = find_family(face); SkASSERT(family->fFaces[face->style()] == face); family->fFaces[face->style()] = NULL; - + for (int i = 0; i < 4; i++) { if (family->fFaces[i] != NULL) { // family is non-empty return NULL; @@ -177,7 +182,7 @@ static void detach_and_delete_family(FamilyRec* family) { static SkTypeface* find_typeface(const char name[], SkTypeface::Style style) { NameFamilyPair* list = gNameList.begin(); int count = gNameList.count(); - + int index = SkStrLCSearch(&list[0].fName, count, name, sizeof(list[0])); if (index >= 0) { @@ -198,7 +203,7 @@ static void add_name(const char name[], FamilyRec* family) { NameFamilyPair* list = gNameList.begin(); int count = gNameList.count(); - + int index = SkStrLCSearch(&list[0].fName, count, name, sizeof(list[0])); if (index < 0) { @@ -216,7 +221,7 @@ static void remove_from_names(FamilyRec* emptyFamily) #endif SkTDArray& list = gNameList; - + // must go backwards when removing for (int i = list.count() - 1; i >= 0; --i) { NameFamilyPair* pair = &list[i]; @@ -234,9 +239,9 @@ public: FamilyTypeface(Style style, bool sysFont, SkTypeface* familyMember) : SkTypeface(style, sk_atomic_inc(&gUniqueFontID) + 1) { fIsSysFont = sysFont; - + SkAutoMutexAcquire ac(gFamilyMutex); - + FamilyRec* rec = NULL; if (familyMember) { rec = find_family(familyMember); @@ -246,10 +251,10 @@ public: } rec->fFaces[style] = this; } - + virtual ~FamilyTypeface() { SkAutoMutexAcquire ac(gFamilyMutex); - + // remove us from our family. If the family is now empty, we return // that and then remove that family from the name list FamilyRec* family = remove_from_family(this); @@ -258,16 +263,16 @@ public: detach_and_delete_family(family); } } - + bool isSysFont() const { return fIsSysFont; } - + virtual SkStream* openStream() = 0; virtual const char* getUniqueString() const = 0; virtual const char* getFilePath() const = 0; - + private: bool fIsSysFont; - + typedef SkTypeface INHERITED; }; @@ -285,7 +290,7 @@ public: virtual ~StreamTypeface() { fStream->unref(); } - + // overrides virtual SkStream* openStream() { // we just ref our existing stream, since the caller will call unref() @@ -298,7 +303,7 @@ public: private: SkStream* fStream; - + typedef FamilyTypeface INHERITED; }; @@ -308,14 +313,14 @@ public: const char path[]) : INHERITED(style, sysFont, familyMember) { SkString fullpath; - + if (sysFont) { GetFullPathForSysFonts(&fullpath, path); path = fullpath.c_str(); } fPath.set(path); } - + // overrides virtual SkStream* openStream() { SkStream* stream = SkNEW_ARGS(SkMMAPStream, (fPath.c_str())); @@ -345,7 +350,7 @@ public: private: SkString fPath; - + typedef FamilyTypeface INHERITED; }; @@ -354,18 +359,19 @@ private: static bool get_name_and_style(const char path[], SkString* name, SkTypeface::Style* style, bool isExpected) { + bool isFixedWidth; SkString fullpath; GetFullPathForSysFonts(&fullpath, path); SkMMAPStream stream(fullpath.c_str()); if (stream.getLength() > 0) { - *style = find_name_and_style(&stream, name); + *style = find_name_and_attributes(&stream, name, &isFixedWidth); return true; } else { SkFILEStream stream(fullpath.c_str()); if (stream.getLength() > 0) { - *style = find_name_and_style(&stream, name); + *style = find_name_and_attributes(&stream, name, &isFixedWidth); return true; } } @@ -403,6 +409,8 @@ static const char* gFBNames[] = { NULL }; null for the list. The names list must be NULL-terminated */ static const FontInitRec gSystemFonts[] = { + { "Arial.ttf", gSansNames }, + { "Times.ttf", gSerifNames }, { "samplefont.ttf", gSansNames }, }; @@ -429,7 +437,7 @@ static void load_system_fonts() { if (NULL != gDefaultNormal) { return; } - + const FontInitRec* rec = gSystemFonts; SkTypeface* firstInFamily = NULL; int fallbackCount = 0; @@ -439,7 +447,7 @@ static void load_system_fonts() { if (rec[i].fNames != NULL) { firstInFamily = NULL; } - + SkString name; SkTypeface::Style style; @@ -515,7 +523,7 @@ SkTypeface* SkFontHost::Deserialize(SkStream* stream) { SkString str; str.resize(len); stream->read(str.writable_str(), len); - + const FontInitRec* rec = gSystemFonts; for (size_t i = 0; i < SK_ARRAY_COUNT(gSystemFonts); i++) { if (strcmp(rec[i].fFileName, str.c_str()) == 0) { @@ -541,10 +549,10 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, load_system_fonts(); SkAutoMutexAcquire ac(gFamilyMutex); - + // clip to legal style bits style = (SkTypeface::Style)(style & SkTypeface::kBoldItalic); - + SkTypeface* tf = NULL; if (NULL != familyFace) { @@ -565,13 +573,13 @@ SkTypeface* SkFontHost::CreateTypeface(const SkTypeface* familyFace, bool SkFontHost::ValidFontID(uint32_t fontID) { SkAutoMutexAcquire ac(gFamilyMutex); - + return find_from_uniqueID(fontID) != NULL; } SkStream* SkFontHost::OpenStream(uint32_t fontID) { SkAutoMutexAcquire ac(gFamilyMutex); - + FamilyTypeface* tf = (FamilyTypeface*)find_from_uniqueID(fontID); SkStream* stream = tf ? tf->openStream() : NULL; @@ -582,12 +590,13 @@ SkStream* SkFontHost::OpenStream(uint32_t fontID) { return stream; } -// static +#if 0 SkAdvancedTypefaceMetrics* SkFontHost::GetAdvancedTypefaceMetrics( uint32_t fontID, bool perGlyphInfo) { SkASSERT(!"SkFontHost::GetAdvancedTypefaceMetrics unimplemented"); return NULL; } +#endif size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, int32_t* index) { @@ -633,9 +642,11 @@ SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { if (NULL == stream || stream->getLength() <= 0) { return NULL; } - + + bool isFixedWidth; SkString name; - SkTypeface::Style style = find_name_and_style(stream, &name); + SkTypeface::Style style = find_name_and_attributes(stream, &name, + &isFixedWidth); return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream)); } -- cgit v1.2.3