Coverage Report

Created: 2026-01-25 07:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/kdegraphics-thumbnailers/ps/dscparse_adapter.cpp
Line
Count
Source
1
/** 
2
 * SPDX-FileCopyrightText: 2001 the KGhostView authors. See file AUTHORS.
3
 *  
4
 * SPDX-License-Identifier: GPL-2.0-or-later
5
 */
6
7
#include "dscparse_adapter.h"
8
9
using namespace std;
10
11
/*-- KDSCBBOX implementation -----------------------------------------------*/
12
13
KDSCBBOX::KDSCBBOX() :
14
0
    _llx( 0 ), _lly( 0 ),
15
0
    _urx( 0 ), _ury( 0 )
16
0
{}
17
18
KDSCBBOX::KDSCBBOX( const KDSCBBOX& b ) :
19
0
    _llx( b._llx ), _lly( b._lly ),
20
0
    _urx( b._urx ), _ury( b._ury )
21
0
{}
22
23
KDSCBBOX::KDSCBBOX( int llx, int lly, int urx, int ury ) :
24
0
    _llx( llx ), _lly( lly ), 
25
0
    _urx( urx ), _ury( ury ) 
26
0
{}
27
28
KDSCBBOX::KDSCBBOX( const CDSCBBOX& bbox ) :
29
0
    _llx( bbox.llx ), _lly( bbox.lly ), 
30
0
    _urx( bbox.urx ), _ury( bbox.ury ) 
31
0
{}
32
33
KDSCBBOX& KDSCBBOX::operator = ( const KDSCBBOX& b ) 
34
0
{ 
35
0
    _llx = b._llx; _lly = b._lly; _urx = b._urx; _ury = b._ury;
36
0
    return *this; 
37
0
}
38
39
bool KDSCBBOX::operator == ( const KDSCBBOX& b ) 
40
0
{ 
41
0
    return ( _llx == b._llx && _lly == b._lly 
42
0
    && _urx == b._urx && _ury == b._ury ); 
43
0
}
44
45
bool KDSCBBOX::operator != ( const KDSCBBOX& b ) 
46
0
{ 
47
0
    return !( *this == b ); 
48
0
}
49
50
0
int KDSCBBOX::llx() const { return _llx; }
51
0
int KDSCBBOX::lly() const { return _lly; }
52
0
int KDSCBBOX::urx() const { return _urx; }
53
0
int KDSCBBOX::ury() const { return _ury; }
54
55
0
int KDSCBBOX::width()  const { return _urx - _llx; }
56
0
int KDSCBBOX::height() const { return _ury - _lly; }
57
58
0
QSize KDSCBBOX::size() const { return QSize( width(), height() ); }
59
60
ostream& operator << ( ostream& os, const KDSCBBOX& source )
61
0
{
62
0
    os << "{ llx: "<< source.llx() << ", lly: " << source.lly()
63
0
       <<  " urx: "<< source.urx() << ", ury: " << source.ury() << " }";
64
0
    return os;
65
0
}
66
67
/*-- KDSCError implementation ----------------------------------------------*/
68
69
KDSCError::KDSCError( Type type, Severity severity, const QByteArray& line,
70
                unsigned int lineNumber ) :
71
0
    _type( type ),
72
0
    _severity( severity ),
73
0
    _line( line ),
74
0
    _lineNumber( lineNumber )
75
0
{}
76
77
KDSCError::Type KDSCError::type() const
78
0
{
79
0
    return _type;
80
0
}
81
82
KDSCError::Severity KDSCError::severity() const
83
0
{
84
0
    return _severity; 
85
0
}
86
87
QByteArray KDSCError::line() const
88
0
{
89
0
    return _line; 
90
0
}
91
92
unsigned int KDSCError::lineNumber() const
93
0
{
94
0
    return _lineNumber; 
95
0
}
96
97
/*-- KDSCOkErrorHandler implementation -------------------------------------*/
98
99
KDSCErrorHandler::Response KDSCOkErrorHandler::error( const KDSCError& err ) 
100
0
{
101
0
    cout << "KDSC: error in line " << err.lineNumber() << endl;
102
    //cout << err.line() << endl;
103
0
    return Ok;
104
0
}
105
106
/*-- KDSC implementation ---------------------------------------------------*/
107
108
KDSC::KDSC() :
109
5.38k
    _errorHandler( nullptr ),
110
5.38k
    _commentHandler( nullptr )
