Split SkGlyph into its own header.
https://codereview.appspot.com/6434049/
git-svn-id: http://skia.googlecode.com/svn/trunk@4741 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gyp/core.gyp b/gyp/core.gyp
index 7b54024..b4753b8 100644
--- a/gyp/core.gyp
+++ b/gyp/core.gyp
@@ -188,6 +188,7 @@
'../include/core/SkFloatingPoint.h',
'../include/core/SkFontHost.h',
'../include/core/SkGeometry.h',
+ '../include/core/SkGlyph.h',
'../include/core/SkGraphics.h',
'../include/core/SkInstCnt.h',
'../include/core/SkMallocPixelRef.h',
diff --git a/include/core/SkAutoKern.h b/include/core/SkAutoKern.h
index 7a5cdef..f6879a1 100644
--- a/include/core/SkAutoKern.h
+++ b/include/core/SkAutoKern.h
@@ -10,7 +10,7 @@
#ifndef SkAutoKern_DEFINED
#define SkAutoKern_DEFINED
-#include "SkScalerContext.h"
+#include "SkGlyph.h"
#define SkAutoKern_AdjustF(prev, next) (((next) - (prev) + 32) >> 6 << 16)
#define SkAutoKern_AdjustS(prev, next) SkIntToScalar(((next) - (prev) + 32) >> 6)
diff --git a/include/core/SkGlyph.h b/include/core/SkGlyph.h
new file mode 100644
index 0000000..649fa7d
--- /dev/null
+++ b/include/core/SkGlyph.h
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2006 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkGlyph_DEFINED
+#define SkGlyph_DEFINED
+
+#include "SkTypes.h"
+#include "SkFixed.h"
+#include "SkMask.h"
+
+class SkPath;
+
+// needs to be != to any valid SkMask::Format
+#define MASK_FORMAT_UNKNOWN (0xFF)
+#define MASK_FORMAT_JUST_ADVANCE MASK_FORMAT_UNKNOWN
+
+#define kMaxGlyphWidth (1<<13)
+
+struct SkGlyph {
+ void* fImage;
+ SkPath* fPath;
+ SkFixed fAdvanceX, fAdvanceY;
+
+ uint32_t fID;
+ uint16_t fWidth, fHeight;
+ int16_t fTop, fLeft;
+
+ uint8_t fMaskFormat;
+ int8_t fRsbDelta, fLsbDelta; // used by auto-kerning
+
+ void init(uint32_t id) {
+ fID = id;
+ fImage = NULL;
+ fPath = NULL;
+ fMaskFormat = MASK_FORMAT_UNKNOWN;
+ }
+
+ /**
+ * Compute the rowbytes for the specified width and mask-format.
+ */
+ static unsigned ComputeRowBytes(unsigned width, SkMask::Format format) {
+ unsigned rb = width;
+ if (SkMask::kBW_Format == format) {
+ rb = (rb + 7) >> 3;
+ } else if (SkMask::kARGB32_Format == format ||
+ SkMask::kLCD32_Format == format)
+ {
+ rb <<= 2;
+ } else if (SkMask::kLCD16_Format == format) {
+ rb = SkAlign4(rb << 1);
+ } else {
+ rb = SkAlign4(rb);
+ }
+ return rb;
+ }
+
+ unsigned rowBytes() const {
+ return ComputeRowBytes(fWidth, (SkMask::Format)fMaskFormat);
+ }
+
+ bool isJustAdvance() const {
+ return MASK_FORMAT_JUST_ADVANCE == fMaskFormat;
+ }
+
+ bool isFullMetrics() const {
+ return MASK_FORMAT_JUST_ADVANCE != fMaskFormat;
+ }
+
+ uint16_t getGlyphID() const {
+ return ID2Code(fID);
+ }
+
+ unsigned getGlyphID(unsigned baseGlyphCount) const {
+ unsigned code = ID2Code(fID);
+ SkASSERT(code >= baseGlyphCount);
+ return code - baseGlyphCount;
+ }
+
+ unsigned getSubX() const {
+ return ID2SubX(fID);
+ }
+
+ SkFixed getSubXFixed() const {
+ return SubToFixed(ID2SubX(fID));
+ }
+
+ SkFixed getSubYFixed() const {
+ return SubToFixed(ID2SubY(fID));
+ }
+
+ size_t computeImageSize() const;
+
+ /** Call this to set all of the metrics fields to 0 (e.g. if the scaler
+ encounters an error measuring a glyph). Note: this does not alter the
+ fImage, fPath, fID, fMaskFormat fields.
+ */
+ void zeroMetrics();
+
+ enum {
+ kSubBits = 2,
+ kSubMask = ((1 << kSubBits) - 1),
+ kSubShift = 24, // must be large enough for glyphs and unichars
+ kCodeMask = ((1 << kSubShift) - 1),
+ // relative offsets for X and Y subpixel bits
+ kSubShiftX = kSubBits,
+ kSubShiftY = 0
+ };
+
+ static unsigned ID2Code(uint32_t id) {
+ return id & kCodeMask;
+ }
+
+ static unsigned ID2SubX(uint32_t id) {
+ return id >> (kSubShift + kSubShiftX);
+ }
+
+ static unsigned ID2SubY(uint32_t id) {
+ return (id >> (kSubShift + kSubShiftY)) & kSubMask;
+ }
+
+ static unsigned FixedToSub(SkFixed n) {
+ return (n >> (16 - kSubBits)) & kSubMask;
+ }
+
+ static SkFixed SubToFixed(unsigned sub) {
+ SkASSERT(sub <= kSubMask);
+ return sub << (16 - kSubBits);
+ }
+
+ static uint32_t MakeID(unsigned code) {
+ return code;
+ }
+
+ static uint32_t MakeID(unsigned code, SkFixed x, SkFixed y) {
+ SkASSERT(code <= kCodeMask);
+ x = FixedToSub(x);
+ y = FixedToSub(y);
+ return (x << (kSubShift + kSubShiftX)) |
+ (y << (kSubShift + kSubShiftY)) |
+ code;
+ }
+
+ void toMask(SkMask* mask) const;
+};
+
+#endif
diff --git a/include/core/SkScalerContext.h b/include/core/SkScalerContext.h
index e59d103..ac11b9c 100644
--- a/include/core/SkScalerContext.h
+++ b/include/core/SkScalerContext.h
@@ -1,4 +1,3 @@
-
/*
* Copyright 2006 The Android Open Source Project
*
@@ -6,157 +5,21 @@
* found in the LICENSE file.
*/
-
#ifndef SkScalerContext_DEFINED
#define SkScalerContext_DEFINED
#include "SkMask.h"
#include "SkMatrix.h"
#include "SkPaint.h"
-#include "SkPath.h"
-#include "SkPoint.h"
-#include "SkTypeface.h"
//#define SK_USE_COLOR_LUMINANCE
+struct SkGlyph;
class SkDescriptor;
class SkMaskFilter;
class SkPathEffect;
class SkRasterizer;
-// needs to be != to any valid SkMask::Format
-#define MASK_FORMAT_UNKNOWN (0xFF)
-#define MASK_FORMAT_JUST_ADVANCE MASK_FORMAT_UNKNOWN
-
-#define kMaxGlyphWidth (1<<13)
-
-struct SkGlyph {
- void* fImage;
- SkPath* fPath;
- SkFixed fAdvanceX, fAdvanceY;
-
- uint32_t fID;
- uint16_t fWidth, fHeight;
- int16_t fTop, fLeft;
-
- uint8_t fMaskFormat;
- int8_t fRsbDelta, fLsbDelta; // used by auto-kerning
-
- void init(uint32_t id) {
- fID = id;
- fImage = NULL;
- fPath = NULL;
- fMaskFormat = MASK_FORMAT_UNKNOWN;
- }
-
- /**
- * Compute the rowbytes for the specified width and mask-format.
- */
- static unsigned ComputeRowBytes(unsigned width, SkMask::Format format) {
- unsigned rb = width;
- if (SkMask::kBW_Format == format) {
- rb = (rb + 7) >> 3;
- } else if (SkMask::kARGB32_Format == format ||
- SkMask::kLCD32_Format == format)
- {
- rb <<= 2;
- } else if (SkMask::kLCD16_Format == format) {
- rb = SkAlign4(rb << 1);
- } else {
- rb = SkAlign4(rb);
- }
- return rb;
- }
-
- unsigned rowBytes() const {
- return ComputeRowBytes(fWidth, (SkMask::Format)fMaskFormat);
- }
-
- bool isJustAdvance() const {
- return MASK_FORMAT_JUST_ADVANCE == fMaskFormat;
- }
-
- bool isFullMetrics() const {
- return MASK_FORMAT_JUST_ADVANCE != fMaskFormat;
- }
-
- uint16_t getGlyphID() const {
- return ID2Code(fID);
- }
-
- unsigned getGlyphID(unsigned baseGlyphCount) const {
- unsigned code = ID2Code(fID);
- SkASSERT(code >= baseGlyphCount);
- return code - baseGlyphCount;
- }
-
- unsigned getSubX() const {
- return ID2SubX(fID);
- }
-
- SkFixed getSubXFixed() const {
- return SubToFixed(ID2SubX(fID));
- }
-
- SkFixed getSubYFixed() const {
- return SubToFixed(ID2SubY(fID));
- }
-
- size_t computeImageSize() const;
-
- /** Call this to set all of the metrics fields to 0 (e.g. if the scaler
- encounters an error measuring a glyph). Note: this does not alter the
- fImage, fPath, fID, fMaskFormat fields.
- */
- void zeroMetrics();
-
- enum {
- kSubBits = 2,
- kSubMask = ((1 << kSubBits) - 1),
- kSubShift = 24, // must be large enough for glyphs and unichars
- kCodeMask = ((1 << kSubShift) - 1),
- // relative offsets for X and Y subpixel bits
- kSubShiftX = kSubBits,
- kSubShiftY = 0
- };
-
- static unsigned ID2Code(uint32_t id) {
- return id & kCodeMask;
- }
-
- static unsigned ID2SubX(uint32_t id) {
- return id >> (kSubShift + kSubShiftX);
- }
-
- static unsigned ID2SubY(uint32_t id) {
- return (id >> (kSubShift + kSubShiftY)) & kSubMask;
- }
-
- static unsigned FixedToSub(SkFixed n) {
- return (n >> (16 - kSubBits)) & kSubMask;
- }
-
- static SkFixed SubToFixed(unsigned sub) {
- SkASSERT(sub <= kSubMask);
- return sub << (16 - kSubBits);
- }
-
- static uint32_t MakeID(unsigned code) {
- return code;
- }
-
- static uint32_t MakeID(unsigned code, SkFixed x, SkFixed y) {
- SkASSERT(code <= kCodeMask);
- x = FixedToSub(x);
- y = FixedToSub(y);
- return (x << (kSubShift + kSubShiftX)) |
- (y << (kSubShift + kSubShiftY)) |
- code;
- }
-
- void toMask(SkMask* mask) const;
-};
-
class SkScalerContext {
public:
enum Flags {
diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h
index f393416..5992a6d 100644
--- a/src/core/SkGlyphCache.h
+++ b/src/core/SkGlyphCache.h
@@ -13,6 +13,7 @@
#include "SkBitmap.h"
#include "SkChunkAlloc.h"
#include "SkDescriptor.h"
+#include "SkGlyph.h"
#include "SkScalerContext.h"
#include "SkTemplates.h"
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index 2cce8ab..7c26921 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -12,6 +12,7 @@
#include "SkDescriptor.h"
#include "SkDraw.h"
#include "SkFontHost.h"
+#include "SkGlyph.h"
#include "SkMaskFilter.h"
#include "SkOrderedReadBuffer.h"
#include "SkPathEffect.h"
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index eed4dca..0d72fa1 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -14,6 +14,7 @@
#include "SkFDot6.h"
#include "SkFloatingPoint.h"
#include "SkFontHost.h"
+#include "SkGlyph.h"
#include "SkMask.h"
#include "SkAdvancedTypefaceMetrics.h"
#include "SkScalerContext.h"
diff --git a/src/ports/SkFontHost_mac_coretext.cpp b/src/ports/SkFontHost_mac_coretext.cpp
index bbbd448..ce5d907 100644
--- a/src/ports/SkFontHost_mac_coretext.cpp
+++ b/src/ports/SkFontHost_mac_coretext.cpp
@@ -23,6 +23,7 @@
#include "SkEndian.h"
#include "SkFontDescriptor.h"
#include "SkFloatingPoint.h"
+#include "SkGlyph.h"
#include "SkPaint.h"
#include "SkString.h"
#include "SkStream.h"
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index 5627f01..082e6e4 100755
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -12,6 +12,7 @@
#include "SkDescriptor.h"
#include "SkFontDescriptor.h"
#include "SkFontHost.h"
+#include "SkGlyph.h"
#include "SkOTUtils.h"
#include "SkStream.h"
#include "SkString.h"