1 // Copyright 2013 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.
5 #ifndef PRINTING_PRINTING_UTILS_H_
6 #define PRINTING_PRINTING_UTILS_H_
12 #include "base/component_export.h"
13 #include "base/containers/span.h"
14 #include "build/build_config.h"
15 #include "build/chromeos_buildflags.h"
17 #if defined(USE_CUPS) && !BUILDFLAG(IS_CHROMEOS_ASH)
18 #include "base/strings/string_piece.h"
22 #include "ui/gfx/geometry/rect.h"
31 // Simplify title to resolve issue with some drivers.
32 COMPONENT_EXPORT(PRINTING_BASE)
33 std::u16string SimplifyDocumentTitle(const std::u16string& title);
35 COMPONENT_EXPORT(PRINTING_BASE)
36 std::u16string SimplifyDocumentTitleWithLength(const std::u16string& title,
39 COMPONENT_EXPORT(PRINTING_BASE)
40 std::u16string FormatDocumentTitleWithOwner(const std::u16string& owner,
41 const std::u16string& title);
43 COMPONENT_EXPORT(PRINTING_BASE)
44 std::u16string FormatDocumentTitleWithOwnerAndLength(
45 const std::u16string& owner,
46 const std::u16string& title,
49 #if defined(USE_CUPS) && !BUILDFLAG(IS_CHROMEOS_ASH)
50 // Returns the paper size (microns) most common in the locale to the nearest
51 // millimeter. Defaults to ISO A4 for an empty or invalid locale.
52 COMPONENT_EXPORT(PRINTING_BASE)
53 gfx::Size GetDefaultPaperSizeFromLocaleMicrons(base::StringPiece locale);
55 // Returns true if both dimensions of the sizes have a delta less than or equal
56 // to the epsilon value.
57 COMPONENT_EXPORT(PRINTING_BASE)
58 bool SizesEqualWithinEpsilon(const gfx::Size& lhs,
64 // Get page content rect adjusted based on
65 // http://dev.w3.org/csswg/css3-page/#positioning-page-box
66 COMPONENT_EXPORT(PRINTING_BASE)
67 gfx::Rect GetCenteredPageContentRect(const gfx::Size& paper_size,
68 const gfx::Size& page_size,
69 const gfx::Rect& page_content_rect);
72 // Helper for tests and DCHECKs to validate that `maybe_pdf_data` suggests a PDF
73 // document. This includes checking a minimal size and magic bytes.
74 COMPONENT_EXPORT(PRINTING_BASE)
75 bool LooksLikePdf(base::span<const char> maybe_pdf_data);
77 } // namespace printing
79 #endif // PRINTING_PRINTING_UTILS_H_