Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not action_obj:
continue
action = self.get_annot_action(action_obj.any.type, action_obj, annotation.area)
if not action:
continue
elif annot_type == Poppler.AnnotType.FILE_ATTACHMENT:
attachment = annotation.annot.get_attachment()
prefix, ext = os.path.splitext(attachment.name)
with tempfile.NamedTemporaryFile('wb', suffix=ext, prefix=prefix, delete=False) as f:
# now the file name is shotgunned
filename = f.name
self.parent.remove_on_exit(filename)
if not attachment.save(filename):
logger.error(_("Pympress can not extract attached file"))
continue
action = Link.build_closure(fileopen, filename)
elif annot_type in {Poppler.AnnotType.TEXT, Poppler.AnnotType.POPUP,
Poppler.AnnotType.FREE_TEXT}:
# text-only annotations, hide them from screen
self.page.remove_annot(annotation.annot)
continue
elif annot_type in {Poppler.AnnotType.STRIKE_OUT, Poppler.AnnotType.HIGHLIGHT,
Poppler.AnnotType.UNDERLINE, Poppler.AnnotType.SQUIGGLY,
Poppler.AnnotType.POLYGON, Poppler.AnnotType.POLY_LINE,
Poppler.AnnotType.SQUARE, Poppler.AnnotType.CIRCLE,
Poppler.AnnotType.CARET, Poppler.AnnotType.LINE,
Poppler.AnnotType.STAMP, Poppler.AnnotType.INK}:
# Poppler already renders annotation of these types, nothing more can be done
# even though the rendering isn't always perfect.
continue
else:
logger.warning(_("Pympress can not interpret annotation of type:") + " {} ".format(annot_type))
dest = self.parent.doc.find_dest(dest_name)
if dest:
return Link.build_closure(self.parent.goto, dest.page_num)
elif dest_name == "GoBack":
return self.parent.hist_prev
elif dest_name == "GoForward":
return self.parent.hist_next
elif dest_name == "FirstPage":
return Link.build_closure(self.parent.goto, 0)
elif dest_name == "PrevPage":
return Link.build_closure(self.parent.goto, self.page_nb - 1)
elif dest_name == "NextPage":
return Link.build_closure(self.parent.goto, self.page_nb + 1)
elif dest_name == "LastPage":
return Link.build_closure(self.parent.goto, self.parent.pages_number() - 1)
elif dest_name == "GoToPage":
# Same as the 'G' action which allows one to pick a page to jump to
return Link.build_closure(self.parent.start_editing_page_number, )
elif dest_name == "Find":
# TODO popup a text box and search results with Page.find_text
# http://lazka.github.io/pgi-docs/Poppler-0.18/classes/Page.html#Poppler.Page.find_text
warning = _("Pympress does not yet support link type \"{}\" to \"{}\"").format(link_type, dest_name)
else:
# TODO find out other possible named actions?
warning = _("Pympress does not recognize link type \"{}\" to \"{}\"").format(link_type, dest_name)
elif link_type == Poppler.ActionType.LAUNCH:
launch = action.launch
if launch.params:
logger.warning("ignoring params: " + str(launch.params))
else:
filename = self.parent.get_full_path(media.get_filename())
if not filename:
logger.error(_("Pympress can not find file ") + media.get_filename())
return None
# TODO grab the show_controls, autoplay, repeat
relative_margins = Poppler.Rectangle()
relative_margins.x1 = rect.x1 / self.pw # left
relative_margins.x2 = 1.0 - rect.x2 / self.pw # right
relative_margins.y1 = rect.y1 / self.ph # bottom
relative_margins.y2 = 1.0 - rect.y2 / self.ph # top
media = (relative_margins, filename, False)
self.medias.append(media)
return Link.build_closure(self.parent.play_media, hash(media))
else:
return self.get_link_action(link_type, action)
elif link_type == Poppler.ActionType.GOTO_DEST:
dest_type = action.goto_dest.dest.type
if dest_type == Poppler.DestType.NAMED:
dest = self.parent.doc.find_dest(action.goto_dest.dest.named_dest)
if dest:
return Link.build_closure(self.parent.goto, dest.page_num - 1)
elif dest_type != Poppler.DestType.UNKNOWN:
return Link.build_closure(self.parent.goto, action.goto_dest.dest.page_num - 1)
elif link_type == Poppler.ActionType.NAMED:
dest_name = action.named.named_dest
dest = self.parent.doc.find_dest(dest_name)
if dest:
return Link.build_closure(self.parent.goto, dest.page_num)
elif dest_name == "GoBack":
return self.parent.hist_prev
elif dest_name == "GoForward":
return self.parent.hist_next
elif dest_name == "FirstPage":
return Link.build_closure(self.parent.goto, 0)
elif dest_name == "PrevPage":
return Link.build_closure(self.parent.goto, self.page_nb - 1)
elif dest_name == "NextPage":
return Link.build_closure(self.parent.goto, self.page_nb + 1)
elif dest_name == "LastPage":
return Link.build_closure(self.parent.goto, self.parent.pages_number() - 1)
elif dest_name == "GoToPage":
# Same as the 'G' action which allows one to pick a page to jump to
return Link.build_closure(self.parent.start_editing_page_number, )
elif dest_name == "Find":
return Link.build_closure(self.parent.goto, dest.page_num)
elif dest_name == "GoBack":
return self.parent.hist_prev
elif dest_name == "GoForward":
return self.parent.hist_next
elif dest_name == "FirstPage":
return Link.build_closure(self.parent.goto, 0)
elif dest_name == "PrevPage":
return Link.build_closure(self.parent.goto, self.page_nb - 1)
elif dest_name == "NextPage":
return Link.build_closure(self.parent.goto, self.page_nb + 1)
elif dest_name == "LastPage":
return Link.build_closure(self.parent.goto, self.parent.pages_number() - 1)
elif dest_name == "GoToPage":
# Same as the 'G' action which allows one to pick a page to jump to
return Link.build_closure(self.parent.start_editing_page_number, )
elif dest_name == "Find":
# TODO popup a text box and search results with Page.find_text
# http://lazka.github.io/pgi-docs/Poppler-0.18/classes/Page.html#Poppler.Page.find_text
warning = _("Pympress does not yet support link type \"{}\" to \"{}\"").format(link_type, dest_name)
else:
# TODO find out other possible named actions?
warning = _("Pympress does not recognize link type \"{}\" to \"{}\"").format(link_type, dest_name)
elif link_type == Poppler.ActionType.LAUNCH:
launch = action.launch
if launch.params:
logger.warning("ignoring params: " + str(launch.params))
filepath = self.parent.get_full_path(launch.file_name)
if not filepath:
logger.error("can not find file " + launch.file_name)
elif link_type == Poppler.ActionType.MOVIE: # Poppler 0.20
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.URI:
warning = Link.build_closure(webbrowser.open_new_tab, action.uri.uri)
elif link_type == Poppler.ActionType.GOTO_REMOTE:
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.OCG_STATE:
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.JAVASCRIPT:
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.UNKNOWN:
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
else:
warning = _("Pympress does not recognize link type \"{}\"").format(link_type)
return Link.build_closure(logger.warning, warning)
else:
# TODO find out other possible named actions?
warning = _("Pympress does not recognize link type \"{}\" to \"{}\"").format(link_type, dest_name)
elif link_type == Poppler.ActionType.LAUNCH:
launch = action.launch
if launch.params:
logger.warning("ignoring params: " + str(launch.params))
filepath = self.parent.get_full_path(launch.file_name)
if not filepath:
logger.error("can not find file " + launch.file_name)
return lambda: None
else:
return Link.build_closure(fileopen, filepath)
elif link_type == Poppler.ActionType.RENDITION: # Poppler 0.22
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.MOVIE: # Poppler 0.20
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.URI:
warning = Link.build_closure(webbrowser.open_new_tab, action.uri.uri)
elif link_type == Poppler.ActionType.GOTO_REMOTE:
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.OCG_STATE:
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.JAVASCRIPT:
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.UNKNOWN:
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
else:
logger.warning("ignoring params: " + str(launch.params))
filepath = self.parent.get_full_path(launch.file_name)
if not filepath:
logger.error("can not find file " + launch.file_name)
return lambda: None
else:
return Link.build_closure(fileopen, filepath)
elif link_type == Poppler.ActionType.RENDITION: # Poppler 0.22
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.MOVIE: # Poppler 0.20
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.URI:
warning = Link.build_closure(webbrowser.open_new_tab, action.uri.uri)
elif link_type == Poppler.ActionType.GOTO_REMOTE:
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.OCG_STATE:
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.JAVASCRIPT:
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
elif link_type == Poppler.ActionType.UNKNOWN:
warning = _("Pympress does not yet support link type \"{}\"").format(link_type)
else:
warning = _("Pympress does not recognize link type \"{}\"").format(link_type)
return Link.build_closure(logger.warning, warning)