Upload upstream chromium 76.0.3809.146
[platform/framework/web/chromium-efl.git] / pdf / pdf_transform.h
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 PDF_PDF_TRANSFORM_H_
6 #define PDF_PDF_TRANSFORM_H_
7
8 namespace gfx {
9 class Rect;
10 }
11
12 namespace chrome_pdf {
13
14 // A rect struct for use with FPDF bounding box functions.
15 // With PDFs, origin is bottom-left.
16 struct PdfRectangle {
17   float left;
18   float bottom;
19   float right;
20   float top;
21 };
22
23 // Calculate the scale factor between |content_rect| and a page of size
24 // |src_width| x |src_height|.
25 //
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,
32                             double src_width,
33                             double src_height,
34                             bool rotated);
35
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);
40
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,
46                                  bool has_media_box,
47                                  bool has_crop_box,
48                                  PdfRectangle* media_box,
49                                  PdfRectangle* crop_box);
50
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.
54 //
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);
59
60 // Scale |box| by |scale_factor|.
61 void ScalePdfRectangle(double scale_factor, PdfRectangle* rect);
62
63 // Calculate the clip box translation offset for a page that does need to be
64 // scaled. All parameters are in points.
65 //
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,
74                                   double* offset_x,
75                                   double* offset_y);
76
77 // Calculate the clip box offset for a page that does not need to be scaled.
78 // All parameters are in points.
79 //
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
83 // degrees.
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
87 // at left-bottom.
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,
91                                      int rotation,
92                                      int page_width,
93                                      int page_height,
94                                      const PdfRectangle& source_clip_box,
95                                      double* offset_x,
96                                      double* offset_y);
97
98 }  // namespace chrome_pdf
99
100 #endif  // PDF_PDF_TRANSFORM_H_