From: Ali Gholami Rudi Date: Fri, 22 Mar 2013 15:51:52 +0000 (+0430) Subject: fbpdf: align with the leftmost/rightmost character in the page X-Git-Url: https://repo.or.cz/w/fbpdf.git/commitdiff_plain/8b5212e91baf6c14f6d34cd373e509e74d7060e3 fbpdf: align with the leftmost/rightmost character in the page [ and ] commands align the screen with the leftmost and rightmost characters on the page. Very convenient especially for multi-column pages. --- diff --git a/README b/README index 53cb050..66de094 100644 --- a/README +++ b/README @@ -38,6 +38,8 @@ j scroll down k scroll up h scroll left l scroll right +[ align with the leftmost character on the page +] align with the rightmost character on the page H show top M show middle L show bottom diff --git a/fbpdf.c b/fbpdf.c index 8cfc880..a6725e1 100644 --- a/fbpdf.c +++ b/fbpdf.c @@ -118,6 +118,38 @@ static void reload(void) showpage(num, head); } +static int rightmost(void) +{ + int ret = 0; + int i, j; + for (i = 0; i < prows; i++) { + j = PDFCOLS - 1; + while (j > ret && pbuf[i * PDFCOLS + j] == FB_VAL(0, 0, 0)) + j--; + while (j > ret && pbuf[i * PDFCOLS + j] == FB_VAL(255, 255, 255)) + j--; + if (ret < j) + ret = j; + } + return ret; +} + +static int leftmost(void) +{ + int ret = PDFCOLS; + int i, j; + for (i = 0; i < prows; i++) { + j = 0; + while (j < ret && pbuf[i * PDFCOLS + j] == FB_VAL(0, 0, 0)) + j++; + while (j < ret && pbuf[i * PDFCOLS + j] == FB_VAL(255, 255, 255)) + j++; + if (ret > j) + ret = j; + } + return ret; +} + static void mainloop(void) { int step = fb_rows() / PAGESTEPS; @@ -211,6 +243,12 @@ static void mainloop(void) case CTRL('u'): head -= fb_rows() * getcount(1) - step; break; + case '[': + left = leftmost() - hstep / 2; + break; + case ']': + left = rightmost() + hstep / 2 - fb_cols(); + break; case CTRLKEY('l'): break; default: