OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef PRINTING_PDF_TRANSFORM_H_ | 5 #ifndef PRINTING_PDF_TRANSFORM_H_ |
6 #define PRINTING_PDF_TRANSFORM_H_ | 6 #define PRINTING_PDF_TRANSFORM_H_ |
7 | 7 |
8 #include "printing/printing_export.h" | 8 #include "printing/printing_export.h" |
9 | 9 |
10 namespace gfx { | 10 namespace gfx { |
11 class Rect; | 11 class Rect; |
12 } | 12 } |
13 | 13 |
14 namespace printing { | 14 namespace printing { |
15 | 15 |
16 // A rect struct for use with FPDF bounding box functions. | 16 // A rect struct for use with FPDF bounding box functions. |
17 // With PDFs, origin is bottom-left. | 17 // With PDFs, origin is bottom-left. |
18 struct PRINTING_EXPORT ClipBox { | 18 struct PRINTING_EXPORT PdfRectangle { |
19 float left; | 19 float left; |
20 float bottom; | |
20 float right; | 21 float right; |
21 float top; | 22 float top; |
22 float bottom; | |
23 }; | 23 }; |
24 | 24 |
25 // Calculate the scale factor between |content_rect| and a page of size | 25 // Calculate the scale factor between |content_rect| and a page of size |
26 // |src_width| x |src_height|. | 26 // |src_width| x |src_height|. |
27 // | 27 // |
28 // |content_rect| specifies the printable area of the destination page, with | 28 // |content_rect| specifies the printable area of the destination page, with |
29 // origin at left-bottom. Values are in points. | 29 // origin at left-bottom. Values are in points. |
30 // |src_width| specifies the source page width in points. | 30 // |src_width| specifies the source page width in points. |
31 // |src_height| specifies the source page height in points. | 31 // |src_height| specifies the source page height in points. |
32 // |rotated| True if source page is rotated 90 degree or 270 degree. | 32 // |rotated| True if source page is rotated 90 degree or 270 degree. |
33 PRINTING_EXPORT double CalculateScaleFactor(const gfx::Rect& content_rect, | 33 PRINTING_EXPORT double CalculateScaleFactor(const gfx::Rect& content_rect, |
34 double src_width, | 34 double src_width, |
35 double src_height, | 35 double src_height, |
36 bool rotated); | 36 bool rotated); |
37 | 37 |
38 // Make the default size to be letter size (8.5" X 11"). We are just following | 38 // Make the default size to be letter size (8.5" X 11"). We are just following |
39 // the PDFium way of handling these corner cases. PDFium always consider | 39 // the PDFium way of handling these corner cases. PDFium always consider |
40 // US-Letter as the default page size. | 40 // US-Letter as the default page size. |
41 PRINTING_EXPORT void SetDefaultClipBox(bool rotated, ClipBox* clip_box); | 41 PRINTING_EXPORT void SetDefaultClipBox(bool rotated, PdfRectangle* clip_box); |
42 | 42 |
43 // Set the media box and/or crop box as needed. If both boxes are there, then | 43 // Set the media box and/or crop box as needed. If both boxes are there, then |
44 // nothing needs to be done. If one box is missing, then fill it with the value | 44 // nothing needs to be done. If one box is missing, then fill it with the value |
45 // from the other box. If both boxes are missing, then they both get the default | 45 // from the other box. If both boxes are missing, then they both get the default |
46 // value from SetDefaultClipBox(), based on |rotated|. | 46 // value from SetDefaultClipBox(), based on |rotated|. |
47 PRINTING_EXPORT void CalculateMediaBoxAndCropBox(bool rotated, | 47 PRINTING_EXPORT void CalculateMediaBoxAndCropBox(bool rotated, |
48 bool has_media_box, | 48 bool has_media_box, |
49 bool has_crop_box, | 49 bool has_crop_box, |
50 printing::ClipBox* media_box, | 50 PdfRectangle* media_box, |
51 printing::ClipBox* crop_box); | 51 PdfRectangle* crop_box); |
52 | 52 |
53 // Compute source clip box boundaries based on the crop box / media box of | 53 // Compute source clip box boundaries based on the crop box / media box of |
54 // source page and scale factor. | 54 // source page and scale factor. |
55 // Returns the computed source clip box values. | 55 // Returns the computed source clip box values. |
56 // | 56 // |
57 // |media_box| The PDF's media box. | 57 // |media_box| The PDF's media box. |
58 // |crop_box| The PDF's crop box. | 58 // |crop_box| The PDF's crop box. |
59 PRINTING_EXPORT ClipBox CalculateClipBoxBoundary(const ClipBox& media_box, | 59 PRINTING_EXPORT PdfRectangle CalculateClipBoxBoundary( |
60 const ClipBox& crop_box); | 60 const PdfRectangle& media_box, |
61 const PdfRectangle& crop_box); | |
61 | 62 |
62 // Scale |box| by |scale_factor|. | 63 // Scale |box| by |scale_factor|. |
63 PRINTING_EXPORT void ScaleClipBox(double scale_factor, ClipBox* box); | 64 PRINTING_EXPORT void ScalePdfRectangle(double scale_factor, PdfRectangle* rect); |
raymes
2016/04/12 22:27:10
How come you changed the name of this function but
Lei Zhang
2016/04/13 01:00:17
This felt generic enough to apply to any PdfRectan
| |
64 | 65 |
65 // Calculate the clip box translation offset for a page that does need to be | 66 // Calculate the clip box translation offset for a page that does need to be |
66 // scaled. All parameters are in points. | 67 // scaled. All parameters are in points. |
67 // | 68 // |
68 // |content_rect| specifies the printable area of the destination page, with | 69 // |content_rect| specifies the printable area of the destination page, with |
69 // origin at left-bottom. | 70 // origin at left-bottom. |
70 // |source_clip_box| specifies the source clip box positions, relative to | 71 // |source_clip_box| specifies the source clip box positions, relative to |
71 // origin at left-bottom. | 72 // origin at left-bottom. |
72 // |offset_x| and |offset_y| will contain the final translation offsets for the | 73 // |offset_x| and |offset_y| will contain the final translation offsets for the |
73 // source clip box, relative to origin at left-bottom. | 74 // source clip box, relative to origin at left-bottom. |
74 PRINTING_EXPORT void CalculateScaledClipBoxOffset( | 75 PRINTING_EXPORT void CalculateScaledClipBoxOffset( |
75 const gfx::Rect& content_rect, | 76 const gfx::Rect& content_rect, |
76 const ClipBox& source_clip_box, | 77 const PdfRectangle& source_clip_box, |
77 double* offset_x, | 78 double* offset_x, |
78 double* offset_y); | 79 double* offset_y); |
79 | 80 |
80 // Calculate the clip box offset for a page that does not need to be scaled. | 81 // Calculate the clip box offset for a page that does not need to be scaled. |
81 // All parameters are in points. | 82 // All parameters are in points. |
82 // | 83 // |
83 // |content_rect| specifies the printable area of the destination page, with | 84 // |content_rect| specifies the printable area of the destination page, with |
84 // origin at left-bottom. | 85 // origin at left-bottom. |
85 // |rotation| specifies the source page rotation values which are N / 90 | 86 // |rotation| specifies the source page rotation values which are N / 90 |
86 // degrees. | 87 // degrees. |
87 // |page_width| specifies the screen destination page width. | 88 // |page_width| specifies the screen destination page width. |
88 // |page_height| specifies the screen destination page height. | 89 // |page_height| specifies the screen destination page height. |
89 // |source_clip_box| specifies the source clip box positions, relative to origin | 90 // |source_clip_box| specifies the source clip box positions, relative to origin |
90 // at left-bottom. | 91 // at left-bottom. |
91 // |offset_x| and |offset_y| will contain the final translation offsets for the | 92 // |offset_x| and |offset_y| will contain the final translation offsets for the |
92 // source clip box, relative to origin at left-bottom. | 93 // source clip box, relative to origin at left-bottom. |
93 PRINTING_EXPORT void CalculateNonScaledClipBoxOffset( | 94 PRINTING_EXPORT void CalculateNonScaledClipBoxOffset( |
94 const gfx::Rect& content_rect, | 95 const gfx::Rect& content_rect, |
95 int rotation, | 96 int rotation, |
96 int page_width, | 97 int page_width, |
97 int page_height, | 98 int page_height, |
98 const ClipBox& source_clip_box, | 99 const PdfRectangle& source_clip_box, |
99 double* offset_x, | 100 double* offset_x, |
100 double* offset_y); | 101 double* offset_y); |
101 | 102 |
102 } // namespace printing | 103 } // namespace printing |
103 | 104 |
104 #endif // PRINTING_PDF_TRANSFORM_H_ | 105 #endif // PRINTING_PDF_TRANSFORM_H_ |
OLD | NEW |