summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qpdf
authorsandman <sandman>2002-04-16 22:16:56 (UTC)
committer sandman <sandman>2002-04-16 22:16:56 (UTC)
commitece373988ee95e4dc3c22eeb012a077595740057 (patch) (unidiff)
treef28fc0976feae59e9b31eae7c17611943cb8a0f2 /noncore/unsupported/qpdf
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 (limited to 'noncore/unsupported/qpdf') (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
@@ -43,2 +43,5 @@
43 43
44 //#define QPDFDBG(x) x // special debug mode
45 #define QPDFDBG(x) // normal compilation
46
44 47
@@ -49,12 +52,5 @@
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}
@@ -112,5 +108,5 @@ QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp
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>" ),
@@ -124,4 +120,4 @@ QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp
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
@@ -187,2 +183,4 @@ QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrol
187 183
184 m_use_string = true;
185
188 // create text object 186 // create text object
@@ -204,6 +202,6 @@ void QOutputDev::startPage ( int /*pageNum*/, GfxState *state )
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
@@ -248,3 +246,3 @@ void 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
@@ -259,3 +257,3 @@ void QOutputDev::restoreState ( GfxState */*state*/ )
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}
@@ -285,3 +283,3 @@ void QOutputDev::updateFlatness ( GfxState */*state*/ )
285 // not supported 283 // not supported
286 //qDebug ( "updateFlatness not supported !\n" ); 284 QPDFDBG( printf ( "updateFlatness not supported !\n" ));
287} 285}
@@ -301,3 +299,3 @@ void QOutputDev::updateMiterLimit ( GfxState */*state*/ )
301{ 299{
302 //qDebug ( "updateMiterLimit not supported !\n" ); 300 QPDFDBG( printf ( "updateMiterLimit not supported !\n" ));
303} 301}
@@ -319,3 +317,3 @@ void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash )
319 317
320 width = q_rnd ( state-> getTransformedLineWidth ( )); 318 width = lrint ( state-> getTransformedLineWidth ( ));
321 319
@@ -411,3 +409,3 @@ void QOutputDev::stroke ( GfxState *state )
411 409
412 //qDebug ( "DRAWING: %d POLYS\n", n ); 410 QPDFDBG( printf ( "DRAWING: %d POLYS\n", n ));
413 411
@@ -419,6 +417,6 @@ void QOutputDev::stroke ( GfxState *state )
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
@@ -458,3 +456,3 @@ void QOutputDev::doFill ( GfxState *state, bool winding )
458 456
459 //qDebug ( "FILLING: %d POLYS\n", n ); 457 QPDFDBG( printf ( "FILLING: %d POLYS\n", n ));
460 458
@@ -469,6 +467,6 @@ void QOutputDev::doFill ( GfxState *state, bool winding )
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
@@ -503,3 +501,3 @@ void QOutputDev::doClip ( GfxState *state, bool winding )
503 501
504 //qDebug ( "CLIPPING: %d POLYS\n", n ); 502 QPDFDBG( printf ( "CLIPPING: %d POLYS\n", n ));
505 503
@@ -514,6 +512,5 @@ void QOutputDev::doClip ( GfxState *state, bool winding )
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
@@ -583,4 +580,4 @@ int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArr
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
@@ -603,3 +600,3 @@ int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArr
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;
@@ -626,5 +623,5 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y,
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
@@ -653,3 +650,3 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y,
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 }
@@ -679,3 +676,3 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y,
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
@@ -698,5 +695,5 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y,
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
@@ -709,3 +706,3 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y,
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 }
@@ -741,3 +738,3 @@ void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str,
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
@@ -747,3 +744,3 @@ void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str,
747 744
748 //qDebug ( "IMAGE MASK (%dx%d)\n", width, height ); 745 QPDFDBG( printf ( "IMAGE MASK (%dx%d)\n", width, height ));
749 746
@@ -802,10 +799,10 @@ void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str,
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
@@ -820,3 +817,3 @@ void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str,
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
@@ -865,3 +862,3 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi
865 862
866 //qDebug ( "IMAGE (%dx%d)\n", width, height ); 863 QPDFDBG( printf ( "IMAGE (%dx%d)\n", width, height ));
867 864
@@ -890,3 +887,3 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi
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
@@ -932,10 +929,10 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi
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
@@ -950,3 +947,3 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi
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
@@ -992,6 +989,6 @@ bool QOutputDev::findText ( const QString &str, int &l, int &t, int &w, int &h,
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;
@@ -1012,6 +1009,6 @@ GBool QOutputDev::findText ( Unicode *s, int len, GBool top, GBool bottom, int *
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;
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
@@ -122,2 +122,6 @@ private:
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
@@ -151,6 +155,5 @@ template <unsigned int SH> inline bool operator != ( int i, const fixed<SH> &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}
@@ -159,3 +162,20 @@ template <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}
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
@@ -54,3 +54,3 @@ INCLUDEPATH += . \
54 54
55LIBS += -L $(OPIEDIR)/lib -lqpe -lstdc++ 55LIBS += -L $(OPIEDIR)/lib -lqpe
56 56