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_cg_mac.h" | 5 #include "printing/pdf_metafile_cg_mac.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 if (scaling_needed) { | 195 if (scaling_needed) { |
196 float x_scaling_factor = rect.size.width / source_rect.size.width; | 196 float x_scaling_factor = rect.size.width / source_rect.size.width; |
197 float y_scaling_factor = rect.size.height / source_rect.size.height; | 197 float y_scaling_factor = rect.size.height / source_rect.size.height; |
198 if (x_scaling_factor > y_scaling_factor) { | 198 if (x_scaling_factor > y_scaling_factor) { |
199 scaling_factor = y_scaling_factor; | 199 scaling_factor = y_scaling_factor; |
200 } else { | 200 } else { |
201 scaling_factor = x_scaling_factor; | 201 scaling_factor = x_scaling_factor; |
202 } | 202 } |
203 } | 203 } |
204 // Some PDFs have a non-zero origin. Need to take that into account. | 204 // Some PDFs have a non-zero origin. Need to take that into account. |
205 float x_offset = rect.origin.x - (source_rect.origin.x * scaling_factor); | 205 float x_offset = -1 * source_rect.origin.x * scaling_factor; |
206 float y_offset = rect.origin.y - (source_rect.origin.y * scaling_factor); | 206 float y_offset = -1 * source_rect.origin.y * scaling_factor; |
207 | 207 |
208 if (center_vertically) { | 208 if (center_horizontally) { |
209 x_offset += (rect.size.width - | 209 x_offset += (rect.size.width - |
210 (source_rect.size.width * scaling_factor))/2; | 210 (source_rect.size.width * scaling_factor))/2; |
211 } | 211 } |
212 if (center_horizontally) { | 212 if (center_vertically) { |
213 y_offset += (rect.size.height - | 213 y_offset += (rect.size.height - |
214 (source_rect.size.height * scaling_factor))/2; | 214 (source_rect.size.height * scaling_factor))/2; |
215 } else { | |
216 // Since 0 y begins at the bottom, we need to adjust so the output appears | |
217 // nearer the top if we are not centering horizontally. | |
218 y_offset += rect.size.height - (source_rect.size.height * scaling_factor); | |
219 } | 215 } |
220 CGContextSaveGState(context); | 216 CGContextSaveGState(context); |
221 CGContextTranslateCTM(context, x_offset, y_offset); | 217 CGContextTranslateCTM(context, x_offset, y_offset); |
222 CGContextScaleCTM(context, scaling_factor, scaling_factor); | 218 CGContextScaleCTM(context, scaling_factor, scaling_factor); |
223 CGContextDrawPDFPage(context, pdf_page); | 219 CGContextDrawPDFPage(context, pdf_page); |
224 CGContextRestoreGState(context); | 220 CGContextRestoreGState(context); |
225 return true; | 221 return true; |
226 } | 222 } |
227 | 223 |
228 unsigned int PdfMetafileCg::GetPageCount() const { | 224 unsigned int PdfMetafileCg::GetPageCount() const { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 291 |
296 if (!pdf_doc_.get()) { | 292 if (!pdf_doc_.get()) { |
297 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( | 293 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( |
298 CGDataProviderCreateWithCFData(pdf_data_)); | 294 CGDataProviderCreateWithCFData(pdf_data_)); |
299 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); | 295 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); |
300 } | 296 } |
301 return pdf_doc_.get(); | 297 return pdf_doc_.get(); |
302 } | 298 } |
303 | 299 |
304 } // namespace printing | 300 } // namespace printing |
OLD | NEW |