From cb4f77d89da1d2b7ae5fd63ef7c9e6f7908ceb97 Mon Sep 17 00:00:00 2001 From: "bungeman@google.com" Date: Wed, 27 Nov 2013 20:53:45 +0000 Subject: Document the SkScalerContext pure virtuals. R=reed@google.com Review URL: https://codereview.chromium.org/92623002 git-svn-id: http://skia.googlecode.com/svn/trunk@12423 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkScalerContext.cpp | 18 +++++++------- src/core/SkScalerContext.h | 57 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp index d4f23ae3d2..4996a73f8d 100644 --- a/src/core/SkScalerContext.cpp +++ b/src/core/SkScalerContext.cpp @@ -352,16 +352,16 @@ void SkScalerContext::getMetrics(SkGlyph* glyph) { glyph->fHeight = SkToU16(ir.height()); if (glyph->fWidth > 0) { - switch (fRec.fMaskFormat) { - case SkMask::kLCD16_Format: - case SkMask::kLCD32_Format: - glyph->fWidth += 2; - glyph->fLeft -= 1; - break; - default: - break; + switch (fRec.fMaskFormat) { + case SkMask::kLCD16_Format: + case SkMask::kLCD32_Format: + glyph->fWidth += 2; + glyph->fLeft -= 1; + break; + default: + break; + } } - } } } diff --git a/src/core/SkScalerContext.h b/src/core/SkScalerContext.h index 2820b5ac2d..e4950edee3 100644 --- a/src/core/SkScalerContext.h +++ b/src/core/SkScalerContext.h @@ -202,16 +202,57 @@ protected: Rec fRec; unsigned fBaseGlyphCount; - virtual unsigned generateGlyphCount() = 0; - virtual uint16_t generateCharToGlyph(SkUnichar) = 0; - virtual void generateAdvance(SkGlyph*) = 0; - virtual void generateMetrics(SkGlyph*) = 0; - virtual void generateImage(const SkGlyph&) = 0; - virtual void generatePath(const SkGlyph&, SkPath*) = 0; + /** Generates the contents of glyph.fAdvanceX and glyph.fAdvanceY. + * May call getMetrics if that would be just as fast. + */ + virtual void generateAdvance(SkGlyph* glyph) = 0; + + /** Generates the contents of glyph.fWidth, fHeight, fTop, fLeft, + * as well as fAdvanceX and fAdvanceY if not already set. + * + * TODO: fMaskFormat is set by getMetrics later; cannot be set here. + */ + virtual void generateMetrics(SkGlyph* glyph) = 0; + + /** Generates the contents of glyph.fImage. + * When called, glyph.fImage will be pointing to a pre-allocated, + * uninitialized region of memory of size glyph.computeImageSize(). + * This method may change glyph.fMaskFormat if the new image size is + * less than or equal to the old image size. + * + * Because glyph.computeImageSize() will determine the size of fImage, + * generateMetrics will be called before generateImage. + */ + virtual void generateImage(const SkGlyph& glyph) = 0; + + /** Sets the passed path to the glyph outline. + * If this cannot be done the path is set to empty; + * this is indistinguishable from a glyph with an empty path. + * This does not set glyph.fPath. + * + * TODO: path is always glyph.fPath, no reason to pass separately. + */ + virtual void generatePath(const SkGlyph& glyph, SkPath* path) = 0; + + /** Retrieves font metrics. + * TODO: there is now a vertical bit, no need for two parameters. + */ virtual void generateFontMetrics(SkPaint::FontMetrics* mX, SkPaint::FontMetrics* mY) = 0; - // default impl returns 0, indicating failure. - virtual SkUnichar generateGlyphToChar(uint16_t); + + /** Returns the number of glyphs in the font. */ + virtual unsigned generateGlyphCount() = 0; + + /** Returns the glyph id for the given unichar. + * If there is no 1:1 mapping from the unichar to a glyph id, returns 0. + */ + virtual uint16_t generateCharToGlyph(SkUnichar unichar) = 0; + + /** Returns the unichar for the given glyph id. + * If there is no 1:1 mapping from the glyph id to a unichar, returns 0. + * The default implementation always returns 0, indicating failure. + */ + virtual SkUnichar generateGlyphToChar(uint16_t glyphId); void forceGenerateImageFromPath() { fGenerateImageFromPath = true; } -- cgit v1.2.3