summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2007-07-17 18:56:42 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2007-07-17 18:56:42 +0200
commit3f0ff82397288f0216fdd367d778a7757cc9355c (patch)
treeb83145bf29da2b8fdf8eca4cdcf6f289a91abdff /src
parentc6a87e3c65772e729b01caefd7f849b7dcbd1855 (diff)
reindent using vim
Diffstat (limited to 'src')
-rw-r--r--src/GsWidget.H78
-rw-r--r--src/GsWidget.cxx658
-rw-r--r--src/PSEditModel.H61
-rw-r--r--src/PSEditModel.cxx390
-rw-r--r--src/PSEditText.H134
-rw-r--r--src/PSEditText.cxx144
-rw-r--r--src/PSEditWidget.H104
-rw-r--r--src/PSEditWidget.cxx482
-rw-r--r--src/PSEditor.H24
-rw-r--r--src/PSEditor.cxx298
-rw-r--r--src/Postscript.H70
-rw-r--r--src/Postscript.cxx606
-rw-r--r--src/PostscriptDSC.H36
-rw-r--r--src/PostscriptDSC.cxx304
-rw-r--r--src/flpsed.cxx56
-rw-r--r--src/util.c88
-rw-r--r--src/util.h4
17 files changed, 1768 insertions, 1769 deletions
diff --git a/src/GsWidget.H b/src/GsWidget.H
index aa3f2a8..95a3242 100644
--- a/src/GsWidget.H
+++ b/src/GsWidget.H
@@ -20,61 +20,61 @@
#include "PostscriptDSC.H"
class GsWidget : public Fl_Widget {
-private:
- PostscriptDSC *dsc;
- int gs_win;
- Atom atoms[5];
- pid_t gs_pid;
- int display_x, display_y;
- int in_fd, reload_needed;
- int zoom_percent;
- int initial_width, initial_height;
- int feeding;
+ private:
+ PostscriptDSC *dsc;
+ int gs_win;
+ Atom atoms[5];
+ pid_t gs_pid;
+ int display_x, display_y;
+ int in_fd, reload_needed;
+ int zoom_percent;
+ int initial_width, initial_height;
+ int feeding;
-protected:
- int page;
- Fl_Offscreen offscreen;
- int xdpi, ydpi;
- int paper_x, paper_y;
+ protected:
+ int page;
+ Fl_Offscreen offscreen;
+ int xdpi, ydpi;
+ int paper_x, paper_y;
- void draw();
+ void draw();
-public:
- GsWidget(int X,int Y,int W, int H);
-
- ~GsWidget();
-
- int open_file(char *f);
+ public:
+ GsWidget(int X,int Y,int W, int H);
- int open_file(int fd);
+ ~GsWidget();
- int load();
+ int open_file(char *f);
- int load_page(int p);
+ int open_file(int fd);
- int reload();
+ int load();
- int next();
+ int load_page(int p);
- int prev();
+ int reload();
- int handleX11(int ev);
+ int next();
- int zoom(int p);
+ int prev();
- int get_page();
+ int handleX11(int ev);
- int get_pages();
+ int zoom(int p);
-private:
- void setProps();
-
- void exec_gs();
+ int get_page();
- void kill_gs();
+ int get_pages();
- int fd_copy(int to, int from, size_t len);
+ private:
+ void setProps();
- bool gs_active();
+ void exec_gs();
+
+ void kill_gs();
+
+ int fd_copy(int to, int from, size_t len);
+
+ bool gs_active();
};
#endif
diff --git a/src/GsWidget.cxx b/src/GsWidget.cxx
index 5db8cae..71537e9 100644
--- a/src/GsWidget.cxx
+++ b/src/GsWidget.cxx
@@ -20,397 +20,397 @@
#define MIN(A,B) ((A)<(B)?(A):(B))
void GsWidget::draw() {
- if (!offscreen) {
- offscreen = fl_create_offscreen(w(), h());
- fl_begin_offscreen(offscreen);
- fl_color(FL_WHITE);
- fl_rectf(0, 0, w(), h());
- fl_end_offscreen();
-
- if (reload_needed) {
- reload();
- reload_needed = 0;
- }
- }
- fl_push_clip(x(), y(), w(), h());
- fl_copy_offscreen(x(), y(), w(), h(), offscreen, 0, 0);
- fl_pop_clip();
+ if (!offscreen) {
+ offscreen = fl_create_offscreen(w(), h());
+ fl_begin_offscreen(offscreen);
+ fl_color(FL_WHITE);
+ fl_rectf(0, 0, w(), h());
+ fl_end_offscreen();
+
+ if (reload_needed) {
+ reload();
+ reload_needed = 0;
+ }
+ }
+ fl_push_clip(x(), y(), w(), h());
+ fl_copy_offscreen(x(), y(), w(), h(), offscreen, 0, 0);
+ fl_pop_clip();
}
void GsWidget::setProps() {
- char data[512];
-
- if (!offscreen) {
- offscreen = fl_create_offscreen(w(), h());
- }
-
- atoms[0] = XInternAtom(fl_display,"GHOSTVIEW" , false);
- atoms[1] = XInternAtom(fl_display,"GHOSTVIEW_COLORS" , false);
- atoms[2] = XInternAtom(fl_display,"NEXT" , false);
- atoms[3] = XInternAtom(fl_display,"PAGE" , false);
- atoms[4] = XInternAtom(fl_display,"DONE" , false);
-
- snprintf(data, sizeof(data), "%d %d %d %d %d %d %d.0 %d.0",
- 0, 0, 0, 0, paper_x, paper_y, xdpi, ydpi);
-
- int xid = fl_xid(window());
-
- XChangeProperty(fl_display, xid, atoms[0],
- XA_STRING, 8, PropModeReplace,
- (unsigned char*) data, strlen(data));
-
- snprintf(data, sizeof(data), "%s %d %d", "Color",
- (int) BlackPixel(fl_display, DefaultScreen(fl_display)),
- (int) WhitePixel(fl_display, DefaultScreen(fl_display)));
-
- XChangeProperty(fl_display, xid, atoms[1],
- XA_STRING, 8, PropModeReplace,
- (unsigned char*) data, strlen(data));
-
- XSync(fl_display, False);
+ char data[512];
+
+ if (!offscreen) {
+ offscreen = fl_create_offscreen(w(), h());
+ }
+
+ atoms[0] = XInternAtom(fl_display,"GHOSTVIEW" , false);
+ atoms[1] = XInternAtom(fl_display,"GHOSTVIEW_COLORS" , false);
+ atoms[2] = XInternAtom(fl_display,"NEXT" , false);
+ atoms[3] = XInternAtom(fl_display,"PAGE" , false);
+ atoms[4] = XInternAtom(fl_display,"DONE" , false);
+
+ snprintf(data, sizeof(data), "%d %d %d %d %d %d %d.0 %d.0",
+ 0, 0, 0, 0, paper_x, paper_y, xdpi, ydpi);
+
+ int xid = fl_xid(window());
+
+ XChangeProperty(fl_display, xid, atoms[0],
+ XA_STRING, 8, PropModeReplace,
+ (unsigned char*) data, strlen(data));
+
+ snprintf(data, sizeof(data), "%s %d %d", "Color",
+ (int) BlackPixel(fl_display, DefaultScreen(fl_display)),
+ (int) WhitePixel(fl_display, DefaultScreen(fl_display)));
+
+ XChangeProperty(fl_display, xid, atoms[1],
+ XA_STRING, 8, PropModeReplace,
+ (unsigned char*) data, strlen(data));
+
+ XSync(fl_display, False);
}
void GsWidget::kill_gs() {
- int status;
+ int status;
- if (gs_pid > 0) {
- kill(gs_pid, SIGTERM);
- waitpid(gs_pid, &status, 0);
- gs_pid = 0;
- }
+ if (gs_pid > 0) {
+ kill(gs_pid, SIGTERM);
+ waitpid(gs_pid, &status, 0);
+ gs_pid = 0;
+ }
}
bool GsWidget::gs_active() {
- return gs_pid > 0 && gs_win;
+ return gs_pid > 0 && gs_win;
}
GsWidget::GsWidget(int X,int Y,int W, int H) : Fl_Widget(X, Y, W, H) {
- offscreen = 0;
- gs_pid = 0;
- page = 0;
- zoom_percent = 100;
- xdpi = 75 * zoom_percent / 100;
- ydpi = 75 * zoom_percent / 100;
- paper_x = 594; // DIN A4
- paper_y = 841; //
- initial_width = W;
- initial_height = H;
- in_fd = -1;
- reload_needed = 0;
- dsc = NULL;
- feeding = 0;
+ offscreen = 0;
+ gs_pid = 0;
+ page = 0;
+ zoom_percent = 100;
+ xdpi = 75 * zoom_percent / 100;
+ ydpi = 75 * zoom_percent / 100;
+ paper_x = 594; // DIN A4
+ paper_y = 841; //
+ initial_width = W;
+ initial_height = H;
+ in_fd = -1;
+ reload_needed = 0;
+ dsc = NULL;
+ feeding = 0;
}
-
+
GsWidget::~GsWidget() {
- kill_gs();
- if (offscreen) {
- fl_delete_offscreen(offscreen);
- }
+ kill_gs();
+ if (offscreen) {
+ fl_delete_offscreen(offscreen);
+ }
}
int GsWidget::open_file(char *f) {
- int fd = open(f, O_RDONLY);
- if (fd == -1) {
- perror("open");
- return 1;
- }
- return open_file(fd);
+ int fd = open(f, O_RDONLY);
+ if (fd == -1) {
+ perror("open");
+ return 1;
+ }
+ return open_file(fd);
}
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;
-
- 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;
+ 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;
+
+ 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;
}
int GsWidget::load() {
- pid_t pid;
-
- if (dsc) {
- return load_page(1);
- }
-
- if (in_fd < 0) {
- return 1;
- }
-
- lseek(in_fd, 0L, SEEK_SET);
-
- fl_cursor(FL_CURSOR_WAIT);
- kill_gs();
-
- if (!offscreen) {
- reload_needed = 1;
- return 0;
- }
-
- setProps();
-
- pid = fork();
- if (pid == (pid_t) 0) {
- dup2(in_fd, STDIN_FILENO);
- exec_gs();
- } else {
- gs_pid = pid;
- page = 0;
- }
-
- return 0;
+ pid_t pid;
+
+ if (dsc) {
+ return load_page(1);
+ }
+
+ if (in_fd < 0) {
+ return 1;
+ }
+
+ lseek(in_fd, 0L, SEEK_SET);
+
+ fl_cursor(FL_CURSOR_WAIT);
+ kill_gs();
+
+ if (!offscreen) {
+ reload_needed = 1;
+ return 0;
+ }
+
+ setProps();
+
+ pid = fork();
+ if (pid == (pid_t) 0) {
+ dup2(in_fd, STDIN_FILENO);
+ exec_gs();
+ } else {
+ gs_pid = pid;
+ page = 0;
+ }
+
+ return 0;
}
int
GsWidget::load_page(int p) {
- pid_t pid;
- int pdes[2];
-
- if (feeding || in_fd < 0) {
- return 1;
- }
-
- if (p < 1 || p > dsc->get_pages()) {
- fprintf(stderr, "Page %d not found in document\n", p);
- return 1;
- }
-
- fl_cursor(FL_CURSOR_WAIT);
- kill_gs();
-
- page = p;
-
- if (!offscreen) {
- reload_needed = 1;
- return 0;
- }
-
- if (pipe(pdes) < 0) {
- perror("pipe");
- return 1;
- }
-
- feeding = 1;
-
- lseek(in_fd, 0L, SEEK_SET);
- setProps();
-
- pid = fork();
- if (pid == (pid_t) 0) {
- close(in_fd);
- close(pdes[1]);
- dup2(pdes[0], STDIN_FILENO);
- exec_gs();
- } else {
- size_t len;
-
- gs_pid = pid;
-
- close(pdes[0]);
-
- lseek(in_fd, 0L, SEEK_SET);
- len = dsc->get_setup_len();
- if (fd_copy(pdes[1], in_fd, len) != 0) {
- close(pdes[1]);
- feeding = 0;
- return 1;
- }
-
- lseek(in_fd, dsc->get_page_off(p), SEEK_SET);
- len = dsc->get_page_len(p);
- if (fd_copy(pdes[1], in_fd, len) != 0) {
- close(pdes[1]);
- feeding = 0;
- return 1;
- }
-
- close(pdes[1]);
- }
-
- feeding = 0;
- return 0;
+ pid_t pid;
+ int pdes[2];
+
+ if (feeding || in_fd < 0) {
+ return 1;
+ }
+
+ if (p < 1 || p > dsc->get_pages()) {
+ fprintf(stderr, "Page %d not found in document\n", p);
+ return 1;
+ }
+
+ fl_cursor(FL_CURSOR_WAIT);
+ kill_gs();
+
+ page = p;
+
+ if (!offscreen) {
+ reload_needed = 1;
+ return 0;
+ }
+
+ if (pipe(pdes) < 0) {
+ perror("pipe");
+ return 1;
+ }
+
+ feeding = 1;
+
+ lseek(in_fd, 0L, SEEK_SET);
+ setProps();
+
+ pid = fork();
+ if (pid == (pid_t) 0) {
+ close(in_fd);
+ close(pdes[1]);
+ dup2(pdes[0], STDIN_FILENO);
+ exec_gs();
+ } else {
+ size_t len;
+
+ gs_pid = pid;
+
+ close(pdes[0]);
+
+ lseek(in_fd, 0L, SEEK_SET);
+ len = dsc->get_setup_len();
+ if (fd_copy(pdes[1], in_fd, len) != 0) {
+ close(pdes[1]);
+ feeding = 0;
+ return 1;
+ }
+
+ lseek(in_fd, dsc->get_page_off(p), SEEK_SET);
+ len = dsc->get_page_len(p);
+ if (fd_copy(pdes[1], in_fd, len) != 0) {
+ close(pdes[1]);
+ feeding = 0;
+ return 1;
+ }
+
+ close(pdes[1]);
+ }
+
+ feeding = 0;
+ return 0;
}
int GsWidget::fd_copy(int to, int from, size_t len) {
- size_t n, r;
- char buf[1024];
- int ret = 0;
+ size_t n, r;
+ char buf[1024];
+ int ret = 0;
- signal(SIGPIPE, SIG_IGN); // don't die if gs has a problem
+ signal(SIGPIPE, SIG_IGN); // don't die if gs has a problem
- n = 0;
- while(len > 0) {
+ n = 0;
+ while(len > 0) {
- Fl::check(); // let fltk do its stuff
+ Fl::check(); // let fltk do its stuff
- r = read(from, buf, MIN(sizeof(buf), len));
+ r = read(from, buf, MIN(sizeof(buf), len));
- if (r < 0) {
- perror("read");
- ret = 1;
- break;
- }
+ if (r < 0) {
+ perror("read");
+ ret = 1;
+ break;
+ }
- write(to, buf, r);
- len -= r;
- }
+ write(to, buf, r);
+ len -= r;
+ }
- signal(SIGPIPE, SIG_DFL);
+ signal(SIGPIPE, SIG_DFL);
- return ret;
+ return ret;
}
void GsWidget::exec_gs() {
- char *argv[16];
- char gvenv[256];
- int d_null = open("/dev/null", O_WRONLY);
-
- dup2(d_null, STDOUT_FILENO);
-
- snprintf(gvenv, sizeof(gvenv), "GHOSTVIEW=%d %d",
- (int) fl_xid(window()), (int) offscreen);
-
- putenv(gvenv);
- argv[0] = "gs";
- argv[1] = "-dSAFER";
- argv[2] = "-dQUIET";
- argv[3] = "-sDEVICE=x11alpha";
- argv[4] = "-dNOPLATFONTS";
- argv[5] = "-dNOPAUSE";
- argv[6] = "-";
- argv[7] = NULL;
- execvp(argv[0], argv);
- perror("exec");
- fprintf(stderr, "Please install ghostscript and make sure 'gs' "
- "is in the PATH.\n");
- exit(1);
+ char *argv[16];
+ char gvenv[256];
+ int d_null = open("/dev/null", O_WRONLY);
+
+ dup2(d_null, STDOUT_FILENO);
+
+ snprintf(gvenv, sizeof(gvenv), "GHOSTVIEW=%d %d",
+ (int) fl_xid(window()), (int) offscreen);
+
+ putenv(gvenv);
+ argv[0] = "gs";
+ argv[1] = "-dSAFER";
+ argv[2] = "-dQUIET";
+ argv[3] = "-sDEVICE=x11alpha";
+ argv[4] = "-dNOPLATFONTS";
+ argv[5] = "-dNOPAUSE";
+ argv[6] = "-";
+ argv[7] = NULL;
+ execvp(argv[0], argv);
+ perror("exec");
+ fprintf(stderr, "Please install ghostscript and make sure 'gs' "
+ "is in the PATH.\n");
+ exit(1);
}
int GsWidget::reload() {
- if (in_fd >= 0) {
- if (dsc) {
- load_page(page);
- } else {
- load();
- }
- return 0;
- } else {
- return 1;
- }
+ if (in_fd >= 0) {
+ if (dsc) {
+ load_page(page);
+ } else {
+ load();
+ }
+ return 0;
+ } else {
+ return 1;
+ }
}
-
+
int GsWidget::next() {
- if (dsc) {
- load_page(page + 1);
- } else {
- 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;
+ if (dsc) {
+ load_page(page + 1);
+ } else {
+ 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;
- }
+ 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 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] ) {
- if (!dsc) {
- reload(); // go back to page 1
- }
- }
- return 1;
- }
- return 0;
+ if (fl_xevent->type == ClientMessage) {
+ gs_win = fl_xevent->xclient.data.l[0];
+
+ 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] ) {
+ if (!dsc) {
+ reload(); // go back to page 1
+ }
+ }
+ return 1;
+ }
+ return 0;
}
int GsWidget::get_page() {
- return page;
+ return page;
}
int GsWidget::zoom(int p) {
- zoom_percent = p;
-
- kill_gs();
-
- if (offscreen) {
- // Clear widget with current size
- fl_begin_offscreen(offscreen);
- fl_color(FL_WHITE);
- fl_rectf(0, 0, w(), h());
- fl_end_offscreen();
- redraw();
-
- fl_delete_offscreen(offscreen);
- offscreen = 0;
- }
-
- w(initial_width * zoom_percent / 100);
- h(initial_height * zoom_percent / 100);
-
- xdpi = 75 * zoom_percent / 100;
- ydpi = 75 * zoom_percent / 100;
- reload();
-
- return 0;
+ zoom_percent = p;
+
+ kill_gs();
+
+ if (offscreen) {
+ // Clear widget with current size
+ fl_begin_offscreen(offscreen);
+ fl_color(FL_WHITE);
+ fl_rectf(0, 0, w(), h());
+ fl_end_offscreen();
+ redraw();
+
+ fl_delete_offscreen(offscreen);
+ offscreen = 0;
+ }
+
+ w(initial_width * zoom_percent / 100);
+ h(initial_height * zoom_percent / 100);
+
+ xdpi = 75 * zoom_percent / 100;
+ ydpi = 75 * zoom_percent / 100;
+ reload();
+
+ return 0;
}
int
GsWidget::get_pages() {
- if (dsc) {
- return dsc->get_pages();
- } else {
- return 0;
- }
+ if (dsc) {
+ return dsc->get_pages();
+ } else {
+ return 0;
+ }
}
diff --git a/src/PSEditModel.H b/src/PSEditModel.H
index 18ea91d..a228793 100644
--- a/src/PSEditModel.H
+++ b/src/PSEditModel.H
@@ -11,64 +11,65 @@
class PSEditModel {
- PSEditText **text;
+ PSEditText **text;
- int max_pages;
+ int max_pages;
- int page;
+ int page;
- PSEditText *cur_text;
+ PSEditText *cur_text;
-public:
- PSEditModel();
+ public:
+ PSEditModel();
- ~PSEditModel();
+ ~PSEditModel();
- void clear();
+ void clear();
- void new_text(int x1, int y1, const char *s, int size, int p, PSEditColor *c);
+ void new_text(int x1, int y1,
+ const char *s, int size, int p, PSEditColor *c);
- void append_text(const char *s);
+ void append_text(const char *s);
- void move(int x1, int y1);
+ void move(int x1, int y1);
- void rm_char();
+ void rm_char();
- void set_size(int s);
+ void set_size(int s);
- int get_size();
+ int get_size();
- void set_color(PSEditColor *c);
+ void set_color(PSEditColor *c);
- int get_color(PSEditColor *c);
+ int get_color(PSEditColor *c);
- void set_page(int p);
+ void set_page(int p);
- int get_page();
+ int get_page();
- char *get_tag();
+ char *get_tag();
- int set_tag(const char *t);
+ int set_tag(const char *t);
- int get_max_pages();
+ int get_max_pages();
- int set_cur_text(int x1, int y1, int p);
+ int set_cur_text(int x1, int y1, int p);
- int next_text(int p);
+ int next_text(int p);
- int is_cur_text(PSEditText *t);
+ int is_cur_text(PSEditText *t);
- PSEditText *get_text(int p);
+ PSEditText *get_text(int p);
- PSEditText *get_cur_text();
+ PSEditText *get_cur_text();
- int replace_tag(char* tag, char* text);
+ int replace_tag(char* tag, char* text);
- int dump_tags();
+ int dump_tags();
- int load(FILE *fp);
+ int load(FILE *fp);
- int save(FILE *sfp, int tmp_fd);
+ int save(FILE *sfp, int tmp_fd);
};
#endif
diff --git a/src/PSEditModel.cxx b/src/PSEditModel.cxx
index 605c0dc..6b4de41 100644
--- a/src/PSEditModel.cxx
+++ b/src/PSEditModel.cxx
@@ -16,281 +16,281 @@
PSEditModel::PSEditModel() {
- max_pages = 32;
- page = 0;
- text = (PSEditText**) malloc(sizeof(PSEditText*) * max_pages);
- if (!text) {
- perror("malloc");
- exit(1);
- }
- for (int i = 0; i < max_pages; i++) {
- text[i] = NULL;
- }
-
- cur_text = NULL;
+ max_pages = 32;
+ page = 0;
+ text = (PSEditText**) malloc(sizeof(PSEditText*) * max_pages);
+ if (!text) {
+ perror("malloc");
+ exit(1);
+ }
+ for (int i = 0; i < max_pages; i++) {
+ text[i] = NULL;
+ }
+
+ cur_text = NULL;
}
void PSEditModel::set_page(int p) {
- int old_max_pages;
+ int old_max_pages;
- if (p >= max_pages) {
- old_max_pages = max_pages;
+ if (p >= max_pages) {
+ old_max_pages = max_pages;
- max_pages = p + max_pages;
- text = (PSEditText**) realloc(text, sizeof(PSEditText*) * max_pages);
- if (!text) {
- perror("realloc");
- exit(1);
- }
+ max_pages = p + max_pages;
+ text = (PSEditText**) realloc(text, sizeof(PSEditText*) * max_pages);
+ if (!text) {
+ perror("realloc");
+ exit(1);
+ }
- for (int i = old_max_pages; i < max_pages; i++) {
- text[i] = NULL;
- }
- }
+ for (int i = old_max_pages; i < max_pages; i++) {
+ text[i] = NULL;
+ }
+ }
- page = p;
- cur_text = NULL;
+ page = p;
+ cur_text = NULL;
}
void PSEditModel::clear() {
- cur_text = NULL;
- for (int i = 0; i < max_pages; i++) {
- if (text[i]) {
- delete(text[i]);
- text[i] = NULL;
- }
- }
+ cur_text = NULL;
+ for (int i = 0; i < max_pages; i++) {
+ if (text[i]) {
+ delete(text[i]);
+ text[i] = NULL;
+ }
+ }
}
void PSEditModel::new_text(int x1, int y1, const char *s,
- int size, int p, PSEditColor *c) {
- set_page(p);
-
- cur_text = new PSEditText(x1, y1, s, size, c);
- if (text[p]) {
- text[p]->append(cur_text);
- } else {
- text[p] = cur_text;
- }
+ int size, int p, PSEditColor *c) {
+ set_page(p);
+
+ cur_text = new PSEditText(x1, y1, s, size, c);
+ if (text[p]) {
+ text[p]->append(cur_text);
+ } else {
+ text[p] = cur_text;
+ }
}
int PSEditModel::set_cur_text(int x1, int y1, int p) {
- PSEditText *t;
-
- if (p < 0 || p >= max_pages) {
- return 1;
- }
-
- if (text[p]) {
- t = text[p]->get_match(x1, y1);
- if (t) {
- cur_text = t;
- return 0;
- }
- }
- return 1;
+ PSEditText *t;
+
+ if (p < 0 || p >= max_pages) {
+ return 1;
+ }
+
+ if (text[p]) {
+ t = text[p]->get_match(x1, y1);
+ if (t) {
+ cur_text = t;
+ return 0;
+ }
+ }
+ return 1;
}
int PSEditModel::next_text(int p) {
- if (p < 0 || p >= max_pages) {
- return 1;
- }
-
- if (cur_text) {
- cur_text = cur_text->get_next();
- }
-
- if (cur_text) {
- return 0;
- } else if (text[p]) {
- cur_text = text[p];
- return 0;
- } else {
- return 1;
- }
+ if (p < 0 || p >= max_pages) {
+ return 1;
+ }
+
+ if (cur_text) {
+ cur_text = cur_text->get_next();
+ }
+
+ if (cur_text) {
+ return 0;
+ } else if (text[p]) {
+ cur_text = text[p];
+ return 0;
+ } else {
+ return 1;
+ }
}
int PSEditModel::is_cur_text(PSEditText *t) {
- return (t && t == cur_text);
+ return (t && t == cur_text);
}
PSEditText *PSEditModel::get_cur_text() {
- return cur_text;
+ return cur_text;
}
void PSEditModel::append_text(const char *s) {
- if (cur_text && s) {
- cur_text->append_text(s);
- }
+ if (cur_text && s) {
+ cur_text->append_text(s);
+ }
}
void PSEditModel::move(int x1, int y1) {
- if (cur_text) {
- cur_text->move(x1, y1);
- }
+ if (cur_text) {
+ cur_text->move(x1, y1);
+ }
}
void PSEditModel::rm_char() {
- if (cur_text) {
- cur_text->rm_char();
- }
+ if (cur_text) {
+ cur_text->rm_char();
+ }
}
void PSEditModel::set_size(int s) {
- if (cur_text) {
- cur_text->size = s;
- }
+ if (cur_text) {
+ cur_text->size = s;
+ }
}
int PSEditModel::get_size() {
- if (cur_text) {
- return cur_text->size;
- } else {
- return -1;
- }
+ if (cur_text) {
+ return cur_text->size;
+ } else {
+ return -1;
+ }
}
void PSEditModel::set_color(PSEditColor *c) {
- if (cur_text) {
- cur_text->text_color.set(c->r, c->g, c->b);
- }
+ if (cur_text) {
+ cur_text->text_color.set(c->r, c->g, c->b);
+ }
}
int PSEditModel::get_color(PSEditColor *c) {
- if (cur_text) {
- c->set(cur_text->text_color.r,
- cur_text->text_color.g,
- cur_text->text_color.b);
- return 0;
- } else {
- return -1;
- }
+ if (cur_text) {
+ c->set(cur_text->text_color.r,
+ cur_text->text_color.g,
+ cur_text->text_color.b);
+ return 0;
+ } else {
+ return -1;
+ }
}
int PSEditModel::get_max_pages() {
- return max_pages;
+ return max_pages;
}
int PSEditModel::set_tag(const char *t) {
- if (cur_text) {
- return cur_text->set_tag(t);
- } else {
- return 1;
- }
+ if (cur_text) {
+ return cur_text->set_tag(t);
+ } else {
+ return 1;
+ }
}
char *PSEditModel::get_tag() {
- if (cur_text) {
- return cur_text->get_tag();
- } else {
- return NULL;
- }
+ if (cur_text) {
+ return cur_text->get_tag();
+ } else {
+ return NULL;
+ }
}
int PSEditModel::replace_tag(char *tag, char *txt) {
- PSEditText *t;
- int p, ret = 0;
-
- for (p = 0; p < max_pages; p++) {
- t = get_text(p);
- while (t) {
- if (t->get_tag() && strcmp(t->get_tag(), tag) == 0) {
- t->set_text(txt);
- ret++;
- }
- t = t->get_next();
- }
- }
-
- return ret;
+ PSEditText *t;
+ int p, ret = 0;
+
+ for (p = 0; p < max_pages; p++) {
+ t = get_text(p);
+ while (t) {
+ if (t->get_tag() && strcmp(t->get_tag(), tag) == 0) {
+ t->set_text(txt);
+ ret++;
+ }
+ t = t->get_next();
+ }
+ }
+
+ return ret;
}
int PSEditModel::dump_tags() {
- PSEditText *t;
- int p, ret = 0;
-
- for (p = 0; p < max_pages; p++) {
- t = get_text(p);
- while (t) {
- if (t->get_tag()) {
- printf("%s=%s\n", t->get_tag(), t->get_text());
- ret++;
- }
- t = t->get_next();
- }
- }
-
- return ret;
+ PSEditText *t;
+ int p, ret = 0;
+
+ for (p = 0; p < max_pages; p++) {
+ t = get_text(p);
+ while (t) {
+ if (t->get_tag()) {
+ printf("%s=%s\n", t->get_tag(), t->get_text());
+ ret++;
+ }
+ t = t->get_next();
+ }
+ }
+
+ return ret;
}
PSEditText *PSEditModel::get_text(int p) {
- if (p >= max_pages) {
- return 0;
- } else {
- return text[p];
- }
+ if (p >= max_pages) {
+ return 0;
+ } else {
+ return text[p];
+ }
}
int PSEditModel::load(FILE *fp) {
- char tmpname[256];
- char linebuf[1024];
- ssize_t ret;
- PSParser *p2 = new PSParser_2(this);
- int tmp_fd;
-
- strncpy(tmpname, "/tmp/PSEditorXXXXXX", sizeof(tmpname));
- tmp_fd = mkstemp(tmpname);
- if (tmp_fd < 0) {
- fprintf(stderr, "Could not create temporary file (errno %d).\n", errno);
- return -1;
- }
- unlink(tmpname);
-
- clear();
-
- while (fgets(linebuf, sizeof(linebuf), fp) != NULL) {
- if (!p2->parse(linebuf)) {
- ret = write(tmp_fd, linebuf, strlen(linebuf));
- if (ret != strlen(linebuf)) {
- fprintf(stderr, "Error while writing to temporary file\n");
- }
- }
- }
-
- lseek(tmp_fd, 0L, SEEK_SET);
-
- delete(p2);
-
- return tmp_fd;
+ char tmpname[256];
+ char linebuf[1024];
+ ssize_t ret;
+ PSParser *p2 = new PSParser_2(this);
+ int tmp_fd;
+
+ strncpy(tmpname, "/tmp/PSEditorXXXXXX", sizeof(tmpname));
+ tmp_fd = mkstemp(tmpname);
+ if (tmp_fd < 0) {
+ fprintf(stderr, "Could not create temporary file (errno %d).\n", errno);
+ return -1;
+ }
+ unlink(tmpname);
+
+ clear();
+
+ while (fgets(linebuf, sizeof(linebuf), fp) != NULL) {
+ if (!p2->parse(linebuf)) {
+ ret = write(tmp_fd, linebuf, strlen(linebuf));
+ if (ret != strlen(linebuf)) {
+ fprintf(stderr, "Error while writing to temporary file\n");
+ }
+ }
+ }
+
+ lseek(tmp_fd, 0L, SEEK_SET);
+
+ delete(p2);
+
+ return tmp_fd;
}
int PSEditModel::save(FILE *sfp, int tmp_fd) {
- off_t pos = lseek(tmp_fd, 0, SEEK_CUR); // save current position
+ off_t pos = lseek(tmp_fd, 0, SEEK_CUR); // save current position
- if (pos == -1) {
- perror("lseek");
- return 1;
- }
+ if (pos == -1) {
+ perror("lseek");
+ return 1;
+ }
- FILE *fp = fdopen(tmp_fd, "r");
+ FILE *fp = fdopen(tmp_fd, "r");
- rewind(fp);
+ rewind(fp);
- PSWriter *pw;
-
- pw = new PSLevel1Writer(this);
-
- pw->write(fp, sfp);
+ PSWriter *pw;
- delete(pw);
-
- lseek(tmp_fd, pos, SEEK_SET); // restore current position
+ pw = new PSLevel1Writer(this);
- return 0;
+ pw->write(fp, sfp);
+
+ delete(pw);
+
+ lseek(tmp_fd, pos, SEEK_SET); // restore current position
+
+ return 0;
}
diff --git a/src/PSEditText.H b/src/PSEditText.H
index d12a878..a62ace6 100644
--- a/src/PSEditText.H
+++ b/src/PSEditText.H
@@ -10,48 +10,48 @@
#include <math.h>
class PSEditColor {
- public:
- double r, g, b;
-
- PSEditColor() {
- r = 0.0;
- g = 0.0;
- b = 0.0;
- }
-
- PSEditColor(double r1, double g1, double b1) {
- set(r1, g1, b1);
- }
-
- void set(unsigned char r1, unsigned char g1, unsigned char b1) {
- r = r1 / 256.0;
- g = g1 / 256.0;
- b = b1 / 256.0;
- }
-
- void set(double r1, double g1, double b1) {
- r = r1;
- g = g1;
- b = b1;
- }
-
- void set(const PSEditColor *c) {
- r = c->r;
- g = c->g;
- b = c->b;
- }
-
- unsigned char get_r() {
- return (unsigned char) rint(r * 256.0);
- }
-
- unsigned char get_g() {
- return (unsigned char) rint(g * 256.0);
- }
-
- unsigned char get_b() {
- return (unsigned char) rint(b * 256.0);
- }
+ public:
+ double r, g, b;
+
+ PSEditColor() {
+ r = 0.0;
+ g = 0.0;
+ b = 0.0;
+ }
+
+ PSEditColor(double r1, double g1, double b1) {
+ set(r1, g1, b1);
+ }
+
+ void set(unsigned char r1, unsigned char g1, unsigned char b1) {
+ r = r1 / 256.0;
+ g = g1 / 256.0;
+ b = b1 / 256.0;
+ }
+
+ void set(double r1, double g1, double b1) {
+ r = r1;
+ g = g1;
+ b = b1;
+ }
+
+ void set(const PSEditColor *c) {
+ r = c->r;
+ g = c->g;
+ b = c->b;
+ }
+
+ unsigned char get_r() {
+ return (unsigned char) rint(r * 256.0);
+ }
+
+ unsigned char get_g() {
+ return (unsigned char) rint(g * 256.0);
+ }
+
+ unsigned char get_b() {
+ return (unsigned char) rint(b * 256.0);
+ }
};
@@ -59,51 +59,51 @@ class PSEditColor {
class PSEditText;
class PSEditText {
- int x, y;
+ int x, y;
- char *s;
+ char *s;
- char *tag;
+ char *tag;
- PSEditText *next;
-
-public:
+ PSEditText *next;
- PSEditColor text_color;
+ public:
- int size;
-
- PSEditText(int x1, int y1, const char *s1, int size1, PSEditColor *c);
+ PSEditColor text_color;
- ~PSEditText();
+ int size;
- void append_text(const char*s1);
+ PSEditText(int x1, int y1, const char *s1, int size1, PSEditColor *c);
- void rm_char();
+ ~PSEditText();
- void move(int x1, int y1);
+ void append_text(const char*s1);
- void append(PSEditText *g);
+ void rm_char();
- PSEditText *get_match(int x1, int y1);
+ void move(int x1, int y1);
- int set_text(const char *t);
+ void append(PSEditText *g);
- char *get_text();
+ PSEditText *get_match(int x1, int y1);
- int is_empty();
+ int set_text(const char *t);
- char *get_tag();
+ char *get_text();
- int set_tag(const char *t);
+ int is_empty();
- int get_size();
+ char *get_tag();
- PSEditText *get_next();
+ int set_tag(const char *t);
- int get_x();
+ int get_size();
- int get_y();
+ PSEditText *get_next();
+
+ int get_x();
+
+ int get_y();
};
#endif
diff --git a/src/PSEditText.cxx b/src/PSEditText.cxx
index 510c2a9..c210106 100644
--- a/src/PSEditText.cxx
+++ b/src/PSEditText.cxx
@@ -14,121 +14,121 @@
PSEditText::PSEditText(int x1, int y1, const char *s1,
- int size1, PSEditColor *c) {
- x = x1;
- y = y1;
- s = strdup(s1);
- tag = NULL;
- size = size1;
- text_color.set(c->r, c->g, c->b);
- next = NULL;
+ int size1, PSEditColor *c) {
+ x = x1;
+ y = y1;
+ s = strdup(s1);
+ tag = NULL;
+ size = size1;
+ text_color.set(c->r, c->g, c->b);
+ next = NULL;
}
PSEditText::~PSEditText() {
- if (next) {
- delete(next);
- }
- if (s) {
- free(s);
- }
- if (tag) {
- free(tag);
- }
-}
-
+ if (next) {
+ delete(next);
+ }
+ if (s) {
+ free(s);
+ }
+ if (tag) {
+ free(tag);
+ }
+}
+
void PSEditText::append_text(const char*s1) {
- int len = (s?strlen(s):0) + strlen(s1) + 1;
- char *tmp = (char*) malloc(len);
-
- strncpy(tmp, s?s:"", len);
- strncat(tmp, s1, len - strlen(tmp));
-
- if (s) {
- free(s);
- }
-
- s = tmp;
+ int len = (s?strlen(s):0) + strlen(s1) + 1;
+ char *tmp = (char*) malloc(len);
+
+ strncpy(tmp, s?s:"", len);
+ strncat(tmp, s1, len - strlen(tmp));
+
+ if (s) {
+ free(s);
+ }
+
+ s = tmp;
}
void PSEditText::rm_char() {
- if (s && strlen(s) > 0) {
- s[strlen(s) - 1] = '\0';
- }
+ if (s && strlen(s) > 0) {
+ s[strlen(s) - 1] = '\0';
+ }
}
void PSEditText::move(int x1, int y1) {
- x = x1;
- y = y1;
+ x = x1;
+ y = y1;
}
void PSEditText::append(PSEditText *g) {
- PSEditText *p = this;
- while (p->next) {
- p = p->next;
- }
- p->next = g;
+ PSEditText *p = this;
+ while (p->next) {
+ p = p->next;
+ }
+ p->next = g;
}
PSEditText *PSEditText::get_match(int x1, int y1) {
- if (abs(x - x1) < 10 && abs(y - y1) < 10) {
- return this;
- } else if (next) {
- return next->get_match(x1, y1);
- } else {
- return NULL;
- }
+ if (abs(x - x1) < 10 && abs(y - y1) < 10) {
+ return this;
+ } else if (next) {
+ return next->get_match(x1, y1);
+ } else {
+ return NULL;
+ }
}
int PSEditText::set_text(const char *t) {
- if (s) {
- free(s);
- }
- if (t) {
- s = strdup(t);
- } else {
- s = NULL;
- }
+ if (s) {
+ free(s);
+ }
+ if (t) {
+ s = strdup(t);
+ } else {
+ s = NULL;
+ }
- return 0;
+ return 0;
}
char *PSEditText::get_text() {
- return s;
+ return s;
}
int PSEditText::is_empty() {
- return !s || !s[0];
+ return !s || !s[0];
}
char *PSEditText::get_tag() {
- return tag;
+ return tag;
}
int PSEditText::set_tag(const char *t) {
- if (tag) {
- free(tag);
- }
- if (t) {
- tag = strdup(t);
- } else {
- tag = NULL;
- }
+ if (tag) {
+ free(tag);
+ }
+ if (t) {
+ tag = strdup(t);
+ } else {
+ tag = NULL;
+ }
- return 0;
+ return 0;
}
int PSEditText::get_size() {
- return size;
+ return size;
}
PSEditText* PSEditText::get_next() {
- return next;
+ return next;
}
int PSEditText::get_x() {
- return x;
+ return x;
}
int PSEditText::get_y() {
- return y;
+ return y;
}
diff --git a/src/PSEditWidget.H b/src/PSEditWidget.H
index 1bff9e5..e3c4886 100644
--- a/src/PSEditWidget.H
+++ b/src/PSEditWidget.H
@@ -15,98 +15,98 @@ typedef void (PSEditCallback)();
class PSText;
class PSEditWidget : public GsWidget {
-private:
- int cur_size;
+ private:
+ int cur_size;
- PSEditColor cur_text_color;
+ PSEditColor cur_text_color;
- int show_tags;
+ int show_tags;
- int zoom_percent;
+ int zoom_percent;
- PSEditCallback *property_changed_cb;
+ PSEditCallback *property_changed_cb;
-protected:
- PSEditModel *model;
+ protected:
+ PSEditModel *model;
- int loaded;
+ int loaded;
- int mod;
+ int mod;
- void clear_text();
+ void clear_text();
- void draw();
+ void draw();
-public:
- PSEditWidget(int X,int Y,int W, int H);
+ public:
+ PSEditWidget(int X,int Y,int W, int H);
- int next();
+ int next();
- void new_text(int x1, int y1, const char *s, int p);
+ void new_text(int x1, int y1, const char *s, int p);
- void new_text(int x1, int y1, const char *s);
+ void new_text(int x1, int y1, const char *s);
- int set_cur_text(int x1, int y1);
-
- int next_text();
-
- void append_text(const char *s);
+ int set_cur_text(int x1, int y1);
- void move(int x1, int y1);
+ int next_text();
- void rel_move(int dx, int dy);
+ void append_text(const char *s);
- void rm_char();
+ void move(int x1, int y1);
- int reload();
+ void rel_move(int dx, int dy);
- void set_size(int s);
+ void rm_char();
- int get_size();
+ int reload();
- void set_color(const PSEditColor *c);
+ void set_size(int s);
- void get_color(PSEditColor *c);
+ int get_size();
- int get_max_pages();
+ void set_color(const PSEditColor *c);
- char *get_tag();
+ void get_color(PSEditColor *c);
- int set_tag(const char *t);
+ int get_max_pages();
- int get_show_tags();
+ char *get_tag();
- void set_show_tags(int s);
+ int set_tag(const char *t);
- PSText * get_text(int p);
+ int get_show_tags();
- int modified();
+ void set_show_tags(int s);
- int file_loaded();
+ PSText * get_text(int p);
- int replace_tag(char* tag, char* text);
+ int modified();
- int zoom(int p);
+ int file_loaded();
- void property_changed_callback(PSEditCallback *cb) {
- property_changed_cb = cb;};
+ int replace_tag(char* tag, char* text);
- private:
- int bb_x(PSEditText *t);
+ int zoom(int p);
- int bb_y(PSEditText *t);
+ void property_changed_callback(PSEditCallback *cb) {
+ property_changed_cb = cb;};
- int bb_w(PSEditText *t);
-
- int bb_h(PSEditText *t);
+ private:
+ int bb_x(PSEditText *t);
- int ps_to_display_x(int x1);
+ int bb_y(PSEditText *t);
- int ps_to_display_y(int y1);
+ int bb_w(PSEditText *t);
- int ps_x(int x1);
+ int bb_h(PSEditText *t);
- int ps_y(int y1);
+ int ps_to_display_x(int x1);
+
+ int ps_to_display_y(int y1);
+
+ int ps_x(int x1);
+
+ int ps_y(int y1);
};
#endif
diff --git a/src/PSEditWidget.cxx b/src/PSEditWidget.cxx
index a72a6f5..6b2a472 100644
--- a/src/PSEditWidget.cxx
+++ b/src/PSEditWidget.cxx
@@ -26,390 +26,390 @@
void PSEditWidget::clear_text() {
- model->clear();
+ model->clear();
}
void PSEditWidget::draw() {
- GsWidget::draw();
- PSEditText *t = model->get_text(page);
- int t_x, t_y;
-
- while (t) {
- t_x = ps_to_display_x(t->get_x());
- t_y = ps_to_display_y(t->get_y());
-
- fl_color(fl_rgb_color(t->text_color.get_r(),
- t->text_color.get_g(),
- t->text_color.get_b()));
-
-
- fl_font(FLPSED_FONT, t->get_size() * zoom_percent / 100);
- fl_draw(t->get_text(), t_x + x(), t_y + y());
- if (model->is_cur_text(t)) {
- fl_draw_box(FL_BORDER_FRAME,
- t_x + x()-1,
- t_y + y()-fl_height()+fl_descent(),
- (int) fl_width(t->get_text())+2,
- fl_height(),
- FL_BLACK);
- }
-
- if (t->get_tag() && show_tags) {
- int text_height = fl_height() - fl_descent();
- fl_color(FL_BLUE);
- fl_font(FLPSED_TAG_FONT, FLPSED_TAG_FONT_SIZE * zoom_percent / 100);
- fl_draw(t->get_tag(), t_x + x(),
- t_y + y() - text_height - 1);
- }
-
- t = t->get_next();
- }
+ GsWidget::draw();
+ PSEditText *t = model->get_text(page);
+ int t_x, t_y;
+
+ while (t) {
+ t_x = ps_to_display_x(t->get_x());
+ t_y = ps_to_display_y(t->get_y());
+
+ fl_color(fl_rgb_color(t->text_color.get_r(),
+ t->text_color.get_g(),
+ t->text_color.get_b()));
+
+
+ fl_font(FLPSED_FONT, t->get_size() * zoom_percent / 100);
+ fl_draw(t->get_text(), t_x + x(), t_y + y());
+ if (model->is_cur_text(t)) {
+ fl_draw_box(FL_BORDER_FRAME,
+ t_x + x()-1,
+ t_y + y()-fl_height()+fl_descent(),
+ (int) fl_width(t->get_text())+2,
+ fl_height(),
+ FL_BLACK);
+ }
+
+ if (t->get_tag() && show_tags) {
+ int text_height = fl_height() - fl_descent();
+ fl_color(FL_BLUE);
+ fl_font(FLPSED_TAG_FONT, FLPSED_TAG_FONT_SIZE * zoom_percent / 100);
+ fl_draw(t->get_tag(), t_x + x(),
+ t_y + y() - text_height - 1);
+ }
+
+ t = t->get_next();
+ }
}
PSEditWidget::PSEditWidget(int X,int Y,int W, int H): GsWidget(X, Y, W, H) {
- model = new PSEditModel();
- cur_size = 12;
- cur_text_color.set(0.0, 0.0, 0.0);
- show_tags = 1;
- zoom_percent = 100;
- property_changed_cb = NULL;
-}
-
+ model = new PSEditModel();
+ cur_size = 12;
+ cur_text_color.set(0.0, 0.0, 0.0);
+ show_tags = 1;
+ zoom_percent = 100;
+ property_changed_cb = NULL;
+}
+
int PSEditWidget::next() {
- model->set_page(page);
- PSEditText *t_new;
+ model->set_page(page);
+ PSEditText *t_new;
- t_new = model->get_cur_text();
+ t_new = model->get_cur_text();
- if (t_new) {
- cur_text_color.set(&t_new->text_color);
- cur_size = t_new->size;
+ if (t_new) {
+ cur_text_color.set(&t_new->text_color);
+ cur_size = t_new->size;
- if (property_changed_cb) {
- property_changed_cb();
- }
- }
+ if (property_changed_cb) {
+ property_changed_cb();
+ }
+ }
- return GsWidget::next();
+ return GsWidget::next();
}
void PSEditWidget::new_text(int x1, int y1, const char *s, int p) {
- PSEditText *t_old, *t;
-
- t_old = model->get_cur_text();
+ PSEditText *t_old, *t;
+
+ t_old = model->get_cur_text();
+
+ model->new_text(ps_x(x1), ps_y(y1), s, cur_size, p, &cur_text_color);
- model->new_text(ps_x(x1), ps_y(y1), s, cur_size, p, &cur_text_color);
-
- t = model->get_cur_text();
+ t = model->get_cur_text();
- if (t) {
- if (!t->is_empty()) {
- mod++;
- }
- damage(4, bb_x(t), bb_y(t), bb_w(t), bb_h(t));
- }
+ if (t) {
+ if (!t->is_empty()) {
+ mod++;
+ }
+ damage(4, bb_x(t), bb_y(t), bb_w(t), bb_h(t));
+ }
- if (t_old) {
- damage(4, bb_x(t_old), bb_y(t_old), bb_w(t_old), bb_h(t_old));
- }
+ if (t_old) {
+ damage(4, bb_x(t_old), bb_y(t_old), bb_w(t_old), bb_h(t_old));
+ }
}
void PSEditWidget::new_text(int x1, int y1, const char *s) {
- new_text(x1, y1, s, get_page());
+ new_text(x1, y1, s, get_page());
}
int PSEditWidget::set_cur_text(int x1, int y1) {
- PSEditText *t_new, *t_old;
+ PSEditText *t_new, *t_old;
- t_old = model->get_cur_text();
+ t_old = model->get_cur_text();
- if (model->set_cur_text(ps_x(x1), ps_y(y1), page) == 0) {
+ if (model->set_cur_text(ps_x(x1), ps_y(y1), page) == 0) {
- t_new = model->get_cur_text();
+ t_new = model->get_cur_text();
- if (t_new) {
- cur_text_color.set(&t_new->text_color);
- cur_size = t_new->size;
- if (property_changed_cb) {
- property_changed_cb();
- }
+ if (t_new) {
+ cur_text_color.set(&t_new->text_color);
+ cur_size = t_new->size;
+ if (property_changed_cb) {
+ property_changed_cb();
+ }
- damage(4, bb_x(t_new), bb_y(t_new), bb_w(t_new), bb_h(t_new));
- }
- if (t_old) {
- damage(4, bb_x(t_old), bb_y(t_old), bb_w(t_old), bb_h(t_old));
- }
+ damage(4, bb_x(t_new), bb_y(t_new), bb_w(t_new), bb_h(t_new));
+ }
+ if (t_old) {
+ damage(4, bb_x(t_old), bb_y(t_old), bb_w(t_old), bb_h(t_old));
+ }
- return 0;
- }
- return 1;
+ return 0;
+ }
+ return 1;
}
int PSEditWidget::next_text() {
- PSEditText *t_new, *t_old;
- int ret;
+ PSEditText *t_new, *t_old;
+ int ret;
- t_old = model->get_cur_text();
+ t_old = model->get_cur_text();
- ret = model->next_text(page);
+ ret = model->next_text(page);
- t_new = model->get_cur_text();
-
- if (t_new) {
- cur_text_color.set(&t_new->text_color);
- cur_size = t_new->size;
- if (property_changed_cb) {
- property_changed_cb();
- }
+ t_new = model->get_cur_text();
- damage(4, bb_x(t_new), bb_y(t_new), bb_w(t_new), bb_h(t_new));
- }
+ if (t_new) {
+ cur_text_color.set(&t_new->text_color);
+ cur_size = t_new->size;
+ if (property_changed_cb) {
+ property_changed_cb();
+ }
- if (t_old) {
- damage(4, bb_x(t_old), bb_y(t_old), bb_w(t_old), bb_h(t_old));
- }
-
- return ret;
+ damage(4, bb_x(t_new), bb_y(t_new), bb_w(t_new), bb_h(t_new));
+ }
+
+ if (t_old) {
+ damage(4, bb_x(t_old), bb_y(t_old), bb_w(t_old), bb_h(t_old));
+ }
+
+ return ret;
}
void PSEditWidget::append_text(const char *s) {
- PSEditText *t;
+ PSEditText *t;
- model->append_text(s);
- mod++;
- t = model->get_cur_text();
- if (t) {
- damage(4, bb_x(t), bb_y(t), bb_w(t), bb_h(t));
- }
+ model->append_text(s);
+ mod++;
+ t = model->get_cur_text();
+ if (t) {
+ damage(4, bb_x(t), bb_y(t), bb_w(t), bb_h(t));
+ }
}
void PSEditWidget::move(int x1, int y1) {
- PSEditText *t;
- int old_bbx, old_bby, old_bbw, old_bbh;
+ PSEditText *t;
+ int old_bbx, old_bby, old_bbw, old_bbh;
- t = model->get_cur_text();
- if (t) {
- old_bbx = bb_x(t);
- old_bby = bb_y(t);
- old_bbw = bb_w(t);
- old_bbh = bb_h(t);
+ t = model->get_cur_text();
+ if (t) {
+ old_bbx = bb_x(t);
+ old_bby = bb_y(t);
+ old_bbw = bb_w(t);
+ old_bbh = bb_h(t);
- model->move(ps_x(x1), ps_y(y1));
- if (!t->is_empty() || t->get_tag()) {
- mod++;
- }
+ model->move(ps_x(x1), ps_y(y1));
+ if (!t->is_empty() || t->get_tag()) {
+ mod++;
+ }
- damage(4, old_bbx, old_bby, old_bbw, old_bbh);
- damage(4, bb_x(t), bb_y(t), bb_w(t), bb_h(t));
- }
+ damage(4, old_bbx, old_bby, old_bbw, old_bbh);
+ damage(4, bb_x(t), bb_y(t), bb_w(t), bb_h(t));
+ }
}
void PSEditWidget::rel_move(int dx, int dy) {
- PSEditText *t;
- int old_bbx, old_bby, old_bbw, old_bbh;
+ PSEditText *t;
+ int old_bbx, old_bby, old_bbw, old_bbh;
- t = model->get_cur_text();
- if (t) {
- old_bbx = bb_x(t);
- old_bby = bb_y(t);
- old_bbw = bb_w(t);
- old_bbh = bb_h(t);
+ t = model->get_cur_text();
+ if (t) {
+ old_bbx = bb_x(t);
+ old_bby = bb_y(t);
+ old_bbw = bb_w(t);
+ old_bbh = bb_h(t);
- model->move(t->get_x() + dx, t->get_y() + dy);
- mod++;
+ model->move(t->get_x() + dx, t->get_y() + dy);
+ mod++;
- damage(4, old_bbx, old_bby, old_bbw, old_bbh);
- damage(4, bb_x(t), bb_y(t), bb_w(t), bb_h(t));
- }
+ damage(4, old_bbx, old_bby, old_bbw, old_bbh);
+ damage(4, bb_x(t), bb_y(t), bb_w(t), bb_h(t));
+ }
}
void PSEditWidget::rm_char() {
- PSEditText *t;
- int width;
+ PSEditText *t;
+ int width;
- t = model->get_cur_text();
- if (t) {
- fl_font(FLPSED_FONT, t->get_size() * zoom_percent / 100);
- width = bb_w(t);
- }
+ t = model->get_cur_text();
+ if (t) {
+ fl_font(FLPSED_FONT, t->get_size() * zoom_percent / 100);
+ width = bb_w(t);
+ }
- model->rm_char();
- mod++;
+ model->rm_char();
+ mod++;
- if (t) {
- damage(4, bb_x(t), bb_y(t), width, bb_h(t));
- }
+ if (t) {
+ damage(4, bb_x(t), bb_y(t), width, bb_h(t));
+ }
}
int PSEditWidget::reload() {
- model->set_page(0);
+ model->set_page(0);
- if (property_changed_cb) {
- property_changed_cb();
- }
+ if (property_changed_cb) {
+ property_changed_cb();
+ }
- return GsWidget::reload();
+ return GsWidget::reload();
}
void PSEditWidget::set_size(int s) {
- PSEditText *t;
- int old_x, old_y, old_w, old_h;
+ PSEditText *t;
+ int old_x, old_y, old_w, old_h;
- t = model->get_cur_text();
- if (t) {
- old_x = bb_x(t);
- old_y = bb_y(t);
- old_w = bb_w(t);
- old_h = bb_h(t);
- }
+ t = model->get_cur_text();
+ if (t) {
+ old_x = bb_x(t);
+ old_y = bb_y(t);
+ old_w = bb_w(t);
+ old_h = bb_h(t);
+ }
- cur_size = s;
- model->set_size(s);
+ cur_size = s;
+ model->set_size(s);
- if (t) {
- damage(4, bb_x(t), bb_y(t), bb_w(t), bb_h(t));
- damage(4, old_x, old_y, old_w, old_h);
- }
+ if (t) {
+ damage(4, bb_x(t), bb_y(t), bb_w(t), bb_h(t));
+ damage(4, old_x, old_y, old_w, old_h);
+ }
}
int PSEditWidget::get_size() {
- int s;
+ int s;
- s = model->get_size();
- if (s >= 0) {
- return s;
- } else {
- return cur_size;
- }
+ s = model->get_size();
+ if (s >= 0) {
+ return s;
+ } else {
+ return cur_size;
+ }
}
void PSEditWidget::set_color(const PSEditColor *c) {
- PSEditText *t;
- uchar *p;
-
- t = model->get_cur_text();
+ PSEditText *t;
+ uchar *p;
- p = (uchar*) &c;
- cur_text_color.set(c);
+ t = model->get_cur_text();
- model->set_color(&cur_text_color);
+ p = (uchar*) &c;
+ cur_text_color.set(c);
- if (t) {
- damage(4, bb_x(t), bb_y(t), bb_w(t), bb_h(t));
- }
+ model->set_color(&cur_text_color);
+
+ if (t) {
+ damage(4, bb_x(t), bb_y(t), bb_w(t), bb_h(t));
+ }
}
void PSEditWidget::get_color(PSEditColor *c) {
- c->set(&cur_text_color);
+ c->set(&cur_text_color);
}
int PSEditWidget::get_max_pages() {
- return model->get_max_pages();
+ return model->get_max_pages();
}
int PSEditWidget::get_show_tags() {
- return show_tags;
+ return show_tags;
}
void PSEditWidget::set_show_tags(int s) {
- show_tags = s;
- redraw();
+ show_tags = s;
+ redraw();
}
int PSEditWidget::set_tag(const char *t) {
- if (model->set_tag(t) == 0) {
- mod++;
- redraw();
- return 0;
- } else {
- return 1;
- }
+ if (model->set_tag(t) == 0) {
+ mod++;
+ redraw();
+ return 0;
+ } else {
+ return 1;
+ }
}
char *PSEditWidget::get_tag() {
- return model->get_tag();
+ return model->get_tag();
}
int PSEditWidget::modified() {
- return mod;
+ return mod;
}
int PSEditWidget::file_loaded() {
- return loaded;
+ return loaded;
}
int PSEditWidget::replace_tag(char *tag, char *text) {
- return model->replace_tag(tag, text);
+ return model->replace_tag(tag, text);
}
int PSEditWidget::zoom(int p) {
- zoom_percent = p;
- return GsWidget::zoom(zoom_percent);
+ zoom_percent = p;
+ return GsWidget::zoom(zoom_percent);
}
int PSEditWidget::bb_x(PSEditText *t) {
- return ps_to_display_x(t->get_x()) + x() - 10;
+ return ps_to_display_x(t->get_x()) + x() - 10;
}
int PSEditWidget::bb_y(PSEditText *t) {
- fl_font(FLPSED_FONT, t->get_size() * zoom_percent / 100);
- return ps_to_display_y(t->get_y()) - fl_height() + y() - 10;
+ fl_font(FLPSED_FONT, t->get_size() * zoom_percent / 100);
+ return ps_to_display_y(t->get_y()) - fl_height() + y() - 10;
}
int PSEditWidget::bb_w(PSEditText *t) {
- int w, wt = 0;
- char *tag;
- fl_font(FLPSED_FONT, t->get_size() * zoom_percent / 100);
- w = (int) fl_width(t->get_text()) + 20;
+ int w, wt = 0;
+ char *tag;
+ fl_font(FLPSED_FONT, t->get_size() * zoom_percent / 100);
+ w = (int) fl_width(t->get_text()) + 20;
+
+ tag = t->get_tag();
+ if (tag) {
+ fl_font(FLPSED_TAG_FONT, FLPSED_TAG_FONT_SIZE * zoom_percent / 100);
+ wt = (int) fl_width(tag) + 20;
+ }
- tag = t->get_tag();
- if (tag) {
- fl_font(FLPSED_TAG_FONT, FLPSED_TAG_FONT_SIZE * zoom_percent / 100);
- wt = (int) fl_width(tag) + 20;
- }
-
- return w>=wt?w:wt;
+ return w>=wt?w:wt;
}
int PSEditWidget::bb_h(PSEditText *t) {
- int ret;
- fl_font(FLPSED_FONT, t->get_size() * zoom_percent / 100);
- ret = fl_height() + 30;
+ int ret;
+ fl_font(FLPSED_FONT, t->get_size() * zoom_percent / 100);
+ ret = fl_height() + 30;
- if (t->get_tag()) {
- fl_font(FLPSED_TAG_FONT, FLPSED_TAG_FONT_SIZE * zoom_percent / 100);
- ret = ret + fl_height();
- }
+ if (t->get_tag()) {
+ fl_font(FLPSED_TAG_FONT, FLPSED_TAG_FONT_SIZE * zoom_percent / 100);
+ ret = ret + fl_height();
+ }
- return ret;
+ return ret;
}
static int round_div(int a, int b) {
- int r;
+ int r;
- r = a / b;
- if (a % b > b / 2) {
- r++;
- }
+ r = a / b;
+ if (a % b > b / 2) {
+ r++;
+ }
- return r;
+ return r;
}
int PSEditWidget::ps_to_display_x(int x1) {
- return round_div(x1 * xdpi, 72);
+ return round_div(x1 * xdpi, 72);
}
int PSEditWidget::ps_to_display_y(int y1) {
- return round_div((paper_y - y1) * xdpi, 72);
+ return round_div((paper_y - y1) * xdpi, 72);
}
int PSEditWidget::ps_x(int x1) {
- return round_div(x1 * 72, xdpi);
+ return round_div(x1 * 72, xdpi);
}
int PSEditWidget::ps_y(int y1) {
- return paper_y - round_div(y1 * 72, ydpi);
+ return paper_y - round_div(y1 * 72, ydpi);
}
diff --git a/src/PSEditor.H b/src/PSEditor.H
index abcf3a3..ece78a8 100644
--- a/src/PSEditor.H
+++ b/src/PSEditor.H
@@ -10,27 +10,25 @@
#include "PSEditWidget.H"
class PSEditor : public PSEditWidget {
- private:
- int tmp_fd;
+ private:
+ int tmp_fd;
- int ps_level;
+ int ps_level;
- int handle(int event);
+ int handle(int event);
-public:
- PSEditor(int X,int Y,int W, int H);
+ public:
+ PSEditor(int X,int Y,int W, int H);
- int open_file(FILE *fp);
+ int open_file(FILE *fp);
- int open_file(const char *f);
+ int open_file(const char *f);
- int save(FILE *fp);
+ int save(FILE *fp);
- int save(const char* savefile);
+ int save(const char* savefile);
- int import(char *f);
+ int import(char *f);
};
-
-
#endif
diff --git a/src/PSEditor.cxx b/src/PSEditor.cxx
index d87388b..acf8d7f 100644
--- a/src/PSEditor.cxx
+++ b/src/PSEditor.cxx
@@ -10,181 +10,181 @@
#include "Postscript.H"
PSEditor::PSEditor(int X,int Y,int W, int H) : PSEditWidget(X, Y, W, H) {
- loaded = 0;
- mod = 0;
- ps_level = 1;
- tmp_fd = -1;
+ loaded = 0;
+ mod = 0;
+ ps_level = 1;
+ tmp_fd = -1;
}
int PSEditor::handle(int event) {
- int mark_x, mark_y;
-
- switch(event) {
- case FL_PUSH:
- if (Fl::event_button() == 1) {
- if (!file_loaded()) {
- return 0;
- }
-
- mark_x = Fl::event_x()-x();
- mark_y = Fl::event_y()-y();
-
- if (!set_cur_text(mark_x, mark_y) == 0) {
- new_text(mark_x, mark_y, "");
- }
-
- Fl::focus(this);
- return 1;
- }
- break;
- case FL_RELEASE:
- if (Fl::event_button() == 2) {
- Fl::paste(*this, 0);
- return 1;
- }
-
- break;
- case FL_DRAG:
- move(Fl::event_x()-x(), Fl::event_y()-y());
- return 1;
- break;
- case FL_KEYBOARD:
- {
- int del;
- int key = Fl::event_key();
- if (key == FL_BackSpace) {
- rm_char();
- } else if (key == FL_Left) {
- rel_move(-1, 0);
- } else if (key == FL_Right) {
- rel_move(1, 0);
- } else if (key == FL_Up) {
- rel_move(0, 1);
- } else if (key == FL_Down) {
- rel_move(0, -1);
- } else if (key == FL_Tab) {
- next_text();
- } else if (Fl::compose(del)) {
- if (del > 0) {
- for (int i=0; i<del; i++) rm_char();
+ int mark_x, mark_y;
+
+ switch(event) {
+ case FL_PUSH:
+ if (Fl::event_button() == 1) {
+ if (!file_loaded()) {
+ return 0;
+ }
+
+ mark_x = Fl::event_x()-x();
+ mark_y = Fl::event_y()-y();
+
+ if (!set_cur_text(mark_x, mark_y) == 0) {
+ new_text(mark_x, mark_y, "");
+ }
+
+ Fl::focus(this);
+ return 1;
+ }
+ break;
+ case FL_RELEASE:
+ if (Fl::event_button() == 2) {
+ Fl::paste(*this, 0);
+ return 1;
+ }
+
+ break;
+ case FL_DRAG:
+ move(Fl::event_x()-x(), Fl::event_y()-y());
+ return 1;
+ break;
+ case FL_KEYBOARD:
+ {
+ int del;
+ int key = Fl::event_key();
+ if (key == FL_BackSpace) {
+ rm_char();
+ } else if (key == FL_Left) {
+ rel_move(-1, 0);
+ } else if (key == FL_Right) {
+ rel_move(1, 0);
+ } else if (key == FL_Up) {
+ rel_move(0, 1);
+ } else if (key == FL_Down) {
+ rel_move(0, -1);
+ } else if (key == FL_Tab) {
+ next_text();
+ } else if (Fl::compose(del)) {
+ if (del > 0) {
+ for (int i=0; i<del; i++) rm_char();
+ }
+ if (Fl::event_length()) {
+ append_text(Fl::event_text());
+ }
+ } else {
+ return 0;
+ }
+
+ return 1;
+ }
+ break;
+ case FL_PASTE:
+ append_text(Fl::event_text());
+ return 1;
+ break;
+ case FL_FOCUS:
+ return 1;
+ break;
+ case FL_UNFOCUS:
+ return 0;
+ break;
}
- if (Fl::event_length()) {
- append_text(Fl::event_text());
- }
- } else {
return 0;
- }
-
- return 1;
- }
- break;
- case FL_PASTE:
- append_text(Fl::event_text());
- return 1;
- break;
- case FL_FOCUS:
- return 1;
- break;
- case FL_UNFOCUS:
- return 0;
- break;
- }
- return 0;
}
int PSEditor::open_file(FILE *fp) {
- if (tmp_fd >= 0) {
- close(tmp_fd);
- }
-
- tmp_fd = model->load(fp);
-
- if (tmp_fd < 0) {
- return 1;
- } else {
- mod = 0;
- loaded = 1;
- return GsWidget::open_file(tmp_fd);
- }
+ if (tmp_fd >= 0) {
+ close(tmp_fd);
+ }
+
+ tmp_fd = model->load(fp);
+
+ if (tmp_fd < 0) {
+ return 1;
+ } else {
+ mod = 0;
+ loaded = 1;
+ return GsWidget::open_file(tmp_fd);
+ }
}
int PSEditor::open_file(const char *f) {
- FILE *fp;
- int ret;
+ FILE *fp;
+ int ret;
- fp = fopen(f, "r");
- if (!fp) {
- perror("fopen");
- return 1;
- }
+ fp = fopen(f, "r");
+ if (!fp) {
+ perror("fopen");
+ return 1;
+ }
- ret = open_file(fp);
- fclose(fp);
+ ret = open_file(fp);
+ fclose(fp);
- return ret;
+ return ret;
}
int PSEditor::save(FILE *fp) {
- int ret;
+ int ret;
+
+ if (!file_loaded()) {
+ return 1;
+ }
- if (!file_loaded()) {
- return 1;
- }
-
- ret = model->save(fp, tmp_fd);
+ ret = model->save(fp, tmp_fd);
- if (ret == 0) {
- mod = 0;
- }
+ if (ret == 0) {
+ mod = 0;
+ }
- return ret;
+ return ret;
}
int PSEditor::save(const char* savefile) {
- FILE *fp;
- int ret;
-
- if (!file_loaded()) {
- return 1;
- }
-
- fp = fopen(savefile, "w");
- if (!fp) {
- perror("fopen");
- return 1;
- }
-
- ret = save(fp);
- fclose(fp);
-
- return ret;
+ FILE *fp;
+ int ret;
+
+ if (!file_loaded()) {
+ return 1;
+ }
+
+ fp = fopen(savefile, "w");
+ if (!fp) {
+ perror("fopen");
+ return 1;
+ }
+
+ ret = save(fp);
+ fclose(fp);
+
+ return ret;
}
int PSEditor::import(char *f) {
- FILE *fp;
- char linebuf[1024];
- PSParser *p2;
-
- if (!file_loaded()) {
- return 1;
- }
-
- fp = fopen(f, "r");
- if (!fp) {
- fprintf(stderr, "Could not open file %s.\n", f);
- return 1;
- }
-
- p2 = new PSParser_2(model);
- while (fgets(linebuf, sizeof(linebuf), fp) != NULL) {
- p2->parse(linebuf);
- }
-
- delete(p2);
-
- mod = 1;
- redraw();
- return 0;
+ FILE *fp;
+ char linebuf[1024];
+ PSParser *p2;
+
+ if (!file_loaded()) {
+ return 1;
+ }
+
+ fp = fopen(f, "r");
+ if (!fp) {
+ fprintf(stderr, "Could not open file %s.\n", f);
+ return 1;
+ }
+
+ p2 = new PSParser_2(model);
+ while (fgets(linebuf, sizeof(linebuf), fp) != NULL) {
+ p2->parse(linebuf);
+ }
+
+ delete(p2);
+
+ mod = 1;
+ redraw();
+ return 0;
}
diff --git a/src/Postscript.H b/src/Postscript.H
index c61fdec..ece0481 100644
--- a/src/Postscript.H
+++ b/src/Postscript.H
@@ -11,73 +11,73 @@
#include "PSEditModel.H"
class PSParser {
- protected:
- PSEditModel *pse;
+ protected:
+ PSEditModel *pse;
- int cur_size;
+ int cur_size;
- PSEditColor cur_text_color;
+ PSEditColor cur_text_color;
- int page;
+ int page;
- public:
- PSParser(PSEditModel *p);
+ public:
+ PSParser(PSEditModel *p);
- virtual int parse(char *line);
+ virtual int parse(char *line);
};
class PSParser_2 : public PSParser {
- private:
- int inside;
+ private:
+ int inside;
- public:
- PSParser_2(PSEditModel *p);
+ public:
+ PSParser_2(PSEditModel *p);
- int parse(char *line);
+ int parse(char *line);
};
class PSWriter {
- protected:
- PSEditModel *pse;
+ protected:
+ PSEditModel *pse;
- char * pos_format;
+ char * pos_format;
- char * size_format;
+ char * size_format;
- char * text_format;
+ char * text_format;
- char * color_format;
+ char * color_format;
- char * glyph_format;
+ char * glyph_format;
- char * tag_format;
+ char * tag_format;
- void write_string(FILE *out, char *s);
+ void write_string(FILE *out, char *s);
- void write_main_block(FILE *out);
+ void write_main_block(FILE *out);
- void write_internal_format(FILE *out);
+ void write_internal_format(FILE *out);
- int write_text(FILE *out, PSEditText *t);
+ int write_text(FILE *out, PSEditText *t);
- virtual char *ps_header();
+ virtual char *ps_header();
- virtual char *ps_trailer();
+ virtual char *ps_trailer();
- public:
- PSWriter(PSEditModel *p);
+ public:
+ PSWriter(PSEditModel *p);
- int write(FILE *in, FILE *out);
+ int write(FILE *in, FILE *out);
};
class PSLevel1Writer : public PSWriter {
- protected:
- char *ps_header();
+ protected:
+ char *ps_header();
- char *ps_trailer();
+ char *ps_trailer();
- public:
- PSLevel1Writer(PSEditModel *p);
+ public:
+ PSLevel1Writer(PSEditModel *p);
};
#endif
diff --git a/src/Postscript.cxx b/src/Postscript.cxx
index 3072ac6..6a5b79f 100644
--- a/src/Postscript.cxx
+++ b/src/Postscript.cxx
@@ -31,362 +31,362 @@
#define PSEDIT_PAGE_MARKER "/PSEditWidgetPageCount %d def %% PSEditWidget\n"
static struct {
- const char *glyph;
- const char *c;
+ const char *glyph;
+ const char *c;
} glyph_char[] = {
- {"adieresis", "ä"},
- {"Adieresis", "Ä"},
- {"odieresis", "ö"},
- {"Odieresis", "Ö"},
- {"udieresis", "ü"},
- {"Udieresis", "Ü"},
- {"germandbls", "ß"},
- {"parenleft", "("},
- {"parenright", ")"},
- {"percent", "%"},
- {"backslash", "\\"},
- {"exclamdown", "¡"},
- {"cent", "¢"},
- {"sterling", "£"},
- {"currency", "¤"},
- {"yen", "¥"},
- {"brokenbar", "¦"},
- {"section", "§"},
- {"diaeresis", "¨"},
- {"copyright", "©"},
- {"ordfeminine","ª"},
- {"guillemotleft","«"},
- {"notsign", "¬"},
- {"hyphen", "­"},
- {"registered", "®"},
- {"macron", "¯"},
- {"degree", "°"},
- {"plusminus", "±"},
- {"twosuperior","²"},
- {"threesuperior","³"},
- {"acute", "´"},
- {"mu", "µ"},
- {"paragraph", "¶"},
- {"periodcentered","·"},
- {"cedilla", "¸"},
- {"onesuperior","¹"},
- {"masculine", "º"},
- {"guillemotright","»"},
- {"onequarter", "¼"},
- {"onehalf", "½"},
- {"threequarters","¾"},
- {"questiondown","¿"},
- {"Agrave", "À"},
- {"Aacute", "Á"},
- {"Acircumflex", "Â"},
- {"Atilde", "Ã"},
- {"Adiaeresis", "Ä"},
- {"Aring", "Å"},
- {"AE", "Æ"},
- {"Ccedilla", "Ç"},
- {"Egrave", "È"},
- {"Eacute", "É"},
- {"Ecircumflex", "Ê"},
- {"Ediaeresis", "Ë"},
- {"Igrave", "Ì"},
- {"Iacute", "Í"},
- {"Icircumflex", "Î"},
- {"Idiaeresis", "Ï"},
- {"ETH", "Ð"},
- {"Ntilde", "Ñ"},
- {"Ograve", "Ò"},
- {"Oacute", "Ó"},
- {"Ocircumflex", "Ô"},
- {"Otilde", "Õ"},
- {"Odiaeresis", "Ö"},
- {"multiply", "×"},
- {"Ooblique", "Ø"},
- {"Ugrave", "Ù"},
- {"Uacute", "Ú"},
- {"Ucircumflex", "Û"},
- {"Udiaeresis", "Ü"},
- {"Yacute", "Ý"},
- {"THORN", "Þ"},
- {"ssharp", "ß"},
- {"agrave", "à"},
- {"aacute", "á"},
- {"acircumflex", "â"},
- {"atilde", "ã"},
- {"adiaeresis", "ä"},
- {"aring", "å"},
- {"ae", "æ"},
- {"ccedilla", "ç"},
- {"egrave", "è"},
- {"eacute", "é"},
- {"ecircumflex", "ê"},
- {"ediaeresis", "ë"},
- {"igrave", "ì"},
- {"iacute", "í"},
- {"icircumflex", "î"},
- {"idiaeresis", "ï"},
- {"eth", "ð"},
- {"ntilde", "ñ"},
- {"ograve", "ò"},
- {"oacute", "ó"},
- {"ocircumflex", "ô"},
- {"otilde", "õ"},
- {"odiaeresis", "ö"},
- {"division", "÷"},
- {"oslash", "ø"},
- {"ugrave", "ù"},
- {"uacute", "ú"},
- {"ucircumflex", "û"},
- {"udiaeresis", "ü"},
- {"yacute", "ý"},
- {"thorn", "þ"},
- {"ydiaeresis", "ÿ"},
- {NULL, NULL}};
+ {"adieresis", "ä"},
+ {"Adieresis", "Ä"},
+ {"odieresis", "ö"},
+ {"Odieresis", "Ö"},
+ {"udieresis", "ü"},
+ {"Udieresis", "Ü"},
+ {"germandbls", "ß"},
+ {"parenleft", "("},
+ {"parenright", ")"},
+ {"percent", "%"},
+ {"backslash", "\\"},
+ {"exclamdown", "¡"},
+ {"cent", "¢"},
+ {"sterling", "£"},
+ {"currency", "¤"},
+ {"yen", "¥"},
+ {"brokenbar", "¦"},
+ {"section", "§"},
+ {"diaeresis", "¨"},
+ {"copyright", "©"},
+ {"ordfeminine","ª"},
+ {"guillemotleft","«"},
+ {"notsign", "¬"},
+ {"hyphen", "­"},
+ {"registered", "®"},
+ {"macron", "¯"},
+ {"degree", "°"},
+ {"plusminus", "±"},
+ {"twosuperior","²"},
+ {"threesuperior","³"},
+ {"acute", "´"},
+ {"mu", "µ"},
+ {"paragraph", "¶"},
+ {"periodcentered","·"},
+ {"cedilla", "¸"},
+ {"onesuperior","¹"},
+ {"masculine", "º"},
+ {"guillemotright","»"},
+ {"onequarter", "¼"},
+ {"onehalf", "½"},
+ {"threequarters","¾"},
+ {"questiondown","¿"},
+ {"Agrave", "À"},
+ {"Aacute", "Á"},
+ {"Acircumflex", "Â"},
+ {"Atilde", "Ã"},
+ {"Adiaeresis", "Ä"},
+ {"Aring", "Å"},
+ {"AE", "Æ"},
+ {"Ccedilla", "Ç"},
+ {"Egrave", "È"},
+ {"Eacute", "É"},
+ {"Ecircumflex", "Ê"},
+ {"Ediaeresis", "Ë"},
+ {"Igrave", "Ì"},
+ {"Iacute", "Í"},
+ {"Icircumflex", "Î"},
+ {"Idiaeresis", "Ï"},
+ {"ETH", "Ð"},
+ {"Ntilde", "Ñ"},
+ {"Ograve", "Ò"},
+ {"Oacute", "Ó"},
+ {"Ocircumflex", "Ô"},
+ {"Otilde", "Õ"},
+ {"Odiaeresis", "Ö"},
+ {"multiply", "×"},
+ {"Ooblique", "Ø"},
+ {"Ugrave", "Ù"},
+ {"Uacute", "Ú"},
+ {"Ucircumflex", "Û"},
+ {"Udiaeresis", "Ü"},
+ {"Yacute", "Ý"},
+ {"THORN", "Þ"},
+ {"ssharp", "ß"},
+ {"agrave", "à"},
+ {"aacute", "á"},
+ {"acircumflex", "â"},
+ {"atilde", "ã"},
+ {"adiaeresis", "ä"},
+ {"aring", "å"},
+ {"ae", "æ"},
+ {"ccedilla", "ç"},
+ {"egrave", "è"},
+ {"eacute", "é"},
+ {"ecircumflex", "ê"},
+ {"ediaeresis", "ë"},
+ {"igrave", "ì"},
+ {"iacute", "í"},
+ {"icircumflex", "î"},
+ {"idiaeresis", "ï"},
+ {"eth", "ð"},
+ {"ntilde", "ñ"},
+ {"ograve", "ò"},
+ {"oacute", "ó"},
+ {"ocircumflex", "ô"},
+ {"otilde", "õ"},
+ {"odiaeresis", "ö"},
+ {"division", "÷"},
+ {"oslash", "ø"},
+ {"ugrave", "ù"},
+ {"uacute", "ú"},
+ {"ucircumflex", "û"},
+ {"udiaeresis", "ü"},
+ {"yacute", "ý"},
+ {"thorn", "þ"},
+ {"ydiaeresis", "ÿ"},
+ {NULL, NULL}};
static const char * glyph_to_char(char *glyph) {
- int i=0;
-
- while(glyph_char[i].glyph != NULL) {
- if (strcmp(glyph_char[i].glyph, glyph) == 0) {
- return glyph_char[i].c;
- }
- i++;
- }
-
- return NULL;
+ int i=0;
+
+ while(glyph_char[i].glyph != NULL) {
+ if (strcmp(glyph_char[i].glyph, glyph) == 0) {
+ return glyph_char[i].c;
+ }
+ i++;
+ }
+
+ return NULL;
}
static const char * char_to_glyph(char *c) {
- int i=0;
-
- while(glyph_char[i].glyph != NULL) {
- if (strncmp(glyph_char[i].c, c, 1) == 0) {
- return glyph_char[i].glyph;
- }
- i++;
- }
-
- return NULL;
+ int i=0;
+
+ while(glyph_char[i].glyph != NULL) {
+ if (strncmp(glyph_char[i].c, c, 1) == 0) {
+ return glyph_char[i].glyph;
+ }
+ i++;
+ }
+
+ return NULL;
}
PSParser::PSParser(PSEditModel *p) {
- pse = p;
- cur_size = 12;
+ pse = p;
+ cur_size = 12;
}
int PSParser::parse(char *line) {
- return 0;
+ return 0;
}
PSParser_2::PSParser_2(PSEditModel *p) : PSParser(p) {
- page = 1;
- inside = 0;
+ page = 1;
+ inside = 0;
}
int PSParser_2::parse(char *line) {
- int x1, y1, size, dummy;
- PSEditColor c;
- char buf[2028];
-
- if (!inside && strcmp(line, PSEDIT_BEGIN) == 0) {
- inside = 1;
- return 1; // line was recognized
- } else if (inside && strcmp(line, PSEDIT_END) == 0) {
- inside = 0;
- return 1;
- } else if (inside && sscanf(line, PSEDIT_PAGE_FORMAT, &page) == 1) {
- return 1;
- } else if (inside && sscanf(line, PSEDIT_SIZE_FORMAT, &size) == 1) {
- cur_size = size;
- return 1;
- } else if (inside && sscanf(line, PSEDIT_COLOR_FORMAT, &c.r, &c.g, &c.b)
- == 3) {
- cur_text_color.set(&c);
- return 1;
- } else if (inside && sscanf(line, PSEDIT_POS_FORMAT, &x1, &y1) == 2) {
- pse->new_text(x1, y1, "", cur_size, page, &cur_text_color);
- return 1;
- } else if (inside && sscanf(line, PSEDIT_GLYPH_FORMAT, buf) == 1) {
- pse->append_text(glyph_to_char(buf));
- return 1;
- } else if (inside && sscanf(line, PSEDIT_TEXT_FORMAT_SCAN, buf) == 1) {
- pse->append_text(buf);
- return 1;
- } else if (inside && sscanf(line, PSEDIT_TAG_FORMAT, buf) == 1) {
- pse->set_tag(buf);
- return 1;
- } else if (inside) {
- return 1;
- } else if (sscanf(line, PSEDIT_PAGE_MARKER, &dummy) == 1) {
- return 1;
- } else {
- return 0; // line not recognized
- }
+ int x1, y1, size, dummy;
+ PSEditColor c;
+ char buf[2028];
+
+ if (!inside && strcmp(line, PSEDIT_BEGIN) == 0) {
+ inside = 1;
+ return 1; // line was recognized
+ } else if (inside && strcmp(line, PSEDIT_END) == 0) {
+ inside = 0;
+ return 1;
+ } else if (inside && sscanf(line, PSEDIT_PAGE_FORMAT, &page) == 1) {
+ return 1;
+ } else if (inside && sscanf(line, PSEDIT_SIZE_FORMAT, &size) == 1) {
+ cur_size = size;
+ return 1;
+ } else if (inside && sscanf(line, PSEDIT_COLOR_FORMAT, &c.r, &c.g, &c.b)
+ == 3) {
+ cur_text_color.set(&c);
+ return 1;
+ } else if (inside && sscanf(line, PSEDIT_POS_FORMAT, &x1, &y1) == 2) {
+ pse->new_text(x1, y1, "", cur_size, page, &cur_text_color);
+ return 1;
+ } else if (inside && sscanf(line, PSEDIT_GLYPH_FORMAT, buf) == 1) {
+ pse->append_text(glyph_to_char(buf));
+ return 1;
+ } else if (inside && sscanf(line, PSEDIT_TEXT_FORMAT_SCAN, buf) == 1) {
+ pse->append_text(buf);
+ return 1;
+ } else if (inside && sscanf(line, PSEDIT_TAG_FORMAT, buf) == 1) {
+ pse->set_tag(buf);
+ return 1;
+ } else if (inside) {
+ return 1;
+ } else if (sscanf(line, PSEDIT_PAGE_MARKER, &dummy) == 1) {
+ return 1;
+ } else {
+ return 0; // line not recognized
+ }
}
PSWriter::PSWriter(PSEditModel *p) {
- pse = p;
+ pse = p;
}
int PSWriter::write(FILE *in, FILE *out) {
- char linebuf[1024];
- int done=0, page = 1;
-
- while (fgets(linebuf, 1024, in) != NULL) {
- // Try to write main block before %%EndSetup or %%EndProlog
- if (!done &&
- (strncmp(linebuf, "%%EndSetup", strlen("%%EndSetup")) == 0 ||
- strncmp(linebuf, "%%EndProlog", strlen("%%EndProlog")) == 0)) {
- done++;
- write_main_block(out);
- }
-
- fprintf(out, "%s", linebuf);
-
- // Try to write main block after %%BeginProlog
- if (!done &&
- (strncmp(linebuf, "%%BeginProlog", strlen("%%BeginProlog")) == 0)) {
- done++;
- write_main_block(out);
- }
-
- if (strncmp(linebuf, "%%Page:", strlen("%%Page:")) == 0) {
- fprintf(out, PSEDIT_PAGE_MARKER, page++);
- }
- }
-
- return 0;
+ char linebuf[1024];
+ int done=0, page = 1;
+
+ while (fgets(linebuf, 1024, in) != NULL) {
+ // Try to write main block before %%EndSetup or %%EndProlog
+ if (!done &&
+ (strncmp(linebuf, "%%EndSetup", strlen("%%EndSetup")) == 0 ||
+ strncmp(linebuf, "%%EndProlog", strlen("%%EndProlog")) == 0)) {
+ done++;
+ write_main_block(out);
+ }
+
+ fprintf(out, "%s", linebuf);
+
+ // Try to write main block after %%BeginProlog
+ if (!done &&
+ (strncmp(linebuf, "%%BeginProlog", strlen("%%BeginProlog")) == 0)) {
+ done++;
+ write_main_block(out);
+ }
+
+ if (strncmp(linebuf, "%%Page:", strlen("%%Page:")) == 0) {
+ fprintf(out, PSEDIT_PAGE_MARKER, page++);
+ }
+ }
+
+ return 0;
}
void PSWriter::write_main_block(FILE *out) {
- fprintf(out, "\n");
- fprintf(out, "%s", PSEDIT_BEGIN);
- fprintf(out, "\n");
-
- write_internal_format(out);
- pos_format = PS_POS_FORMAT;
- size_format = PS_SIZE_FORMAT;
- color_format = PS_COLOR_FORMAT;
- text_format = PS_TEXT_FORMAT;
- glyph_format = PS_GLYPH_FORMAT;
- tag_format = PS_TAG_FORMAT;
-
- fprintf(out, "\n");
- fprintf(out, ps_header());
-
- for (int i=1;i<pse->get_max_pages();i++) {
- if (pse->get_text(i)) {
- fprintf(out, "dup %d eq { \n", i);
- write_text(out, pse->get_text(i));
- fprintf(out, "} if\n");
- }
- }
-
- fprintf(out, ps_trailer());
- fprintf(out, "\n");
- fprintf(out, "%s", PSEDIT_END);
- fprintf(out, "\n");
+ fprintf(out, "\n");
+ fprintf(out, "%s", PSEDIT_BEGIN);
+ fprintf(out, "\n");
+
+ write_internal_format(out);
+ pos_format = PS_POS_FORMAT;
+ size_format = PS_SIZE_FORMAT;
+ color_format = PS_COLOR_FORMAT;
+ text_format = PS_TEXT_FORMAT;
+ glyph_format = PS_GLYPH_FORMAT;
+ tag_format = PS_TAG_FORMAT;
+
+ fprintf(out, "\n");
+ fprintf(out, ps_header());
+
+ for (int i=1;i<pse->get_max_pages();i++) {
+ if (pse->get_text(i)) {
+ fprintf(out, "dup %d eq { \n", i);
+ write_text(out, pse->get_text(i));
+ fprintf(out, "} if\n");
+ }
+ }
+
+ fprintf(out, ps_trailer());
+ fprintf(out, "\n");
+ fprintf(out, "%s", PSEDIT_END);
+ fprintf(out, "\n");
}
void PSWriter::write_internal_format(FILE *out) {
- pos_format = PSEDIT_POS_FORMAT;
- size_format = PSEDIT_SIZE_FORMAT;
- color_format = PSEDIT_COLOR_FORMAT;
- text_format = PSEDIT_TEXT_FORMAT_PRINT;
- glyph_format = PSEDIT_GLYPH_FORMAT;
- tag_format = PSEDIT_TAG_FORMAT;
-
- for (int i=1;i<pse->get_max_pages();i++) {
- if (pse->get_text(i)) {
- fprintf(out, PSEDIT_PAGE_FORMAT, i);
- write_text(out, pse->get_text(i));
- }
- }
+ pos_format = PSEDIT_POS_FORMAT;
+ size_format = PSEDIT_SIZE_FORMAT;
+ color_format = PSEDIT_COLOR_FORMAT;
+ text_format = PSEDIT_TEXT_FORMAT_PRINT;
+ glyph_format = PSEDIT_GLYPH_FORMAT;
+ tag_format = PSEDIT_TAG_FORMAT;
+
+ for (int i=1;i<pse->get_max_pages();i++) {
+ if (pse->get_text(i)) {
+ fprintf(out, PSEDIT_PAGE_FORMAT, i);
+ write_text(out, pse->get_text(i));
+ }
+ }
}
void PSWriter::write_string(FILE *out, char *s) {
- const char *glyph;
-
- if (strlen(s) == 0) {
- return;
- } else if ((glyph = char_to_glyph(s)) != NULL) {
- fprintf(out, glyph_format, glyph);
- write_string(out, &(s[1]));
- return;
- } else {
- for(int i=0; i<strlen(s); i++) {
- if ((glyph = char_to_glyph(&(s[i]))) != NULL) {
- char *s1 = strdup(s);
- s1[i] = '\0';
- fprintf(out, text_format, s1);
- free(s1);
- write_string(out, &(s[i]));
- return;
+ const char *glyph;
+
+ if (strlen(s) == 0) {
+ return;
+ } else if ((glyph = char_to_glyph(s)) != NULL) {
+ fprintf(out, glyph_format, glyph);
+ write_string(out, &(s[1]));
+ return;
+ } else {
+ for(int i=0; i<strlen(s); i++) {
+ if ((glyph = char_to_glyph(&(s[i]))) != NULL) {
+ char *s1 = strdup(s);
+ s1[i] = '\0';
+ fprintf(out, text_format, s1);
+ free(s1);
+ write_string(out, &(s[i]));
+ return;
+ }
+ }
+ fprintf(out, text_format, s);
}
- }
- fprintf(out, text_format, s);
- }
- return;
+ return;
}
int PSWriter::write_text(FILE *out, PSEditText *t) {
- char *s;
-
- if (!t) {
- return 0;
- }
-
- s = t->get_text();
-
- if (strcmp(s, "") != 0 || t->get_tag() != NULL) {
- fprintf(out, size_format, t->get_size());
- fprintf(out, color_format,
- t->text_color.r,
- t->text_color.g,
- t->text_color.b);
- fprintf(out, pos_format, t->get_x(), t->get_y());
- if (t->get_tag()) {
- fprintf(out, tag_format, t->get_tag());
- }
-
- write_string(out, s);
- }
-
- if (t->get_next()) {
- return write_text(out, t->get_next());
- }
-
- return 0;
+ char *s;
+
+ if (!t) {
+ return 0;
+ }
+
+ s = t->get_text();
+
+ if (strcmp(s, "") != 0 || t->get_tag() != NULL) {
+ fprintf(out, size_format, t->get_size());
+ fprintf(out, color_format,
+ t->text_color.r,
+ t->text_color.g,
+ t->text_color.b);
+ fprintf(out, pos_format, t->get_x(), t->get_y());
+ if (t->get_tag()) {
+ fprintf(out, tag_format, t->get_tag());
+ }
+
+ write_string(out, s);
+ }
+
+ if (t->get_next()) {
+ return write_text(out, t->get_next());
+ }
+
+ return 0;
}
char * PSWriter::ps_header() {
- return "";
+ return "";
}
char * PSWriter::ps_trailer() {
- return "";
+ return "";
}
PSLevel1Writer::PSLevel1Writer(PSEditModel *p) : PSWriter(p) {};
char * PSLevel1Writer::ps_header() {
- return
- "/PSEditWidgetPageCount 0 def\n"
- "/PSEditWidgetPC 0 def\n"
- "/PSEditWidgetFontHelvetica /Helvetica findfont def\n"
- "/PSEditWidgetshowpage /showpage load def\n"
- "/showpage {\n"
- "gsave initgraphics\n"
- "PSEditWidgetPageCount 0 eq { \n"
- "/PSEditWidgetPC PSEditWidgetPC 1 add def PSEditWidgetPC\n"
- "} {\n"
- "PSEditWidgetPageCount\n"
- "} ifelse\n";
+ return
+ "/PSEditWidgetPageCount 0 def\n"
+ "/PSEditWidgetPC 0 def\n"
+ "/PSEditWidgetFontHelvetica /Helvetica findfont def\n"
+ "/PSEditWidgetshowpage /showpage load def\n"
+ "/showpage {\n"
+ "gsave initgraphics\n"
+ "PSEditWidgetPageCount 0 eq { \n"
+ "/PSEditWidgetPC PSEditWidgetPC 1 add def PSEditWidgetPC\n"
+ "} {\n"
+ "PSEditWidgetPageCount\n"
+ "} ifelse\n";
}
char * PSLevel1Writer::ps_trailer() {
- return "grestore PSEditWidgetshowpage} def\n";
+ return "grestore PSEditWidgetshowpage} def\n";
}
diff --git a/src/PostscriptDSC.H b/src/PostscriptDSC.H
index 20bc07e..7b4a45d 100644
--- a/src/PostscriptDSC.H
+++ b/src/PostscriptDSC.H
@@ -8,25 +8,25 @@
#define POSTSCRIPTDSC_H
class PostscriptDSC {
- private:
- int bb_x, bb_y, bb_w, bb_h;
- size_t setup_len;
- int pages;
-
- size_t *page_off;
- size_t *page_len;
+ private:
+ int bb_x, bb_y, bb_w, bb_h;
+ size_t setup_len;
+ int pages;
- public:
- PostscriptDSC();
- ~PostscriptDSC();
-
- int parse(int fd);
- int get_pages();
- void get_bounding_box(int *x, int *y, int *w, int *h);
- size_t get_setup_len();
- size_t get_page_off(int p);
- size_t get_page_len(int p);
- void print();
+ size_t *page_off;
+ size_t *page_len;
+
+ public:
+ PostscriptDSC();
+ ~PostscriptDSC();
+
+ int parse(int fd);
+ int get_pages();
+ void get_bounding_box(int *x, int *y, int *w, int *h);
+ size_t get_setup_len();
+ size_t get_page_off(int p);
+ size_t get_page_len(int p);
+ void print();
};
#endif
diff --git a/src/PostscriptDSC.cxx b/src/PostscriptDSC.cxx
index 241dade..99354e7 100644
--- a/src/PostscriptDSC.cxx
+++ b/src/PostscriptDSC.cxx
@@ -11,189 +11,189 @@
#include "PostscriptDSC.H"
PostscriptDSC::PostscriptDSC() {
- bb_x = 0;
- bb_y = 0;
- bb_w = 594; // A4
- bb_h = 841; //
- setup_len = 0;
- pages = 0;
- page_off = NULL;
- page_len = NULL;
+ bb_x = 0;
+ bb_y = 0;
+ bb_w = 594; // A4
+ bb_h = 841; //
+ setup_len = 0;
+ pages = 0;
+ page_off = NULL;
+ page_len = NULL;
}
PostscriptDSC::~PostscriptDSC() {
- if (page_off) {
- free(page_off);
- }
- if (page_len) {
- free(page_len);
- }
+ if (page_off) {
+ free(page_off);
+ }
+ if (page_len) {
+ free(page_len);
+ }
}
int
PostscriptDSC::parse(int fd) {
- FILE *fp;
- char linebuf[1024];
- int x, y, w, h;
- int p1 = 0, ps;
- int i = 0;
- int bb_read = 0;
- int max_pages = 128;
-
- bb_x = 0;
- bb_y = 0;
- bb_w = 594; // A4
- bb_h = 841; //
- setup_len = 0;
- pages = 0;
-
- if (page_off) {
- free(page_off);
- page_off = NULL;
- }
- if(page_len) {
- free(page_len);
- page_len = NULL;
- }
-
- fp = fdopen(fd, "r");
- if (!fp) {
- perror("fdopen");
- return 1;
- }
-
- page_off = (size_t*) malloc(sizeof(size_t) * max_pages);
- memset(page_off, 0, sizeof(size_t) * max_pages);
- page_len = (size_t*) malloc(sizeof(size_t) * max_pages);
- memset(page_len, 0, sizeof(size_t) * max_pages);
-
- while (fgets(linebuf, sizeof(linebuf), fp) != NULL) {
- if (!bb_read &&
- sscanf(linebuf, "%%%%BoundingBox: %d %d %d %d", &x, &y, &w, &h) == 4) {
- bb_x = x;
- bb_y = y;
- bb_w = w;
- bb_h = h;
- bb_read++;
- } else if (setup_len == 0 &&
- strncmp(linebuf, "%%EndSetup", strlen("%%EndSetup")) == 0) {
- setup_len = ftell(fp);
- } else if (strncmp(linebuf, "%%Page: ", strlen("%%Page: ")) == 0) {
- char *p_str = &linebuf[strlen(linebuf)];
-
- // implicitely end setup section
- if (!setup_len) {
- setup_len = ftell(fp);
- }
-
- // move p_str back to beginning of last number in linebuf
- while (p_str > linebuf && !isdigit(*p_str)) {
- p_str--;
- }
- while (p_str > linebuf && isdigit(*p_str)) {
- p_str--;
- }
-
- p1 = atoi(p_str);
-
- if (p1 < 1) {
- fprintf(stderr, "Page %d out of range\n", p1);
- return 1;
- }
-
- if (p1 > max_pages) {
- page_off = (size_t*) realloc(page_off, 2 * max_pages * sizeof(size_t));
- memset(page_off + max_pages, 0, sizeof(size_t) * max_pages);
- page_len = (size_t*) realloc(page_len, 2 * max_pages * sizeof(size_t));
- memset(page_len + max_pages, 0, sizeof(size_t) * max_pages);
- max_pages = max_pages * 2;
- }
-
- if (page_off[p1 - 1] != 0) {
- fprintf(stderr, "Page %d already defined\n", p1);
- return 1;
- }
- if (p1 > 1 && page_off[p1 - 2] == 0) {
- fprintf(stderr, "Page %d not yet defined\n", p1 - 1);
- return 1;
- }
-
- page_off[p1 - 1] = ftell(fp);
- if (p1 > 1) {
- page_len[p1 - 2] = page_off[p1 - 1] - page_off[p1 - 2];
- }
-
- if (p1 > pages) {
- pages = p1;
- }
- }
- }
-
- // Now do some checks
- if (!setup_len) {
- fprintf(stderr, "PageSetup end not found\n");
- return 1;
- }
- if (page_len && page_off && p1 > 0 && p1 <= pages) {
- page_len[p1 - 1] = ftell(fp) - page_off[p1 - 1];
-
- for (int i=0; i<pages; i++) {
- if (page_off[i] == 0 || page_len[i] == 0) {
- fprintf(stderr, "Page %d not defined\n", i);
- return 1;
- }
- }
- } else {
- return 1;
- }
-
- return 0;
+ FILE *fp;
+ char linebuf[1024];
+ int x, y, w, h;
+ int p1 = 0, ps;
+ int i = 0;
+ int bb_read = 0;
+ int max_pages = 128;
+
+ bb_x = 0;
+ bb_y = 0;
+ bb_w = 594; // A4
+ bb_h = 841; //
+ setup_len = 0;
+ pages = 0;
+
+ if (page_off) {
+ free(page_off);
+ page_off = NULL;
+ }
+ if(page_len) {
+ free(page_len);
+ page_len = NULL;
+ }
+
+ fp = fdopen(fd, "r");
+ if (!fp) {
+ perror("fdopen");
+ return 1;
+ }
+
+ page_off = (size_t*) malloc(sizeof(size_t) * max_pages);
+ memset(page_off, 0, sizeof(size_t) * max_pages);
+ page_len = (size_t*) malloc(sizeof(size_t) * max_pages);
+ memset(page_len, 0, sizeof(size_t) * max_pages);
+
+ while (fgets(linebuf, sizeof(linebuf), fp) != NULL) {
+ if (!bb_read &&
+ sscanf(linebuf, "%%%%BoundingBox: %d %d %d %d", &x, &y, &w, &h) == 4) {
+ bb_x = x;
+ bb_y = y;
+ bb_w = w;
+ bb_h = h;
+ bb_read++;
+ } else if (setup_len == 0 &&
+ strncmp(linebuf, "%%EndSetup", strlen("%%EndSetup")) == 0) {
+ setup_len = ftell(fp);
+ } else if (strncmp(linebuf, "%%Page: ", strlen("%%Page: ")) == 0) {
+ char *p_str = &linebuf[strlen(linebuf)];
+
+ // implicitely end setup section
+ if (!setup_len) {
+ setup_len = ftell(fp);
+ }
+
+ // move p_str back to beginning of last number in linebuf
+ while (p_str > linebuf && !isdigit(*p_str)) {
+ p_str--;
+ }
+ while (p_str > linebuf && isdigit(*p_str)) {
+ p_str--;
+ }
+
+ p1 = atoi(p_str);
+
+ if (p1 < 1) {
+ fprintf(stderr, "Page %d out of range\n", p1);
+ return 1;
+ }
+
+ if (p1 > max_pages) {
+ page_off = (size_t*) realloc(page_off, 2 * max_pages * sizeof(size_t));
+ memset(page_off + max_pages, 0, sizeof(size_t) * max_pages);
+ page_len = (size_t*) realloc(page_len, 2 * max_pages * sizeof(size_t));
+ memset(page_len + max_pages, 0, sizeof(size_t) * max_pages);
+ max_pages = max_pages * 2;
+ }
+
+ if (page_off[p1 - 1] != 0) {
+ fprintf(stderr, "Page %d already defined\n", p1);
+ return 1;
+ }
+ if (p1 > 1 && page_off[p1 - 2] == 0) {
+ fprintf(stderr, "Page %d not yet defined\n", p1 - 1);
+ return 1;
+ }
+
+ page_off[p1 - 1] = ftell(fp);
+ if (p1 > 1) {
+ page_len[p1 - 2] = page_off[p1 - 1] - page_off[p1 - 2];
+ }
+
+ if (p1 > pages) {
+ pages = p1;
+ }
+ }
+ }
+
+ // Now do some checks
+ if (!setup_len) {
+ fprintf(stderr, "PageSetup end not found\n");
+ return 1;
+ }
+ if (page_len && page_off && p1 > 0 && p1 <= pages) {
+ page_len[p1 - 1] = ftell(fp) - page_off[p1 - 1];
+
+ for (int i=0; i<pages; i++) {
+ if (page_off[i] == 0 || page_len[i] == 0) {
+ fprintf(stderr, "Page %d not defined\n", i);
+ return 1;
+ }
+ }
+ } else {
+ return 1;
+ }
+
+ return 0;
}
void
PostscriptDSC::get_bounding_box(int *x, int *y, int *w, int *h) {
- *x = bb_x;
- *y = bb_y;
- *w = bb_w;
- *h = bb_h;
+ *x = bb_x;
+ *y = bb_y;
+ *w = bb_w;
+ *h = bb_h;
}
int
PostscriptDSC::get_pages() {
- return pages;
+ return pages;
}
size_t
PostscriptDSC::get_setup_len() {
- return setup_len;
+ return setup_len;
}
size_t
PostscriptDSC::get_page_off(int p) {
- if (p < 1 || p > pages) {
- return 0;
- } else {
- return page_off[p - 1];
- }
+ if (p < 1 || p > pages) {
+ return 0;
+ } else {
+ return page_off[p - 1];
+ }
}
size_t
PostscriptDSC::get_page_len(int p) {
- if (p < 1 || p > pages) {
- return 0;
- } else {
- return page_len[p - 1];
- }
+ if (p < 1 || p > pages) {
+ return 0;
+ } else {
+ return page_len[p - 1];
+ }
}
void
PostscriptDSC::print() {
- int i;
+ int i;
- 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++) {
- printf("p %d, off %d, len %d\n", i, page_off[i], page_len[i]);
- }
+ 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++) {
+ 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 04f402e..5d8cc07 100644
--- a/src/flpsed.cxx
+++ b/src/flpsed.cxx
@@ -45,28 +45,28 @@ int xev_handler(int ev) {
void save_cb();
int check_save(void) {
- if (!psed_p->modified()) return 1;
+ if (!psed_p->modified()) return 1;
- int r = fl_choice("The current file has not been saved.\n"
- "Would you like to save it now?",
- "Cancel", "Save", "Discard");
+ int r = fl_choice("The current file has not been saved.\n"
+ "Would you like to save it now?",
+ "Cancel", "Save", "Discard");
- if (r == 1) {
- save_cb(); // Save the file...
- return !psed_p->modified();
- }
+ if (r == 1) {
+ save_cb(); // Save the file...
+ return !psed_p->modified();
+ }
- return (r == 2) ? 1 : 0;
+ return (r == 2) ? 1 : 0;
}
static int
confirm_overwrite(const char *f) {
- struct stat sb;
- if (stat(f, &sb) == 0) {
- return fl_choice("The file exists.\n", "Cancel", "Overwrite", NULL);
- } else {
- return 1;
- }
+ struct stat sb;
+ if (stat(f, &sb) == 0) {
+ return fl_choice("The file exists.\n", "Cancel", "Overwrite", NULL);
+ } else {
+ return 1;
+ }
}
char filename[256] = "";
@@ -74,9 +74,9 @@ char filename[256] = "";
void page_sel_cb(Fl_Widget *w, void *) {
int p = page_sel->value();
- if (p > 0) {
- psed_p->load_page(page_sel->value());
- }
+ if (p > 0) {
+ psed_p->load_page(page_sel->value());
+ }
}
void page_sel_fill() {
@@ -179,7 +179,7 @@ void export_pdf_cb() {
perror("pexecvp");
}
- signal(SIGPIPE, SIG_DFL);
+ signal(SIGPIPE, SIG_DFL);
}
}
@@ -230,10 +230,10 @@ void print_cb() {
close(tmp_fd);
if (psed_p->save(tmpname) != 0) {
fprintf(stderr, "Failed to print file\n");
- } else {
- snprintf(buf, 256, "lpr %s", tmpname);
- system(buf);
- }
+ } else {
+ snprintf(buf, 256, "lpr %s", tmpname);
+ system(buf);
+ }
unlink(tmpname);
}
}
@@ -241,8 +241,8 @@ void print_cb() {
void about_cb() {
fl_message("flpsed -- a PostScript annotator\n"
"Version %s\n\n"
- "(c) Johannes Hofmann 2004-2006\n\n"
- "PostScript is a registered trademark of Adobe Systems", VERSION);
+ "(c) Johannes Hofmann 2004-2006\n\n"
+ "PostScript is a registered trademark of Adobe Systems", VERSION);
}
Fl_Choice *size_c;
@@ -352,10 +352,10 @@ Fl_Menu_Item menuitems[] = {
{ 0 },
{ "&Zoom", 0, 0, 0, FL_SUBMENU },
- { "50 %", 0, (Fl_Callback *)zoom_cb },
+ { "50 %", 0, (Fl_Callback *)zoom_cb },
{ "75 %", 0, (Fl_Callback *)zoom_cb },
{ "100 %", 0, (Fl_Callback *)zoom_cb },
- { "150 %", 0, (Fl_Callback *)zoom_cb },
+ { "150 %", 0, (Fl_Callback *)zoom_cb },
{ "200 %", 0, (Fl_Callback *)zoom_cb },
{ "250 %", 0, (Fl_Callback *)zoom_cb },
{ 0 },
@@ -468,7 +468,7 @@ int main(int argc, char** argv) {
if (err) {
usage();
exit(1);
- }
+ }
my_argc = argc - optind;
my_argv = argv + optind;
diff --git a/src/util.c b/src/util.c
index a5e7c02..8cf0608 100644
--- a/src/util.c
+++ b/src/util.c
@@ -12,48 +12,48 @@
FILE *
pexecvp(const char *file, char *const argv[], pid_t *pid, char *type) {
- FILE *iop;
- int pdes[2];
-
- if (pipe(pdes) < 0) {
- return NULL;
- }
-
- *pid = vfork();
-
- if (*pid == -1) {
- perror("vfork");
- close(pdes[0]);
- close(pdes[1]);
- return NULL;
- } else if (*pid == 0) {
- /* child */
-
- if (*type == 'r') {
- close(pdes[0]);
- if (pdes[1] != STDOUT_FILENO) {
- dup2(pdes[1], STDOUT_FILENO);
- close(pdes[1]);
- }
- } else {
- close(pdes[1]);
- if (pdes[0] != STDIN_FILENO) {
- dup2(pdes[0], STDIN_FILENO);
- close(pdes[0]);
- }
- }
-
- execvp(file, argv);
- exit(127);
- } else {
- /* parent */
- if (*type == 'r') {
- iop = fdopen(pdes[0], "r");
- close(pdes[1]);
- } else {
- iop = fdopen(pdes[1], "w");
- close(pdes[0]);
- }
- return iop;
- }
+ FILE *iop;
+ int pdes[2];
+
+ if (pipe(pdes) < 0) {
+ return NULL;
+ }
+
+ *pid = vfork();
+
+ if (*pid == -1) {
+ perror("vfork");
+ close(pdes[0]);
+ close(pdes[1]);
+ return NULL;
+ } else if (*pid == 0) {
+ /* child */
+
+ if (*type == 'r') {
+ close(pdes[0]);
+ if (pdes[1] != STDOUT_FILENO) {
+ dup2(pdes[1], STDOUT_FILENO);
+ close(pdes[1]);
+ }
+ } else {
+ close(pdes[1]);
+ if (pdes[0] != STDIN_FILENO) {
+ dup2(pdes[0], STDIN_FILENO);
+ close(pdes[0]);
+ }
+ }
+
+ execvp(file, argv);
+ exit(127);
+ } else {
+ /* parent */
+ if (*type == 'r') {
+ iop = fdopen(pdes[0], "r");
+ close(pdes[1]);
+ } else {
+ iop = fdopen(pdes[1], "w");
+ close(pdes[0]);
+ }
+ return iop;
+ }
}
diff --git a/src/util.h b/src/util.h
index 51e167e..9cceb6f 100644
--- a/src/util.h
+++ b/src/util.h
@@ -13,8 +13,8 @@
extern "C" {
#endif
-FILE *
-pexecvp(const char *file, char *const argv[], pid_t *pid, char *type);
+ FILE *
+ pexecvp(const char *file, char *const argv[], pid_t *pid, char *type);
#ifdef __cplusplus
}