View Single Post
Old 03-26-2024, 09:20 PM   #16
elinkser
Groupie
elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.elinkser has survived committing the World's Second Greatest Blunder.
 
Posts: 186
Karma: 146236
Join Date: Oct 2022
Device: Kobo Clara HD
FBPDF - A PDF/EPUB VIEWER FOR ELINKS

***


FBPDF - A PDF/EPUB VIEWER FOR ELINKS


Fbpdf is a mupdf-based pdf viewer from the same author as fbpad.


$ source ~/koxtoolchain/refs/x-compile.sh kobo env bare
(Prepare build system as was done in Post #4 above.)

mupdf
$ wget https://mupdf.com/downloads/archive/...-source.tar.gz

$ tar zxvf mupdf-1.24.0-source.tar.gz

$ cd mupdf-1.24.0-source/

$ make shared-clean

$ make CC=arm-kobo-linux-gnueabihf-gcc CXX=arm-kobo-linux-gnueabihf-g++ OBJCOPY=arm-kobo-linux-gnueabihf-objcopy LINK=arm-kobo-linux-gnueabihf-gcc LD=arm-kobo-linux-gnueabihf-ld AR=arm-kobo-linux-gnueabihf-ar RANLIB=arm-kobo-linux-gnueabihf-ranlib XCFLAGS=" -fPIC -DTOFU_CJK -DTOFU_NOTO " HAVE_X11=no HAVE_GLUT=no shared-release

$ ls -l build/shared-release/libmupdf.so.24.0
-rwxr-xr-x 1 6514576 build/shared-release/libmupdf.so.24.0

$ file build/shared-release/mutool
build/shared-release/mutool: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.33, stripped


$ cd ..



*The next section was already done in Post #4 above:

************************************************** **

NiLuJe/FBInk

https://github.com/NiLuJe/FBInk/releases

$ wget https://github.com/NiLuJe/FBInk/rele...v1.25.0.tar.xz

$ tar xJf FBInk-v1.25.0.tar.xz

$ cd FBInk-v1.25.0/

$ make static stripped

$ cd ..



ddvk / fbpad-eink
forked from kisonecat/fbpad-eink
https://github.com/ddvk/fbpad-eink

$ wget https://github.com/ddvk/fbpad-eink/a...ads/master.zip

$ unzip fbpad-eink-master.zip

$ cd ..


************************************************** **





aligrudi/fbpdf
https://github.com/aligrudi/fbpdf

$ wget https://github.com/aligrudi/fbpdf/ar...ads/master.zip

$ mv master.zip fbpdf-master.zip

$ unzip fbpdf-master.zip

$ cd fbpdf-master/

$ cp -r ../mupdf-1.24.0-source/include .

$ mkdir lib

$ cp -r ../mupdf-1.24.0-source/build/shared-release/libmupdf* lib/


$ mkdir FBInk

$ cp -r ../FBInk-v1.25.0/Release FBInk/

$ cp ../FBInk-v1.25.0/fbink.h FBInk/

$ cp ../fbpad-eink-master/draw.c .

$ cp ../fbpad-eink-master/draw.h .


$ nano -l draw.h
Code:
...
 19 void  fbpdf_refresh(int fd, int invalid_top, int invalid_left, int invalid_right, int invalid_bottom);
$ nano -l draw.c
Code:
...
160
161 void fbpdf_refresh(int fd, int invalid_top, int invalid_left, int invalid_right, int invalid_bottom) {
162   fbink_refresh( fb_fd(),
163                  invalid_top,
164                  invalid_left,
165                  invalid_right - invalid_left,
166                  invalid_bottom - invalid_top,
167                  cfg() );
168 }


*** UPDATE ***
Modified space,b,r,s, and R defs.
**************

$ nano -l fbpdf.c
Code:
...
 27 #define FBDEV           "/dev/fb0"
...
 43 static int percentDisplay;      /* percent of display used */
 44 static int startDisplay;        /* start percent of display used */
 45 static int firstRow;            /* first row of display used */
 46 static int numRows;             /* number of rows of display used */
...
 74                 memcpy(fb_mem(i - srow + firstRow), rbuf, scols * bpp);
 75         }
 76         free(rbuf);
 77         fbpdf_refresh(fb_fd(), firstRow, 0, scols, firstRow + srows);
 78 }
