File: pdf_transform.h

package info (click to toggle)
chromium 145.0.7632.159-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,976,224 kB
  • sloc: cpp: 36,198,469; ansic: 7,634,080; javascript: 3,564,060; python: 1,649,622; xml: 838,470; asm: 717,087; pascal: 185,708; sh: 88,786; perl: 88,718; objc: 79,984; sql: 59,811; cs: 42,452; fortran: 24,101; makefile: 21,144; tcl: 15,277; php: 14,022; yacc: 9,066; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,328; ada: 727; jsp: 228; sed: 36
file content (94 lines) | stat: -rw-r--r-- 3,918 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PDF_PDF_TRANSFORM_H_
#define PDF_PDF_TRANSFORM_H_

#include "pdf/pdf_rect.h"
#include "ui/gfx/geometry/vector2d_f.h"

namespace gfx {
class Rect;
class SizeF;
}  // namespace gfx

namespace chrome_pdf {

// All the code here works in the PDF coordinate space. The origin is at the
// bottom-left, and all units are in points.

// Calculate the scale factor between `content_rect` and a page of `src_size`.
//
// `content_rect` specifies the printable area of the destination page.
// `src_size` specifies the source page size.
// `rotated` True if source page is rotated 90 degree or 270 degree.
float CalculateScaleFactor(const gfx::Rect& content_rect,
                           const gfx::SizeF& src_size,
                           bool rotated);

// Set the media box and/or crop box as needed. If both boxes are there, then
// nothing needs to be done. If one box is missing, then fill it with the value
// from the other box. If both boxes are missing, then they both get the default
// value from GetDefaultClipBox(), based on `rotated`.
void CalculateMediaBoxAndCropBox(bool rotated,
                                 bool has_media_box,
                                 bool has_crop_box,
                                 PdfRect* media_box,
                                 PdfRect* crop_box);

// Compute source clip box boundaries based on the crop box / media box of
// source page and scale factor.
// Returns the computed source clip box values.
//
// `media_box` The PDF's media box.
// `crop_box` The PDF's crop box.
PdfRect CalculateClipBoxBoundary(const PdfRect& media_box,
                                 const PdfRect& crop_box);

// Calculate the clip box translation offset for a page that does need to be
// scaled.
//
// `content_rect` specifies the printable area of the destination page.
// `source_clip_box` specifies the source clip box positions, relative to the
// origin.
// Returns the final translation offsets for the source clip box, relative to
// the origin.
gfx::Vector2dF CalculateScaledClipBoxOffset(const gfx::Rect& content_rect,
                                            const PdfRect& source_clip_box);

// Calculate the clip box offset for a page that needs to be centered, but not
// scaled, and the page size is bigger than the source clip box size.
//
// `rotation` specifies the source page rotation values which are N / 90
// degrees.
// `page_width` specifies the screen destination page width.
// `page_height` specifies the screen destination page height.
// `source_clip_box` specifies the source clip box positions, relative to the
// origin.
// Returns the final translation offsets for the source clip box, relative to
// the origin.
gfx::Vector2dF CalculateCenterClipBoxOffset(int rotation,
                                            int page_width,
                                            int page_height,
                                            const PdfRect& source_clip_box);

// Calculate the clip box offset for a page that does not need to be scaled or
// centered.
//
// `rotation` specifies the source page rotation values which are N / 90
// degrees.
// `page_width` specifies the screen destination page width.
// `page_height` specifies the screen destination page height.
// `source_clip_box` specifies the source clip box positions, relative to the
// origin.
// Returns the final translation offsets for the source clip box, relative to
// the origin.
gfx::Vector2dF CalculateNonScaledClipBoxOffset(int rotation,
                                               int page_width,
                                               int page_height,
                                               const PdfRect& source_clip_box);

}  // namespace chrome_pdf

#endif  // PDF_PDF_TRANSFORM_H_