Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 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_transform.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "ui/gfx/geometry/rect.h" | |
| 11 | |
| 12 namespace printing { | |
| 13 | |
| 14 double CalculateScaleFactor(const gfx::Rect& content_rect, | |
| 15 double src_width, | |
| 16 double src_height, | |
| 17 bool rotated) { | |
| 18 if (src_width == 0 || src_height == 0) | |
|
raymes
2015/10/26 04:04:48
I noticed you pulled out the first parameter of th
Lei Zhang
2015/10/26 04:39:26
Most of the changes are just refactorings. I'll co
| |
| 19 return 1.0; | |
| 20 | |
| 21 double actual_source_page_width = rotated ? src_height : src_width; | |
| 22 double actual_source_page_height = rotated ? src_width : src_height; | |
| 23 double ratio_x = static_cast<double>(content_rect.width()) / | |
| 24 actual_source_page_width; | |
| 25 double ratio_y = static_cast<double>(content_rect.height()) / | |
| 26 actual_source_page_height; | |
| 27 return std::min(ratio_x, ratio_y); | |
| 28 } | |
| 29 | |
| 30 void SetDefaultClipBox(bool rotated, ClipBox* clip_box) { | |
| 31 const int kDpi = 72; | |
| 32 const float kPaperWidth = 8.5 * kDpi; | |
| 33 const float kPaperHeight = 11 * kDpi; | |
| 34 clip_box->left = 0; | |
| 35 clip_box->bottom = 0; | |
| 36 clip_box->right = rotated ? kPaperHeight : kPaperWidth; | |
| 37 clip_box->top = rotated ? kPaperWidth : kPaperHeight; | |
| 38 } | |
| 39 | |
| 40 ClipBox CalculateClipBoxBoundary(const ClipBox& media_box, | |
| 41 const ClipBox& crop_box, | |
| 42 double scale_factor, | |
| 43 bool rotated) { | |
| 44 ClipBox clip_box; | |
| 45 | |
| 46 // Clip |media_box| to the size of |crop_box|, but ignore |crop_box| if it is | |
| 47 // bigger than |media_box|. | |
| 48 clip_box.left = | |
| 49 (crop_box.left < media_box.left) ? media_box.left : crop_box.left; | |
| 50 clip_box.right = | |
| 51 (crop_box.right > media_box.right) ? media_box.right : crop_box.right; | |
| 52 clip_box.top = (crop_box.top > media_box.top) ? media_box.top : crop_box.top; | |
| 53 clip_box.bottom = | |
| 54 (crop_box.bottom < media_box.bottom) ? media_box.bottom : crop_box.bottom; | |
| 55 | |
| 56 // Finally, scale |clip_box|. | |
| 57 clip_box.left *= scale_factor; | |
| 58 clip_box.right *= scale_factor; | |
| 59 clip_box.bottom *= scale_factor; | |
| 60 clip_box.top *= scale_factor; | |
| 61 return clip_box; | |
| 62 } | |
| 63 | |
| 64 void CalculateScaledClipBoxOffset(const gfx::Rect& content_rect, | |
| 65 const ClipBox& source_clip_box, | |
| 66 double* offset_x, | |
| 67 double* offset_y) { | |
| 68 const float clip_box_width = source_clip_box.right - source_clip_box.left; | |
| 69 const float clip_box_height = source_clip_box.top - source_clip_box.bottom; | |
| 70 | |
| 71 // Center the intended clip region to real clip region. | |
| 72 *offset_x = (content_rect.width() - clip_box_width) / 2 + content_rect.x() - | |
| 73 source_clip_box.left; | |
| 74 *offset_y = (content_rect.height() - clip_box_height) / 2 + content_rect.y() - | |
| 75 source_clip_box.bottom; | |
| 76 } | |
| 77 | |
| 78 void CalculateNonScaledClipBoxOffset(const gfx::Rect& content_rect, | |
| 79 int rotation, | |
| 80 int page_width, | |
| 81 int page_height, | |
| 82 const ClipBox& source_clip_box, | |
| 83 double* offset_x, | |
| 84 double* offset_y) { | |
| 85 // Align the intended clip region to left-top corner of real clip region. | |
| 86 switch (rotation) { | |
| 87 case 0: | |
| 88 *offset_x = -1 * source_clip_box.left; | |
| 89 *offset_y = page_height - source_clip_box.top; | |
| 90 break; | |
| 91 case 1: | |
| 92 *offset_x = 0; | |
| 93 *offset_y = -1 * source_clip_box.bottom; | |
| 94 break; | |
| 95 case 2: | |
| 96 *offset_x = page_width - source_clip_box.right; | |
| 97 *offset_y = 0; | |
| 98 break; | |
| 99 case 3: | |
| 100 *offset_x = page_height - source_clip_box.right; | |
| 101 *offset_y = page_width - source_clip_box.top; | |
| 102 break; | |
| 103 default: | |
| 104 NOTREACHED(); | |
| 105 break; | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 } // namespace printing | |
| OLD | NEW |