...
255                 switch (c) {    /* commands that require redrawing */
256                 case ' ':
257                                                 if (srow < -(int)(srows / 11)) {
258                                                         srow += (int)(9 * srows / 10);
259                                                 } else {
260                                                         if (!loadpage(num + getcount(1)))
261                                                                 srow = prow;
262                                                 }
263                                                 break;
264                 case 'b':
265                                                 srow -= (int)(srows / 2);
266                                                 if (srow < -prows / 2) {
267                                                         srow = -prows / 2;
268                                                         if (!loadpage(num - getcount(1)))
269                                                                 srow = -(int)(srows / 2);
270                                                 }
271                                                 break;
272                 case CTRLKEY('b'):
273                 case CTRLKEY('f'):
274                 case 'J':
275                         if (!loadpage(num + getcount(1)))
276                                 srow = prow;
277                         break;
278                 case 'K':
279                         if (!loadpage(num - getcount(1)))
280                                 srow = prow;
281                         break;
282                 case 'r':
283                                 setmark('\'');
284                                 if (!loadpage(num - count))
285                                         srow = prow;
286                                 break;
287                 case 's':
288                                 setmark('\'');
289                                 if (!loadpage(num + count))
290                                         srow = prow;
291                                 break;
292                 case 'g':
293                 case 'G':
...
319                 case 'R':
320                         rotate = getcount(0);
321                         if (!loadpage(num))
322                                 srow = prow;
323                         break;
...
352 /*              case ' ': */
...
418         if (fb_init(FBDEV))
419                 return 1;
420         srows = fb_rows();
421         scols = fb_cols();
422
423         if (getenv("FBPDF_START") != NULL) {
424                 printf("FBPDF_START = %s\n", getenv("FBPDF_START"));
425                 startDisplay = atoi(getenv("FBPDF_START"));
426                 if (startDisplay < 1 || startDisplay > 99) {
427                         startDisplay = 0;
428                 }
429         } else {
430                 startDisplay = 0;
431         }
432         firstRow = srows * startDisplay / 100;
433         
434         if (getenv("FBPDF_PERCENT") != NULL) {
435                 printf("FBPDF_PERCENT = %s\n", getenv("FBPDF_PERCENT"));
436                 percentDisplay = atoi(getenv("FBPDF_PERCENT"));
437                 if (percentDisplay < 1 || percentDisplay > 99) {
438                         percentDisplay = 100;
439                 }
440         } else {
441                 percentDisplay = 100;
442         }
443         if ((startDisplay + percentDisplay) > 100) {
444                 percentDisplay = 100 - startDisplay;
445         }
446         numRows = srows * percentDisplay / 100;
447
448         if ((firstRow + numRows) > srows) {
449                 numRows = numRows - 1;
450         }
451         srows = numRows;
...

$ nano -l Makefile
Code:
...
  2 CC = arm-kobo-linux-gnueabihf-gcc
...
 14         $(CC) -o $@ $^ $(LDFLAGS) -lmupdf -lmupdf-pkcs7 -lmupdf-threads -lm FBInk/Release/libfbink.a
...

$ make fbpdf

$ file fbpdf
fbpdf: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.33, with debug_info, not stripped

$ ls -l fbpdf
-rwxr-xr-x 1 23832 fbpdf

$ cd ..

$ cp fbpdf-master/lib/libmupdf.so.24.0 .

$ ls -l libmupdf.so.24.0
-rwxr-xr-x 1 6514576 libmupdf.so.24.0

I compressed the libmupdf.so.24.0 file:
$ xz -z libmupdf.so.24.0

$ ls -l libmupdf.so.24.0.xz
-rwxr-xr-x 1 3353772 libmupdf.so.24.0.xz

I split up the libmupdf.so.24.0.xz file, so that it meets mobileread.com 1MB upload limit:
* UPDATE - I guess upload limits were increased, or did I imagine the whole thing? Hmmm...
Anyway, just unzip the one file now

$ split -d -b 1000000 libmupdf.so.24.0.xz mx

$ ls -l mx*
-rw-r--r-- 1 1000000 mx00
-rw-r--r-- 1 1000000 mx01
-rw-r--r-- 1 1000000 mx02
-rw-r--r-- 1 353772 mx03

I added .zip extension to the split files to meet mobileread.com naming convention - didn't actually zip them) :

$ mv mx00 mx00.zip
$ mv mx01 mx01.zip
$ mv mx02 mx02.zip
$ mv mx03 mx03.zip

$ ls -l mx*
-rw-r--r-- 1 1000000 mx00.zip
-rw-r--r-- 1 1000000 mx01.zip
-rw-r--r-- 1 1000000 mx02.zip
-rw-r--r-- 1 353772 mx03.zip


Now to recreate the original libmupdf.so.24.0 file, you just have to reverse the process.
Copy the mx*.zip files to the Kobo's /mnt/onboard/.adds/kordir/libs/ folder.

On your kobo, reassemble the libmupdf.so.24.0.xz compressed file:

# cd /mnt/onboard/.adds/kordir/libs/

# cat mx*.zip > libmupdf.so.24.0.xz

# xz -d libmupdf.so.24.0.xz

# ls -l libmupdf.so.24.0
-rwxr-xr-x 1 6514576 libmupdf.so.24.0

With libmupdf.so.24.0 installed in /mnt/onboard/.adds/kordir/libs/ folder:

Copy the fbpdf binary to the Kobo's /mnt/onboard/.adds/kordir/scripts/ folder.

Copy sample files fbpdf.pdf and sfm.epub, and self.png to the /mnt/onboard/.adds/kordir/ folder.

# . /korenv.sh

# FBPDF_PERCENT=58 fbpdf -z 20 fbpdf.pdf

# FBPDF_START=29 FBPDF_PERCENT=29 fbpdf -z 20 sfm.epub

# FBPDF_PERCENT=58 fbpdf -z 5 self.png

space to PageDown
b to PageUp
j,k to scroll each page
q to quit


Now you can set up fbpdf as the pdf handler for elinks:

Edit /mnt/onboard/.adds/kordir/.elinks/elinks.conf
Code:
...
set mime.extension.pdf="application/pdf"

set mime.handler.pdf_viewer.unix.ask = 1
set mime.handler.pdf_viewer.unix-xwin.ask = 0

set mime.handler.pdf_viewer.unix.block = 1
set mime.handler.pdf_viewer.unix-xwin.block = 0

set mime.handler.pdf_viewer.unix.program = "/mnt/onboard/.adds/kordir/scripts/fbpdf %"
set mime.handler.pdf_viewer.unix-xwin.program = "/mnt/onboard/.adds/kordir/scripts/fbpdf %"

set mime.type.application.pdf = "pdf_viewer"
...
So if you run elinks like this:
# FBPDF_PERCENT=58 elinks
(Hit . <RET> to browse the current folder)

Navigate to a pdf file and it will open with fbpdf.
e.g. 25z to zoom 2.5x
h,l to scroll left,right

Similarly edit /mnt/onboard/.adds/kordir/.elinks/elinks.conf to set fbpdf as an epub handler:
Code:
...
set mime.extension.epub="application/epub"

set mime.handler.epub_viewer.unix.ask = 1
set mime.handler.epub_viewer.unix-xwin.ask = 0

set mime.handler.epub_viewer.unix.block = 1
set mime.handler.epub_viewer.unix-xwin.block = 0

set mime.handler.epub_viewer.unix.program = "/mnt/onboard/.adds/kordir/scripts/fbpdf %"
set mime.handler.epub_viewer.unix-xwin.program = "/mnt/onboard/.adds/kordir/scripts/fbpdf %"

set mime.type.application.epub = "epub_viewer"
...
What the heck - edit the image viewer to fbpdf too, it's all fbink under the hood anyway

Code:
# set mime.handler.image_viewer.unix.program = "/mnt/onboard/.adds/kordir/scripts/fbink -G -y 30 -g file=% ;sleep 2"
# set mime.handler.image_viewer.unix-xwin.program = "/mnt/onboard/.adds/kordir/scripts/fbink -G -y 30 -g file=% ;sleep 2"
set mime.handler.image_viewer.unix.program = "/mnt/onboard/.adds/kordir/scripts/fbpdf %"
set mime.handler.image_viewer.unix-xwin.program = "/mnt/onboard/.adds/kordir/scripts/fbpdf %"

*** UPDATE ***
Modified space,b,r,s, and R defs.
**************

space now scrolls down, then next page when reaches bottom
b now scrolls up, then previous page when reaches top
r for rotate has been reassigned to R
ESC followed by integer to reset 'count'. Then:
g to goto page 'count'
s to skim forward 'count' pages
r to skim backward 'count' pages
i to get info
q to quit

Included mutool and muraster utility binaries.

***


******* UPDATE2 *****
Width and css support.
***********************
UPDATE2a : support ignore doc css when user css provided

$ nano -l mupdf.c
Code:
...
  7 #define MIN_(a, b)      ((a) < (b) ? (a) : (b))
  8
  9 static float layout_w = FZ_DEFAULT_LAYOUT_W;
 10 static float layout_h = FZ_DEFAULT_LAYOUT_H;
 11 static float layout_em = FZ_DEFAULT_LAYOUT_EM;
 12 static char *layout_css = NULL;
 13 static int layout_use_doc_css = 1;
 14
 15 struct doc {
...
 64         }
 65         if (getenv("FBPDF_CSS") != NULL) {
 66                 printf("FBPDF_CSS = %s\n", getenv("FBPDF_CSS"));
 67                 layout_css = getenv("FBPDF_CSS");
 68                 if (getenv("FBPDF_DOCCSS") != NULL) {
 69                         printf("FBPDF_DOCCSS = %s\n", getenv("FBPDF_DOCCSS"));
 70                         layout_use_doc_css = fz_atoi(getenv("FBPDF_DOCCSS"));
 71                         if (layout_use_doc_css != 0)
 72                                 layout_use_doc_css = 1;
 73                 }
 74                 fz_buffer *buf = fz_read_file(doc->ctx, layout_css);
 75                 fz_set_user_css(doc->ctx, fz_string_from_buffer(doc->ctx, buf));
 76                 fz_drop_buffer(doc->ctx, buf);
 77                 fz_set_use_document_css(doc->ctx, layout_use_doc_css);
 78         }
 79         if (getenv("FBPDF_WIDTH") != NULL) {
 80                 printf("FBPDF_WIDTH = %s\n", getenv("FBPDF_WIDTH"));
 81                 layout_w = fz_atof(getenv("FBPDF_WIDTH"));
 82                 if (layout_w < 50 || layout_w > 5000) {
 83                         layout_w = FZ_DEFAULT_LAYOUT_W;
 84                 }
 85         } else {
 86                 layout_w = FZ_DEFAULT_LAYOUT_W;
 87         }
 88         fz_layout_document(doc->ctx, doc->pdf, layout_w, layout_h, layout_em);
 89         return doc;
 90 }
