author | sandman <sandman> | 2002-04-16 22:16:56 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-04-16 22:16:56 (UTC) |
commit | ece373988ee95e4dc3c22eeb012a077595740057 (patch) (side-by-side diff) | |
tree | f28fc0976feae59e9b31eae7c17611943cb8a0f2 /noncore/unsupported/qpdf/QOutputDev.cpp | |
parent | e7e4ecaae60f5444c4ec581077f91e6b412c780c (diff) | |
download | opie-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/QOutputDev.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/unsupported/qpdf/QOutputDev.cpp | 135 |
1 files changed, 66 insertions, 69 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 @@ +//#define QPDFDBG(x) x // special debug mode +#define QPDFDBG(x) // normal compilation + @@ -49,12 +52,5 @@ -static inline int q_rnd ( fp_t d ) -{ -// qDebug ( "Q_RND: %f -> %d\n", (double) d, (int) ( d >= 0 ? d +0.5 : d - 0.5 )); - - return (int) ( d >= 0 ? d + 0.5 : d - 0.5 ); -} - static inline QColor q_col ( const GfxRGB &rgb ) { - return QColor ( q_rnd ( rgb. r * 255 ), q_rnd ( rgb. g * 255 ), q_rnd ( rgb. b * 255 )); + return QColor ( lrint ( rgb. r * 255 ), lrint ( rgb. g * 255 ), lrint ( rgb. b * 255 )); } @@ -112,5 +108,5 @@ QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp // compute size and normalized transform matrix - int size = q_rnd ( sqrt ( m21 * m21 + m22 * m22 )); + int size = lrint ( sqrt ( m21 * m21 + m22 * m22 )); -/* 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", + 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", (( 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 ( gfxFont-> getEmbeddedFontName ( ) ? gfxFont-> getEmbeddedFontName ( ) : "<n/a>" ), - (double) m11, (double) m12, (double) m21, (double) m22 ); -*/ + (double) m11, (double) m12, (double) m21, (double) m22 )); + @@ -187,2 +183,4 @@ QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrol + m_use_string = true; + // create text object @@ -204,6 +202,6 @@ void QOutputDev::startPage ( int /*pageNum*/, GfxState *state ) - m_pixmap = new QPixmap ( q_rnd ( state-> getPageWidth ( )), q_rnd ( state-> getPageHeight ( ))); + m_pixmap = new QPixmap ( lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( ))); m_painter = new QPainter ( m_pixmap ); -// qDebug ( "NEW PIXMAP (%d x %d)\n", q_rnd ( state-> getPageWidth ( )), q_rnd ( state-> getPageHeight ( ))); + QPDFDBG( printf ( "NEW PIXMAP (%ld x %ld)\n", lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( )))); @@ -248,3 +246,3 @@ void QOutputDev::saveState ( GfxState */*state*/ ) { -// qDebug ( "SAVE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( )); + QPDFDBG( printf ( "SAVE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( ))); @@ -259,3 +257,3 @@ void QOutputDev::restoreState ( GfxState */*state*/ ) // m_painter-> setClipping ( false ); -// qDebug ( "RESTORE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( )); + QPDFDBG ( printf ( "RESTORE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( ))); } @@ -285,3 +283,3 @@ void QOutputDev::updateFlatness ( GfxState */*state*/ ) // not supported -// qDebug ( "updateFlatness not supported !\n" ); + QPDFDBG( printf ( "updateFlatness not supported !\n" )); } @@ -301,3 +299,3 @@ void QOutputDev::updateMiterLimit ( GfxState */*state*/ ) { -// qDebug ( "updateMiterLimit not supported !\n" ); + QPDFDBG( printf ( "updateMiterLimit not supported !\n" )); } @@ -319,3 +317,3 @@ void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash ) - width = q_rnd ( state-> getTransformedLineWidth ( )); + width = lrint ( state-> getTransformedLineWidth ( )); @@ -411,3 +409,3 @@ void QOutputDev::stroke ( GfxState *state ) -// qDebug ( "DRAWING: %d POLYS\n", n ); + QPDFDBG( printf ( "DRAWING: %d POLYS\n", n )); @@ -419,6 +417,6 @@ void QOutputDev::stroke ( GfxState *state ) if ( len >= 2 ) { -// qDebug ( " - POLY %d: ", i ); -// for ( int ii = 0; ii < len; ii++ ) -// qDebug ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )); -// qDebug ( "\n" ); + QPDFDBG( printf ( " - POLY %d: ", i )); + QPDFDBG( for ( int ii = 0; ii < len; ii++ )) + QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); + QPDFDBG( printf ( "\n" )); @@ -458,3 +456,3 @@ void QOutputDev::doFill ( GfxState *state, bool winding ) -// qDebug ( "FILLING: %d POLYS\n", n ); + QPDFDBG( printf ( "FILLING: %d POLYS\n", n )); @@ -469,6 +467,6 @@ void QOutputDev::doFill ( GfxState *state, bool winding ) if ( len >= 3 ) { -// qDebug ( " - POLY %d: ", i ); -// for ( int ii = 0; ii < len; ii++ ) -// qDebug ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )); -// qDebug ( "\n" ); + QPDFDBG( printf ( " - POLY %d: ", i )); + QPDFDBG( for ( int ii = 0; ii < len; ii++ )) + QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); + QPDFDBG( printf ( "\n" )); @@ -503,3 +501,3 @@ void QOutputDev::doClip ( GfxState *state, bool winding ) -// qDebug ( "CLIPPING: %d POLYS\n", n ); + QPDFDBG( printf ( "CLIPPING: %d POLYS\n", n )); @@ -514,6 +512,5 @@ void QOutputDev::doClip ( GfxState *state, bool winding ) -// qDebug ( " - POLY %d: ", i ); -// for ( int ii = 0; ii < len; ii++ ) -// qDebug ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )); -// qDebug ( "\n" ); + QPDFDBG( printf ( " - POLY %d: ", i )); + QPDFDBG( for ( int ii = 0; ii < len; ii++ ) printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( ))); + QPDFDBG( printf ( "\n" )); @@ -583,4 +580,4 @@ int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArr QPointArray tmp; - tmp. setPoints ( 4, q_rnd ( x0 ), q_rnd ( y0 ), q_rnd ( x1 ), q_rnd ( y1 ), - q_rnd ( x2 ), q_rnd ( y2 ), q_rnd ( x3 ), q_rnd ( y3 )); + tmp. setPoints ( 4, lrint ( x0 ), lrint ( y0 ), lrint ( x1 ), lrint ( y1 ), + lrint ( x2 ), lrint ( y2 ), lrint ( x3 ), lrint ( y3 )); @@ -603,3 +600,3 @@ int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArr - points. putPoints ( points. count ( ), 1, q_rnd ( x1 ), q_rnd ( y1 )); + points. putPoints ( points. count ( ), 1, lrint ( x1 ), lrint ( y1 )); ++i; @@ -626,5 +623,5 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, fp_t x1, y1, dx1, dy1; - - m_text-> addChar ( state, x, y, dx, dy, u, uLen ); - + + if ( uLen > 0 ) + m_text-> addChar ( state, x, y, dx, dy, u, uLen ); @@ -653,3 +650,3 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, str [i] = ' '; -// qDebug ( "CHARACTER NOT IN FONT: %hx\n", c. unicode ( )); + QPDFDBG( printf ( "CHARACTER NOT IN FONT: %hx\n", c. unicode ( ))); } @@ -679,3 +676,3 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, - QWMatrix mat ( q_rnd ( m11 / fsize ), q_rnd ( m12 / fsize ), -q_rnd ( m21 / fsize ), -q_rnd ( m22 / fsize ), q_rnd ( x1 ), q_rnd ( y1 )); + QWMatrix mat ( lrint ( m11 / fsize ), lrint ( m12 / fsize ), -lrint ( m21 / fsize ), -lrint ( m22 / fsize ), lrint ( x1 ), lrint ( y1 )); @@ -698,5 +695,5 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, if ( fsize > 5 ) - m_painter-> drawText ( q_rnd ( x1 ), q_rnd ( y1 ), str ); + m_painter-> drawText ( lrint ( x1 ), lrint ( y1 ), str ); else - 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 ( )); + m_painter-> fillRect ( lrint ( x1 ), lrint ( y1 ), lrint ( QMAX( fp_t(1), dx1 )), lrint ( QMAX( fsize, dy1 )), m_painter-> pen ( ). color ( )); @@ -709,3 +706,3 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, -// qDebug ( "DRAW TEXT: \"%s\" at (%d/%d)\n", str. local8Bit ( ). data ( ), q_rnd ( x1 ), q_rnd ( y1 )); + QPDFDBG( printf ( "DRAW TEXT: \"%s\" at (%ld/%ld)\n", str. local8Bit ( ). data ( ), lrint ( x1 ), lrint ( y1 ))); } @@ -741,3 +738,3 @@ void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str, state-> getFillRGB ( &rgb ); - uint val = ( q_rnd ( rgb. r * 255 ) & 0xff ) << 16 | ( q_rnd ( rgb. g * 255 ) & 0xff ) << 8 | ( q_rnd ( rgb. b * 255 ) & 0xff ); + uint val = ( lrint ( rgb. r * 255 ) & 0xff ) << 16 | ( lrint ( rgb. g * 255 ) & 0xff ) << 8 | ( lrint ( rgb. b * 255 ) & 0xff ); @@ -747,3 +744,3 @@ void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str, -// qDebug ( "IMAGE MASK (%dx%d)\n", width, height ); + QPDFDBG( printf ( "IMAGE MASK (%dx%d)\n", width, height )); @@ -802,10 +799,10 @@ void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str, if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) { - qDebug ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" ); + QPDFDBG( printf ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" )); } else { - int x = q_rnd ( ctm [4] ); - int y = q_rnd ( ctm [5] ); + int x = lrint ( ctm [4] ); + int y = lrint ( ctm [5] ); - int w = q_rnd ( ctm [0] ); - int h = q_rnd ( ctm [3] ); + int w = lrint ( ctm [0] ); + int h = lrint ( ctm [3] ); @@ -820,3 +817,3 @@ void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str, -// qDebug ( "DRAWING IMAGE MASKED: %d/%d - %dx%d\n", x, y, w, h ); + QPDFDBG( printf ( "DRAWING IMAGE MASKED: %d/%d - %dx%d\n", x, y, w, h )); @@ -865,3 +862,3 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi -// qDebug ( "IMAGE (%dx%d)\n", width, height ); + QPDFDBG( printf ( "IMAGE (%dx%d)\n", width, height )); @@ -890,3 +887,3 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi - uint val = ( q_rnd ( rgb. r * 255 ) & 0xff ) << 16 | ( q_rnd ( rgb. g * 255 ) & 0xff ) << 8 | ( q_rnd ( rgb. b * 255 ) & 0xff ); + uint val = ( lrint ( rgb. r * 255 ) & 0xff ) << 16 | ( lrint ( rgb. g * 255 ) & 0xff ) << 8 | ( lrint ( rgb. b * 255 ) & 0xff ); @@ -932,10 +929,10 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi if (( ctm [1] < -0.1 ) || ( ctm [1] > 0.1 ) || ( ctm [2] < -0.1 ) || ( ctm [2] > 0.1 )) { - qDebug ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" ); + QPDFDBG( printf ( "### ROTATED / SHEARED / ETC -- CANNOT DISPLAY THIS IMAGE\n" )); } else { - int x = q_rnd ( ctm [4] ); - int y = q_rnd ( ctm [5] ); + int x = lrint ( ctm [4] ); + int y = lrint ( ctm [5] ); - int w = q_rnd ( ctm [0] ); - int h = q_rnd ( ctm [3] ); + int w = lrint ( ctm [0] ); + int h = lrint ( ctm [3] ); @@ -950,3 +947,3 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi -// qDebug ( "DRAWING IMAGE: %d/%d - %dx%d\n", x, y, w, h ); + QPDFDBG( printf ( "DRAWING IMAGE: %d/%d - %dx%d\n", x, y, w, h )); @@ -992,6 +989,6 @@ bool QOutputDev::findText ( const QString &str, int &l, int &t, int &w, int &h, if ( m_text-> findText ( s, len, top, bottom, &x1, &y1, &x2, &y2 )) { - l = q_rnd ( x1 ); - t = q_rnd ( y1 ); - w = q_rnd ( x2 ) - l + 1; - h = q_rnd ( y2 ) - t + 1; + l = lrint ( x1 ); + t = lrint ( y1 ); + w = lrint ( x2 ) - l + 1; + h = lrint ( y2 ) - t + 1; found = true; @@ -1012,6 +1009,6 @@ GBool QOutputDev::findText ( Unicode *s, int len, GBool top, GBool bottom, int * if ( m_text-> findText ( s, len, top, bottom, &xMin1, &yMin1, &xMax1, &yMax1 )) { - *xMin = q_rnd ( xMin1 ); - *xMax = q_rnd ( xMax1 ); - *yMin = q_rnd ( yMin1 ); - *yMax = q_rnd ( yMax1 ); + *xMin = lrint ( xMin1 ); + *xMax = lrint ( xMax1 ); + *yMin = lrint ( yMin1 ); + *yMax = lrint ( yMax1 ); found = true; |