From 382846248e84c478f713deabbb05a18c1a0d6951 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Thu, 21 Oct 2004 17:55:36 +0000 Subject: separated model out from PSEditWidget separated model out from PSEditWidget --- src/PSEditModel.H | 62 +++++++++++++ src/PSEditModel.cxx | 184 +++++++++++++++++++++++++++++++++++++++ src/PSEditText.H | 56 ++++++++++++ src/PSEditText.cxx | 137 +++++++++++++++++++++++++++++ src/PSEditWidget.H | 43 +-------- src/PSEditWidget.cxx | 241 +++++++-------------------------------------------- src/PSEditor.cxx | 14 +-- src/Postscript.H | 25 +++--- src/Postscript.cxx | 28 +++--- src/flpsed.cxx | 59 +++++++++---- 10 files changed, 552 insertions(+), 297 deletions(-) create mode 100644 src/PSEditModel.H create mode 100644 src/PSEditModel.cxx create mode 100644 src/PSEditText.H create mode 100644 src/PSEditText.cxx (limited to 'src') diff --git a/src/PSEditModel.H b/src/PSEditModel.H new file mode 100644 index 0000000..2d3f780 --- /dev/null +++ b/src/PSEditModel.H @@ -0,0 +1,62 @@ +// +// "$Id: PSEditModel.H,v 1.1 2004/10/21 19:55:36 hofmann Exp $" +// +// X11 header file for the Fast Light Tool Kit (FLTK). +// +// Copyright 2004 by Johannes Hofmann +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// + +#ifndef PSEditModel_H +#define PSEditModel_H + +#include "PSEditText.H" + +class PSEditModel { + PSEditText **text; + int max_pages; + int page; + PSEditText *cur_text; + float xdpi, ydpi; + int paper_x, paper_y; + + +public: + PSEditModel(int x1, int y1, float dx, float dy); + ~PSEditModel(); + + void clear(); + void new_text(int x1, int y1, const char *s, int size, int p); + void append_text(const char *s); + void move(int x1, int y1); + void rm_char(); + void set_size(int s); + int get_size(); + void set_page(int p); + int get_page(); + char *get_tag(); + int set_tag(const char *t); + int get_max_pages(); + int set_cur_text(int x1, int y1, int p); + PSEditText *get_text(int p); + 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/PSEditModel.cxx b/src/PSEditModel.cxx new file mode 100644 index 0000000..9e12d7a --- /dev/null +++ b/src/PSEditModel.cxx @@ -0,0 +1,184 @@ +// +// "$Id: PSEditModel.cxx,v 1.1 2004/10/21 19:55:36 hofmann Exp $" +// +// PSEditWidget routines. +// +// Copyright 2004 by Johannes Hofmann +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// + +#include +#include +#include +#include +#include + +#include "PSEditText.H" +#include "PSEditModel.H" + + +PSEditModel::PSEditModel(int x1, int y1, float dx, float dy) { + paper_x = x1; + paper_y = y1; + xdpi = dx; + ydpi = dy; + max_pages = 32; + 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; + + old_max_pages = max_pages; + + if (p >= max_pages) { + 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; + } + } + + 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; + } + } +} + +void PSEditModel::new_text(int x1, int y1, const char *s, int size, int p) { + cur_text = new PSEditText(x1, y1, s, size); + if (text[p]) { + text[p]->append(cur_text); + } else { + text[p] = cur_text; + } +} + +int PSEditModel::set_cur_text(int x1, int y1, int p) { + if (p < 0 || p >= max_pages) { + return 1; + } + + if (text[p]) { + cur_text = text[p]->get_match(x1, y1); + if (cur_text) { + return 0; + } + } + return 1; +} + +void PSEditModel::append_text(const char *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); + } +} + + +void PSEditModel::rm_char() { + if (cur_text) { + cur_text->rm_char(); + } +} + + +void PSEditModel::set_size(int s) { + if (cur_text) { + cur_text->size = s; + } +} + +int PSEditModel::get_size() { + if (cur_text) { + return cur_text->size; + } else { + return -1; + } +} + + +int PSEditModel::get_max_pages() { + return max_pages; +} + +int PSEditModel::set_tag(const char *t) { + 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; + } +} + +PSEditText *PSEditModel::get_text(int p) { + if (p >= max_pages) { + return 0; + } else { + return text[p]; + } +} + +int PSEditModel::ps_to_display_x(int x1) { + return (int) ((float) x1 * xdpi / 72.0); +} + +int PSEditModel::ps_to_display_y(int y1) { + return (int) ((float) (paper_y - y1) * xdpi / 72.0); +} + +int PSEditModel::ps_x(int x1) { + return (int) ((float) x1 * 72.0 / xdpi); +} + +int PSEditModel::ps_y(int y1) { + return paper_y - (int)((float) y1 * 72.0 / ydpi); +} diff --git a/src/PSEditText.H b/src/PSEditText.H new file mode 100644 index 0000000..a695b5e --- /dev/null +++ b/src/PSEditText.H @@ -0,0 +1,56 @@ +// +// "$Id: PSEditText.H,v 1.1 2004/10/21 19:55:36 hofmann Exp $" +// +// X11 header file for the Fast Light Tool Kit (FLTK). +// +// Copyright 2004 by Johannes Hofmann +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// + +#ifndef PSEditText_H +#define PSEditText_H +class PSEditText; + +class PSEditText { + int x, y; + char *s; + char *tag; + PSEditText *next; + +public: + int c; + int size; + + PSEditText(int x1, int y1, const char *s1, int size1); + ~PSEditText(); + void append_text(const char*s1); + void rm_char(); + void move(int x1, int y1); + void append(PSEditText *g); + PSEditText *get_match(int x1, int y1); + char *get_text(); + char *get_tag(); + int set_tag(const char *t); + int get_size(); + PSEditText *get_next(); + int get_color(); + int get_x(); + int get_y(); + void draw(int off_x,int off_y); +}; + +#endif diff --git a/src/PSEditText.cxx b/src/PSEditText.cxx new file mode 100644 index 0000000..309fb0c --- /dev/null +++ b/src/PSEditText.cxx @@ -0,0 +1,137 @@ +// +// "$Id: PSEditText.cxx,v 1.1 2004/10/21 19:55:36 hofmann Exp $" +// +// PSEditWidget routines. +// +// Copyright 2004 by Johannes Hofmann +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// + +#include +#include +#include +#include +#include + +#include "PSEditText.H" + + +PSEditText::PSEditText(int x1, int y1, const char *s1, int size1) { + x = x1; + y = y1; + s = strdup(s1); + tag = NULL; + c = 0; + size = size1; + next = NULL; +} + +PSEditText::~PSEditText() { + 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; +} + +void PSEditText::rm_char() { + if (s && strlen(s) > 0) { + s[strlen(s) - 1] = '\0'; + } +} + +void PSEditText::move(int x1, int y1) { + x = x1; + y = y1; +} + +void PSEditText::append(PSEditText *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; + } +} + +char *PSEditText::get_text() { + return s; +} + +char *PSEditText::get_tag() { + return tag; +} + +int PSEditText::set_tag(const char *t) { + if (tag) { + free(tag); + } + if (t) { + tag = strdup(t); + } else { + tag = NULL; + } + + return 0; +} + +int PSEditText::get_size() { + return size; +} + +int PSEditText::get_color() { + return c; +} + +PSEditText* PSEditText::get_next() { + return next; +} + +int PSEditText::get_x() { + return x; +} + +int PSEditText::get_y() { + return y; +} diff --git a/src/PSEditWidget.H b/src/PSEditWidget.H index afb3021..5f196cd 100644 --- a/src/PSEditWidget.H +++ b/src/PSEditWidget.H @@ -1,5 +1,5 @@ // -// "$Id: PSEditWidget.H,v 1.7 2004/10/12 20:52:23 hofmann Exp $" +// "$Id: PSEditWidget.H,v 1.8 2004/10/21 19:55:36 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -25,25 +25,23 @@ #define PSEditWidget_H #include "GsWidget.H" +#include "PSEditModel.H" class PSText; class PSEditWidget : public GsWidget { private: - PSText **text; - int max_pages; int cur_size; int show_tags; protected: + PSEditModel *model; int loaded; int mod; void clear_text(); void draw(); public: - PSText *cur_text; - PSEditWidget(int X,int Y,int W, int H); int next(); void new_text(int x1, int y1, const char *s, int p); @@ -52,10 +50,6 @@ public: void append_text(const char *s); void move(int x1, int y1); void rm_char(); - int ps_to_display_x(int x1); - int ps_to_display_y(int y1); - int ps_x(int x1); - int ps_y(int y1); int reload(); void set_cur_size(int s); void set_size(int s); @@ -68,36 +62,7 @@ public: PSText * get_text(int p); int modified(); int file_loaded(); -}; - - -class PSText { - int x, y; - char *s; - char *tag; - PSText *next; - PSEditWidget *gsew; - -public: - Fl_Color c; - int size; - - PSText(PSEditWidget *g, int x1, int y1, const char *s1, int size1); - ~PSText(); - void append_text(const char*s1); - void rm_char(); - void move(int x1, int y1); - void append(PSText *g); - PSText *get_match(int x1, int y1); - char *get_text(); - char *get_tag(); - int set_tag(const char *t); - int get_size(); - PSText *get_next(); - Fl_Color get_color(); - int get_x(); - int get_y(); - void draw(int off_x,int off_y); + int replace_tag(char* tag, char* text); }; #endif diff --git a/src/PSEditWidget.cxx b/src/PSEditWidget.cxx index c10d550..ef8431c 100644 --- a/src/PSEditWidget.cxx +++ b/src/PSEditWidget.cxx @@ -1,5 +1,5 @@ // -// "$Id: PSEditWidget.cxx,v 1.17 2004/10/13 18:03:08 hofmann Exp $" +// "$Id: PSEditWidget.cxx,v 1.18 2004/10/21 19:55:36 hofmann Exp $" // // PSEditWidget routines. // @@ -38,52 +38,27 @@ #include "PSEditWidget.H" void PSEditWidget::clear_text() { - cur_text = NULL; - for (int i = 0; i < max_pages; i++) { - if (text[i]) { - delete(text[i]); - text[i] = NULL; - } - } + model->clear(); } void PSEditWidget::draw() { GsWidget::draw(); - if (text[page]) { - text[page]->draw(x() ,y()); - } + } PSEditWidget::PSEditWidget(int X,int Y,int W, int H) : GsWidget(X, Y, W, H) { - max_pages = 32; - text = (PSText**) malloc(sizeof(PSText*) * max_pages); - for (int i = 0; i < max_pages; i++) { - text[i] = NULL; - } - cur_text = NULL; + model = new PSEditModel(paper_x, paper_y, xdpi, ydpi); cur_size = 12; show_tags = 1; } int PSEditWidget::next() { - if (page >= max_pages) { - max_pages = max_pages * 2; - text = (PSText**) realloc(text, sizeof(PSText*) * max_pages); - for (int i = max_pages / 2; i < max_pages; i++) { - text[i] = NULL; - } - } - cur_text = NULL; + model->set_page(page); return GsWidget::next(); } void PSEditWidget::new_text(int x1, int y1, const char *s, int p) { - cur_text = new PSText(this, x1, y1, s, cur_size); - if (text[p]) { - text[p]->append(cur_text); - } else { - text[p] = cur_text; - } + model->new_text(x1, y1, s, cur_size, p); redraw(); } @@ -92,55 +67,31 @@ void PSEditWidget::new_text(int x1, int y1, const char *s) { } int PSEditWidget::set_cur_text(int x1, int y1) { - if (text[page]) { - cur_text = text[page]->get_match(x1, y1); - if (cur_text) { - redraw(); - return 0; - } + if (model->set_cur_text(x1, y1, page) == 0) { + redraw(); + return 0; } return 1; } void PSEditWidget::append_text(const char *s) { - if (cur_text && s) { - cur_text->append_text(s); - redraw(); - } + model->append_text(s); + redraw(); } void PSEditWidget::move(int x1, int y1) { - if (cur_text) { - cur_text->move(x1, y1); - redraw(); - } + model->move(x1, y1); + redraw(); } void PSEditWidget::rm_char() { - if (cur_text) { - cur_text->rm_char(); - redraw(); - } -} - -int PSEditWidget::ps_to_display_x(int x1) { - return (int) ((float) x1 * xdpi / 72.0); -} - -int PSEditWidget::ps_to_display_y(int y1) { - return (int) ((float) (paper_y - y1) * xdpi / 72.0); -} - -int PSEditWidget::ps_x(int x1) { - return (int) ((float) x1 * 72.0 / xdpi); + model->rm_char(); + redraw(); } -int PSEditWidget::ps_y(int y1) { - return paper_y - (int)((float) y1 * 72.0 / ydpi); -} int PSEditWidget::reload() { - cur_text = NULL; + model->set_page(0); return GsWidget::reload(); } @@ -150,23 +101,23 @@ void PSEditWidget::set_cur_size(int s) { void PSEditWidget::set_size(int s) { set_cur_size(s); - if (cur_text) { - cur_text->size = s; - redraw(); - } + model->set_size(s); + redraw(); } int PSEditWidget::get_size() { - if (cur_text) { - return cur_text->size; + int s; + + s = model->get_size(); + if (s >= 0) { + return s; } else { return cur_size; } } - int PSEditWidget::get_max_pages() { - return max_pages; + return model->get_max_pages(); } int PSEditWidget::get_show_tags() { @@ -178,29 +129,17 @@ void PSEditWidget::set_show_tags(int s) { redraw(); } -PSText *PSEditWidget::get_text(int p) { - if (p >= max_pages) { - return 0; - } else { - return text[p]; - } -} - int PSEditWidget::set_tag(const char *t) { - if (cur_text) { + if (model->set_tag(t) == 0) { mod++; - return cur_text->set_tag(t); + return 0; } else { return 1; } } char *PSEditWidget::get_tag() { - if (cur_text) { - return cur_text->get_tag(); - } else { - return NULL; - } + return model->get_tag(); } int PSEditWidget::modified() { @@ -211,131 +150,9 @@ int PSEditWidget::file_loaded() { return loaded; } -PSText::PSText(PSEditWidget *g, int x1, int y1, const char *s1, int size1) { - x = x1; - y = y1; - s = strdup(s1); - tag = NULL; - c = FL_BLACK; - size = size1; - next = NULL; - gsew = g; -} +int PSEditWidget::replace_tag(char *tag, char *text) { + fprintf(stderr, "%s => %s\n", tag, text); -PSText::~PSText() { - if (next) { - delete(next); - } - if (s) { - free(s); - } - if (tag) { - free(tag); - } -} - -void PSText::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; -} - -void PSText::rm_char() { - if (s && strlen(s) > 0) { - s[strlen(s) - 1] = '\0'; - } -} - -void PSText::move(int x1, int y1) { - x = x1; - y = y1; -} - -void PSText::append(PSText *g) { - PSText *p = this; - while (p->next) { - p = p->next; - } - p->next = g; -} - -PSText *PSText::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; - } -} - -void PSText::draw(int off_x,int off_y) { - PSText *p = this; - fl_color(c); - fl_font(FL_HELVETICA, size); - fl_draw(s, x + off_x, y + off_y); - if (gsew->cur_text == this) { - fl_draw_box(FL_BORDER_FRAME, x+off_x-1, y+off_y-fl_height()+fl_descent(), - (int) fl_width(s)+2, fl_height(), FL_BLACK); - } - - if (tag && gsew->get_show_tags()) { - int text_height = fl_height() - fl_descent(); - fl_color(FL_BLUE); - fl_font(FL_COURIER, 10); - fl_draw(tag, x + off_x, y + off_y - text_height - 1); - } - - if (p->next) { - p->next->draw(off_x, off_y); - } -} - -char *PSText::get_text() { - return s; -} - -char *PSText::get_tag() { - return tag; -} - -int PSText::set_tag(const char *t) { - if (tag) { - free(tag); - } - if (t) { - tag = strdup(t); - } else { - tag = NULL; - } - gsew->redraw(); return 0; } -int PSText::get_size() { - return size; -} - -Fl_Color PSText::get_color() { - return c; -} - -PSText* PSText::get_next() { - return next; -} - -int PSText::get_x() { - return x; -} - -int PSText::get_y() { - return y; -} diff --git a/src/PSEditor.cxx b/src/PSEditor.cxx index 8e9de8b..64b4a6f 100644 --- a/src/PSEditor.cxx +++ b/src/PSEditor.cxx @@ -1,5 +1,5 @@ // -// "$Id: PSEditor.cxx,v 1.11 2004/10/12 20:52:23 hofmann Exp $" +// "$Id: PSEditor.cxx,v 1.12 2004/10/21 19:55:36 hofmann Exp $" // // PSEditor routines. // @@ -110,8 +110,8 @@ int PSEditor::load(char *f) { char tmpname[256]; char linebuf[1024]; int ret; - PSParser *p1 = new PSParser_1(this); - PSParser *p2 = new PSParser_2(this); + PSParser *p1 = new PSParser_1(model); + PSParser *p2 = new PSParser_2(model); fp = fopen(f, "r"); if (!fp) { @@ -161,9 +161,9 @@ int PSEditor::save(const char* savefile) { PSWriter *pw; if (ps_level == 2) { - pw = new PSLevel2Writer(this); + pw = new PSLevel2Writer(model); } else { - pw = new PSLevel1Writer(this); + pw = new PSLevel1Writer(model); } pw->write(fp, sfp); @@ -192,8 +192,8 @@ int PSEditor::import(char *f) { return 1; } - p1 = new PSParser_1(this); - p2 = new PSParser_2(this); + p1 = new PSParser_1(model); + p2 = new PSParser_2(model); while (fgets(linebuf, 1024, fp) != NULL) { if (!p2->parse(linebuf)) { p1->parse(linebuf); diff --git a/src/Postscript.H b/src/Postscript.H index 72c4492..d9c436f 100644 --- a/src/Postscript.H +++ b/src/Postscript.H @@ -1,5 +1,5 @@ // -// "$Id: Postscript.H,v 1.3 2004/10/13 18:03:08 hofmann Exp $" +// "$Id: Postscript.H,v 1.4 2004/10/21 19:55:36 hofmann Exp $" // // X11 header file for the Fast Light Tool Kit (FLTK). // @@ -24,22 +24,23 @@ #ifndef POSTSCRIPT_H #define POSTSCRIPT_H -#include "PSEditWidget.H" - +#include +#include "PSEditModel.H" class PSParser { protected: - PSEditWidget *pse; + PSEditModel *pse; + int cur_size; int page; public: - PSParser(PSEditWidget *p); + PSParser(PSEditModel *p); virtual int parse(char *line); }; class PSParser_1 : public PSParser { public: - PSParser_1(PSEditWidget *p); + PSParser_1(PSEditModel *p); int parse(char *line); }; @@ -48,13 +49,13 @@ class PSParser_2 : public PSParser { int inside; public: - PSParser_2(PSEditWidget *p); + PSParser_2(PSEditModel *p); int parse(char *line); }; class PSWriter { protected: - PSEditWidget *pse; + PSEditModel *pse; char * pos_format; char * size_format; char * text_format; @@ -62,12 +63,12 @@ class PSWriter { char * tag_format; void write_string(FILE *out, char *s); void write_internal_format(FILE *out); - int write_text(FILE *out, PSText *t); + int write_text(FILE *out, PSEditText *t); virtual char *ps_header(); virtual char *ps_trailer(); public: - PSWriter(PSEditWidget *p); + PSWriter(PSEditModel *p); int write(FILE *in, FILE *out); }; @@ -76,7 +77,7 @@ class PSLevel1Writer : public PSWriter { char *ps_header(); char *ps_trailer(); public: - PSLevel1Writer(PSEditWidget *p); + PSLevel1Writer(PSEditModel *p); }; class PSLevel2Writer : public PSWriter { @@ -84,7 +85,7 @@ class PSLevel2Writer : public PSWriter { char *ps_header(); char *ps_trailer(); public: - PSLevel2Writer(PSEditWidget *p); + PSLevel2Writer(PSEditModel *p); }; diff --git a/src/Postscript.cxx b/src/Postscript.cxx index 5461483..61021ce 100644 --- a/src/Postscript.cxx +++ b/src/Postscript.cxx @@ -1,5 +1,5 @@ // -// "$Id: Postscript.cxx,v 1.9 2004/10/13 18:03:08 hofmann Exp $" +// "$Id: Postscript.cxx,v 1.10 2004/10/21 19:55:36 hofmann Exp $" // // Postscript handling routines. // @@ -21,6 +21,8 @@ // USA. // +#include +#include #include "Postscript.H" #define PS_POS_FORMAT "newpath %d %d moveto %% PSEditWidget\n" @@ -94,8 +96,9 @@ static const char * char_to_glyph(char *c) { return NULL; } -PSParser::PSParser(PSEditWidget *p) { +PSParser::PSParser(PSEditModel *p) { pse = p; + cur_size = 12; } int PSParser::parse(char *line) { @@ -103,7 +106,7 @@ int PSParser::parse(char *line) { } -PSParser_1::PSParser_1(PSEditWidget *p) : PSParser(p) { +PSParser_1::PSParser_1(PSEditModel *p) : PSParser(p) { page = 1; } @@ -117,11 +120,11 @@ int PSParser_1::parse(char *line) { if (strstr(line, "% PSEditWidget")) { if (sscanf(line, PS_SIZE_FORMAT, &size) == 1) { - pse->set_cur_size(size); + cur_size = size; return 1; // line was recognized } else if (sscanf(line, PS_POS_FORMAT, &x1, &y1) == 2) { pse->new_text(pse->ps_to_display_x(x1), pse->ps_to_display_y(y1), - "", page); + "", cur_size, page); return 1; } else if (sscanf(line, PS_GLYPH_FORMAT, glyph) == 1) { pse->append_text(glyph_to_char(glyph)); @@ -139,7 +142,7 @@ int PSParser_1::parse(char *line) { } } -PSParser_2::PSParser_2(PSEditWidget *p) : PSParser(p) { +PSParser_2::PSParser_2(PSEditModel *p) : PSParser(p) { page = 1; inside = 0; } @@ -157,10 +160,11 @@ int PSParser_2::parse(char *line) { } else if (inside && sscanf(line, PSEDIT_PAGE_FORMAT, &page) == 1) { return 1; } else if (inside && sscanf(line, PSEDIT_SIZE_FORMAT, &size) == 1) { - pse->set_cur_size(size); + cur_size = size; return 1; } else if (inside && sscanf(line, PSEDIT_POS_FORMAT, &x1, &y1) == 2) { - pse->new_text(pse->ps_to_display_x(x1), pse->ps_to_display_y(y1),"",page); + pse->new_text(pse->ps_to_display_x(x1), pse->ps_to_display_y(y1),"", + cur_size, page); return 1; } else if (inside && sscanf(line, PSEDIT_GLYPH_FORMAT, buf) == 1) { pse->append_text(glyph_to_char(buf)); @@ -186,7 +190,7 @@ int PSParser_2::parse(char *line) { // -PSWriter::PSWriter(PSEditWidget *p) { +PSWriter::PSWriter(PSEditModel *p) { pse = p; } @@ -278,7 +282,7 @@ void PSWriter::write_string(FILE *out, char *s) { return; } -int PSWriter::write_text(FILE *out, PSText *t) { +int PSWriter::write_text(FILE *out, PSEditText *t) { char *s; if (!t) { @@ -314,7 +318,7 @@ char * PSWriter::ps_trailer() { return ""; } -PSLevel1Writer::PSLevel1Writer(PSEditWidget *p) : PSWriter(p) {}; +PSLevel1Writer::PSLevel1Writer(PSEditModel *p) : PSWriter(p) {}; char * PSLevel1Writer::ps_header() { return \ @@ -335,7 +339,7 @@ char * PSLevel1Writer::ps_trailer() { } -PSLevel2Writer::PSLevel2Writer(PSEditWidget *p) : PSWriter(p) {}; +PSLevel2Writer::PSLevel2Writer(PSEditModel *p) : PSWriter(p) {}; char * PSLevel2Writer::ps_header() { return \ diff --git a/src/flpsed.cxx b/src/flpsed.cxx index eb85736..802ad94 100644 --- a/src/flpsed.cxx +++ b/src/flpsed.cxx @@ -1,5 +1,5 @@ // -// "$Id: flpsed.cxx,v 1.16 2004/10/13 18:03:08 hofmann Exp $" +// "$Id: flpsed.cxx,v 1.17 2004/10/21 19:55:36 hofmann Exp $" // // flpsed program. // @@ -202,27 +202,56 @@ Fl_Menu_Item menuitems[] = { }; int main(int argc, char** argv) { - Fl_Window window(600,700); - Fl_Menu_Bar* m = new Fl_Menu_Bar(0, 0, 600, 30); + char c, *sep, *tmp; + int err; + Fl_Window *win; + Fl_Menu_Bar* m; + Fl_Scroll *scroll; + + win = new Fl_Window(600,700); + m = new Fl_Menu_Bar(0, 0, 600, 30); m->menu(menuitems); - - Fl_Scroll scroll(0, 30, window.w(), window.h()-30); + scroll = new Fl_Scroll(0, 30, win->w(), win->h()-30); gsw_p = new PSEditor(0, 0, 700, 900); - scroll.end(); + scroll->end(); + fl_open_display(); Fl::add_handler(xev_handler); - window.resizable(scroll); - - window.end(); - window.callback((Fl_Callback *)quit_cb); - window.show(1, argv); - - + win->resizable(scroll); + + win->end(); + win->callback((Fl_Callback *)quit_cb); + win->show(1, argv); + + err = 0; + while ((c = getopt(argc, argv, "t:")) != EOF) { + switch (c) { + case 't': + tmp = strdup(optarg); + if (!tmp) { + perror("strdup"); + exit(1); + } + sep = strchr(tmp, '='); + if (!sep) { + fprintf(stderr, "Cannot parse %s\n", optarg); + free(tmp); + continue; + } + *sep = '\0'; + gsw_p->replace_tag(tmp, sep+1); + free(tmp); + break; + default: + err++; + } + } - if (argc >= 2) { - gsw_p->load(argv[1]); + if (err) { + exit(1); } + return Fl::run(); } -- cgit v1.2.3