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