summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/GsWidget.H2
-rw-r--r--src/GsWidget.cxx85
-rw-r--r--src/PostscriptDSC.H2
-rw-r--r--src/PostscriptDSC.cxx19
-rw-r--r--src/flpsed.cxx7
5 files changed, 83 insertions, 32 deletions
diff --git a/src/GsWidget.H b/src/GsWidget.H
index 370de14..cc4e9fd 100644
--- a/src/GsWidget.H
+++ b/src/GsWidget.H
@@ -71,6 +71,8 @@ public:
int next();
+ int prev();
+
int handleX11(int ev);
int zoom(int p);
diff --git a/src/GsWidget.cxx b/src/GsWidget.cxx
index 888d599..3d3a081 100644
--- a/src/GsWidget.cxx
+++ b/src/GsWidget.cxx
@@ -114,7 +114,7 @@ GsWidget::GsWidget(int X,int Y,int W, int H) : Fl_Widget(X, Y, W, H) {
initial_height = H;
in_fd = -1;
reload_needed = 0;
- dsc = new PostscriptDSC();
+ dsc = NULL;
}
GsWidget::~GsWidget() {
@@ -137,9 +137,13 @@ int GsWidget::open_file(int fd) {
if (in_fd >= 0 && fd != in_fd) {
close (in_fd);
}
-
in_fd = fd;
+ if (dsc) {
+ delete(dsc);
+ }
+ dsc = new PostscriptDSC();
+
if (dsc->parse(in_fd) == 0) {
int bb_x, bb_y, bb_w, bb_h;
@@ -147,8 +151,15 @@ int GsWidget::open_file(int fd) {
dsc->get_bounding_box(&bb_x, &bb_y, &bb_w, &bb_h);
paper_x = bb_w;
paper_y = bb_h;
+ } else {
+ delete(dsc);
+ dsc = NULL;
+ paper_x = 594; // DIN A4
+ paper_y = 841; //
}
+ page = 0;
+
return 0;
}
@@ -156,6 +167,10 @@ int GsWidget::open_file(int fd) {
int GsWidget::load() {
pid_t pid;
+ if (dsc) {
+ return load_page(0);
+ }
+
if (in_fd < 0) {
return 1;
}
@@ -178,7 +193,7 @@ int GsWidget::load() {
exec_gs();
} else {
gs_pid = pid;
- page = 0;
+ page = 1;
}
return 0;
@@ -193,7 +208,7 @@ GsWidget::load_page(int p) {
return 1;
}
- if (p < 1 || p > dsc->get_pages()) {
+ if (p < 0 || p >= dsc->get_pages()) {
fprintf(stderr, "Page %d not found in document\n", p);
return 1;
}
@@ -201,6 +216,11 @@ GsWidget::load_page(int p) {
fl_cursor(FL_CURSOR_WAIT);
kill_gs();
+ if (!offscreen) {
+ reload_needed = 1;
+ return 0;
+ }
+
if (pipe(pdes) < 0) {
perror("pipe");
return 1;
@@ -295,7 +315,11 @@ int GsWidget::reload() {
int ret;
if (in_fd >= 0) {
- open_file(in_fd);
+ if (dsc) {
+ load_page(page);
+ } else {
+ load();
+ }
return 0;
} else {
return 1;
@@ -303,35 +327,54 @@ int GsWidget::reload() {
}
int GsWidget::next() {
- if (!gs_active()) {
- return 1;
+ if (dsc) {
+ load_page(page + 1);
} else {
- fl_cursor(FL_CURSOR_WAIT);
-
- XEvent e;
- e.xclient.type = ClientMessage;
- e.xclient.display = fl_display;
- e.xclient.window = gs_win;
- e.xclient.message_type = atoms[2];
- e.xclient.format = 32;
-
- XSendEvent(fl_display, gs_win, false, 0, &e);
- XFlush(fl_display);
+ if (!gs_active()) {
+ return 1;
+ } else {
+ fl_cursor(FL_CURSOR_WAIT);
+
+ XEvent e;
+ e.xclient.type = ClientMessage;
+ e.xclient.display = fl_display;
+ e.xclient.window = gs_win;
+ e.xclient.message_type = atoms[2];
+ e.xclient.format = 32;
+
+ XSendEvent(fl_display, gs_win, false, 0, &e);
+ XFlush(fl_display);
+ }
}
return 0;
}
+int GsWidget::prev() {
+ if (dsc) {
+ load_page(page - 1);
+ return 0;
+ } else {
+ return 1;
+ }
+}
+
int GsWidget::handleX11(int ev) {
if (fl_xevent->type == ClientMessage) {
gs_win = fl_xevent->xclient.data.l[0];
- if(fl_xevent->xclient.message_type == atoms[3]) {
- page++; // PAGE revceived
+ if(fl_xevent->xclient.message_type == atoms[3]) { // PAGE received
damage(FL_DAMAGE_ALL);
fl_cursor(FL_CURSOR_DEFAULT);
+ if (dsc) {
+ kill_gs();
+ } else {
+ page++;
+ }
} else if(fl_xevent->xclient.message_type == atoms[4] ) {
- reload(); // go back to page 1
+ if (!dsc) {
+ reload(); // go back to page 1
+ }
}
return 1;
}
diff --git a/src/PostscriptDSC.H b/src/PostscriptDSC.H
index 6c5823f..503cb28 100644
--- a/src/PostscriptDSC.H
+++ b/src/PostscriptDSC.H
@@ -32,7 +32,7 @@ class PostscriptDSC {
public:
PostscriptDSC();
~PostscriptDSC();
-
+
int parse(int fd);
int get_pages();
void get_bounding_box(int *x, int *y, int *w, int *h);
diff --git a/src/PostscriptDSC.cxx b/src/PostscriptDSC.cxx
index bd47837..40b39c9 100644
--- a/src/PostscriptDSC.cxx
+++ b/src/PostscriptDSC.cxx
@@ -35,6 +35,9 @@ PostscriptDSC::PostscriptDSC() {
page_len = NULL;
}
+PostscriptDSC::~PostscriptDSC() {
+}
+
int
PostscriptDSC::parse(int fd) {
FILE *fp;
@@ -42,7 +45,7 @@ PostscriptDSC::parse(int fd) {
int x, y, w, h;
int p1, p2, ps;
int i = 0;
-
+
bb_x = 0;
bb_y = 0;
bb_w = 594; // A4
@@ -80,8 +83,8 @@ PostscriptDSC::parse(int fd) {
page_len = (size_t*) malloc(sizeof(size_t) * (pages + 1));
memset(page_len, 0, sizeof(size_t) * (pages + 1));
} else if (sscanf(linebuf, "%%%%Page: %d %d", &p1, &p2) == 2) {
- if (p2 > pages) {
- fprintf(stderr, "Page %d > Pages (%d)\n", p1, pages);
+ if (p1 > pages || p1 < 1) {
+ fprintf(stderr, "Page %d out of range (0 - %d)\n", p1, pages);
return 1;
}
if (page_off[p1] != NULL) {
@@ -99,6 +102,10 @@ PostscriptDSC::parse(int fd) {
}
}
}
+
+ page_len[p1] = ftello(fp) - page_off[p1];
+
+ return 0;
}
void
@@ -121,12 +128,12 @@ PostscriptDSC::get_setup_len() {
size_t
PostscriptDSC::get_page_off(int p) {
- return page_off[p];
+ return page_off[p+1];
}
size_t
PostscriptDSC::get_page_len(int p) {
- return page_len[p];
+ return page_len[p+1];
}
void
@@ -135,7 +142,7 @@ PostscriptDSC::print() {
printf("x %d, y %d, w %d, h %d\n", bb_x, bb_y, bb_w, bb_h);
printf("setup_len %d\n", setup_len);
- for (i=0; i<pages; i++) {
+ for (i=1; i<=pages; i++) {
printf("p %d, off %d, len %d\n", i, page_off[i], page_len[i]);
}
}
diff --git a/src/flpsed.cxx b/src/flpsed.cxx
index 596d1ac..deb2579 100644
--- a/src/flpsed.cxx
+++ b/src/flpsed.cxx
@@ -82,7 +82,7 @@ void open_cb() {
if(file != NULL) {
psed_p->open_file(file);
- psed_p->load_page(2);
+ psed_p->load();
}
}
@@ -164,7 +164,7 @@ void import_cb() {
}
void first_cb() {
- psed_p->reload();
+ psed_p->load();
}
void next_cb() {
@@ -528,9 +528,8 @@ int main(int argc, char** argv) {
win->show(1, argv);
if (in_fp) {
- sleep(1); // this seems to be necessary on fast systems to make the
- // GHOSTVIEW property available to ghostsscript.
psed_p->open_file(in_fp);
+ psed_p->load();
fclose(in_fp);
}