aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkAdvancedTypefaceMetrics.h
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2016-05-08 18:47:16 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-05-08 18:47:16 -0700
commite20a87517043ec4a30dcc7e711ca49087e8942ff (patch)
treea850e29b414362f0d84d919ca18b5462df8e4857 /src/core/SkAdvancedTypefaceMetrics.h
parent0938befe5d1e36df820a67e5dc554b462388d46b (diff)
SkAdvancedTypefaceMetrics: abstract out linked list
+ use SkSinglyLinkedList<T> + move SkSinglyLinkedList.h to core + remove SkHackyAutoTDelete + getAdvanceData() -> setGlyphWidths() + finishRange no longer templated + remove unused templated functions GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1953153004 Review-Url: https://codereview.chromium.org/1953153004
Diffstat (limited to 'src/core/SkAdvancedTypefaceMetrics.h')
-rw-r--r--src/core/SkAdvancedTypefaceMetrics.h113
1 files changed, 46 insertions, 67 deletions
diff --git a/src/core/SkAdvancedTypefaceMetrics.h b/src/core/SkAdvancedTypefaceMetrics.h
index eae7318215..5e7e59331f 100644
--- a/src/core/SkAdvancedTypefaceMetrics.h
+++ b/src/core/SkAdvancedTypefaceMetrics.h
@@ -14,34 +14,7 @@
#include "SkString.h"
#include "SkTDArray.h"
#include "SkTemplates.h"
-
-// Whatever std::unique_ptr Clank's using doesn't seem to work with AdvanceMetric's
-// style of forward-declaration. Probably just a bug in an old libc++ / libstdc++.
-// For now, hack around it with our own smart pointer. It'd be nice to clean up.
-template <typename T>
-class SkHackyAutoTDelete : SkNoncopyable {
-public:
- explicit SkHackyAutoTDelete(T* ptr = nullptr) : fPtr(ptr) {}
- ~SkHackyAutoTDelete() { delete fPtr; }
-
- T* get() const { return fPtr; }
- T* operator->() const { return fPtr; }
-
- void reset(T* ptr = nullptr) {
- if (ptr != fPtr) {
- delete fPtr;
- fPtr = ptr;
- }
- }
- T* release() {
- T* ptr = fPtr;
- fPtr = nullptr;
- return ptr;
- }
-
-private:
- T* fPtr;
-};
+#include "SkSinglyLinkedList.h"
/** \class SkAdvancedTypefaceMetrics
@@ -68,6 +41,29 @@ public:
~SkAdvancedTypefaceMetrics();
+ /** 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 nullptr
+ means all glyphs in the font.
+ @param glyphIDsCount Number of elements in subsetGlyphIds.
+ Ignored if glyphIDs is nullptr.
+ @param getAdvance A function that takes a glyph id and
+ passes back advance data from the
+ typeface. Returns false on failure.
+ */
+ template <typename FontHandle>
+ void setGlyphWidths(FontHandle fontHandle,
+ int num_glyphs,
+ const uint32_t* subsetGlyphIDs,
+ uint32_t subsetGlyphIDsLength,
+ bool (*getAdvance)(FontHandle fontHandle,
+ int gId,
+ int16_t* data));
+
SkString fFontName;
enum FontType {
@@ -126,7 +122,22 @@ public:
uint16_t fStartId;
uint16_t fEndId;
SkTDArray<Data> fAdvance;
- SkHackyAutoTDelete<AdvanceMetric<Data> > fNext;
+ AdvanceMetric(uint16_t startId) : fStartId(startId) {}
+ AdvanceMetric(AdvanceMetric&& other)
+ : fType(other.fType)
+ , fStartId(other.fStartId)
+ , fEndId(other.fEndId) {
+ fAdvance.swap(other.fAdvance);
+ }
+ AdvanceMetric& operator=(AdvanceMetric&& other) {
+ fType = other.fType;
+ fStartId = other.fStartId;
+ fEndId = other.fEndId;
+ fAdvance.swap(other.fAdvance);
+ return *this;
+ }
+ AdvanceMetric(const AdvanceMetric&) = delete;
+ AdvanceMetric& operator=(const AdvanceMetric&) = delete;
};
struct VerticalMetric {
@@ -138,9 +149,9 @@ public:
typedef AdvanceMetric<VerticalMetric> VerticalAdvanceRange;
// This is indexed by glyph id.
- SkAutoTDelete<WidthRange> fGlyphWidths;
+ SkSinglyLinkedList<WidthRange> fGlyphWidths;
// Only used for Vertical CID fonts.
- SkAutoTDelete<VerticalAdvanceRange> fVerticalMetrics;
+ SkSinglyLinkedList<VerticalAdvanceRange> fVerticalMetrics;
// The names of each glyph, only populated for postscript fonts.
SkAutoTDelete<SkAutoTArray<SkString> > fGlyphNames;
@@ -149,45 +160,13 @@ public:
// kToUnicode_PerGlyphInfo is passed to GetAdvancedTypefaceMetrics.
SkTDArray<SkUnichar> fGlyphToUnicode;
+ static void FinishRange(WidthRange* range,
+ int endId,
+ WidthRange::MetricType type);
+
private:
typedef SkRefCnt INHERITED;
};
-namespace skia_advanced_typeface_metrics_utils {
-
-template <typename Data>
-void resetRange(SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range,
- int startId);
-
-template <typename Data, template<typename> class AutoTDelete>
-SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* appendRange(
- AutoTDelete<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 nullptr means all glyphs in the font.
- @param glyphIDsCount Number of elements in subsetGlyphIds. Ignored if
- glyphIDs is nullptr.
-*/
-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