View Single Post
Old 12-20-2023, 08:57 PM   #11
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: 185
Karma: 146236
Join Date: Oct 2022
Device: Kobo Clara HD
FBPAD2 - WITH USER-CONFIGURABLE FONT AND PERCENTAGE OF DISPLAY

***

FBPAD2 - WITH USER-CONFIGURABLE FONT AND PERCENTAGE OF DISPLAY

One fbpad to do the job of four.
fbpad -> fbpad2
fbpadS -> fbpad2 -f RobotoMono-MediumS.tf
fbpadkb -> fbpad2 -p 58
fbpadkbS -> fbpad2 -f RobotoMono-MediumS.tf -p 58


* fbpad2 is just a working title - I guess the actual name should be fbpad-eink-rev2 or something.

***

From FBInk build of Post #4 above:

$ unzip fbpads-master.zip

$ cd fbpads-master/

$ cd fbpad_mkfn/

$ make

Grab some fonts e.g.:
RobotoMono-Medium.ttf
GWMonospace.ttf


Generate small fonts for fbpadkbS:

$ nano -l gen.sh
CODE]
5 # OP="-h34 -w19"
6 # SZ="18h135v135"
7 OP="-h26 -w14"
8 SZ="18h100v100"
9 ./mkfn_ft $OP $FP/RobotoMono-Medium.ttf:$SZ >RobotoMono-MediumS.tf
10 ./mkfn_ft $OP $FP/GWMonospace.ttf:$SZ >GWMonospaceS.tf
[/CODE]

$ ./gen.sh
tinyfont[ 875]: height=26 width=14
tinyfont[ 2858]: height=26 width=14


Generate large fonts for fbpadkb:

$ nano -l gen.sh
CODE]
5 OP="-h34 -w19"
6 SZ="18h135v135"
7 # OP="-h26 -w14"
8 # SZ="18h100v100"
9 ./mkfn_ft $OP $FP/RobotoMono-Medium.ttf:$SZ >RobotoMono-Medium.tf
10 ./mkfn_ft $OP $FP/GWMonospace.ttf:$SZ >GWMonospace.tf
[/CODE]

$ ./gen.sh
tinyfont[ 875]: height=34 width=19
tinyfont[ 2858]: height=34 width=19


$ ls -l *.tf
-rw-r--r-- 136976 courr.tf
-rw-r--r-- 322024 RobotoMono-MediumS.tf
-rw-r--r-- 568774 RobotoMono-Medium.tf
-rw-r--r-- 1051768 GWMonospaceS.tf
-rw-r--r-- 1857724 GWMonospace.tf

$ cd ..

$ cd ..



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

$ cd FBInk-v1.25.0/

$ source ~/koxtoolchain/refs/x-compile.sh kobo env bare

$ make static

$ cd ..



$ unzip fbpad-eink-master.zip

$ cd fbpad-eink-master/

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

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

