[email protected] | 0a4392a | 2012-03-23 17:50:19 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "printing/pdf_metafile_skia.h" |
| 6 | |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 7 | #include "base/files/file.h" |
halcanary | 67ce00b8 | 2015-09-27 21:59:53 | [diff] [blame] | 8 | #include "base/time/time.h" |
halcanary | 73b63fd | 2015-11-06 00:02:14 | [diff] [blame] | 9 | #include "printing/print_settings.h" |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 10 | #include "third_party/skia/include/core/SkDocument.h" |
| 11 | #include "third_party/skia/include/core/SkPictureRecorder.h" |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 12 | #include "third_party/skia/include/core/SkStream.h" |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 13 | #include "ui/gfx/geometry/safe_integer_conversions.h" |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 14 | #include "ui/gfx/skia_util.h" |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 15 | |
[email protected] | b8d85bc | 2011-06-22 13:34:57 | [diff] [blame] | 16 | #if defined(OS_MACOSX) |
| 17 | #include "printing/pdf_metafile_cg_mac.h" |
| 18 | #endif |
| 19 | |
[email protected] | 0daaebfe | 2014-03-15 00:09:05 | [diff] [blame] | 20 | #if defined(OS_POSIX) |
| 21 | #include "base/file_descriptor_posix.h" |
| 22 | #endif |
| 23 | |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 24 | namespace { |
thestig | e3f5f5d4 | 2015-07-16 19:46:24 | [diff] [blame] | 25 | |
thestig | e3f5f5d4 | 2015-07-16 19:46:24 | [diff] [blame] | 26 | bool WriteAssetToBuffer(const SkStreamAsset* asset, |
| 27 | void* buffer, |
| 28 | size_t size) { |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 29 | // Calling duplicate() keeps original asset state unchanged. |
dcheng | c3df9ba | 2016-04-07 23:09:32 | [diff] [blame] | 30 | std::unique_ptr<SkStreamAsset> assetCopy(asset->duplicate()); |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 31 | size_t length = assetCopy->getLength(); |
| 32 | if (length > size) |
| 33 | return false; |
| 34 | return (length == assetCopy->read(buffer, length)); |
| 35 | } |
| 36 | |
thestig | 5ff7db2 | 2016-02-13 04:42:45 | [diff] [blame] | 37 | SkTime::DateTime TimeToSkTime(base::Time time) { |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 38 | base::Time::Exploded exploded; |
| 39 | time.UTCExplode(&exploded); |
| 40 | SkTime::DateTime skdate; |
| 41 | skdate.fTimeZoneMinutes = 0; |
| 42 | skdate.fYear = exploded.year; |
| 43 | skdate.fMonth = exploded.month; |
| 44 | skdate.fDayOfWeek = exploded.day_of_week; |
| 45 | skdate.fDay = exploded.day_of_month; |
| 46 | skdate.fHour = exploded.hour; |
| 47 | skdate.fMinute = exploded.minute; |
| 48 | skdate.fSecond = exploded.second; |
| 49 | return skdate; |
| 50 | } |
| 51 | |
| 52 | sk_sp<SkDocument> MakePdfDocument(SkWStream* wStream) { |
| 53 | SkDocument::PDFMetadata metadata; |
| 54 | SkTime::DateTime now = TimeToSkTime(base::Time::Now()); |
| 55 | metadata.fCreation.fEnabled = true; |
| 56 | metadata.fCreation.fDateTime = now; |
| 57 | metadata.fModified.fEnabled = true; |
| 58 | metadata.fModified.fDateTime = now; |
| 59 | const std::string& agent = printing::GetAgent(); |
| 60 | metadata.fCreator = agent.empty() ? SkString("Chromium") |
| 61 | : SkString(agent.c_str(), agent.size()); |
| 62 | return SkDocument::MakePDF(wStream, SK_ScalarDefaultRasterDPI, metadata, |
| 63 | nullptr, false); |
thestig | 5ff7db2 | 2016-02-13 04:42:45 | [diff] [blame] | 64 | } |
| 65 | |
thestig | e3f5f5d4 | 2015-07-16 19:46:24 | [diff] [blame] | 66 | } // namespace |
| 67 | |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 68 | namespace printing { |
| 69 | |
| 70 | struct PdfMetafileSkiaData { |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 71 | SkPictureRecorder recorder_; // Current recording |
| 72 | |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 73 | std::vector<sk_sp<SkPicture>> pages_; |
dcheng | c3df9ba | 2016-04-07 23:09:32 | [diff] [blame] | 74 | std::unique_ptr<SkStreamAsset> pdf_data_; |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 75 | |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 76 | // The scale factor is used because Blink occasionally calls |
| 77 | // SkCanvas::getTotalMatrix() even though the total matrix is not as |
| 78 | // meaningful for a vector canvas as for a raster canvas. |
| 79 | float scale_factor_; |
| 80 | |
[email protected] | b8d85bc | 2011-06-22 13:34:57 | [diff] [blame] | 81 | #if defined(OS_MACOSX) |
| 82 | PdfMetafileCg pdf_cg_; |
| 83 | #endif |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | PdfMetafileSkia::~PdfMetafileSkia() {} |
| 87 | |
| 88 | bool PdfMetafileSkia::Init() { |
| 89 | return true; |
| 90 | } |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 91 | |
| 92 | // TODO(halcanary): Create a Metafile class that only stores data. |
| 93 | // Metafile::InitFromData is orthogonal to what the rest of |
| 94 | // PdfMetafileSkia does. |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 95 | bool PdfMetafileSkia::InitFromData(const void* src_buffer, |
thestig | 707a24b2 | 2015-09-14 18:16:33 | [diff] [blame] | 96 | uint32_t src_buffer_size) { |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 97 | data_->pdf_data_.reset(new SkMemoryStream(src_buffer, src_buffer_size, true)); |
| 98 | return true; |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 99 | } |
| 100 | |
thestig | 192677ec | 2016-06-09 07:43:17 | [diff] [blame^] | 101 | void PdfMetafileSkia::StartPage(const gfx::Size& page_size, |
halcanary | 5be808e | 2014-11-10 22:20:05 | [diff] [blame] | 102 | const gfx::Rect& content_area, |
| 103 | const float& scale_factor) { |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 104 | DCHECK_GT(page_size.width(), 0); |
| 105 | DCHECK_GT(page_size.height(), 0); |
| 106 | DCHECK_GT(scale_factor, 0.0f); |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 107 | if (data_->recorder_.getRecordingCanvas()) |
thestig | 5ff7db2 | 2016-02-13 04:42:45 | [diff] [blame] | 108 | FinishPage(); |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 109 | DCHECK(!data_->recorder_.getRecordingCanvas()); |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 110 | |
| 111 | float inverse_scale = 1.0 / scale_factor; |
| 112 | SkCanvas* canvas = data_->recorder_.beginRecording( |
| 113 | inverse_scale * page_size.width(), inverse_scale * page_size.height()); |
| 114 | if (content_area != gfx::Rect(page_size)) { |
| 115 | canvas->scale(inverse_scale, inverse_scale); |
| 116 | SkRect sk_content_area = gfx::RectToSkRect(content_area); |
| 117 | canvas->clipRect(sk_content_area); |
| 118 | canvas->translate(sk_content_area.x(), sk_content_area.y()); |
| 119 | canvas->scale(scale_factor, scale_factor); |
| 120 | } |
| 121 | |
| 122 | data_->scale_factor_ = scale_factor; |
halcanary | 5baa8fb4 | 2015-04-03 21:39:30 | [diff] [blame] | 123 | // We scale the recording canvas's size so that |
| 124 | // canvas->getTotalMatrix() returns a value that ignores the scale |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 125 | // factor. We store the scale factor and re-apply it later. |
| 126 | // http://crbug.com/469656 |
halcanary | 5baa8fb4 | 2015-04-03 21:39:30 | [diff] [blame] | 127 | // Recording canvas is owned by the data_->recorder_. No ref() necessary. |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 128 | } |
| 129 | |
tomhudson | ed673beb | 2016-01-28 14:14:22 | [diff] [blame] | 130 | SkCanvas* PdfMetafileSkia::GetVectorCanvasForNewPage( |
halcanary | 5be808e | 2014-11-10 22:20:05 | [diff] [blame] | 131 | const gfx::Size& page_size, |
| 132 | const gfx::Rect& content_area, |
| 133 | const float& scale_factor) { |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 134 | StartPage(page_size, content_area, scale_factor); |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 135 | return data_->recorder_.getRecordingCanvas(); |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | bool PdfMetafileSkia::FinishPage() { |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 139 | if (!data_->recorder_.getRecordingCanvas()) |
| 140 | return false; |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 141 | |
| 142 | sk_sp<SkPicture> pic = data_->recorder_.finishRecordingAsPicture(); |
| 143 | if (data_->scale_factor_ != 1.0f) { |
| 144 | SkRect rect = pic->cullRect(); |
| 145 | DCHECK_EQ(rect.x(), 0); |
| 146 | DCHECK_EQ(rect.y(), 0); |
| 147 | DCHECK_GT(rect.right(), 0); |
| 148 | DCHECK_GT(rect.bottom(), 0); |
| 149 | SkCanvas* canvas = |
| 150 | data_->recorder_.beginRecording(data_->scale_factor_ * rect.right(), |
| 151 | data_->scale_factor_ * rect.bottom()); |
| 152 | canvas->scale(data_->scale_factor_, data_->scale_factor_); |
| 153 | canvas->drawPicture(pic); |
| 154 | pic = data_->recorder_.finishRecordingAsPicture(); |
| 155 | } |
| 156 | data_->pages_.push_back(std::move(pic)); |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 157 | return true; |
| 158 | } |
| 159 | |
| 160 | bool PdfMetafileSkia::FinishDocument() { |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 161 | // If we've already set the data in InitFromData, leave it be. |
| 162 | if (data_->pdf_data_) |
| 163 | return false; |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 164 | |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 165 | if (data_->recorder_.getRecordingCanvas()) |
thestig | 5ff7db2 | 2016-02-13 04:42:45 | [diff] [blame] | 166 | FinishPage(); |
[email protected] | 67e16b39 | 2011-05-30 20:58:09 | [diff] [blame] | 167 | |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 168 | SkDynamicMemoryWStream stream; |
thestig | 192677ec | 2016-06-09 07:43:17 | [diff] [blame^] | 169 | // TODO(halcanary): support more document types (XPS, a sequence of display |
| 170 | // lists). |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 171 | sk_sp<SkDocument> doc = MakePdfDocument(&stream); |
halcanary | fb23228 | 2016-04-28 18:34:24 | [diff] [blame] | 172 | |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 173 | for (const sk_sp<SkPicture>& page : data_->pages_) { |
| 174 | SkRect rect = page->cullRect(); |
| 175 | DCHECK_EQ(rect.x(), 0); |
| 176 | DCHECK_EQ(rect.y(), 0); |
| 177 | DCHECK_GT(rect.right(), 0); |
| 178 | DCHECK_GT(rect.bottom(), 0); |
| 179 | SkCanvas* canvas = doc->beginPage(rect.right(), rect.bottom()); |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 180 | canvas->drawPicture(page); |
| 181 | doc->endPage(); |
halcanary | 0aeeb333 | 2016-03-18 14:32:39 | [diff] [blame] | 182 | } |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 183 | if (!doc->close()) |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 184 | return false; |
[email protected] | 67e16b39 | 2011-05-30 20:58:09 | [diff] [blame] | 185 | |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 186 | data_->pdf_data_.reset(stream.detachAsStream()); |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 187 | return true; |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 188 | } |
| 189 | |
thestig | 707a24b2 | 2015-09-14 18:16:33 | [diff] [blame] | 190 | uint32_t PdfMetafileSkia::GetDataSize() const { |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 191 | if (!data_->pdf_data_) |
| 192 | return 0; |
thestig | 707a24b2 | 2015-09-14 18:16:33 | [diff] [blame] | 193 | return base::checked_cast<uint32_t>(data_->pdf_data_->getLength()); |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | bool PdfMetafileSkia::GetData(void* dst_buffer, |
thestig | 707a24b2 | 2015-09-14 18:16:33 | [diff] [blame] | 197 | uint32_t dst_buffer_size) const { |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 198 | if (!data_->pdf_data_) |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 199 | return false; |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 200 | return WriteAssetToBuffer(data_->pdf_data_.get(), dst_buffer, |
| 201 | base::checked_cast<size_t>(dst_buffer_size)); |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 202 | } |
| 203 | |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 204 | gfx::Rect PdfMetafileSkia::GetPageBounds(unsigned int page_number) const { |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 205 | if (page_number < data_->pages_.size()) { |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 206 | const sk_sp<SkPicture>& page = data_->pages_[page_number]; |
| 207 | SkRect rect = page->cullRect(); |
| 208 | DCHECK_EQ(rect.x(), 0); |
| 209 | DCHECK_EQ(rect.y(), 0); |
| 210 | DCHECK_GT(rect.right(), 0); |
| 211 | DCHECK_GT(rect.bottom(), 0); |
| 212 | return gfx::Rect(gfx::ToRoundedInt(rect.right()), |
| 213 | gfx::ToRoundedInt(rect.bottom())); |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 214 | } |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 215 | return gfx::Rect(); |
| 216 | } |
| 217 | |
| 218 | unsigned int PdfMetafileSkia::GetPageCount() const { |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 219 | return base::checked_cast<unsigned int>(data_->pages_.size()); |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | gfx::NativeDrawingContext PdfMetafileSkia::context() const { |
| 223 | NOTREACHED(); |
thestig | 192677ec | 2016-06-09 07:43:17 | [diff] [blame^] | 224 | return nullptr; |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 225 | } |
| 226 | |
thestig | 192677ec | 2016-06-09 07:43:17 | [diff] [blame^] | 227 | |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 228 | #if defined(OS_WIN) |
| 229 | bool PdfMetafileSkia::Playback(gfx::NativeDrawingContext hdc, |
| 230 | const RECT* rect) const { |
| 231 | NOTREACHED(); |
| 232 | return false; |
| 233 | } |
| 234 | |
| 235 | bool PdfMetafileSkia::SafePlayback(gfx::NativeDrawingContext hdc) const { |
| 236 | NOTREACHED(); |
| 237 | return false; |
| 238 | } |
| 239 | |
[email protected] | b8d85bc | 2011-06-22 13:34:57 | [diff] [blame] | 240 | #elif defined(OS_MACOSX) |
| 241 | /* TODO(caryclark): The set up of PluginInstance::PrintPDFOutput may result in |
| 242 | rasterized output. Even if that flow uses PdfMetafileCg::RenderPage, |
| 243 | the drawing of the PDF into the canvas may result in a rasterized output. |
| 244 | PDFMetafileSkia::RenderPage should be not implemented as shown and instead |
| 245 | should do something like the following CL in PluginInstance::PrintPDFOutput: |
| 246 | http://codereview.chromium.org/7200040/diff/1/webkit/plugins/ppapi/ppapi_plugin_instance.cc |
| 247 | */ |
| 248 | bool PdfMetafileSkia::RenderPage(unsigned int page_number, |
| 249 | CGContextRef context, |
| 250 | const CGRect rect, |
[email protected] | b5cf844c | 2012-06-18 21:49:20 | [diff] [blame] | 251 | const MacRenderPageParams& params) const { |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 252 | DCHECK_GT(GetDataSize(), 0U); |
[email protected] | e195fbf5 | 2011-06-27 16:51:20 | [diff] [blame] | 253 | if (data_->pdf_cg_.GetDataSize() == 0) { |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 254 | if (GetDataSize() == 0) |
| 255 | return false; |
| 256 | size_t length = data_->pdf_data_->getLength(); |
| 257 | std::vector<uint8_t> buffer(length); |
| 258 | (void)WriteAssetToBuffer(data_->pdf_data_.get(), &buffer[0], length); |
thestig | 707a24b2 | 2015-09-14 18:16:33 | [diff] [blame] | 259 | data_->pdf_cg_.InitFromData(&buffer[0], |
| 260 | base::checked_cast<uint32_t>(length)); |
[email protected] | e195fbf5 | 2011-06-27 16:51:20 | [diff] [blame] | 261 | } |
[email protected] | b5cf844c | 2012-06-18 21:49:20 | [diff] [blame] | 262 | return data_->pdf_cg_.RenderPage(page_number, context, rect, params); |
[email protected] | b8d85bc | 2011-06-22 13:34:57 | [diff] [blame] | 263 | } |
| 264 | #endif |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 265 | |
halcanary | 5be808e | 2014-11-10 22:20:05 | [diff] [blame] | 266 | bool PdfMetafileSkia::SaveTo(base::File* file) const { |
| 267 | if (GetDataSize() == 0U) |
| 268 | return false; |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 269 | |
| 270 | // Calling duplicate() keeps original asset state unchanged. |
dcheng | c3df9ba | 2016-04-07 23:09:32 | [diff] [blame] | 271 | std::unique_ptr<SkStreamAsset> asset(data_->pdf_data_->duplicate()); |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 272 | |
thestig | 192677ec | 2016-06-09 07:43:17 | [diff] [blame^] | 273 | const size_t kMaximumBufferSize = 1024 * 1024; |
| 274 | std::vector<char> buffer(std::min(kMaximumBufferSize, asset->getLength())); |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 275 | do { |
| 276 | size_t read_size = asset->read(&buffer[0], buffer.size()); |
| 277 | if (read_size == 0) |
| 278 | break; |
| 279 | DCHECK_GE(buffer.size(), read_size); |
| 280 | if (!file->WriteAtCurrentPos(&buffer[0], |
| 281 | base::checked_cast<int>(read_size))) { |
| 282 | return false; |
| 283 | } |
| 284 | } while (!asset->isAtEnd()); |
| 285 | |
| 286 | return true; |
halcanary | 5be808e | 2014-11-10 22:20:05 | [diff] [blame] | 287 | } |
| 288 | |
halcanary | 5be808e | 2014-11-10 22:20:05 | [diff] [blame] | 289 | PdfMetafileSkia::PdfMetafileSkia() : data_(new PdfMetafileSkiaData) { |
[email protected] | 19b9d3b | 2011-07-23 02:08:57 | [diff] [blame] | 290 | } |
[email protected] | 59751637 | 2011-07-01 05:10:44 | [diff] [blame] | 291 | |
dcheng | c3df9ba | 2016-04-07 23:09:32 | [diff] [blame] | 292 | std::unique_ptr<PdfMetafileSkia> PdfMetafileSkia::GetMetafileForCurrentPage() { |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 293 | // If we only ever need the metafile for the last page, should we |
| 294 | // only keep a handle on one SkPicture? |
dcheng | c3df9ba | 2016-04-07 23:09:32 | [diff] [blame] | 295 | std::unique_ptr<PdfMetafileSkia> metafile(new PdfMetafileSkia); |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 296 | |
| 297 | if (data_->pages_.size() == 0) |
dcheng | e4860045 | 2015-12-28 02:24:50 | [diff] [blame] | 298 | return metafile; |
[email protected] | 59751637 | 2011-07-01 05:10:44 | [diff] [blame] | 299 | |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 300 | if (data_->recorder_.getRecordingCanvas()) // page outstanding |
dcheng | e4860045 | 2015-12-28 02:24:50 | [diff] [blame] | 301 | return metafile; |
[email protected] | 59751637 | 2011-07-01 05:10:44 | [diff] [blame] | 302 | |
halcanary | 223f70a | 2016-06-09 00:07:42 | [diff] [blame] | 303 | metafile->data_->pages_.push_back(data_->pages_.back()); |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 304 | |
| 305 | if (!metafile->FinishDocument()) // Generate PDF. |
vitalybuka | 5d129058 | 2014-09-12 09:19:59 | [diff] [blame] | 306 | metafile.reset(); |
halcanary | ff21476 | 2015-01-22 20:34:32 | [diff] [blame] | 307 | |
dcheng | e4860045 | 2015-12-28 02:24:50 | [diff] [blame] | 308 | return metafile; |
[email protected] | 59751637 | 2011-07-01 05:10:44 | [diff] [blame] | 309 | } |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 310 | |
[email protected] | 8f87929 | 2011-04-08 00:21:20 | [diff] [blame] | 311 | } // namespace printing |