1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: jobdata.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #include "vcl/jobdata.hxx"
35 #include "vcl/printerinfomanager.hxx"
37 #include "tools/stream.hxx"
39 #include "sal/alloca.h"
44 JobData
& JobData::operator=(const JobData
& rRight
)
46 m_nCopies
= rRight
.m_nCopies
;
47 m_nLeftMarginAdjust
= rRight
.m_nLeftMarginAdjust
;
48 m_nRightMarginAdjust
= rRight
.m_nRightMarginAdjust
;
49 m_nTopMarginAdjust
= rRight
.m_nTopMarginAdjust
;
50 m_nBottomMarginAdjust
= rRight
.m_nBottomMarginAdjust
;
51 m_nColorDepth
= rRight
.m_nColorDepth
;
52 m_eOrientation
= rRight
.m_eOrientation
;
53 m_aPrinterName
= rRight
.m_aPrinterName
;
54 m_pParser
= rRight
.m_pParser
;
55 m_aContext
= rRight
.m_aContext
;
56 m_nPSLevel
= rRight
.m_nPSLevel
;
57 m_nColorDevice
= rRight
.m_nColorDevice
;
59 if( ! m_pParser
&& m_aPrinterName
.getLength() )
61 PrinterInfoManager
& rMgr
= PrinterInfoManager::get();
62 rMgr
.setupJobContextData( *this );
67 bool JobData::getStreamBuffer( void*& pData
, int& bytes
)
71 m_pParser
= m_aContext
.getParser();
72 if( m_pParser
!= m_aContext
.getParser() ||
76 SvMemoryStream aStream
;
79 // write header job data
80 aStream
.WriteLine( "JobData 1" );
83 aLine
+= ByteString( String( m_aPrinterName
), RTL_TEXTENCODING_UTF8
);
84 aStream
.WriteLine( aLine
);
86 aLine
= "orientation=";
87 aLine
+= m_eOrientation
== orientation::Landscape
? "Landscape" : "Portrait";
88 aStream
.WriteLine( aLine
);
91 aLine
+= ByteString::CreateFromInt32( m_nCopies
);
92 aStream
.WriteLine( aLine
);
94 aLine
= "margindajustment=";
95 aLine
+= ByteString::CreateFromInt32( m_nLeftMarginAdjust
);
97 aLine
+= ByteString::CreateFromInt32( m_nRightMarginAdjust
);
99 aLine
+= ByteString::CreateFromInt32( m_nTopMarginAdjust
);
101 aLine
+= ByteString::CreateFromInt32( m_nBottomMarginAdjust
);
102 aStream
.WriteLine( aLine
);
104 aLine
= "colordepth=";
105 aLine
+= ByteString::CreateFromInt32( m_nColorDepth
);
106 aStream
.WriteLine( aLine
);
109 aLine
+= ByteString::CreateFromInt32( m_nPSLevel
);
110 aStream
.WriteLine( aLine
);
112 aLine
= "colordevice=";
113 aLine
+= ByteString::CreateFromInt32( m_nColorDevice
);
114 aStream
.WriteLine( aLine
);
116 // now append the PPDContext stream buffer
117 aStream
.WriteLine( "PPDContexData" );
119 void* pContextBuffer
= m_aContext
.getStreamableBuffer( nBytes
);
121 aStream
.Write( pContextBuffer
, nBytes
);
124 pData
= rtl_allocateMemory( bytes
= aStream
.Tell() );
125 memcpy( pData
, aStream
.GetData(), bytes
);
129 bool JobData::constructFromStreamBuffer( void* pData
, int bytes
, JobData
& rJobData
)
131 SvMemoryStream
aStream( pData
, bytes
, STREAM_READ
);
133 bool bVersion
= false;
134 bool bPrinter
= false;
135 bool bOrientation
= false;
136 bool bCopies
= false;
137 bool bContext
= false;
138 bool bMargin
= false;
139 bool bColorDepth
= false;
140 bool bColorDevice
= false;
141 bool bPSLevel
= false;
142 while( ! aStream
.IsEof() )
144 aStream
.ReadLine( aLine
);
145 if( aLine
.CompareTo( "JobData", 7 ) == COMPARE_EQUAL
)
147 else if( aLine
.CompareTo( "printer=", 8 ) == COMPARE_EQUAL
)
150 rJobData
.m_aPrinterName
= String( aLine
.Copy( 8 ), RTL_TEXTENCODING_UTF8
);
152 else if( aLine
.CompareTo( "orientation=", 12 ) == COMPARE_EQUAL
)
155 rJobData
.m_eOrientation
= aLine
.Copy( 12 ).EqualsIgnoreCaseAscii( "landscape" ) ? orientation::Landscape
: orientation::Portrait
;
157 else if( aLine
.CompareTo( "copies=", 7 ) == COMPARE_EQUAL
)
160 rJobData
.m_nCopies
= aLine
.Copy( 7 ).ToInt32();
162 else if( aLine
.CompareTo( "margindajustment=",17 ) == COMPARE_EQUAL
)
165 ByteString
aValues( aLine
.Copy( 17 ) );
166 rJobData
.m_nLeftMarginAdjust
= aValues
.GetToken( 0, ',' ).ToInt32();
167 rJobData
.m_nRightMarginAdjust
= aValues
.GetToken( 1, ',' ).ToInt32();
168 rJobData
.m_nTopMarginAdjust
= aValues
.GetToken( 2, ',' ).ToInt32();
169 rJobData
.m_nBottomMarginAdjust
= aValues
.GetToken( 3, ',' ).ToInt32();
171 else if( aLine
.CompareTo( "colordepth=", 11 ) == COMPARE_EQUAL
)
174 rJobData
.m_nColorDepth
= aLine
.Copy( 11 ).ToInt32();
176 else if( aLine
.CompareTo( "colordevice=", 12 ) == COMPARE_EQUAL
)
179 rJobData
.m_nColorDevice
= aLine
.Copy( 12 ).ToInt32();
181 else if( aLine
.CompareTo( "pslevel=", 8 ) == COMPARE_EQUAL
)
184 rJobData
.m_nPSLevel
= aLine
.Copy( 8 ).ToInt32();
186 else if( aLine
.Equals( "PPDContexData" ) )
190 PrinterInfoManager
& rManager
= PrinterInfoManager::get();
191 const PrinterInfo
& rInfo
= rManager
.getPrinterInfo( rJobData
.m_aPrinterName
);
192 rJobData
.m_pParser
= PPDParser::getParser( rInfo
.m_aDriverName
);
193 if( rJobData
.m_pParser
)
195 rJobData
.m_aContext
.setParser( rJobData
.m_pParser
);
196 int nBytes
= bytes
- aStream
.Tell();
197 void* pRemain
= alloca( bytes
- aStream
.Tell() );
198 aStream
.Read( pRemain
, nBytes
);
199 rJobData
.m_aContext
.rebuildFromStreamBuffer( pRemain
, nBytes
);
206 return bVersion
&& bPrinter
&& bOrientation
&& bCopies
&& bContext
&& bMargin
&& bPSLevel
&& bColorDevice
&& bColorDepth
;