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.
5 #ifndef PDF_PDF_TRANSFORM_H_
6 #define PDF_PDF_TRANSFORM_H_
12 namespace chrome_pdf {
14 // A rect struct for use with FPDF bounding box functions.
15 // With PDFs, origin is bottom-left.
23 // Calculate the scale factor between |content_rect| and a page of size
24 // |src_width| x |src_height|.
26 // |content_rect| specifies the printable area of the destination page, with
27 // origin at left-bottom. Values are in points.
28 // |src_width| specifies the source page width in points.
29 // |src_height| specifies the source page height in points.
30 // |rotated| True if source page is rotated 90 degree or 270 degree.
31 double CalculateScaleFactor(const gfx::Rect& content_rect,
36 // Make the default size to be letter size (8.5" X 11"). We are just following
37 // the PDFium way of handling these corner cases. PDFium always consider
38 // US-Letter as the default page size.
39 void SetDefaultClipBox(bool rotated, PdfRectangle* clip_box);
41 // Set the media box and/or crop box as needed. If both boxes are there, then
42 // nothing needs to be done. If one box is missing, then fill it with the value
43 // from the other box. If both boxes are missing, then they both get the default
44 // value from SetDefaultClipBox(), based on |rotated|.
45 void CalculateMediaBoxAndCropBox(bool rotated,
48 PdfRectangle* media_box,
49 PdfRectangle* crop_box);
51 // Compute source clip box boundaries based on the crop box / media box of
52 // source page and scale factor.
53 // Returns the computed source clip box values.
55 // |media_box| The PDF's media box.
56 // |crop_box| The PDF's crop box.
57 PdfRectangle CalculateClipBoxBoundary(const PdfRectangle& media_box,
58 const PdfRectangle& crop_box);
60 // Scale |box| by |scale_factor|.
61 void ScalePdfRectangle(double scale_factor, PdfRectangle* rect);
63 // Calculate the clip box translation offset for a page that does need to be
64 // scaled. All parameters are in points.
66 // |content_rect| specifies the printable area of the destination page, with
67 // origin at left-bottom.
68 // |source_clip_box| specifies the source clip box positions, relative to
69 // origin at left-bottom.
70 // |offset_x| and |offset_y| will contain the final translation offsets for the
71 // source clip box, relative to origin at left-bottom.
72 void CalculateScaledClipBoxOffset(const gfx::Rect& content_rect,
73 const PdfRectangle& source_clip_box,
77 // Calculate the clip box offset for a page that does not need to be scaled.
78 // All parameters are in points.
80 // |content_rect| specifies the printable area of the destination page, with
81 // origin at left-bottom.
82 // |rotation| specifies the source page rotation values which are N / 90
84 // |page_width| specifies the screen destination page width.
85 // |page_height| specifies the screen destination page height.
86 // |source_clip_box| specifies the source clip box positions, relative to origin
88 // |offset_x| and |offset_y| will contain the final translation offsets for the
89 // source clip box, relative to origin at left-bottom.
90 void CalculateNonScaledClipBoxOffset(const gfx::Rect& content_rect,
94 const PdfRectangle& source_clip_box,
98 } // namespace chrome_pdf
100 #endif // PDF_PDF_TRANSFORM_H_