-rw-r--r-- | noncore/unsupported/qpdf/QOutputDev.cpp | 135 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/fixed.h | 28 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/qpdf.pro | 2 |
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 @@ -36,32 +36,28 @@ #include <qpixmap.h> #include <qimage.h> #include <qpainter.h> #include <qdict.h> #include <qtimer.h> #include <qapplication.h> #include <qclipboard.h> +//#define QPDFDBG(x) x // special debug mode +#define QPDFDBG(x) // normal compilation + //------------------------------------------------------------------------ // Constants and macros //------------------------------------------------------------------------ -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 )); } //------------------------------------------------------------------------ // Font substitutions //------------------------------------------------------------------------ struct QOutFontSubst { @@ -105,30 +101,30 @@ QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp // build dict for std. fonts on first invocation if ( stdfonts. isEmpty ( )) { for ( QOutFontSubst *ptr = qStdFonts; ptr-> m_name; ptr++ ) { stdfonts. insert ( QString ( ptr-> m_name ), ptr ); } } // 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>" ), size, gfxFont-> isBold ( ), gfxFont-> isItalic ( ), gfxFont-> isFixedWidth ( ), gfxFont-> isSerif ( ), gfxFont-> isSymbolic ( ), gfxFont-> isCIDFont ( ), ( gfxFont-> getEmbeddedFontName ( ) ? gfxFont-> getEmbeddedFontName ( ) : "<n/a>" ), - (double) m11, (double) m12, (double) m21, (double) m22 ); -*/ + (double) m11, (double) m12, (double) m21, (double) m22 )); + QString fname (( gfxFont-> getName ( )) ? gfxFont-> getName ( )-> getCString ( ) : "<n/a>" ); QFont f; f. setPixelSize ( size > 0 ? size : 8 ); // type3 fonts misbehave sometimes // fast lookup for std. fonts QOutFontSubst *subst = stdfonts [fname]; @@ -180,16 +176,18 @@ QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp // QOutputDev //------------------------------------------------------------------------ QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrollView ( parent, name, WRepaintNoErase | WResizeNoErase | flags ) { m_pixmap = 0; m_painter = 0; + m_use_string = true; + // create text object m_text = new TextPage ( gFalse ); } QOutputDev::~QOutputDev ( ) { delete m_painter; delete m_pixmap; @@ -197,20 +195,20 @@ QOutputDev::~QOutputDev ( ) } void QOutputDev::startPage ( int /*pageNum*/, GfxState *state ) { delete m_pixmap; delete m_painter; - 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 ( )))); resizeContents ( m_pixmap-> width ( ), m_pixmap-> height ( )); setContentsPos ( 0, 0 ); m_pixmap-> fill ( white ); // clear window m_text-> clear ( ); // cleat text object viewport ( )-> repaint ( ); } @@ -241,28 +239,28 @@ void QOutputDev::drawLink ( Link *link, Catalog */*catalog*/ ) m_painter-> setPen ( blue ); m_painter-> drawRect ( x, y, dx, dy ); m_painter-> setPen ( oldpen ); } } 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 ( ))); m_painter-> save ( ); } void QOutputDev::restoreState ( GfxState */*state*/ ) { m_painter-> restore ( ); // m_painter-> setClipRegion ( QRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( ))); // 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 ( ))); } void QOutputDev::updateAll ( GfxState *state ) { updateLineAttrs ( state, gTrue ); // updateFlatness ( state ); // updateMiterLimit ( state ); updateFillColor ( state ); @@ -278,33 +276,33 @@ void QOutputDev::updateCTM ( GfxState *state, fp_t /*m11*/, fp_t /*m12*/, fp_t / void QOutputDev::updateLineDash ( GfxState *state ) { updateLineAttrs ( state, gTrue ); } void QOutputDev::updateFlatness ( GfxState */*state*/ ) { // not supported -// qDebug ( "updateFlatness not supported !\n" ); + QPDFDBG( printf ( "updateFlatness not supported !\n" )); } void QOutputDev::updateLineJoin ( GfxState *state ) { updateLineAttrs ( state, gFalse ); } void QOutputDev::updateLineCap ( GfxState *state ) { updateLineAttrs ( state, gFalse ); } // unimplemented void QOutputDev::updateMiterLimit ( GfxState */*state*/ ) { -// qDebug ( "updateMiterLimit not supported !\n" ); + QPDFDBG( printf ( "updateMiterLimit not supported !\n" )); } void QOutputDev::updateLineWidth ( GfxState *state ) { updateLineAttrs ( state, gFalse ); } void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash ) @@ -312,17 +310,17 @@ void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash ) fp_t *dashPattern; int dashLength; fp_t dashStart; Qt::PenCapStyle cap; Qt::PenJoinStyle join; int width; - width = q_rnd ( state-> getTransformedLineWidth ( )); + width = lrint ( state-> getTransformedLineWidth ( )); switch ( state-> getLineCap ( )) { case 0: cap = FlatCap; break; case 1: cap = RoundCap; break; case 2: cap = SquareCap; break; default: qWarning ( "Bad line cap style (%d)\n", state-> getLineCap ( )); cap = FlatCap; @@ -404,28 +402,28 @@ void QOutputDev::updateFont ( GfxState *state ) void QOutputDev::stroke ( GfxState *state ) { QPointArray points; QArray<int> lengths; // transform points int n = convertPath ( state, points, lengths ); -// qDebug ( "DRAWING: %d POLYS\n", n ); + QPDFDBG( printf ( "DRAWING: %d POLYS\n", n )); // draw each subpath int j = 0; for ( int i = 0; i < n; i++ ) { int len = lengths [i]; 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" )); m_painter-> drawPolyline ( points, j, len ); } j += len; } qApp-> processEvents ( ); } @@ -451,31 +449,31 @@ void QOutputDev::eoFill ( GfxState *state ) void QOutputDev::doFill ( GfxState *state, bool winding ) { QPointArray points; QArray<int> lengths; // transform points int n = convertPath ( state, points, lengths ); -// qDebug ( "FILLING: %d POLYS\n", n ); + QPDFDBG( printf ( "FILLING: %d POLYS\n", n )); QPen oldpen = m_painter-> pen ( ); m_painter-> setPen ( QPen ( NoPen )); // draw each subpath int j = 0; for ( int i = 0; i < n; i++ ) { int len = lengths [i]; 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" )); m_painter-> drawPolygon ( points, winding, j, len ); } j += len; } m_painter-> setPen ( oldpen ); qApp-> processEvents ( ); @@ -496,31 +494,30 @@ void QOutputDev::doClip ( GfxState *state, bool winding ) QPointArray points; QArray<int> lengths; // transform points int n = convertPath ( state, points, lengths ); QRegion region; -// qDebug ( "CLIPPING: %d POLYS\n", n ); + QPDFDBG( printf ( "CLIPPING: %d POLYS\n", n )); // draw each subpath int j = 0; for ( int i = 0; i < n; i++ ) { int len = lengths [i]; if ( len >= 3 ) { QPointArray dummy; dummy. setRawData ( points. data ( ) + j, len ); -// 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" )); region |= QRegion ( dummy, winding ); dummy. resetRawData ( points. data ( ) + j, len ); } j += len; } @@ -576,18 +573,18 @@ int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArr while ( i < m ) { if ( i >= 1 && subpath-> getCurve ( i )) { state-> transform ( subpath-> getX ( i - 1 ), subpath-> getY ( i - 1 ), &x0, &y0 ); state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 ); state-> transform ( subpath-> getX ( i + 1 ), subpath-> getY ( i + 1 ), &x2, &y2 ); state-> transform ( subpath-> getX ( i + 2 ), subpath-> getY ( i + 2 ), &x3, &y3 ); 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 )); #if QT_VERSION < 300 tmp = tmp. quadBezier ( ); for ( uint loop = 0; loop < tmp. count ( ); loop++ ) { QPoint p = tmp. point ( loop ); points. putPoints ( points. count ( ), 1, p. x ( ), p. y ( )); } @@ -596,17 +593,17 @@ int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArr points. putPoints ( points. count ( ), tmp. count ( ), tmp ); #endif i += 3; } else { state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 ); - points. putPoints ( points. count ( ), 1, q_rnd ( x1 ), q_rnd ( y1 )); + points. putPoints ( points. count ( ), 1, lrint ( x1 ), lrint ( y1 )); ++i; } } return points. count ( ) - oldcnt; } void QOutputDev::beginString ( GfxState *state, GString */*s*/ ) @@ -619,19 +616,19 @@ void QOutputDev::endString ( GfxState */*state*/ ) m_text-> endString ( ); } void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, fp_t dx, fp_t dy, fp_t originX, fp_t originY, CharCode code, Unicode *u, int uLen ) { 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 ); // check for invisible text -- this is used by Acrobat Capture if (( state-> getRender ( ) & 3 ) == 3 ) { return; } x -= originX; y -= originY; @@ -646,17 +643,17 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, for ( int i = 0; i < uLen; i++ ) { QChar c = QChar ( u [i] ); if ( fm. inFont ( c )) { str [i] = QChar ( u [i] ); } else { str [i] = ' '; -// qDebug ( "CHARACTER NOT IN FONT: %hx\n", c. unicode ( )); + QPDFDBG( printf ( "CHARACTER NOT IN FONT: %hx\n", c. unicode ( ))); } } if (( uLen == 1 ) && ( str [0] == ' ' )) return; fp_t m11, m12, m21, m22; @@ -672,17 +669,17 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, bool dorot = (( m12 < -0.1 ) || ( m12 > 0.1 )) && (( m21 < -0.1 ) || ( m21 > 0.1 )); if ( dorot ) { oldmat = m_painter-> worldMatrix ( ); cerr << endl << "ROTATED: " << m11 << ", " << m12 << ", " << m21 << ", " << m22 << " / SIZE: " << fsize << " / TEXT: " << str. local8Bit ( ) << endl << endl; - 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 )); m_painter-> setWorldMatrix ( mat ); x1 = 0; y1 = 0; } #endif @@ -691,28 +688,28 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y, if (!( state-> getRender ( ) & 1 )) { QPen fillpen = oldpen; fillpen. setColor ( m_painter-> brush ( ). color ( )); m_painter-> setPen ( fillpen ); } 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 ( )); m_painter-> setPen ( oldpen ); #ifndef QT_NO_TRANSFORMATIONS if ( dorot ) m_painter-> setWorldMatrix ( oldmat ); #endif -// 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 ))); } else if ( code != 0 ) { // some PDF files use CID 0, which is .notdef, so just ignore it qWarning ( "Unknown character (CID=%d Unicode=%hx)\n", code, (unsigned short) ( uLen > 0 ? u [0] : (Unicode) 0 )); } qApp-> processEvents ( ); } @@ -734,23 +731,23 @@ void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str, str->close(); } return; } GfxRGB rgb; 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 ); QImage img ( width, height, 32 ); img. setAlphaBuffer ( true ); -// qDebug ( "IMAGE MASK (%dx%d)\n", width, height ); + QPDFDBG( printf ( "IMAGE MASK (%dx%d)\n", width, height )); // initialize the image stream ImageStream *imgStr = new ImageStream ( str, width, 1, 1 ); imgStr-> reset ( ); uchar **scanlines = img. jumpTable ( ); if ( ctm [3] > 0 ) @@ -795,35 +792,35 @@ void QOutputDev::drawImageMask ( GfxState *state, Object */*ref*/, Stream *str, #else m_painter-> drawImage ( QPoint ( 0, 0 ), img ); #endif m_painter-> setWorldMatrix ( oldmat ); #else 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] ); if ( w < 0 ) { x += w; w = -w; } if ( h < 0 ) { y += h; h = -h; } -// 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 )); img = img. smoothScale ( w, h ); qApp-> processEvents ( ); m_painter-> drawImage ( x, y, img ); } #endif @@ -858,17 +855,17 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi return; } QImage img ( width, height, 32 ); if ( maskColors ) img. setAlphaBuffer ( true ); -// qDebug ( "IMAGE (%dx%d)\n", width, height ); + QPDFDBG( printf ( "IMAGE (%dx%d)\n", width, height )); // initialize the image stream ImageStream *imgStr = new ImageStream ( str, width, nComps, nBits ); imgStr-> reset ( ); Guchar pixBuf [gfxColorMaxComps]; GfxRGB rgb; @@ -883,17 +880,17 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi if ( ctm [0] < 0 ) scanline += ( width - 1 ); for ( int x = 0; x < width; x++ ) { imgStr-> getPixel ( pixBuf ); colorMap-> getRGB ( pixBuf, &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 ); if ( maskColors ) { for ( int k = 0; k < nComps; ++k ) { if (( pixBuf [k] < maskColors [2 * k] ) || ( pixBuf [k] > maskColors [2 * k] )) { val |= 0xff000000; break; } } @@ -925,35 +922,35 @@ void QOutputDev::drawImage(GfxState *state, Object */*ref*/, Stream *str, int wi m_painter-> drawImage ( QPoint ( 0, 0 ), img ); #endif m_painter-> setWorldMatrix ( oldmat ); #else // QT_NO_TRANSFORMATIONS 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] ); if ( w < 0 ) { x += w; w = -w; } if ( h < 0 ) { y += h; h = -h; } -// 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 )); img = img. smoothScale ( w, h ); qApp-> processEvents ( ); m_painter-> drawImage ( x, y, img ); } #endif @@ -985,40 +982,40 @@ bool QOutputDev::findText ( const QString &str, int &l, int &t, int &w, int &h, s [i] = str [i]. unicode ( ); fp_t x1 = (fp_t) l; fp_t y1 = (fp_t) t; fp_t x2 = (fp_t) l + w - 1; fp_t y2 = (fp_t) t + h - 1; 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; } delete [] s; return found; } GBool QOutputDev::findText ( Unicode *s, int len, GBool top, GBool bottom, int *xMin, int *yMin, int *xMax, int *yMax ) { bool found = false; fp_t xMin1 = (double) *xMin; fp_t yMin1 = (double) *yMin; fp_t xMax1 = (double) *xMax; fp_t yMax1 = (double) *yMax; 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; } return found; } QString QOutputDev::getText ( int l, int t, int w, int h ) { GString *gstr = m_text-> getText ( l, t, l + w - 1, t + h - 1 ); 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 @@ -115,16 +115,20 @@ private: friend bool operator != <> ( double d, const fixed &f ); friend bool operator < <> ( int i, const fixed &f ); friend bool operator > <> ( int i, const fixed &f ); friend bool operator <= <> ( int i, const fixed &f ); friend bool operator >= <> ( int i, const fixed &f ); friend bool operator == <> ( int i, const fixed &f ); friend bool operator != <> ( int i, const fixed &f ); + + friend long int lrint ( const fixed &f ); + friend fixed sqrt ( const fixed &f ); + friend fixed fabs ( const fixed &f ); #endif }; template <unsigned int SH> inline fixed<SH> operator + ( int i, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::i2f( i ) + f. m_f, true ); } template <unsigned int SH> inline fixed<SH> operator - ( int i, const fixed<SH> &f ) { return fixed<SH> ( fixed<SH>::i2f( i ) - f. m_f, true ); } template <unsigned int SH> inline fixed<SH> operator * ( int i, const fixed<SH> &f ) { return fixed<SH> ( i * f. m_f, true ); } template <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 ); } @@ -144,25 +148,41 @@ template <unsigned int SH> inline bool operator != ( double d, const fixed<SH> & template <unsigned int SH> inline bool operator < ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) < f. m_f; } template <unsigned int SH> inline bool operator > ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) > f. m_f; } template <unsigned int SH> inline bool operator <= ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) <= f. m_f; } template <unsigned int SH> inline bool operator >= ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) >= f. m_f; } template <unsigned int SH> inline bool operator == ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) == f. m_f; } template <unsigned int SH> inline bool operator != ( int i, const fixed<SH> &f ) { return fixed<SH>::i2f( i ) != f. m_f; } - -template <unsigned int SH> inline fixed<SH> sqrt ( const fixed<SH> &f ) +template <unsigned int SH> inline long int lrint ( const fixed<SH> &f ) { - return fixed<SH> ( double( sqrt ( double( f )))); + return fixed<SH>::f2i (( f. m_f < 0 ) ? f. m_f - ( 1 << ( SH - 1 )) : f. m_f + ( 1 << ( SH - 1 ))); } template <unsigned int SH> inline fixed<SH> fabs ( const fixed<SH> &f ) { - return ( f < 0 ) ? -f : f; + return ( f. m_f < 0 ) ? fixed<SH> ( -f. m_f, true ) : f; +} + +// roughly from QPE / qmath.h +template <unsigned int SH> inline fixed<SH> sqrt ( const fixed<SH> &f ) +{ + if ( f. m_f <= 0 ) + return fixed<SH> ( 0, true ); + + fixed<SH>::fix_t a0 = 0; + fixed<SH>::fix_t a1 = f. m_f; // take value as first approximation + + do { + a0 = a1; + a1 = ( a0 + fixed<SH>::div ( f. m_f, a0 )) >> 1; + } while ( abs ( fixed<SH>::div ( a1 - a0, a1 )) > 1 ); + + return fixed<SH> ( a1, true ); } template <unsigned int SH> inline ostream &operator << ( ostream &o, const fixed<SH> &f ) { o << double( f ); return o; } 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 @@ -47,14 +47,14 @@ HEADERS = QOutputDev.h \ INCLUDEPATH += . \ .. \ xpdf \ $(OPIEDIR)/include \ ../goo \ goo -LIBS += -L $(OPIEDIR)/lib -lqpe -lstdc++ +LIBS += -L $(OPIEDIR)/lib -lqpe DESTDIR = $(OPIEDIR)/bin TARGET = qpdf TRANSLATIONS = ../../i18n/de/qpdf.ts |