summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2010-06-21 00:26:14 +0200
committerTor Andersson <tor@ghostscript.com>2010-06-21 00:26:14 +0200
commit7d99b0fdbdcfb802bee9222bd0e90ed4fde2515d (patch)
tree0628a4517b1a5e05d729c1067bc6b71efff8f900
parent13b58bb6cab9384935d0b9c2b42c1e0034806ea1 (diff)
downloadmupdf-7d99b0fdbdcfb802bee9222bd0e90ed4fde2515d.tar.xz
Prepare for searching by implementing the UI for entering a search string. Changed key bindings a bit.
-rw-r--r--apps/pdfapp.c205
-rw-r--r--apps/pdfapp.h9
-rw-r--r--apps/win_main.c76
-rw-r--r--apps/x11_main.c99
-rw-r--r--fitz/dev_draw.c2
5 files changed, 251 insertions, 140 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c
index 0442b1fc..c7c07ace 100644
--- a/apps/pdfapp.c
+++ b/apps/pdfapp.c
@@ -31,26 +31,29 @@ static void pdfapp_error(pdfapp_t *app, fz_error error)
char *pdfapp_usage(pdfapp_t *app)
{
return
- " <\t\t-- rotate left\n"
- " >\t\t-- rotate right\n"
- " u up\t\t-- scroll up\n"
- " d down\t-- scroll down\n"
- " = +\t\t-- zoom in\n"
- " -\t\t-- zoom out\n"
- " w\t\t-- shrinkwrap\n"
- " r\t\t-- reload file\n"
- "\n"
- " n pgdn space\t-- next page\n"
- " b pgup back\t-- previous page\n"
- " right\t\t-- next page\n"
- " left\t\t-- previous page\n"
- " N F\t\t-- next 10\n"
- " B\t\t-- back 10\n"
- " m\t\t-- mark page for snap back\n"
- " t\t\t-- pop back to last mark\n"
- " 123g\t\t-- go to page\n"
- "\n"
- " left drag to pan, right drag to copy text\n";
+ "L\t\t-- rotate left\n"
+ "R\t\t-- rotate right\n"
+ "h\t\t-- scroll left\n"
+ "j down\t\t-- scroll down\n"
+ "k up\t\t-- scroll up\n"
+ "l\t\t-- scroll right\n"
+ "+\t\t-- zoom in\n"
+ "-\t\t-- zoom out\n"
+ "w\t\t-- shrinkwrap\n"
+ "r\t\t-- reload file\n"
+ ". pgdn right space\t-- next page\n"
+ ", pgup left b\t-- previous page\n"
+ ">\t\t-- next 10 pages\n"
+ "<\t\t-- back 10 pages\n"
+ "m\t\t-- mark page for snap back\n"
+ "t\t\t-- pop back to latest mark\n"
+ "1m\t\t-- mark page in register 1\n"
+ "1t\t\t-- go to page in register 1\n"
+ "123g\t\t-- go to page 123\n"
+ "/\t\t-- search for text\n"
+ "n\t\t-- find next search result\n"
+ "N\t\t-- find previous search result\n"
+ ;
}
void pdfapp_init(pdfapp_t *app)
@@ -61,6 +64,32 @@ void pdfapp_init(pdfapp_t *app)
app->resolution = 72;
}
+void pdfapp_invert(pdfapp_t *app, fz_bbox rect)
+{
+ unsigned *p;
+ int x, y;
+
+ int x0 = rect.x0 - app->panx;
+ int x1 = rect.x1 - app->panx;
+ int y0 = rect.y0 - app->pany;
+ int y1 = rect.y1 - app->pany;
+
+ x0 = CLAMP(x0, 0, app->image->w - 1);
+ x1 = CLAMP(x1, 0, app->image->w - 1);
+ y0 = CLAMP(y0, 0, app->image->h - 1);
+ y1 = CLAMP(y1, 0, app->image->h - 1);
+
+ for (y = y0; y < y1; y++)
+ {
+ p = (unsigned *)(app->image->samples + (y * app->image->w + x0) * 4);
+ for (x = x0; x < x1; x++)
+ {
+ *p = ~0 - *p;
+ p ++;
+ }
+ }
+}
+
void pdfapp_open(pdfapp_t *app, char *filename, int fd)
{
fz_obj *obj;
@@ -336,6 +365,36 @@ void pdfapp_onkey(pdfapp_t *app, int c)
int oldpage = app->pageno;
enum panning panto = PAN_TO_TOP;
+ if (app->isediting)
+ {
+ int n = strlen(app->search);
+ if (c < ' ')
+ {
+ if (c == '\b' && n > 0)
+ app->search[n - 1] = 0;
+ if (c == '\n' || c == '\r')
+ {
+ app->isediting = 0;
+ winrepaint(app);
+ pdfapp_onkey(app, 'n');
+ }
+ if (c == '\033')
+ {
+ app->isediting = 0;
+ winrepaint(app);
+ }
+ }
+ else
+ {
+ if (n + 2 < sizeof app->search)
+ {
+ app->search[n] = c;
+ app->search[n + 1] = 0;
+ }
+ }
+ return;
+ }
+
/*
* Save numbers typed for later
*/
@@ -349,9 +408,17 @@ void pdfapp_onkey(pdfapp_t *app, int c)
switch (c)
{
- /*
- * Zoom and rotate
- */
+ case '?':
+ winhelp(app);
+ break;
+
+ case 'q':
+ winclose(app);
+ break;
+
+ /*
+ * Zoom and rotate
+ */
case '+':
case '=':
@@ -366,15 +433,17 @@ void pdfapp_onkey(pdfapp_t *app, int c)
app->resolution = MINRES;
pdfapp_showpage(app, 0, 1);
break;
- case '<':
+
+ case 'L':
app->rotate -= 90;
pdfapp_showpage(app, 0, 1);
break;
- case '>':
+ case 'R':
app->rotate += 90;
pdfapp_showpage(app, 0, 1);
break;
+#ifdef DEBUG
case 'a':
app->rotate -= 15;
pdfapp_showpage(app, 0, 1);
@@ -383,10 +452,11 @@ void pdfapp_onkey(pdfapp_t *app, int c)
app->rotate += 15;
pdfapp_showpage(app, 0, 1);
break;
+#endif
- /*
- * Pan view, but dont need to repaint image
- */
+ /*
+ * Pan view, but dont need to repaint image
+ */
case 'w':
app->shrinkwrap = 1;
@@ -394,29 +464,29 @@ void pdfapp_onkey(pdfapp_t *app, int c)
pdfapp_showpage(app, 0, 0);
break;
- case 'd':
- app->pany -= app->image->h / 10;
+ case 'h':
+ app->panx += app->image->w / 10;
pdfapp_showpage(app, 0, 0);
break;
- case 'u':
- app->pany += app->image->h / 10;
+ case 'j':
+ app->pany -= app->image->h / 10;
pdfapp_showpage(app, 0, 0);
break;
- case ',':
- app->panx += app->image->w / 10;
+ case 'k':
+ app->pany += app->image->h / 10;
pdfapp_showpage(app, 0, 0);
break;
- case '.':
+ case 'l':
app->panx -= app->image->w / 10;
pdfapp_showpage(app, 0, 0);
break;
- /*
- * Page navigation
- */
+ /*
+ * Page navigation
+ */
case 'g':
case '\n':
@@ -461,11 +531,11 @@ void pdfapp_onkey(pdfapp_t *app, int c)
app->pageno = app->hist[--app->histlen];
break;
- /*
- * Back and forth ...
- */
+ /*
+ * Back and forth ...
+ */
- case 'p':
+ case ',':
panto = PAN_TO_BOTTOM;
if (app->numberlen > 0)
app->pageno -= atoi(app->number);
@@ -473,7 +543,7 @@ void pdfapp_onkey(pdfapp_t *app, int c)
app->pageno--;
break;
- case 'n':
+ case '.':
panto = PAN_TO_TOP;
if (app->numberlen > 0)
app->pageno += atoi(app->number);
@@ -482,7 +552,6 @@ void pdfapp_onkey(pdfapp_t *app, int c)
break;
case 'b':
- case '\b':
panto = DONT_PAN;
if (app->numberlen > 0)
app->pageno -= atoi(app->number);
@@ -490,7 +559,6 @@ void pdfapp_onkey(pdfapp_t *app, int c)
app->pageno--;
break;
- case 'f':
case ' ':
panto = DONT_PAN;
if (app->numberlen > 0)
@@ -499,19 +567,41 @@ void pdfapp_onkey(pdfapp_t *app, int c)
app->pageno++;
break;
- case 'B':
- panto = PAN_TO_TOP; app->pageno -= 10; break;
- case 'F':
- panto = PAN_TO_TOP; app->pageno += 10; break;
+ case '<':
+ panto = PAN_TO_TOP;
+ app->pageno -= 10;
+ break;
+ case '>':
+ panto = PAN_TO_TOP;
+ app->pageno += 10;
+ break;
- /*
- * Reloading the file...
- */
+ /*
+ * Reloading the file...
+ */
case 'r':
oldpage = -1;
winreloadfile(app);
break;
+
+ /*
+ * Searching
+ */
+
+ case '/':
+ app->isediting = 1;
+ app->search[0] = 0;
+ break;
+
+ case 'n':
+ printf("search forward for: '%s'\n", app->search);
+ break;
+
+ case 'N':
+ printf("search backward for: '%s'\n", app->search);
+ break;
+
}
if (c < '0' || c > '9')
@@ -526,9 +616,14 @@ void pdfapp_onkey(pdfapp_t *app, int c)
{
switch (panto)
{
- case PAN_TO_TOP: app->pany = 0; break;
- case PAN_TO_BOTTOM: app->pany = -2000; break;
- case DONT_PAN: break;
+ case PAN_TO_TOP:
+ app->pany = 0;
+ break;
+ case PAN_TO_BOTTOM:
+ app->pany = -2000;
+ break;
+ case DONT_PAN:
+ break;
}
pdfapp_showpage(app, 1, 1);
}
diff --git a/apps/pdfapp.h b/apps/pdfapp.h
index 567781e8..dc19be58 100644
--- a/apps/pdfapp.h
+++ b/apps/pdfapp.h
@@ -22,6 +22,10 @@ extern void winopenuri(pdfapp_t*, char *s);
extern void wincursor(pdfapp_t*, int curs);
extern void windocopy(pdfapp_t*);
extern void winreloadfile(pdfapp_t*);
+extern void wininvert(pdfapp_t*, fz_bbox rect);
+extern void windrawstring(pdfapp_t*, int x, int y, char *s);
+extern void winclose(pdfapp_t*);
+extern void winhelp(pdfapp_t*);
struct pdfapp_s
{
@@ -63,6 +67,10 @@ struct pdfapp_s
int selx, sely;
fz_bbox selr;
+ /* search state */
+ int isediting;
+ char search[512];
+
/* client context storage */
void *userdata;
};
@@ -78,3 +86,4 @@ void pdfapp_onmouse(pdfapp_t *app, int x, int y, int btn, int modifiers, int sta
void pdfapp_oncopy(pdfapp_t *app, unsigned short *ucsbuf, int ucslen);
void pdfapp_onresize(pdfapp_t *app, int w, int h);
+extern void pdfapp_invert(pdfapp_t *app, fz_bbox rect);
diff --git a/apps/win_main.c b/apps/win_main.c
index da896a4c..ea7ce550 100644
--- a/apps/win_main.c
+++ b/apps/win_main.c
@@ -232,7 +232,7 @@ dlogaboutproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
return FALSE;
}
-void help()
+void winhelp()
{
int code = DialogBoxW(NULL, L"IDD_DLOGABOUT", hwndframe, dlogaboutproc);
if (code <= 0)
@@ -344,6 +344,12 @@ void winopen()
SetCursor(arrowcurs);
}
+void winclose(pdfapp_t *app)
+{
+ pdfapp_close(app);
+ exit(0);
+}
+
void wincursor(pdfapp_t *app, int curs)
{
if (curs == ARROW)
@@ -395,33 +401,18 @@ void winconvert(pdfapp_t *app, fz_pixmap *image)
}
}
-void invertcopyrect(void)
+void windrawrect(pdfapp_t *app, fz_bbox rect, int color)
{
- unsigned char *p;
- int x0 = gapp.selr.x0 - gapp.panx;
- int x1 = gapp.selr.x1 - gapp.panx;
- int y0 = gapp.selr.y0 - gapp.pany;
- int y1 = gapp.selr.y1 - gapp.pany;
- int x, y;
-
- x0 = CLAMP(x0, 0, gapp.image->w - 1);
- x1 = CLAMP(x1, 0, gapp.image->w - 1);
- y0 = CLAMP(y0, 0, gapp.image->h - 1);
- y1 = CLAMP(y1, 0, gapp.image->h - 1);
-
- for (y = y0; y < y1; y++)
- {
- p = bmpdata + y * bmpstride + x0 * 3;
- for (x = x0; x < x1; x++)
- {
- p[0] = 255 - p[0];
- p[1] = 255 - p[1];
- p[2] = 255 - p[2];
- p += 3;
- }
- }
+ RECT r;
+ r.left = rect.x0;
+ r.top = rect.y0;
+ r.right = rect.x1;
+ r.bottom = rect.y1;
+ FillRect(hdc, &r, (HBRUSH)GetStockObject(WHITE_BRUSH));
+}
- justcopied = 1;
+void windrawstring(pdfapp_t *app, int x, int y, char *s)
+{
}
void winblit()
@@ -435,7 +426,10 @@ void winblit()
if (bmpdata)
{
if (gapp.iscopying || justcopied)
- invertcopyrect();
+ {
+ pdfapp_invert(&gapp, gapp.selr);
+ justcopied = 1;
+ }
dibinf->bmiHeader.biWidth = gapp.image->w;
dibinf->bmiHeader.biHeight = -gapp.image->h;
@@ -455,7 +449,10 @@ void winblit()
);
if (gapp.iscopying || justcopied)
- invertcopyrect();
+ {
+ pdfapp_invert(&gapp, gapp.selr);
+ justcopied = 1;
+ }
}
/* Grey background */
@@ -560,21 +557,16 @@ void handlekey(int c)
switch (c)
{
case VK_F1: c = '?'; break;
- case VK_ESCAPE: c = 'q'; break;
- case VK_DOWN: c = 'd'; break;
- case VK_UP: c = 'u'; break;
- case VK_LEFT: c = 'p'; break;
- case VK_RIGHT: c = 'n'; break;
- case VK_PRIOR: c = 'b'; break;
- case VK_NEXT: c = ' '; break;
+ case VK_ESCAPE: c = '\033; break;
+ case VK_DOWN: c = 'j'; break;
+ case VK_UP: c = 'k'; break;
+ case VK_LEFT: c = 'b'; break;
+ case VK_RIGHT: c = ' '; break;
+ case VK_PRIOR: c = ','; break;
+ case VK_NEXT: c = '.'; break;
}
- if (c == 'q')
- exit(0);
- else if (c == '?' || c == 'h')
- help();
- else
- pdfapp_onkey(&gapp, c);
+ pdfapp_onkey(&gapp, c);
}
void handlemouse(int x, int y, int btn, int state)
@@ -612,7 +604,7 @@ frameproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_SYSCOMMAND:
if (wParam == ID_ABOUT)
{
- help();
+ winhelp();
return 0;
}
if (wParam == ID_DOCINFO)
diff --git a/apps/x11_main.c b/apps/x11_main.c
index 61abaa63..a1382a67 100644
--- a/apps/x11_main.c
+++ b/apps/x11_main.c
@@ -180,6 +180,11 @@ static void winopen(void)
x11fd = ConnectionNumber(xdpy);
}
+void winclose(pdfapp_t *app)
+{
+ closing = 1;
+}
+
void wincursor(pdfapp_t *app, int curs)
{
if (curs == ARROW)
@@ -205,6 +210,11 @@ void winconvert(pdfapp_t *app, fz_pixmap *image)
/* never mind */
}
+void winhelp(pdfapp_t *app)
+{
+ fprintf(stderr, "%s", pdfapp_usage(app));
+}
+
void winresize(pdfapp_t *app, int w, int h)
{
XWindowChanges values;
@@ -247,32 +257,10 @@ static void fillrect(int x, int y, int w, int h)
XFillRectangle(xdpy, xwin, xgc, x, y, w, h);
}
-static void invertcopyrect()
+void windrawrect(pdfapp_t *app, fz_bbox rect, int color)
{
- unsigned *p;
- int x, y;
-
- int x0 = gapp.selr.x0 - gapp.panx;
- int x1 = gapp.selr.x1 - gapp.panx;
- int y0 = gapp.selr.y0 - gapp.pany;
- int y1 = gapp.selr.y1 - gapp.pany;
-
- x0 = CLAMP(x0, 0, gapp.image->w - 1);
- x1 = CLAMP(x1, 0, gapp.image->w - 1);
- y0 = CLAMP(y0, 0, gapp.image->h - 1);
- y1 = CLAMP(y1, 0, gapp.image->h - 1);
-
- for (y = y0; y < y1; y++)
- {
- p = (unsigned *)(gapp.image->samples + (y * gapp.image->w + x0) * 4);
- for (x = x0; x < x1; x++)
- {
- *p = ~0 - *p;
- p ++;
- }
- }
-
- justcopied = 1;
+ XSetForeground(xdpy, xgc, WhitePixel(xdpy, xscr));
+ XFillRectangle(xdpy, xwin, xgc, rect.x0, rect.y0, rect.x1 - rect.x0, rect.y1 - rect.y0);
}
static void winblit(pdfapp_t *app)
@@ -293,7 +281,10 @@ static void winblit(pdfapp_t *app)
fillrect(x1, y0+2, 2, gapp.image->h);
if (gapp.iscopying || justcopied)
- invertcopyrect();
+ {
+ pdfapp_invert(&gapp, gapp.selr);
+ justcopied = 1;
+ }
ximage_blit(xwin, xgc,
x0, y0,
@@ -304,7 +295,19 @@ static void winblit(pdfapp_t *app)
gapp.image->w * gapp.image->n);
if (gapp.iscopying || justcopied)
- invertcopyrect();
+ {
+ pdfapp_invert(&gapp, gapp.selr);
+ justcopied = 1;
+ }
+
+ if (gapp.isediting)
+ {
+ char buf[sizeof(gapp.search) + 50];
+ sprintf(buf, "Search: %s", gapp.search);
+ XSetForeground(xdpy, xgc, WhitePixel(xdpy, xscr));
+ fillrect(0, 0, gapp.winw, 30);
+ windrawstring(&gapp, 10, 20, buf);
+ }
}
void winrepaint(pdfapp_t *app)
@@ -312,7 +315,7 @@ void winrepaint(pdfapp_t *app)
dirty = 1;
}
-static void windrawstring(pdfapp_t *app, char *s, int x, int y)
+void windrawstringxor(pdfapp_t *app, int x, int y, char *s)
{
int prevfunction;
XGCValues xgcv;
@@ -330,6 +333,14 @@ static void windrawstring(pdfapp_t *app, char *s, int x, int y)
XGetGCValues(xdpy, xgc, GCFunction, &xgcv);
xgcv.function = prevfunction;
XChangeGC(xdpy, xgc, GCFunction, &xgcv);
+
+ printf("drawstring '%s'\n", s);
+}
+
+void windrawstring(pdfapp_t *app, int x, int y, char *s)
+{
+ XSetForeground(xdpy, xgc, BlackPixel(xdpy, DefaultScreen(xdpy)));
+ XDrawString(xdpy, xwin, xgc, x, y, s, strlen(s));
}
static void windrawpageno(pdfapp_t *app)
@@ -340,7 +351,7 @@ static void windrawpageno(pdfapp_t *app)
if (ret >= 0)
{
isshowingpage = 1;
- windrawstring(&gapp, s, 10, 20);
+ windrawstringxor(&gapp, 10, 20, s);
}
}
@@ -462,12 +473,7 @@ static void onkey(int c)
winrepaint(&gapp);
}
- if (c == 'P')
- windrawpageno(&gapp);
- else if (c == 'q')
- closing = 1;
- else
- pdfapp_onkey(&gapp, c);
+ pdfapp_onkey(&gapp, c);
}
static void onmouse(int x, int y, int btn, int modifiers, int state)
@@ -628,28 +634,28 @@ int main(int argc, char **argv)
switch (keysym)
{
case XK_Escape:
- len = 1; buf[0] = 'q';
+ len = 1; buf[0] = '\033';
break;
case XK_Up:
- len = 1; buf[0] = 'u';
+ len = 1; buf[0] = 'k';
break;
case XK_Down:
- len = 1; buf[0] = 'd';
+ len = 1; buf[0] = 'j';
break;
case XK_Left:
- len = 1; buf[0] = 'p';
+ len = 1; buf[0] = 'b';
break;
case XK_Right:
- len = 1; buf[0] = 'n';
+ len = 1; buf[0] = ' ';
break;
case XK_Page_Up:
- len = 1; buf[0] = 'b';
+ len = 1; buf[0] = ',';
break;
case XK_Page_Down:
- len = 1; buf[0] = ' ';
+ len = 1; buf[0] = '.';
break;
}
if (len)
@@ -668,6 +674,15 @@ int main(int argc, char **argv)
}
}
+ if (gapp.isediting)
+ {
+ char buf[sizeof(gapp.search) + 50];
+ sprintf(buf, "Search: %s", gapp.search);
+ XSetForeground(xdpy, xgc, WhitePixel(xdpy, xscr));
+ fillrect(0, 0, gapp.winw, 30);
+ windrawstring(&gapp, 10, 20, buf);
+ }
+
if (!wasshowingpage && isshowingpage)
winsettmo(&tmo, &tmo_at);
diff --git a/fitz/dev_draw.c b/fitz/dev_draw.c
index 75100f2e..0b909f85 100644
--- a/fitz/dev_draw.c
+++ b/fitz/dev_draw.c
@@ -520,7 +520,7 @@ calcimagestate(fz_drawdevice *dev, fz_pixmap *image, fz_matrix ctm,
*bbox = fz_boundgel(dev->gel);
*bbox = fz_intersectbbox(*bbox, dev->scissor);
-
+
mat.a = 1.0f / w;
mat.b = 0;
mat.c = 0;