OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 The Android Open Source Project | 2 * Copyright 2011 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 "SkAdvancedTypefaceMetrics.h" | 8 #include "SkAdvancedTypefaceMetrics.h" |
9 #include "SkEndian.h" | 9 #include "SkEndian.h" |
10 #include "SkFontDescriptor.h" | 10 #include "SkFontDescriptor.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 } | 149 } |
150 | 150 |
151 /////////////////////////////////////////////////////////////////////////////// | 151 /////////////////////////////////////////////////////////////////////////////// |
152 | 152 |
153 void SkTypeface::serialize(SkWStream* wstream) const { | 153 void SkTypeface::serialize(SkWStream* wstream) const { |
154 bool isLocal = false; | 154 bool isLocal = false; |
155 SkFontDescriptor desc(this->style()); | 155 SkFontDescriptor desc(this->style()); |
156 this->onGetFontDescriptor(&desc, &isLocal); | 156 this->onGetFontDescriptor(&desc, &isLocal); |
157 | 157 |
158 // Embed font data if it's a local font. | 158 // Embed font data if it's a local font. |
159 if (isLocal && NULL == desc.getFontData()) { | 159 if (isLocal && !desc.hasFontData()) { |
160 int ttcIndex; | 160 int ttcIndex; |
161 desc.setFontData(this->onOpenStream(&ttcIndex)); | 161 desc.setFontData(this->onOpenStream(&ttcIndex)); |
162 desc.setFontIndex(ttcIndex); | 162 desc.setFontIndex(ttcIndex); |
163 } | 163 } |
164 desc.serialize(wstream); | 164 desc.serialize(wstream); |
165 } | 165 } |
166 | 166 |
167 void SkTypeface::serializeForcingEmbedding(SkWStream* wstream) const { | 167 void SkTypeface::serializeForcingEmbedding(SkWStream* wstream) const { |
168 bool ignoredIsLocal; | 168 bool ignoredIsLocal; |
169 SkFontDescriptor desc(this->style()); | 169 SkFontDescriptor desc(this->style()); |
170 this->onGetFontDescriptor(&desc, &ignoredIsLocal); | 170 this->onGetFontDescriptor(&desc, &ignoredIsLocal); |
171 | 171 |
172 // Always embed font data. | 172 // Always embed font data. |
173 if (NULL == desc.getFontData()) { | 173 if (!desc.hasFontData()) { |
174 int ttcIndex; | 174 int ttcIndex; |
175 desc.setFontData(this->onOpenStream(&ttcIndex)); | 175 desc.setFontData(this->onOpenStream(&ttcIndex)); |
176 desc.setFontIndex(ttcIndex); | 176 desc.setFontIndex(ttcIndex); |
177 } | 177 } |
178 desc.serialize(wstream); | 178 desc.serialize(wstream); |
179 } | 179 } |
180 | 180 |
181 SkTypeface* SkTypeface::Deserialize(SkStream* stream) { | 181 SkTypeface* SkTypeface::Deserialize(SkStream* stream) { |
182 SkFontDescriptor desc(stream); | 182 SkFontDescriptor desc(stream); |
183 SkStream* data = desc.getFontData(); | 183 SkStream* data = desc.transferFontData(); |
184 if (data) { | 184 if (data) { |
185 SkTypeface* typeface = SkTypeface::CreateFromStream(data, desc.getFontIn
dex()); | 185 SkTypeface* typeface = SkTypeface::CreateFromStream(data, desc.getFontIn
dex()); |
186 if (typeface) { | 186 if (typeface) { |
187 return typeface; | 187 return typeface; |
188 } | 188 } |
189 } | 189 } |
190 return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle()); | 190 return SkTypeface::CreateFromName(desc.getFamilyName(), desc.getStyle()); |
191 } | 191 } |
192 | 192 |
193 /////////////////////////////////////////////////////////////////////////////// | 193 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 if (ctx.get()) { | 343 if (ctx.get()) { |
344 SkPaint::FontMetrics fm; | 344 SkPaint::FontMetrics fm; |
345 ctx->getFontMetrics(&fm); | 345 ctx->getFontMetrics(&fm); |
346 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, | 346 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, |
347 fm.fXMax * invTextSize, fm.fBottom * invTextSize); | 347 fm.fXMax * invTextSize, fm.fBottom * invTextSize); |
348 return true; | 348 return true; |
349 } | 349 } |
350 return false; | 350 return false; |
351 } | 351 } |
352 | 352 |
OLD | NEW |