Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/ports/SkFontHost_FreeType.cpp

Issue 882763002: SkFontHost_FreeType takes advantage of SkStreamAsset. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 void updateGlyphIfLCD(SkGlyph* glyph); 226 void updateGlyphIfLCD(SkGlyph* glyph);
227 // Caller must lock gFTMutex before calling this function. 227 // Caller must lock gFTMutex before calling this function.
228 // update FreeType2 glyph slot with glyph emboldened 228 // update FreeType2 glyph slot with glyph emboldened
229 void emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph); 229 void emboldenIfNeeded(FT_Face face, FT_GlyphSlot glyph);
230 }; 230 };
231 231
232 /////////////////////////////////////////////////////////////////////////// 232 ///////////////////////////////////////////////////////////////////////////
233 /////////////////////////////////////////////////////////////////////////// 233 ///////////////////////////////////////////////////////////////////////////
234 234
235 struct SkFaceRec { 235 struct SkFaceRec {
236 SkFaceRec* fNext; 236 SkFaceRec* fNext;
237 FT_Face fFace; 237 FT_Face fFace;
238 FT_StreamRec fFTStream; 238 FT_StreamRec fFTStream;
239 SkAutoTDelete<SkStream> fSkStream; 239 SkAutoTDelete<SkStreamAsset> fSkStream;
240 uint32_t fRefCnt; 240 uint32_t fRefCnt;
241 uint32_t fFontID; 241 uint32_t fFontID;
242 242
243 // assumes ownership of the stream, will delete when its done 243 // assumes ownership of the stream, will delete when its done
244 SkFaceRec(SkStream* strm, uint32_t fontID); 244 SkFaceRec(SkStreamAsset* strm, uint32_t fontID);
245 }; 245 };
246 246
247 extern "C" { 247 extern "C" {
248 static unsigned long sk_ft_stream_io(FT_Stream stream, 248 static unsigned long sk_ft_stream_io(FT_Stream ftStream,
249 unsigned long offset, 249 unsigned long offset,
250 unsigned char* buffer, 250 unsigned char* buffer,
251 unsigned long count) 251 unsigned long count)
252 { 252 {
253 SkStream* str = (SkStream*)stream->descriptor.pointer; 253 SkStreamAsset* stream = static_cast<SkStreamAsset*>(ftStream->descriptor .pointer);
254 254
255 if (count) { 255 if (count) {
256 if (!str->rewind()) { 256 if (!stream->seek(offset)) {
257 return 0; 257 return 0;
258 } 258 }
259 if (offset) { 259 count = stream->read(buffer, count);
260 if (str->skip(offset) != offset) {
261 return 0;
262 }
263 }
264 count = str->read(buffer, count);
265 } 260 }
266 return count; 261 return count;
267 } 262 }
268 263
269 static void sk_ft_stream_close(FT_Stream) {} 264 static void sk_ft_stream_close(FT_Stream) {}
270 } 265 }
271 266
272 SkFaceRec::SkFaceRec(SkStream* strm, uint32_t fontID) 267 SkFaceRec::SkFaceRec(SkStreamAsset* stream, uint32_t fontID)
273 : fNext(NULL), fSkStream(strm), fRefCnt(1), fFontID(fontID) { 268 : fNext(NULL), fSkStream(stream), fRefCnt(1), fFontID(fontID)
274 // SkDEBUGF(("SkFaceRec: opening %s (%p)\n", key.c_str(), strm)); 269 {
275
276 sk_bzero(&fFTStream, sizeof(fFTStream)); 270 sk_bzero(&fFTStream, sizeof(fFTStream));
277 fFTStream.size = fSkStream->getLength(); 271 fFTStream.size = fSkStream->getLength();
278 fFTStream.descriptor.pointer = fSkStream; 272 fFTStream.descriptor.pointer = fSkStream;
279 fFTStream.read = sk_ft_stream_io; 273 fFTStream.read = sk_ft_stream_io;
280 fFTStream.close = sk_ft_stream_close; 274 fFTStream.close = sk_ft_stream_close;
281 } 275 }
282 276
283 // Will return 0 on failure 277 // Will return 0 on failure
284 // Caller must lock gFTMutex before calling this function. 278 // Caller must lock gFTMutex before calling this function.
285 static SkFaceRec* ref_ft_face(const SkTypeface* typeface) { 279 static SkFaceRec* ref_ft_face(const SkTypeface* typeface) {
286 gFTMutex.assertHeld(); 280 gFTMutex.assertHeld();
287 281
288 const SkFontID fontID = typeface->uniqueID(); 282 const SkFontID fontID = typeface->uniqueID();
289 SkFaceRec* rec = gFaceRecHead; 283 SkFaceRec* rec = gFaceRecHead;
290 while (rec) { 284 while (rec) {
291 if (rec->fFontID == fontID) { 285 if (rec->fFontID == fontID) {
292 SkASSERT(rec->fFace); 286 SkASSERT(rec->fFace);
293 rec->fRefCnt += 1; 287 rec->fRefCnt += 1;
294 return rec; 288 return rec;
295 } 289 }
296 rec = rec->fNext; 290 rec = rec->fNext;
297 } 291 }
298 292
299 int face_index; 293 int face_index;
300 SkStream* strm = typeface->openStream(&face_index); 294 SkStreamAsset* stream = typeface->openStream(&face_index);
301 if (NULL == strm) { 295 if (NULL == stream) {
302 return NULL; 296 return NULL;
303 } 297 }
304 298
305 // this passes ownership of strm to the rec 299 // this passes ownership of stream to the rec
306 rec = SkNEW_ARGS(SkFaceRec, (strm, fontID)); 300 rec = SkNEW_ARGS(SkFaceRec, (stream, fontID));
307 301
308 FT_Open_Args args; 302 FT_Open_Args args;
309 memset(&args, 0, sizeof(args)); 303 memset(&args, 0, sizeof(args));
310 const void* memoryBase = strm->getMemoryBase(); 304 const void* memoryBase = stream->getMemoryBase();
311
312 if (memoryBase) { 305 if (memoryBase) {
313 args.flags = FT_OPEN_MEMORY; 306 args.flags = FT_OPEN_MEMORY;
314 args.memory_base = (const FT_Byte*)memoryBase; 307 args.memory_base = (const FT_Byte*)memoryBase;
315 args.memory_size = strm->getLength(); 308 args.memory_size = stream->getLength();
316 } else { 309 } else {
317 args.flags = FT_OPEN_STREAM; 310 args.flags = FT_OPEN_STREAM;
318 args.stream = &rec->fFTStream; 311 args.stream = &rec->fFTStream;
319 } 312 }
320 313
321 FT_Error err = FT_Open_Face(gFTLibrary->library(), &args, face_index, &rec-> fFace); 314 FT_Error err = FT_Open_Face(gFTLibrary->library(), &args, face_index, &rec-> fFace);
322 if (err) { // bad filename, try the default font 315 if (err) { // bad filename, try the default font
323 SkDEBUGF(("ERROR: unable to open font '%x'\n", fontID)); 316 SkDEBUGF(("ERROR: unable to open font '%x'\n", fontID));
324 SkDELETE(rec); 317 SkDELETE(rec);
325 return NULL; 318 return NULL;
(...skipping 1392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 if (style) { 1711 if (style) {
1719 *style = SkFontStyle(weight, width, slant); 1712 *style = SkFontStyle(weight, width, slant);
1720 } 1713 }
1721 if (isFixedPitch) { 1714 if (isFixedPitch) {
1722 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1715 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1723 } 1716 }
1724 1717
1725 FT_Done_Face(face); 1718 FT_Done_Face(face);
1726 return true; 1719 return true;
1727 } 1720 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698