Chromium Code Reviews| Index: src/fonts/SkRandomScalerContext.cpp |
| diff --git a/src/fonts/SkGScalerContext.cpp b/src/fonts/SkRandomScalerContext.cpp |
| similarity index 67% |
| copy from src/fonts/SkGScalerContext.cpp |
| copy to src/fonts/SkRandomScalerContext.cpp |
| index 5787478cecd24c298208a7099adda4368e978787..085f83fff37c5a145f9f5a8de32bdea8abceb4fd 100644 |
| --- a/src/fonts/SkGScalerContext.cpp |
| +++ b/src/fonts/SkRandomScalerContext.cpp |
| @@ -1,19 +1,19 @@ |
| /* |
| - * Copyright 2013 Google Inc. |
| + * Copyright 2015 Google Inc. |
| * |
| * Use of this source code is governed by a BSD-style license that can be |
| * found in the LICENSE file. |
| */ |
| -#include "SkGScalerContext.h" |
| +#include "SkRandomScalerContext.h" |
| #include "SkGlyph.h" |
| #include "SkPath.h" |
| #include "SkCanvas.h" |
| -class SkGScalerContext : public SkScalerContext { |
| +class SkRandomScalerContext : public SkScalerContext { |
| public: |
| - SkGScalerContext(SkGTypeface*, const SkDescriptor*); |
| - virtual ~SkGScalerContext(); |
| + SkRandomScalerContext(SkRandomTypeface*, const SkDescriptor*); |
| + virtual ~SkRandomScalerContext(); |
| protected: |
| unsigned generateGlyphCount() override; |
| @@ -25,7 +25,7 @@ protected: |
| void generateFontMetrics(SkPaint::FontMetrics*) override; |
| private: |
| - SkGTypeface* fFace; |
| + SkRandomTypeface* fFace; |
| SkScalerContext* fProxy; |
| SkMatrix fMatrix; |
| }; |
| @@ -34,11 +34,9 @@ private: |
| #include "SkDescriptor.h" |
| -SkGScalerContext::SkGScalerContext(SkGTypeface* face, const SkDescriptor* desc) |
| +SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face, const SkDescriptor* desc) |
| : SkScalerContext(face, desc) |
| - , fFace(face) |
| -{ |
| - |
| + , fFace(face) { |
| size_t descSize = SkDescriptor::ComputeOverhead(1) + sizeof(SkScalerContext::Rec); |
| SkAutoDescriptor ad(descSize); |
| SkDescriptor* newDesc = ad.getDesc(); |
| @@ -63,19 +61,19 @@ SkGScalerContext::SkGScalerContext(SkGTypeface* face, const SkDescriptor* desc) |
| fMatrix.preScale(SK_Scalar1 / STD_SIZE, SK_Scalar1 / STD_SIZE); |
| } |
| -SkGScalerContext::~SkGScalerContext() { |
| +SkRandomScalerContext::~SkRandomScalerContext() { |
| SkDELETE(fProxy); |
| } |
| -unsigned SkGScalerContext::generateGlyphCount() { |
| +unsigned SkRandomScalerContext::generateGlyphCount() { |
| return fProxy->getGlyphCount(); |
| } |
| -uint16_t SkGScalerContext::generateCharToGlyph(SkUnichar uni) { |
| +uint16_t SkRandomScalerContext::generateCharToGlyph(SkUnichar uni) { |
| return fProxy->charToGlyphID(uni); |
| } |
| -void SkGScalerContext::generateAdvance(SkGlyph* glyph) { |
| +void SkRandomScalerContext::generateAdvance(SkGlyph* glyph) { |
| fProxy->getAdvance(glyph); |
| SkVector advance; |
| @@ -85,7 +83,7 @@ void SkGScalerContext::generateAdvance(SkGlyph* glyph) { |
| glyph->fAdvanceY = SkScalarToFixed(advance.fY); |
| } |
| -void SkGScalerContext::generateMetrics(SkGlyph* glyph) { |
| +void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) { |
| fProxy->getMetrics(glyph); |
| SkVector advance; |
| @@ -109,10 +107,26 @@ void SkGScalerContext::generateMetrics(SkGlyph* glyph) { |
| glyph->fTop = ibounds.fTop; |
| glyph->fWidth = ibounds.width(); |
| glyph->fHeight = ibounds.height(); |
| - glyph->fMaskFormat = SkMask::kARGB32_Format; |
| + |
| + // Here we will change the mask format of the glyph |
| + // NOTE this is being overridden by the base class |
| + SkMask::Format format; |
| + switch (glyph->getGlyphID() % 3) { |
| + case 0: |
| + format = SkMask::kLCD16_Format; |
| + break; |
| + case 1: |
| + format = SkMask::kA8_Format; |
| + break; |
| + default: |
| + format = SkMask::kARGB32_Format; |
| + } |
| + |
| + glyph->fMaskFormat = format; |
| } |
| -void SkGScalerContext::generateImage(const SkGlyph& glyph) { |
| +void SkRandomScalerContext::generateImage(const SkGlyph& glyph) { |
| + SkMask::Format format = static_cast<SkMask::Format>(glyph.fMaskFormat); |
| if (SkMask::kARGB32_Format == glyph.fMaskFormat) { |
| SkPath path; |
| fProxy->getPath(glyph, &path); |
| @@ -130,14 +144,16 @@ void SkGScalerContext::generateImage(const SkGlyph& glyph) { |
| } else { |
| fProxy->getImage(glyph); |
| } |
| + |
| + SkASSERT(glyph.fMaskFormat == format); |
|
bungeman-skia
2015/07/24 18:43:53
Even with SkScalerContext not overriding things, t
|
| } |
| -void SkGScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) { |
| +void SkRandomScalerContext::generatePath(const SkGlyph& glyph, SkPath* path) { |
| fProxy->getPath(glyph, path); |
| path->transform(fMatrix); |
| } |
| -void SkGScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) { |
| +void SkRandomScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) { |
| fProxy->getFontMetrics(metrics); |
| if (metrics) { |
| SkScalar scale = fMatrix.getScaleY(); |
| @@ -157,110 +173,69 @@ void SkGScalerContext::generateFontMetrics(SkPaint::FontMetrics* metrics) { |
| #include "SkTypefaceCache.h" |
| -SkGTypeface::SkGTypeface(SkTypeface* proxy, const SkPaint& paint) |
| +SkRandomTypeface::SkRandomTypeface(SkTypeface* proxy, const SkPaint& paint) |
| : SkTypeface(proxy->fontStyle(), SkTypefaceCache::NewFontID(), false) |
| , fProxy(SkRef(proxy)) |
| , fPaint(paint) {} |
| -SkGTypeface::~SkGTypeface() { |
| +SkRandomTypeface::~SkRandomTypeface() { |
| fProxy->unref(); |
| } |
| -SkScalerContext* SkGTypeface::onCreateScalerContext( |
| +SkScalerContext* SkRandomTypeface::onCreateScalerContext( |
| const SkDescriptor* desc) const { |
| - return SkNEW_ARGS(SkGScalerContext, (const_cast<SkGTypeface*>(this), desc)); |
| + return SkNEW_ARGS(SkRandomScalerContext, (const_cast<SkRandomTypeface*>(this), desc)); |
| } |
| -void SkGTypeface::onFilterRec(SkScalerContextRec* rec) const { |
| +void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const { |
| fProxy->filterRec(rec); |
| rec->setHinting(SkPaint::kNo_Hinting); |
| rec->fMaskFormat = SkMask::kARGB32_Format; |
| } |
| -SkAdvancedTypefaceMetrics* SkGTypeface::onGetAdvancedTypefaceMetrics( |
| +SkAdvancedTypefaceMetrics* SkRandomTypeface::onGetAdvancedTypefaceMetrics( |
| PerGlyphInfo info, |
| const uint32_t* glyphIDs, |
| uint32_t glyphIDsCount) const { |
| return fProxy->getAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount); |
| } |
| -SkStreamAsset* SkGTypeface::onOpenStream(int* ttcIndex) const { |
| +SkStreamAsset* SkRandomTypeface::onOpenStream(int* ttcIndex) const { |
| return fProxy->openStream(ttcIndex); |
| } |
| -void SkGTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
| +void SkRandomTypeface::onGetFontDescriptor(SkFontDescriptor* desc, |
| bool* isLocal) const { |
| fProxy->getFontDescriptor(desc, isLocal); |
| } |
| -int SkGTypeface::onCharsToGlyphs(const void* chars, Encoding encoding, |
| +int SkRandomTypeface::onCharsToGlyphs(const void* chars, Encoding encoding, |
| uint16_t glyphs[], int glyphCount) const { |
| return fProxy->charsToGlyphs(chars, encoding, glyphs, glyphCount); |
| } |
| -int SkGTypeface::onCountGlyphs() const { |
| +int SkRandomTypeface::onCountGlyphs() const { |
| return fProxy->countGlyphs(); |
| } |
| -int SkGTypeface::onGetUPEM() const { |
| +int SkRandomTypeface::onGetUPEM() const { |
| return fProxy->getUnitsPerEm(); |
| } |
| -void SkGTypeface::onGetFamilyName(SkString* familyName) const { |
| +void SkRandomTypeface::onGetFamilyName(SkString* familyName) const { |
| fProxy->getFamilyName(familyName); |
| } |
| -SkTypeface::LocalizedStrings* SkGTypeface::onCreateFamilyNameIterator() const { |
| +SkTypeface::LocalizedStrings* SkRandomTypeface::onCreateFamilyNameIterator() const { |
| return fProxy->createFamilyNameIterator(); |
| } |
| -int SkGTypeface::onGetTableTags(SkFontTableTag tags[]) const { |
| +int SkRandomTypeface::onGetTableTags(SkFontTableTag tags[]) const { |
| return fProxy->getTableTags(tags); |
| } |
| -size_t SkGTypeface::onGetTableData(SkFontTableTag tag, size_t offset, |
| +size_t SkRandomTypeface::onGetTableData(SkFontTableTag tag, size_t offset, |
| size_t length, void* data) const { |
| return fProxy->getTableData(tag, offset, length, data); |
| } |
| -/////////////////////////////////////////////////////////////////////////////// |
| - |
| -#if 0 |
| -// under construction -- defining a font purely in terms of skia primitives |
| -// ala an SVG-font. |
| -class SkGFont : public SkRefCnt { |
| -public: |
| - virtual ~SkGFont(); |
| - |
| - int unicharToGlyph(SkUnichar) const; |
| - |
| - int countGlyphs() const { return fCount; } |
| - |
| - float getAdvance(int index) const { |
| - SkASSERT((unsigned)index < (unsigned)fCount); |
| - return fGlyphs[index].fAdvance; |
| - } |
| - |
| - const SkPath& getPath(int index) const { |
| - SkASSERT((unsigned)index < (unsigned)fCount); |
| - return fGlyphs[index].fPath; |
| - } |
| - |
| -private: |
| - struct Glyph { |
| - SkUnichar fUni; |
| - float fAdvance; |
| - SkPath fPath; |
| - }; |
| - int fCount; |
| - Glyph* fGlyphs; |
| - |
| - friend class SkGFontBuilder; |
| - SkGFont(int count, Glyph* array); |
| -}; |
| - |
| -class SkGFontBuilder { |
| -public: |
| - |
| -}; |
| -#endif |