aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
authorGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-02 02:11:22 +0000
committerGravatar vandebo@chromium.org <vandebo@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-02 02:11:22 +0000
commitc48b2b330f8bf0e01381e27ca36f48ef5c7d8d5f (patch)
tree5eee4cfe896ef6fe78ef48de073e600139538bce /include/core
parent0748f217ba21f764401757886cda3bdb395a360d (diff)
Cleanup SkPDFTypfaceInfo and make it more generic.
Renamed to SkAdvancedTypefaceMetrics. Include Em size and return all metrics in unscaled font units. Make retrieval of advances optional. Reorder SkAdvancedTypefaceMetrics to be somewhat logical. Change the types of fields in SkAdvancedTypefaceMetrics to their minimum required size. Review URL: http://codereview.appspot.com/4121049 git-svn-id: http://skia.googlecode.com/svn/trunk@752 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkAdvancedTypefaceMetrics.h (renamed from include/core/SkPDFTypefaceInfo.h)91
-rw-r--r--include/core/SkFontHost.h11
-rw-r--r--include/core/SkTypeface.h11
3 files changed, 55 insertions, 58 deletions
diff --git a/include/core/SkPDFTypefaceInfo.h b/include/core/SkAdvancedTypefaceMetrics.h
index 00338c4dc8..0c718d4f32 100644
--- a/include/core/SkPDFTypefaceInfo.h
+++ b/include/core/SkAdvancedTypefaceMetrics.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef SkPDFTypefaceInfo_DEFINED
-#define SkPDFTypefaceInfo_DEFINED
+#ifndef SkAdvancedTypefaceMetrics_DEFINED
+#define SkAdvancedTypefaceMetrics_DEFINED
#include "SkRect.h"
#include "SkRefCnt.h"
@@ -24,15 +24,17 @@
#include "SkTemplates.h"
#include "SkTScopedPtr.h"
-/** \class SkPDFTypefaceInfo
+/** \class SkAdvancedTypefaceMetrics
- The SkPDFTypefaceInfo is used by the PDF backend to correctly embed
- typefaces. This class is filled in with information about a given typeface
- by the SkFontHost class.
+ The SkAdvancedTypefaceMetrics class is used by the PDF backend to correctly
+ embed typefaces. This class is filled in with information about a given
+ typeface by the SkFontHost class.
*/
-class SkPDFTypefaceInfo : public SkRefCnt {
+class SkAdvancedTypefaceMetrics : public SkRefCnt {
public:
+ SkString fFontName;
+
enum FontType {
kType1_Font,
kType1CID_Font,
@@ -43,16 +45,36 @@ public:
};
// The type of the underlying font program. This field determines which
// of the following fields are valid. If it is kOther_Font or
- // kNotEmbeddable_Font, fFontName may be valid, but no other fields are
- // valid.
+ // kNotEmbeddable_Font, the per glyph information will never be populated.
FontType fType;
// fMultiMaster may be true for Type1_Font or CFF_Font.
bool fMultiMaster;
- SkString fFontName;
- SkIRect fBBox; // The bounding box of all glyphs (in font units).
+ uint16_t fLastGlyphID; // The last valid glyph ID in the font.
+ uint16_t fEmSize; // The size of the em box (defines font units).
- uint16_t fLastGlyphID;
+ // These enum values match the values used in the PDF file format.
+ enum StyleFlags {
+ kFixedPitch_Style = 0x00001,
+ kSerif_Style = 0x00002,
+ kSymbolic_Style = 0x00004,
+ kScript_Style = 0x00008,
+ kNonsymbolic_Style = 0x00020,
+ kItalic_Style = 0x00040,
+ kAllCaps_Style = 0x10000,
+ kSmallCaps_Style = 0x20000,
+ kForceBold_Style = 0x40000,
+ };
+ uint16_t fStyle; // Font style characteristics.
+ int16_t fItalicAngle; // Counterclockwise degrees from vertical of the
+ // dominant vertical stroke for an Italic face.
+ // The following fields are all in font units.
+ int16_t fAscent; // Max height above baseline, not including accents.
+ int16_t fDescent; // Max depth below baseline (negative).
+ int16_t fStemV; // Thickness of dominant vertical stem.
+ int16_t fCapHeight; // Height (from baseline) of top of flat capitals.
+
+ SkIRect fBBox; // The bounding box of all glyphs (in font units).
template <typename Data>
struct AdvanceMetric {
@@ -62,18 +84,18 @@ public:
kRun, // fStartID-fEndID have same advance: fAdvance.count = 1
};
MetricType fType;
- int fStartId;
- int fEndId;
+ uint16_t fStartId;
+ uint16_t fEndId;
SkTDArray<Data> fAdvance;
SkTScopedPtr<AdvanceMetric<Data> > fNext;
};
struct VerticalMetric {
- int fVerticalAdvance;
- int fOriginXDisp; // Horizontal displacement of the secondary origin.
- int fOriginYDisp; // Vertical displacement of the secondary origin.
+ int16_t fVerticalAdvance;
+ int16_t fOriginXDisp; // Horiz. displacement of the secondary origin.
+ int16_t fOriginYDisp; // Vert. displacement of the secondary origin.
};
- typedef AdvanceMetric<int> WidthRange;
+ typedef AdvanceMetric<int16_t> WidthRange;
typedef AdvanceMetric<VerticalMetric> VerticalAdvanceRange;
// This is indexed by glyph id.
@@ -83,39 +105,6 @@ public:
// The names of each glyph, only populated for postscript fonts.
SkTScopedPtr<SkAutoTArray<SkString> > fGlyphNames;
-
- // Metrics: probably used by the pdf renderer for substitution, which
- // shouldn't be needed with embedding fonts. Optional fields with a value
- // of 0 will be ignored.
-
- // The enum values match the values used in the PDF file format.
- enum StyleFlags {
- kFixedPitch_Style = 0x00001,
- kSerif_Style = 0x00002,
- kSymbolic_Style = 0x00004,
- kScript_Style = 0x00008,
- kNonsymbolic_Style = 0x00020,
- kItalic_Style = 0x00040,
- kAllCaps_Style = 0x10000,
- kSmallCaps_Style = 0x20000,
- kForceBold_Style = 0x40000,
- };
- uint16_t fStyle; // Font style characteristics.
- long fItalicAngle; // Counterclockwise degrees from vertical of the
- // dominant vertical stroke for an Italic face.
- SkScalar fAscent; // Max height above baseline, not including accents.
- SkScalar fDescent; // Max depth below baseline (negative).
- SkScalar fStemV; // Thickness of dominant vertical stem.
- SkScalar fCapHeight; // Height (from baseline) of top of flat capitals.
-
- /* Omit the optional entries. Better to let the viewer compute them, since
- * it has to be able to anyway.
- SkScalar fLeading; // Space between lines. Optional.
- SkScalar fXHeight; // Height of top of 'x'. Optional.
- SkScalar fStemH; // Thickness of dominant horizontal stem. Optional.
- SkScalar fAvgWidth; // Average width of glyphs. Optional.
- SkScalar fMaxWidth; // Max width of a glyph. Optional.
- */
};
#endif
diff --git a/include/core/SkFontHost.h b/include/core/SkFontHost.h
index 4363ecd1d0..e669f2c2a7 100644
--- a/include/core/SkFontHost.h
+++ b/include/core/SkFontHost.h
@@ -176,10 +176,15 @@ public:
///////////////////////////////////////////////////////////////////////////
- /** Retrieve information about the typeface needed for inclusion in a
- PDF output device. Returns NULL if it is unable to find the font.
+ /** Retrieve detailed typeface metrics. Used by the PDF backend.
+ @param perGlyphInfo Indicate if the glyph specific information.
+ @param perGlyphInfo Indicate if the glyph specific information (advances
+ and names) should be populated.
+ @return The returned object has already been referenced. NULL is
+ returned if the font is not found.
*/
- static SkPDFTypefaceInfo* GetPDFTypefaceInfo(SkFontID);
+ static SkAdvancedTypefaceMetrics* GetAdvancedTypefaceMetrics(
+ SkFontID fontID, bool perGlyphInfo);
/** Return the number of tables in the font
*/
diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h
index b7ccf512e1..cea6ab1df9 100644
--- a/include/core/SkTypeface.h
+++ b/include/core/SkTypeface.h
@@ -20,7 +20,7 @@
#include "SkRefCnt.h"
class SkStream;
-class SkPDFTypefaceInfo;
+class SkAdvancedTypefaceMetrics;
class SkWStream;
/** \class SkTypeface
@@ -131,10 +131,13 @@ public:
*/
static SkTypeface* Deserialize(SkStream*);
- /** Retrieve information about the typeface needed for inclusion in a
- PDF output device.
+ /** Retrieve detailed typeface metrics. Used by the PDF backend.
+ @param perGlyphInfo Indicate if the glyph specific information (advances
+ and names) should be populated.
+ @return The returned object has already been referenced.
*/
- SkPDFTypefaceInfo* getPDFTypefaceInfo() const;
+ SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics(
+ bool perGlyphInfo) const;
protected:
/** uniqueID must be unique (please!) and non-zero