OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 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 "SkScalerContext.h" | 10 #include "SkScalerContext.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 const void* data = desc->findEntry(tag, &len); | 68 const void* data = desc->findEntry(tag, &len); |
69 | 69 |
70 if (data) { | 70 if (data) { |
71 SkOrderedReadBuffer buffer(data, len); | 71 SkOrderedReadBuffer buffer(data, len); |
72 obj = buffer.readFlattenable(); | 72 obj = buffer.readFlattenable(); |
73 SkASSERT(buffer.offset() == buffer.size()); | 73 SkASSERT(buffer.offset() == buffer.size()); |
74 } | 74 } |
75 return obj; | 75 return obj; |
76 } | 76 } |
77 | 77 |
78 SkScalerContext::SkScalerContext(const SkDescriptor* desc) | 78 SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc) |
79 : fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, NULL))
) | 79 : fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, NULL))
) |
80 | 80 |
81 , fBaseGlyphCount(0) | 81 , fBaseGlyphCount(0) |
82 | 82 , fTypeface(SkRef(typeface)) |
83 , fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_
SkDescriptorTag))) | 83 , fPathEffect(static_cast<SkPathEffect*>(load_flattenable(desc, kPathEffect_
SkDescriptorTag))) |
84 , fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_
SkDescriptorTag))) | 84 , fMaskFilter(static_cast<SkMaskFilter*>(load_flattenable(desc, kMaskFilter_
SkDescriptorTag))) |
85 , fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_
SkDescriptorTag))) | 85 , fRasterizer(static_cast<SkRasterizer*>(load_flattenable(desc, kRasterizer_
SkDescriptorTag))) |
86 | 86 |
87 // Initialize based on our settings. Subclasses can also force this. | 87 // Initialize based on our settings. Subclasses can also force this. |
88 , fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != NULL || fRas
terizer != NULL) | 88 , fGenerateImageFromPath(fRec.fFrameWidth > 0 || fPathEffect != NULL || fRas
terizer != NULL) |
89 | 89 |
90 , fNextContext(NULL) | 90 , fNextContext(NULL) |
91 | 91 |
92 , fPreBlend(fMaskFilter ? SkMaskGamma::PreBlend() : SkScalerContext::GetMask
PreBlend(fRec)) | 92 , fPreBlend(fMaskFilter ? SkMaskGamma::PreBlend() : SkScalerContext::GetMask
PreBlend(fRec)) |
(...skipping 17 matching lines...) Expand all Loading... |
110 } | 110 } |
111 | 111 |
112 SkScalerContext::~SkScalerContext() { | 112 SkScalerContext::~SkScalerContext() { |
113 SkDELETE(fNextContext); | 113 SkDELETE(fNextContext); |
114 | 114 |
115 SkSafeUnref(fPathEffect); | 115 SkSafeUnref(fPathEffect); |
116 SkSafeUnref(fMaskFilter); | 116 SkSafeUnref(fMaskFilter); |
117 SkSafeUnref(fRasterizer); | 117 SkSafeUnref(fRasterizer); |
118 } | 118 } |
119 | 119 |
| 120 // Return the context associated with the next logical typeface, or NULL if |
| 121 // there are no more entries in the fallback chain. |
120 static SkScalerContext* allocNextContext(const SkScalerContext::Rec& rec) { | 122 static SkScalerContext* allocNextContext(const SkScalerContext::Rec& rec) { |
121 // fonthost will determine the next possible font to search, based | 123 SkTypeface* newFace = SkFontHost::NextLogicalTypeface(rec.fFontID, rec.fOrig
FontID); |
122 // on the current font in fRec. It will return NULL if ctx is our | 124 if (0 == newFace) { |
123 // last font that can be searched (i.e. ultimate fallback font) | |
124 uint32_t newFontID = SkFontHost::NextLogicalFont(rec.fFontID, rec.fOrigFontI
D); | |
125 if (0 == newFontID) { | |
126 return NULL; | 125 return NULL; |
127 } | 126 } |
| 127 |
| 128 SkAutoTUnref<SkTypeface> aur(newFace); |
| 129 uint32_t newFontID = newFace->uniqueID(); |
128 | 130 |
129 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); | 131 SkAutoDescriptor ad(sizeof(rec) + SkDescriptor::ComputeOverhead(1)); |
130 SkDescriptor* desc = ad.getDesc(); | 132 SkDescriptor* desc = ad.getDesc(); |
131 | 133 |
132 desc->init(); | 134 desc->init(); |
133 SkScalerContext::Rec* newRec = | 135 SkScalerContext::Rec* newRec = |
134 (SkScalerContext::Rec*)desc->addEntry(kRec_SkDescriptorTag, | 136 (SkScalerContext::Rec*)desc->addEntry(kRec_SkDescriptorTag, |
135 sizeof(rec), &rec); | 137 sizeof(rec), &rec); |
136 newRec->fFontID = newFontID; | 138 newRec->fFontID = newFontID; |
137 desc->computeChecksum(); | 139 desc->computeChecksum(); |
138 | 140 |
139 return SkFontHost::CreateScalerContext(desc); | 141 return newFace->createScalerContext(desc); |
140 } | 142 } |
141 | 143 |
142 /* Return the next context, creating it if its not already created, but return | 144 /* Return the next context, creating it if its not already created, but return |
143 NULL if the fonthost says there are no more fonts to fallback to. | 145 NULL if the fonthost says there are no more fonts to fallback to. |
144 */ | 146 */ |
145 SkScalerContext* SkScalerContext::getNextContext() { | 147 SkScalerContext* SkScalerContext::getNextContext() { |
146 SkScalerContext* next = fNextContext; | 148 SkScalerContext* next = fNextContext; |
147 // if next is null, then either it isn't cached yet, or we're at the | 149 // if next is null, then either it isn't cached yet, or we're at the |
148 // end of our possible chain | 150 // end of our possible chain |
149 if (NULL == next) { | 151 if (NULL == next) { |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 } | 735 } |
734 return kNone_SkAxisAlignment; | 736 return kNone_SkAxisAlignment; |
735 } | 737 } |
736 | 738 |
737 /////////////////////////////////////////////////////////////////////////////// | 739 /////////////////////////////////////////////////////////////////////////////// |
738 | 740 |
739 #include "SkFontHost.h" | 741 #include "SkFontHost.h" |
740 | 742 |
741 class SkScalerContext_Empty : public SkScalerContext { | 743 class SkScalerContext_Empty : public SkScalerContext { |
742 public: | 744 public: |
743 SkScalerContext_Empty(const SkDescriptor* desc) : SkScalerContext(desc) {} | 745 SkScalerContext_Empty(SkTypeface* face, const SkDescriptor* desc) |
| 746 : SkScalerContext(face, desc) {} |
744 | 747 |
745 protected: | 748 protected: |
746 virtual unsigned generateGlyphCount() SK_OVERRIDE { | 749 virtual unsigned generateGlyphCount() SK_OVERRIDE { |
747 return 0; | 750 return 0; |
748 } | 751 } |
749 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE { | 752 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE { |
750 return 0; | 753 return 0; |
751 } | 754 } |
752 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE { | 755 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE { |
753 glyph->zeroMetrics(); | 756 glyph->zeroMetrics(); |
(...skipping 15 matching lines...) Expand all Loading... |
769 }; | 772 }; |
770 | 773 |
771 extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc); | 774 extern SkScalerContext* SkCreateColorScalerContext(const SkDescriptor* desc); |
772 | 775 |
773 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc) const
{ | 776 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc) const
{ |
774 SkScalerContext* c = NULL; //SkCreateColorScalerContext(desc); | 777 SkScalerContext* c = NULL; //SkCreateColorScalerContext(desc); |
775 if (NULL == c) { | 778 if (NULL == c) { |
776 c = this->onCreateScalerContext(desc); | 779 c = this->onCreateScalerContext(desc); |
777 } | 780 } |
778 if (NULL == c) { | 781 if (NULL == c) { |
779 c = SkNEW_ARGS(SkScalerContext_Empty, (desc)); | 782 c = SkNEW_ARGS(SkScalerContext_Empty, |
| 783 (const_cast<SkTypeface*>(this), desc)); |
780 } | 784 } |
781 return c; | 785 return c; |
782 } | 786 } |
783 | 787 |
784 | 788 |
OLD | NEW |