vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / print / drivers / gutenprint / GPCapabilities.cpp
blob2b4d9be8b1161ce9277a4d1395dc3cda36592315
1 /*
2 * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
4 * Copyright 2010, Haiku. All rights reserved.
5 * Distributed under the terms of the MIT License.
7 * Authors:
8 * Michael Pfeiffer
9 */
12 #include "GPCapabilities.h"
14 #include "GPBinding.h"
15 #include "GPData.h"
16 #include "PrinterData.h"
19 GPCapabilities::GPCapabilities(const PrinterData* printer_data)
21 PrinterCap(printer_data)
23 InitCapabilitiesFromGutenprint();
27 GPCapabilities::~GPCapabilities()
31 int
32 GPCapabilities::CountCap(CapID category) const
34 const GPArray<struct BaseCap>* capabilities;
36 switch (category) {
37 case kPaper:
38 return fPageSizes.Size();
39 case kPaperSource:
40 return fInputSlots.Size();
41 case kResolution:
42 return fResolutions.Size();
43 case kColor:
44 return fPrintingModes.Size();
45 case kDriverSpecificCapabilities:
46 return fDriverSpecificCategories.Size();
48 default:
49 capabilities = DriverSpecificCapabilities(category);
50 if (capabilities == NULL)
51 return 0;
52 return capabilities->Size();
57 const BaseCap**
58 GPCapabilities::GetCaps(CapID category) const
60 typedef const BaseCap** ArrayType;
61 const GPArray<struct BaseCap>* capabilities;
63 switch (category) {
64 case kPaper:
65 return (ArrayType)fPageSizes.Array();
66 case kPaperSource:
67 return (ArrayType)fInputSlots.Array();
68 case kResolution:
69 return (ArrayType)fResolutions.Array();
70 case kColor:
71 return (ArrayType)fPrintingModes.Array();
72 case kDriverSpecificCapabilities:
73 return (ArrayType)fDriverSpecificCategories.Array();
75 default:
76 capabilities = DriverSpecificCapabilities(category);
77 if (capabilities == NULL)
78 return NULL;
79 return (ArrayType)capabilities->Array();
84 bool
85 GPCapabilities::Supports(CapID category) const
87 switch (category) {
88 case kPaper:
89 case kPaperSource:
90 case kResolution:
91 case kColor:
92 return true;
94 default:
95 return CountCap(category) > 0;
99 void
100 GPCapabilities::InitCapabilitiesFromGutenprint()
102 const GPData* data = dynamic_cast<const GPData*>(GetPrinterData());
103 ASSERT(data != NULL);
104 // capabilities are available only after printer model
105 // has been selected
106 if (data->fGutenprintDriverName == "")
107 return;
110 GPBinding binding;
111 binding.GetCapabilities(data->fGutenprintDriverName.String(), this);
115 const GPArray<struct BaseCap>*
116 GPCapabilities::DriverSpecificCapabilities(int32 category) const
118 DriverSpecificCapabilitiesType::const_iterator it =
119 fDriverSpecificCapabilities.find(category);
120 if (it == fDriverSpecificCapabilities.end())
121 return NULL;
122 return &it->second;