diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-06-22 22:15:08 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2024-03-26 23:22:12 -0700 |
commit | ac447e8dc2f0b0c711ca17211646784dc9c5395f (patch) | |
tree | adb8acbccc54e3a6f709816191c7c36852a2c5af /src | |
parent | eae0536be815f732a1c11c892d5808ce4113f365 (diff) |
PdfLinkModel: if quadpoints available, convert to rects
If QPdfLink stored polygons instead of rects, it would make sense to
transform each point using QPdfDocumentPrivate::mapPageToView();
but the quadpoints (polygons) in the test.pdf from QTBUG-100630 happen
to describe rectangles. This patch successfully does the transform so
that they line up with the link text. It doesn't do much good since the
links in that PDF are invalid anyway, but presumably links using
quadpoints occur in the real world sometimes.
Pick-to: 6.7
Task-number: QTBUG-100630
Change-Id: I0cb151dbb30ca73c8f9ed2bcd29508ced05de064
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/pdf/qpdflinkmodel.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/pdf/qpdflinkmodel.cpp b/src/pdf/qpdflinkmodel.cpp index 645dff21a..0a8b1e812 100644 --- a/src/pdf/qpdflinkmodel.cpp +++ b/src/pdf/qpdflinkmodel.cpp @@ -203,7 +203,28 @@ void QPdfLinkModelPrivate::update() std::swap(rect.bottom, rect.top); QPdfLink linkData; - linkData.d->rects << document->d->mapPageToView(pdfPage, rect.left, rect.top, rect.right, rect.bottom); + // Use quad points if present; otherwise use the rect. + if (int quadPointsCount = FPDFLink_CountQuadPoints(linkAnnot) > 0) { + for (int i = 0; i < quadPointsCount; ++i) { + FS_QUADPOINTSF point; + if (FPDFLink_GetQuadPoints(linkAnnot, i, &point)) { + // Quadpoints are counter clockwise from bottom left (x1, y1) + QPolygonF poly; + poly << QPointF(point.x1, point.y1); + poly << QPointF(point.x2, point.y2); + poly << QPointF(point.x3, point.y3); + poly << QPointF(point.x4, point.y4); + QRectF bounds = poly.boundingRect(); + bounds = document->d->mapPageToView(pdfPage, bounds.left(), bounds.top(), bounds.right(), bounds.bottom()); + qCDebug(qLcLink) << "quadpoints" << i << "of" << quadPointsCount << ":" << poly << "mapped bounds" << bounds; + linkData.d->rects << bounds; + // QPdfLink could store polygons rather than rects, to get the benefit of quadpoints; + // so far we didn't bother. It would be an API change, and we'd need to use Shapes in PdfLinkDelegate.qml + } + } + } else { + linkData.d->rects << document->d->mapPageToView(pdfPage, rect.left, rect.top, rect.right, rect.bottom); + } FPDF_DEST dest = FPDFLink_GetDest(doc, linkAnnot); FPDF_ACTION action = FPDFLink_GetAction(linkAnnot); switch (FPDFAction_GetType(action)) { @@ -211,7 +232,7 @@ void QPdfLinkModelPrivate::update() case PDFACTION_GOTO: { linkData.d->page = FPDFDest_GetDestPageIndex(doc, dest); if (linkData.d->page < 0) { - qCWarning(qLcLink) << "skipping link with invalid page number"; + qCWarning(qLcLink) << "skipping link with invalid page number" << linkData.d->page; continue; // while enumerating links } FPDF_BOOL hasX, hasY, hasZoom; |