$ cp ../fbpads-master/fbpad_mkfn/*.tf fonts/


***



$ nano -l Makefile
Code:
  3 CC := arm-kobo-linux-gnueabihf-gcc
  4 all: fbpad2 
...
  6 %.o: %.c conf.h
...
 10         xxd -i fonts/RobotoMono-Medium.tf > font.h
 11 fbpad2: fbpad.o term.o pad.o draw.o font.o isdw.o scrsnap.o FBInk/Release/libfbink.a
...
15         rm -f *.o fbpad2

$ rm font.h

$ make font.h
xxd -i fonts/RobotoMono-MediumS.tf > font.h


$ nano -l conf.h
Code:
17 typedef int fbval_t;
...
20 #define FR "ar.tf"
21 #define FI "ai.tf"
22 #define FB "ab.tf"
$ nano -l font.c
Code:
 37 struct font *embeddefont(){
 38         struct font *font;
 39         struct tinyfont head;
 40     memcpy(&head, fonts_RobotoMono_Medium_tf, sizeof(head));
 41         font = malloc(sizeof(*font));
 42         font->n = head.n;
 43         font->rows = head.rows;
 44         font->cols = head.cols;
 45         font->rows = head.rows;
 46         font->glyphs = (int*)(fonts_RobotoMono_Medium_tf + sizeof(head));
 47         font->data =(char*) (fonts_RobotoMono_Medium_tf + sizeof(head) + font->n * sizeof(int));
 48     printf("n %d\n", font->n);
 49     printf("cols %d\n", font->cols);
 50     printf("rows %d\n", font->rows);
 51         return font;
 52 }
$ nano -l fbpad.h
Code:
 57 int pad_init(char *tinyfont, int percentDisplay);
 ...
 67 struct font *embeddefont(void);
$ nano -l fbpad.c
Code:
335 int main(int argc, char *argv[])
336 {
337         char *hide = "\x1b[2J\x1b[H\x1b[?25l";
338         char *show = "\x1b[?25h";
339         char **args = argv + 1;
340         char *tinyfont = NULL;
341         int percentDisplay = 100;
342         if (fb_init(FBDEV)) {
...
351         int i;
352         int j = 0;
353         for (i = 1; i < argc; i++) {
354                 if (argv[i][0] == '-' && argv[i][1] == 'f') {
355                         tinyfont = argv[++i];
356                         j++;
357                 } else if (argv[i][0] == '-' && argv[i][1] == 'p') {
358                         percentDisplay = atoi(argv[++i]);
359                         if (percentDisplay < 1)
360                                 percentDisplay = 1;
361                         if (percentDisplay > 99)
362                                 percentDisplay = 100;
363                         j++;
364                 } else if (argv[i][0] == '-' && argv[i][1] == 'h') {
365                         printf("usage: %s [options] [command]\npossible options are:\n -h: print this help\n -f: set path to tinyfont\n -p: set percent display\n",argv[0]);
366                         return 1;
367                 }
368         }
369         args = args + 2 * j;
370
371         if (pad_init(tinyfont, percentDisplay)) {
372                 fprintf(stderr, "fbpad: cannot find fonts\n");
373                 return 1;
374         }
$ nano -l pad.c
Code:
 21 int pad_init(char* tinyfont)
 22 {
 23         if (pad_font(tinyfont, FI, FB))
 24                 return 1;
 25         rows = fb_rows() * percentDisplay / 100 / fnrows;
...
219 int pad_font(char *fr, char *fi, char *fb)
220 {
221         struct font *r = font_open(fr);
222         if (!r) {
223                 r = font_open("ar.tf");
224                 if (!r) {
225                         r = embeddefont();
226                         if (!r) 
227                                 return 1;
228                 }
229         }
230         fonts[0] = r;
231         fonts[1] = NULL;
232         fonts[2] = NULL;
233         memset(gc_info, 0, sizeof(gc_info));
234         fnrows = font_rows(fonts[0]);
235         fncols = font_cols(fonts[0]);
236         return 0;
237 }

$ make

$ ls -l fbpad2
-rwxr-xr-x 604248 fbpad2

Copy fbpad2 to /mnt/onboard/.adds/koreader/scripts/ folder on your Kobo.

Copy the tinyfonts you generated to the /mnt/onboard/.adds/koreader/ folder on your Kobo:
courr.tf
GWMonospaceS.tf
GWMonospace.tf
RobotoMono-MediumS.tf
RobotoMono-Medium.tf

On the kobo, rename whichever tinyfont you want to be the regular font to "ar.tf", e.g.:
# cp RobotoMono-MediumS.tf ar.tf

From SSH shell run (after first running ". /korenv.sh" as was done in Post #4):
# fbpad2 -p 58 /bin/sh
n 875
cols 14
rows 26
1072x1448 pixels, so 76x32 characters

Input commands from your SSH shell.


Now kill fbpad2 (e.g. with fbmenu.sh entry) and retry fbpad2 in the built-in font:

For fbpad2 to use the built-in font, there must be no ar.tf, so delete it:

# rm ar.tf

# fbpad2 -p 58 /bin/sh
n 875
cols 19
rows 34
1072x1448 pixels, so 56x24 characters

Run a command e.g. "ps" and you see the built-in larger RobotoMono-Medium.tf font.


Now kill fbpad2 and retry fbpad2 in a font you specify as a command line parameter:

# fbpad2 -f courr.tf -p 58 /bin/sh
n 323
cols 15
rows 28
1072x1448 pixels, so 71x29 characters

***

You can also crosscompile the mkfn_ft binary to convert ttf fonts to tf right on your Kobo:

Grab some fonts e.g.:
DejaVuSansMono.ttf

$ cd ttf-build

$ cd fbpads-master/

$ cd fbpad_mkfn/

$ source ~/koxtoolchain/refs/x-compile.sh kobo env bare

Freetype
https://freetype.org/download.html

Download from:
https://sourceforge.net/projects/fre...etype2/2.13.1/

$ tar zxvf freetype-2.13.1.tar.gz

$ cd freetype-2.13.1/

$ ./configure --host=arm-kobo-linux-gnueabihf

$ make

$ cd ..

$ nano -l Makefile
Code:
  2 CC = arm-kobo-linux-gnueabihf-gcc
...
  4 CFLAGS = -O2 -Wall  -I./freetype-2.13.1/include/
...
 11         $(CC) -c $(CFLAGS) mkfn_ft.c
12         $(CC) -o $@ mkfn_ft.o mkfn.o isdw.o $(LDFLAGS) ./freetype-2.13.1/objs/.libs/libfreetype.a
$ make clean

$ make

$ file mkfn_ft
mkfn_ft: 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

Generate large fonts for fbpadkb:

$ nano -l gen.sh
CODE]
5 OP="-h34 -w19"
6 SZ="18h135v135"
7 # OP="-h26 -w14"
8 # SZ="18h100v100"
9 ./mkfn_ft $OP $FP/DejaVuSansMono.ttf:$SZ >DejaVuSansMono.tf
10
[/CODE]

Now copy the mkfn_ft binary, the gen.sh script, and the DejaVuSansMono.ttf font to the /mnt/onboard/.adds/koreader/ folder of your Kobo.

Now on your Kobo, cd to the /mnt/onboard/.adds/koreader/ folder and run the gen.sh script.

# ./gen.sh
tinyfont[ 3258]: height=34 width=19

# ls -l *.tf
-rw-r--r-- 2117724 DejaVuSansMono.tf


Add characters like ¡€£°♜幸☺♫√ꭍ to one of your oskansi keyboard layouts.
(They may appear as empty squares on the keyboard if the default oskansi font of Roboto-Medium.ttf does not include their code.)

Run fbpad2 using the same font in tinyfont format:
# fbpad2 -f DejaVuSansMono.tf -p 58 /bin/sh

Now if you run oskansi, the shell still shows Unicode characters as question marks, but if you enter characters into an app like nano, at least some characters are displayed:

# . /korenv.sh

# nano /mnt/onboard/shared/u.txt
Code:
¡€£°♜幸☺♫√ꭍ
(All these characters are correctly displayed except for the 幸 and the ꭍ.)
And if you open u.txt on a desktop environment with a font that supports more Unicode characters, you will see they were faithfully transmitted.

Moreover, running gnuchess in graphic mode shows the symbols.

# gnuchess -e -g
White (1) : e2e4
1. e2e4

black KQkq e3
♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜
♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟




♙ ♙ ♙ ♙ ♙ ♙ ♙
♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖

Thinking...

white KQkq
♜ ♞ ♝ ♛ ♚ ♝ ♜
♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟




♙ ♙ ♙ ♙ ♙ ♙ ♙
♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖


My move is : Nf6
White (2) : quit

Not necessarily more legible, but at least it's Unicode, right?

***

*UPDATE - START PERCENT DISPLAY COMMANDLINE OPTION:

Enable putting fbpad2 at bottom since now you can put fbkeyboard2 at top (see following post):

$ nano -l fbpad.h
Code:
...
 57 int pad_init(char *tinyfont, int percentDisplay, int starttDisplay);
 ...
$ nano -l fbpad.c
Code:
...
350         int percentDisplay = 100;
351         int starttDisplay = 0;
352         if (fb_init(FBDEV)) {
...
374                         startDisplay = atoi(argv[++i]);
375                         if (startDisplay < 0)
376                                 startDisplay = 0;
377                         if (startDisplay > 99)
378                                 startDisplay = 99;
379                         j++;
380                 } else if (argv[i][0] == '-' && argv[i][1] == 'h') {
381                         printf("usage: %s [options] [command]\npossible options are:\n -h: print this help\n -f: set path to tinyfont\n -p: set percent display\n -s: set start percent display\n",argv[0]);
382                         return 1;
383                 }
...
387         if (pad_init(tinyfont, percentDisplay, startDisplay)) {
...
$ nano -l pad.c
Code:
...
 15 static int startRow;
...
 21 int pad_init(char* tinyfont, int percentDisplay, int startDisplay)
 22 {
 23         if (pad_font(tinyfont, FI, FB))
 24                 return 1;
 25         startRow = fb_rows() * startDisplay / 100 / fnrows;
 26         rows = fb_rows() * percentDisplay / 100 / fnrows;
 27         if (rows > (fb_rows() / fnrows - startRow))
 28                 rows = (fb_rows() / fnrows - startRow);
 29         cols = fb_cols() / fncols;
 30         printf("%dx%d pixels, so %dx%d characters\n", fb_cols(), fb_rows(), cols, rows );
 31         return 0;
 32 }
...
149 void pad_put(int ch, int r, int c, int fg, int bg)
150 {
151         r = r + startRow;
...
179 void pad_fill(int sr, int er, int sc, int ec, int c)
180 {
181         sr = sr + startRow;
182         er = er + startRow;
183         int fber = er >= 0 ? er * fnrows : (startRow + rows) * fnrows;
184         int fbec = ec >= 0 ? ec * fncols : fb_cols();
...

$ make

Now on kobo try fbpad2 at bottom with fbkeyboard2 at top (see following post):

# . /korenv.sh

# fbpad2 -p 63 -s 37 /bin/sh 0</dev/tty1 &

# fbkeyboard2 -c 99 -g

Keyboard is at the top, terminal output at the bottom!




***


TRY THE TAGS TERMINAL SWITCHING AND SCROLLING FEATURE OF FBPAD:

There is a cool tags system in fbpad you can access if you run "fbpad2" by itself, i.e. without the "/bin/sh" parameter.

Then you need to enter ALT-c from keyboard to start a shell, list tags with ALT-p, and switch terminals with ALT-x, where x can be one of the terminals listed in conf.h, i.e. "xnlhtr01uiva-".


Run fbpad2 from an SSH session.

# fbpad2 -p 63 -s 37 0</dev/tty1 &

# fbkeyboard2 -c 99 -g

Enter ALT-c and you get the shell prompt on the Kobo display.

Enter ALT-p and you get the tags list at the bottom of the screen, e.g.:
TAGS: (x) n l h t r 0 1 u i v a -

Enter ALT-n then ALT-p, the tags list shows you have switched to terminal (n):
TAGS: x (n) l h t r 0 1 u i v a -

Enter ALT-c and enter a command e.g. "ls"<RET>

Enter ALT-x then ALT-p, the tags list shows you have switched back to terminal (x):
TAGS: (x) n l h t r 0 1 u i v a -

Enter a command e.g. "lsof"<RET>

Enter a command e.g. "ps"<RET>

Enter ALT-, and you scroll up.

Enter ALT-. and you scroll down.

CTRL-ALT-q to end the fbpad session.

CTRL-ALT-x to end the fbkeyboard session.



Now try fbpad2 with the shell command as a command line argument.

# fbpad2 -p 63 -s 37 /bin/sh 0</dev/tty1 &

# fbkeyboard2 -c 99 -g

Now the terminal appears without needing to enter ALT-c.
However the tag commands no longer work and you cannnot use CTRL-ALT-q to end the fbpad session.
(However you can still use "pkill fbpad" then CTRL-ALT-x to end the fbkeyboard session.)


Binaries fbpad2-shared and fbkeyboard2-shared from Post #12 should work the same way




***


Note: Segmentation error message on exit due to introduction of embeddefont() in fbpad-eink corrected here:

$ nano -l font.c
Code:
...
 45 //      font->rows = head.rows;
...
106 void font_free(struct font *font)
107 {
108         struct tinyfont head;
109         if (font->glyphs != (int*)(fonts_RobotoMono_Medium_tf + sizeof(head))) {
110                 if (font->data)
111                         free(font->data);
112                 if (font->glyphs)
113                         free(font->glyphs);
114         }
115         free(font);
116 }
...
***

MAKE SHARED VERSION OF FBPAD2:

$ cd ..

$ cd fbpad-eink-master/

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

$ nano -l Makefile
Code:
...
  2 LDFLAGS += -lutil -lm -LFBInk/Release/ -lfbink
  3 CC := arm-kobo-linux-gnueabihf-gcc
  4 all: fbpad2-shared
...
 11 fbpad2-shared: fbpad.o term.o pad.o draw.o font.o isdw.o scrsnap.o 
...
 15         rm -f *.o fbpad2-shared
$ make

***
$ zip -r fbpad2.zip fbpad2/

***
Attached Files
File Type: zip mkfn-kobo.zip (888.6 KB, 69 views)
File Type: zip fbpad2.zip (232.3 KB, 58 views)

Last edited by elinkser; 01-26-2024 at 06:11 PM. Reason: korenv.sh,mkfn-kobo,startDisplay,shared,tags,seg on exit
elinkser is offline   Reply With Quote