| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // Private to RefFreeType and UnrefFreeType | 151 // Private to RefFreeType and UnrefFreeType |
| 152 static int gFTCount; | 152 static int gFTCount; |
| 153 | 153 |
| 154 // Caller must lock gFTMutex before calling this function. | 154 // Caller must lock gFTMutex before calling this function. |
| 155 static bool ref_ft_library() { | 155 static bool ref_ft_library() { |
| 156 gFTMutex.assertHeld(); | 156 gFTMutex.assertHeld(); |
| 157 SkASSERT(gFTCount >= 0); | 157 SkASSERT(gFTCount >= 0); |
| 158 | 158 |
| 159 if (0 == gFTCount) { | 159 if (0 == gFTCount) { |
| 160 SkASSERT(NULL == gFTLibrary); | 160 SkASSERT(NULL == gFTLibrary); |
| 161 gFTLibrary = SkNEW(FreeTypeLibrary); | 161 gFTLibrary = new FreeTypeLibrary; |
| 162 } | 162 } |
| 163 ++gFTCount; | 163 ++gFTCount; |
| 164 return gFTLibrary->library(); | 164 return gFTLibrary->library(); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Caller must lock gFTMutex before calling this function. | 167 // Caller must lock gFTMutex before calling this function. |
| 168 static void unref_ft_library() { | 168 static void unref_ft_library() { |
| 169 gFTMutex.assertHeld(); | 169 gFTMutex.assertHeld(); |
| 170 SkASSERT(gFTCount > 0); | 170 SkASSERT(gFTCount > 0); |
| 171 | 171 |
| 172 --gFTCount; | 172 --gFTCount; |
| 173 if (0 == gFTCount) { | 173 if (0 == gFTCount) { |
| 174 SkASSERT(NULL != gFTLibrary); | 174 SkASSERT(NULL != gFTLibrary); |
| 175 SkDELETE(gFTLibrary); | 175 delete gFTLibrary; |
| 176 SkDEBUGCODE(gFTLibrary = NULL;) | 176 SkDEBUGCODE(gFTLibrary = NULL;) |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 class SkScalerContext_FreeType : public SkScalerContext_FreeType_Base { | 180 class SkScalerContext_FreeType : public SkScalerContext_FreeType_Base { |
| 181 public: | 181 public: |
| 182 SkScalerContext_FreeType(SkTypeface*, const SkDescriptor* desc); | 182 SkScalerContext_FreeType(SkTypeface*, const SkDescriptor* desc); |
| 183 virtual ~SkScalerContext_FreeType(); | 183 virtual ~SkScalerContext_FreeType(); |
| 184 | 184 |
| 185 bool success() const { | 185 bool success() const { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 } | 312 } |
| 313 rec = rec->fNext; | 313 rec = rec->fNext; |
| 314 } | 314 } |
| 315 | 315 |
| 316 SkAutoTDelete<SkFontData> data(typeface->createFontData()); | 316 SkAutoTDelete<SkFontData> data(typeface->createFontData()); |
| 317 if (NULL == data || !data->hasStream()) { | 317 if (NULL == data || !data->hasStream()) { |
| 318 return NULL; | 318 return NULL; |
| 319 } | 319 } |
| 320 | 320 |
| 321 // this passes ownership of stream to the rec | 321 // this passes ownership of stream to the rec |
| 322 rec = SkNEW_ARGS(SkFaceRec, (data->detachStream(), fontID)); | 322 rec = new SkFaceRec(data->detachStream(), fontID); |
| 323 | 323 |
| 324 FT_Open_Args args; | 324 FT_Open_Args args; |
| 325 memset(&args, 0, sizeof(args)); | 325 memset(&args, 0, sizeof(args)); |
| 326 const void* memoryBase = rec->fSkStream->getMemoryBase(); | 326 const void* memoryBase = rec->fSkStream->getMemoryBase(); |
| 327 if (memoryBase) { | 327 if (memoryBase) { |
| 328 args.flags = FT_OPEN_MEMORY; | 328 args.flags = FT_OPEN_MEMORY; |
| 329 args.memory_base = (const FT_Byte*)memoryBase; | 329 args.memory_base = (const FT_Byte*)memoryBase; |
| 330 args.memory_size = rec->fSkStream->getLength(); | 330 args.memory_size = rec->fSkStream->getLength(); |
| 331 } else { | 331 } else { |
| 332 args.flags = FT_OPEN_STREAM; | 332 args.flags = FT_OPEN_STREAM; |
| 333 args.stream = &rec->fFTStream; | 333 args.stream = &rec->fFTStream; |
| 334 } | 334 } |
| 335 | 335 |
| 336 FT_Error err = FT_Open_Face(gFTLibrary->library(), &args, data->getIndex(),
&rec->fFace); | 336 FT_Error err = FT_Open_Face(gFTLibrary->library(), &args, data->getIndex(),
&rec->fFace); |
| 337 if (err) { | 337 if (err) { |
| 338 SkDEBUGF(("ERROR: unable to open font '%x'\n", fontID)); | 338 SkDEBUGF(("ERROR: unable to open font '%x'\n", fontID)); |
| 339 SkDELETE(rec); | 339 delete rec; |
| 340 return NULL; | 340 return NULL; |
| 341 } | 341 } |
| 342 SkASSERT(rec->fFace); | 342 SkASSERT(rec->fFace); |
| 343 | 343 |
| 344 ft_face_setup_axes(rec->fFace, *data); | 344 ft_face_setup_axes(rec->fFace, *data); |
| 345 | 345 |
| 346 // FreeType will set the charmap to the "most unicode" cmap if it exists. | 346 // FreeType will set the charmap to the "most unicode" cmap if it exists. |
| 347 // If there are no unicode cmaps, the charmap is set to NULL. | 347 // If there are no unicode cmaps, the charmap is set to NULL. |
| 348 // However, "symbol" cmaps should also be considered "fallback unicode" cmap
s | 348 // However, "symbol" cmaps should also be considered "fallback unicode" cmap
s |
| 349 // because they are effectively private use area only (even if they aren't). | 349 // because they are effectively private use area only (even if they aren't). |
| (...skipping 17 matching lines...) Expand all Loading... |
| 367 while (rec) { | 367 while (rec) { |
| 368 SkFaceRec* next = rec->fNext; | 368 SkFaceRec* next = rec->fNext; |
| 369 if (rec->fFace == face) { | 369 if (rec->fFace == face) { |
| 370 if (--rec->fRefCnt == 0) { | 370 if (--rec->fRefCnt == 0) { |
| 371 if (prev) { | 371 if (prev) { |
| 372 prev->fNext = next; | 372 prev->fNext = next; |
| 373 } else { | 373 } else { |
| 374 gFaceRecHead = next; | 374 gFaceRecHead = next; |
| 375 } | 375 } |
| 376 FT_Done_Face(face); | 376 FT_Done_Face(face); |
| 377 SkDELETE(rec); | 377 delete rec; |
| 378 } | 378 } |
| 379 return; | 379 return; |
| 380 } | 380 } |
| 381 prev = rec; | 381 prev = rec; |
| 382 rec = next; | 382 rec = next; |
| 383 } | 383 } |
| 384 SkDEBUGFAIL("shouldn't get here, face not in list"); | 384 SkDEBUGFAIL("shouldn't get here, face not in list"); |
| 385 } | 385 } |
| 386 | 386 |
| 387 class AutoFTAccess { | 387 class AutoFTAccess { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 | 655 |
| 656 // returns false if there is any non-90-rotation or skew | 656 // returns false if there is any non-90-rotation or skew |
| 657 static bool isAxisAligned(const SkScalerContext::Rec& rec) { | 657 static bool isAxisAligned(const SkScalerContext::Rec& rec) { |
| 658 return 0 == rec.fPreSkewX && | 658 return 0 == rec.fPreSkewX && |
| 659 (bothZero(rec.fPost2x2[0][1], rec.fPost2x2[1][0]) || | 659 (bothZero(rec.fPost2x2[0][1], rec.fPost2x2[1][0]) || |
| 660 bothZero(rec.fPost2x2[0][0], rec.fPost2x2[1][1])); | 660 bothZero(rec.fPost2x2[0][0], rec.fPost2x2[1][1])); |
| 661 } | 661 } |
| 662 | 662 |
| 663 SkScalerContext* SkTypeface_FreeType::onCreateScalerContext( | 663 SkScalerContext* SkTypeface_FreeType::onCreateScalerContext( |
| 664 const SkDescriptor* desc) const { | 664 const SkDescriptor* desc) const { |
| 665 SkScalerContext_FreeType* c = SkNEW_ARGS(SkScalerContext_FreeType, | 665 SkScalerContext_FreeType* c = |
| 666 (const_cast<SkTypeface_FreeType*>(this), | 666 new SkScalerContext_FreeType(const_cast<SkTypeface_FreeType*>(this),
desc); |
| 667 desc)); | |
| 668 if (!c->success()) { | 667 if (!c->success()) { |
| 669 SkDELETE(c); | 668 delete c; |
| 670 c = NULL; | 669 c = NULL; |
| 671 } | 670 } |
| 672 return c; | 671 return c; |
| 673 } | 672 } |
| 674 | 673 |
| 675 void SkTypeface_FreeType::onFilterRec(SkScalerContextRec* rec) const { | 674 void SkTypeface_FreeType::onFilterRec(SkScalerContextRec* rec) const { |
| 676 //BOGUS: http://code.google.com/p/chromium/issues/detail?id=121119 | 675 //BOGUS: http://code.google.com/p/chromium/issues/detail?id=121119 |
| 677 //Cap the requested size as larger sizes give bogus values. | 676 //Cap the requested size as larger sizes give bogus values. |
| 678 //Remove when http://code.google.com/p/skia/issues/detail?id=554 is fixed. | 677 //Remove when http://code.google.com/p/skia/issues/detail?id=554 is fixed. |
| 679 if (rec->fTextSize > SkIntToScalar(1 << 14)) { | 678 if (rec->fTextSize > SkIntToScalar(1 << 14)) { |
| (...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1732 (*axes)[i].fTag = ftAxis.tag; | 1731 (*axes)[i].fTag = ftAxis.tag; |
| 1733 (*axes)[i].fMinimum = ftAxis.minimum; | 1732 (*axes)[i].fMinimum = ftAxis.minimum; |
| 1734 (*axes)[i].fDefault = ftAxis.def; | 1733 (*axes)[i].fDefault = ftAxis.def; |
| 1735 (*axes)[i].fMaximum = ftAxis.maximum; | 1734 (*axes)[i].fMaximum = ftAxis.maximum; |
| 1736 } | 1735 } |
| 1737 } | 1736 } |
| 1738 | 1737 |
| 1739 FT_Done_Face(face); | 1738 FT_Done_Face(face); |
| 1740 return true; | 1739 return true; |
| 1741 } | 1740 } |
| OLD | NEW |