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 "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
10 #include "SkGraphics.h" | 11 #include "SkGraphics.h" |
11 #include "SkDescriptor.h" | 12 #include "SkDescriptor.h" |
12 #include "SkPaint.h" | 13 #include "SkPaint.h" |
13 #include "SkString.h" | 14 #include "SkString.h" |
14 #include "SkStream.h" | 15 #include "SkStream.h" |
15 #include "SkThread.h" | 16 #include "SkThread.h" |
16 #include "SkTSearch.h" | 17 #include "SkTSearch.h" |
17 #include "SkTypeface_android.h" | 18 #include "SkTypeface_android.h" |
18 #include "FontHostConfiguration_android.h" | 19 #include "FontHostConfiguration_android.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 NameFamilyPair* pair = &list[i]; | 274 NameFamilyPair* pair = &list[i]; |
274 if (pair->fFamily == emptyFamily) { | 275 if (pair->fFamily == emptyFamily) { |
275 pair->destruct(); | 276 pair->destruct(); |
276 list.remove(i); | 277 list.remove(i); |
277 } | 278 } |
278 } | 279 } |
279 } | 280 } |
280 | 281 |
281 /////////////////////////////////////////////////////////////////////////////// | 282 /////////////////////////////////////////////////////////////////////////////// |
282 | 283 |
283 class FamilyTypeface : public SkTypeface { | 284 class FamilyTypeface : public SkTypeface_FreeType { |
284 public: | 285 public: |
285 FamilyTypeface(Style style, bool sysFont, SkTypeface* familyMember, | 286 FamilyTypeface(Style style, bool sysFont, SkTypeface* familyMember, |
286 bool isFixedWidth) | 287 bool isFixedWidth) |
287 : SkTypeface(style, sk_atomic_inc(&gUniqueFontID) + 1, isFixedWidth) { | 288 : INHERITED(style, sk_atomic_inc(&gUniqueFontID) + 1, isFixedWidth) { |
288 fIsSysFont = sysFont; | 289 fIsSysFont = sysFont; |
289 | 290 |
290 // our caller has acquired the gFamilyHeadAndNameListMutex so this is sa
fe | 291 // our caller has acquired the gFamilyHeadAndNameListMutex so this is sa
fe |
291 FamilyRec* rec = NULL; | 292 FamilyRec* rec = NULL; |
292 if (familyMember) { | 293 if (familyMember) { |
293 rec = find_family(familyMember); | 294 rec = find_family(familyMember); |
294 SkASSERT(rec); | 295 SkASSERT(rec); |
295 } else { | 296 } else { |
296 rec = SkNEW(FamilyRec); | 297 rec = SkNEW(FamilyRec); |
297 } | 298 } |
(...skipping 14 matching lines...) Expand all Loading... |
312 | 313 |
313 bool isSysFont() const { return fIsSysFont; } | 314 bool isSysFont() const { return fIsSysFont; } |
314 | 315 |
315 virtual SkStream* openStream() = 0; | 316 virtual SkStream* openStream() = 0; |
316 virtual const char* getUniqueString() const = 0; | 317 virtual const char* getUniqueString() const = 0; |
317 virtual const char* getFilePath() const = 0; | 318 virtual const char* getFilePath() const = 0; |
318 | 319 |
319 private: | 320 private: |
320 bool fIsSysFont; | 321 bool fIsSysFont; |
321 | 322 |
322 typedef SkTypeface INHERITED; | 323 typedef SkTypeface_FreeType INHERITED; |
323 }; | 324 }; |
324 | 325 |
325 /////////////////////////////////////////////////////////////////////////////// | 326 /////////////////////////////////////////////////////////////////////////////// |
326 | 327 |
327 class StreamTypeface : public FamilyTypeface { | 328 class StreamTypeface : public FamilyTypeface { |
328 public: | 329 public: |
329 StreamTypeface(Style style, bool sysFont, SkTypeface* familyMember, | 330 StreamTypeface(Style style, bool sysFont, SkTypeface* familyMember, |
330 SkStream* stream, bool isFixedWidth) | 331 SkStream* stream, bool isFixedWidth) |
331 : INHERITED(style, sysFont, familyMember, isFixedWidth) { | 332 : INHERITED(style, sysFont, familyMember, isFixedWidth) { |
332 SkASSERT(stream); | 333 SkASSERT(stream); |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 } | 860 } |
860 if (index) { | 861 if (index) { |
861 *index = 0; // we don't have collections (yet) | 862 *index = 0; // we don't have collections (yet) |
862 } | 863 } |
863 return size; | 864 return size; |
864 } else { | 865 } else { |
865 return 0; | 866 return 0; |
866 } | 867 } |
867 } | 868 } |
868 | 869 |
869 SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) { | 870 SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFo
ntID) { |
870 #if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) | 871 #if defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) |
871 // Skia does not support font fallback for ndk applications in order to | 872 // Skia does not support font fallback for ndk applications in order to |
872 // enable clients such as WebKit to customize their font selection. | 873 // enable clients such as WebKit to customize their font selection. |
873 // Clients can use GetFallbackFamilyNameForChar() to get the fallback | 874 // Clients can use GetFallbackFamilyNameForChar() to get the fallback |
874 // font for individual characters. | 875 // font for individual characters. |
875 return 0; | 876 return NULL; |
876 #else | 877 #else |
877 SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); | 878 SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); |
878 | 879 |
879 load_system_fonts(); | 880 load_system_fonts(); |
880 | 881 |
881 const SkTypeface* origTypeface = find_from_uniqueID(origFontID); | 882 const SkTypeface* origTypeface = find_from_uniqueID(origFontID); |
882 const SkTypeface* currTypeface = find_from_uniqueID(currFontID); | 883 const SkTypeface* currTypeface = find_from_uniqueID(currFontID); |
883 | 884 |
884 SkASSERT(origTypeface != 0); | 885 SkASSERT(origTypeface != 0); |
885 SkASSERT(currTypeface != 0); | 886 SkASSERT(currTypeface != 0); |
886 SkASSERT(gFallbackFonts); | 887 SkASSERT(gFallbackFonts); |
887 | 888 |
888 // Our fallback list always stores the id of the plain in each fallback | 889 // Our fallback list always stores the id of the plain in each fallback |
889 // family, so we transform currFontID to its plain equivalent. | 890 // family, so we transform currFontID to its plain equivalent. |
890 currFontID = find_typeface(currTypeface, SkTypeface::kNormal)->uniqueID(); | 891 currFontID = find_typeface(currTypeface, SkTypeface::kNormal)->uniqueID(); |
891 | 892 |
892 /* First see if fontID is already one of our fallbacks. If so, return | 893 /* First see if fontID is already one of our fallbacks. If so, return |
893 its successor. If fontID is not in our list, then return the first one | 894 its successor. If fontID is not in our list, then return the first one |
894 in our list. Note: list is zero-terminated, and returning zero means | 895 in our list. Note: list is zero-terminated, and returning zero means |
895 we have no more fonts to use for fallbacks. | 896 we have no more fonts to use for fallbacks. |
896 */ | 897 */ |
897 const uint32_t* list = gFallbackFonts; | 898 const uint32_t* list = gFallbackFonts; |
898 for (int i = 0; list[i] != 0; i++) { | 899 for (int i = 0; list[i] != 0; i++) { |
899 if (list[i] == currFontID) { | 900 if (list[i] == currFontID) { |
900 if (list[i+1] == 0) | 901 if (list[i+1] == 0) |
901 return 0; | 902 return NULL; |
902 const SkTypeface* nextTypeface = find_from_uniqueID(list[i+1]); | 903 const SkTypeface* nextTypeface = find_from_uniqueID(list[i+1]); |
903 return find_typeface(nextTypeface, origTypeface->style())->uniqueID(
); | 904 return SkRef(find_typeface(nextTypeface, origTypeface->style())); |
904 } | 905 } |
905 } | 906 } |
906 | 907 |
907 // If we get here, currFontID was not a fallback, so we start at the | 908 // If we get here, currFontID was not a fallback, so we start at the |
908 // beginning of our list. Assuming there is at least one fallback font, | 909 // beginning of our list. Assuming there is at least one fallback font, |
909 // i.e. gFallbackFonts[0] != 0. | 910 // i.e. gFallbackFonts[0] != 0. |
910 const SkTypeface* firstTypeface = find_from_uniqueID(list[0]); | 911 const SkTypeface* firstTypeface = find_from_uniqueID(list[0]); |
911 return find_typeface(firstTypeface, origTypeface->style())->uniqueID(); | 912 return SkRef(find_typeface(firstTypeface, origTypeface->style())); |
912 #endif | 913 #endif |
913 } | 914 } |
914 | 915 |
915 /////////////////////////////////////////////////////////////////////////////// | 916 /////////////////////////////////////////////////////////////////////////////// |
916 | 917 |
917 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { | 918 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { |
918 if (NULL == stream || stream->getLength() <= 0) { | 919 if (NULL == stream || stream->getLength() <= 0) { |
919 return NULL; | 920 return NULL; |
920 } | 921 } |
921 | 922 |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 const char* fontsdir) { | 1122 const char* fontsdir) { |
1122 gTestMainConfigFile = mainconf; | 1123 gTestMainConfigFile = mainconf; |
1123 gTestFallbackConfigFile = fallbackconf; | 1124 gTestFallbackConfigFile = fallbackconf; |
1124 gTestFontFilePrefix = fontsdir; | 1125 gTestFontFilePrefix = fontsdir; |
1125 SkASSERT(gTestMainConfigFile); | 1126 SkASSERT(gTestMainConfigFile); |
1126 SkASSERT(gTestFallbackConfigFile); | 1127 SkASSERT(gTestFallbackConfigFile); |
1127 SkASSERT(gTestFontFilePrefix); | 1128 SkASSERT(gTestFontFilePrefix); |
1128 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", | 1129 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", |
1129 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); | 1130 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); |
1130 } | 1131 } |
OLD | NEW |