Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix links made with annotations #93

Merged
merged 2 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion bepdf/beos/Annotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,36 @@ void TextAnnot::Print() {
fprintf(stderr, "Open: %s\n", IsOpen() ? "true" : "false");
}

LinkAnnot::LinkAnnot(LinkAnnot* copy)
: Annotation(copy),
mLinkAction(NULL)
{
}


LinkAnnot::LinkAnnot(Dict* d)
: Annotation(d),
mLinkAction(NULL)
{
Object obj;

// look for destination
if (d->lookup("Dest", &obj) && !obj.isNull()) {
mLinkAction = LinkAction::parseDest(&obj);
// look for action
} else {
if (d->lookup("A", &obj) && obj.isDict()) {
mLinkAction = LinkAction::parseAction(&obj/*, baseURI*/);
}
}
obj.free();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of the file is in tabs, but this is in spaces. Koder bug? :p

Copy link
Member Author

@KapiX KapiX Jul 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I do not see .editorconfig in this repo. Where would the bug be? :)
  2. I was more occupied reverting all the removed trailing whitespace to actually notice that indentation is inconsistent. ;)
  3. This is copied verbatim from XPDF.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, can't Koder auto-detect the use of tabs in most source files? I thought it did...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It overrides settings only if there is .editorconfig in the repo (and that has a few bugs). There is no auto-detection.

}

void LinkAnnot::Print() {
fprintf(stderr, "Link\n");
Annotation::Print();
}

free_text_justification ToFreeTextJustification(const char* name) {
if (strcmp(name, "left") == 0) return left_justify;
if (strcmp(name, "centered") == 0) return centered;
Expand Down Expand Up @@ -1350,7 +1380,9 @@ Annotations::Annotations(Object* annots, BePDFAcroForm* acroForm)
a = new StampAnnot(annot.getDict());
} else if (subType.isName("Ink")) {
a = new InkAnnot(annot.getDict());
} else if (subType.isName("FileAttachment") == 0){
} else if (subType.isName("Link")) {
a = new LinkAnnot(annot.getDict());
} else if (subType.isName("FileAttachment") == 0) {
a = new FileAttachmentAnnot(annot.getDict());
}

Expand Down
16 changes: 16 additions & 0 deletions bepdf/beos/Annotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,22 @@ class TextAnnot : public Annotation {
virtual void Print();
};

class LinkAnnot : public Annotation {
private:
LinkAction *mLinkAction;

public:
LinkAnnot(LinkAnnot* copy);
LinkAnnot(Dict* annot);

Annotation* Clone() { return new LinkAnnot(this); }

LinkAction* GetLinkAction() { return mLinkAction; }

virtual void Visit(AnnotVisitor* v) { v->DoLink(this); }
virtual void Print();
};

class StyledAnnot : public Annotation {
private:
BorderStyle mStyle;
Expand Down
20 changes: 16 additions & 4 deletions bepdf/beos/PDFView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,12 +1362,18 @@ PDFView::HandleLink(BPoint point) {
char *s;
BString pdfFile;

action = OnLink(point);
if (mAnnotation) {
ShowAnnotWindow(false);
return true;
LinkAnnot* link = dynamic_cast<LinkAnnot*>(mAnnotation);
if(link == NULL) {
ShowAnnotWindow(false);
return true;
} else {
action = link->GetLinkAction();
}
}

if ((action = OnLink(point)) != NULL) {
if (action != NULL) {
// PDFLock lock;

if (IsLinkToPDF(action, &pdfFile)) {
Expand Down Expand Up @@ -1681,7 +1687,13 @@ PDFView::DisplayLink(BPoint point)
mLinkAction = NULL;
mAnnotation = annot;
SetViewCursor(gApp->linkCursor);
SetToolTip(B_TRANSLATE("Annotation"));
LinkAnnot* link = dynamic_cast<LinkAnnot*>(annot);
if(link == NULL) {
SetToolTip(B_TRANSLATE("Annotation"));
} else {
LinkToString(link->GetLinkAction(), &str);
SetToolTip( str.String() );
}
ShowToolTip();
}
return;
Expand Down