summaryrefslogtreecommitdiff
path: root/apps/windows/win_main.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2005-03-31 12:58:07 +0200
committerTor Andersson <tor@ghostscript.com>2005-03-31 12:58:07 +0200
commit9a66d290b823080fe559e53bfd80785184e6fc27 (patch)
treeb099246d44008a03c445bae9724ff5b7a939d48e /apps/windows/win_main.c
parentd9f39824674b6c94a5dd3ab7646301cb1f1e305b (diff)
downloadmupdf-9a66d290b823080fe559e53bfd80785184e6fc27.tar.xz
pan & scan in windows ghostpdf
Diffstat (limited to 'apps/windows/win_main.c')
-rw-r--r--apps/windows/win_main.c648
1 files changed, 392 insertions, 256 deletions
diff --git a/apps/windows/win_main.c b/apps/windows/win_main.c
index bdb0bb64..9f106a4a 100644
--- a/apps/windows/win_main.c
+++ b/apps/windows/win_main.c
@@ -4,30 +4,50 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commdlg.h>
+#include <shellapi.h>
+
+#define fz_abort(eo) winabort(eo->msg)
+
+void showpage(void);
static HWND hwnd = NULL;
static HDC hdc;
+static HBRUSH bgbrush;
+static HBRUSH shbrush;
static BITMAPINFO *dibinf;
-static TCHAR szAppName[] = TEXT("mupdf");
+static TCHAR szAppName[] = TEXT("ghostpdf");
static HCURSOR arrowcurs, handcurs, waitcurs;
static LRESULT CALLBACK windproc(HWND, UINT, WPARAM, LPARAM);
+static int winwidth = 0;
+static int winheight = 0;
+
+static int isdown = 0;
+static int oldx = 0, oldy = 0;
+
+
+static int bmpstride = 0;
+static char *bmpdata = NULL;
+
+static int screenwidth = 640;
+static int screenheight = 480;
+static int shrinkwrap = 1;
+static int panx = 0;
+static int pany = 0;
+static char *password = "";
+static char *filename = "";
static char *doctitle = "<untitled>";
static float zoom = 1.0;
static int rotate = 0;
static int pageno = 1;
static int count = 0;
-static char *password = "";
-static char *filename = "";
-
static pdf_page *page = nil;
static fz_obj *pageobj = nil;
static int hist[256];
static int histlen = 0;
-/* for 123G commands */
static unsigned char pagebuf[256];
static int pagebufidx = 0;
@@ -37,7 +57,35 @@ static pdf_outline *outline;
static fz_renderer *rast;
static fz_pixmap *image;
-#define fz_abort(eo) winabort(eo->msg)
+/*
+ * Dialog boxes
+ */
+
+void winwarn(const char *fmt, ...)
+{
+ char buf[1024];
+ va_list ap;
+ va_start(ap, fmt);
+ vsprintf(buf, fmt, ap);
+ va_end(ap);
+ MessageBoxA(hwnd, buf, "GhostPDF: Warning", MB_ICONWARNING);
+}
+
+void winerror(const char *fmt, ...)
+{
+ char buf[1024];
+ va_list ap;
+ va_start(ap, fmt);
+ vsprintf(buf, fmt, ap);
+ va_end(ap);
+ MessageBoxA(hwnd, buf, "GhostPDF: Error", MB_ICONERROR);
+ exit(1);
+}
+
+void winabort(const char *msg)
+{
+ winerror("There was a problem with file \"%s\":\n\n%s\n", filename, msg);
+}
int getfilename(char *buf, int len)
{
@@ -103,24 +151,24 @@ char *getpassword(void)
void help()
{
- char *msg = \
- "ghostpdf [-b] [-pzr page/zoom/rotate] [-u password] file.pdf\n\n"
- /*"key commands:\n" */
- " h\tdisplay this help\n"
- " <\trotate left\n"
- " >\trotate right\n"
- " +\tzoom in\n"
- " -\tzoom out\n"
- " b\tgo back one page\n"
- " B\tgo back ten pages\n"
- " f\tgo forward one page\n"
- " F\tgo forward ten pages\n"
- " G\tgo to last page\n"
- " m\tmark page for pop-back\n"
- " t\tpop back to last mark\n"
- " 123g\tgo to page 123\n"
- "\nGhostPDF is Copyright (C) 2005 artofcode LLC\n"
- ;
+ char msg[1024];
+ sprintf(msg,
+ "GhostPDF v%0.2f -- %s\n\n"
+ " h\t-- display this help\n"
+ " <\t-- rotate left\n"
+ " >\t-- rotate right\n"
+ " +\t-- zoom in\n"
+ " -\t-- zoom out\n"
+ " w\t-- shrinkwrap window\n"
+ " b\t-- go back one page\n"
+ " B\t-- go back ten pages\n"
+ " f\t-- go forward one page\n"
+ " F\t-- go forward ten pages\n"
+ " G\t-- go to last page\n"
+ " m\t-- mark page\n"
+ " t\t-- pop back to last marked page\n"
+ " 123g\t-- go to page 123\n",
+ PDF_VERSION / 100.0, PDF_COPYRIGHT);
MessageBoxA(hwnd, msg, "GhostPDF: Usage", MB_ICONINFORMATION);
}
@@ -130,35 +178,14 @@ void usage()
exit(1);
}
-void winwarn(const char *fmt, ...)
-{
- char buf[1024];
- va_list ap;
- va_start(ap, fmt);
- vsprintf(buf, fmt, ap);
- va_end(ap);
- MessageBoxA(hwnd, buf, "GhostPDF: Warning", MB_ICONWARNING);
-}
-
-void winerror(const char *fmt, ...)
-{
- char buf[1024];
- va_list ap;
- va_start(ap, fmt);
- vsprintf(buf, fmt, ap);
- va_end(ap);
- MessageBoxA(hwnd, buf, "GhostPDF: Error", MB_ICONERROR);
- exit(1);
-}
-
-void winabort(const char *msg)
-{
- winerror("There was a problem with file \"%s\":\n\n%s\n", filename, msg);
-}
+/*
+ * Main window
+ */
void winopen()
{
WNDCLASS wc;
+ RECT r;
/* Create and register window class */
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
@@ -173,11 +200,20 @@ void winopen()
wc.lpszClassName = szAppName;
assert(RegisterClass(&wc) && "Register window class");
+ /* Get screen size */
+ SystemParametersInfo(SPI_GETWORKAREA, 0, &r, 0);
+ screenwidth = r.right - r.left;
+ screenheight = r.bottom - r.top;
+
/* Create cursors */
arrowcurs = LoadCursor(NULL, IDC_ARROW);
handcurs = LoadCursor(NULL, IDC_HAND);
waitcurs = LoadCursor(NULL, IDC_WAIT);
+ /* And a background color */
+ bgbrush = CreateSolidBrush(RGB(0x70,0x70,0x70));
+ shbrush = CreateSolidBrush(RGB(0x40,0x40,0x40));
+
/* Init DIB info for buffer */
dibinf = malloc(sizeof(BITMAPINFO) + 12);
assert(dibinf != NULL);
@@ -194,10 +230,9 @@ void winopen()
/* Create window */
hwnd = CreateWindow(szAppName, // window class name
NULL, // window caption
- //WS_OVERLAPPEDWINDOW, // window style
- WS_CAPTION|WS_THICKFRAME|WS_SYSMENU|WS_MINIMIZEBOX,
- CW_USEDEFAULT, // initial x position
- 5, // CW_USEDEFAULT, // initial y position
+ WS_OVERLAPPEDWINDOW,
+ 5, //CW_USEDEFAULT, // initial x position
+ 5, //CW_USEDEFAULT, // initial y position
300, // initial x size
300, // initial y size
NULL, // parent window handle
@@ -212,23 +247,22 @@ void winopen()
SetCursor(arrowcurs);
}
-void winblit()
+void winconvertimage()
{
- /* TODO: repack image in windows format */
- int stride = ((image->w * 3 + 3) / 4) * 4;
- char *buf;
- char *s;
- char *p;
int y, x;
- buf = fz_malloc(image->h * stride);
- if (!buf)
+ if (bmpdata)
+ fz_free(bmpdata);
+
+ bmpstride = ((image->w * 3 + 3) / 4) * 4;
+ bmpdata = fz_malloc(image->h * bmpstride);
+ if (!bmpdata)
return;
for (y = 0; y < image->h; y++)
{
- p = buf + y * stride;
- s = image->samples + y * image->w * 4;
+ char *p = bmpdata + y * bmpstride;
+ char *s = image->samples + y * image->w * 4;
for (x = 0; x < image->w; x++)
{
p[x * 3 + 0] = s[x * 4 + 3];
@@ -236,31 +270,67 @@ void winblit()
p[x * 3 + 2] = s[x * 4 + 1];
}
}
+}
+
+void winblit()
+{
+ int x0 = panx;
+ int y0 = pany;
+ int x1 = panx + image->w;
+ int y1 = pany + image->h;
+ RECT r;
- dibinf->bmiHeader.biWidth = image->w;
- dibinf->bmiHeader.biHeight = -image->h;
- dibinf->bmiHeader.biSizeImage = image->h * stride;
-
- assert(hdc != NULL);
- SetDIBitsToDevice(hdc,
- 0, /* destx */
- 0, /* desty */
- image->w, /* destw */
- image->h, /* desth */
- 0, /* srcx */
- 0, /* srcy */
- 0, /* startscan */
- image->h, /* numscans */
- buf, /* pBits */
- dibinf, /* pInfo */
- DIB_RGB_COLORS /* color use flag */
- );
-
- fz_free(buf);
+ if (bmpdata)
+ {
+ dibinf->bmiHeader.biWidth = image->w;
+ dibinf->bmiHeader.biHeight = -image->h;
+ dibinf->bmiHeader.biSizeImage = image->h * bmpstride;
+ SetDIBitsToDevice(hdc,
+ panx, /* destx */
+ pany, /* desty */
+ image->w, /* destw */
+ image->h, /* desth */
+ 0, /* srcx */
+ 0, /* srcy */
+ 0, /* startscan */
+ image->h, /* numscans */
+ bmpdata, /* pBits */
+ dibinf, /* pInfo */
+ DIB_RGB_COLORS /* color use flag */
+ );
+ }
+
+
+ r.top = 0; r.bottom = winheight;
+ r.left = 0; r.right = x0;
+ FillRect(hdc, &r, bgbrush);
+ r.left = x1; r.right = winwidth;
+ FillRect(hdc, &r, bgbrush);
+
+ r.left = 0; r.right = winwidth;
+ r.top = 0; r.bottom = y0;
+ FillRect(hdc, &r, bgbrush);
+ r.top = y1; r.bottom = winheight;
+ FillRect(hdc, &r, bgbrush);
+
+ r.left = x0 + 2;
+ r.right = x1 + 2;
+ r.top = y1;
+ r.bottom = y1 + 2;
+ FillRect(hdc, &r, shbrush);
+ r.left = x1;
+ r.right = x1 + 2;
+ r.top = y0 + 2;
+ r.bottom = y1;
+ FillRect(hdc, &r, shbrush);
}
void winresize(int w, int h)
{
+ if (w > screenwidth * 95 / 100)
+ w = screenwidth * 95 / 100;
+ if (h > screenheight * 95 / 100)
+ h = screenheight * 95 / 100;
ShowWindow(hwnd, SW_SHOWDEFAULT);
w += GetSystemMetrics(SM_CXFRAME) * 2;
h += GetSystemMetrics(SM_CYFRAME) * 2;
@@ -270,8 +340,7 @@ void winresize(int w, int h)
void winrepaint(void)
{
- RECT wr = (RECT){0, 0, image->w, image->h};
- InvalidateRect(hwnd, &wr, 0);
+ InvalidateRect(hwnd, NULL, 0);
}
void dragndrop()
@@ -280,176 +349,35 @@ void dragndrop()
ReleaseCapture();
}
-static void showpage(void)
-{
- fz_error *error;
- fz_matrix ctm;
- fz_rect bbox;
- fz_obj *obj;
-
- assert(pageno > 0 && pageno <= pdf_getpagecount(pages));
-
- SetCursor(waitcurs);
-
- if (image)
- fz_droppixmap(image);
- image = nil;
-
- obj = pdf_getpageobject(pages, pageno - 1);
- if (obj == pageobj)
- goto Lskipload;
- pageobj = obj;
-
- if (page)
- pdf_droppage(page);
-
- error = pdf_loadpage(&page, xref, pageobj);
- if (error)
- fz_abort(error);
-
-Lskipload:
-
- ctm = fz_identity();
- ctm = fz_concat(ctm, fz_translate(0, -page->mediabox.max.y));
- ctm = fz_concat(ctm, fz_scale(zoom, -zoom));
- ctm = fz_concat(ctm, fz_rotate(rotate + page->rotate));
-
- bbox = fz_transformaabb(ctm, page->mediabox);
-
- error = fz_rendertree(&image, rast, page->tree, ctm, fz_roundrect(bbox), 1);
- if (error)
- fz_abort(error);
-
- SetCursor(arrowcurs);
- {
- char buf[512];
- sprintf(buf, "%s - %d/%d", doctitle, pageno, count);
- SetWindowTextA(hwnd, buf);
- }
-
- winresize(image->w, image->h);
- winrepaint();
-}
-
-static void pdfopen(void)
-{
- fz_error *error;
- fz_obj *obj;
-
- error = pdf_newxref(&xref);
- if (error)
- fz_abort(error);
-
- error = pdf_loadxref(xref, filename);
- if (error)
- {
- if (!strncmp(error->msg, "ioerror", 7))
- fz_abort(error);
- winwarn(
- "There was a problem with file \"%s\".\n"
- "It may be corrupted, or generated by broken software.\n\n"
- "%s\n\nTrying to continue anyway...",
- filename, error->msg);
- error = pdf_repairxref(xref, filename);
- if (error)
- fz_abort(error);
- }
-
- error = pdf_decryptxref(xref);
- if (error)
- fz_abort(error);
-
- if (xref->crypt)
- {
- error = pdf_setpassword(xref->crypt, password);
- while (error)
- {
- fz_droperror(error);
- password = getpassword();
- if (!password)
- exit(1);
- error = pdf_setpassword(xref->crypt, password);
- if (error)
- winwarn("Invalid password.");
- }
- }
-
- obj = fz_dictgets(xref->trailer, "Root");
- if (!obj)
- fz_abort(fz_throw("syntaxerror: missing Root object"));
- error = pdf_loadindirect(&xref->root, xref, obj);
- if (error) fz_abort(error);
-
- obj = fz_dictgets(xref->trailer, "Info");
- if (obj)
- {
- error = pdf_loadindirect(&xref->info, xref, obj);
- if (error) fz_abort(error);
- }
-
- error = pdf_loadnametrees(xref);
- if (error) fz_abort(error);
-
- error = pdf_loadoutline(&outline, xref);
- if (error) fz_abort(error);
-
- doctitle = filename;
- if (strrchr(doctitle, '\\')) doctitle = strrchr(doctitle, '\\') + 1;
- if (strrchr(doctitle, '/')) doctitle = strrchr(doctitle, '/') + 1;
- if (xref->info)
- {
- obj = fz_dictgets(xref->info, "Title");
- if (obj)
- {
- error = pdf_toutf8(&doctitle, obj);
- if (error) fz_abort(error);
- }
- }
-
-// if (outline)
-// pdf_debugoutline(outline, 0);
-
- error = pdf_loadpagetree(&pages, xref);
- if (error) fz_abort(error);
-
- count = pdf_getpagecount(pages);
-
- error = fz_newrenderer(&rast, pdf_devicergb, 0, 1024 * 512);
- if (error) fz_abort(error);
+/*
+ * Event handling
+ */
- image = nil;
-}
-
-static void dumptext()
+void dumptext()
{
fz_error *error;
pdf_textline *line;
-
error = pdf_loadtextfromtree(&line, page->tree);
if (error)
fz_abort(error);
-
pdf_debugtextline(line);
-
pdf_droptextline(line);
}
-static void gotouri(fz_obj *uri)
+void gotouri(fz_obj *uri)
{
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
char cmd[2048];
char buf[2048];
memcpy(buf, fz_tostrbuf(uri), fz_tostrlen(uri));
buf[fz_tostrlen(uri)] = 0;
- if (getenv("BROWSER"))
- sprintf(cmd, "$BROWSER %s &", buf);
- else
- sprintf(cmd, "start %s", buf);
- system(cmd);
+ ShellExecute(hwnd, "open", buf, 0, 0, SW_SHOWNORMAL);
}
-static void gotopage(fz_obj *obj)
+void gotopage(fz_obj *obj)
{
int oid = fz_tonum(obj);
int i;
@@ -471,7 +399,7 @@ static void gotopage(fz_obj *obj)
}
}
-static void handlekey(int c)
+void handlekey(int c)
{
int oldpage = pageno;
float oldzoom = zoom;
@@ -553,6 +481,13 @@ static void handlekey(int c)
case '>':
rotate += 90;
break;
+
+ case 'w':
+ shrinkwrap = 1;
+ panx = pany = 0;
+ winresize(image->w, image->h);
+ break;
+
case VK_ESCAPE:
case 'q':
exit(0);
@@ -582,14 +517,14 @@ static void handlekey(int c)
showpage();
}
-static void handlemouse(int x, int y, int btn)
+void handlemouse(int x, int y, int btn, int state)
{
pdf_link *link;
fz_matrix ctm;
fz_point p;
- p.x = x + image->x;
- p.y = y + image->y;
+ p.x = x - panx + image->x;
+ p.y = y - pany + image->y;
ctm = fz_identity();
ctm = fz_concat(ctm, fz_translate(0, -page->mediabox.max.y));
@@ -609,18 +544,56 @@ static void handlemouse(int x, int y, int btn)
if (link)
{
SetCursor(handcurs);
- if (btn)
+ if (btn == 1 && state == 1)
{
if (fz_isstring(link->dest))
gotouri(link->dest);
if (fz_isindirect(link->dest))
gotopage(link->dest);
+ return;
}
}
else
{
SetCursor(arrowcurs);
}
+
+ if (state == 1)
+ {
+ isdown = 1;
+ SetCapture(hwnd);
+ }
+ else if (state == -1)
+ {
+ isdown = 0;
+ ReleaseCapture();
+ }
+ else if (isdown)
+ {
+ int newx = panx + x - oldx;
+ int newy = pany + y - oldy;
+
+ /* constrain panning if window is smaller */
+ if (winwidth <= image->w && winheight <= image->h)
+ {
+ if (newx > 0) newx = 0;
+ if (newx + image->w < winwidth)
+ newx = winwidth - image->w;
+ if (newy > 0) newy = 0;
+ if (newy + image->h < winheight)
+ newy = winheight - image->h;
+ }
+
+ if (panx != newx || pany != newy)
+ {
+ panx = newx;
+ pany = newy;
+ winrepaint();
+ }
+ }
+
+ oldx = x;
+ oldy = y;
}
LRESULT CALLBACK
@@ -649,8 +622,18 @@ windproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
//puts("WM_KILLFOCUS");
return 0;
+ case WM_SIZE:
+ if (wParam == SIZE_MINIMIZED)
+ return 0;
+ if (wParam == SIZE_MAXIMIZED)
+ shrinkwrap = 0;
+ winwidth = LOWORD(lParam);
+ winheight = HIWORD(lParam);
+ winrepaint();
+ return 0;
+
case WM_SIZING:
- //puts("WM_SIZING");
+ shrinkwrap = 0;
return 0;
/* Paint events are low priority and automagically catenated
@@ -671,33 +654,33 @@ windproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_LBUTTONDOWN:
//puts("WM_LBUTTONDOWN");
- handlemouse(x, y, 1);
- return 0;
- case WM_RBUTTONDOWN:
- //puts("WM_RBUTTONDOWN");
- handlemouse(x, y, 4);
+ handlemouse(x, y, 1, 1);
return 0;
case WM_MBUTTONDOWN:
//puts("WM_MBUTTONDOWN");
- handlemouse(x, y, 2);
+ handlemouse(x, y, 2, 1);
+ return 0;
+ case WM_RBUTTONDOWN:
+ //puts("WM_RBUTTONDOWN");
+ handlemouse(x, y, 3, 1);
return 0;
case WM_LBUTTONUP:
//puts("WM_LBUTTONUP");
- handlemouse(x, y, 0);
+ handlemouse(x, y, 1, -1);
return 0;
- case WM_RBUTTONUP:
+ case WM_MBUTTONUP:
//puts("WM_RBUTTONUP");
- handlemouse(x, y, 0);
+ handlemouse(x, y, 2, -1);
return 0;
- case WM_MBUTTONUP:
+ case WM_RBUTTONUP:
//puts("WM_RBUTTONUP");
- handlemouse(x, y, 0);
+ handlemouse(x, y, 3, -1);
return 0;
case WM_MOUSEMOVE:
//puts("WM_MOUSEMOVE");
- handlemouse(x, y, 0);
+ handlemouse(x, y, 0, 0);
return 0;
/* Mouse wheel */
@@ -740,6 +723,7 @@ windproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case VK_NEXT:
case VK_ESCAPE:
handlekey(wParam);
+ handlemouse(oldx, oldy, 0, 0); /* update cursor */
return 0;
}
return 1;
@@ -748,6 +732,7 @@ windproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_CHAR:
//printf("WM_CHAR: %d '%c'\n", wParam, wParam);
handlekey(wParam);
+ handlemouse(oldx, oldy, 0, 0); /* update cursor */
return 0;
}
@@ -757,6 +742,160 @@ windproc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
return DefWindowProc(hwnd, message, wParam, lParam);
}
+/*
+ * Draw page, init and main stuff
+ */
+
+void showpage(void)
+{
+ fz_error *error;
+ fz_matrix ctm;
+ fz_rect bbox;
+ fz_obj *obj;
+
+ assert(pageno > 0 && pageno <= pdf_getpagecount(pages));
+
+ SetCursor(waitcurs);
+
+ if (image)
+ fz_droppixmap(image);
+ image = nil;
+
+ obj = pdf_getpageobject(pages, pageno - 1);
+ if (obj == pageobj)
+ goto Lskipload;
+ pageobj = obj;
+
+ if (page)
+ pdf_droppage(page);
+
+ error = pdf_loadpage(&page, xref, pageobj);
+ if (error)
+ fz_abort(error);
+
+Lskipload:
+
+ ctm = fz_identity();
+ ctm = fz_concat(ctm, fz_translate(0, -page->mediabox.max.y));
+ ctm = fz_concat(ctm, fz_scale(zoom, -zoom));
+ ctm = fz_concat(ctm, fz_rotate(rotate + page->rotate));
+
+ bbox = fz_transformaabb(ctm, page->mediabox);
+
+ error = fz_rendertree(&image, rast, page->tree, ctm, fz_roundrect(bbox), 1);
+ if (error)
+ fz_abort(error);
+
+ winconvertimage();
+
+ SetCursor(arrowcurs);
+ {
+ char buf[512];
+ sprintf(buf, "%s - %d/%d", doctitle, pageno, count);
+ SetWindowTextA(hwnd, buf);
+ }
+
+ if (shrinkwrap)
+ {
+ if (winwidth == image->w)
+ panx = 0;
+ if (winheight == image->h)
+ pany = 0;
+ winresize(image->w, image->h);
+ }
+
+ winrepaint();
+}
+
+void pdfopen(void)
+{
+ fz_error *error;
+ fz_obj *obj;
+
+ error = pdf_newxref(&xref);
+ if (error)
+ fz_abort(error);
+
+ error = pdf_loadxref(xref, filename);
+ if (error)
+ {
+ if (!strncmp(error->msg, "ioerror", 7))
+ fz_abort(error);
+ winwarn(
+ "There was a problem with file \"%s\".\n"
+ "It may be corrupted, or generated by broken software.\n\n"
+ "%s\n\nTrying to continue anyway...",
+ filename, error->msg);
+ error = pdf_repairxref(xref, filename);
+ if (error)
+ fz_abort(error);
+ }
+
+ error = pdf_decryptxref(xref);
+ if (error)
+ fz_abort(error);
+
+ if (xref->crypt)
+ {
+ error = pdf_setpassword(xref->crypt, password);
+ while (error)
+ {
+ fz_droperror(error);
+ password = getpassword();
+ if (!password)
+ exit(1);
+ error = pdf_setpassword(xref->crypt, password);
+ if (error)
+ winwarn("Invalid password.");
+ }
+ }
+
+ obj = fz_dictgets(xref->trailer, "Root");
+ if (!obj)
+ fz_abort(fz_throw("syntaxerror: missing Root object"));
+ error = pdf_loadindirect(&xref->root, xref, obj);
+ if (error) fz_abort(error);
+
+ obj = fz_dictgets(xref->trailer, "Info");
+ if (obj)
+ {
+ error = pdf_loadindirect(&xref->info, xref, obj);
+ if (error) fz_abort(error);
+ }
+
+ error = pdf_loadnametrees(xref);
+ if (error) fz_abort(error);
+
+ error = pdf_loadoutline(&outline, xref);
+ if (error) fz_abort(error);
+
+ doctitle = filename;
+ if (strrchr(doctitle, '\\')) doctitle = strrchr(doctitle, '\\') + 1;
+ if (strrchr(doctitle, '/')) doctitle = strrchr(doctitle, '/') + 1;
+ if (xref->info)
+ {
+ obj = fz_dictgets(xref->info, "Title");
+ if (obj)
+ {
+ error = pdf_toutf8(&doctitle, obj);
+ if (error) fz_abort(error);
+ }
+ }
+
+// if (outline)
+// pdf_debugoutline(outline, 0);
+
+ error = pdf_loadpagetree(&pages, xref);
+ if (error) fz_abort(error);
+
+ count = pdf_getpagecount(pages);
+
+ error = fz_newrenderer(&rast, pdf_devicergb, 0, 1024 * 512);
+ if (error) fz_abort(error);
+
+ image = nil;
+}
+
int main(int argc, char **argv)
{
char buf[1024];
@@ -783,10 +922,7 @@ int main(int argc, char **argv)
if (argc - optind == 0)
{
if (!getfilename(buf, sizeof buf))
- {
- help();
exit(0);
- }
filename = buf;
}
else