fixup! [M120 Migration][NaCl][PPFWK] Upgradable pepper plugin requirement
[platform/framework/web/chromium-efl.git] / pdf / pdf_transform.h
1 // Copyright 2015 The Chromium Authors
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 PointF;
10 class Rect;
11 class SizeF;
12 }  // namespace gfx
13
14 namespace chrome_pdf {
15
16 // A rect struct for use with FPDF bounding box functions.
17 // With PDFs, origin is bottom-left.
18 struct PdfRectangle {
19   float left;
20   float bottom;
21   float right;
22   float top;
23 };
24
25 // Calculate the scale factor between `content_rect` and a page of `src_size`.
26 //
27 // `content_rect` specifies the printable area of the destination page, with
28 // origin at left-bottom. Values are in points.
29 // `src_size` specifies the source page size in points.
30 // `rotated` True if source page is rotated 90 degree or 270 degree.
31 float CalculateScaleFactor(const gfx::Rect& content_rect,
32                            const gfx::SizeF& src_size,
33                            bool rotated);
34
35 // Make the default size to be letter size (8.5" X 11"). We are just following
36 // the PDFium way of handling these corner cases. PDFium always consider
37 // US-Letter as the default page size.
38 void SetDefaultClipBox(bool rotated, PdfRectangle* clip_box);
39
40 // Set the media box and/or crop box as needed. If both boxes are there, then
41 // nothing needs to be done. If one box is missing, then fill it with the value
42 // from the other box. If both boxes are missing, then they both get the default
43 // value from SetDefaultClipBox(), based on `rotated`.
44 void CalculateMediaBoxAndCropBox(bool rotated,
45                                  bool has_media_box,
46                                  bool has_crop_box,
47                                  PdfRectangle* media_box,
48                                  PdfRectangle* crop_box);
49
50 // Compute source clip box boundaries based on the crop box / media box of
51 // source page and scale factor.
52 // Returns the computed source clip box values.
53 //
54 // `media_box` The PDF's media box.
55 // `crop_box` The PDF's crop box.
56 PdfRectangle CalculateClipBoxBoundary(const PdfRectangle& media_box,
57                                       const PdfRectangle& crop_box);
58
59 // Scale `rect` by `scale_factor`.
60 void ScalePdfRectangle(float scale_factor, PdfRectangle* rect);
61
62 // Calculate the clip box translation offset for a page that does need to be
63 // scaled. All parameters are in points.
64 //
65 // `content_rect` specifies the printable area of the destination page, with
66 // origin at left-bottom.
67 // `source_clip_box` specifies the source clip box positions, relative to
68 // origin at left-bottom.
69 // Returns the final translation offsets for the source clip box, relative to
70 // origin at left-bottom.
71 gfx::PointF CalculateScaledClipBoxOffset(const gfx::Rect& content_rect,
72                                          const PdfRectangle& source_clip_box_);
73
74 // Calculate the clip box offset for a page that does not need to be scaled.
75 // All parameters are in points.
76 //
77 // `rotation` specifies the source page rotation values which are N / 90
78 // degrees.
79 // `page_width` specifies the screen destination page width.
80 // `page_height` specifies the screen destination page height.
81 // `source_clip_box` specifies the source clip box positions, relative to origin
82 // at left-bottom.
83 // Returns the final translation offsets for the source clip box, relative to
84 // origin at left-bottom.
85 gfx::PointF CalculateNonScaledClipBoxOffset(
86     int rotation,
87     int page_width,
88     int page_height,
89     const PdfRectangle& source_clip_box);
90
91 }  // namespace chrome_pdf
92
93 #endif  // PDF_PDF_TRANSFORM_H_