File: cups_ipp_helper.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (80 lines) | stat: -rw-r--r-- 2,753 bytes parent folder | download | duplicates (8)
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
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Methods for parsing IPP Printer attributes.

#ifndef PRINTING_BACKEND_CUPS_IPP_HELPER_H_
#define PRINTING_BACKEND_CUPS_IPP_HELPER_H_

#include <cups/cups.h>

#include <memory>

#include "base/component_export.h"
#include "printing/backend/print_backend.h"

namespace printing {

class CupsPrinter;

struct COMPONENT_EXPORT(PRINT_BACKEND) IppDeleter {
  void operator()(ipp_t* ipp) const;
};
// Smart ptr wrapper for CUPS ipp_t
using ScopedIppPtr = std::unique_ptr<ipp_t, IppDeleter>;

// MediaColData is used to store info needed to create a media-col-database
// entry.  Variable width/height entries are optional, in which case the max
// width/height will be the same as the min width/height.
struct COMPONENT_EXPORT(PRINT_BACKEND) MediaColData {
  bool HasVariableWidth() const { return min_width != max_width; }
  bool HasVariableHeight() const { return min_height != max_height; }

  int min_width;
  int min_height;
  int max_width;
  int max_height;
  int bottom_margin;
  int left_margin;
  int right_margin;
  int top_margin;
};

// Returns the default paper setting for `printer`.
COMPONENT_EXPORT(PRINT_BACKEND)
PrinterSemanticCapsAndDefaults::Paper DefaultPaper(const CupsPrinter& printer);

// Populates the `printer_info` object with attributes retrieved using IPP from
// `printer`.
COMPONENT_EXPORT(PRINT_BACKEND)
void CapsAndDefaultsFromPrinter(const CupsPrinter& printer,
                                PrinterSemanticCapsAndDefaults* printer_info);

// Gets the printer margins for the provided paper size.
COMPONENT_EXPORT(PRINT_BACKEND)
gfx::Rect GetPrintableAreaForSize(const CupsPrinter& printer,
                                  const gfx::Size& size_um);

// Wraps `ipp` in unique_ptr with appropriate deleter
COMPONENT_EXPORT(PRINT_BACKEND) ScopedIppPtr WrapIpp(ipp_t* ipp);

// Returns a MediaColData object by extracting necessary fields from `db_entry`.
COMPONENT_EXPORT(PRINT_BACKEND)
std::optional<MediaColData> ExtractMediaColData(ipp_t* db_entry);

// Creates a new media-col-database entry from `data`.  The caller is
// responsible for the returned memory.
COMPONENT_EXPORT(PRINT_BACKEND)
ScopedIppPtr NewMediaCollection(const MediaColData& data);

// Variable height entries are only allowed with a fixed width.  If an entry has
// a variable height and variable width, that entry is filtered out.  However, a
// new entry is created with that variable height for EACH fixed width (among
// all the entries).
COMPONENT_EXPORT(PRINT_BACKEND)
void FilterMediaColSizes(ScopedIppPtr& attributes);

}  // namespace printing

#endif  // PRINTING_BACKEND_CUPS_IPP_HELPER_H_