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