OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2009 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 16 matching lines...) Expand all Loading... |
27 */ | 27 */ |
28 | 28 |
29 #ifndef GlyphMetricsMap_h | 29 #ifndef GlyphMetricsMap_h |
30 #define GlyphMetricsMap_h | 30 #define GlyphMetricsMap_h |
31 | 31 |
32 #include "platform/fonts/Glyph.h" | 32 #include "platform/fonts/Glyph.h" |
33 #include "platform/geometry/FloatRect.h" | 33 #include "platform/geometry/FloatRect.h" |
34 #include "wtf/Allocator.h" | 34 #include "wtf/Allocator.h" |
35 #include "wtf/Assertions.h" | 35 #include "wtf/Assertions.h" |
36 #include "wtf/HashMap.h" | 36 #include "wtf/HashMap.h" |
37 #include "wtf/OwnPtr.h" | 37 #include "wtf/PtrUtil.h" |
38 #include "wtf/PassOwnPtr.h" | |
39 #include "wtf/text/Unicode.h" | 38 #include "wtf/text/Unicode.h" |
| 39 #include <memory> |
40 | 40 |
41 namespace blink { | 41 namespace blink { |
42 | 42 |
43 const float cGlyphSizeUnknown = -1; | 43 const float cGlyphSizeUnknown = -1; |
44 | 44 |
45 template<class T> class GlyphMetricsMap { | 45 template<class T> class GlyphMetricsMap { |
46 USING_FAST_MALLOC(GlyphMetricsMap); | 46 USING_FAST_MALLOC(GlyphMetricsMap); |
47 WTF_MAKE_NONCOPYABLE(GlyphMetricsMap); | 47 WTF_MAKE_NONCOPYABLE(GlyphMetricsMap); |
48 public: | 48 public: |
49 GlyphMetricsMap() : m_filledPrimaryPage(false) { } | 49 GlyphMetricsMap() : m_filledPrimaryPage(false) { } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 return &m_primaryPage; | 86 return &m_primaryPage; |
87 return locatePageSlowCase(pageNumber); | 87 return locatePageSlowCase(pageNumber); |
88 } | 88 } |
89 | 89 |
90 GlyphMetricsPage* locatePageSlowCase(unsigned pageNumber); | 90 GlyphMetricsPage* locatePageSlowCase(unsigned pageNumber); |
91 | 91 |
92 static T unknownMetrics(); | 92 static T unknownMetrics(); |
93 | 93 |
94 bool m_filledPrimaryPage; | 94 bool m_filledPrimaryPage; |
95 GlyphMetricsPage m_primaryPage; // We optimize for the page that contains gl
yph indices 0-255. | 95 GlyphMetricsPage m_primaryPage; // We optimize for the page that contains gl
yph indices 0-255. |
96 OwnPtr<HashMap<int, OwnPtr<GlyphMetricsPage>>> m_pages; | 96 std::unique_ptr<HashMap<int, std::unique_ptr<GlyphMetricsPage>>> m_pages; |
97 }; | 97 }; |
98 | 98 |
99 template<> inline float GlyphMetricsMap<float>::unknownMetrics() | 99 template<> inline float GlyphMetricsMap<float>::unknownMetrics() |
100 { | 100 { |
101 return cGlyphSizeUnknown; | 101 return cGlyphSizeUnknown; |
102 } | 102 } |
103 | 103 |
104 template<> inline FloatRect GlyphMetricsMap<FloatRect>::unknownMetrics() | 104 template<> inline FloatRect GlyphMetricsMap<FloatRect>::unknownMetrics() |
105 { | 105 { |
106 return FloatRect(0, 0, cGlyphSizeUnknown, cGlyphSizeUnknown); | 106 return FloatRect(0, 0, cGlyphSizeUnknown, cGlyphSizeUnknown); |
107 } | 107 } |
108 | 108 |
109 template<class T> typename GlyphMetricsMap<T>::GlyphMetricsPage* GlyphMetricsMap
<T>::locatePageSlowCase(unsigned pageNumber) | 109 template<class T> typename GlyphMetricsMap<T>::GlyphMetricsPage* GlyphMetricsMap
<T>::locatePageSlowCase(unsigned pageNumber) |
110 { | 110 { |
111 GlyphMetricsPage* page; | 111 GlyphMetricsPage* page; |
112 if (!pageNumber) { | 112 if (!pageNumber) { |
113 ASSERT(!m_filledPrimaryPage); | 113 ASSERT(!m_filledPrimaryPage); |
114 page = &m_primaryPage; | 114 page = &m_primaryPage; |
115 m_filledPrimaryPage = true; | 115 m_filledPrimaryPage = true; |
116 } else { | 116 } else { |
117 if (m_pages) { | 117 if (m_pages) { |
118 page = m_pages->get(pageNumber); | 118 page = m_pages->get(pageNumber); |
119 if (page) | 119 if (page) |
120 return page; | 120 return page; |
121 } else { | 121 } else { |
122 m_pages = adoptPtr(new HashMap<int, OwnPtr<GlyphMetricsPage>>); | 122 m_pages = wrapUnique(new HashMap<int, std::unique_ptr<GlyphMetricsPa
ge>>); |
123 } | 123 } |
124 page = new GlyphMetricsPage; | 124 page = new GlyphMetricsPage; |
125 m_pages->set(pageNumber, adoptPtr(page)); | 125 m_pages->set(pageNumber, wrapUnique(page)); |
126 } | 126 } |
127 | 127 |
128 // Fill in the whole page with the unknown glyph information. | 128 // Fill in the whole page with the unknown glyph information. |
129 for (unsigned i = 0; i < GlyphMetricsPage::size; i++) | 129 for (unsigned i = 0; i < GlyphMetricsPage::size; i++) |
130 page->setMetricsForIndex(i, unknownMetrics()); | 130 page->setMetricsForIndex(i, unknownMetrics()); |
131 | 131 |
132 return page; | 132 return page; |
133 } | 133 } |
134 | 134 |
135 } // namespace blink | 135 } // namespace blink |
136 | 136 |
137 #endif | 137 #endif |
OLD | NEW |