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 #ifndef DSCPARSE_ADAPTER_H
20 #define DSCPARSE_ADAPTER_H
37 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 93)
39 * We add a quick 'n' dirty inline implementation of auto_ptr for older
40 * releases of GCC, which don't include an auto_ptr implementation in
44 template <class T
> class auto_ptr
{
49 typedef T element_type
;
50 explicit auto_ptr(T
* p
= 0) : _ptr(p
) {}
51 auto_ptr(auto_ptr
& a
) : _ptr(a
.release()) {}
52 template <class T1
> auto_ptr(auto_ptr
<T1
>& a
) : _ptr(a
.release()) {}
53 auto_ptr
& operator=(auto_ptr
& a
) {
61 auto_ptr
& operator=(auto_ptr
<T1
>& a
) {
62 if (a
.get() != this->get()) {
68 ~auto_ptr() { delete _ptr
; }
70 T
& operator*() const { return *_ptr
; }
71 T
* operator->() const { return _ptr
; }
72 T
* get() const { return _ptr
; }
73 T
* release() { T
* tmp
= _ptr
; _ptr
= 0; return tmp
; }
74 void reset(T
* p
= 0) { delete _ptr
; _ptr
= p
; }
85 KDSCBBOX( const KDSCBBOX
& b
);
86 KDSCBBOX( int llx
, int lly
, int urx
, int ury
);
87 KDSCBBOX( const CDSCBBOX
& bbox
);
89 KDSCBBOX
& operator = ( const KDSCBBOX
& b
);
91 bool operator == ( const KDSCBBOX
& b
);
92 bool operator != ( const KDSCBBOX
& b
);
105 int _llx
, _lly
, _urx
, _ury
;
108 std::ostream
& operator << ( std::ostream
&, const KDSCBBOX
& );
116 BBox
= CDSC_MESSAGE_BBOX
,
117 EarlyTrailer
= CDSC_MESSAGE_EARLY_TRAILER
,
118 EarlyEOF
= CDSC_MESSAGE_EARLY_EOF
,
119 PageInTrailer
= CDSC_MESSAGE_PAGE_IN_TRAILER
,
120 PageOrdinal
= CDSC_MESSAGE_PAGE_ORDINAL
,
121 PagesWrong
= CDSC_MESSAGE_PAGES_WRONG
,
122 EPSNoBBox
= CDSC_MESSAGE_EPS_NO_BBOX
,
123 EPSPages
= CDSC_MESSAGE_EPS_PAGES
,
124 NoMedia
= CDSC_MESSAGE_NO_MEDIA
,
125 AtEnd
= CDSC_MESSAGE_ATEND
,
126 DuplicateComment
= CDSC_MESSAGE_DUP_COMMENT
,
127 DuplicateTrailer
= CDSC_MESSAGE_DUP_TRAILER
,
128 BeginEnd
= CDSC_MESSAGE_BEGIN_END
,
129 BadSection
= CDSC_MESSAGE_BAD_SECTION
,
130 LongLine
= CDSC_MESSAGE_LONG_LINE
,
131 IncorrectUsage
= CDSC_MESSAGE_INCORRECT_USAGE
136 Information
= CDSC_ERROR_INFORM
,
137 Warning
= CDSC_ERROR_WARN
,
138 Error
= CDSC_ERROR_ERROR
141 KDSCError( Type
, Severity
, const QByteArray
& line
,
142 unsigned int lineNumber
);
145 Severity
severity() const;
146 QByteArray
line() const;
147 unsigned int lineNumber() const;
153 unsigned int _lineNumber
;
157 class KDSCErrorHandler
160 virtual ~KDSCErrorHandler() {}
163 Ok
= CDSC_RESPONSE_OK
,
164 Cancel
= CDSC_RESPONSE_CANCEL
,
165 IgnoreAll
= CDSC_RESPONSE_IGNORE_ALL
168 virtual Response
error( const KDSCError
& ) = 0;
171 class KDSCOkErrorHandler
: public KDSCErrorHandler
173 Response
error( const KDSCError
& );
176 class KDSCCommentHandler
179 virtual ~KDSCCommentHandler() {}
183 PSAdobe
= CDSC_PSADOBE
,
184 BeginComments
= CDSC_BEGINCOMMENTS
,
185 EndComments
= CDSC_ENDCOMMENTS
,
187 Creator
= CDSC_CREATOR
,
188 CreationDate
= CDSC_CREATIONDATE
,
191 LanguageLevel
= CDSC_LANGUAGELEVEL
,
192 BoundingBox
= CDSC_BOUNDINGBOX
,
193 Orientation
= CDSC_ORIENTATION
,
194 PageOrder
= CDSC_PAGEORDER
,
195 DocumentMedia
= CDSC_DOCUMENTMEDIA
,
196 DocumentPaperSizes
= CDSC_DOCUMENTPAPERSIZES
,
197 DocumentPaperForms
= CDSC_DOCUMENTPAPERFORMS
,
198 DocumentPaperColors
= CDSC_DOCUMENTPAPERCOLORS
,
199 DocumentPaperWeights
= CDSC_DOCUMENTPAPERWEIGHTS
,
200 DocumentData
= CDSC_DOCUMENTDATA
,
201 Requirements
= CDSC_REQUIREMENTS
,
202 DocumentNeededFonts
= CDSC_DOCUMENTNEEDEDFONTS
,
203 DocumentSuppliedFonts
= CDSC_DOCUMENTSUPPLIEDFONTS
,
204 HiResBoundingBox
= CDSC_HIRESBOUNDINGBOX
,
205 CropBox
= CDSC_CROPBOX
,
208 BeginPreview
= CDSC_BEGINPREVIEW
,
209 EndPreview
= CDSC_ENDPREVIEW
,
212 BeginDefaults
= CDSC_BEGINDEFAULTS
,
213 EndDefaults
= CDSC_ENDDEFAULTS
,
214 // also %%PageMedia, %%PageOrientation, %%PageBoundingBox
217 BeginProlog
= CDSC_BEGINPROLOG
,
218 EndProlog
= CDSC_ENDPROLOG
,
219 BeginFont
= CDSC_BEGINFONT
,
220 EndFont
= CDSC_ENDFONT
,
221 BeginFeature
= CDSC_BEGINFEATURE
,
222 EndFeature
= CDSC_ENDFEATURE
,
223 BeginResource
= CDSC_BEGINRESOURCE
,
224 EndResource
= CDSC_ENDRESOURCE
,
225 BeginProcset
= CDSC_BEGINPROCSET
,
226 EndProcset
= CDSC_ENDPROCSET
,
229 BeginSetup
= CDSC_BEGINSETUP
,
230 EndSetup
= CDSC_ENDSETUP
,
231 Feature
= CDSC_FEATURE
,
232 PaperColor
= CDSC_PAPERCOLOR
,
233 PaperForm
= CDSC_PAPERFORM
,
234 PaperWeight
= CDSC_PAPERWEIGHT
,
235 PaperSize
= CDSC_PAPERSIZE
,
236 // also %%Begin/EndFeature, %%Begin/EndResource
240 PageTrailer
= CDSC_PAGETRAILER
,
241 BeginPageSetup
= CDSC_BEGINPAGESETUP
,
242 EndPageSetup
= CDSC_ENDPAGESETUP
,
243 PageMedia
= CDSC_PAGEMEDIA
,
244 // also %%PaperColor, %%PaperForm, %%PaperWeight, %%PaperSize
245 PageOrientation
= CDSC_PAGEORIENTATION
,
246 PageBoundingBox
= CDSC_PAGEBOUNDINGBOX
,
247 // also %%Begin/EndFont, %%Begin/EndFeature
248 // also %%Begin/EndResource, %%Begin/EndProcSet
249 IncludeFont
= CDSC_INCLUDEFONT
,
250 ViewingOrientation
= CDSC_VIEWINGORIENTATION
,
253 Trailer
= CDSC_TRAILER
,
254 // also %%Pages, %%BoundingBox, %%Orientation, %%PageOrder,
256 // %%Page is recognised as an error
257 // also %%DocumentNeededFonts, %%DocumentSuppliedFonts
263 virtual void comment( Name name
) { std::cout
<< name
<< std::endl
; }
266 class KDSCScanHandler
;
273 /*--- Adapter for CDSC ------------------------------------------------*/
274 QString
dsc_version() const;
282 unsigned int preview() const;
283 unsigned int language_level() const;
284 unsigned int document_data() const;
286 unsigned long begincomments() const;
287 unsigned long endcomments() const;
288 unsigned long beginpreview() const;
289 unsigned long endpreview() const;
290 unsigned long begindefaults() const;
291 unsigned long enddefaults() const;
292 unsigned long beginprolog() const;
293 unsigned long endprolog() const;
294 unsigned long beginsetup() const;
295 unsigned long endsetup() const;
296 unsigned long begintrailer() const;
297 unsigned long endtrailer() const;
299 CDSCPAGE
* page() const;
301 unsigned int page_count() const;
302 unsigned int page_pages() const;
303 unsigned int page_order() const;
304 unsigned int page_orientation() const;
306 CDSCCTM
* viewing_orientation() const;
308 unsigned int media_count() const;
309 CDSCMEDIA
** media() const;
310 const CDSCMEDIA
* page_media() const;
312 #if defined(__GNUC__) && (__GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 93))
313 auto_ptr
<KDSCBBOX
> bbox() const;
314 auto_ptr
<KDSCBBOX
> page_bbox() const;
316 std::auto_ptr
<KDSCBBOX
> bbox() const;
317 std::auto_ptr
<KDSCBBOX
> page_bbox() const;
320 // CDSCDOSEPS *doseps;
322 QString
dsc_title() const;
323 QString
dsc_creator() const;
324 QString
dsc_date() const;
325 QString
dsc_for() const;
327 // unsigned int max_error
329 bool scanData( char*, unsigned int );
332 * Tidy up from incorrect DSC comments.
336 KDSCErrorHandler
* errorHandler() const;
337 void setErrorHandler( KDSCErrorHandler
* );
339 KDSCCommentHandler
* commentHandler() const;
340 void setCommentHandler( KDSCCommentHandler
* );
342 /*--- Extra methods for convenience -----------------------------------*/
343 bool isStructured() const;
345 /*--- Temporary -------------------------------------------------------*/
349 static int errorFunction( void* caller_data
, CDSC
* dsc
,
350 unsigned int explanation
,
351 const char* line
, unsigned int line_len
);
355 KDSCErrorHandler
* _errorHandler
;
356 KDSCCommentHandler
* _commentHandler
;
357 KDSCScanHandler
* _scanHandler
;
360 class KDSCScanHandler
363 virtual ~KDSCScanHandler() {}
364 KDSCScanHandler( CDSC
* cdsc
) : _cdsc( cdsc
) {}
366 virtual bool scanData( char* buf
, unsigned int count
)
368 return ( dsc_scan_data( _cdsc
, buf
, count
) >= 0 );
375 class KDSCScanHandlerByLine
: public KDSCScanHandler
378 KDSCScanHandlerByLine( CDSC
* cdsc
, KDSCCommentHandler
* commentHandler
) :
379 KDSCScanHandler( cdsc
),
380 _commentHandler( commentHandler
)
383 virtual bool scanData( char* buf
, unsigned int count
);
386 KDSCCommentHandler
* _commentHandler
;
391 // vim:sw=4:sts=4:ts=8:noet