3 Preview printer driver.
5 Copyright (c) 2001, 2002 OpenBeOS.
6 Copyright (c) 2005 - 2008 Haiku.
13 Permission is hereby granted, free of charge, to any person obtaining a copy of
14 this software and associated documentation files (the "Software"), to deal in
15 the Software without restriction, including without limitation the rights to
16 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17 of the Software, and to permit persons to whom the Software is furnished to do
18 so, subject to the following conditions:
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
33 #include "PrintUtils.h"
41 ScaleRect(const BRect
& rect
, float scale
)
43 BRect
scaleRect(rect
);
45 scaleRect
.left
*= scale
;
46 scaleRect
.right
*= scale
;
47 scaleRect
.top
*= scale
;
48 scaleRect
.bottom
*= scale
;
55 SetBool(BMessage
* msg
, const char* name
, bool value
)
57 if (msg
->HasBool(name
)) {
58 msg
->ReplaceBool(name
, value
);
60 msg
->AddBool(name
, value
);
66 SetFloat(BMessage
* msg
, const char* name
, float value
)
68 if (msg
->HasFloat(name
)) {
69 msg
->ReplaceFloat(name
, value
);
71 msg
->AddFloat(name
, value
);
77 SetInt32(BMessage
* msg
, const char* name
, int32 value
)
79 if (msg
->HasInt32(name
)) {
80 msg
->ReplaceInt32(name
, value
);
82 msg
->AddInt32(name
, value
);
88 SetString(BMessage
* msg
, const char* name
, const char* value
)
90 if (msg
->HasString(name
, 0)) {
91 msg
->ReplaceString(name
, value
);
93 msg
->AddString(name
, value
);
99 SetRect(BMessage
* msg
, const char* name
, const BRect
& rect
)
101 if (msg
->HasRect(name
)) {
102 msg
->ReplaceRect(name
, rect
);
104 msg
->AddRect(name
, rect
);
110 SetString(BMessage
* msg
, const char* name
, const BString
& value
)
112 SetString(msg
, name
, value
.String());
117 bool InList(const char* list
[], const char* name
)
119 for (int i
= 0; list
[i
] != NULL
; ++i
) {
120 if (strcmp(list
[i
], name
) == 0)
128 AddFields(BMessage
* to
, const BMessage
* from
, const char* excludeList
[],
129 const char* includeList
[], bool overwrite
)
133 #ifndef B_BEOS_VERSION_DANO
140 for (int32 i
= 0; from
->GetInfo(B_ANY_TYPE
, i
, &name
, &type
, &count
)
142 if (excludeList
&& InList(excludeList
, name
))
145 if (includeList
&& !InList(includeList
, name
))
150 if (!overwrite
&& to
->FindData(name
, type
, 0, &data
, &size
) == B_OK
)
153 // replace existing data
154 to
->RemoveName(name
);
156 for (int32 j
= 0; j
< count
; ++j
) {
157 if (from
->FindData(name
, type
, j
, &data
, &size
) == B_OK
) {
158 if (type
== B_STRING_TYPE
) {
159 to
->AddString(name
, (const char*)data
);
160 } else if (type
== B_MESSAGE_TYPE
) {
162 from
->FindMessage(name
, j
, &m
);
163 to
->AddMessage(name
, &m
);
165 to
->AddData(name
, type
, data
, size
);