To allow forward declarations, move SkScalerContext::Rec to SkScalerContextRec

Review URL: https://codereview.appspot.com/6462059

git-svn-id: http://skia.googlecode.com/svn/trunk@5090 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2012-08-14 19:13:55 +00:00
parent b5e4703b86
commit a9d4e84c43
3 changed files with 103 additions and 87 deletions

View File

@ -10,10 +10,11 @@
#ifndef SkFontHost_DEFINED #ifndef SkFontHost_DEFINED
#define SkFontHost_DEFINED #define SkFontHost_DEFINED
#include "SkScalerContext.h"
#include "SkTypeface.h" #include "SkTypeface.h"
class SkDescriptor; class SkDescriptor;
class SkScalerContext;
struct SkScalerContextRec;
class SkStream; class SkStream;
class SkWStream; class SkWStream;
@ -167,7 +168,7 @@ public:
A lazy (but valid) fonthost can do nothing in its FilterRec routine. A lazy (but valid) fonthost can do nothing in its FilterRec routine.
*/ */
static void FilterRec(SkScalerContext::Rec* rec); static void FilterRec(SkScalerContextRec* rec);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////

View File

@ -24,44 +24,11 @@ class SkMaskFilter;
class SkPathEffect; class SkPathEffect;
class SkRasterizer; class SkRasterizer;
//The following typedef hides from the rest of the implementation the number of /*
//most significant bits to consider when creating mask gamma tables. Two bits * To allow this to be forward-declared, it must be its own typename, rather
//per channel was chosen as a balance between fidelity (more bits) and cache * than a nested struct inside SkScalerContext (where it started).
//sizes (fewer bits). */
typedef SkTMaskGamma<2, 2, 2> SkMaskGamma; struct SkScalerContextRec {
class SkScalerContext {
public:
enum Flags {
kFrameAndFill_Flag = 0x0001,
kDevKernText_Flag = 0x0002,
kEmbeddedBitmapText_Flag = 0x0004,
kEmbolden_Flag = 0x0008,
kSubpixelPositioning_Flag = 0x0010,
kAutohinting_Flag = 0x0020,
kVertical_Flag = 0x0040,
// together, these two flags resulting in a two bit value which matches
// up with the SkPaint::Hinting enum.
kHinting_Shift = 7, // to shift into the other flags above
kHintingBit1_Flag = 0x0080,
kHintingBit2_Flag = 0x0100,
// these should only ever be set if fMaskFormat is LCD16 or LCD32
kLCD_Vertical_Flag = 0x0200, // else Horizontal
kLCD_BGROrder_Flag = 0x0400, // else RGB order
// Generate A8 from LCD source (for GDI), only meaningful if fMaskFormat is kA8
// Perhaps we can store this (instead) in fMaskFormat, in hight bit?
kGenA8FromLCD_Flag = 0x0800,
};
// computed values
enum {
kHinting_Mask = kHintingBit1_Flag | kHintingBit2_Flag,
};
struct Rec {
uint32_t fOrigFontID; uint32_t fOrigFontID;
uint32_t fFontID; uint32_t fFontID;
SkScalar fTextSize, fPreScaleX, fPreSkewX; SkScalar fTextSize, fPreScaleX, fPreSkewX;
@ -122,14 +89,8 @@ public:
void getLocalMatrix(SkMatrix*) const; void getLocalMatrix(SkMatrix*) const;
void getSingleMatrix(SkMatrix*) const; void getSingleMatrix(SkMatrix*) const;
SkPaint::Hinting getHinting() const { inline SkPaint::Hinting getHinting() const;
unsigned hint = (fFlags & kHinting_Mask) >> kHinting_Shift; inline void setHinting(SkPaint::Hinting);
return static_cast<SkPaint::Hinting>(hint);
}
void setHinting(SkPaint::Hinting hinting) {
fFlags = (fFlags & ~kHinting_Mask) | (hinting << kHinting_Shift);
}
SkMask::Format getFormat() const { SkMask::Format getFormat() const {
return static_cast<SkMask::Format>(fMaskFormat); return static_cast<SkMask::Format>(fMaskFormat);
@ -142,8 +103,48 @@ public:
void setLuminanceColor(SkColor c) { void setLuminanceColor(SkColor c) {
fLumBits = c; fLumBits = c;
} }
};
//The following typedef hides from the rest of the implementation the number of
//most significant bits to consider when creating mask gamma tables. Two bits
//per channel was chosen as a balance between fidelity (more bits) and cache
//sizes (fewer bits).
typedef SkTMaskGamma<2, 2, 2> SkMaskGamma;
class SkScalerContext {
public:
typedef SkScalerContextRec Rec;
enum Flags {
kFrameAndFill_Flag = 0x0001,
kDevKernText_Flag = 0x0002,
kEmbeddedBitmapText_Flag = 0x0004,
kEmbolden_Flag = 0x0008,
kSubpixelPositioning_Flag = 0x0010,
kAutohinting_Flag = 0x0020,
kVertical_Flag = 0x0040,
// together, these two flags resulting in a two bit value which matches
// up with the SkPaint::Hinting enum.
kHinting_Shift = 7, // to shift into the other flags above
kHintingBit1_Flag = 0x0080,
kHintingBit2_Flag = 0x0100,
// these should only ever be set if fMaskFormat is LCD16 or LCD32
kLCD_Vertical_Flag = 0x0200, // else Horizontal
kLCD_BGROrder_Flag = 0x0400, // else RGB order
// Generate A8 from LCD source (for GDI), only meaningful if fMaskFormat is kA8
// Perhaps we can store this (instead) in fMaskFormat, in hight bit?
kGenA8FromLCD_Flag = 0x0800,
}; };
// computed values
enum {
kHinting_Mask = kHintingBit1_Flag | kHintingBit2_Flag,
};
SkScalerContext(const SkDescriptor* desc); SkScalerContext(const SkDescriptor* desc);
virtual ~SkScalerContext(); virtual ~SkScalerContext();
@ -267,5 +268,19 @@ enum SkAxisAlignment {
*/ */
SkAxisAlignment SkComputeAxisAlignmentForHText(const SkMatrix& matrix); SkAxisAlignment SkComputeAxisAlignmentForHText(const SkMatrix& matrix);
///////////////////////////////////////////////////////////////////////////////
SkPaint::Hinting SkScalerContextRec::getHinting() const {
unsigned hint = (fFlags & SkScalerContext::kHinting_Mask) >>
SkScalerContext::kHinting_Shift;
return static_cast<SkPaint::Hinting>(hint);
}
void SkScalerContextRec::setHinting(SkPaint::Hinting hinting) {
fFlags = (fFlags & ~SkScalerContext::kHinting_Mask) |
(hinting << SkScalerContext::kHinting_Shift);
}
#endif #endif

View File

@ -691,7 +691,7 @@ void SkScalerContext::internalGetPath(const SkGlyph& glyph, SkPath* fillPath,
} }
void SkScalerContext::Rec::getMatrixFrom2x2(SkMatrix* dst) const { void SkScalerContextRec::getMatrixFrom2x2(SkMatrix* dst) const {
dst->reset(); dst->reset();
dst->setScaleX(fPost2x2[0][0]); dst->setScaleX(fPost2x2[0][0]);
dst->setSkewX( fPost2x2[0][1]); dst->setSkewX( fPost2x2[0][1]);
@ -699,14 +699,14 @@ void SkScalerContext::Rec::getMatrixFrom2x2(SkMatrix* dst) const {
dst->setScaleY(fPost2x2[1][1]); dst->setScaleY(fPost2x2[1][1]);
} }
void SkScalerContext::Rec::getLocalMatrix(SkMatrix* m) const { void SkScalerContextRec::getLocalMatrix(SkMatrix* m) const {
m->setScale(SkScalarMul(fTextSize, fPreScaleX), fTextSize); m->setScale(SkScalarMul(fTextSize, fPreScaleX), fTextSize);
if (fPreSkewX) { if (fPreSkewX) {
m->postSkew(fPreSkewX, 0); m->postSkew(fPreSkewX, 0);
} }
} }
void SkScalerContext::Rec::getSingleMatrix(SkMatrix* m) const { void SkScalerContextRec::getSingleMatrix(SkMatrix* m) const {
this->getLocalMatrix(m); this->getLocalMatrix(m);
// now concat the device matrix // now concat the device matrix