| 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_metafile_cairo_linux.h" | 5 #include "printing/pdf_metafile_cairo_linux.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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 if (src_buffer == NULL || src_buffer_size == 0) | 112 if (src_buffer == NULL || src_buffer_size == 0) |
| 113 return false; | 113 return false; |
| 114 | 114 |
| 115 raw_data_ = std::string(reinterpret_cast<const char*>(src_buffer), | 115 raw_data_ = std::string(reinterpret_cast<const char*>(src_buffer), |
| 116 src_buffer_size); | 116 src_buffer_size); |
| 117 current_data_ = &raw_data_; | 117 current_data_ = &raw_data_; |
| 118 return true; | 118 return true; |
| 119 } | 119 } |
| 120 | 120 |
| 121 skia::PlatformDevice* PdfMetafileCairo::StartPageForVectorCanvas( | 121 skia::PlatformDevice* PdfMetafileCairo::StartPageForVectorCanvas( |
| 122 const gfx::Size& page_size, const gfx::Point& content_origin, | 122 const gfx::Size& page_size, const gfx::Rect& content_area, |
| 123 const float& scale_factor) { | 123 const float& scale_factor) { |
| 124 if (!StartPage(page_size, content_origin, scale_factor)) | 124 if (!StartPage(page_size, content_area, scale_factor)) |
| 125 return NULL; | 125 return NULL; |
| 126 | 126 |
| 127 return skia::VectorPlatformDeviceCairoFactory::CreateDevice( | 127 return skia::VectorPlatformDeviceCairoFactory::CreateDevice( |
| 128 context_, page_size.width(), page_size.height(), true); | 128 context_, page_size.width(), page_size.height(), true); |
| 129 } | 129 } |
| 130 | 130 |
| 131 bool PdfMetafileCairo::StartPage(const gfx::Size& page_size, | 131 bool PdfMetafileCairo::StartPage(const gfx::Size& page_size, |
| 132 const gfx::Point& content_origin, | 132 const gfx::Rect& content_area, |
| 133 const float& scale_factor) { | 133 const float& scale_factor) { |
| 134 DCHECK(IsSurfaceValid(surface_)); | 134 DCHECK(IsSurfaceValid(surface_)); |
| 135 DCHECK(IsContextValid(context_)); | 135 DCHECK(IsContextValid(context_)); |
| 136 // Passing this check implies page_surface_ is NULL, and current_page_ is | 136 // Passing this check implies page_surface_ is NULL, and current_page_ is |
| 137 // empty. | 137 // empty. |
| 138 DCHECK_GT(page_size.width(), 0); | 138 DCHECK_GT(page_size.width(), 0); |
| 139 DCHECK_GT(page_size.height(), 0); | 139 DCHECK_GT(page_size.height(), 0); |
| 140 // |scale_factor| is not supported yet. | 140 // |scale_factor| is not supported yet. |
| 141 DCHECK_EQ(scale_factor, 1); | 141 DCHECK_EQ(scale_factor, 1); |
| 142 | 142 |
| 143 // Don't let WebKit draw over the margins. | 143 // Don't let WebKit draw over the margins. |
| 144 cairo_surface_set_device_offset(surface_, | 144 cairo_surface_set_device_offset(surface_, |
| 145 content_origin.x(), | 145 content_area.x(), |
| 146 content_origin.y()); | 146 content_area.y()); |
| 147 | 147 |
| 148 cairo_pdf_surface_set_size(surface_, page_size.width(), page_size.height()); | 148 cairo_pdf_surface_set_size(surface_, page_size.width(), page_size.height()); |
| 149 return context_ != NULL; | 149 return context_ != NULL; |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool PdfMetafileCairo::FinishPage() { | 152 bool PdfMetafileCairo::FinishPage() { |
| 153 DCHECK(IsSurfaceValid(surface_)); | 153 DCHECK(IsSurfaceValid(surface_)); |
| 154 DCHECK(IsContextValid(context_)); | 154 DCHECK(IsContextValid(context_)); |
| 155 | 155 |
| 156 // Flushes all rendering for current page. | 156 // Flushes all rendering for current page. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 250 |
| 251 void PdfMetafileCairo::CleanUpAll() { | 251 void PdfMetafileCairo::CleanUpAll() { |
| 252 CleanUpContext(&context_); | 252 CleanUpContext(&context_); |
| 253 CleanUpSurface(&surface_); | 253 CleanUpSurface(&surface_); |
| 254 cairo_data_.clear(); | 254 cairo_data_.clear(); |
| 255 raw_data_.clear(); | 255 raw_data_.clear(); |
| 256 skia::VectorPlatformDeviceCairo::ClearFontCache(); | 256 skia::VectorPlatformDeviceCairo::ClearFontCache(); |
| 257 } | 257 } |
| 258 | 258 |
| 259 } // namespace printing | 259 } // namespace printing |
| OLD | NEW |