diff --git a/gyp/core.gypi b/gyp/core.gypi index b6a929fc9d..f6a2ce2ca7 100644 --- a/gyp/core.gypi +++ b/gyp/core.gypi @@ -18,6 +18,7 @@ '<(skia_src_path)/core/SkAAClip.cpp', '<(skia_src_path)/core/SkAnnotation.cpp', '<(skia_src_path)/core/SkAdvancedTypefaceMetrics.cpp', + '<(skia_src_path)/core/SkAdvancedTypefaceMetrics.h', '<(skia_src_path)/core/SkAlphaRuns.cpp', '<(skia_src_path)/core/SkAntiRun.h', '<(skia_src_path)/core/SkBBHFactory.cpp', @@ -242,7 +243,6 @@ '<(skia_src_path)/pipe/SkGPipeRead.cpp', '<(skia_src_path)/pipe/SkGPipeWrite.cpp', - '<(skia_include_path)/core/SkAdvancedTypefaceMetrics.h', '<(skia_include_path)/core/SkBBHFactory.h', '<(skia_include_path)/core/SkBitmap.h', '<(skia_include_path)/core/SkBitmapDevice.h', diff --git a/include/core/SkTypeface.h b/include/core/SkTypeface.h index 6a6d7241a2..7d8b892f2c 100644 --- a/include/core/SkTypeface.h +++ b/include/core/SkTypeface.h @@ -10,9 +10,10 @@ #ifndef SkTypeface_DEFINED #define SkTypeface_DEFINED -#include "SkAdvancedTypefaceMetrics.h" #include "SkFontStyle.h" #include "SkLazyPtr.h" +#include "SkRect.h" +#include "SkString.h" #include "SkWeakRefCnt.h" class SkDescriptor; @@ -307,6 +308,16 @@ public: } protected: + // The type of advance data wanted. + enum PerGlyphInfo { + kNo_PerGlyphInfo = 0x0, // Don't populate any per glyph info. + kHAdvance_PerGlyphInfo = 0x1, // Populate horizontal advance data. + kVAdvance_PerGlyphInfo = 0x2, // Populate vertical advance data. + kGlyphNames_PerGlyphInfo = 0x4, // Populate glyph names (Type 1 only). + kToUnicode_PerGlyphInfo = 0x8 // Populate ToUnicode table, ignored + // for Type 1 fonts + }; + /** uniqueID must be unique and non-zero */ SkTypeface(const SkFontStyle& style, SkFontID uniqueID, bool isFixedPitch = false); @@ -321,7 +332,7 @@ protected: virtual SkScalerContext* onCreateScalerContext(const SkDescriptor*) const = 0; virtual void onFilterRec(SkScalerContextRec*) const = 0; virtual SkAdvancedTypefaceMetrics* onGetAdvancedTypefaceMetrics( - SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, + PerGlyphInfo, const uint32_t* glyphIDs, uint32_t glyphIDsCount) const = 0; @@ -368,7 +379,7 @@ private: @return The returned object has already been referenced. */ SkAdvancedTypefaceMetrics* getAdvancedTypefaceMetrics( - SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, + PerGlyphInfo, const uint32_t* glyphIDs = NULL, uint32_t glyphIDsCount = 0) const; diff --git a/include/core/SkAdvancedTypefaceMetrics.h b/src/core/SkAdvancedTypefaceMetrics.h similarity index 91% rename from include/core/SkAdvancedTypefaceMetrics.h rename to src/core/SkAdvancedTypefaceMetrics.h index 06757c0c17..34c5211ba4 100644 --- a/include/core/SkAdvancedTypefaceMetrics.h +++ b/src/core/SkAdvancedTypefaceMetrics.h @@ -74,16 +74,6 @@ public: SkIRect fBBox; // The bounding box of all glyphs (in font units). - // The type of advance data wanted. - enum PerGlyphInfo { - kNo_PerGlyphInfo = 0x0, // Don't populate any per glyph info. - kHAdvance_PerGlyphInfo = 0x1, // Populate horizontal advance data. - kVAdvance_PerGlyphInfo = 0x2, // Populate vertical advance data. - kGlyphNames_PerGlyphInfo = 0x4, // Populate glyph names (Type 1 only). - kToUnicode_PerGlyphInfo = 0x8 // Populate ToUnicode table, ignored - // for Type 1 fonts - }; - template struct AdvanceMetric { enum MetricType { diff --git a/src/core/SkTypeface.cpp b/src/core/SkTypeface.cpp index bbf3f44896..0f5d70b1a8 100644 --- a/src/core/SkTypeface.cpp +++ b/src/core/SkTypeface.cpp @@ -35,7 +35,7 @@ protected: } 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 @@ void SkTypeface::getFamilyName(SkString* name) const { } 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 17eee82a13..5787478cec 100644 --- a/src/fonts/SkGScalerContext.cpp +++ b/src/fonts/SkGScalerContext.cpp @@ -178,7 +178,7 @@ void SkGTypeface::onFilterRec(SkScalerContextRec* rec) const { } 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 e0f32625cd..75f3ebedbd 100644 --- a/src/fonts/SkGScalerContext.h +++ b/src/fonts/SkGScalerContext.h @@ -23,7 +23,7 @@ protected: 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 733e95fdb8..8ff9f4323b 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 @@ void SkTestTypeface::onFilterRec(SkScalerContextRec* rec) const { } 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 573a3df212..1d4b89ae17 100644 --- a/src/fonts/SkTestScalerContext.h +++ b/src/fonts/SkTestScalerContext.h @@ -69,7 +69,7 @@ protected: 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 11cf012337..c2dfa8ea7f 100644 --- a/src/pdf/SkPDFFont.cpp +++ b/src/pdf/SkPDFFont.cpp @@ -829,13 +829,13 @@ SkPDFFont* SkPDFFont::GetFontResource(SkPDFCanon* canon, return SkRef(relatedFont); } } else { - SkAdvancedTypefaceMetrics::PerGlyphInfo info; - info = SkAdvancedTypefaceMetrics::kGlyphNames_PerGlyphInfo; - info = SkTBitOr( - info, SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo); + SkTypeface::PerGlyphInfo info; + info = SkTypeface::kGlyphNames_PerGlyphInfo; + info = SkTBitOr( + info, SkTypeface::kToUnicode_PerGlyphInfo); #if !defined (SK_SFNTLY_SUBSETTER) - info = SkTBitOr( - info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo); + info = SkTBitOr( + info, SkTypeface::kHAdvance_PerGlyphInfo); #endif fontMetrics.reset( typeface->getAdvancedTypefaceMetrics(info, NULL, 0)); @@ -1127,10 +1127,10 @@ bool SkPDFCIDFont::populate(const SkPDFGlyphSet* subset) { subset->exportTo(&glyphIDs); } - SkAdvancedTypefaceMetrics::PerGlyphInfo info; - info = SkAdvancedTypefaceMetrics::kGlyphNames_PerGlyphInfo; - info = SkTBitOr( - info, SkAdvancedTypefaceMetrics::kHAdvance_PerGlyphInfo); + SkTypeface::PerGlyphInfo info; + info = SkTypeface::kGlyphNames_PerGlyphInfo; + info = SkTBitOr( + info, SkTypeface::kHAdvance_PerGlyphInfo); uint32_t* glyphs = (glyphIDs.count() == 0) ? NULL : glyphIDs.begin(); uint32_t glyphsCount = glyphs ? glyphIDs.count() : 0; SkAutoTUnref fontMetrics( diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index 4b6738e7e4..5c53b9d913 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -460,7 +460,7 @@ static void populate_glyph_to_unicode(FT_Face& face, SkTDArray* glyph } 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 @@ SkAdvancedTypefaceMetrics* SkTypeface_FreeType::onGetAdvancedTypefaceMetrics( 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 @@ SkAdvancedTypefaceMetrics* SkTypeface_FreeType::onGetAdvancedTypefaceMetrics( } } - 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 @@ SkAdvancedTypefaceMetrics* SkTypeface_FreeType::onGetAdvancedTypefaceMetrics( } } - 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 36efba011d..857d2c8990 100644 --- a/src/ports/SkFontHost_FreeType_common.h +++ b/src/ports/SkFontHost_FreeType_common.h @@ -61,9 +61,8 @@ protected: 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 d97b09c651..3c7be46364 100755 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -19,6 +19,7 @@ #include #endif +#include "SkAdvancedTypefaceMetrics.h" #include "SkCGUtils.h" #include "SkColorPriv.h" #include "SkDescriptor.h" @@ -453,7 +454,7 @@ protected: 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 @@ static void CFStringToSkString(CFStringRef src, SkString* dst) { } SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics( - SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, + PerGlyphInfo perGlyphInfo, const uint32_t* glyphIDs, uint32_t glyphIDsCount) const { @@ -1565,7 +1566,7 @@ SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics( 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 @@ SkAdvancedTypefaceMetrics* SkTypeface_Mac::onGetAdvancedTypefaceMetrics( } } - 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 bb5f8de782..bcbbe11288 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 @@ protected: 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 @@ static bool getWidthAdvance(HDC hdc, int gId, int16_t* advance) { } SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics( - SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, + PerGlyphInfo perGlyphInfo, const uint32_t* glyphIDs, uint32_t glyphIDsCount) const { LOGFONT lf = fLogFont; @@ -1782,7 +1780,7 @@ SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics( SkAdvancedTypefaceMetrics::kNotEmbeddable_FontFlag); } - if (perGlyphInfo & SkAdvancedTypefaceMetrics::kToUnicode_PerGlyphInfo) { + if (perGlyphInfo & kToUnicode_PerGlyphInfo) { populate_glyph_to_unicode(hdc, glyphCount, &(info->fGlyphToUnicode)); } @@ -1841,7 +1839,7 @@ SkAdvancedTypefaceMetrics* LogFontTypeface::onGetAdvancedTypefaceMetrics( } } - 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 f44557819c..cf45c16b80 100644 --- a/src/ports/SkTypeface_win_dw.cpp +++ b/src/ports/SkTypeface_win_dw.cpp @@ -322,7 +322,7 @@ static bool getWidthAdvance(IDWriteFontFace* fontFace, int gId, int16_t* advance } SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics( - SkAdvancedTypefaceMetrics::PerGlyphInfo perGlyphInfo, + PerGlyphInfo perGlyphInfo, const uint32_t* glyphIDs, uint32_t glyphIDsCount) const { @@ -355,7 +355,7 @@ SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics( 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 @@ SkAdvancedTypefaceMetrics* DWriteFontTypeface::onGetAdvancedTypefaceMetrics( } */ - 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 9921aed4f7..71d928bcb9 100644 --- a/src/ports/SkTypeface_win_dw.h +++ b/src/ports/SkTypeface_win_dw.h @@ -99,9 +99,8 @@ protected: 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;