111
5.38k
{
112
5.38k
    _cdsc = dsc_init( this );
113
5.38k
    Q_ASSERT( _cdsc != nullptr );
114
5.38k
    _scanHandler = new KDSCScanHandler( _cdsc );
115
5.38k
}
116
117
KDSC::~KDSC()
118
5.38k
{
119
5.38k
    dsc_free( _cdsc );
120
5.38k
    delete _scanHandler;
121
5.38k
}
122
123
QString KDSC::dsc_version() const
124
0
{
125
0
    return QString( _cdsc->dsc_version );   
126
0
}
127
128
bool KDSC::dsc() const
129
0
{
130
0
    return ( _cdsc->dsc == TRUE );
131
0
}
132
133
bool KDSC::ctrld() const
134
5.27k
{
135
5.27k
    return ( _cdsc->ctrld == TRUE );
136
5.27k
}
137
138
bool KDSC::pjl() const
139
5.38k
{
140
5.38k
    return ( _cdsc->pjl == TRUE );
141
5.38k
}
142
143
bool KDSC::epsf() const
144
0
{
145
0
    return ( _cdsc->epsf == TRUE );
146
0
}
147
148
bool KDSC::pdf() const
149
0
{
150
0
    return ( _cdsc->pdf == TRUE );
151
0
}
152
153
unsigned int KDSC::preview() const
154
5.17k
{
155
5.17k
    return _cdsc->preview;
156
5.17k
}
157
158
unsigned int KDSC::language_level() const
159
0
{
160
0
    return _cdsc->language_level;
161
0
}
162
163
unsigned int KDSC::document_data() const
164
0
{
165
0
    return _cdsc->document_data;
166
0
}
167
168
unsigned long KDSC::begincomments() const
169
0
{
170
0
    return _cdsc->begincomments;
171
0
}
172
173
unsigned long KDSC::endcomments() const
174
0
{
175
0
    return _cdsc->endcomments;
176
0
}
177
178
unsigned long KDSC::beginpreview() const
179
0
{
180
0
    return _cdsc->beginpreview;
181
0
}
182
183
unsigned long KDSC::endpreview() const
184
0
{
185
0
    return _cdsc->endpreview;
186
0
}
187
188
unsigned long KDSC::begindefaults() const
189
0
{
190
0
    return _cdsc->begindefaults;
191
0
}
192
193
unsigned long KDSC::enddefaults() const
194
0
{
195
0
    return _cdsc->enddefaults;
196
0
}
197
198
unsigned long KDSC::beginprolog() const
199
0
{
200
0
    return _cdsc->beginprolog;
201
0
}
202
203
unsigned long KDSC::endprolog() const
204
0
{
205
0
    return _cdsc->endprolog;
206
0
}
207
208
unsigned long KDSC::beginsetup() const
209
0
{
210
0
    return _cdsc->beginsetup;
211
0
}
212
213
unsigned long KDSC::endsetup() const
214
0
{
215
0
    return _cdsc->endsetup;
216
0
}
217
218
unsigned long KDSC::begintrailer() const
219
0
{
220
0
    return _cdsc->begintrailer;
221
0
}
222
223
unsigned long KDSC::endtrailer() const
224
0
{
225
0
    return _cdsc->endtrailer;
226
0
}
227
228
CDSCPAGE* KDSC::page() const
229
0
{
230
0
    return _cdsc->page;
231
0
}
232
233
unsigned int KDSC::page_count() const
234
0
{
235
0
    return _cdsc->page_count;
236
0
}
237
238
unsigned int KDSC::page_pages() const
239
0
{
240
0
    return _cdsc->page_pages;
241
0
}
242
243
unsigned int KDSC::page_order() const
244
0
{
245
0
    return _cdsc->page_order;
246
0
}
247
248
unsigned int KDSC::page_orientation() const
249
0
{
250
0
    return _cdsc->page_orientation;
251
0
}
252
253
CDSCCTM* KDSC::viewing_orientation() const
254
0
{
255
0
    return _cdsc->viewing_orientation;
256
0
}
257
258
unsigned int KDSC::media_count() const
259
0
{
260
0
    return _cdsc->media_count;
261
0
}
262
263
CDSCMEDIA** KDSC::media() const
264
0
{
265
0
    return _cdsc->media;
266
0
}
267
268
const CDSCMEDIA* KDSC::page_media() const
269
0
{
270
0
    return _cdsc->page_media;
271
0
}
272
273
std::unique_ptr<KDSCBBOX> KDSC::bbox() const
274
5.17k
{
275
5.17k
    if( _cdsc->bbox == nullptr )
276
5.17k
  return nullptr;
277
0
    else
278
0
  return std::make_unique<KDSCBBOX>( *_cdsc->bbox );
279
5.17k
}
280
281
std::unique_ptr<KDSCBBOX> KDSC::page_bbox() const
282
0
{
283
0
    if( _cdsc->page_bbox == nullptr )
284
0
  return nullptr;
285
0
    else
286
0
  return std::make_unique<KDSCBBOX>( *_cdsc->page_bbox );
287
0
}
288
289
QString KDSC::dsc_title() const
290
0
{
291
0
    return QString( _cdsc->dsc_title );
292
0
}
293
294
QString KDSC::dsc_creator() const
295
0
{
296
0
    return QString( _cdsc->dsc_creator );
297
0
}
298
299
QString KDSC::dsc_date() const
300
0
{
301
0
    return QString( _cdsc->dsc_date );
302
0
}
303
304
QString KDSC::dsc_for() const
305
0
{
306
0
    return QString( _cdsc->dsc_for );
307
0
}
308
309
bool KDSC::scanData( char* buffer, unsigned int count )
310
18.0k
{
311
18.0k
    return _scanHandler->scanData( buffer, count );
312
18.0k
}
313
314
int KDSC::fixup()
315
0
{
316
0
    return dsc_fixup( _cdsc );
317
0
}
318
319
KDSCErrorHandler* KDSC::errorHandler() const
320
0
{
321
0
    return _errorHandler;
322
0
}
323
324
void KDSC::setErrorHandler( KDSCErrorHandler* errorHandler )
325
0
{
326
0
    _errorHandler = errorHandler;
327
0
    if( errorHandler == nullptr )
328
0
  dsc_set_error_function( _cdsc, nullptr );
329
0
    else
330
0
  dsc_set_error_function( _cdsc, &errorFunction );
331
0
}
332
333
KDSCCommentHandler* KDSC::commentHandler() const
334
0
{
335
0
    return _commentHandler;
336
0
}
337
338
void KDSC::setCommentHandler( KDSCCommentHandler* commentHandler )
339
5.38k
{
340
5.38k
    if( _commentHandler != nullptr && commentHandler == nullptr )
341
0
    {
342
0
  delete _scanHandler;
343
0
  _scanHandler = new KDSCScanHandler( _cdsc );
344
0
    }
345
5.38k
    else if( _commentHandler == nullptr && commentHandler != nullptr )
346
5.38k
    {
347
5.38k
  delete _scanHandler;
348
5.38k
  _scanHandler = new KDSCScanHandlerByLine( _cdsc, commentHandler );
349
5.38k
    }
350
5.38k
    _commentHandler = commentHandler;
351
5.38k
}
352
353
bool KDSC::isStructured() const 
354
0
{
355
0
    return epsf() ? ( page_count() > 1 ) : ( page_count() > 0 );
356
0
}
357
358
CDSC* KDSC::cdsc() const
359
0
{
360
0
    return _cdsc;
361
0
}
362
363
int KDSC::errorFunction( void* caller_data, CDSC* dsc,
364
  unsigned int explanation, const char* line, unsigned int line_len )
