| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkAdvancedTypefaceMetrics.h" | 10 #include "SkAdvancedTypefaceMetrics.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 template <typename Data> | 66 template <typename Data> |
| 67 void resetRange(SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range, | 67 void resetRange(SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range, |
| 68 int startId) { | 68 int startId) { |
| 69 range->fStartId = startId; | 69 range->fStartId = startId; |
| 70 range->fAdvance.setCount(0); | 70 range->fAdvance.setCount(0); |
| 71 } | 71 } |
| 72 | 72 |
| 73 template <typename Data> | 73 template <typename Data> |
| 74 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* appendRange( | 74 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* appendRange( |
| 75 SkTScopedPtr<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot, | 75 SkAutoTDelete<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> >* nextSlot
, |
| 76 int startId) { | 76 int startId) { |
| 77 nextSlot->reset(new SkAdvancedTypefaceMetrics::AdvanceMetric<Data>); | 77 nextSlot->reset(new SkAdvancedTypefaceMetrics::AdvanceMetric<Data>); |
| 78 resetRange(nextSlot->get(), startId); | 78 resetRange(nextSlot->get(), startId); |
| 79 return nextSlot->get(); | 79 return nextSlot->get(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 template <typename Data> | 82 template <typename Data> |
| 83 void zeroWildcardsInRange( | 83 void zeroWildcardsInRange( |
| 84 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range)
{ | 84 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* range)
{ |
| 85 SkASSERT(false); | 85 SkASSERT(false); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // a. Removing 4 0's or don't care's is a win | 141 // a. Removing 4 0's or don't care's is a win |
| 142 // The cost of stopping and starting the range plus a run is 22 | 142 // The cost of stopping and starting the range plus a run is 22 |
| 143 // characters | 143 // characters |
| 144 // b. Removing 3 repeating advances is a win | 144 // b. Removing 3 repeating advances is a win |
| 145 // c. Removing 2 repeating advances and 3 don't cares is a win | 145 // c. Removing 2 repeating advances and 3 don't cares is a win |
| 146 // When not currently in a range the cost of a run over a range is 16 | 146 // When not currently in a range the cost of a run over a range is 16 |
| 147 // characaters, so: | 147 // characaters, so: |
| 148 // d. Removing a leading 0/don't cares is a win because it is omitted | 148 // d. Removing a leading 0/don't cares is a win because it is omitted |
| 149 // e. Removing 2 repeating advances is a win | 149 // e. Removing 2 repeating advances is a win |
| 150 | 150 |
| 151 SkTScopedPtr<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> > result; | 151 SkAutoTDelete<SkAdvancedTypefaceMetrics::AdvanceMetric<Data> > result; |
| 152 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* curRange; | 152 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* curRange; |
| 153 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* prevRange = NULL; | 153 SkAdvancedTypefaceMetrics::AdvanceMetric<Data>* prevRange = NULL; |
| 154 Data lastAdvance = kInvalidAdvance; | 154 Data lastAdvance = kInvalidAdvance; |
| 155 int repeatedAdvances = 0; | 155 int repeatedAdvances = 0; |
| 156 int wildCardsInRun = 0; | 156 int wildCardsInRun = 0; |
| 157 int trailingWildCards = 0; | 157 int trailingWildCards = 0; |
| 158 uint32_t subsetIndex = 0; | 158 uint32_t subsetIndex = 0; |
| 159 | 159 |
| 160 // Limit the loop count to glyph id ranges provided. | 160 // Limit the loop count to glyph id ranges provided. |
| 161 int firstIndex = 0; | 161 int firstIndex = 0; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 trailingWildCards = 0; | 238 trailingWildCards = 0; |
| 239 } | 239 } |
| 240 curRange->fAdvance.append(1, &advance); | 240 curRange->fAdvance.append(1, &advance); |
| 241 if (advance != kDontCareAdvance) { | 241 if (advance != kDontCareAdvance) { |
| 242 lastAdvance = advance; | 242 lastAdvance = advance; |
| 243 } | 243 } |
| 244 } | 244 } |
| 245 if (curRange->fStartId == lastIndex) { | 245 if (curRange->fStartId == lastIndex) { |
| 246 SkASSERT(prevRange); | 246 SkASSERT(prevRange); |
| 247 SkASSERT(prevRange->fNext->fStartId == lastIndex); | 247 SkASSERT(prevRange->fNext->fStartId == lastIndex); |
| 248 prevRange->fNext.reset(); | 248 prevRange->fNext.free(); |
| 249 } else { | 249 } else { |
| 250 finishRange(curRange, lastIndex - 1, | 250 finishRange(curRange, lastIndex - 1, |
| 251 SkAdvancedTypefaceMetrics::WidthRange::kRange); | 251 SkAdvancedTypefaceMetrics::WidthRange::kRange); |
| 252 } | 252 } |
| 253 return result.release(); | 253 return result.detach(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 // Make AdvanceMetric template functions available for linking with typename | 256 // Make AdvanceMetric template functions available for linking with typename |
| 257 // WidthRange and VerticalAdvanceRange. | 257 // WidthRange and VerticalAdvanceRange. |
| 258 #if defined(SK_BUILD_FOR_WIN) | 258 #if defined(SK_BUILD_FOR_WIN) |
| 259 template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData( | 259 template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData( |
| 260 HDC hdc, | 260 HDC hdc, |
| 261 int num_glyphs, | 261 int num_glyphs, |
| 262 const uint32_t* subsetGlyphIDs, | 262 const uint32_t* subsetGlyphIDs, |
| 263 uint32_t subsetGlyphIDsLength, | 263 uint32_t subsetGlyphIDsLength, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 280 CTFontRef ctFont, | 280 CTFontRef ctFont, |
| 281 int num_glyphs, | 281 int num_glyphs, |
| 282 const uint32_t* subsetGlyphIDs, | 282 const uint32_t* subsetGlyphIDs, |
| 283 uint32_t subsetGlyphIDsLength, | 283 uint32_t subsetGlyphIDsLength, |
| 284 bool (*getAdvance)(CTFontRef ctFont, int gId, int16_t* data)); | 284 bool (*getAdvance)(CTFontRef ctFont, int gId, int16_t* data)); |
| 285 #endif | 285 #endif |
| 286 template void resetRange( | 286 template void resetRange( |
| 287 SkAdvancedTypefaceMetrics::WidthRange* range, | 287 SkAdvancedTypefaceMetrics::WidthRange* range, |
| 288 int startId); | 288 int startId); |
| 289 template SkAdvancedTypefaceMetrics::WidthRange* appendRange( | 289 template SkAdvancedTypefaceMetrics::WidthRange* appendRange( |
| 290 SkTScopedPtr<SkAdvancedTypefaceMetrics::WidthRange >* nextSlot, | 290 SkAutoTDelete<SkAdvancedTypefaceMetrics::WidthRange >* nextSlot, |
| 291 int startId); | 291 int startId); |
| 292 template void finishRange<int16_t>( | 292 template void finishRange<int16_t>( |
| 293 SkAdvancedTypefaceMetrics::WidthRange* range, | 293 SkAdvancedTypefaceMetrics::WidthRange* range, |
| 294 int endId, | 294 int endId, |
| 295 SkAdvancedTypefaceMetrics::WidthRange::MetricType type); | 295 SkAdvancedTypefaceMetrics::WidthRange::MetricType type); |
| 296 | 296 |
| 297 template void resetRange( | 297 template void resetRange( |
| 298 SkAdvancedTypefaceMetrics::VerticalAdvanceRange* range, | 298 SkAdvancedTypefaceMetrics::VerticalAdvanceRange* range, |
| 299 int startId); | 299 int startId); |
| 300 template SkAdvancedTypefaceMetrics::VerticalAdvanceRange* appendRange( | 300 template SkAdvancedTypefaceMetrics::VerticalAdvanceRange* appendRange( |
| 301 SkTScopedPtr<SkAdvancedTypefaceMetrics::VerticalAdvanceRange >* | 301 SkAutoTDelete<SkAdvancedTypefaceMetrics::VerticalAdvanceRange >* |
| 302 nextSlot, | 302 nextSlot, |
| 303 int startId); | 303 int startId); |
| 304 template void finishRange<SkAdvancedTypefaceMetrics::VerticalMetric>( | 304 template void finishRange<SkAdvancedTypefaceMetrics::VerticalMetric>( |
| 305 SkAdvancedTypefaceMetrics::VerticalAdvanceRange* range, | 305 SkAdvancedTypefaceMetrics::VerticalAdvanceRange* range, |
| 306 int endId, | 306 int endId, |
| 307 SkAdvancedTypefaceMetrics::VerticalAdvanceRange::MetricType type); | 307 SkAdvancedTypefaceMetrics::VerticalAdvanceRange::MetricType type); |
| 308 | 308 |
| 309 // additional declaration needed for testing with a face of an unknown type | 309 // additional declaration needed for testing with a face of an unknown type |
| 310 template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData( | 310 template SkAdvancedTypefaceMetrics::WidthRange* getAdvanceData( |
| 311 void* fontData, | 311 void* fontData, |
| 312 int num_glyphs, | 312 int num_glyphs, |
| 313 const uint32_t* subsetGlyphIDs, | 313 const uint32_t* subsetGlyphIDs, |
| 314 uint32_t subsetGlyphIDsLength, | 314 uint32_t subsetGlyphIDsLength, |
| 315 bool (*getAdvance)(void* fontData, int gId, int16_t* data)); | 315 bool (*getAdvance)(void* fontData, int gId, int16_t* data)); |
| 316 | 316 |
| 317 } // namespace skia_advanced_typeface_metrics_utils | 317 } // namespace skia_advanced_typeface_metrics_utils |
| OLD | NEW |