...

$ make fbpdf

Recopy the fbpdf binary to the Kobo's /mnt/onboard/.adds/kordir/scripts/ folder.

Copy Style.css and sfm.epub to the /mnt/onboard/.adds/kordir/ folder.

# . /korenv.sh

# fbpdf -z 25 sfm.epub

# FBPDF_WIDTH=420 fbpdf -z 25 sfm.epub

# FBPDF_WIDTH=210 fbpdf -z 50 sfm.epub

# fbpdf -z 25 sfm.epub

# FBPDF_CSS=Style.css fbpdf -z 25 sfm.epub

# FBPDF_CSS=Style.css FBPDF_DOCCSS=0 fbpdf -z 25 sfm.epub


* SECURITY NOTE RE XZ *
On desktop:
$ xz -V
xz (XZ Utils) 5.2.4
liblzma 5.2.4
On Kobo:
# xz -v
BusyBox v1.31.1.kobo (2020-04-22 11:41:43 EDT) multi-call binary.


***
Attached Files
File Type: zip fbpdf-build.zip (306.8 KB, 70 views)
File Type: zip libmupdf.zip (4.11 MB, 8 views)

Last edited by elinkser; 05-09-2024 at 07:48 AM. Reason: space,b,r,s+mutool+width/css+doccss+single zip file
elinkser is offline   Reply With Quote