Add support for drawing a hyperlink in QPdfEngine
Adds the drawHyperlink method so that clients can draw a hyperlink pointing to the specified URL at the specified rectangle. That new method is to be used by GraphicContext::setURLForRect implementations that want to render anchors as clickable links in PDF documents. Task-number: QTBUG-44563 Change-Id: I7b0c602da37ee157d18115c531ab1b11fe304c13 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>bb10
parent
fd57ec5c5f
commit
e9eeb68a65
|
|
@ -996,6 +996,34 @@ void QPdfEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
|
|||
*d->currentPage << "Q\n";
|
||||
}
|
||||
|
||||
void QPdfEngine::drawHyperlink(const QRectF &r, const QUrl &url)
|
||||
{
|
||||
Q_D(QPdfEngine);
|
||||
|
||||
const uint annot = d->addXrefEntry(-1);
|
||||
const QByteArray urlascii = url.toEncoded();
|
||||
int len = urlascii.size();
|
||||
QVarLengthArray<char> url_esc(0);
|
||||
for (int j = 0; j < len; j++) {
|
||||
if (urlascii[j] == '(' || urlascii[j] == ')' || urlascii[j] == '\\')
|
||||
url_esc.append('\\');
|
||||
url_esc.append(urlascii[j]);
|
||||
}
|
||||
url_esc.append('\0');
|
||||
|
||||
char buf[256];
|
||||
const QRectF rr = d->pageMatrix().mapRect(r);
|
||||
d->xprintf("<<\n/Type /Annot\n/Subtype /Link\n/Rect [");
|
||||
d->xprintf("%s ", qt_real_to_string(rr.left(), buf));
|
||||
d->xprintf("%s ", qt_real_to_string(rr.top(), buf));
|
||||
d->xprintf("%s ", qt_real_to_string(rr.right(), buf));
|
||||
d->xprintf("%s", qt_real_to_string(rr.bottom(), buf));
|
||||
d->xprintf("]\n/Border [0 0 0]\n/A <<\n");
|
||||
d->xprintf("/Type /Action\n/S /URI\n/URI (%s)\n", url_esc.constData());
|
||||
d->xprintf(">>\n>>\n");
|
||||
d->xprintf("endobj\n");
|
||||
d->currentPage->annotations.append(annot);
|
||||
}
|
||||
|
||||
void QPdfEngine::updateState(const QPaintEngineState &state)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -188,6 +188,8 @@ public:
|
|||
Qt::ImageConversionFlags flags = Qt::AutoColor) Q_DECL_OVERRIDE;
|
||||
void drawTiledPixmap (const QRectF & rectangle, const QPixmap & pixmap, const QPointF & point) Q_DECL_OVERRIDE;
|
||||
|
||||
void drawHyperlink(const QRectF &r, const QUrl &url);
|
||||
|
||||
void updateState(const QPaintEngineState &state) Q_DECL_OVERRIDE;
|
||||
|
||||
int metric(QPaintDevice::PaintDeviceMetric metricType) const;
|
||||
|
|
|
|||
Loading…
Reference in New Issue