365
0
{
366
0
    KDSCError error( 
367
0
      static_cast< KDSCError::Type >( explanation ), 
368
0
      static_cast< KDSCError::Severity >( dsc->severity[explanation] ),
369
0
      QByteArray( line, line_len + 1 ),
370
0
      dsc->line_count
371
0
    );
372
    
373
0
    KDSC* kdsc = static_cast< KDSC* >( caller_data );
374
0
    Q_ASSERT( kdsc );
375
    
376
0
    return kdsc->errorHandler()->error( error );
377
0
}
378
379
bool KDSCScanHandlerByLine::scanData( char* buf, unsigned int count )
380
18.0k
{
381
18.0k
    char* lineStart = buf;
382
18.0k
    char* it = buf;
383
57.6M
    while( it < buf + count )
384
57.5M
    {
385
57.5M
  if( *it++ == '\n' )
386
2.12M
  {
387
2.12M
      int retval = dsc_scan_data( _cdsc, lineStart, it - lineStart );
388
2.12M
      if( retval < 0 ) 
389
0
    return false;
390
2.12M
      else if( retval > 0 )
391
1.97M
      {
392
1.97M
    _commentHandler->comment( 
393
1.97M
      static_cast<KDSCCommentHandler::Name>( retval ) );
394
1.97M
      }
395
2.12M
      lineStart = it;
396
2.12M
  }
397
57.5M
    }
398
  
399
18.0k
    if( it != lineStart )
400
17.2k
    {
401
  // Scan the remaining part of the string.
402
17.2k
  return ( dsc_scan_data( _cdsc, lineStart, it - lineStart ) < 0 );
403
17.2k
    }
404
763
    else
405
763
  return true;
406
18.0k
}
407
408
// vim:sw=4:sts=4:ts=8:noet