Skip to content

Commit

Permalink
Merge changes from the original author of llpp (malc)
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Stecker committed Aug 30, 2024
2 parents dbf07cf + b0bca89 commit e8f7830
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 61 deletions.
8 changes: 2 additions & 6 deletions BUILDING
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Prerequisites for building from sources:
mupdf [https://mupdf.com]
opengl [https://en.wikipedia.org/wiki/OpenGL]
git [https://git-scm.com]
ocaml 4.14.0 [https://ocaml.org]
ocaml 5.2.0 [https://ocaml.org]
If not present will be downloaded from the network and
built/used locally without system-wide installation.
This requires either:
Expand All @@ -19,9 +19,5 @@ To download mupdf+prerequisites that llpp is known to work with:
To build llpp (binary will be in build/llpp):
- bash build.bash build

# by default llpp looks for .config/llpp.conf file
# hence .config directory should be present otherwise
# llpp will fail to start

To build man pages (will be in build/doc/[name].1)
To build man pages
- bash build.bash build doc
17 changes: 10 additions & 7 deletions build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ mudeps=('freetype2' 'gumbo' 'harfbuzz' 'libjpeg' 'libopenjp2' 'x11' 'zlib')

mkdir -p $outd/{$wsid,lablGL}

isfresh() {
test -f "$1.past" || return 1
test "$(<$1.past)" = "$2"
} 2>/dev/null

# thanks to Sebastian Rasmussen
isfresh() { test "$(cat $1.past)" = "$2"; } 2>/dev/null

mbt=${mbt:-release}
test -n "${gmk:-}" && gmk=false || gmk=true
Expand Down Expand Up @@ -72,10 +69,15 @@ oincs() {
}

oflags() {
local f=""
case "${1#$outd/}" in
lablGL/*) f="-g";;
utf8syms.cmo|confstruct.cmo|config.cmo|ffi.cmo|wsi/cocoa/wsi.cmo)
utf8syms.cmo|confstruct.cmo)
f="-g -strict-sequence -strict-formats -alert @all-missing-mli";;
wsi/x11/wsi.cm[io]) f="-g -I +unix";;
utils.cmi) f="-g -I +unix -I +str";;
config.cmo|ffi.cmo|main.cmo|utils.cmo|parser.cmo|uiutils.cmo|help.cmo)
f="-g -I +unix -I +str -strict-sequence -strict-formats -alert @all-missing-mli";;
*) f="-g -strict-sequence -strict-formats -alert @all -warn-error @A";;
esac
echo $(oincs $outd $1) -I +unix -I +str $f
Expand Down Expand Up @@ -288,7 +290,8 @@ else
bocamlc wsi/x11/xlib.o
fi

cmd="ocamlc -custom $libs -o $outd/llpp $cobjs $modules -cclib \"$clibs\" -I +unix -I +str"
cmd="ocamlc -custom $libs -o $outd/llpp $cobjs $modules -cclib \"$clibs\""
cmd="$cmd -I +unix -I +str"
keycmd="digest $outd/llpp $cobjs $modules $mulibs"
isfresh "$outd/llpp" "$cmd$(eval $keycmd)" || {
echo linking $outd/llpp
Expand Down
14 changes: 9 additions & 5 deletions config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ let multicolumns_of_string s =
try
(int_of_string s, 0, 0)
with _ ->
Scanf.sscanf s "%u,%u,%u" (fun n a b ->
if a > 1 || b > 1
then error "subtly broken";
(n, a, b)
)
try
Scanf.sscanf s "%u,%u,%u" (fun n a b ->
if a > 1 || b > 1
then error "subtly broken";
(n, a, b)
)
with End_of_file ->
(1, 0, 0)

include Confstruct

Expand Down Expand Up @@ -365,6 +368,7 @@ module S = struct
let tilelru : (tilemapkey * opaque * pixmapsize) Queue.t = Queue.create ()
let fontpath = ref E.s
let redirstderr = ref false
let loading = ref true
end

let conf = { defconf with keyhashes = copykeyhashes defconf }
Expand Down
13 changes: 7 additions & 6 deletions genconfstruct.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
set -eu

cat<<EOF
let zs = ""
type rgb = (float * float * float)
and rgba = (float * float * float * float)
and fitmodel = | FitWidth | FitProportional | FitPage
Expand Down Expand Up @@ -105,8 +106,8 @@ g beyecolumns "columncount option" None
s selcmd "{|$clip|}"
s pastecmd "{|$paste|}"
s paxcmd '{|echo PAX "%s">&2|}'
s passcmd Utils.E.s
s savecmd Utils.E.s
s passcmd zs
s savecmd zs
b updatecurs true
K keyhashes '(string * keyhash) list' \
'(let mk n = (n, Hashtbl.create 1) in
Expand All @@ -119,15 +120,15 @@ s stcmd "{|echo SyncTex|}"
b riani false
g paxmark mark MarkWord
b leftscroll false
s title Utils.E.s
s title zs
f lastvisit 0.0
b annotinline true
b coarseprespos false
g css css Utils.E.s
g css css zs
b usedoccss true
s key Utils.E.s
s key zs
P pax
g dcf dcf Utils.E.s
g dcf dcf zs
s hcs "{|aoeuidhtns|}"
i rlw 420
i rlh 595
Expand Down
2 changes: 1 addition & 1 deletion help.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let keys =
{|-----Quitting-----
escape/q - quit
q - quit
Q - quit without saving the configuration or changes
W - save changes

Expand Down
62 changes: 30 additions & 32 deletions link.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@
#pragma GCC diagnostic ignored "-Wdocumentation"
#pragma GCC diagnostic ignored "-Wdouble-promotion"
#pragma GCC diagnostic ignored "-Wimplicit-int-float-conversion"
#pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
#pragma GCC diagnostic ignored "-Wunsafe-buffer-usage"
#else
#pragma GCC diagnostic error "-Wcast-qual"
#endif

#include GL_H

#define CAML_NAME_SPACE
#include <caml/fail.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/unixsupport.h>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
#pragma GCC diagnostic ignored "-Wundef"
#include <mupdf/fitz.h>
#include <mupdf/pdf.h>
#pragma GCC diagnostic pop
Expand Down Expand Up @@ -357,7 +359,7 @@ static int openxref (char *filename, char *mimetype, char *password,

static void docinfo (void)
{
struct { char *tag; char *name; } tab[] = {
const struct { const char *tag; const char *name; } tab[] = {
{ FZ_META_INFO_TITLE, "Title" },
{ FZ_META_INFO_AUTHOR, "Author" },
{ FZ_META_FORMAT, "Format" },
Expand All @@ -366,6 +368,8 @@ static void docinfo (void)
{ FZ_META_INFO_PRODUCER, "Producer" },
{ FZ_META_INFO_CREATIONDATE, "Creation date" },
{ FZ_META_INFO_MODIFICATIONDATE, "Modification date"},
{ FZ_META_INFO_SUBJECT, "Subject" },
{ FZ_META_INFO_KEYWORDS, "Keywords" },
};
int len = 0, need;
char *buf = NULL;
Expand Down Expand Up @@ -593,7 +597,12 @@ static void initpdims1 (void)
pdf_obj *obj = pdf_dict_getp (ctx, pdf_trailer (ctx, pdf),
"Root/Pages/MediaBox");
rootmediabox = pdf_to_rect (ctx, obj);
pdf_load_page_tree (ctx, pdf);
fz_try (ctx) {
pdf_load_page_tree (ctx, pdf);
}
fz_catch (ctx) {
printd ("emsg pdf_load_page_tree: %s", fz_caught_message (ctx));
}
}

for (pageno = 0; pageno < cxcount; ++pageno) {
Expand All @@ -605,19 +614,7 @@ static void initpdims1 (void)
pdf_obj *pageobj = NULL;

fz_var (pageobj);
if (pdf->rev_page_map) {
for (int i = 0; i < pdf->map_page_count; ++i) {
if (pdf->rev_page_map[i].page == pageno) {
pageobj = pdf_get_xref_entry (
ctx, pdf, pdf->rev_page_map[i].object
)->obj;
break;
}
}
}
if (!pageobj) {
pageobj = pdf_lookup_page_obj (ctx, pdf, pageno);
}
pageobj = pdf_lookup_page_obj (ctx, pdf, pageno);

rotate = pdf_to_int (ctx, pdf_dict_gets (ctx, pageobj, "Rotate"));

Expand Down Expand Up @@ -952,20 +949,17 @@ static struct pagedim *pdimofpageno (int pageno)

static void recurse_outline (fz_outline *outline, int level)
{
/* Significantly simplified by Sebastian Rasmussen */
while (outline) {
int pageno;
fz_point p;
fz_location loc;
int pageno;
fz_point p = { .x = outline->x, .y = outline->y };

loc = fz_resolve_link (state.ctx, state.doc, String_val (outline->uri),
loc = fz_resolve_link (state.ctx, state.doc, outline->uri,
&p.x, &p.y);
pageno = fz_page_number_from_location (state.ctx, state.doc, loc);
if (pageno >= 0) {
struct pagedim *pdim =
pdimofpageno (
fz_page_number_from_location (state.ctx, state.doc,
outline->page)
);
struct pagedim *pdim = pdimofpageno (pageno);
int h = fz_maxi (fz_absi (pdim->bounds.y1 - pdim->bounds.y0), 0);
p = fz_transform_point (p, pdim->ctm);
printd ("o %d %d %d %d %s",
Expand Down Expand Up @@ -1497,18 +1491,15 @@ static void *mainloop (void UNUSED_ATTR *unused)
break;
}
case Creqlayout: {
char *nameddest;
int rotate, off, h;
int fitmodel;
pdf_document *pdf;

printd ("clear");
ret = sscanf (p, "%d %d %d %n", &rotate, &fitmodel, &h, &off);
if (ret != 3) {
errx (1, "bad reqlayout line `%.*s' ret=%d", len, p, ret);
}
lock ("reqlayout");
pdf = pdf_specifics (state.ctx, state.doc);
if (state.rotate != rotate || state.fitmodel != fitmodel) {
state.gen += 1;
}
Expand All @@ -1518,8 +1509,12 @@ static void *mainloop (void UNUSED_ATTR *unused)
layout ();
process_outline ();

nameddest = p + off;
if (pdf && nameddest && *nameddest) {
#ifdef TODO_LINK_URI
char *nameddest = p + off;
if (nameddest && *nameddest) {
fz_link_dest ld;
const char *uri = "#%s" % nameddest;
sd = fz_resolve_link_dest (state.ctx, doc, uri);
fz_point xy;
struct pagedim *pdim;
fz_location loc = fz_resolve_link (state.ctx, (fz_document*)pdf, nameddest,
Expand All @@ -1529,6 +1524,7 @@ static void *mainloop (void UNUSED_ATTR *unused)
xy = fz_transform_point (xy, pdim->ctm);
printd ("a %d %d %d", loc.page, (int) xy.x, (int) xy.y);
}
#endif

state.gen++;
unlock ("reqlayout");
Expand Down Expand Up @@ -2559,9 +2555,9 @@ ML (getfileannot (value ptr_v, value n_v))
pdf_obj *fs = pdf_dict_get (state.ctx,
pdf_annot_obj (state.ctx, slink->u.annot),
PDF_NAME (FS));
pdf_embedded_file_params file_params;
pdf_get_embedded_file_params (state.ctx, fs, &file_params);
ret_v = caml_copy_string (file_params.filename);
pdf_embedded_file_params params;
pdf_get_embedded_file_params (state.ctx, fs, &params);
ret_v = caml_copy_string (params.filename);

unlock (__func__);
CAMLreturn (ret_v);
Expand All @@ -2575,6 +2571,7 @@ ML0 (savefileannot (value ptr_v, value n_v, value path_v))

lock (__func__);
struct slink *slink = &page->slinks[Int_val (n_v)];

fz_try (state.ctx) {
pdf_obj *fs = pdf_dict_get (state.ctx,
pdf_annot_obj (state.ctx, slink->u.annot),
Expand All @@ -2588,6 +2585,7 @@ ML0 (savefileannot (value ptr_v, value n_v, value path_v))
printd ("emsg saving '%s': %s", path, fz_caught_message (state.ctx));
}
unlock (__func__);
CAMLreturn0;
}

ML (getlinkrect (value ptr_v, value n_v))
Expand Down
2 changes: 1 addition & 1 deletion misc/getmupdf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ MUPDF_OUTPUT_DIR="$1"
u="git://git.ghostscript.com/mupdf"
#u="https://github.com/ArtifexSoftware/mupdf"
MUPDF_URL="${2-$u}"
MUPDF_DESIRED_VERSION="f6ddaf30da1defe3be961f1172b83554bc6f6b48"
MUPDF_DESIRED_VERSION="fac9da1c7cd03776df1011e1e4cb168c33e7a194"

if [ ! -d ${MUPDF_OUTPUT_DIR} ]; then
echo "mupdf does not exist, fetching it from ${MUPDF_URL}"
Expand Down
8 changes: 5 additions & 3 deletions misc/llppac
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ case $type in
fi
;;
image)
missing convert "convert(http://www.imagemagick.org/script/convert.php)"
conv='convert - pdf:"$casp"'
missing ffmpeg "ffmpeg(https://www.ffmpeg.org"
unset dc
caspsuf=".jpg"
conv='ffmpeg -loglevel fatal -i - "$casp"'
;;
dvi)
test -n "$dc" && die "cannot convert compressed '$mime'"
Expand All @@ -168,4 +170,4 @@ casp=$cachedir/${hash%% *}$caspsuf
{ test -n "${force-}" || test ! -e "$casp"; } && eval "$filt" "$conv"
shift

exec llpp -origin $origin "$@" "$casp"
exec llpp -origin "$origin" "$@" "$casp"
12 changes: 12 additions & 0 deletions todo.org
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,15 @@
* TODO llpp -last and llpp select first entry in history behave differently
586cb865549a22765a91ee0983e02a56429b1577
* TODO llpp recode and comment "tile" handling
* TODO changing interpagespace in setup breaks navigation
- State "TODO" from [2023-02-17 Fri 05:39]
* TODO scaled page indicator lines are drawn on top of scrollbar
* TODO don't forget to credit sebras for outline location simplification
- State "TODO" from [2023-02-22 Wed 02:54]
* TODO fix interpagespace setting (was setting it to negated value)
- State "TODO" from [2023-02-22 Wed 03:55]
* TODO zoom in on something quit llpp, reopen... whoops
- State "TODO" from [2023-02-22 Wed 03:59]
* TODO zoom in in ecma376.pdf it will enter endless eviction loop
- State "TODO" from [2023-02-22 Wed 04:00]
* TODO x location is not restored when entering from history (-last works!)

0 comments on commit e8f7830

Please sign in to comment.