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

Unified Diff: src/fonts/SkRandomScalerContext.cpp

Issue 1260473004: Adding debug SkScalerContext which returns random mask formats (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more twiddling Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/fonts/SkRandomScalerContext.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/fonts/SkRandomScalerContext.cpp
diff --git a/src/fonts/SkGScalerContext.cpp b/src/fonts/SkRandomScalerContext.cpp
similarity index 63%
copy from src/fonts/SkGScalerContext.cpp
copy to src/fonts/SkRandomScalerContext.cpp
index 5787478cecd24c298208a7099adda4368e978787..2bfa289937fadc070072c1f09b1565f850925baf 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,8 +83,8 @@ void SkGScalerContext::generateAdvance(SkGlyph* glyph) {
glyph->fAdvanceY = SkScalarToFixed(advance.fY);
}
-void SkGScalerContext::generateMetrics(SkGlyph* glyph) {
- fProxy->getMetrics(glyph);
+void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
+ fProxy->getAdvance(glyph);
SkVector advance;
fMatrix.mapXY(SkFixedToScalar(glyph->fAdvanceX),
@@ -109,10 +107,49 @@ 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() % 6) {
+ case 0:
+ format = SkMask::kLCD16_Format;
+ break;
+ case 1:
+ format = SkMask::kA8_Format;
+ break;
+ case 2:
+ format = SkMask::kARGB32_Format;
+ break;
+ default:
+ // we will fiddle with these in generate image
+ format = (SkMask::Format)MASK_FORMAT_UNKNOWN;
+ }
+
+ glyph->fMaskFormat = format;
}
-void SkGScalerContext::generateImage(const SkGlyph& glyph) {
+void SkRandomScalerContext::generateImage(const SkGlyph& glyph) {
+ SkMask::Format format = (SkMask::Format)glyph.fMaskFormat;
+ switch (glyph.getGlyphID() % 6) {
+ case 0:
+ case 1:
+ case 2:
+ break;
+ case 3:
+ format = SkMask::kLCD16_Format;
+ break;
+ case 4:
+ format = SkMask::kA8_Format;
+ break;
+ case 5:
+ format = SkMask::kARGB32_Format;
+ break;
+ }
+ const_cast<SkGlyph&>(glyph).fMaskFormat = format;
+
+ // if the format is ARGB, we just draw the glyph from path ourselves. Otherwise, we force
+ // our proxy context to generate the image from paths.
if (SkMask::kARGB32_Format == glyph.fMaskFormat) {
SkPath path;
fProxy->getPath(glyph, &path);
@@ -128,16 +165,18 @@ void SkGScalerContext::generateImage(const SkGlyph& glyph) {
canvas.concat(fMatrix);
canvas.drawPath(path, fFace->paint());
} else {
+ this->forceGenerateImageFromPath();
fProxy->getImage(glyph);
+ this->forceOffGenerateImageFromPath();
}
}
-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 +196,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
« no previous file with comments | « src/fonts/SkRandomScalerContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698