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 "SkAdvancedTypefaceMetrics.h" | 8 #include "SkAdvancedTypefaceMetrics.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 bool shouldSubpixelBitmap(const SkGlyph&, const SkMatrix&); | 227 bool shouldSubpixelBitmap(const SkGlyph&, const SkMatrix&); |
228 }; | 228 }; |
229 | 229 |
230 /////////////////////////////////////////////////////////////////////////// | 230 /////////////////////////////////////////////////////////////////////////// |
231 /////////////////////////////////////////////////////////////////////////// | 231 /////////////////////////////////////////////////////////////////////////// |
232 | 232 |
233 struct SkFaceRec { | 233 struct SkFaceRec { |
234 SkFaceRec* fNext; | 234 SkFaceRec* fNext; |
235 FT_Face fFace; | 235 FT_Face fFace; |
236 FT_StreamRec fFTStream; | 236 FT_StreamRec fFTStream; |
237 SkAutoTDelete<SkStreamAsset> fSkStream; | 237 std::unique_ptr<SkStreamAsset> fSkStream; |
238 uint32_t fRefCnt; | 238 uint32_t fRefCnt; |
239 uint32_t fFontID; | 239 uint32_t fFontID; |
240 | 240 |
241 // assumes ownership of the stream, will delete when its done | 241 SkFaceRec(std::unique_ptr<SkStreamAsset> stream, uint32_t fontID); |
242 SkFaceRec(SkStreamAsset* strm, uint32_t fontID); | |
243 }; | 242 }; |
244 | 243 |
245 extern "C" { | 244 extern "C" { |
246 static unsigned long sk_ft_stream_io(FT_Stream ftStream, | 245 static unsigned long sk_ft_stream_io(FT_Stream ftStream, |
247 unsigned long offset, | 246 unsigned long offset, |
248 unsigned char* buffer, | 247 unsigned char* buffer, |
249 unsigned long count) | 248 unsigned long count) |
250 { | 249 { |
251 SkStreamAsset* stream = static_cast<SkStreamAsset*>(ftStream->descriptor
.pointer); | 250 SkStreamAsset* stream = static_cast<SkStreamAsset*>(ftStream->descriptor
.pointer); |
252 | 251 |
253 if (count) { | 252 if (count) { |
254 if (!stream->seek(offset)) { | 253 if (!stream->seek(offset)) { |
255 return 0; | 254 return 0; |
256 } | 255 } |
257 count = stream->read(buffer, count); | 256 count = stream->read(buffer, count); |
258 } | 257 } |
259 return count; | 258 return count; |
260 } | 259 } |
261 | 260 |
262 static void sk_ft_stream_close(FT_Stream) {} | 261 static void sk_ft_stream_close(FT_Stream) {} |
263 } | 262 } |
264 | 263 |
265 SkFaceRec::SkFaceRec(SkStreamAsset* stream, uint32_t fontID) | 264 SkFaceRec::SkFaceRec(std::unique_ptr<SkStreamAsset> stream, uint32_t fontID) |
266 : fNext(nullptr), fSkStream(stream), fRefCnt(1), fFontID(fontID) | 265 : fNext(nullptr), fSkStream(std::move(stream)), fRefCnt(1), fFontID(font
ID) |
267 { | 266 { |
268 sk_bzero(&fFTStream, sizeof(fFTStream)); | 267 sk_bzero(&fFTStream, sizeof(fFTStream)); |
269 fFTStream.size = fSkStream->getLength(); | 268 fFTStream.size = fSkStream->getLength(); |
270 fFTStream.descriptor.pointer = fSkStream; | 269 fFTStream.descriptor.pointer = fSkStream.get(); |
271 fFTStream.read = sk_ft_stream_io; | 270 fFTStream.read = sk_ft_stream_io; |
272 fFTStream.close = sk_ft_stream_close; | 271 fFTStream.close = sk_ft_stream_close; |
273 } | 272 } |
274 | 273 |
275 static void ft_face_setup_axes(FT_Face face, const SkFontData& data) { | 274 static void ft_face_setup_axes(FT_Face face, const SkFontData& data) { |
276 if (!(face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS)) { | 275 if (!(face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS)) { |
277 return; | 276 return; |
278 } | 277 } |
279 | 278 |
280 SkDEBUGCODE( | 279 SkDEBUGCODE( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 SkFaceRec* rec = gFaceRecHead; | 311 SkFaceRec* rec = gFaceRecHead; |
313 while (rec) { | 312 while (rec) { |
314 if (rec->fFontID == fontID) { | 313 if (rec->fFontID == fontID) { |
315 SkASSERT(rec->fFace); | 314 SkASSERT(rec->fFace); |
316 rec->fRefCnt += 1; | 315 rec->fRefCnt += 1; |
317 return rec->fFace; | 316 return rec->fFace; |
318 } | 317 } |
319 rec = rec->fNext; | 318 rec = rec->fNext; |
320 } | 319 } |
321 | 320 |
322 SkAutoTDelete<SkFontData> data(typeface->createFontData()); | 321 std::unique_ptr<SkFontData> data = typeface->makeFontData(); |
323 if (nullptr == data || !data->hasStream()) { | 322 if (nullptr == data || !data->hasStream()) { |
324 return nullptr; | 323 return nullptr; |
325 } | 324 } |
326 | 325 |
327 // this passes ownership of stream to the rec | |
328 rec = new SkFaceRec(data->detachStream(), fontID); | 326 rec = new SkFaceRec(data->detachStream(), fontID); |
329 | 327 |
330 FT_Open_Args args; | 328 FT_Open_Args args; |
331 memset(&args, 0, sizeof(args)); | 329 memset(&args, 0, sizeof(args)); |
332 const void* memoryBase = rec->fSkStream->getMemoryBase(); | 330 const void* memoryBase = rec->fSkStream->getMemoryBase(); |
333 if (memoryBase) { | 331 if (memoryBase) { |
334 args.flags = FT_OPEN_MEMORY; | 332 args.flags = FT_OPEN_MEMORY; |
335 args.memory_base = (const FT_Byte*)memoryBase; | 333 args.memory_base = (const FT_Byte*)memoryBase; |
336 args.memory_size = rec->fSkStream->getLength(); | 334 args.memory_size = rec->fSkStream->getLength(); |
337 } else { | 335 } else { |
(...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1769 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n", | 1767 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n", |
1770 name.c_str(), | 1768 name.c_str(), |
1771 (skTag >> 24) & 0xFF, | 1769 (skTag >> 24) & 0xFF, |
1772 (skTag >> 16) & 0xFF, | 1770 (skTag >> 16) & 0xFF, |
1773 (skTag >> 8) & 0xFF, | 1771 (skTag >> 8) & 0xFF, |
1774 (skTag) & 0xFF)); | 1772 (skTag) & 0xFF)); |
1775 } | 1773 } |
1776 } | 1774 } |
1777 ) | 1775 ) |
1778 } | 1776 } |
OLD | NEW |