Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
KItinerary
Commits
2b66dacb
Commit
2b66dacb
authored
Aug 19, 2022
by
Volker Krause
Browse files
Add API for extractor scripts to query PDF links in a specific sub rect
parent
29942f8f
Changes
3
Hide whitespace changes
Inline
Side-by-side
autotests/pdfdocumenttest.cpp
View file @
2b66dacb
...
...
@@ -86,10 +86,17 @@ private Q_SLOTS:
QCOMPARE
(
doc
->
pageCount
(),
1
);
const
auto
page
=
doc
->
page
(
0
);
QCOMPARE
(
page
.
linkCount
(),
1
);
const
auto
link
=
page
.
link
(
0
);
auto
link
=
page
.
link
(
0
);
QCOMPARE
(
link
.
url
(),
QLatin1String
(
"https://kde.org"
));
qDebug
()
<<
link
.
area
();
QVERIFY
(
link
.
area
().
isValid
());
QCOMPARE
(
page
.
linksInRect
(
0.0
,
0.0
,
1.0
,
1.0
).
size
(),
1
);
QCOMPARE
(
page
.
linksInRect
(
0.0
,
0.0
,
1.0
,
0.5
).
size
(),
1
);
link
=
page
.
linksInRect
(
0.0
,
0.0
,
0.5
,
0.5
).
at
(
0
).
value
<
PdfLink
>
();
QCOMPARE
(
link
.
url
(),
QLatin1String
(
"https://kde.org"
));
QCOMPARE
(
page
.
linksInRect
(
0.0
,
0.0
,
0.2
,
0.5
).
size
(),
1
);
QCOMPARE
(
page
.
linksInRect
(
0.0
,
0.5
,
1.0
,
1.0
).
size
(),
0
);
}
void
testInvalidPdfDocument
()
...
...
src/lib/pdf/pdfdocument.cpp
View file @
2b66dacb
...
...
@@ -175,6 +175,31 @@ QVariantList PdfPage::linksVariant() const
return
l
;
}
QVariantList
PdfPage
::
linksInRect
(
double
left
,
double
top
,
double
right
,
double
bottom
)
const
{
QRectF
bbox
(
QPointF
(
left
,
top
),
QPointF
(
right
,
bottom
));
d
->
load
();
QVariantList
l
;
for
(
const
auto
&
link
:
d
->
m_links
)
{
if
(
!
link
.
area
().
intersects
(
bbox
))
{
continue
;
}
l
.
push_back
(
QVariant
::
fromValue
(
link
));
}
std
::
sort
(
l
.
begin
(),
l
.
end
(),
[](
const
auto
&
lhs
,
const
auto
&
rhs
)
{
const
auto
lhsLink
=
lhs
.
template
value
<
PdfLink
>();
const
auto
rhsLink
=
rhs
.
template
value
<
PdfLink
>();
if
(
lhsLink
.
area
().
top
()
==
rhsLink
.
area
().
top
())
{
return
lhsLink
.
area
().
left
()
<
rhsLink
.
area
().
left
();
}
return
lhsLink
.
area
().
top
()
<
rhsLink
.
area
().
top
();
});
return
l
;
}
PdfDocument
::
PdfDocument
(
QObject
*
parent
)
:
QObject
(
parent
)
...
...
src/lib/pdf/pdfdocument.h
View file @
2b66dacb
...
...
@@ -62,6 +62,12 @@ public:
/** The n-th link found in this document. */
PdfLink
link
(
int
index
)
const
;
/** Returns all links in the specified sub-rect of this page.
* All parameters are relative values between @c 0 and @c 1 of the entire page size.
* Links are sorted top to bottom / left to right based on their top left corner.
*/
Q_INVOKABLE
QVariantList
linksInRect
(
double
left
,
double
top
,
double
right
,
double
bottom
)
const
;
private:
QVariantList
imagesVariant
()
const
;
QVariantList
linksVariant
()
const
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment