summaryrefslogtreecommitdiff
authorsandman <sandman>2002-04-16 22:16:56 (UTC)
committer sandman <sandman>2002-04-16 22:16:56 (UTC)
commitece373988ee95e4dc3c22eeb012a077595740057 (patch) (unidiff)
treef28fc0976feae59e9b31eae7c17611943cb8a0f2
parente7e4ecaae60f5444c4ec581077f91e6b412c780c (diff)
downloadopie-ece373988ee95e4dc3c22eeb012a077595740057.zip
opie-ece373988ee95e4dc3c22eeb012a077595740057.tar.gz
opie-ece373988ee95e4dc3c22eeb012a077595740057.tar.bz2
- fixed a bug with zero-length strings
- introduces macros for fast PDF-debugging - speedup in math-emulation (rounding,sqrt,fabs) - libstdc++ not needed anymore
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/QOutputDev.cpp135
-rw-r--r--noncore/unsupported/qpdf/fixed.h28
-rw-r--r--noncore/unsupported/qpdf/qpdf.pro2
3 files changed, 91 insertions, 74 deletions
diff --git a/noncore/unsupported/qpdf/QOutputDev.cpp b/noncore/unsupported/qpdf/QOutputDev.cpp
index 02f269d..15a58b1 100644
--- a/noncore/unsupported/qpdf/QOutputDev.cpp
+++ b/noncore/unsupported/qpdf/QOutputDev.cpp
@@ -32,40 +32,36 @@
32#include "TextOutputDev.h" 32#include "TextOutputDev.h"
33#include "QOutputDev.h" 33#include "QOutputDev.h"
34 34
35 35
36#include <qpixmap.h> 36#include <qpixmap.h>
37#include <qimage.h> 37#include <qimage.h>
38#include <qpainter.h> 38#include <qpainter.h>
39#include <qdict.h> 39#include <qdict.h>
40#include <qtimer.h> 40#include <qtimer.h>
41#include <qapplication.h> 41#include <qapplication.h>
42#include <qclipboard.h> 42#include <qclipboard.h>
43 43
44 //#define QPDFDBG(x) x // special debug mode
45 #define QPDFDBG(x) // normal compilation
46
44 47
45//------------------------------------------------------------------------ 48//------------------------------------------------------------------------
46// Constants and macros 49// Constants and macros
47//------------------------------------------------------------------------ 50//------------------------------------------------------------------------
48 51
49 52
50static inline int q_rnd ( fp_t d )
51{
52 //qDebug ( "Q_RND: %f -> %d\n", (double) d, (int) ( d >= 0 ? d +0.5 : d - 0.5 ));
53
54 return (int) ( d >= 0 ? d + 0.5 : d - 0.5 );
55}
56
57static inline QColor q_col ( const GfxRGB &rgb ) 53static inline QColor q_col ( const GfxRGB &rgb )
58{ 54{
59 return QColor ( q_rnd ( rgb. r * 255 ), q_rnd ( rgb. g * 255 ), q_rnd ( rgb. b * 255 )); 55 return QColor ( lrint ( rgb. r * 255 ), lrint ( rgb. g * 255 ), lrint ( rgb. b * 255 ));
60} 56}
61 57
62 58
63//------------------------------------------------------------------------ 59//------------------------------------------------------------------------
64// Font substitutions 60// Font substitutions
65//------------------------------------------------------------------------ 61//------------------------------------------------------------------------
66 62
67struct QOutFontSubst { 63struct QOutFontSubst {
68 char * m_name; 64 char * m_name;
69 char * m_sname; 65 char * m_sname;
70 bool m_bold; 66 bool m_bold;
71 bool m_italic; 67 bool m_italic;
@@ -101,38 +97,38 @@ static QOutFontSubst qStdFonts [] = {
101QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp_t m22 ) 97QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp_t m22 )
102{ 98{
103 static QDict<QOutFontSubst> stdfonts; 99 static QDict<QOutFontSubst> stdfonts;
104 100
105 // build dict for std. fonts on first invocation 101 // build dict for std. fonts on first invocation
106 if ( stdfonts. isEmpty ( )) { 102 if ( stdfonts. isEmpty ( )) {
107 for ( QOutFontSubst *ptr = qStdFonts; ptr-> m_name; ptr++ ) { 103 for ( QOutFontSubst *ptr = qStdFonts; ptr-> m_name; ptr++ ) {
108 stdfonts. insert ( QString ( ptr-> m_name ), ptr ); 104 stdfonts. insert ( QString ( ptr-> m_name ), ptr );
109 } 105 }
110 } 106 }
111 107
112 // compute size and normalized transform matrix 108 // compute size and normalized transform matrix
113 int size = q_rnd ( sqrt ( m21 * m21 + m22 * m22 )); 109 int size = lrint ( sqrt ( m21 * m21 + m22 * m22 ));
114 110
115 /*qDebug ( "SET FONT: Name=%s, Size=%d, Bold=%d, Italic=%d, Mono=%d, Serif=%d, Symbol=%d, CID=%d, EmbFN=%s, M=(%f,%f,%f,%f)\n", 111 QPDFDBG( printf ( "SET FONT: Name=%s, Size=%d, Bold=%d, Italic=%d, Mono=%d, Serif=%d, Symbol=%d, CID=%d, EmbFN=%s, M=(%f,%f,%f,%f)\n",
116 (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ), 112 (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ),
117 size, 113 size,
118 gfxFont-> isBold ( ), 114 gfxFont-> isBold ( ),
119 gfxFont-> isItalic ( ), 115 gfxFont-> isItalic ( ),
120 gfxFont-> isFixedWidth ( ), 116 gfxFont-> isFixedWidth ( ),
121 gfxFont-> isSerif ( ), 117 gfxFont-> isSerif ( ),
122 gfxFont-> isSymbolic ( ), 118 gfxFont-> isSymbolic ( ),
123 gfxFont-> isCIDFont ( ), 119 gfxFont-> isCIDFont ( ),
124 ( gfxFont-> getEmbeddedFontName ( ) ? gfxFont-> getEmbeddedFontName ( ) : "<n/a>" ), 120 ( gfxFont-> getEmbeddedFontName ( ) ? gfxFont-> getEmbeddedFontName ( ) : "<n/a>" ),
125 (double) m11, (double) m12, (double) m21, (double) m22 ); 121 (double) m11, (double) m12, (double) m21, (double) m22 ));
126*/ 122
127 123
128 QString fname (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ); 124 QString fname (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" );
129 125
130 QFont f; 126 QFont f;
131 f. setPixelSize ( size > 0 ? size : 8 ); // type3 fonts misbehave sometimes 127 f. setPixelSize ( size > 0 ? size : 8 ); // type3 fonts misbehave sometimes
132 128
133 // fast lookup for std. fonts 129 // fast lookup for std. fonts
134 QOutFontSubst *subst = stdfonts [fname]; 130 QOutFontSubst *subst = stdfonts [fname];
135 131
136 if ( subst ) { 132 if ( subst ) {
137 if ( subst-> m_sname ) 133 if ( subst-> m_sname )
138 f. setFamily ( subst-> m_sname ); 134 f. setFamily ( subst-> m_sname );
@@ -176,45 +172,47 @@ QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp
176 172
177 173
178 174
179//------------------------------------------------------------------------ 175//------------------------------------------------------------------------
180// QOutputDev 176// QOutputDev
181//------------------------------------------------------------------------ 177//------------------------------------------------------------------------
182 178
183QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrollView ( parent, name, WRepaintNoErase | WResizeNoErase | flags ) 179QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrollView ( parent, name, WRepaintNoErase | WResizeNoErase | flags )
184{ 180{
185 m_pixmap = 0; 181 m_pixmap = 0;
186 m_painter = 0; 182 m_painter = 0;
187 183
184 m_use_string = true;
185
188 // create text object 186 // create text object
189 m_text = new TextPage ( gFalse ); 187 m_text = new TextPage ( gFalse );
190} 188}
191 189
192QOutputDev::~QOutputDev ( ) 190QOutputDev::~QOutputDev ( )
193{ 191{
194 delete m_painter; 192 delete m_painter;
195 delete m_pixmap; 193 delete m_pixmap;
196 delete m_text; 194 delete m_text;
197} 195}
198 196
199 197
200void QOutputDev::startPage ( int /*pageNum*/, GfxState *state ) 198void QOutputDev::startPage ( int /*pageNum*/, GfxState *state )
201{ 199{
202 delete m_pixmap; 200 delete m_pixmap;
203 delete m_painter; 201 delete m_painter;
204 202
205 m_pixmap = new QPixmap ( q_rnd ( state-> getPageWidth ( )), q_rnd ( state-> getPageHeight ( ))); 203 m_pixmap = new QPixmap ( lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( )));
206 m_painter = new QPainter ( m_pixmap ); 204 m_painter = new QPainter ( m_pixmap );
207 205
208 //qDebug ( "NEW PIXMAP (%d x %d)\n", q_rnd ( state-> getPageWidth ( )), q_rnd ( state-> getPageHeight ( ))); 206 QPDFDBG( printf ( "NEW PIXMAP (%ld x %ld)\n", lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( ))));
209 207
210 resizeContents ( m_pixmap-> width ( ), m_pixmap-> height ( )); 208 resizeContents ( m_pixmap-> width ( ), m_pixmap-> height ( ));
211 setContentsPos ( 0, 0 ); 209 setContentsPos ( 0, 0 );
212 210
213 m_pixmap-> fill ( white ); // clear window 211 m_pixmap-> fill ( white ); // clear window
214 m_text-> clear ( ); // cleat text object 212 m_text-> clear ( ); // cleat text object
215 viewport ( )-> repaint ( ); 213 viewport ( )-> repaint ( );
216} 214}
217 215
218void QOutputDev::endPage ( ) 216void QOutputDev::endPage ( )
219{ 217{
220 m_text-> coalesce ( ); 218 m_text-> coalesce ( );
@@ -237,36 +235,36 @@ void QOutputDev::drawLink ( Link *link, Catalog */*catalog*/ )
237 cvtUserToDev ( x1, y1, &x, &y ); 235 cvtUserToDev ( x1, y1, &x, &y );
238 cvtUserToDev ( x2, y2, &dx, &dy ); 236 cvtUserToDev ( x2, y2, &dx, &dy );
239 237
240 QPen oldpen = m_painter-> pen ( ); 238 QPen oldpen = m_painter-> pen ( );
241 m_painter-> setPen ( blue ); 239 m_painter-> setPen ( blue );
242 m_painter-> drawRect ( x, y, dx, dy ); 240 m_painter-> drawRect ( x, y, dx, dy );
243 m_painter-> setPen ( oldpen ); 241 m_painter-> setPen ( oldpen );
244 } 242 }
245} 243}
246 244
247void QOutputDev::saveState ( GfxState */*state*/ ) 245void QOutputDev::saveState ( GfxState */*state*/ )
248{ 246{
249 //qDebug ( "SAVE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( )); 247 QPDFDBG( printf ( "SAVE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( )));
250 248
251 m_painter-> save ( ); 249 m_painter-> save ( );
252} 250}
253 251
254void QOutputDev::restoreState ( GfxState */*state*/ ) 252void QOutputDev::restoreState ( GfxState */*state*/ )
255{ 253{
256 m_painter-> restore ( ); 254 m_painter-> restore ( );
257 255
258 //m_painter-> setClipRegion ( QRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( ))); 256 //m_painter-> setClipRegion ( QRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( )));
259 //m_painter-> setClipping ( false ); 257 //m_painter-> setClipping ( false );
260 //qDebug ( "RESTORE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( )); 258 QPDFDBG ( printf ( "RESTORE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( )));
261} 259}
262 260
263void QOutputDev::updateAll ( GfxState *state ) 261void QOutputDev::updateAll ( GfxState *state )
264{ 262{
265 updateLineAttrs ( state, gTrue ); 263 updateLineAttrs ( state, gTrue );
266 //updateFlatness ( state ); 264 //updateFlatness ( state );
267 //updateMiterLimit ( state ); 265 //updateMiterLimit ( state );
268 updateFillColor ( state ); 266 updateFillColor ( state );
269 updateStrokeColor ( state ); 267 updateStrokeColor ( state );
270 updateFont ( state ); 268 updateFont ( state );
271} 269}
272 270
@@ -274,59 +272,59 @@ void QOutputDev::updateCTM ( GfxState *state, fp_t /*m11*/, fp_t /*m12*/, fp_t /
274{ 272{
275 updateLineAttrs ( state, gTrue ); 273 updateLineAttrs ( state, gTrue );
276} 274}
277 275
278void QOutputDev::updateLineDash ( GfxState *state ) 276void QOutputDev::updateLineDash ( GfxState *state )
279{ 277{
280 updateLineAttrs ( state, gTrue ); 278 updateLineAttrs ( state, gTrue );
281} 279}
282 280
283void QOutputDev::updateFlatness ( GfxState */*state*/ ) 281void QOutputDev::updateFlatness ( GfxState */*state*/ )
284{ 282{
285 // not supported 283 // not supported
286 //qDebug ( "updateFlatness not supported !\n" ); 284 QPDFDBG( printf ( "updateFlatness not supported !\n" ));
287} 285}
288 286
289void QOutputDev::updateLineJoin ( GfxState *state ) 287void QOutputDev::updateLineJoin ( GfxState *state )
290{ 288{
291 updateLineAttrs ( state, gFalse ); 289 updateLineAttrs ( state, gFalse );
292} 290}
293 291
294void QOutputDev::updateLineCap ( GfxState *state ) 292void QOutputDev::updateLineCap ( GfxState *state )
295{ 293{
296 updateLineAttrs ( state, gFalse ); 294 updateLineAttrs ( state, gFalse );
297} 295}
298 296
299// unimplemented 297// unimplemented
300void QOutputDev::updateMiterLimit ( GfxState */*state*/ ) 298void QOutputDev::updateMiterLimit ( GfxState */*state*/ )
301{ 299{
302 //qDebug ( "updateMiterLimit not supported !\n" ); 300 QPDFDBG( printf ( "updateMiterLimit not supported !\n" ));
303} 301}
304 302
305void QOutputDev::updateLineWidth ( GfxState *state ) 303void QOutputDev::updateLineWidth ( GfxState *state )
306{ 304{
307 updateLineAttrs ( state, gFalse ); 305 updateLineAttrs ( state, gFalse );
308} 306}
309 307
310void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash ) 308void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash )
311{ 309{
312 fp_t *dashPattern; 310 fp_t *dashPattern;
313 int dashLength; 311 int dashLength;
314 fp_t dashStart; 312 fp_t dashStart;
315 313
316 Qt::PenCapStyle cap; 314 Qt::PenCapStyle cap;
317 Qt::PenJoinStyle join; 315 Qt::PenJoinStyle join;
318 int width; 316 int width;
319 317
320 width = q_rnd ( state-> getTransformedLineWidth ( )); 318 width = lrint ( state-> getTransformedLineWidth ( ));
321 319
322 switch ( state-> getLineCap ( )) { 320 switch ( state-> getLineCap ( )) {
323 case 0: cap = FlatCap; break; 321 case 0: cap = FlatCap; break;
324 case 1: cap = RoundCap; break; 322 case 1: cap = RoundCap; break;
325 case 2: cap = SquareCap; break; 323 case 2: cap = SquareCap; break;
326 default: 324 default:
327 qWarning ( "Bad line cap style (%d)\n", state-> getLineCap ( )); 325 qWarning ( "Bad line cap style (%d)\n", state-> getLineCap ( ));
328 cap = FlatCap; 326 cap = FlatCap;
329 break; 327 break;
330 } 328 }
331 329
332 switch (state->getLineJoin()) { 330 switch (state->getLineJoin()) {
@@ -400,36 +398,36 @@ void QOutputDev::updateFont ( GfxState *state )
400 m_painter-> setFont ( font ); 398 m_painter-> setFont ( font );
401 m_text-> updateFont ( state ); 399 m_text-> updateFont ( state );
402} 400}
403 401
404void QOutputDev::stroke ( GfxState *state ) 402void QOutputDev::stroke ( GfxState *state )
405{ 403{
406 QPointArray points; 404 QPointArray points;
407 QArray<int> lengths; 405 QArray<int> lengths;
408 406
409 // transform points 407 // transform points
410 int n = convertPath ( state, points, lengths ); 408 int n = convertPath ( state, points, lengths );
411 409
412 //qDebug ( "DRAWING: %d POLYS\n", n ); 410 QPDFDBG( printf ( "DRAWING: %d POLYS\n", n ));
413 411
414 // draw each subpath 412 // draw each subpath
415 int j = 0; 413 int j = 0;
416 for ( int i = 0; i < n; i++ ) { 414 for ( int i = 0; i < n; i++ ) {
417 int len = lengths [i]; 415 int len = lengths [i];
418 416
419 if ( len >= 2 ) { 417 if ( len >= 2 ) {
420 // qDebug ( " - POLY %d: ", i ); 418 QPDFDBG( printf ( " - POLY %d: ", i ));
421 // for ( int ii = 0; ii < len; ii++ ) 419 QPDFDBG( for ( int ii = 0; ii < len; ii++ ))
422 // qDebug ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )); 420 QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )));
423 // qDebug ( "\n" ); 421 QPDFDBG( printf ( "\n" ));
424 422
425 m_painter-> drawPolyline ( points, j, len ); 423 m_painter-> drawPolyline ( points, j, len );
426 } 424 }
427 j += len; 425 j += len;
428 } 426 }
429 qApp-> processEvents ( ); 427 qApp-> processEvents ( );
430} 428}
431 429
432void QOutputDev::fill ( GfxState *state ) 430void QOutputDev::fill ( GfxState *state )
433{ 431{
434 doFill ( state, true ); 432 doFill ( state, true );
435} 433}
@@ -447,39 +445,39 @@ void QOutputDev::eoFill ( GfxState *state )
447// polygon, it also draws lines around the border. This is done 445// polygon, it also draws lines around the border. This is done
448// only for single-component polygons, since it's not very 446// only for single-component polygons, since it's not very
449// compatible with the compound polygon kludge (see convertPath()). 447// compatible with the compound polygon kludge (see convertPath()).
450// 448//
451void QOutputDev::doFill ( GfxState *state, bool winding ) 449void QOutputDev::doFill ( GfxState *state, bool winding )
452{ 450{
453 QPointArray points; 451 QPointArray points;
454 QArray<int> lengths; 452 QArray<int> lengths;
455 453
456 // transform points 454 // transform points
457 int n = convertPath ( state, points, lengths ); 455 int n = convertPath ( state, points, lengths );
458 456
459 //qDebug ( "FILLING: %d POLYS\n", n ); 457 QPDFDBG( printf ( "FILLING: %d POLYS\n", n ));
460 458
461 QPen oldpen = m_painter-> pen ( ); 459 QPen oldpen = m_painter-> pen ( );
462 m_painter-> setPen ( QPen ( NoPen )); 460 m_painter-> setPen ( QPen ( NoPen ));
463 461
464 // draw each subpath 462 // draw each subpath
465 int j = 0; 463 int j = 0;
466 for ( int i = 0; i < n; i++ ) { 464 for ( int i = 0; i < n; i++ ) {
467 int len = lengths [i]; 465 int len = lengths [i];
468 466
469 if ( len >= 3 ) { 467 if ( len >= 3 ) {
470 // qDebug ( " - POLY %d: ", i ); 468 QPDFDBG( printf ( " - POLY %d: ", i ));
471 // for ( int ii = 0; ii < len; ii++ ) 469 QPDFDBG( for ( int ii = 0; ii < len; ii++ ))
472 // qDebug ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )); 470 QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )));
473 // qDebug ( "\n" ); 471 QPDFDBG( printf ( "\n" ));
474 472
475 m_painter-> drawPolygon ( points, winding, j, len ); 473 m_painter-> drawPolygon ( points, winding, j, len );
476 } 474 }
477 j += len; 475 j += len;
478 } 476 }
479 m_painter-> setPen ( oldpen ); 477 m_painter-> setPen ( oldpen );
480 478
481 qApp-> processEvents ( ); 479 qApp-> processEvents ( );
482} 480}
483 481
484void QOutputDev::clip ( GfxState *state ) 482void QOutputDev::clip ( GfxState *state )
485{ 483{
@@ -492,39 +490,38 @@ void QOutputDev::eoClip ( GfxState *state )
492} 490}
493 491
494void QOutputDev::doClip ( GfxState *state, bool winding ) 492void QOutputDev::doClip ( GfxState *state, bool winding )
495{ 493{
496 QPointArray points; 494 QPointArray points;
497 QArray<int> lengths; 495 QArray<int> lengths;
498 496
499 // transform points 497 // transform points
500 int n = convertPath ( state, points, lengths ); 498 int n = convertPath ( state, points, lengths );
501 499
502 QRegion region; 500 QRegion region;
503 501
504 //qDebug ( "CLIPPING: %d POLYS\n", n ); 502 QPDFDBG( printf ( "CLIPPING: %d POLYS\n", n ));
505 503
506 // draw each subpath 504 // draw each subpath
507 int j = 0; 505 int j = 0;
508 for ( int i = 0; i < n; i++ ) { 506 for ( int i = 0; i < n; i++ ) {
509 int len = lengths [i]; 507 int len = lengths [i];
510 508
511 if ( len >= 3 ) { 509 if ( len >= 3 ) {
512 QPointArray dummy; 510 QPointArray dummy;
513 dummy. setRawData ( points. data ( ) + j, len ); 511 dummy. setRawData ( points. data ( ) + j, len );
514 512
515 // qDebug ( " - POLY %d: ", i ); 513 QPDFDBG( printf ( " - POLY %d: ", i ));
516 // for ( int ii = 0; ii < len; ii++ ) 514 QPDFDBG( for ( int ii = 0; ii < len; ii++ ) printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )));
517 // qDebug ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )); 515 QPDFDBG( printf ( "\n" ));
518 // qDebug ( "\n" );
519 516
520 region |= QRegion ( dummy, winding ); 517 region |= QRegion ( dummy, winding );
521 518
522 dummy. resetRawData ( points. data ( ) + j, len ); 519 dummy. resetRawData ( points. data ( ) + j, len );
523 } 520 }
524 j += len; 521 j += len;
525 } 522 }
526 523
527 if ( m_painter-> hasClipping ( )) 524 if ( m_painter-> hasClipping ( ))
528 region &= m_painter-> clipRegion ( ); 525 region &= m_painter-> clipRegion ( );
529 526
530 //m_painter-> setClipRegion ( region ); 527 //m_painter-> setClipRegion ( region );
@@ -572,95 +569,95 @@ int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArr
572 569
573 int m = subpath-> getNumPoints ( ); 570 int m = subpath-> getNumPoints ( );
574 int i = 0; 571 int i = 0;
575 572
576 while ( i < m ) { 573 while ( i < m ) {
577 if ( i >= 1 && subpath-> getCurve ( i )) { 574 if ( i >= 1 && subpath-> getCurve ( i )) {
578 state-> transform ( subpath-> getX ( i - 1 ), subpath-> getY ( i - 1 ), &x0, &y0 ); 575 state-> transform ( subpath-> getX ( i - 1 ), subpath-> getY ( i - 1 ), &x0, &y0 );
579 state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 ); 576 state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 );
580 state-> transform ( subpath-> getX ( i + 1 ), subpath-> getY ( i + 1 ), &x2, &y2 ); 577 state-> transform ( subpath-> getX ( i + 1 ), subpath-> getY ( i + 1 ), &x2, &y2 );
581 state-> transform ( subpath-> getX ( i + 2 ), subpath-> getY ( i + 2 ), &x3, &y3 ); 578 state-> transform ( subpath-> getX ( i + 2 ), subpath-> getY ( i + 2 ), &x3, &y3 );
582 579
583 QPointArray tmp; 580 QPointArray tmp;
584 tmp. setPoints ( 4, q_rnd ( x0 ), q_rnd ( y0 ), q_rnd ( x1 ), q_rnd ( y1 ), 581 tmp. setPoints ( 4, lrint ( x0 ), lrint ( y0 ), lrint ( x1 ), lrint ( y1 ),
585 q_rnd ( x2 ), q_rnd ( y2 ), q_rnd ( x3 ), q_rnd ( y3 )); 582 lrint ( x2 ), lrint ( y2 ), lrint ( x3 ), lrint ( y3 ));
586 583
587#if QT_VERSION < 300 584#if QT_VERSION < 300
588 tmp = tmp. quadBezier ( ); 585 tmp = tmp. quadBezier ( );
589 586
590 for ( uint loop = 0; loop < tmp. count ( ); loop++ ) { 587 for ( uint loop = 0; loop < tmp. count ( ); loop++ ) {
591 QPoint p = tmp. point ( loop ); 588 QPoint p = tmp. point ( loop );
592 points. putPoints ( points. count ( ), 1, p. x ( ), p. y ( )); 589 points. putPoints ( points. count ( ), 1, p. x ( ), p. y ( ));
593 } 590 }
594#else 591#else
595 tmp = tmp. cubicBezier ( ); 592 tmp = tmp. cubicBezier ( );
596 points. putPoints ( points. count ( ), tmp. count ( ), tmp ); 593 points. putPoints ( points. count ( ), tmp. count ( ), tmp );
597#endif 594#endif
598 595
599 i += 3; 596 i += 3;
600 } 597 }
601 else { 598 else {
602 state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 ); 599 state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 );
603 600
604 points. putPoints ( points. count ( ), 1, q_rnd ( x1 ), q_rnd ( y1 )); 601 points. putPoints ( points. count ( ), 1, lrint ( x1 ), lrint ( y1 ));
605 ++i; 602 ++i;
606 } 603 }
607 } 604 }
608 return points. count ( ) - oldcnt; 605 return points. count ( ) - oldcnt;
609} 606}
610 607
611 608
612void QOutputDev::beginString ( GfxState *state, GString */*s*/ ) 609void QOutputDev::beginString ( GfxState *state, GString */*s*/ )
613{ 610{
614 m_text-> beginString ( state ); 611 m_text-> beginString ( state );
615} 612}
616 613
617void QOutputDev::endString ( GfxState */*state*/ ) 614void QOutputDev::endString ( GfxState */*state*/ )
618{ 615{
619 m_text-> endString ( ); 616 m_text-> endString ( );
620} 617}
621 618
622void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, 619void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y,
623 fp_t dx, fp_t dy, fp_t originX, fp_t originY, 620 fp_t dx, fp_t dy, fp_t originX, fp_t originY,
624 CharCode code, Unicode *u, int uLen ) 621 CharCode code, Unicode *u, int uLen )
625{ 622{
626 fp_t x1, y1, dx1, dy1; 623 fp_t x1, y1, dx1, dy1;
627 624
628 m_text-> addChar ( state, x, y, dx, dy, u, uLen ); 625 if ( uLen > 0 )
629 626 m_text-> addChar ( state, x, y, dx, dy, u, uLen );
630 627
631 // check for invisible text -- this is used by Acrobat Capture 628 // check for invisible text -- this is used by Acrobat Capture
632 if (( state-> getRender ( ) & 3 ) == 3 ) { 629 if (( state-> getRender ( ) & 3 ) == 3 ) {
633 return; 630 return;
634 } 631 }
635 632
636 x -= originX; 633 x -= originX;
637 y -= originY; 634 y -= originY;
638 state-> transform ( x, y, &x1, &y1 ); 635 state-> transform ( x, y, &x1, &y1 );
639 state-> transformDelta ( dx, dy, &dx1, &dy1 ); 636 state-> transformDelta ( dx, dy, &dx1, &dy1 );
640 637
641 638
642 if ( uLen > 0 ) { 639 if ( uLen > 0 ) {
643 QString str; 640 QString str;
644 QFontMetrics fm = m_painter-> fontMetrics ( ); 641 QFontMetrics fm = m_painter-> fontMetrics ( );
645 642
646 for ( int i = 0; i < uLen; i++ ) { 643 for ( int i = 0; i < uLen; i++ ) {
647 QChar c = QChar ( u [i] ); 644 QChar c = QChar ( u [i] );
648 645
649 if ( fm. inFont ( c )) { 646 if ( fm. inFont ( c )) {
650 str [i] = QChar ( u [i] ); 647 str [i] = QChar ( u [i] );
651 } 648 }
652 else { 649 else {
653 str [i] = ' '; 650 str [i] = ' ';
654 // qDebug ( "CHARACTER NOT IN FONT: %hx\n", c. unicode ( )); 651 QPDFDBG( printf ( "CHARACTER NOT IN FONT: %hx\n", c. unicode ( )));
655 } 652 }
656 } 653 }
657 654
658 if (( uLen == 1 ) && ( str [0] == ' ' )) 655 if (( uLen == 1 ) && ( str [0] == ' ' ))
659 return; 656 return;
660 657
661 658
662 fp_t m11, m12, m21, m22; 659 fp_t m11, m12, m21, m22;
663 660
664 state-> getFontTransMat ( &m11, &m12, &m21, &m22 ); 661 state-> getFontTransMat ( &m11, &m12, &m21, &m22 );
665 m11 *= state-> getHorizScaling ( ); 662 m11 *= state-> getHorizScaling ( );
666 m12 *= state-> getHorizScaling ( ); 663 m12 *= state-> getHorizScaling ( );
@@ -668,55 +665,55 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y,
668 fp_t fsize = m_painter-> font ( ). pixelSize ( ); 665 fp_t fsize = m_painter-> font ( ). pixelSize ( );
669 666
670#ifndef QT_NO_TRANSFORMATIONS 667#ifndef QT_NO_TRANSFORMATIONS
671 QWMatrix oldmat; 668 QWMatrix oldmat;
672 669
673 bool dorot = (( m12 < -0.1 ) || ( m12 > 0.1 )) && (( m21 < -0.1 ) || ( m21 > 0.1 )); 670 bool dorot = (( m12 < -0.1 ) || ( m12 > 0.1 )) && (( m21 < -0.1 ) || ( m21 > 0.1 ));
674 671
675 if ( dorot ) { 672 if ( dorot ) {
676 oldmat = m_painter-> worldMatrix ( ); 673 oldmat = m_painter-> worldMatrix ( );
677 674
678 cerr << endl << "ROTATED: " << m11 << ", " << m12 << ", " << m21 << ", " << m22 << " / SIZE: " << fsize << " / TEXT: " << str. local8Bit ( ) << endl << endl; 675 cerr << endl << "ROTATED: " << m11 << ", " << m12 << ", " << m21 << ", " << m22 << " / SIZE: " << fsize << " / TEXT: " << str. local8Bit ( ) << endl << endl;
679 676
680 QWMatrix mat ( q_rnd ( m11 / fsize ), q_rnd ( m12 / fsize ), -q_rnd ( m21 / fsize ), -q_rnd ( m22 / fsize ), q_rnd ( x1 ), q_rnd ( y1 )); 677 QWMatrix mat ( lrint ( m11 / fsize ), lrint ( m12 / fsize ), -lrint ( m21 / fsize ), -lrint ( m22 / fsize ), lrint ( x1 ), lrint ( y1 ));
681 678
682 m_painter-> setWorldMatrix ( mat ); 679 m_painter-> setWorldMatrix ( mat );
683 680
684 x1 = 0; 681 x1 = 0;
685 y1 = 0; 682 y1 = 0;
686 } 683 }
687#endif 684#endif
688 685
689 QPen oldpen = m_painter-> pen ( ); 686 QPen oldpen = m_painter-> pen ( );
690 687
691 if (!( state-> getRender ( ) & 1 )) { 688 if (!( state-> getRender ( ) & 1 )) {
692 QPen fillpen = oldpen; 689 QPen fillpen = oldpen;
693 690
694 fillpen. setColor ( m_painter-> brush ( ). color ( )); 691 fillpen. setColor ( m_painter-> brush ( ). color ( ));
695 m_painter-> setPen ( fillpen ); 692 m_painter-> setPen ( fillpen );
696 } 693 }
697 694
698 if ( fsize > 5 ) 695 if ( fsize > 5 )
699 m_painter-> drawText ( q_rnd ( x1 ), q_rnd ( y1 ), str ); 696 m_painter-> drawText ( lrint ( x1 ), lrint ( y1 ), str );
700 else 697 else
701 m_painter-> fillRect ( q_rnd ( x1 ), q_rnd ( y1 ), q_rnd ( QMAX( fp_t(1), dx1 )), q_rnd ( QMAX( fsize, dy1 )), m_painter-> pen ( ). color ( )); 698 m_painter-> fillRect ( lrint ( x1 ), lrint ( y1 ), lrint ( QMAX( fp_t(1), dx1 )), lrint ( QMAX( fsize, dy1 )), m_painter-> pen ( ). color ( ));
702 699
703 m_painter-> setPen ( oldpen ); 700 m_painter-> setPen ( oldpen );
704 701
705#ifndef QT_NO_TRANSFORMATIONS 702#ifndef QT_NO_TRANSFORMATIONS
706 if ( dorot ) 703 if ( dorot )
707 m_painter-> setWorldMatrix ( oldmat ); 704 m_painter-> setWorldMatrix ( oldmat );
708 #endif 705 #endif
709 706
710 // qDebug ( "DRAW TEXT: \"%s\" at (%d/%d)\n", str. local8Bit ( ). data ( ), q_rnd ( x1 ), q_rnd ( y1 )); 707 QPDFDBG( printf ( "DRAW TEXT: \"%s\" at (%ld/%ld)\n", str. local8Bit ( ). data ( ), lrint ( x1 ), lrint ( y1 )));
711 } 708 }
712 else if ( code != 0 ) { 709 else if ( code != 0 ) {
713 // some PDF files use CID 0, which is .notdef, so just ignore it 710 // some PDF files use CID 0, which is .notdef, so just ignore it
714 qWarning ( "Unknown character (CID=%d Unicode=%hx)\n", code, (unsigned short) ( uLen > 0 ? u [0] : (Unicode) 0 )); 711 qWarning ( "Unknown character (CID=%d Unicode=%hx)\n", code, (unsigned short) ( uLen > 0 ? u [0] : (Unicode) 0 ));
715 } 712 }
716 qApp-> processEvents ( ); 713 qApp-> processEvents ( );
717} 714}
718 715
719 716
720 717
721void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str, int width, int height, GBool invert, GBool inlineImg ) 718void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str, int width, int height, GBool invert, GBool inlineImg )
722{ 719{
@@ -730,31 +727,31 @@ void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str,
730 str-> reset ( ); 727 str-> reset ( );
731 int j = height * (( width + 7 ) / 8 ); 728 int j = height * (( width + 7 ) / 8 );
732 for ( int i = 0; i < j; i++ ) 729 for ( int i = 0; i < j; i++ )
733 str->getChar(); 730 str->getChar();
734 731
735 str->close(); 732 str->close();
736 } 733 }
737 return; 734 return;
738 } 735 }
739 736
740 GfxRGB rgb; 737 GfxRGB rgb;
741 state-> getFillRGB ( &rgb ); 738 state-> getFillRGB ( &rgb );
742 uint val = ( q_rnd ( rgb. r * 255 ) & 0xff ) << 16 | ( q_rnd ( rgb. g * 255 ) & 0xff ) << 8 | ( q_rnd ( rgb. b * 255 ) & 0xff ); 739 uint val = ( lrint ( rgb. r * 255 ) & 0xff ) << 16 | ( lrint ( rgb. g * 255 ) & 0xff ) << 8 | ( lrint ( rgb. b * 255 ) & 0xff );
743 740
744 741
745 QImage img ( width, height, 32 ); 742 QImage img ( width, height, 32 );
746 img. setAlphaBuffer ( true ); 743 img. setAlphaBuffer ( true );
747 744
748 //qDebug ( "IMAGE MASK (%dx%d)\n", width, height ); 745 QPDFDBG( printf ( "IMAGE MASK (%dx%d)\n", width, height ));
749 746
750 // initialize the image stream 747 // initialize the image stream
751 ImageStream *imgStr = new ImageStream ( str, width, 1, 1 ); 748 ImageStream *imgStr = new ImageStream ( str, width, 1, 1 );
752 imgStr-> reset ( ); 749 imgStr-> reset ( );
753 750
754 uchar **scanlines = img. jumpTable ( ); 751 uchar **scanlines = img. jumpTable ( );
755 752
756 if ( ctm [3] > 0 ) 753 if ( ctm [3] > 0 )
757 scanlines += ( height - 1 ); 754 scanlines += ( height - 1 );
758 755
759 for ( int y = 0; y < height; y++ ) { 756 for ( int y = 0; y < height; y++ ) {
760 QRgb *scanline = (QRgb *) *scanlines; 757 QRgb *scanline = (QRgb *) *scanlines;
@@ -791,43 +788,43 @@ void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str,
791#ifdef QWS 788#ifdef QWS
792 QPixmap pm; 789 QPixmap pm;
793 pm. convertFromImage ( img ); 790 pm. convertFromImage ( img );
794 m_painter-> drawPixmap ( 0, 0, pm ); 791 m_painter-> drawPixmap ( 0, 0, pm );
795#else 792#else
796 m_painter-> drawImage ( QPoint ( 0, 0 ), img ); 793 m_painter-> drawImage ( QPoint ( 0, 0 ), img );
797#endif 794#endif
798 795
799 m_painter-> setWorldMatrix ( oldmat ); 796 m_painter-> setWorldMatrix ( oldmat );
800 797
801#else 798#else
802 if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) { 799 if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) {
803 qDebug ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" ); 800 QPDFDBG( printf ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" ));
804 } 801 }
805 else { 802 else {
806 int x = q_rnd ( ctm [4] ); 803 int x = lrint ( ctm [4] );
807 int y = q_rnd ( ctm [5] ); 804 int y = lrint ( ctm [5] );
808 805
809 int w = q_rnd ( ctm [0] ); 806 int w = lrint ( ctm [0] );
810 int h = q_rnd ( ctm [3] ); 807 int h = lrint ( ctm [3] );
811 808
812 if ( w < 0 ) { 809 if ( w < 0 ) {
813 x += w; 810 x += w;
814 w = -w; 811 w = -w;
815 } 812 }
816 if ( h < 0 ) { 813 if ( h < 0 ) {
817 y += h; 814 y += h;
818 h = -h; 815 h = -h;
819 } 816 }
820 817
821 // qDebug ( "DRAWING IMAGE MASKED: %d/%d - %dx%d\n", x, y, w, h ); 818 QPDFDBG( printf ( "DRAWING IMAGE MASKED: %d/%d - %dx%d\n", x, y, w, h ));
822 819
823 img = img. smoothScale ( w, h ); 820 img = img. smoothScale ( w, h );
824 qApp-> processEvents ( ); 821 qApp-> processEvents ( );
825 m_painter-> drawImage ( x, y, img ); 822 m_painter-> drawImage ( x, y, img );
826 } 823 }
827 824
828#endif 825#endif
829 826
830 delete imgStr; 827 delete imgStr;
831 qApp-> processEvents ( ); 828 qApp-> processEvents ( );
832} 829}
833 830
@@ -854,50 +851,50 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi
854 str->getChar(); 851 str->getChar();
855 852
856 str->close(); 853 str->close();
857 } 854 }
858 return; 855 return;
859 } 856 }
860 857
861 QImage img ( width, height, 32 ); 858 QImage img ( width, height, 32 );
862 859
863 if ( maskColors ) 860 if ( maskColors )
864 img. setAlphaBuffer ( true ); 861 img. setAlphaBuffer ( true );
865 862
866 //qDebug ( "IMAGE (%dx%d)\n", width, height ); 863 QPDFDBG( printf ( "IMAGE (%dx%d)\n", width, height ));
867 864
868 // initialize the image stream 865 // initialize the image stream
869 ImageStream *imgStr = new ImageStream ( str, width, nComps, nBits ); 866 ImageStream *imgStr = new ImageStream ( str, width, nComps, nBits );
870 imgStr-> reset ( ); 867 imgStr-> reset ( );
871 868
872 Guchar pixBuf [gfxColorMaxComps]; 869 Guchar pixBuf [gfxColorMaxComps];
873 GfxRGB rgb; 870 GfxRGB rgb;
874 871
875 872
876 uchar **scanlines = img. jumpTable ( ); 873 uchar **scanlines = img. jumpTable ( );
877 874
878 if ( ctm [3] > 0 ) 875 if ( ctm [3] > 0 )
879 scanlines += ( height - 1 ); 876 scanlines += ( height - 1 );
880 877
881 for ( int y = 0; y < height; y++ ) { 878 for ( int y = 0; y < height; y++ ) {
882 QRgb *scanline = (QRgb *) *scanlines; 879 QRgb *scanline = (QRgb *) *scanlines;
883 880
884 if ( ctm [0] < 0 ) 881 if ( ctm [0] < 0 )
885 scanline += ( width - 1 ); 882 scanline += ( width - 1 );
886 883
887 for ( int x = 0; x < width; x++ ) { 884 for ( int x = 0; x < width; x++ ) {
888 imgStr-> getPixel ( pixBuf ); 885 imgStr-> getPixel ( pixBuf );
889 colorMap-> getRGB ( pixBuf, &rgb ); 886 colorMap-> getRGB ( pixBuf, &rgb );
890 887
891 uint val = ( q_rnd ( rgb. r * 255 ) & 0xff ) << 16 | ( q_rnd ( rgb. g * 255 ) & 0xff ) << 8 | ( q_rnd ( rgb. b * 255 ) & 0xff ); 888 uint val = ( lrint ( rgb. r * 255 ) & 0xff ) << 16 | ( lrint ( rgb. g * 255 ) & 0xff ) << 8 | ( lrint ( rgb. b * 255 ) & 0xff );
892 889
893 if ( maskColors ) { 890 if ( maskColors ) {
894 for ( int k = 0; k < nComps; ++k ) { 891 for ( int k = 0; k < nComps; ++k ) {
895 if (( pixBuf [k] < maskColors [2 * k] ) || ( pixBuf [k] > maskColors [2 * k] )) { 892 if (( pixBuf [k] < maskColors [2 * k] ) || ( pixBuf [k] > maskColors [2 * k] )) {
896 val |= 0xff000000; 893 val |= 0xff000000;
897 break; 894 break;
898 } 895 }
899 } 896 }
900 } 897 }
901 *scanline = val; 898 *scanline = val;
902 899
903 ctm [0] < 0 ? scanline-- : scanline++; 900 ctm [0] < 0 ? scanline-- : scanline++;
@@ -921,43 +918,43 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi
921 QPixmap pm; 918 QPixmap pm;
922 pm. convertFromImage ( img ); 919 pm. convertFromImage ( img );
923 m_painter-> drawPixmap ( 0, 0, pm ); 920 m_painter-> drawPixmap ( 0, 0, pm );
924 #else 921 #else
925 m_painter-> drawImage ( QPoint ( 0, 0 ), img ); 922 m_painter-> drawImage ( QPoint ( 0, 0 ), img );
926#endif 923#endif
927 924
928 m_painter-> setWorldMatrix ( oldmat ); 925 m_painter-> setWorldMatrix ( oldmat );
929 926
930#else // QT_NO_TRANSFORMATIONS 927#else // QT_NO_TRANSFORMATIONS
931 928
932 if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) { 929 if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) {
933 qDebug ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" ); 930 QPDFDBG( printf ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" ));
934 } 931 }
935 else { 932 else {
936 int x = q_rnd ( ctm [4] ); 933 int x = lrint ( ctm [4] );
937 int y = q_rnd ( ctm [5] ); 934 int y = lrint ( ctm [5] );
938 935
939 int w = q_rnd ( ctm [0] ); 936 int w = lrint ( ctm [0] );
940 int h = q_rnd ( ctm [3] ); 937 int h = lrint ( ctm [3] );
941 938
942 if ( w < 0 ) { 939 if ( w < 0 ) {
943 x += w; 940 x += w;
944 w = -w; 941 w = -w;
945 } 942 }
946 if ( h < 0 ) { 943 if ( h < 0 ) {
947 y += h; 944 y += h;
948 h = -h; 945 h = -h;
949 } 946 }
950 947
951 // qDebug ( "DRAWING IMAGE: %d/%d - %dx%d\n", x, y, w, h ); 948 QPDFDBG( printf ( "DRAWING IMAGE: %d/%d - %dx%d\n", x, y, w, h ));
952 949
953 img = img. smoothScale ( w, h ); 950 img = img. smoothScale ( w, h );
954 qApp-> processEvents ( ); 951 qApp-> processEvents ( );
955 m_painter-> drawImage ( x, y, img ); 952 m_painter-> drawImage ( x, y, img );
956 } 953 }
957 954
958#endif 955#endif
959 956
960 957
961 delete imgStr; 958 delete imgStr;
962 qApp-> processEvents ( ); 959 qApp-> processEvents ( );
963} 960}
@@ -981,48 +978,48 @@ bool QOutputDev::findText ( const QString &str, int &l, int &t, int &w, int &h,
981 uint len = str. length ( ); 978 uint len = str. length ( );
982 Unicode *s = new Unicode [len]; 979 Unicode *s = new Unicode [len];
983 980
984 for ( uint i = 0; i < len; i++ ) 981 for ( uint i = 0; i < len; i++ )
985 s [i] = str [i]. unicode ( ); 982 s [i] = str [i]. unicode ( );
986 983
987 fp_t x1 = (fp_t) l; 984 fp_t x1 = (fp_t) l;
988 fp_t y1 = (fp_t) t; 985 fp_t y1 = (fp_t) t;
989 fp_t x2 = (fp_t) l + w - 1; 986 fp_t x2 = (fp_t) l + w - 1;
990 fp_t y2 = (fp_t) t + h - 1; 987 fp_t y2 = (fp_t) t + h - 1;
991 988
992 if ( m_text-> findText ( s, len, top, bottom, &x1, &y1, &x2, &y2 )) { 989 if ( m_text-> findText ( s, len, top, bottom, &x1, &y1, &x2, &y2 )) {
993 l = q_rnd ( x1 ); 990 l = lrint ( x1 );
994 t = q_rnd ( y1 ); 991 t = lrint ( y1 );
995 w = q_rnd ( x2 ) - l + 1; 992 w = lrint ( x2 ) - l + 1;
996 h = q_rnd ( y2 ) - t + 1; 993 h = lrint ( y2 ) - t + 1;
997 found = true; 994 found = true;
998 } 995 }
999 delete [] s; 996 delete [] s;
1000 997
1001 return found; 998 return found;
1002} 999}
1003 1000
1004GBool QOutputDev::findText ( Unicode *s, int len, GBool top, GBool bottom, int *xMin, int *yMin, int *xMax, int *yMax ) 1001GBool QOutputDev::findText ( Unicode *s, int len, GBool top, GBool bottom, int *xMin, int *yMin, int *xMax, int *yMax )
1005{ 1002{
1006 bool found = false; 1003 bool found = false;
1007 fp_t xMin1 = (double) *xMin; 1004 fp_t xMin1 = (double) *xMin;
1008 fp_t yMin1 = (double) *yMin; 1005 fp_t yMin1 = (double) *yMin;
1009 fp_t xMax1 = (double) *xMax; 1006 fp_t xMax1 = (double) *xMax;
1010 fp_t yMax1 = (double) *yMax; 1007 fp_t yMax1 = (double) *yMax;
1011 1008
1012 if ( m_text-> findText ( s, len, top, bottom, &xMin1, &yMin1, &xMax1, &yMax1 )) { 1009 if ( m_text-> findText ( s, len, top, bottom, &xMin1, &yMin1, &xMax1, &yMax1 )) {
1013 *xMin = q_rnd ( xMin1 ); 1010 *xMin = lrint ( xMin1 );
1014 *xMax = q_rnd ( xMax1 ); 1011 *xMax = lrint ( xMax1 );
1015 *yMin = q_rnd ( yMin1 ); 1012 *yMin = lrint ( yMin1 );
1016 *yMax = q_rnd ( yMax1 ); 1013 *yMax = lrint ( yMax1 );
1017 found = true; 1014 found = true;
1018 } 1015 }
1019 return found; 1016 return found;
1020} 1017}
1021 1018
1022QString QOutputDev::getText ( int l, int t, int w, int h ) 1019QString QOutputDev::getText ( int l, int t, int w, int h )
1023{ 1020{
1024 GString *gstr = m_text-> getText ( l, t, l + w - 1, t + h - 1 ); 1021 GString *gstr = m_text-> getText ( l, t, l + w - 1, t + h - 1 );
1025 QString str = gstr-> getCString ( ); 1022 QString str = gstr-> getCString ( );
1026 delete gstr; 1023 delete gstr;
1027 return str; 1024 return str;
1028} 1025}
diff --git a/noncore/unsupported/qpdf/fixed.h b/noncore/unsupported/qpdf/fixed.h
index 111b95e..c912954 100644
--- a/noncore/unsupported/qpdf/fixed.h
+++ b/noncore/unsupported/qpdf/fixed.h
@@ -111,24 +111,28 @@ private:
111 friend bool operator > <> ( double d, const fixed &f ); 111 friend bool operator > <> ( double d, const fixed &f );
112 friend bool operator <= <> ( double d, const fixed &f ); 112 friend bool operator <= <> ( double d, const fixed &f );
113 friend bool operator >= <> ( double d, const fixed &f ); 113 friend bool operator >= <> ( double d, const fixed &f );
114 friend bool operator == <> ( double d, const fixed &f ); 114 friend bool operator == <> ( double d, const fixed &f );
115 friend bool operator != <> ( double d, const fixed &f ); 115 friend bool operator != <> ( double d, const fixed &f );
116 116
117 friend bool operator < <> ( int i, const fixed &f ); 117 friend bool operator < <> ( int i, const fixed &f );
118 friend bool operator > <> ( int i, const fixed &f ); 118 friend bool operator > <> ( int i, const fixed &f );
119 friend bool operator <= <> ( int i, const fixed &f ); 119 friend bool operator <= <> ( int i, const fixed &f );
120 friend bool operator >= <> ( int i, const fixed &f ); 120 friend bool operator >= <> ( int i, const fixed &f );
121 friend bool operator == <> ( int i, const fixed &f ); 121 friend bool operator == <> ( int i, const fixed &f );
122 friend bool operator != <> ( int i, const fixed &f ); 122 friend bool operator != <> ( int i, const fixed &f );
123
124 friend long int lrint ( const fixed &f );
125 friend fixed sqrt ( const fixed &f );
126 friend fixed fabs ( const fixed &f );
123#endif 127#endif
124}; 128};
125 129
126 130
127template <unsigned int SH> inline fixed<SH> operator + ( int i, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::i2f( i ) + f. m_f, true ); } 131template <unsigned int SH> inline fixed<SH> operator + ( int i, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::i2f( i ) + f. m_f, true ); }
128template <unsigned int SH> inline fixed<SH> operator - ( int i, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::i2f( i ) - f. m_f, true ); } 132template <unsigned int SH> inline fixed<SH> operator - ( int i, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::i2f( i ) - f. m_f, true ); }
129template <unsigned int SH> inline fixed<SH> operator * ( int i, const fixed<SH> &f ) { return fixed<SH> ( i * f. m_f, true ); } 133template <unsigned int SH> inline fixed<SH> operator * ( int i, const fixed<SH> &f ) { return fixed<SH> ( i * f. m_f, true ); }
130template <unsigned int SH> inline fixed<SH> operator / ( int i, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::div ( fixed<SH>::i2f( i ), f. m_f ), true ); } 134template <unsigned int SH> inline fixed<SH> operator / ( int i, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::div ( fixed<SH>::i2f( i ), f. m_f ), true ); }
131//template <unsigned int SH> inline fixed<SH> operator / ( int i, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::i2f ( i / fixed<SH>::f2i ( f. m_f )), true ); } 135//template <unsigned int SH> inline fixed<SH> operator / ( int i, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::i2f ( i / fixed<SH>::f2i ( f. m_f )), true ); }
132 136
133template <unsigned int SH> inline fixed<SH> operator + ( double d, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::d2f( d ) + f. m_f, true ); } 137template <unsigned int SH> inline fixed<SH> operator + ( double d, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::d2f( d ) + f. m_f, true ); }
134template <unsigned int SH> inline fixed<SH> operator - ( double d, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::d2f( d ) - f. m_f, true ); } 138template <unsigned int SH> inline fixed<SH> operator - ( double d, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::d2f( d ) - f. m_f, true ); }
@@ -140,30 +144,46 @@ template <unsigned int SH> inline bool operator > ( double d, const fixed<SH> &
140template <unsigned int SH> inline bool operator <= ( double d, const fixed<SH> &f ) { return fixed<SH>::d2f( d ) <= f. m_f; } 144template <unsigned int SH> inline bool operator <= ( double d, const fixed<SH> &f ) { return fixed<SH>::d2f( d ) <= f. m_f; }
141template <unsigned int SH> inline bool operator >= ( double d, const fixed<SH> &f ) { return fixed<SH>::d2f( d ) >= f. m_f; } 145template <unsigned int SH> inline bool operator >= ( double d, const fixed<SH> &f ) { return fixed<SH>::d2f( d ) >= f. m_f; }
142template <unsigned int SH> inline bool operator == ( double d, const fixed<SH> &f ) { return fixed<SH>::d2f( d ) == f. m_f; } 146template <unsigned int SH> inline bool operator == ( double d, const fixed<SH> &f ) { return fixed<SH>::d2f( d ) == f. m_f; }
143template <unsigned int SH> inline bool operator != ( double d, const fixed<SH> &f ) { return fixed<SH>::d2f( d ) != f. m_f; } 147template <unsigned int SH> inline bool operator != ( double d, const fixed<SH> &f ) { return fixed<SH>::d2f( d ) != f. m_f; }
144 148
145template <unsigned int SH> inline bool operator < ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) < f. m_f; } 149template <unsigned int SH> inline bool operator < ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) < f. m_f; }
146template <unsigned int SH> inline bool operator > ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) > f. m_f; } 150template <unsigned int SH> inline bool operator > ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) > f. m_f; }
147template <unsigned int SH> inline bool operator <= ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) <= f. m_f; } 151template <unsigned int SH> inline bool operator <= ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) <= f. m_f; }
148template <unsigned int SH> inline bool operator >= ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) >= f. m_f; } 152template <unsigned int SH> inline bool operator >= ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) >= f. m_f; }
149template <unsigned int SH> inline bool operator == ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) == f. m_f; } 153template <unsigned int SH> inline bool operator == ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) == f. m_f; }
150template <unsigned int SH> inline bool operator != ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) != f. m_f; } 154template <unsigned int SH> inline bool operator != ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) != f. m_f; }
151 155
152 156template <unsigned int SH> inline long int lrint ( const fixed<SH> &f )
153template <unsigned int SH> inline fixed<SH> sqrt ( const fixed<SH> &f )
154{ 157{
155 return fixed<SH> ( double( sqrt ( double( f )))); 158 return fixed<SH>::f2i (( f. m_f < 0 ) ? f. m_f - ( 1 << ( SH - 1 )) : f. m_f + ( 1 << ( SH - 1 )));
156} 159}
157 160
158template <unsigned int SH> inline fixed<SH> fabs ( const fixed<SH> &f ) 161template <unsigned int SH> inline fixed<SH> fabs ( const fixed<SH> &f )
159{ 162{
160 return ( f < 0 ) ? -f : f; 163 return ( f. m_f < 0 ) ? fixed<SH> ( -f. m_f, true ) : f;
164}
165
166// roughly from QPE / qmath.h
167template <unsigned int SH> inline fixed<SH> sqrt ( const fixed<SH> &f )
168{
169 if ( f. m_f <= 0 )
170 return fixed<SH> ( 0, true );
171
172 fixed<SH>::fix_t a0 = 0;
173 fixed<SH>::fix_t a1 = f. m_f; // take value as first approximation
174
175 do {
176 a0 = a1;
177 a1 = ( a0 + fixed<SH>::div ( f. m_f, a0 )) >> 1;
178 } while ( abs ( fixed<SH>::div ( a1 - a0, a1 )) > 1 );
179
180 return fixed<SH> ( a1, true );
161} 181}
162 182
163template <unsigned int SH> inline ostream &operator << ( ostream &o, const fixed<SH> &f ) 183template <unsigned int SH> inline ostream &operator << ( ostream &o, const fixed<SH> &f )
164{ 184{
165 o << double( f ); 185 o << double( f );
166 return o; 186 return o;
167} 187}
168 188
169#endif 189#endif
diff --git a/noncore/unsupported/qpdf/qpdf.pro b/noncore/unsupported/qpdf/qpdf.pro
index 6ba4f49..0c2e38b 100644
--- a/noncore/unsupported/qpdf/qpdf.pro
+++ b/noncore/unsupported/qpdf/qpdf.pro
@@ -43,18 +43,18 @@ SOURCES = xpdf/Array.cc \
43HEADERS = QOutputDev.h \ 43HEADERS = QOutputDev.h \
44 QPEOutputDev.h \ 44 QPEOutputDev.h \
45 qbusybar.h \ 45 qbusybar.h \
46 qpdf.h 46 qpdf.h
47 47
48INCLUDEPATH += . \ 48INCLUDEPATH += . \
49 .. \ 49 .. \
50 xpdf \ 50 xpdf \
51 $(OPIEDIR)/include \ 51 $(OPIEDIR)/include \
52 ../goo \ 52 ../goo \
53 goo 53 goo
54 54
55LIBS += -L $(OPIEDIR)/lib -lqpe -lstdc++ 55LIBS += -L $(OPIEDIR)/lib -lqpe
56 56
57DESTDIR = $(OPIEDIR)/bin 57DESTDIR = $(OPIEDIR)/bin
58TARGET = qpdf 58TARGET = qpdf
59 59
60TRANSLATIONS = ../../i18n/de/qpdf.ts 60TRANSLATIONS = ../../i18n/de/qpdf.ts