printing_utils.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2013 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 PRINTING_PRINTING_UTILS_H_
  5. #define PRINTING_PRINTING_UTILS_H_
  6. #include <stddef.h>
  7. #include <string>
  8. #include "base/component_export.h"
  9. #include "base/containers/span.h"
  10. #include "build/build_config.h"
  11. #include "build/chromeos_buildflags.h"
  12. #if defined(USE_CUPS) && !BUILDFLAG(IS_CHROMEOS_ASH)
  13. #include "base/strings/string_piece.h"
  14. #endif
  15. #if BUILDFLAG(IS_WIN)
  16. #include "ui/gfx/geometry/rect.h"
  17. #endif
  18. namespace gfx {
  19. class Size;
  20. }
  21. namespace printing {
  22. // Simplify title to resolve issue with some drivers.
  23. COMPONENT_EXPORT(PRINTING_BASE)
  24. std::u16string SimplifyDocumentTitle(const std::u16string& title);
  25. COMPONENT_EXPORT(PRINTING_BASE)
  26. std::u16string SimplifyDocumentTitleWithLength(const std::u16string& title,
  27. size_t length);
  28. COMPONENT_EXPORT(PRINTING_BASE)
  29. std::u16string FormatDocumentTitleWithOwner(const std::u16string& owner,
  30. const std::u16string& title);
  31. COMPONENT_EXPORT(PRINTING_BASE)
  32. std::u16string FormatDocumentTitleWithOwnerAndLength(
  33. const std::u16string& owner,
  34. const std::u16string& title,
  35. size_t length);
  36. #if defined(USE_CUPS) && !BUILDFLAG(IS_CHROMEOS_ASH)
  37. // Returns the paper size (microns) most common in the locale to the nearest
  38. // millimeter. Defaults to ISO A4 for an empty or invalid locale.
  39. COMPONENT_EXPORT(PRINTING_BASE)
  40. gfx::Size GetDefaultPaperSizeFromLocaleMicrons(base::StringPiece locale);
  41. // Returns true if both dimensions of the sizes have a delta less than or equal
  42. // to the epsilon value.
  43. COMPONENT_EXPORT(PRINTING_BASE)
  44. bool SizesEqualWithinEpsilon(const gfx::Size& lhs,
  45. const gfx::Size& rhs,
  46. int epsilon);
  47. #endif
  48. #if BUILDFLAG(IS_WIN)
  49. // Get page content rect adjusted based on
  50. // http://dev.w3.org/csswg/css3-page/#positioning-page-box
  51. COMPONENT_EXPORT(PRINTING_BASE)
  52. gfx::Rect GetCenteredPageContentRect(const gfx::Size& paper_size,
  53. const gfx::Size& page_size,
  54. const gfx::Rect& page_content_rect);
  55. #endif
  56. // Helper for tests and DCHECKs to validate that `maybe_pdf_data` suggests a PDF
  57. // document. This includes checking a minimal size and magic bytes.
  58. COMPONENT_EXPORT(PRINTING_BASE)
  59. bool LooksLikePdf(base::span<const char> maybe_pdf_data);
  60. } // namespace printing
  61. #endif // PRINTING_PRINTING_UTILS_H_