fbpdf: align with the leftmost/rightmost character in the page
authorAli Gholami Rudi <ali@rudi.ir>
Fri, 22 Mar 2013 15:51:52 +0000 (22 20:21 +0430)
committerAli Gholami Rudi <ali@rudi.ir>
Fri, 22 Mar 2013 15:51:52 +0000 (22 20:21 +0430)
[ and ] commands align the screen with the leftmost and rightmost
characters on the page.  Very convenient especially for multi-column
pages.

README
fbpdf.c

diff --git a/README b/README
index 53cb050..66de094 100644 (file)
--- 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 (file)
--- 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: