Make SkAdvancedTypefaceMetrics private.
Review URL: https://codereview.chromium.org/1129283003
diff --git a/src/core/SkAdvancedTypefaceMetrics.h b/src/core/SkAdvancedTypefaceMetrics.h
new file mode 100644
index 0000000..34c5211
--- /dev/null
+++ b/src/core/SkAdvancedTypefaceMetrics.h
@@ -0,0 +1,152 @@
+
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#ifndef SkAdvancedTypefaceMetrics_DEFINED
+#define SkAdvancedTypefaceMetrics_DEFINED
+
+#include "SkRect.h"
+#include "SkRefCnt.h"
+#include "SkString.h"
+#include "SkTDArray.h"
+#include "SkTemplates.h"
+
+/** \class SkAdvancedTypefaceMetrics
+
+ The SkAdvancedTypefaceMetrics class is used by the PDF backend to correctly
+ embed typefaces. This class is created and filled in with information by
+ SkTypeface::getAdvancedTypefaceMetrics.
+*/
+
+class SkAdvancedTypefaceMetrics : public SkRefCnt {
+public:
+ SK_DECLARE_INST_COUNT(SkAdvancedTypefaceMetrics)
+
+ SkString fFontName;
+
+ enum FontType {
+ kType1_Font,
+ kType1CID_Font,
+ kCFF_Font,
+ kTrueType_Font,
+ kOther_Font,
+ };
+ // The type of the underlying font program. This field determines which
+ // of the following fields are valid. If it is kOther_Font the per glyph
+ // information will never be populated.
+ FontType fType;
+
+ enum FontFlags {
+ kEmpty_FontFlag = 0x0, //!<No flags set
+ kMultiMaster_FontFlag = 0x1, //!<May be true for Type1 or CFF fonts.
+ kNotEmbeddable_FontFlag = 0x2, //!<May not be embedded.
+ kNotSubsettable_FontFlag = 0x4, //!<May not be subset.
+ };
+ // Global font flags.
+ FontFlags fFlags;
+
+ uint16_t fLastGlyphID; // The last valid glyph ID in the font.
+ uint16_t fEmSize; // The size of the em box (defines font units).
+
+ // These enum values match the values used in the PDF file format.
+ enum StyleFlags {
+ kFixedPitch_Style = 0x00001,
+ kSerif_Style = 0x00002,
+ kScript_Style = 0x00008,
+ 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 {
+ enum MetricType {
+ kDefault, // Default advance: fAdvance.count = 1
+ kRange, // Advances for a range: fAdvance.count = fEndID-fStartID
+ kRun // fStartID-fEndID have same advance: fAdvance.count = 1
+ };
+ MetricType fType;
+ uint16_t fStartId;
+ uint16_t fEndId;
+ SkTDArray<Data> fAdvance;
+ SkAutoTDelete<AdvanceMetric<Data> > fNext;
+ };
+
+ struct VerticalMetric {
+ int16_t fVerticalAdvance;
+ int16_t fOriginXDisp; // Horiz. displacement of the secondary origin.
+ int16_t fOriginYDisp; // Vert. displacement of the secondary origin.
+ };
+ typedef AdvanceMetric<int16_t> WidthRange;
+ typedef AdvanceMetric<VerticalMetric> VerticalAdvanceRange;
+
+ // This is indexed by glyph id.
+ SkAutoTDelete<WidthRange> fGlyphWidths;
+ // Only used for Vertical CID fonts.
+ SkAutoTDelete<VerticalAdvanceRange> fVerticalMetrics;
+
+ // The names of each glyph, only populated for postscript fonts.
+ SkAutoTDelete<SkAutoTArray<SkString> > fGlyphNames;
+
+ // The mapping from glyph to Unicode, only populated if
+ // kToUnicode_PerGlyphInfo is passed to GetAdvancedTypefaceMetrics.
+ SkTDArray<SkUnichar> fGlyphToUnicode;
+
+private:
+ typedef SkRefCnt INHERITED;
+};
+
+namespace skia_advanced_typeface_metrics_utils {
+
+template <typename Data>
+void resetRange(SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range,
+ int startId);
+
+template <typename Data>
+SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* appendRange(
+ SkAutoTDelete<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot,
+ int startId);
+
+template <typename Data>
+void finishRange(
+ SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range,
+ int endId,
+ typename SkAdvancedTypefaceMetrics::AdvanceMetric<Data>::MetricType
+ type);
+
+/** Retrieve advance data for glyphs. Used by the PDF backend. It calls
+ underlying platform dependent API getAdvance to acquire the data.
+ @param num_glyphs Total number of glyphs in the given font.
+ @param glyphIDs For per-glyph info, specify subset of the font by
+ giving glyph ids. Each integer represents a glyph
+ id. Passing NULL means all glyphs in the font.
+ @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if
+ glyphIDs is NULL.
+*/
+template <typename Data, typename FontHandle>
+SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData(
+ FontHandle fontHandle,
+ int num_glyphs,
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount,
+ bool (*getAdvance)(FontHandle fontHandle, int gId, Data* data));
+
+} // namespace skia_advanced_typeface_metrics_utils
+
+#endif
diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp
index bbf3f44..0f5d70b 100644
--- a/src/core/SkTypeface.cpp
+++ b/src/core/SkTypeface.cpp
@@ -35,7 +35,7 @@
}
void onFilterRec(SkScalerContextRec*) const override { }
virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo,
+ PerGlyphInfo,
const uint32_t*, uint32_t) const override { return NULL; }
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override { }
virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
@@ -265,7 +265,7 @@
}
SkAdvancedTypefaceMetrics* SkTypeface::getAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo info,
+ PerGlyphInfo info,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const {
SkAdvancedTypefaceMetrics* result =
diff --git a/src/fonts/SkGScalerContext.cpp b/src/fonts/SkGScalerContext.cpp
index 17eee82..5787478 100644
--- a/src/fonts/SkGScalerContext.cpp
+++ b/src/fonts/SkGScalerContext.cpp
@@ -178,7 +178,7 @@
}
SkAdvancedTypefaceMetrics* SkGTypeface::onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo info,
+ PerGlyphInfo info,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const {
return fProxy->getAdvancedTypefaceMetrics(info, glyphIDs, glyphIDsCount);
diff --git a/src/fonts/SkGScalerContext.h b/src/fonts/SkGScalerContext.h
index e0f3262..75f3ebe 100644
--- a/src/fonts/SkGScalerContext.h
+++ b/src/fonts/SkGScalerContext.h
@@ -23,7 +23,7 @@
SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo,
+ PerGlyphInfo,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const override;
SkStreamAsset* onOpenStream(int* ttcIndex) const override;
diff --git a/src/fonts/SkTestScalerContext.cpp b/src/fonts/SkTestScalerContext.cpp
index 733e95f..8ff9f43 100644
--- a/src/fonts/SkTestScalerContext.cpp
+++ b/src/fonts/SkTestScalerContext.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkAdvancedTypefaceMetrics.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkDescriptor.h"
@@ -140,7 +141,7 @@
}
SkAdvancedTypefaceMetrics* SkTestTypeface::onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo ,
+ PerGlyphInfo ,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const {
// pdf only
diff --git a/src/fonts/SkTestScalerContext.h b/src/fonts/SkTestScalerContext.h
index 573a3df..1d4b89a 100644
--- a/src/fonts/SkTestScalerContext.h
+++ b/src/fonts/SkTestScalerContext.h
@@ -69,7 +69,7 @@
SkScalerContext* onCreateScalerContext(const SkDescriptor* desc) const override;
void onFilterRec(SkScalerContextRec* rec) const override;
SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo,
+ PerGlyphInfo,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const override;
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index 11cf012..c2dfa8e 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -829,13 +829,13 @@
return SkRef(relatedFont);
}
} else {
- SkAdvancedTypefaceMetrics::PerGlyphInfo info;
- info = SkAdvancedTypefaceMetrics::kGlyphNames_PerGlyphInfo;
- info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>(
- info, SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo);
+ SkTypeface::PerGlyphInfo info;
+ info = SkTypeface::kGlyphNames_PerGlyphInfo;
+ info = SkTBitOr<SkTypeface::PerGlyphInfo>(
+ info, SkTypeface::kToUnicode_PerGlyphInfo);
#if !defined (SK_SFNTLY_SUBSETTER)
- info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>(
- info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo);
+ info = SkTBitOr<SkTypeface::PerGlyphInfo>(
+ info, SkTypeface::kHAdvance_PerGlyphInfo);
#endif
fontMetrics.reset(
typeface->getAdvancedTypefaceMetrics(info, NULL, 0));
@@ -1127,10 +1127,10 @@
subset->exportTo(&glyphIDs);
}
- SkAdvancedTypefaceMetrics::PerGlyphInfo info;
- info = SkAdvancedTypefaceMetrics::kGlyphNames_PerGlyphInfo;
- info = SkTBitOr<SkAdvancedTypefaceMetrics::PerGlyphInfo>(
- info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo);
+ SkTypeface::PerGlyphInfo info;
+ info = SkTypeface::kGlyphNames_PerGlyphInfo;
+ info = SkTBitOr<SkTypeface::PerGlyphInfo>(
+ info, SkTypeface::kHAdvance_PerGlyphInfo);
uint32_t* glyphs = (glyphIDs.count() == 0) ? NULL : glyphIDs.begin();
uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0;
SkAutoTUnref<const SkAdvancedTypefaceMetrics> fontMetrics(
diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp
index 4b6738e..5c53b9d 100644
--- a/src/ports/SkFontHost_FreeType.cpp
+++ b/src/ports/SkFontHost_FreeType.cpp
@@ -460,7 +460,7 @@
}
SkAdvancedTypefaceMetrics* SkTypeface_FreeType::onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
+ PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const {
#if defined(SK_BUILD_FOR_MAC)
@@ -587,10 +587,10 @@
face->bbox.xMax, face->bbox.yMin);
if (!FT_IS_SCALABLE(face)) {
- perGlyphInfo = SkAdvancedTypefaceMetrics::kNo_PerGlyphInfo;
+ perGlyphInfo = kNo_PerGlyphInfo;
}
- if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) {
+ if (perGlyphInfo & kHAdvance_PerGlyphInfo) {
if (FT_IS_FIXED_WIDTH(face)) {
appendRange(&info->fGlyphWidths, 0);
int16_t advance = face->max_advance_width;
@@ -624,12 +624,12 @@
}
}
- if (perGlyphInfo & SkAdvancedTypefaceMetrics::kVAdvance_PerGlyphInfo &&
+ if (perGlyphInfo & kVAdvance_PerGlyphInfo &&
FT_HAS_VERTICAL(face)) {
SkASSERT(false); // Not implemented yet.
}
- if (perGlyphInfo & SkAdvancedTypefaceMetrics::kGlyphNames_PerGlyphInfo &&
+ if (perGlyphInfo & kGlyphNames_PerGlyphInfo &&
info->fType == SkAdvancedTypefaceMetrics::kType1_Font) {
// Postscript fonts may contain more than 255 glyphs, so we end up
// using multiple font descriptions with a glyph ordering. Record
@@ -643,7 +643,7 @@
}
}
- if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo &&
+ if (perGlyphInfo & kToUnicode_PerGlyphInfo &&
info->fType != SkAdvancedTypefaceMetrics::kType1_Font &&
face->num_charmaps) {
populate_glyph_to_unicode(face, &(info->fGlyphToUnicode));
diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h
index 36efba0..857d2c8 100644
--- a/src/ports/SkFontHost_FreeType_common.h
+++ b/src/ports/SkFontHost_FreeType_common.h
@@ -61,9 +61,8 @@
virtual SkScalerContext* onCreateScalerContext(
const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
- virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo,
- const uint32_t*, uint32_t) const override;
+ SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo, const uint32_t*, uint32_t) const override;
int onGetUPEM() const override;
virtual bool onGetKerningPairAdjustments(const uint16_t glyphs[], int count,
int32_t adjustments[]) const override;
diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp
index d97b09c..3c7be46 100755
--- a/src/ports/SkFontHost_mac.cpp
+++ b/src/ports/SkFontHost_mac.cpp
@@ -19,6 +19,7 @@
#include <CoreFoundation/CoreFoundation.h>
#endif
+#include "SkAdvancedTypefaceMetrics.h"
#include "SkCGUtils.h"
#include "SkColorPriv.h"
#include "SkDescriptor.h"
@@ -453,7 +454,7 @@
void onFilterRec(SkScalerContextRec*) const override;
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo,
+ PerGlyphInfo,
const uint32_t*, uint32_t) const override;
virtual int onCharsToGlyphs(const void* chars, Encoding, uint16_t glyphs[],
int glyphCount) const override;
@@ -1543,7 +1544,7 @@
}
SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
+ PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const {
@@ -1565,7 +1566,7 @@
info->fFlags = SkAdvancedTypefaceMetrics::kEmpty_FontFlag;
info->fStyle = 0;
- if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) {
+ if (perGlyphInfo & kToUnicode_PerGlyphInfo) {
populate_glyph_to_unicode(ctFont, glyphCount, &info->fGlyphToUnicode);
}
@@ -1632,7 +1633,7 @@
}
}
- if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) {
+ if (perGlyphInfo & kHAdvance_PerGlyphInfo) {
if (info->fStyle & SkAdvancedTypefaceMetrics::kFixedPitch_Style) {
skia_advanced_typeface_metrics_utils::appendRange(&info->fGlyphWidths, 0);
info->fGlyphWidths->fAdvance.append(1, &min_width);
diff --git a/src/ports/SkFontHost_win.cpp b/src/ports/SkFontHost_win.cpp
index bb5f8de..bcbbe11 100755
--- a/src/ports/SkFontHost_win.cpp
+++ b/src/ports/SkFontHost_win.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2006 The Android Open Source Project
*
@@ -257,9 +256,8 @@
SkStreamAsset* onOpenStream(int* ttcIndex) const override;
SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
- virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo,
- const uint32_t*, uint32_t) const override;
+ SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo, const uint32_t*, uint32_t) const override;
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
uint16_t glyphs[], int glyphCount) const override;
@@ -1733,7 +1731,7 @@
}
SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
+ PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const {
LOGFONT lf = fLogFont;
@@ -1782,7 +1780,7 @@
SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag);
}
- if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) {
+ if (perGlyphInfo & kToUnicode_PerGlyphInfo) {
populate_glyph_to_unicode(hdc, glyphCount, &(info->fGlyphToUnicode));
}
@@ -1841,7 +1839,7 @@
}
}
- if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) {
+ if (perGlyphInfo & kHAdvance_PerGlyphInfo) {
if (info->fStyle & SkAdvancedTypefaceMetrics::kFixedPitch_Style) {
appendRange(&info->fGlyphWidths, 0);
info->fGlyphWidths->fAdvance.append(1, &min_width);
diff --git a/src/ports/SkTypeface_win_dw.cpp b/src/ports/SkTypeface_win_dw.cpp
index f445578..cf45c16 100644
--- a/src/ports/SkTypeface_win_dw.cpp
+++ b/src/ports/SkTypeface_win_dw.cpp
@@ -322,7 +322,7 @@
}
SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo,
+ PerGlyphInfo perGlyphInfo,
const uint32_t* glyphIDs,
uint32_t glyphIDsCount) const {
@@ -355,7 +355,7 @@
hr = sk_wchar_to_skstring(familyName.get(), familyNameLen, &info->fFontName);
- if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) {
+ if (perGlyphInfo & kToUnicode_PerGlyphInfo) {
populate_glyph_to_unicode(fDWriteFontFace.get(), glyphCount, &(info->fGlyphToUnicode));
}
@@ -442,7 +442,7 @@
}
*/
- if (perGlyphInfo & SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo) {
+ if (perGlyphInfo & kHAdvance_PerGlyphInfo) {
if (fixedWidth) {
appendRange(&info->fGlyphWidths, 0);
int16_t advance;
diff --git a/src/ports/SkTypeface_win_dw.h b/src/ports/SkTypeface_win_dw.h
index 9921aed..71d928b 100644
--- a/src/ports/SkTypeface_win_dw.h
+++ b/src/ports/SkTypeface_win_dw.h
@@ -99,9 +99,8 @@
SkStreamAsset* onOpenStream(int* ttcIndex) const override;
SkScalerContext* onCreateScalerContext(const SkDescriptor*) const override;
void onFilterRec(SkScalerContextRec*) const override;
- virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
- SkAdvancedTypefaceMetrics::PerGlyphInfo,
- const uint32_t*, uint32_t) const override;
+ SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics(
+ PerGlyphInfo, const uint32_t*, uint32_t) const override;
void onGetFontDescriptor(SkFontDescriptor*, bool*) const override;
virtual int onCharsToGlyphs(const void* chars, Encoding encoding,
uint16_t glyphs[], int glyphCount) const override;