pdf_transform.h 3.5 KB

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