xref: /haiku/src/add-ons/print/drivers/lpstyl/LpstylCap.cpp (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 /*
2 * Copyright 2017, Haiku. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Adrien Destugues <pulkomandy@pulkomandy.tk>
7 */
8 #include "LpstylCap.h"
9 
10 
11 #define TO72DPI(a)	(a * 72.0f / 360.0f)
12 
13 
14 static const PaperCap a4(
15 	"A4",
16 	true,
17 	JobData::kA4,
18 	BRect(0.0f,           0.0f,           TO72DPI(2975.0f), TO72DPI(4210.0f)),
19 	BRect(TO72DPI(72.0f), TO72DPI(72.0f), TO72DPI(2903.0f), TO72DPI(4138.0f)));
20 
21 static const PaperCap letter(
22 	"Letter",
23 	true,
24 	JobData::kLetter,
25 	BRect(0.0f,           0.0f,           TO72DPI(3060.0f), TO72DPI(3960.0f)),
26 	BRect(TO72DPI(72.0f), TO72DPI(72.0f), TO72DPI(2988.0f), TO72DPI(3888.0f)));
27 
28 
29 static const ResolutionCap dpi360("360dpi",   true,  1, 360,  360);
30 
31 
32 static const PaperCap* papers[] = {
33 	&a4,
34 	&letter,
35 };
36 
37 static const ResolutionCap* resolutions[] = {
38 	&dpi360,
39 };
40 
41 static const ColorCap color("Color", false, JobData::kColor);
42 static const ColorCap monochrome("Shades of Gray", true, JobData::kMonochrome);
43 
44 static const ColorCap* colors[] = {
45 	&color,
46 	&monochrome
47 };
48 
49 // This is required so libprint saves PrinterData in the printer spool dir.
50 static const ProtocolClassCap proto("Serial", true, 1, "Serial port");
51 
52 static const ProtocolClassCap* protocols[] = {
53 	&proto
54 };
55 
56 
57 int
58 LpstylCap::CountCap(CapID capid) const
59 {
60 	switch (capid) {
61 		case kPaper:
62 			return sizeof(papers) / sizeof(papers[0]);
63 		case kResolution:
64 			return sizeof(resolutions) / sizeof(resolutions[0]);
65 #if 0
66 		case kPaperSource:
67 			return sizeof(papersources) / sizeof(papersources[0]);
68 		case kPrintStyle:
69 			return sizeof(printstyles) / sizeof(printstyles[0]);
70 		case kBindingLocation:
71 			return sizeof(bindinglocations) / sizeof(bindinglocations[0]);
72 #endif
73 		case kColor:
74 			return sizeof(colors) / sizeof(colors[0]);
75 		case kProtocolClass:
76 			return sizeof(protocols) / sizeof(protocols[0]);
77 		default:
78 			return 0;
79 		}
80 }
81 
82 
83 const BaseCap**
84 LpstylCap::GetCaps(CapID capid) const
85 {
86 	switch (capid) {
87 		case kPaper:
88 			return (const BaseCap **)papers;
89 		case kResolution:
90 			return (const BaseCap **)resolutions;
91 #if 0
92 		case kPaperSource:
93 			return (const BaseCap **)papersources;
94 		case kPrintStyle:
95 			return (const BaseCap **)printstyles;
96 		case kBindingLocation:
97 			return (const BaseCap **)bindinglocations;
98 #endif
99 		case kProtocolClass:
100 			return (const BaseCap **)protocols;
101 		case kColor:
102 			return (const BaseCap **)colors;
103 		default:
104 			return NULL;
105 	}
106 }
107 
108 
109 bool
110 LpstylCap::Supports(CapID capid) const
111 {
112 	switch (capid) {
113 		case kPaper:
114 		case kResolution:
115 		case kColor:
116 		case kProtocolClass:
117 			return true;
118 		case kPaperSource:
119 		case kPrintStyle:
120 		case kBindingLocation:
121 		case kCopyCommand:
122 		case kHalftone:
123 		default:
124 			return false;
125 	}
126 }
127