| OLD | NEW |
| 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 // that and then remove that family from the name list | 306 // that and then remove that family from the name list |
| 307 FamilyRec* family = remove_from_family(this); | 307 FamilyRec* family = remove_from_family(this); |
| 308 if (NULL != family) { | 308 if (NULL != family) { |
| 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 SkStream* openStream() = 0; | |
| 317 virtual const char* getUniqueString() const = 0; | 316 virtual const char* getUniqueString() const = 0; |
| 318 virtual const char* getFilePath() const = 0; | 317 virtual const char* getFilePath() const = 0; |
| 319 | 318 |
| 320 private: | 319 private: |
| 321 bool fIsSysFont; | 320 bool fIsSysFont; |
| 322 | 321 |
| 323 typedef SkTypeface_FreeType INHERITED; | 322 typedef SkTypeface_FreeType INHERITED; |
| 324 }; | 323 }; |
| 325 | 324 |
| 326 /////////////////////////////////////////////////////////////////////////////// | 325 /////////////////////////////////////////////////////////////////////////////// |
| 327 | 326 |
| 328 class StreamTypeface : public FamilyTypeface { | 327 class StreamTypeface : public FamilyTypeface { |
| 329 public: | 328 public: |
| 330 StreamTypeface(Style style, bool sysFont, SkTypeface* familyMember, | 329 StreamTypeface(Style style, bool sysFont, SkTypeface* familyMember, |
| 331 SkStream* stream, bool isFixedWidth) | 330 SkStream* stream, bool isFixedWidth) |
| 332 : INHERITED(style, sysFont, familyMember, isFixedWidth) { | 331 : INHERITED(style, sysFont, familyMember, isFixedWidth) { |
| 333 SkASSERT(stream); | 332 SkASSERT(stream); |
| 334 stream->ref(); | 333 stream->ref(); |
| 335 fStream = stream; | 334 fStream = stream; |
| 336 } | 335 } |
| 337 virtual ~StreamTypeface() { | 336 virtual ~StreamTypeface() { |
| 338 fStream->unref(); | 337 fStream->unref(); |
| 339 } | 338 } |
| 340 | 339 |
| 341 // overrides | 340 virtual const char* getUniqueString() SK_OVERRIDE const { return NULL; } |
| 342 virtual SkStream* openStream() { | 341 virtual const char* getFilePath() SK_OVERRIDE const { return NULL; } |
| 342 |
| 343 protected: |
| 344 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
| 345 *ttcIndex = 0; |
| 343 // we just ref our existing stream, since the caller will call unref() | 346 // we just ref our existing stream, since the caller will call unref() |
| 344 // when they are through | 347 // when they are through |
| 345 fStream->ref(); | 348 fStream->ref(); |
| 346 // must rewind each time, since the caller assumes a "new" stream | 349 // must rewind each time, since the caller assumes a "new" stream |
| 347 fStream->rewind(); | 350 fStream->rewind(); |
| 348 return fStream; | 351 return fStream; |
| 349 } | 352 } |
| 350 virtual const char* getUniqueString() const { return NULL; } | |
| 351 virtual const char* getFilePath() const { return NULL; } | |
| 352 | 353 |
| 353 private: | 354 private: |
| 354 SkStream* fStream; | 355 SkStream* fStream; |
| 355 | 356 |
| 356 typedef FamilyTypeface INHERITED; | 357 typedef FamilyTypeface INHERITED; |
| 357 }; | 358 }; |
| 358 | 359 |
| 359 class FileTypeface : public FamilyTypeface { | 360 class FileTypeface : public FamilyTypeface { |
| 360 public: | 361 public: |
| 361 FileTypeface(Style style, bool sysFont, SkTypeface* familyMember, | 362 FileTypeface(Style style, bool sysFont, SkTypeface* familyMember, |
| 362 const char path[], bool isFixedWidth) | 363 const char path[], bool isFixedWidth) |
| 363 : INHERITED(style, sysFont, familyMember, isFixedWidth) { | 364 : INHERITED(style, sysFont, familyMember, isFixedWidth) { |
| 364 SkString fullpath; | 365 SkString fullpath; |
| 365 | 366 |
| 366 if (sysFont) { | 367 if (sysFont) { |
| 367 GetFullPathForSysFonts(&fullpath, path); | 368 GetFullPathForSysFonts(&fullpath, path); |
| 368 path = fullpath.c_str(); | 369 path = fullpath.c_str(); |
| 369 } | 370 } |
| 370 fPath.set(path); | 371 fPath.set(path); |
| 371 } | 372 } |
| 372 | 373 |
| 373 virtual SkStream* openStream() SK_OVERRIDE { | |
| 374 return SkStream::NewFromFile(fPath.c_str()); | |
| 375 } | |
| 376 | |
| 377 virtual const char* getUniqueString() const SK_OVERRIDE { | 374 virtual const char* getUniqueString() const SK_OVERRIDE { |
| 378 const char* str = strrchr(fPath.c_str(), '/'); | 375 const char* str = strrchr(fPath.c_str(), '/'); |
| 379 if (str) { | 376 if (str) { |
| 380 str += 1; // skip the '/' | 377 str += 1; // skip the '/' |
| 381 } | 378 } |
| 382 return str; | 379 return str; |
| 383 } | 380 } |
| 384 | 381 |
| 385 virtual const char* getFilePath() const SK_OVERRIDE { | 382 virtual const char* getFilePath() const SK_OVERRIDE { |
| 386 return fPath.c_str(); | 383 return fPath.c_str(); |
| 387 } | 384 } |
| 388 | 385 |
| 386 protected: |
| 387 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
| 388 *ttcIndex = 0; |
| 389 return SkStream::NewFromFile(fPath.c_str()); |
| 390 } |
| 391 |
| 389 private: | 392 private: |
| 390 SkString fPath; | 393 SkString fPath; |
| 391 | 394 |
| 392 typedef FamilyTypeface INHERITED; | 395 typedef FamilyTypeface INHERITED; |
| 393 }; | 396 }; |
| 394 | 397 |
| 395 /////////////////////////////////////////////////////////////////////////////// | 398 /////////////////////////////////////////////////////////////////////////////// |
| 396 /////////////////////////////////////////////////////////////////////////////// | 399 /////////////////////////////////////////////////////////////////////////////// |
| 397 | 400 |
| 398 static bool get_name_and_style(const char path[], SkString* name, | 401 static bool get_name_and_style(const char path[], SkString* name, |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 descriptor.setFamilyName(find_family_name(face)); | 745 descriptor.setFamilyName(find_family_name(face)); |
| 743 descriptor.setStyle(face->style()); | 746 descriptor.setStyle(face->style()); |
| 744 descriptor.setFontFileName(((FamilyTypeface*)face)->getUniqueString()); | 747 descriptor.setFontFileName(((FamilyTypeface*)face)->getUniqueString()); |
| 745 } | 748 } |
| 746 | 749 |
| 747 descriptor.serialize(stream); | 750 descriptor.serialize(stream); |
| 748 | 751 |
| 749 const bool isCustomFont = !((FamilyTypeface*)face)->isSysFont(); | 752 const bool isCustomFont = !((FamilyTypeface*)face)->isSysFont(); |
| 750 if (isCustomFont) { | 753 if (isCustomFont) { |
| 751 // store the entire font in the fontData | 754 // store the entire font in the fontData |
| 752 SkStream* fontStream = ((FamilyTypeface*)face)->openStream(); | 755 SkStream* fontStream = face->openStream(NULL); |
| 753 const uint32_t length = fontStream->getLength(); | 756 const uint32_t length = fontStream->getLength(); |
| 754 | 757 |
| 755 stream->writePackedUInt(length); | 758 stream->writePackedUInt(length); |
| 756 stream->writeStream(fontStream, length); | 759 stream->writeStream(fontStream, length); |
| 757 | 760 |
| 758 fontStream->unref(); | 761 fontStream->unref(); |
| 759 } else { | 762 } else { |
| 760 stream->writePackedUInt(0); | 763 stream->writePackedUInt(0); |
| 761 } | 764 } |
| 762 } | 765 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 | 829 |
| 827 if (NULL == tf) { | 830 if (NULL == tf) { |
| 828 tf = find_best_face(gDefaultFamily, style); | 831 tf = find_best_face(gDefaultFamily, style); |
| 829 } | 832 } |
| 830 | 833 |
| 831 // we ref(), since the semantic is to return a new instance | 834 // we ref(), since the semantic is to return a new instance |
| 832 tf->ref(); | 835 tf->ref(); |
| 833 return tf; | 836 return tf; |
| 834 } | 837 } |
| 835 | 838 |
| 836 SkStream* SkFontHost::OpenStream(uint32_t fontID) { | |
| 837 SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); | |
| 838 | |
| 839 FamilyTypeface* tf = (FamilyTypeface*)find_from_uniqueID(fontID); | |
| 840 SkStream* stream = tf ? tf->openStream() : NULL; | |
| 841 | |
| 842 if (stream && stream->getLength() == 0) { | |
| 843 stream->unref(); | |
| 844 stream = NULL; | |
| 845 } | |
| 846 return stream; | |
| 847 } | |
| 848 | |
| 849 SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFo
ntID) { | 839 SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFo
ntID) { |
| 850 #if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) | 840 #if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) |
| 851 // Skia does not support font fallback for ndk applications in order to | 841 // Skia does not support font fallback for ndk applications in order to |
| 852 // enable clients such as WebKit to customize their font selection. | 842 // enable clients such as WebKit to customize their font selection. |
| 853 // Clients can use GetFallbackFamilyNameForChar() to get the fallback | 843 // Clients can use GetFallbackFamilyNameForChar() to get the fallback |
| 854 // font for individual characters. | 844 // font for individual characters. |
| 855 return NULL; | 845 return NULL; |
| 856 #else | 846 #else |
| 857 SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); | 847 SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); |
| 858 | 848 |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 const char* fontsdir) { | 1091 const char* fontsdir) { |
| 1102 gTestMainConfigFile = mainconf; | 1092 gTestMainConfigFile = mainconf; |
| 1103 gTestFallbackConfigFile = fallbackconf; | 1093 gTestFallbackConfigFile = fallbackconf; |
| 1104 gTestFontFilePrefix = fontsdir; | 1094 gTestFontFilePrefix = fontsdir; |
| 1105 SkASSERT(gTestMainConfigFile); | 1095 SkASSERT(gTestMainConfigFile); |
| 1106 SkASSERT(gTestFallbackConfigFile); | 1096 SkASSERT(gTestFallbackConfigFile); |
| 1107 SkASSERT(gTestFontFilePrefix); | 1097 SkASSERT(gTestFontFilePrefix); |
| 1108 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", | 1098 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", |
| 1109 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); | 1099 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); |
| 1110 } | 1100 } |
| OLD | NEW |