| 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" |
| 11 #include "SkFontMgr.h" | 11 #include "SkFontMgr.h" |
| 12 #include "SkLazyPtr.h" | 12 #include "SkLazyPtr.h" |
| 13 #include "SkMutex.h" | 13 #include "SkMutex.h" |
| 14 #include "SkOTTable_OS_2.h" | 14 #include "SkOTTable_OS_2.h" |
| 15 #include "SkStream.h" | 15 #include "SkStream.h" |
| 16 #include "SkTypeface.h" | 16 #include "SkTypeface.h" |
| 17 | 17 |
| 18 SkTypeface::SkTypeface(const SkFontStyle& style, SkFontID fontID, bool isFixedPi
tch) | 18 SkTypeface::SkTypeface(const SkFontStyle& style, SkFontID fontID, bool isFixedPi
tch) |
| 19 : fUniqueID(fontID), fStyle(style), fIsFixedPitch(isFixedPitch) { } | 19 : fUniqueID(fontID), fStyle(style), fIsFixedPitch(isFixedPitch) { } |
| 20 | 20 |
| 21 SkTypeface::~SkTypeface() { } | 21 SkTypeface::~SkTypeface() { } |
| 22 | 22 |
| 23 | 23 |
| 24 SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = NULL
; | 24 SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ) = NULL
; |
| 25 | 25 |
| 26 /////////////////////////////////////////////////////////////////////////////// | 26 /////////////////////////////////////////////////////////////////////////////// |
| 27 | 27 |
| 28 class SkEmptyTypeface : public SkTypeface { | 28 class SkEmptyTypeface : public SkTypeface { |
| 29 public: | 29 public: |
| 30 static SkEmptyTypeface* Create() { | 30 static SkEmptyTypeface* Create() { return new SkEmptyTypeface; } |
| 31 return SkNEW(SkEmptyTypeface); | |
| 32 } | |
| 33 protected: | 31 protected: |
| 34 SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { } | 32 SkEmptyTypeface() : SkTypeface(SkFontStyle(), 0, true) { } |
| 35 | 33 |
| 36 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return NULL; } | 34 SkStreamAsset* onOpenStream(int* ttcIndex) const override { return NULL; } |
| 37 SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override { | 35 SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override { |
| 38 return NULL; | 36 return NULL; |
| 39 } | 37 } |
| 40 void onFilterRec(SkScalerContextRec*) const override { } | 38 void onFilterRec(SkScalerContextRec*) const override { } |
| 41 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( | 39 virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( |
| 42 PerGlyphInfo, | 40 PerGlyphInfo, |
| 43 const uint32_t*, uint32_t) const override { retu
rn NULL; } | 41 const uint32_t*, uint32_t) const override { retu
rn NULL; } |
| 44 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { } | 42 void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { } |
| 45 virtual int onCharsToGlyphs(const void* chars, Encoding encoding, | 43 virtual int onCharsToGlyphs(const void* chars, Encoding encoding, |
| 46 uint16_t glyphs[], int glyphCount) const overrid
e { | 44 uint16_t glyphs[], int glyphCount) const overrid
e { |
| 47 if (glyphs && glyphCount > 0) { | 45 if (glyphs && glyphCount > 0) { |
| 48 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0])); | 46 sk_bzero(glyphs, glyphCount * sizeof(glyphs[0])); |
| 49 } | 47 } |
| 50 return 0; | 48 return 0; |
| 51 } | 49 } |
| 52 int onCountGlyphs() const override { return 0; }; | 50 int onCountGlyphs() const override { return 0; }; |
| 53 int onGetUPEM() const override { return 0; }; | 51 int onGetUPEM() const override { return 0; }; |
| 54 class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings { | 52 class EmptyLocalizedStrings : public SkTypeface::LocalizedStrings { |
| 55 public: | 53 public: |
| 56 bool next(SkTypeface::LocalizedString*) override { return false; } | 54 bool next(SkTypeface::LocalizedString*) override { return false; } |
| 57 }; | 55 }; |
| 58 void onGetFamilyName(SkString* familyName) const override { | 56 void onGetFamilyName(SkString* familyName) const override { |
| 59 familyName->reset(); | 57 familyName->reset(); |
| 60 } | 58 } |
| 61 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override { | 59 SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override { |
| 62 return SkNEW(EmptyLocalizedStrings); | 60 return new EmptyLocalizedStrings; |
| 63 }; | 61 }; |
| 64 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; } | 62 int onGetTableTags(SkFontTableTag tags[]) const override { return 0; } |
| 65 size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override
{ | 63 size_t onGetTableData(SkFontTableTag, size_t, size_t, void*) const override
{ |
| 66 return 0; | 64 return 0; |
| 67 } | 65 } |
| 68 }; | 66 }; |
| 69 | 67 |
| 70 namespace { | 68 namespace { |
| 71 | 69 |
| 72 SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex); | 70 SK_DECLARE_STATIC_MUTEX(gCreateDefaultMutex); |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 321 |
| 324 #include "SkDescriptor.h" | 322 #include "SkDescriptor.h" |
| 325 #include "SkPaint.h" | 323 #include "SkPaint.h" |
| 326 | 324 |
| 327 struct SkTypeface::BoundsComputer { | 325 struct SkTypeface::BoundsComputer { |
| 328 const SkTypeface& fTypeface; | 326 const SkTypeface& fTypeface; |
| 329 | 327 |
| 330 BoundsComputer(const SkTypeface& tf) : fTypeface(tf) {} | 328 BoundsComputer(const SkTypeface& tf) : fTypeface(tf) {} |
| 331 | 329 |
| 332 SkRect* operator()() const { | 330 SkRect* operator()() const { |
| 333 SkRect* rect = SkNEW(SkRect); | 331 SkRect* rect = new SkRect; |
| 334 if (!fTypeface.onComputeBounds(rect)) { | 332 if (!fTypeface.onComputeBounds(rect)) { |
| 335 rect->setEmpty(); | 333 rect->setEmpty(); |
| 336 } | 334 } |
| 337 return rect; | 335 return rect; |
| 338 } | 336 } |
| 339 }; | 337 }; |
| 340 | 338 |
| 341 SkRect SkTypeface::getBounds() const { | 339 SkRect SkTypeface::getBounds() const { |
| 342 return *fLazyBounds.get(BoundsComputer(*this)); | 340 return *fLazyBounds.get(BoundsComputer(*this)); |
| 343 } | 341 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 365 if (ctx.get()) { | 363 if (ctx.get()) { |
| 366 SkPaint::FontMetrics fm; | 364 SkPaint::FontMetrics fm; |
| 367 ctx->getFontMetrics(&fm); | 365 ctx->getFontMetrics(&fm); |
| 368 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, | 366 bounds->set(fm.fXMin * invTextSize, fm.fTop * invTextSize, |
| 369 fm.fXMax * invTextSize, fm.fBottom * invTextSize); | 367 fm.fXMax * invTextSize, fm.fBottom * invTextSize); |
| 370 return true; | 368 return true; |
| 371 } | 369 } |
| 372 return false; | 370 return false; |
| 373 } | 371 } |
| 374 | 372 |
| OLD | NEW |