Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keybinding to fbpdf to invert colors of document. Add man page. #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ O set page number and go to current page
z zoom; prefix multiplied by 10 (i.e. '15z' = 150%)
r set rotation in degrees
i print some information
I invert colors
q quit
^[/escape clear the numerical prefix
mx mark page as 'x' (or any other letter)
Expand Down
2 changes: 1 addition & 1 deletion djvulibre.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void djvu_render(ddjvu_page_t *page, int iw, int ih, void *bitmap)
ddjvu_format_release(fmt);
}

void *doc_draw(struct doc *doc, int p, int zoom, int rotate, int *rows, int *cols)
void *doc_draw(struct doc *doc, int p, int zoom, int rotate, int *rows, int *cols, int invert)
{
ddjvu_page_t *page;
ddjvu_pageinfo_t info;
Expand Down
2 changes: 1 addition & 1 deletion doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ typedef unsigned int fbval_t;

struct doc *doc_open(char *path);
int doc_pages(struct doc *doc);
void *doc_draw(struct doc *doc, int page, int zoom, int rotate, int *rows, int *cols);
void *doc_draw(struct doc *doc, int page, int zoom, int rotate, int *rows, int *cols, int invert);
void doc_close(struct doc *doc);
138 changes: 138 additions & 0 deletions fbpdf.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
.TH "fbpdf" 1 "2018\-01\-05" "" "General Commands Manual"
.SH NAME
.B fbpdf
\- view PDF files on the frame buffer
.SH SYNOPSIS
.PP
.B fbpdf
[\fB\-r\fR \fIrotation\fR]
[\fB\-z\fR \fIzoom_x10\fR]
[\fB\-p\fR \fIpage_number\fR]
.I file.pdf
.SH OPTIONS
.PP
\fB\-r\fR \fIrotation\fR Set rotation to \fIrotation\fR degrees.
.br
\fB\-z\fR \fIzoom_x10\fR Set zoom to ten times \fIzoom_x10\fR percent.
.br
\fB\-p\fR \fIpage_number\fR Open \fIfile.pdf\fR to page \fIpage_number\fR.
.SH DESCRIPTION
.PP
.B fbpdf
is a framebuffer PDF and djvu viewer. The following table lists the
key-bindings available in \fBfbpdf\fR. Most of them accept a numerical prefix;
for instance, \fB^F\fR tells \fBfbpdf\fR to show the next page while \fB5^F\fR
tells it to show the fifth next page.
.TS
aB aB
_ s
a a .
Key Action
^F/J next page
^B/K previous page
G go to page (the last page if no prefix)
o set page number (for 'G' command only)
O set page number and go to current page
z zoom; prefix multiplied by 10 (i.e. '15z' = 150%)
r set rotation in degrees
i print some information
I invert colors
q quit
^[/escape clear the numerical prefix
mx mark page as 'x' (or any other letter)
\&'x jump to the page marked as 'x'
\&`x jump to the page and position marked as 'x'
j scroll down
k scroll up
h scroll left
l scroll right
[ align with the left edge of the page
] align with the right edge of the page
{ align with the leftmost character on the page
} align with the rightmost character on the page
H show page top
M centre the page vertically
L show page bottom
C centre the page horizontally
^D/space page down
^U/^H/backspace page up
^L redraw
e reload current file
f zoom to fit page height
w zoom to fit page width
W zoom to fit page contents horizontally
Z set the default zoom level for 'z' command
d sleep one second before the next command
.TE
.SH "EXIT STATUS"
.PP
\fBfbpdf\fR returns 1 in case of error, 0 otherwise.
.TH "fbpdf" 1 "2018\-01\-05" "" "General Commands Manual"
.SH NAME
.B fbpdf
\- view PDF files on the frame buffer
.SH SYNOPSIS
.PP
.B fbpdf
[\fB\-r\fR \fIrotation\fR]
[\fB\-z\fR \fIzoom_x10\fR]
[\fB\-p\fR \fIpage_number\fR]
.I file.pdf
.SH OPTIONS
.PP
\fB\-r\fR \fIrotation\fR Set rotation to \fIrotation\fR degrees.
.br
\fB\-z\fR \fIzoom_x10\fR Set zoom to ten times \fIzoom_x10\fR percent.
.br
\fB\-p\fR \fIpage_number\fR Open \fIfile.pdf\fR to page \fIpage_number\fR.
.SH DESCRIPTION
.PP
.B fbpdf
is a framebuffer PDF and djvu viewer. The following table lists the
key-bindings available in \fBfbpdf\fR. Most of them accept a numerical prefix;
for instance, \fB^F\fR tells \fBfbpdf\fR to show the next page while \fB5^F\fR
tells it to show the fifth next page.
.TS
aB aB
_ s
a a .
Key Action
^F/J next page
^B/K previous page
G go to page (the last page if no prefix)
o set page number (for 'G' command only)
O set page number and go to current page
z zoom; prefix multiplied by 10 (i.e. '15z' = 150%)
r set rotation in degrees
i print some information
I invert colors
q quit
^[/escape clear the numerical prefix
mx mark page as 'x' (or any other letter)
\&'x jump to the page marked as 'x'
\&`x jump to the page and position marked as 'x'
j scroll down
k scroll up
h scroll left
l scroll right
[ align with the left edge of the page
] align with the right edge of the page
{ align with the leftmost character on the page
} align with the rightmost character on the page
H show page top
M centre the page vertically
L show page bottom
C centre the page horizontally
^D/space page down
^U/^H/backspace page up
^L redraw
e reload current file
f zoom to fit page height
w zoom to fit page width
W zoom to fit page contents horizontally
Z set the default zoom level for 'z' command
d sleep one second before the next command
.TE
.SH "EXIT STATUS"
.PP
\fBfbpdf\fR returns 1 in case of error, 0 otherwise.
7 changes: 6 additions & 1 deletion fbpdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static int zoom = 15;
static int zoom_def = 15; /* default zoom */
static int rotate;
static int count;
static int invert; /* invert colors? */

static void draw(void)
{
Expand All @@ -76,7 +77,7 @@ static int loadpage(int p)
return 1;
prows = 0;
free(pbuf);
pbuf = doc_draw(doc, p, zoom, rotate, &prows, &pcols);
pbuf = doc_draw(doc, p, zoom, rotate, &prows, &pcols, invert);
prow = -prows / 2;
pcol = -pcols / 2;
num = p;
Expand Down Expand Up @@ -330,6 +331,10 @@ static void mainloop(void)
break;
case CTRLKEY('l'):
break;
case 'I':
invert = !invert;
loadpage(num);
break;
default: /* no need to redraw */
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion mupdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct doc {
fz_document *pdf;
};

void *doc_draw(struct doc *doc, int p, int zoom, int rotate, int *rows, int *cols)
void *doc_draw(struct doc *doc, int p, int zoom, int rotate, int *rows, int *cols, int invert)
{
fz_matrix ctm;
fz_pixmap *pix;
Expand All @@ -26,6 +26,8 @@ void *doc_draw(struct doc *doc, int p, int zoom, int rotate, int *rows, int *col
fz_drop_pixmap(doc->ctx, pix);
return NULL;
}
if (invert)
fz_invert_pixmap(doc->ctx, pix);
for (y = 0; y < pix->h; y++) {
unsigned char *s = &pix->samples[y * pix->stride];
for (x = 0; x < pix->w; x++)
Expand Down