XpdfWidget.cc (xpdf-4.03) | : | XpdfWidget.cc (xpdf-4.04) | ||
---|---|---|---|---|
skipping to change at line 1268 | skipping to change at line 1268 | |||
emit printStatus(nextPage, firstPage, lastPage); | emit printStatus(nextPage, firstPage, lastPage); | |||
} | } | |||
void XpdfWidget::setPrintDPI(int hDPI, int vDPI) { | void XpdfWidget::setPrintDPI(int hDPI, int vDPI) { | |||
printHDPI = hDPI; | printHDPI = hDPI; | |||
printVDPI = vDPI; | printVDPI = vDPI; | |||
} | } | |||
#endif // XPDFWIDGET_PRINTING | #endif // XPDFWIDGET_PRINTING | |||
QImage XpdfWidget::convertPageToImage(int page, double dpi) { | QImage XpdfWidget::convertPageToImage(int page, double dpi, bool transparent) { | |||
PDFDoc *doc; | ||||
SplashColor paperColor; | ||||
SplashOutputDev *out; | ||||
SplashBitmap *bitmap; | ||||
QImage *img; | ||||
try { | try { | |||
if (!(doc = core->getDoc())) { | PDFDoc *doc = core->getDoc(); | |||
if (!doc) { | ||||
return QImage(); | return QImage(); | |||
} | } | |||
if (page < 1 || page > doc->getNumPages()) { | if (page < 1 || page > doc->getNumPages()) { | |||
return QImage(); | return QImage(); | |||
} | } | |||
paperColor[0] = paperColor[1] = paperColor[2] = 0xff; | if (transparent) { | |||
out = new SplashOutputDev(splashModeRGB8, 4, gFalse, paperColor); | SplashColor paperColor; | |||
out->startDoc(doc->getXRef()); | paperColor[0] = paperColor[1] = paperColor[2] = 0xff; // unused | |||
doc->displayPage(out, page, dpi, dpi, core->getRotate(), | SplashOutputDev *out = new SplashOutputDev(splashModeRGB8, 1, gFalse, | |||
gFalse, gTrue, gFalse); | paperColor); | |||
bitmap = out->getBitmap(); | out->setNoComposite(gTrue); | |||
img = new QImage((const uchar *)bitmap->getDataPtr(), bitmap->getWidth(), | out->startDoc(doc->getXRef()); | |||
bitmap->getHeight(), QImage::Format_RGB888); | doc->displayPage(out, page, dpi, dpi, core->getRotate(), | |||
// force a copy | gFalse, gTrue, gFalse); | |||
QImage img2(img->copy()); | SplashBitmap *bitmap = out->getBitmap(); | |||
delete img; | QImage img(bitmap->getWidth(), bitmap->getHeight(), | |||
delete out; | QImage::Format_ARGB32); | |||
return img2; | Guchar *pix = bitmap->getDataPtr(); | |||
Guchar *alpha = bitmap->getAlphaPtr(); | ||||
Guint *argb = (Guint *)img.bits(); | ||||
for (int y = 0; y < bitmap->getHeight(); ++y) { | ||||
for (int x = 0; x < bitmap->getWidth(); ++x) { | ||||
*argb = (*alpha << 24) | (pix[0] << 16) | (pix[1] << 8) | pix[2]; | ||||
pix += 3; | ||||
++alpha; | ||||
++argb; | ||||
} | ||||
} | ||||
delete out; | ||||
return img; | ||||
} else { | ||||
SplashColor paperColor; | ||||
paperColor[0] = paperColor[1] = paperColor[2] = 0xff; | ||||
SplashOutputDev *out = new SplashOutputDev(splashModeRGB8, 4, gFalse, | ||||
paperColor); | ||||
out->startDoc(doc->getXRef()); | ||||
doc->displayPage(out, page, dpi, dpi, core->getRotate(), | ||||
gFalse, gTrue, gFalse); | ||||
SplashBitmap *bitmap = out->getBitmap(); | ||||
QImage *img = new QImage((const uchar *)bitmap->getDataPtr(), | ||||
bitmap->getWidth(), bitmap->getHeight(), | ||||
QImage::Format_RGB888); | ||||
// force a copy | ||||
QImage img2(img->copy()); | ||||
delete img; | ||||
delete out; | ||||
return img2; | ||||
} | ||||
} catch (GMemException e) { | } catch (GMemException e) { | |||
return QImage(); | return QImage(); | |||
} | } | |||
} | } | |||
QImage XpdfWidget::convertRegionToImage(int page, double x0, double y0, | QImage XpdfWidget::convertRegionToImage(int page, double x0, double y0, | |||
double x1, double y1, double dpi) { | double x1, double y1, double dpi, | |||
PDFDoc *doc; | bool transparent) { | |||
PDFRectangle *box; | ||||
SplashColor paperColor; | ||||
SplashOutputDev *out; | ||||
SplashBitmap *bitmap; | ||||
QImage *img; | ||||
int sliceX, sliceY, sliceW, sliceH, rot; | ||||
double t, k; | ||||
try { | try { | |||
if (!(doc = core->getDoc())) { | PDFDoc *doc = core->getDoc(); | |||
if (!doc) { | ||||
return QImage(); | return QImage(); | |||
} | } | |||
if (page < 1 || page > doc->getNumPages()) { | if (page < 1 || page > doc->getNumPages()) { | |||
return QImage(); | return QImage(); | |||
} | } | |||
if (x0 > x1) { | if (x0 > x1) { | |||
t = x0; x0 = x1; x1 = t; | double t = x0; x0 = x1; x1 = t; | |||
} | } | |||
if (y0 > y1) { | if (y0 > y1) { | |||
t = y0; y0 = y1; y1 = t; | double t = y0; y0 = y1; y1 = t; | |||
} | } | |||
box = doc->getCatalog()->getPage(page)->getCropBox(); | PDFRectangle *box = doc->getCatalog()->getPage(page)->getCropBox(); | |||
rot = doc->getPageRotate(page); | int rot = doc->getPageRotate(page); | |||
k = dpi / 72.0; | double k = dpi / 72.0; | |||
int sliceX, sliceY, sliceW, sliceH; | ||||
if (rot == 90) { | if (rot == 90) { | |||
sliceX = (int)(k * (y0 - box->y1)); | sliceX = (int)(k * (y0 - box->y1)); | |||
sliceY = (int)(k * (x0 - box->x1)); | sliceY = (int)(k * (x0 - box->x1)); | |||
sliceW = (int)(k * (y1 - y0)); | sliceW = (int)(k * (y1 - y0)); | |||
sliceH = (int)(k * (x1 - x0)); | sliceH = (int)(k * (x1 - x0)); | |||
} else if (rot == 180) { | } else if (rot == 180) { | |||
sliceX = (int)(k * (box->x2 - x1)); | sliceX = (int)(k * (box->x2 - x1)); | |||
sliceY = (int)(k * (y0 - box->y1)); | sliceY = (int)(k * (y0 - box->y1)); | |||
sliceW = (int)(k * (x1 - x0)); | sliceW = (int)(k * (x1 - x0)); | |||
sliceH = (int)(k * (y1 - y0)); | sliceH = (int)(k * (y1 - y0)); | |||
skipping to change at line 1350 | skipping to change at line 1369 | |||
sliceY = (int)(k * (box->x2 - x1)); | sliceY = (int)(k * (box->x2 - x1)); | |||
sliceW = (int)(k * (y1 - y0)); | sliceW = (int)(k * (y1 - y0)); | |||
sliceH = (int)(k * (x1 - x0)); | sliceH = (int)(k * (x1 - x0)); | |||
} else { | } else { | |||
sliceX = (int)(k * (x0 - box->x1)); | sliceX = (int)(k * (x0 - box->x1)); | |||
sliceY = (int)(k * (box->y2 - y1)); | sliceY = (int)(k * (box->y2 - y1)); | |||
sliceW = (int)(k * (x1 - x0)); | sliceW = (int)(k * (x1 - x0)); | |||
sliceH = (int)(k * (y1 - y0)); | sliceH = (int)(k * (y1 - y0)); | |||
} | } | |||
paperColor[0] = paperColor[1] = paperColor[2] = 0xff; | if (transparent) { | |||
out = new SplashOutputDev(splashModeRGB8, 4, gFalse, paperColor); | SplashColor paperColor; | |||
out->startDoc(doc->getXRef()); | paperColor[0] = paperColor[1] = paperColor[2] = 0xff; // unused | |||
doc->displayPageSlice(out, page, dpi, dpi, core->getRotate(), | SplashOutputDev *out = new SplashOutputDev(splashModeRGB8, 1, gFalse, | |||
gFalse, gTrue, gFalse, | paperColor); | |||
sliceX, sliceY, sliceW, sliceH); | out->setNoComposite(gTrue); | |||
bitmap = out->getBitmap(); | out->startDoc(doc->getXRef()); | |||
img = new QImage((const uchar *)bitmap->getDataPtr(), bitmap->getWidth(), | doc->displayPageSlice(out, page, dpi, dpi, core->getRotate(), | |||
bitmap->getHeight(), QImage::Format_RGB888); | gFalse, gTrue, gFalse, | |||
// force a copy | sliceX, sliceY, sliceW, sliceH); | |||
QImage img2(img->copy()); | SplashBitmap *bitmap = out->getBitmap(); | |||
delete img; | QImage img(bitmap->getWidth(), bitmap->getHeight(), | |||
delete out; | QImage::Format_ARGB32); | |||
return img2; | Guchar *pix = bitmap->getDataPtr(); | |||
Guchar *alpha = bitmap->getAlphaPtr(); | ||||
Guint *argb = (Guint *)img.bits(); | ||||
for (int y = 0; y < bitmap->getHeight(); ++y) { | ||||
for (int x = 0; x < bitmap->getWidth(); ++x) { | ||||
*argb = (*alpha << 24) | (pix[0] << 16) | (pix[1] << 8) | pix[2]; | ||||
pix += 3; | ||||
++alpha; | ||||
++argb; | ||||
} | ||||
} | ||||
delete out; | ||||
return img; | ||||
} else { | ||||
SplashColor paperColor; | ||||
paperColor[0] = paperColor[1] = paperColor[2] = 0xff; | ||||
SplashOutputDev *out = new SplashOutputDev(splashModeRGB8, 4, gFalse, | ||||
paperColor); | ||||
out->startDoc(doc->getXRef()); | ||||
doc->displayPageSlice(out, page, dpi, dpi, core->getRotate(), | ||||
gFalse, gTrue, gFalse, | ||||
sliceX, sliceY, sliceW, sliceH); | ||||
SplashBitmap *bitmap = out->getBitmap(); | ||||
QImage *img = new QImage((const uchar *)bitmap->getDataPtr(), | ||||
bitmap->getWidth(), bitmap->getHeight(), | ||||
QImage::Format_RGB888); | ||||
// force a copy | ||||
QImage img2(img->copy()); | ||||
delete img; | ||||
delete out; | ||||
return img2; | ||||
} | ||||
} catch (GMemException e) { | } catch (GMemException e) { | |||
return QImage(); | return QImage(); | |||
} | } | |||
} | } | |||
QImage XpdfWidget::getThumbnail(int page) { | QImage XpdfWidget::getThumbnail(int page) { | |||
Object thumbObj, decodeObj, colorSpaceObj, obj; | Object thumbObj, decodeObj, colorSpaceObj, obj; | |||
Dict *thumbDict; | Dict *thumbDict; | |||
GfxColorSpace *colorSpace; | GfxColorSpace *colorSpace; | |||
GfxImageColorMap *colorMap; | GfxImageColorMap *colorMap; | |||
skipping to change at line 2088 | skipping to change at line 2138 | |||
void XpdfWidget::mousePressEvent(QMouseEvent *e) { | void XpdfWidget::mousePressEvent(QMouseEvent *e) { | |||
int x, y; | int x, y; | |||
lastMousePressX[0] = lastMousePressX[1]; | lastMousePressX[0] = lastMousePressX[1]; | |||
lastMousePressY[0] = lastMousePressY[1]; | lastMousePressY[0] = lastMousePressY[1]; | |||
lastMousePressTime[0] = lastMousePressTime[1]; | lastMousePressTime[0] = lastMousePressTime[1]; | |||
lastMousePressX[1] = lastMousePressX[2]; | lastMousePressX[1] = lastMousePressX[2]; | |||
lastMousePressY[1] = lastMousePressY[2]; | lastMousePressY[1] = lastMousePressY[2]; | |||
lastMousePressTime[1] = lastMousePressTime[2]; | lastMousePressTime[1] = lastMousePressTime[2]; | |||
lastMousePressX[2] = e->x(); | lastMousePressX[2] = e->pos().x(); | |||
lastMousePressY[2] = e->y(); | lastMousePressY[2] = e->pos().y(); | |||
lastMousePressTime[2] = e->timestamp(); | lastMousePressTime[2] = e->timestamp(); | |||
lastMouseEventWasPress = true; | lastMouseEventWasPress = true; | |||
if (!mousePassthrough) { | if (!mousePassthrough) { | |||
x = (int)(e->x() * scaleFactor); | x = (int)(e->pos().x() * scaleFactor); | |||
y = (int)(e->y() * scaleFactor); | y = (int)(e->pos().y() * scaleFactor); | |||
if (e->button() == Qt::LeftButton) { | if (e->button() == Qt::LeftButton) { | |||
core->startSelection(x, y, e->modifiers() & Qt::ShiftModifier); | core->startSelection(x, y, e->modifiers() & Qt::ShiftModifier); | |||
} else if (e->button() == Qt::MidButton) { | } else if (e->button() == Qt::MiddleButton) { | |||
core->startPan(x, y); | core->startPan(x, y); | |||
} | } | |||
} | } | |||
emit mousePress(e); | emit mousePress(e); | |||
} | } | |||
void XpdfWidget::mouseReleaseEvent(QMouseEvent *e) { | void XpdfWidget::mouseReleaseEvent(QMouseEvent *e) { | |||
int x, y; | int x, y; | |||
// some versions of Qt drop mouse press events in double-clicks (?) | // some versions of Qt drop mouse press events in double-clicks (?) | |||
if (!lastMouseEventWasPress) { | if (!lastMouseEventWasPress) { | |||
mousePressEvent(e); | mousePressEvent(e); | |||
} | } | |||
lastMouseEventWasPress = false; | lastMouseEventWasPress = false; | |||
x = y = 0; | x = y = 0; | |||
if (!mousePassthrough) { | if (!mousePassthrough) { | |||
x = (int)(e->x() * scaleFactor); | x = (int)(e->pos().x() * scaleFactor); | |||
y = (int)(e->y() * scaleFactor); | y = (int)(e->pos().y() * scaleFactor); | |||
if (e->button() == Qt::LeftButton) { | if (e->button() == Qt::LeftButton) { | |||
core->endSelection(x, y); | core->endSelection(x, y); | |||
} else if (e->button() == Qt::MidButton) { | } else if (e->button() == Qt::MiddleButton) { | |||
core->endPan(x, y); | core->endPan(x, y); | |||
} | } | |||
} | } | |||
emit mouseRelease(e); | emit mouseRelease(e); | |||
// double and triple clicks have to be "quick" and "nearby"; | // double and triple clicks have to be "quick" and "nearby"; | |||
// single clicks just have to be "nearby" | // single clicks just have to be "nearby" | |||
ulong maxTime = (ulong)QApplication::doubleClickInterval(); | ulong maxTime = (ulong)QApplication::doubleClickInterval(); | |||
int maxDistance = QApplication::startDragDistance(); | int maxDistance = QApplication::startDragDistance(); | |||
if (e->timestamp() - lastMousePressTime[0] < 2 * maxTime && | if (e->timestamp() - lastMousePressTime[0] < 2 * maxTime && | |||
abs(e->x() - lastMousePressX[0]) + abs(e->y() - lastMousePressY[0]) | abs(e->pos().x() - lastMousePressX[0]) | |||
<= maxDistance) { | + abs(e->pos().y() - lastMousePressY[0]) <= maxDistance) { | |||
if (!mousePassthrough && e->button() == Qt::LeftButton) { | if (!mousePassthrough && e->button() == Qt::LeftButton) { | |||
core->selectLine(x, y); | core->selectLine(x, y); | |||
} | } | |||
emit mouseTripleClick(e); | emit mouseTripleClick(e); | |||
} else if (e->timestamp() - lastMousePressTime[1] < maxTime && | } else if (e->timestamp() - lastMousePressTime[1] < maxTime && | |||
abs(e->x() - lastMousePressX[1]) + abs(e->y() - lastMousePressY[1]) | abs(e->pos().x() - lastMousePressX[1]) | |||
<= maxDistance) { | + abs(e->pos().y() - lastMousePressY[1]) <= maxDistance) { | |||
if (!mousePassthrough && e->button() == Qt::LeftButton) { | if (!mousePassthrough && e->button() == Qt::LeftButton) { | |||
core->selectWord(x, y); | core->selectWord(x, y); | |||
} | } | |||
emit mouseDoubleClick(e); | emit mouseDoubleClick(e); | |||
} else if (abs(e->x() - lastMousePressX[2]) + abs(e->y() - lastMousePressY[2]) | } else if (abs(e->pos().x() - lastMousePressX[2]) | |||
<= maxDistance) { | + abs(e->pos().y() - lastMousePressY[2]) <= maxDistance) { | |||
emit mouseClick(e); | emit mouseClick(e); | |||
} | } | |||
} | } | |||
void XpdfWidget::mouseMoveEvent(QMouseEvent *e) { | void XpdfWidget::mouseMoveEvent(QMouseEvent *e) { | |||
int x, y; | int x, y; | |||
x = (int)(e->x() * scaleFactor); | x = (int)(e->pos().x() * scaleFactor); | |||
y = (int)(e->y() * scaleFactor); | y = (int)(e->pos().y() * scaleFactor); | |||
core->mouseMove(x, y); | core->mouseMove(x, y); | |||
emit mouseMove(e); | emit mouseMove(e); | |||
} | } | |||
void XpdfWidget::wheelEvent(QWheelEvent *e) { | void XpdfWidget::wheelEvent(QWheelEvent *e) { | |||
if (!mousePassthrough) { | if (!mousePassthrough) { | |||
QAbstractScrollArea::wheelEvent(e); | QAbstractScrollArea::wheelEvent(e); | |||
} | } | |||
emit mouseWheel(e); | emit mouseWheel(e); | |||
} | } | |||
End of changes. 18 change blocks. | ||||
67 lines changed or deleted | 117 lines changed or added |