Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Unified Diff: src/core/SkAdvancedTypefaceMetrics.cpp

Issue 1955053002: SkAdvancedTypefaceMetrics: getAdvanceData uses std::function (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkAdvancedTypefaceMetrics.cpp
diff --git a/src/core/SkAdvancedTypefaceMetrics.cpp b/src/core/SkAdvancedTypefaceMetrics.cpp
index 318f4a06bc23cbbb4801a76ea55b7f156360db75..559259e60e37313b3d613cd658308bdee629ba3c 100644
--- a/src/core/SkAdvancedTypefaceMetrics.cpp
+++ b/src/core/SkAdvancedTypefaceMetrics.cpp
@@ -9,24 +9,6 @@
#include "SkAdvancedTypefaceMetrics.h"
#include "SkTypes.h"
-#if defined(SK_BUILD_FOR_WIN)
-#include <dwrite.h>
-#endif
-
-// forward declare structs needed for getAdvanceData() template for freetype
-struct FT_FaceRec_;
-typedef struct FT_FaceRec_* FT_Face;
-
-#ifdef SK_BUILD_FOR_MAC
-#import <ApplicationServices/ApplicationServices.h>
-#endif
-
-#ifdef SK_BUILD_FOR_IOS
-#include <CoreText/CoreText.h>
-#include <CoreGraphics/CoreGraphics.h>
-#include <CoreFoundation/CoreFoundation.h>
-#endif
-
template <typename Data>
static void unwind(SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* ptr) {
while (ptr) {
@@ -137,13 +119,12 @@ void finishRange(
zeroWildcardsInRange(range);
}
-template <typename Data, typename FontHandle>
+template <typename Data>
SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData(
- FontHandle fontHandle,
int num_glyphs,
const uint32_t* subsetGlyphIDs,
uint32_t subsetGlyphIDsLength,
- bool (*getAdvance)(FontHandle fontHandle, int gId, Data* data)) {
+ std::function<bool(int gId, Data* data)> getAdvance) {
// Assuming that on average, the ASCII representation of an advance plus
// a space is 8 characters and the ASCII representation of a glyph id is 3
// characters, then the following cut offs for using different range types
@@ -187,7 +168,7 @@ SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData(
if (!subsetGlyphIDs ||
(subsetIndex < subsetGlyphIDsLength &&
static_cast<uint32_t>(gId) == subsetGlyphIDs[subsetIndex])) {
- SkAssertResult(getAdvance(fontHandle, gId, &advance));
+ SkAssertResult(getAdvance(gId, &advance));
++subsetIndex;
} else {
advance = kDontCareAdvance;
@@ -269,33 +250,11 @@ SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* getAdvanceData(
// Make AdvanceMetric template functions available for linking with typename
// WidthRange and VerticalAdvanceRange.
template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData(
- FT_Face face,
int num_glyphs,
- const uint32_t* subsetGlyphIDs,
- uint32_t subsetGlyphIDsLength,
- bool (*getAdvance)(FT_Face face, int gId, int16_t* data));
+ const uint32_t* glyphIDs,
+ uint32_t glyphIDsCount,
+ std::function<bool(int, int16_t*)> getAdvance);
-#if defined(SK_BUILD_FOR_WIN)
-template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData(
- HDC hdc,
- int num_glyphs,
- const uint32_t* subsetGlyphIDs,
- uint32_t subsetGlyphIDsLength,
- bool (*getAdvance)(HDC hdc, int gId, int16_t* data));
-template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData(
- IDWriteFontFace* fontFace,
- int num_glyphs,
- const uint32_t* subsetGlyphIDs,
- uint32_t subsetGlyphIDsLength,
- bool (*getAdvance)(IDWriteFontFace* fontFace, int gId, int16_t* data));
-#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
-template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData(
- CTFontRef ctFont,
- int num_glyphs,
- const uint32_t* subsetGlyphIDs,
- uint32_t subsetGlyphIDsLength,
- bool (*getAdvance)(CTFontRef ctFont, int gId, int16_t* data));
-#endif
template void resetRange(
SkAdvancedTypefaceMetrics::WidthRange* range,
int startId);
@@ -319,12 +278,4 @@ template void finishRange<SkAdvancedTypefaceMetrics::VerticalMetric>(
int endId,
SkAdvancedTypefaceMetrics::VerticalAdvanceRange::MetricType type);
-// additional declaration needed for testing with a face of an unknown type
-template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData(
- void* fontData,
- int num_glyphs,
- const uint32_t* subsetGlyphIDs,
- uint32_t subsetGlyphIDsLength,
- bool (*getAdvance)(void* fontData, int gId, int16_t* data));
-
} // namespace skia_advanced_typeface_metrics_utils

Powered by Google App Engine
This is Rietveld 408576698