OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 The Android Open Source Project | 3 * Copyright 2011 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkFontHost.h" | 10 #include "SkFontHost.h" |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 406 |
407 // these globals are assigned (once) by load_system_fonts() | 407 // these globals are assigned (once) by load_system_fonts() |
408 static FamilyRec* gDefaultFamily; | 408 static FamilyRec* gDefaultFamily; |
409 static SkTypeface* gDefaultNormal; | 409 static SkTypeface* gDefaultNormal; |
410 | 410 |
411 /* This is sized conservatively, assuming that it will never be a size issue. | 411 /* This is sized conservatively, assuming that it will never be a size issue. |
412 It will be initialized in load_system_fonts(), and will be filled with the | 412 It will be initialized in load_system_fonts(), and will be filled with the |
413 fontIDs that can be used for fallback consideration, in sorted order (sorted | 413 fontIDs that can be used for fallback consideration, in sorted order (sorted |
414 meaning element[0] should be used first, then element[1], etc. When we hit | 414 meaning element[0] should be used first, then element[1], etc. When we hit |
415 a fontID==0 in the array, the list is done, hence our allocation size is | 415 a fontID==0 in the array, the list is done, hence our allocation size is |
416 +1 the total number of possible system fonts. Also see NextLogicalFont(). | 416 +1 the total number of possible system fonts. Also see NextLogicalTypeface()
. |
417 */ | 417 */ |
418 static uint32_t gFallbackFonts[SK_ARRAY_COUNT(gSystemFonts)+1]; | 418 static uint32_t gFallbackFonts[SK_ARRAY_COUNT(gSystemFonts)+1]; |
419 | 419 |
420 /* Called once (ensured by the sentinel check at the beginning of our body). | 420 /* Called once (ensured by the sentinel check at the beginning of our body). |
421 Initializes all the globals, and register the system fonts. | 421 Initializes all the globals, and register the system fonts. |
422 */ | 422 */ |
423 static void load_system_fonts() { | 423 static void load_system_fonts() { |
424 // check if we've already be called | 424 // check if we've already be called |
425 if (NULL != gDefaultNormal) { | 425 if (NULL != gDefaultNormal) { |
426 return; | 426 return; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 } | 596 } |
597 if (index) { | 597 if (index) { |
598 *index = 0; // we don't have collections (yet) | 598 *index = 0; // we don't have collections (yet) |
599 } | 599 } |
600 return size; | 600 return size; |
601 } else { | 601 } else { |
602 return 0; | 602 return 0; |
603 } | 603 } |
604 } | 604 } |
605 | 605 |
606 SkFontID SkFontHost::NextLogicalFont(SkFontID currFontID, SkFontID origFontID) { | 606 SkTypeface* SkFontHost::NextLogicalTypeface(SkFontID currFontID, SkFontID origFo
ntID) { |
607 load_system_fonts(); | 607 load_system_fonts(); |
608 | 608 |
609 /* First see if fontID is already one of our fallbacks. If so, return | 609 /* First see if fontID is already one of our fallbacks. If so, return |
610 its successor. If fontID is not in our list, then return the first one | 610 its successor. If fontID is not in our list, then return the first one |
611 in our list. Note: list is zero-terminated, and returning zero means | 611 in our list. Note: list is zero-terminated, and returning zero means |
612 we have no more fonts to use for fallbacks. | 612 we have no more fonts to use for fallbacks. |
613 */ | 613 */ |
614 const uint32_t* list = gFallbackFonts; | 614 const uint32_t* list = gFallbackFonts; |
615 for (int i = 0; list[i] != 0; i++) { | 615 for (int i = 0; list[i] != 0; i++) { |
616 if (list[i] == currFontID) { | 616 if (list[i] == currFontID) { |
617 return list[i+1]; | 617 return SkSafeRef(find_from_uniqueID(list[i+1])); |
618 } | 618 } |
619 } | 619 } |
620 return list[0]; | 620 return SkSafeRef(list[0]); |
621 } | 621 } |
622 | 622 |
623 /////////////////////////////////////////////////////////////////////////////// | 623 /////////////////////////////////////////////////////////////////////////////// |
624 | 624 |
625 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { | 625 SkTypeface* SkFontHost::CreateTypefaceFromStream(SkStream* stream) { |
626 if (NULL == stream || stream->getLength() <= 0) { | 626 if (NULL == stream || stream->getLength() <= 0) { |
627 return NULL; | 627 return NULL; |
628 } | 628 } |
629 | 629 |
630 SkTypeface::Style style; | 630 SkTypeface::Style style; |
631 if (find_name_and_attributes(stream, NULL, &style, NULL)) { | 631 if (find_name_and_attributes(stream, NULL, &style, NULL)) { |
632 return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream)); | 632 return SkNEW_ARGS(StreamTypeface, (style, false, NULL, stream)); |
633 } else { | 633 } else { |
634 return NULL; | 634 return NULL; |
635 } | 635 } |
636 } | 636 } |
637 | 637 |
638 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { | 638 SkTypeface* SkFontHost::CreateTypefaceFromFile(const char path[]) { |
639 SkStream* stream = SkNEW_ARGS(SkMMAPStream, (path)); | 639 SkStream* stream = SkNEW_ARGS(SkMMAPStream, (path)); |
640 SkTypeface* face = SkFontHost::CreateTypefaceFromStream(stream); | 640 SkTypeface* face = SkFontHost::CreateTypefaceFromStream(stream); |
641 // since we created the stream, we let go of our ref() here | 641 // since we created the stream, we let go of our ref() here |
642 stream->unref(); | 642 stream->unref(); |
643 return face; | 643 return face; |
644 } | 644 } |
OLD | NEW |