OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2008 Google Inc. | 2 * Copyright 2008 Google Inc. |
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 "SkFontConfigInterface.h" | 8 #include "SkFontConfigInterface.h" |
9 #include "SkFontDescriptor.h" | 9 #include "SkFontDescriptor.h" |
10 #include "SkFontHost.h" | 10 #include "SkFontHost.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 } | 240 } |
241 // failed to allocate, so just skip and create-from-name | 241 // failed to allocate, so just skip and create-from-name |
242 stream->skip(length); | 242 stream->skip(length); |
243 } | 243 } |
244 | 244 |
245 return SkFontHost::CreateTypeface(NULL, familyName, style); | 245 return SkFontHost::CreateTypeface(NULL, familyName, style); |
246 } | 246 } |
247 | 247 |
248 /////////////////////////////////////////////////////////////////////////////// | 248 /////////////////////////////////////////////////////////////////////////////// |
249 | 249 |
250 static SkStream* open_stream(const FontConfigTypeface* face) { | 250 static SkStream* open_stream(const FontConfigTypeface* face, int* ttcIndex) { |
251 SkStream* stream = face->getLocalStream(); | 251 SkStream* stream = face->getLocalStream(); |
252 int index; | |
252 if (stream) { | 253 if (stream) { |
253 stream->ref(); | 254 stream->ref(); |
255 // should have been provided by CreateFromStream() | |
256 *ttcIndex = 0; | |
254 } else { | 257 } else { |
255 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); | 258 SkAutoTUnref<SkFontConfigInterface> fci(RefFCI()); |
256 if (NULL == fci.get()) { | 259 if (NULL == fci.get()) { |
257 return NULL; | 260 return NULL; |
258 } | 261 } |
259 stream = fci->openStream(face->getIdentity()); | 262 stream = fci->openStream(face->getIdentity()); |
263 // ttcIndex should be returned explicitly by openStream() | |
264 *ttcIndex = (int)face->getIdentity().fIntPtr; | |
260 } | 265 } |
261 return stream; | 266 return stream; |
262 } | 267 } |
263 | 268 |
264 SkStream* SkFontHost::OpenStream(uint32_t id) { | 269 SkStream* SkFontHost::OpenStream(uint32_t id) { |
265 FontConfigTypeface* face = (FontConfigTypeface*)SkTypefaceCache::FindByID(id ); | 270 FontConfigTypeface* face = (FontConfigTypeface*)SkTypefaceCache::FindByID(id ); |
266 if (NULL == face) { | 271 if (NULL == face) { |
267 return NULL; | 272 return NULL; |
268 } | 273 } |
269 return open_stream(face); | 274 |
275 int ttcIndex; | |
276 // We should return ttcIndex from this call. | |
277 return open_stream(face, &ttcIndex); | |
270 } | 278 } |
271 | 279 |
272 size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, | 280 size_t SkFontHost::GetFileName(SkFontID fontID, char path[], size_t length, |
273 int32_t* index) { | 281 int32_t* index) { |
274 FontConfigTypeface* face = (FontConfigTypeface*)SkTypefaceCache::FindByID(fo ntID); | 282 FontConfigTypeface* face = (FontConfigTypeface*)SkTypefaceCache::FindByID(fo ntID); |
275 if (NULL == face || face->getLocalStream()) { | 283 if (NULL == face || face->getLocalStream()) { |
276 return 0; | 284 return 0; |
277 } | 285 } |
278 | 286 |
279 // Here we cheat, and "know" what is in the identity fields. | 287 // Here we cheat, and "know" what is in the identity fields. |
280 | 288 |
281 const SkString& filename = face->getIdentity().fString; | 289 const SkString& filename = face->getIdentity().fString; |
282 if (index) { | 290 if (index) { |
283 *index = (int32_t)face->getIdentity().fIntPtr; | 291 *index = (int32_t)face->getIdentity().fIntPtr; |
284 } | 292 } |
285 if (path) { | 293 if (path) { |
286 size_t len = SkMin32(length, filename.size()); | 294 size_t len = SkMin32(length, filename.size()); |
287 memcpy(path, filename.c_str(), len); | 295 memcpy(path, filename.c_str(), len); |
288 } | 296 } |
289 return filename.size(); | 297 return filename.size(); |
290 } | 298 } |
291 | 299 |
292 /////////////////////////////////////////////////////////////////////////////// | 300 /////////////////////////////////////////////////////////////////////////////// |
293 | 301 |
294 int FontConfigTypeface::onGetTableTags(SkFontTableTag tags[]) const { | 302 int FontConfigTypeface::onGetTableTags(SkFontTableTag tags[]) const { |
295 SkAutoTUnref<SkStream> stream(open_stream(this)); | 303 int ttcIndex; |
296 return stream.get() ? SkFontStream::GetTableTags(stream, tags) : 0; | 304 SkAutoTUnref<SkStream> stream(open_stream(this, &ttcIndex)); |
305 return stream.get() ? | |
bungeman-skia
2013/03/05 22:07:33
I know it isn't as popular, but I prefer formattin
| |
306 SkFontStream::GetTableTags(stream, ttcIndex, tags) : | |
307 0; | |
297 } | 308 } |
298 | 309 |
299 size_t FontConfigTypeface::onGetTableData(SkFontTableTag tag, size_t offset, | 310 size_t FontConfigTypeface::onGetTableData(SkFontTableTag tag, size_t offset, |
300 size_t length, void* data) const { | 311 size_t length, void* data) const { |
301 SkAutoTUnref<SkStream> stream(open_stream(this)); | 312 int ttcIndex; |
313 SkAutoTUnref<SkStream> stream(open_stream(this, &ttcIndex)); | |
302 return stream.get() ? | 314 return stream.get() ? |
303 SkFontStream::GetTableData(stream, tag, offset, length, data) : | 315 SkFontStream::GetTableData(stream, ttcIndex, |
304 0; | 316 tag, offset, length, data) : |
317 0; | |
305 } | 318 } |
306 | 319 |
307 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const { | 320 void FontConfigTypeface::onGetFontDescriptor(SkFontDescriptor* desc) const { |
308 desc->setStyle(this->style()); | 321 desc->setStyle(this->style()); |
309 desc->setFamilyName(this->getFamilyName()); | 322 desc->setFamilyName(this->getFamilyName()); |
310 } | 323 } |
OLD | NEW |