OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "printing/pdf_ps_metafile_cairo.h" | 5 #include "printing/pdf_ps_metafile_cairo.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include <cairo.h> | 9 #include <cairo.h> |
10 #include <cairo-pdf.h> | 10 #include <cairo-pdf.h> |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 DLOG(ERROR) << "Cannot create Cairo context for PdfPsMetafile!"; | 106 DLOG(ERROR) << "Cannot create Cairo context for PdfPsMetafile!"; |
107 CleanUpContext(&context_); | 107 CleanUpContext(&context_); |
108 CleanUpSurface(&surface_); | 108 CleanUpSurface(&surface_); |
109 return false; | 109 return false; |
110 } | 110 } |
111 | 111 |
112 cairo_set_user_data(context_, &kPdfMetafileKey, this, DestroyContextData); | 112 cairo_set_user_data(context_, &kPdfMetafileKey, this, DestroyContextData); |
113 return true; | 113 return true; |
114 } | 114 } |
115 | 115 |
116 bool PdfPsMetafile::Init(const void* src_buffer, uint32 src_buffer_size) { | 116 bool PdfPsMetafile::InitFromData(const void* src_buffer, |
| 117 uint32 src_buffer_size) { |
117 // We need to check at least these two members to ensure Init() has not been | 118 // We need to check at least these two members to ensure Init() has not been |
118 // called before | 119 // called before |
119 DCHECK(!context_); | 120 DCHECK(!context_); |
120 DCHECK(data_.empty()); | 121 DCHECK(data_.empty()); |
121 | 122 |
122 if (src_buffer == NULL || src_buffer_size == 0) | 123 if (src_buffer == NULL || src_buffer_size == 0) |
123 return false; | 124 return false; |
124 | 125 |
125 data_ = std::string(reinterpret_cast<const char*>(src_buffer), | 126 data_ = std::string(reinterpret_cast<const char*>(src_buffer), |
126 src_buffer_size); | 127 src_buffer_size); |
127 return true; | 128 return true; |
128 } | 129 } |
129 | 130 |
130 bool PdfPsMetafile::SetRawData(const void* src_buffer, | 131 bool PdfPsMetafile::SetRawData(const void* src_buffer, |
131 uint32 src_buffer_size) { | 132 uint32 src_buffer_size) { |
132 if (!context_) { | 133 if (!context_) { |
133 // If Init has not already been called, just call Init() | 134 // If Init has not already been called, just call Init() |
134 return Init(src_buffer, src_buffer_size); | 135 return InitFromData(src_buffer, src_buffer_size); |
135 } | 136 } |
136 // If a context has already been created, remember this data in | 137 // If a context has already been created, remember this data in |
137 // raw_override_data_ | 138 // raw_override_data_ |
138 if (src_buffer == NULL || src_buffer_size == 0) | 139 if (src_buffer == NULL || src_buffer_size == 0) |
139 return false; | 140 return false; |
140 | 141 |
141 raw_override_data_ = std::string(reinterpret_cast<const char*>(src_buffer), | 142 raw_override_data_ = std::string(reinterpret_cast<const char*>(src_buffer), |
142 src_buffer_size); | 143 src_buffer_size); |
143 | 144 |
144 return true; | 145 return true; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 274 } |
274 | 275 |
275 void PdfPsMetafile::CleanUpAll() { | 276 void PdfPsMetafile::CleanUpAll() { |
276 CleanUpContext(&context_); | 277 CleanUpContext(&context_); |
277 CleanUpSurface(&surface_); | 278 CleanUpSurface(&surface_); |
278 data_.clear(); | 279 data_.clear(); |
279 skia::VectorPlatformDevice::ClearFontCache(); | 280 skia::VectorPlatformDevice::ClearFontCache(); |
280 } | 281 } |
281 | 282 |
282 } // namespace printing | 283 } // namespace printing |
OLD | NEW |