Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "vcl/jobdata.hxx"
31 : : #include "vcl/printerinfomanager.hxx"
32 : :
33 : : #include "tools/stream.hxx"
34 : :
35 : : #include <sal/alloca.h>
36 : : #include <rtl/strbuf.hxx>
37 : :
38 : : using namespace psp;
39 : :
40 : 501 : JobData& JobData::operator=(const JobData& rRight)
41 : : {
42 : 501 : m_nCopies = rRight.m_nCopies;
43 : 501 : m_nLeftMarginAdjust = rRight.m_nLeftMarginAdjust;
44 : 501 : m_nRightMarginAdjust = rRight.m_nRightMarginAdjust;
45 : 501 : m_nTopMarginAdjust = rRight.m_nTopMarginAdjust;
46 : 501 : m_nBottomMarginAdjust = rRight.m_nBottomMarginAdjust;
47 : 501 : m_nColorDepth = rRight.m_nColorDepth;
48 : 501 : m_eOrientation = rRight.m_eOrientation;
49 : 501 : m_aPrinterName = rRight.m_aPrinterName;
50 : 501 : m_pParser = rRight.m_pParser;
51 : 501 : m_aContext = rRight.m_aContext;
52 : 501 : m_nPSLevel = rRight.m_nPSLevel;
53 : 501 : m_nPDFDevice = rRight.m_nPDFDevice;
54 : 501 : m_nColorDevice = rRight.m_nColorDevice;
55 : :
56 [ - + ][ - + ]: 501 : if( !m_pParser && !m_aPrinterName.isEmpty() )
[ + + ]
57 : : {
58 : 0 : PrinterInfoManager& rMgr = PrinterInfoManager::get();
59 : 0 : rMgr.setupJobContextData( *this );
60 : : }
61 : 501 : return *this;
62 : : }
63 : :
64 : 0 : void JobData::setCollate( bool bCollate )
65 : : {
66 : 0 : const PPDParser* pParser = m_aContext.getParser();
67 [ # # ]: 0 : if( pParser )
68 : : {
69 [ # # ]: 0 : const PPDKey* pKey = pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "Collate" ) ) );
70 [ # # ]: 0 : if( pKey )
71 : : {
72 : 0 : const PPDValue* pVal = NULL;
73 [ # # ]: 0 : if( bCollate )
74 [ # # ]: 0 : pVal = pKey->getValue( String( RTL_CONSTASCII_USTRINGPARAM( "True" ) ) );
75 : : else
76 : : {
77 [ # # ]: 0 : pVal = pKey->getValue( String( RTL_CONSTASCII_USTRINGPARAM( "False" ) ) );
78 [ # # ]: 0 : if( ! pVal )
79 [ # # ]: 0 : pVal = pKey->getValue( String( RTL_CONSTASCII_USTRINGPARAM( "None" ) ) );
80 : : }
81 : 0 : m_aContext.setValue( pKey, pVal );
82 : : }
83 : : }
84 : 0 : }
85 : :
86 : 0 : bool JobData::setPaper( int i_nWidth, int i_nHeight )
87 : : {
88 : 0 : bool bSuccess = false;
89 [ # # ]: 0 : if( m_pParser )
90 : : {
91 [ # # ][ # # ]: 0 : rtl::OUString aPaper( m_pParser->matchPaper( i_nWidth, i_nHeight ) );
[ # # ]
92 : :
93 [ # # ][ # # ]: 0 : const PPDKey* pKey = m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) ) );
[ # # ]
94 [ # # ][ # # ]: 0 : const PPDValue* pValue = pKey ? pKey->getValueCaseInsensitive( aPaper ) : NULL;
[ # # ][ # # ]
[ # # ][ # # ]
95 : :
96 [ # # ][ # # ]: 0 : bSuccess = pKey && pValue && m_aContext.setValue( pKey, pValue, false );
[ # # ][ # # ]
97 : : }
98 : 0 : return bSuccess;
99 : : }
100 : :
101 : 0 : bool JobData::setPaperBin( int i_nPaperBin )
102 : : {
103 : 0 : bool bSuccess = false;
104 [ # # ]: 0 : if( m_pParser )
105 : : {
106 [ # # ]: 0 : const PPDKey* pKey = m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "InputSlot" ) ) );
107 [ # # ]: 0 : const PPDValue* pValue = pKey ? pKey->getValue( i_nPaperBin ) : NULL;
108 : :
109 [ # # ][ # # ]: 0 : bSuccess = pKey && pValue && m_aContext.setValue( pKey, pValue, false );
[ # # ]
110 : : }
111 : 0 : return bSuccess;
112 : : }
113 : :
114 : 112 : bool JobData::getStreamBuffer( void*& pData, int& bytes )
115 : : {
116 : : // consistency checks
117 [ - + ]: 112 : if( ! m_pParser )
118 : 0 : m_pParser = m_aContext.getParser();
119 [ + - ][ - + ]: 112 : if( m_pParser != m_aContext.getParser() ||
[ - + ]
120 : 112 : ! m_pParser )
121 : 0 : return false;
122 : :
123 [ + - ]: 112 : SvMemoryStream aStream;
124 : :
125 : : // write header job data
126 [ + - ]: 112 : aStream.WriteLine(rtl::OString(RTL_CONSTASCII_STRINGPARAM("JobData 1")));
127 : :
128 : 112 : rtl::OStringBuffer aLine;
129 : :
130 [ + - ]: 112 : aLine.append(RTL_CONSTASCII_STRINGPARAM("printer="));
131 [ + - ][ + - ]: 112 : aLine.append(rtl::OUStringToOString(m_aPrinterName, RTL_TEXTENCODING_UTF8));
132 [ + - ]: 112 : aStream.WriteLine(aLine.makeStringAndClear());
133 : :
134 [ + - ]: 112 : aLine.append(RTL_CONSTASCII_STRINGPARAM("orientation="));
135 [ - + ]: 112 : if (m_eOrientation == orientation::Landscape)
136 [ # # ]: 0 : aLine.append(RTL_CONSTASCII_STRINGPARAM("Landscape"));
137 : : else
138 [ + - ]: 112 : aLine.append(RTL_CONSTASCII_STRINGPARAM("Portrait"));
139 [ + - ]: 112 : aStream.WriteLine(aLine.makeStringAndClear());
140 : :
141 [ + - ]: 112 : aLine.append(RTL_CONSTASCII_STRINGPARAM("copies="));
142 [ + - ]: 112 : aLine.append(static_cast<sal_Int32>(m_nCopies));
143 [ + - ]: 112 : aStream.WriteLine(aLine.makeStringAndClear());
144 : :
145 [ + - ]: 112 : aLine.append(RTL_CONSTASCII_STRINGPARAM("margindajustment="));
146 [ + - ]: 112 : aLine.append(static_cast<sal_Int32>(m_nLeftMarginAdjust));
147 [ + - ]: 112 : aLine.append(',');
148 [ + - ]: 112 : aLine.append(static_cast<sal_Int32>(m_nRightMarginAdjust));
149 [ + - ]: 112 : aLine.append(',');
150 [ + - ]: 112 : aLine.append(static_cast<sal_Int32>(m_nTopMarginAdjust));
151 [ + - ]: 112 : aLine.append(',');
152 [ + - ]: 112 : aLine.append(static_cast<sal_Int32>(m_nBottomMarginAdjust));
153 [ + - ]: 112 : aStream.WriteLine(aLine.makeStringAndClear());
154 : :
155 [ + - ]: 112 : aLine.append(RTL_CONSTASCII_STRINGPARAM("colordepth="));
156 [ + - ]: 112 : aLine.append(static_cast<sal_Int32>(m_nColorDepth));
157 [ + - ]: 112 : aStream.WriteLine(aLine.makeStringAndClear());
158 : :
159 [ + - ]: 112 : aLine.append(RTL_CONSTASCII_STRINGPARAM("pslevel="));
160 [ + - ]: 112 : aLine.append(static_cast<sal_Int32>(m_nPSLevel));
161 [ + - ]: 112 : aStream.WriteLine(aLine.makeStringAndClear());
162 : :
163 [ + - ]: 112 : aLine.append(RTL_CONSTASCII_STRINGPARAM("pdfdevice="));
164 [ + - ]: 112 : aLine.append(static_cast<sal_Int32>(m_nPDFDevice));
165 [ + - ]: 112 : aStream.WriteLine(aLine.makeStringAndClear());
166 : :
167 [ + - ]: 112 : aLine.append(RTL_CONSTASCII_STRINGPARAM("colordevice="));
168 [ + - ]: 112 : aLine.append(static_cast<sal_Int32>(m_nColorDevice));
169 [ + - ]: 112 : aStream.WriteLine(aLine.makeStringAndClear());
170 : :
171 : : // now append the PPDContext stream buffer
172 [ + - ]: 112 : aStream.WriteLine( "PPDContexData" );
173 : : sal_uLong nBytes;
174 [ + - ]: 112 : char* pContextBuffer = m_aContext.getStreamableBuffer( nBytes );
175 [ + - ]: 112 : if( nBytes )
176 [ + - ]: 112 : aStream.Write( pContextBuffer, nBytes );
177 [ + - ]: 112 : delete [] pContextBuffer;
178 : :
179 : : // success
180 : 112 : pData = rtl_allocateMemory( bytes = aStream.Tell() );
181 [ + - ]: 112 : memcpy( pData, aStream.GetData(), bytes );
182 [ + - ]: 112 : return true;
183 : : }
184 : :
185 : 115 : bool JobData::constructFromStreamBuffer( void* pData, int bytes, JobData& rJobData )
186 : : {
187 [ + - ]: 115 : SvMemoryStream aStream( pData, bytes, STREAM_READ );
188 : 115 : rtl::OString aLine;
189 : 115 : bool bVersion = false;
190 : 115 : bool bPrinter = false;
191 : 115 : bool bOrientation = false;
192 : 115 : bool bCopies = false;
193 : 115 : bool bContext = false;
194 : 115 : bool bMargin = false;
195 : 115 : bool bColorDepth = false;
196 : 115 : bool bColorDevice = false;
197 : 115 : bool bPSLevel = false;
198 : 115 : bool bPDFDevice = false;
199 : :
200 : 115 : const char printerEquals[] = "printer=";
201 : 115 : const char orientatationEquals[] = "orientation=";
202 : 115 : const char copiesEquals[] = "copies=";
203 : 115 : const char margindajustmentEquals[] = "margindajustment=";
204 : 115 : const char colordepthEquals[] = "colordepth=";
205 : 115 : const char colordeviceEquals[] = "colordevice=";
206 : 115 : const char pslevelEquals[] = "pslevel=";
207 : 115 : const char pdfdeviceEquals[] = "pdfdevice=";
208 : :
209 [ + + ]: 1380 : while( ! aStream.IsEof() )
210 : : {
211 [ + - ]: 1265 : aStream.ReadLine( aLine );
212 [ + + ]: 1265 : if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM("JobData")))
213 : 115 : bVersion = true;
214 [ + + ]: 1150 : else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(printerEquals)))
215 : : {
216 : 115 : bPrinter = true;
217 [ + - ]: 115 : rJobData.m_aPrinterName = rtl::OStringToOUString(aLine.copy(RTL_CONSTASCII_LENGTH(printerEquals)), RTL_TEXTENCODING_UTF8);
218 : : }
219 [ + + ]: 1035 : else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(orientatationEquals)))
220 : : {
221 : 115 : bOrientation = true;
222 [ - + ]: 115 : rJobData.m_eOrientation = aLine.copy(RTL_CONSTASCII_LENGTH(orientatationEquals)).equalsIgnoreAsciiCase("landscape") ? orientation::Landscape : orientation::Portrait;
223 : : }
224 [ + + ]: 920 : else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(copiesEquals)))
225 : : {
226 : 115 : bCopies = true;
227 : 115 : rJobData.m_nCopies = aLine.copy(RTL_CONSTASCII_LENGTH(copiesEquals)).toInt32();
228 : : }
229 [ + + ]: 805 : else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(margindajustmentEquals)))
230 : : {
231 : 115 : bMargin = true;
232 : 115 : rtl::OString aValues(aLine.copy(RTL_CONSTASCII_LENGTH(margindajustmentEquals)));
233 : 115 : rJobData.m_nLeftMarginAdjust = aValues.getToken(0, ',').toInt32();
234 : 115 : rJobData.m_nRightMarginAdjust = aValues.getToken(1, ',').toInt32();
235 : 115 : rJobData.m_nTopMarginAdjust = aValues.getToken(2, ',').toInt32();
236 : 115 : rJobData.m_nBottomMarginAdjust = aValues.getToken(3, ',').toInt32();
237 : : }
238 [ + + ]: 690 : else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(colordepthEquals)))
239 : : {
240 : 115 : bColorDepth = true;
241 : 115 : rJobData.m_nColorDepth = aLine.copy(RTL_CONSTASCII_LENGTH(colordepthEquals)).toInt32();
242 : : }
243 [ + + ]: 575 : else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(colordeviceEquals)))
244 : : {
245 : 115 : bColorDevice = true;
246 : 115 : rJobData.m_nColorDevice = aLine.copy(RTL_CONSTASCII_LENGTH(colordeviceEquals)).toInt32();
247 : : }
248 [ + + ]: 460 : else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(pslevelEquals)))
249 : : {
250 : 115 : bPSLevel = true;
251 : 115 : rJobData.m_nPSLevel = aLine.copy(RTL_CONSTASCII_LENGTH(pslevelEquals)).toInt32();
252 : : }
253 [ + + ]: 345 : else if (aLine.matchL(RTL_CONSTASCII_STRINGPARAM(pdfdeviceEquals)))
254 : : {
255 : 115 : bPDFDevice = true;
256 : 115 : rJobData.m_nPDFDevice = aLine.copy(RTL_CONSTASCII_LENGTH(pdfdeviceEquals)).toInt32();
257 : : }
258 [ + + ]: 230 : else if (aLine.equalsL(RTL_CONSTASCII_STRINGPARAM("PPDContexData")))
259 : : {
260 [ + - ]: 115 : if( bPrinter )
261 : : {
262 [ + - ]: 115 : PrinterInfoManager& rManager = PrinterInfoManager::get();
263 [ + - ]: 115 : const PrinterInfo& rInfo = rManager.getPrinterInfo( rJobData.m_aPrinterName );
264 [ + - ][ + - ]: 115 : rJobData.m_pParser = PPDParser::getParser( rInfo.m_aDriverName );
[ + - ]
265 [ + - ]: 115 : if( rJobData.m_pParser )
266 : : {
267 [ + - ]: 115 : rJobData.m_aContext.setParser( rJobData.m_pParser );
268 : 115 : int nBytes = bytes - aStream.Tell();
269 : 115 : char* pRemain = (char*)alloca( bytes - aStream.Tell() );
270 [ + - ]: 115 : aStream.Read( pRemain, nBytes );
271 [ + - ]: 115 : rJobData.m_aContext.rebuildFromStreamBuffer( pRemain, nBytes );
272 : 115 : bContext = true;
273 : : }
274 : : }
275 : : }
276 : : }
277 : :
278 [ + - ][ + - ]: 115 : return bVersion && bPrinter && bOrientation && bCopies && bContext && bMargin && bPSLevel && bPDFDevice && bColorDevice && bColorDepth;
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
279 : : }
280 : :
281 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|