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, | |
|
Lei Zhang
2015/10/26 04:39:26
This has been simplified by removing |scale_to_fit
| |
| 15 double src_width, | |
| 16 double src_height, | |
| 17 bool rotated) { | |
| 18 if (src_width == 0 || src_height == 0) | |
| 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 void CalculateMediaBoxAndCropBox(bool rotated, | |
|
Lei Zhang
2015/10/26 04:39:26
This is new. It's split off from CalculateClipBoxB
| |
| 41 bool has_media_box, | |
| 42 bool has_crop_box, | |
| 43 printing::ClipBox* media_box, | |
| 44 printing::ClipBox* crop_box) { | |
| 45 if (has_media_box) { | |
| 46 if (!has_crop_box) | |
| 47 *crop_box = *media_box; | |
| 48 return; | |
| 49 } | |
| 50 | |
| 51 if (!has_crop_box) | |
| 52 SetDefaultClipBox(rotated, crop_box); | |
| 53 *media_box = *crop_box; | |
| 54 } | |
| 55 | |
| 56 ClipBox CalculateClipBoxBoundary(const ClipBox& media_box, | |
|
Lei Zhang
2015/10/26 04:39:26
This has been simplified. The rest of the function
| |
| 57 const ClipBox& crop_box) { | |
| 58 ClipBox clip_box; | |
| 59 | |
| 60 // Clip |media_box| to the size of |crop_box|, but ignore |crop_box| if it is | |
| 61 // bigger than |media_box|. | |
| 62 clip_box.left = | |
| 63 (crop_box.left < media_box.left) ? media_box.left : crop_box.left; | |
| 64 clip_box.right = | |
| 65 (crop_box.right > media_box.right) ? media_box.right : crop_box.right; | |
| 66 clip_box.top = (crop_box.top > media_box.top) ? media_box.top : crop_box.top; | |
| 67 clip_box.bottom = | |
| 68 (crop_box.bottom < media_box.bottom) ? media_box.bottom : crop_box.bottom; | |
| 69 return clip_box; | |
| 70 } | |
| 71 | |
| 72 void ScaleClipBox(double scale_factor, ClipBox* box) { | |
|
Lei Zhang
2015/10/26 04:39:26
Split this out into its own function.
| |
| 73 box->left *= scale_factor; | |
| 74 box->right *= scale_factor; | |
| 75 box->bottom *= scale_factor; | |
| 76 box->top *= scale_factor; | |
| 77 } | |
| 78 | |
| 79 void CalculateScaledClipBoxOffset(const gfx::Rect& content_rect, | |
|
Lei Zhang
2015/10/26 04:39:26
No changes.
| |
| 80 const ClipBox& source_clip_box, | |
| 81 double* offset_x, | |
| 82 double* offset_y) { | |
| 83 const float clip_box_width = source_clip_box.right - source_clip_box.left; | |
| 84 const float clip_box_height = source_clip_box.top - source_clip_box.bottom; | |
| 85 | |
| 86 // Center the intended clip region to real clip region. | |
| 87 *offset_x = (content_rect.width() - clip_box_width) / 2 + content_rect.x() - | |
| 88 source_clip_box.left; | |
| 89 *offset_y = (content_rect.height() - clip_box_height) / 2 + content_rect.y() - | |
| 90 source_clip_box.bottom; | |
| 91 } | |
| 92 | |
| 93 void CalculateNonScaledClipBoxOffset(const gfx::Rect& content_rect, | |
|
Lei Zhang
2015/10/26 04:39:26
No changes here.
| |
| 94 int rotation, | |
| 95 int page_width, | |
| 96 int page_height, | |
| 97 const ClipBox& source_clip_box, | |
| 98 double* offset_x, | |
| 99 double* offset_y) { | |
| 100 // Align the intended clip region to left-top corner of real clip region. | |
| 101 switch (rotation) { | |
| 102 case 0: | |
| 103 *offset_x = -1 * source_clip_box.left; | |
| 104 *offset_y = page_height - source_clip_box.top; | |
| 105 break; | |
| 106 case 1: | |
| 107 *offset_x = 0; | |
| 108 *offset_y = -1 * source_clip_box.bottom; | |
| 109 break; | |
| 110 case 2: | |
| 111 *offset_x = page_width - source_clip_box.right; | |
| 112 *offset_y = 0; | |
| 113 break; | |
| 114 case 3: | |
| 115 *offset_x = page_height - source_clip_box.right; | |
| 116 *offset_y = page_width - source_clip_box.top; | |
| 117 break; | |
| 118 default: | |
| 119 NOTREACHED(); | |
| 120 break; | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 } // namespace printing | |
| OLD | NEW |