Save attached files when

C code was mostly copy pasted from
$MUPDF/platform/gl/gl-annotate.c:save_attachment_dialog

This piggybacks on existing savepath-command.

Testing was done when savepath-command was set to "echo '%s'" and a
document from https://github.com/moosotc/llpp/issues/170 [1]. The
annotation rectangles an the fifth page overlap making it impossible
to use mouse to click on the icon with a pin (file attachment
annotation), however one can enter keyboard navigation mode (set to
insert by default) and select last/covered annotation rectangle with
the keyboard) (selecting this annotation via hint mode (bound to 'F'
by default) works too)

[1] https://github.com/moosotc/llpp/files/6566150/CorrectionLEMAIRE_SAKURA.AMELIE_CPFR_DEV02.pdf
This commit is contained in:
malc 2021-05-31 14:54:34 +03:00
parent 186695fe4b
commit d9acdc0081
3 changed files with 30 additions and 1 deletions

2
ffi.ml
View File

@ -43,6 +43,8 @@ external hasunsavedchanges : unit -> bool = "ml_hasunsavedchanges"
external savedoc : string -> unit = "ml_savedoc"
external gettextannot : opaque -> slinkindex -> string = "ml_gettextannot"
external getfileannot : opaque -> slinkindex -> string = "ml_getfileannot"
external savefileannot : opaque -> slinkindex -> string -> unit
= "ml_savefileannot"
external wcmd : Unix.file_descr -> bytes -> int -> unit = "ml_wcmd"
external rcmd : Unix.file_descr -> string = "ml_rcmd"
external uritolocation : string -> (pageno * float * float) = "ml_uritolocation"

14
link.c
View File

@ -2522,6 +2522,20 @@ ML (getfileannot (value ptr_v, value n_v))
CAMLreturn (ret_v);
}
ML0 (savefileannot (value ptr_v, value n_v, value path_v))
{
CAMLparam3 (ptr_v, n_v, path_v);
struct page *page = parse_pointer (__func__, String_val (ptr_v));
lock (__func__);
struct slink *slink = &page->slinks[Int_val (n_v)];
pdf_obj *fs = pdf_dict_get (state.ctx, slink->u.annot->obj, PDF_NAME (FS));
fz_buffer *buf = pdf_load_embedded_file (state.ctx, fs);
fz_save_buffer (state.ctx, buf, String_val (path_v));
fz_drop_buffer (state.ctx, buf);
unlock (__func__);
}
ML (getlinkrect (value ptr_v, value n_v))
{
CAMLparam2 (ptr_v, n_v);

15
main.ml
View File

@ -2760,8 +2760,21 @@ let gotounder = function
let pageno, x, y = Ffi.uritolocation s in
addnav ();
gotopagexy pageno x y
| Utext _ | Unone | Ufileannot _ -> ()
| Utext _ | Unone -> ()
| Utextannot (opaque, slinkindex) -> enterannotmode opaque slinkindex
| Ufileannot (opaque, slinkindex) ->
if emptystr conf.savecmd
then adderrmsg "savepath-command is empty"
"don't know where to save attachment"
else
let filename = Ffi.getfileannot opaque slinkindex in
let savecmd = Str.global_replace Re.percent filename conf.savecmd in
let path =
getcmdoutput
(adderrfmt savecmd
"failed to obtain path to the saved attachment: %s") savecmd
in
Ffi.savefileannot opaque slinkindex path
let gotooutline (_, _, kind) =
match kind with