Skip to content

Commit 50ee75c

Browse files
committed
when link and an image overlap on page, prioritize links (fixes #5200)
Also for #5119, #5056
1 parent 774c6a4 commit 50ee75c

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/EngineMupdf.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,10 @@ static TocItem* NewTocItemWithDestination(TocItem* parent, char* title, IPageDes
10291029

10301030
// TODO: could be optimized
10311031
static bool RectFullyContains(RectF r1, RectF r2) {
1032+
// if same size, we don't consider it that one covers another
1033+
if (r1 == r2) {
1034+
return false;
1035+
}
10321036
return r1.Contains(r2.TL()) && r1.Contains(r2.BR());
10331037
}
10341038

@@ -1057,18 +1061,29 @@ static bool RemoveHeWhoFullyContains(Vec<IPageElement*>& els) {
10571061
// that is fully obscured by all other elements
10581062
// if not fully obscured, return the first one
10591063
static IPageElement* PickBestElement(Vec<IPageElement*>& els) {
1060-
if (els.Size() == 0) {
1064+
int n = els.Size();
1065+
if (n == 0) {
10611066
return nullptr;
10621067
}
1063-
1064-
Encore:
1065-
int n = els.Size();
10661068
if (n == 1) {
10671069
return els[0];
10681070
}
1071+
1072+
// for https://github.com/sumatrapdfreader/sumatrapdf/issues/5200
1073+
// priority for destinations (e.g. links) over images
1074+
for (IPageElement* el : els) {
1075+
if (el->GetKind() == kindPageElementDest) {
1076+
return el;
1077+
}
1078+
}
1079+
Encore:
10691080
bool didRemove = RemoveHeWhoFullyContains(els);
10701081
if (didRemove) {
10711082
ReportIf(els.Size() != n - 1);
1083+
n = els.Size();
1084+
if (n == 1) {
1085+
return els[0];
1086+
}
10721087
goto Encore;
10731088
}
10741089
return els[0];

0 commit comments

Comments
 (0)