OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkPDFBitmap.h" | 8 #include "SkPDFBitmap.h" |
9 #include "SkPDFCanon.h" | 9 #include "SkPDFCanon.h" |
10 #include "SkPDFFont.h" | 10 #include "SkPDFFont.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 template <class T> T* assert_ptr(T* p) { SkASSERT(p); return p; } | 34 template <class T> T* assert_ptr(T* p) { SkASSERT(p); return p; } |
35 | 35 |
36 // requires `bool T::equals(const U&) const` | 36 // requires `bool T::equals(const U&) const` |
37 template <typename T, typename U> | 37 template <typename T, typename U> |
38 T* find_item(const SkTDArray<T*>& ptrArray, const U& object) { | 38 T* find_item(const SkTDArray<T*>& ptrArray, const U& object) { |
39 for (int i = 0; i < ptrArray.count(); ++i) { | 39 for (int i = 0; i < ptrArray.count(); ++i) { |
40 if (ptrArray[i]->equals(object)) { | 40 if (ptrArray[i]->equals(object)) { |
41 return ptrArray[i]; | 41 return ptrArray[i]; |
42 } | 42 } |
43 } | 43 } |
44 return NULL; | 44 return nullptr; |
45 } | 45 } |
46 | 46 |
47 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
48 | 48 |
49 SkPDFFont* SkPDFCanon::findFont(uint32_t fontID, | 49 SkPDFFont* SkPDFCanon::findFont(uint32_t fontID, |
50 uint16_t glyphID, | 50 uint16_t glyphID, |
51 SkPDFFont** relatedFontPtr) const { | 51 SkPDFFont** relatedFontPtr) const { |
52 SkASSERT(relatedFontPtr); | 52 SkASSERT(relatedFontPtr); |
53 | 53 |
54 SkPDFFont* relatedFont = NULL; | 54 SkPDFFont* relatedFont = nullptr; |
55 for (int i = 0; i < fFontRecords.count(); ++i) { | 55 for (int i = 0; i < fFontRecords.count(); ++i) { |
56 SkPDFFont::Match match = SkPDFFont::IsMatch( | 56 SkPDFFont::Match match = SkPDFFont::IsMatch( |
57 fFontRecords[i].fFont, fFontRecords[i].fFontID, | 57 fFontRecords[i].fFont, fFontRecords[i].fFontID, |
58 fFontRecords[i].fGlyphID, fontID, glyphID); | 58 fFontRecords[i].fGlyphID, fontID, glyphID); |
59 if (SkPDFFont::kExact_Match == match) { | 59 if (SkPDFFont::kExact_Match == match) { |
60 return fFontRecords[i].fFont; | 60 return fFontRecords[i].fFont; |
61 } else if (!relatedFont && SkPDFFont::kRelated_Match == match) { | 61 } else if (!relatedFont && SkPDFFont::kRelated_Match == match) { |
62 relatedFont = fFontRecords[i].fFont; | 62 relatedFont = fFontRecords[i].fFont; |
63 } | 63 } |
64 } | 64 } |
65 *relatedFontPtr = relatedFont; // May still be NULL. | 65 *relatedFontPtr = relatedFont; // May still be nullptr. |
66 return NULL; | 66 return nullptr; |
67 } | 67 } |
68 | 68 |
69 void SkPDFCanon::addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID) { | 69 void SkPDFCanon::addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID) { |
70 SkPDFCanon::FontRec* rec = fFontRecords.push(); | 70 SkPDFCanon::FontRec* rec = fFontRecords.push(); |
71 rec->fFont = SkRef(font); | 71 rec->fFont = SkRef(font); |
72 rec->fFontID = fontID; | 72 rec->fFontID = fontID; |
73 rec->fGlyphID = fGlyphID; | 73 rec->fGlyphID = fGlyphID; |
74 } | 74 } |
75 | 75 |
76 //////////////////////////////////////////////////////////////////////////////// | 76 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 25 matching lines...) Expand all Loading... |
102 | 102 |
103 void SkPDFCanon::addImageShader(SkPDFImageShader* pdfShader) { | 103 void SkPDFCanon::addImageShader(SkPDFImageShader* pdfShader) { |
104 fImageShaderRecords.push(SkRef(pdfShader)); | 104 fImageShaderRecords.push(SkRef(pdfShader)); |
105 } | 105 } |
106 | 106 |
107 //////////////////////////////////////////////////////////////////////////////// | 107 //////////////////////////////////////////////////////////////////////////////// |
108 | 108 |
109 const SkPDFGraphicState* SkPDFCanon::findGraphicState( | 109 const SkPDFGraphicState* SkPDFCanon::findGraphicState( |
110 const SkPDFGraphicState& key) const { | 110 const SkPDFGraphicState& key) const { |
111 const WrapGS* ptr = fGraphicStateRecords.find(WrapGS(&key)); | 111 const WrapGS* ptr = fGraphicStateRecords.find(WrapGS(&key)); |
112 return ptr ? ptr->fPtr : NULL; | 112 return ptr ? ptr->fPtr : nullptr; |
113 } | 113 } |
114 | 114 |
115 void SkPDFCanon::addGraphicState(const SkPDFGraphicState* state) { | 115 void SkPDFCanon::addGraphicState(const SkPDFGraphicState* state) { |
116 SkASSERT(state); | 116 SkASSERT(state); |
117 WrapGS w(SkRef(state)); | 117 WrapGS w(SkRef(state)); |
118 SkASSERT(!fGraphicStateRecords.contains(w)); | 118 SkASSERT(!fGraphicStateRecords.contains(w)); |
119 fGraphicStateRecords.add(w); | 119 fGraphicStateRecords.add(w); |
120 } | 120 } |
121 | 121 |
122 //////////////////////////////////////////////////////////////////////////////// | 122 //////////////////////////////////////////////////////////////////////////////// |
123 | 123 |
124 SkPDFBitmap* SkPDFCanon::findBitmap(const SkBitmap& bm) const { | 124 SkPDFBitmap* SkPDFCanon::findBitmap(const SkBitmap& bm) const { |
125 return find_item(fBitmapRecords, bm); | 125 return find_item(fBitmapRecords, bm); |
126 } | 126 } |
127 | 127 |
128 void SkPDFCanon::addBitmap(SkPDFBitmap* pdfBitmap) { | 128 void SkPDFCanon::addBitmap(SkPDFBitmap* pdfBitmap) { |
129 fBitmapRecords.push(SkRef(pdfBitmap)); | 129 fBitmapRecords.push(SkRef(pdfBitmap)); |
130 } | 130 } |
OLD | NEW |