2 * Copyright (C) 2001 the KGhostView authors. See file AUTHORS.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "dscparse_adapter.h"
23 /*-- KDSCBBOX implementation -----------------------------------------------*/
25 KDSCBBOX::KDSCBBOX() :
30 KDSCBBOX::KDSCBBOX( const KDSCBBOX
& b
) :
31 _llx( b
._llx
), _lly( b
._lly
),
32 _urx( b
._urx
), _ury( b
._ury
)
35 KDSCBBOX::KDSCBBOX( int llx
, int lly
, int urx
, int ury
) :
36 _llx( llx
), _lly( lly
),
37 _urx( urx
), _ury( ury
)
40 KDSCBBOX::KDSCBBOX( const CDSCBBOX
& bbox
) :
41 _llx( bbox
.llx
), _lly( bbox
.lly
),
42 _urx( bbox
.urx
), _ury( bbox
.ury
)
45 KDSCBBOX
& KDSCBBOX::operator = ( const KDSCBBOX
& b
)
47 _llx
= b
._llx
; _lly
= b
._lly
; _urx
= b
._urx
; _ury
= b
._ury
;
51 bool KDSCBBOX::operator == ( const KDSCBBOX
& b
)
53 return ( _llx
== b
._llx
&& _lly
== b
._lly
54 && _urx
== b
._urx
&& _ury
== b
._ury
);
57 bool KDSCBBOX::operator != ( const KDSCBBOX
& b
)
59 return !( *this == b
);
62 int KDSCBBOX::llx() const { return _llx
; }
63 int KDSCBBOX::lly() const { return _lly
; }
64 int KDSCBBOX::urx() const { return _urx
; }
65 int KDSCBBOX::ury() const { return _ury
; }
67 int KDSCBBOX::width() const { return _urx
- _llx
; }
68 int KDSCBBOX::height() const { return _ury
- _lly
; }
70 QSize
KDSCBBOX::size() const { return QSize( width(), height() ); }
72 ostream
& operator << ( ostream
& os
, const KDSCBBOX
& source
)
74 os
<< "{ llx: "<< source
.llx() << ", lly: " << source
.lly()
75 << " urx: "<< source
.urx() << ", ury: " << source
.ury() << " }";
79 /*-- KDSCError implementation ----------------------------------------------*/
81 KDSCError::KDSCError( Type type
, Severity severity
, const QByteArray
& line
,
82 unsigned int lineNumber
) :
84 _severity( severity
),
86 _lineNumber( lineNumber
)
89 KDSCError::Type
KDSCError::type() const
94 KDSCError::Severity
KDSCError::severity() const
99 QByteArray
KDSCError::line() const
104 unsigned int KDSCError::lineNumber() const
109 /*-- KDSCOkErrorHandler implementation -------------------------------------*/
111 KDSCErrorHandler::Response
KDSCOkErrorHandler::error( const KDSCError
& err
)
113 cout
<< "KDSC: error in line " << err
.lineNumber() << endl
;
114 //cout << err.line() << endl;
118 /*-- KDSC implementation ---------------------------------------------------*/
124 _cdsc
= dsc_init( this );
125 Q_ASSERT( _cdsc
!= 0 );
126 _scanHandler
= new KDSCScanHandler( _cdsc
);
135 QString
KDSC::dsc_version() const
137 return QString( _cdsc
->dsc_version
);
140 bool KDSC::dsc() const
142 return ( _cdsc
->dsc
== TRUE
);
145 bool KDSC::ctrld() const
147 return ( _cdsc
->ctrld
== TRUE
);
150 bool KDSC::pjl() const
152 return ( _cdsc
->pjl
== TRUE
);
155 bool KDSC::epsf() const
157 return ( _cdsc
->epsf
== TRUE
);
160 bool KDSC::pdf() const
162 return ( _cdsc
->pdf
== TRUE
);
165 unsigned int KDSC::preview() const
167 return _cdsc
->preview
;
170 unsigned int KDSC::language_level() const
172 return _cdsc
->language_level
;
175 unsigned int KDSC::document_data() const
177 return _cdsc
->document_data
;
180 unsigned long KDSC::begincomments() const
182 return _cdsc
->begincomments
;
185 unsigned long KDSC::endcomments() const
187 return _cdsc
->endcomments
;
190 unsigned long KDSC::beginpreview() const
192 return _cdsc
->beginpreview
;
195 unsigned long KDSC::endpreview() const
197 return _cdsc
->endpreview
;
200 unsigned long KDSC::begindefaults() const
202 return _cdsc
->begindefaults
;
205 unsigned long KDSC::enddefaults() const
207 return _cdsc
->enddefaults
;
210 unsigned long KDSC::beginprolog() const
212 return _cdsc
->beginprolog
;
215 unsigned long KDSC::endprolog() const
217 return _cdsc
->endprolog
;
220 unsigned long KDSC::beginsetup() const
222 return _cdsc
->beginsetup
;
225 unsigned long KDSC::endsetup() const
227 return _cdsc
->endsetup
;
230 unsigned long KDSC::begintrailer() const
232 return _cdsc
->begintrailer
;
235 unsigned long KDSC::endtrailer() const
237 return _cdsc
->endtrailer
;
240 CDSCPAGE
* KDSC::page() const
245 unsigned int KDSC::page_count() const
247 return _cdsc
->page_count
;
250 unsigned int KDSC::page_pages() const
252 return _cdsc
->page_pages
;
255 unsigned int KDSC::page_order() const
257 return _cdsc
->page_order
;
260 unsigned int KDSC::page_orientation() const
262 return _cdsc
->page_orientation
;
265 CDSCCTM
* KDSC::viewing_orientation() const
267 return _cdsc
->viewing_orientation
;
270 unsigned int KDSC::media_count() const
272 return _cdsc
->media_count
;
275 CDSCMEDIA
** KDSC::media() const
280 const CDSCMEDIA
* KDSC::page_media() const
282 return _cdsc
->page_media
;
285 auto_ptr
<KDSCBBOX
> KDSC::bbox() const
287 if( _cdsc
->bbox
== 0 )
288 return auto_ptr
<KDSCBBOX
>( 0 );
290 return auto_ptr
<KDSCBBOX
>( new KDSCBBOX( *_cdsc
->bbox
) );
293 auto_ptr
<KDSCBBOX
> KDSC::page_bbox() const
295 if( _cdsc
->page_bbox
== 0 )
296 return auto_ptr
<KDSCBBOX
>( 0 );
298 return auto_ptr
<KDSCBBOX
>( new KDSCBBOX( *_cdsc
->page_bbox
) );
301 QString
KDSC::dsc_title() const
303 return QString( _cdsc
->dsc_title
);
306 QString
KDSC::dsc_creator() const
308 return QString( _cdsc
->dsc_creator
);
311 QString
KDSC::dsc_date() const
313 return QString( _cdsc
->dsc_date
);
316 QString
KDSC::dsc_for() const
318 return QString( _cdsc
->dsc_for
);
321 bool KDSC::scanData( char* buffer
, unsigned int count
)
323 return _scanHandler
->scanData( buffer
, count
);
328 return dsc_fixup( _cdsc
);
331 KDSCErrorHandler
* KDSC::errorHandler() const
333 return _errorHandler
;
336 void KDSC::setErrorHandler( KDSCErrorHandler
* errorHandler
)
338 _errorHandler
= errorHandler
;
339 if( errorHandler
== 0 )
340 dsc_set_error_function( _cdsc
, 0 );
342 dsc_set_error_function( _cdsc
, &errorFunction
);
345 KDSCCommentHandler
* KDSC::commentHandler() const
347 return _commentHandler
;
350 void KDSC::setCommentHandler( KDSCCommentHandler
* commentHandler
)
352 if( _commentHandler
!= 0 && commentHandler
== 0 )
355 _scanHandler
= new KDSCScanHandler( _cdsc
);
357 else if( _commentHandler
== 0 && commentHandler
!= 0 )
360 _scanHandler
= new KDSCScanHandlerByLine( _cdsc
, commentHandler
);
362 _commentHandler
= commentHandler
;
365 bool KDSC::isStructured() const
367 return epsf() ? ( page_count() > 1 ) : ( page_count() > 0 );
370 CDSC
* KDSC::cdsc() const
375 int KDSC::errorFunction( void* caller_data
, CDSC
* dsc
,
376 unsigned int explanation
, const char* line
, unsigned int line_len
)
379 static_cast< KDSCError::Type
>( explanation
),
380 static_cast< KDSCError::Severity
>( dsc
->severity
[explanation
] ),
381 QByteArray( line
, line_len
+ 1 ),
385 KDSC
* kdsc
= static_cast< KDSC
* >( caller_data
);
388 return kdsc
->errorHandler()->error( error
);
391 bool KDSCScanHandlerByLine::scanData( char* buf
, unsigned int count
)
393 char* lineStart
= buf
;
395 while( it
< buf
+ count
)
399 int retval
= dsc_scan_data( _cdsc
, lineStart
, it
- lineStart
);
402 else if( retval
> 0 )
404 _commentHandler
->comment(
405 static_cast<KDSCCommentHandler::Name
>( retval
) );
411 if( it
!= lineStart
)
413 // Scan the remaining part of the string.
414 return ( dsc_scan_data( _cdsc
, lineStart
, it
- lineStart
) < 0 );
420 // vim:sw=4:sts=4:ts=8:noet