summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/PSEditModel.H8
-rw-r--r--src/PSEditModel.cxx24
-rw-r--r--src/PSEditText.H59
-rw-r--r--src/PSEditText.cxx11
-rw-r--r--src/PSEditWidget.H15
-rw-r--r--src/PSEditWidget.cxx68
-rw-r--r--src/Postscript.H6
-rw-r--r--src/Postscript.cxx21
-rw-r--r--src/flpsed.cxx92
9 files changed, 264 insertions, 40 deletions
diff --git a/src/PSEditModel.H b/src/PSEditModel.H
index ca28f5a..d181814 100644
--- a/src/PSEditModel.H
+++ b/src/PSEditModel.H
@@ -1,5 +1,5 @@
//
-// "$Id: PSEditModel.H,v 1.11 2004/11/10 18:32:59 hofmann Exp $"
+// "$Id: PSEditModel.H,v 1.12 2005/06/17 18:20:42 hofmann Exp $"
//
// X11 header file for the Fast Light Tool Kit (FLTK).
//
@@ -43,7 +43,7 @@ public:
void clear();
- void new_text(int x1, int y1, const char *s, int size, int p);
+ void new_text(int x1, int y1, const char *s, int size, int p, PSEditColor *c);
void append_text(const char *s);
@@ -55,6 +55,10 @@ public:
int get_size();
+ void set_color(PSEditColor *c);
+
+ int get_color(PSEditColor *c);
+
void set_page(int p);
int get_page();
diff --git a/src/PSEditModel.cxx b/src/PSEditModel.cxx
index 8792414..e0028ce 100644
--- a/src/PSEditModel.cxx
+++ b/src/PSEditModel.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: PSEditModel.cxx,v 1.13 2005/02/28 17:56:51 hofmann Exp $"
+// "$Id: PSEditModel.cxx,v 1.14 2005/06/17 18:20:42 hofmann Exp $"
//
// PSEditWidget routines.
//
@@ -79,10 +79,11 @@ void PSEditModel::clear() {
}
}
-void PSEditModel::new_text(int x1, int y1, const char *s, int size, int p) {
+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);
+ cur_text = new PSEditText(x1, y1, s, size, c);
if (text[p]) {
text[p]->append(cur_text);
} else {
@@ -169,6 +170,23 @@ int PSEditModel::get_size() {
}
}
+void PSEditModel::set_color(PSEditColor *c) {
+ 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;
+ }
+}
+
int PSEditModel::get_max_pages() {
return max_pages;
diff --git a/src/PSEditText.H b/src/PSEditText.H
index ea35dd8..7d3d1b8 100644
--- a/src/PSEditText.H
+++ b/src/PSEditText.H
@@ -1,5 +1,5 @@
//
-// "$Id: PSEditText.H,v 1.4 2004/11/08 18:10:34 hofmann Exp $"
+// "$Id: PSEditText.H,v 1.5 2005/06/17 18:20:42 hofmann Exp $"
//
// X11 header file for the Fast Light Tool Kit (FLTK).
//
@@ -23,6 +23,56 @@
#ifndef PSEditText_H
#define PSEditText_H
+
+#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);
+ }
+
+
+};
+
class PSEditText;
class PSEditText {
@@ -35,11 +85,12 @@ class PSEditText {
PSEditText *next;
public:
- int c;
+
+ PSEditColor text_color;
int size;
- PSEditText(int x1, int y1, const char *s1, int size1);
+ PSEditText(int x1, int y1, const char *s1, int size1, PSEditColor *c);
~PSEditText();
@@ -65,8 +116,6 @@ public:
PSEditText *get_next();
- int get_color();
-
int get_x();
int get_y();
diff --git a/src/PSEditText.cxx b/src/PSEditText.cxx
index 001f3c1..0231807 100644
--- a/src/PSEditText.cxx
+++ b/src/PSEditText.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: PSEditText.cxx,v 1.2 2004/10/21 21:02:05 hofmann Exp $"
+// "$Id: PSEditText.cxx,v 1.3 2005/06/17 18:20:42 hofmann Exp $"
//
// PSEditWidget routines.
//
@@ -30,13 +30,14 @@
#include "PSEditText.H"
-PSEditText::PSEditText(int x1, int y1, const char *s1, int size1) {
+PSEditText::PSEditText(int x1, int y1, const char *s1,
+ int size1, PSEditColor *c) {
x = x1;
y = y1;
s = strdup(s1);
tag = NULL;
- c = 0;
size = size1;
+ text_color.set(c->r, c->g, c->b);
next = NULL;
}
@@ -133,10 +134,6 @@ int PSEditText::get_size() {
return size;
}
-int PSEditText::get_color() {
- return c;
-}
-
PSEditText* PSEditText::get_next() {
return next;
}
diff --git a/src/PSEditWidget.H b/src/PSEditWidget.H
index 689b938..f7cb3f5 100644
--- a/src/PSEditWidget.H
+++ b/src/PSEditWidget.H
@@ -1,5 +1,5 @@
//
-// "$Id: PSEditWidget.H,v 1.16 2005/06/05 19:57:57 hofmann Exp $"
+// "$Id: PSEditWidget.H,v 1.17 2005/06/17 18:20:42 hofmann Exp $"
//
// X11 header file for the Fast Light Tool Kit (FLTK).
//
@@ -27,16 +27,22 @@
#include "GsWidget.H"
#include "PSEditModel.H"
+typedef void (PSEditCallback)();
+
class PSText;
class PSEditWidget : public GsWidget {
private:
int cur_size;
+ PSEditColor cur_text_color;
+
int show_tags;
int zoom_percent;
+ PSEditCallback *property_changed_cb;
+
protected:
PSEditModel *model;
@@ -75,6 +81,10 @@ public:
int get_size();
+ void set_color(const PSEditColor *c);
+
+ void get_color(PSEditColor *c);
+
int get_max_pages();
char *get_tag();
@@ -95,6 +105,9 @@ public:
int zoom(int p);
+ void property_changed_callback(PSEditCallback *cb) {
+ property_changed_cb = cb;};
+
private:
int bb_x(PSEditText *t);
diff --git a/src/PSEditWidget.cxx b/src/PSEditWidget.cxx
index 6efccb8..d67ac94 100644
--- a/src/PSEditWidget.cxx
+++ b/src/PSEditWidget.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: PSEditWidget.cxx,v 1.36 2005/06/05 19:57:57 hofmann Exp $"
+// "$Id: PSEditWidget.cxx,v 1.37 2005/06/17 18:20:42 hofmann Exp $"
//
// PSEditWidget routines.
//
@@ -55,7 +55,11 @@ void PSEditWidget::draw() {
t_x = ps_to_display_x(t->get_x());
t_y = ps_to_display_y(t->get_y());
- fl_color((Fl_Color) t->get_color());
+ 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)) {
@@ -80,15 +84,29 @@ void PSEditWidget::draw() {
}
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;
}
int PSEditWidget::next() {
- model->set_page(page);
+ model->set_page(page);
+ PSEditText *t_new;
+
+ 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();
+ }
+ }
+
return GsWidget::next();
}
@@ -97,7 +115,7 @@ void PSEditWidget::new_text(int x1, int y1, const char *s, int p) {
t_old = model->get_cur_text();
- model->new_text(ps_x(x1), ps_y(y1), s, cur_size, p);
+ model->new_text(ps_x(x1), ps_y(y1), s, cur_size, p, &cur_text_color);
mod++;
t = model->get_cur_text();
@@ -125,11 +143,18 @@ int PSEditWidget::set_cur_text(int x1, int y1) {
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();
+ }
+
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;
@@ -146,13 +171,19 @@ int PSEditWidget::next_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();
+ }
+
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;
}
@@ -226,6 +257,11 @@ void PSEditWidget::rm_char() {
int PSEditWidget::reload() {
model->set_page(0);
+
+ if (property_changed_cb) {
+ property_changed_cb();
+ }
+
return GsWidget::reload();
}
@@ -262,6 +298,26 @@ int PSEditWidget::get_size() {
}
}
+void PSEditWidget::set_color(const PSEditColor *c) {
+ PSEditText *t;
+ uchar *p;
+
+ t = model->get_cur_text();
+
+ p = (uchar*) &c;
+ cur_text_color.set(c);
+
+ 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);
+}
+
int PSEditWidget::get_max_pages() {
return model->get_max_pages();
}
diff --git a/src/Postscript.H b/src/Postscript.H
index 62c9513..fd32103 100644
--- a/src/Postscript.H
+++ b/src/Postscript.H
@@ -1,5 +1,5 @@
//
-// "$Id: Postscript.H,v 1.6 2005/02/28 19:53:58 hofmann Exp $"
+// "$Id: Postscript.H,v 1.7 2005/06/17 18:20:42 hofmann Exp $"
//
// X11 header file for the Fast Light Tool Kit (FLTK).
//
@@ -33,6 +33,8 @@ class PSParser {
int cur_size;
+ PSEditColor cur_text_color;
+
int page;
public:
@@ -68,6 +70,8 @@ class PSWriter {
char * text_format;
+ char * color_format;
+
char * glyph_format;
char * tag_format;
diff --git a/src/Postscript.cxx b/src/Postscript.cxx
index c0270ab..691e994 100644
--- a/src/Postscript.cxx
+++ b/src/Postscript.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: Postscript.cxx,v 1.15 2005/04/19 20:29:58 hofmann Exp $"
+// "$Id: Postscript.cxx,v 1.16 2005/06/17 18:20:42 hofmann Exp $"
//
// Postscript handling routines.
//
@@ -29,6 +29,7 @@
#define PS_TEXT_FORMAT "(%s) show %% PSEditWidget\n"
#define PS_SIZE_FORMAT "/HelveticaNeue-Roman findfont %d scalefont setfont"\
" %% PSEditWidget\n"
+#define PS_COLOR_FORMAT "%lf %lf %lf setrgbcolor %% PSEditWidget\n"
#define PS_GLYPH_FORMAT "/%s glyphshow %% PSEditWidget\n"
#define PS_TAG_FORMAT ""
@@ -44,6 +45,7 @@
#define PSEDIT_TEXT_FORMAT_PRINT "%% PSEditWidget: TEXT (%s)\n"
#define PSEDIT_TEXT_FORMAT_SCAN "%% PSEditWidget: TEXT (%[^)])\n"
#define PSEDIT_SIZE_FORMAT "%% PSEditWidget: SIZE %d\n"
+#define PSEDIT_COLOR_FORMAT "%% PSEditWidget: COLOR %lf %lf %lf\n"
#define PSEDIT_GLYPH_FORMAT "%% PSEditWidget: GLYPH %s\n"
#define PSEDIT_TAG_FORMAT "%% PSEditWidget: TAG %s\n"
@@ -208,6 +210,7 @@ PSParser_1::PSParser_1(PSEditModel *p) : PSParser(p) {
int PSParser_1::parse(char *line) {
int x1, y1, size;
char *s, *e, glyph[1024];
+ PSEditColor c;
if (strcmp(line, "showpage\n") == 0) {
page++;
@@ -218,7 +221,7 @@ int PSParser_1::parse(char *line) {
cur_size = size;
return 1; // line was recognized
} else if (sscanf(line, PS_POS_FORMAT, &x1, &y1) == 2) {
- pse->new_text(x1, y1, "", cur_size, page);
+ pse->new_text(x1, y1, "", cur_size, page, &c);
return 1;
} else if (sscanf(line, PS_GLYPH_FORMAT, glyph) == 1) {
pse->append_text(glyph_to_char(glyph));
@@ -243,6 +246,7 @@ PSParser_2::PSParser_2(PSEditModel *p) : PSParser(p) {
int PSParser_2::parse(char *line) {
int x1, y1, size, dummy;
+ PSEditColor c;
char buf[2028];
if (!inside && strcmp(line, PSEDIT_BEGIN) == 0) {
@@ -256,8 +260,13 @@ int PSParser_2::parse(char *line) {
} 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) {
+ fprintf(stderr, "==> c %f %f %f\n", c.r, c.g, c.b);
+ 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);
+ 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));
@@ -325,6 +334,7 @@ void PSWriter::write_main_block(FILE *out) {
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;
@@ -350,6 +360,7 @@ void PSWriter::write_main_block(FILE *out) {
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;
@@ -398,6 +409,10 @@ int PSWriter::write_text(FILE *out, PSEditText *t) {
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());
diff --git a/src/flpsed.cxx b/src/flpsed.cxx
index d2d5cb6..ace258d 100644
--- a/src/flpsed.cxx
+++ b/src/flpsed.cxx
@@ -1,5 +1,5 @@
//
-// "$Id: flpsed.cxx,v 1.36 2005/05/25 18:50:39 hofmann Exp $"
+// "$Id: flpsed.cxx,v 1.37 2005/06/17 18:20:42 hofmann Exp $"
//
// flpsed program.
//
@@ -40,6 +40,7 @@
#include <FL/Fl_Int_Input.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Menu_Item.H>
+#include <FL/Fl_Color_Chooser.H>
#include "PSEditor.H"
#include "util.h"
@@ -212,6 +213,39 @@ void about_cb() {
"PostScript is a registered trademark of Adobe Systems");
}
+Fl_Choice *size_c;
+Fl_Button *color_b;
+
+struct {
+ char *label;
+ int size;
+} text_sizes[] = {
+ {"8", 8},
+ {"10", 10},
+ {"12", 12},
+ {"14", 14},
+ {"18", 18},
+ {"24", 24},
+ {NULL, 0}
+};
+
+void property_changed_cb() {
+ PSEditColor c;
+ int size;
+
+ psed_p->get_color(&c);
+ color_b->color(fl_rgb_color(c.get_r(), c.get_g(), c.get_b()));
+ color_b->redraw();
+
+ size = psed_p->get_size();
+ for (int i=0; text_sizes[i].label != NULL; i++) {
+ if (size == text_sizes[i].size) {
+ size_c->value(i);
+ size_c->redraw();
+ }
+ }
+}
+
void size_cb(Fl_Widget *w, void *) {
Fl_Menu_* mw = (Fl_Menu_*)w;
const Fl_Menu_Item* m = mw->mvalue();
@@ -220,6 +254,24 @@ void size_cb(Fl_Widget *w, void *) {
}
}
+void color_cb(Fl_Widget *w, void *v) {
+ uchar r, g, b;
+ PSEditColor pc;
+
+ psed_p->get_color(&pc);
+
+ r = pc.get_r();
+ g = pc.get_g();
+ b = pc.get_b();
+
+ if (!fl_color_chooser("Text Color", r, g, b)) return;
+ Fl_Button* button = (Fl_Button*)v;
+ pc.set(r, g, b);
+ psed_p->set_color(&pc);
+ button->color(fl_rgb_color(r, g, b));
+ button->parent()->redraw();
+}
+
void zoom_cb(Fl_Widget *w, void *) {
Fl_Menu_* mw = (Fl_Menu_*)w;
const Fl_Menu_Item* m = mw->mvalue();
@@ -275,15 +327,6 @@ Fl_Menu_Item menuitems[] = {
{ "250 %", 0, (Fl_Callback *)zoom_cb },
{ 0 },
- { "&Size", 0, 0, 0, FL_SUBMENU },
- { "8", 0, (Fl_Callback *)size_cb },
- { "10", 0, (Fl_Callback *)size_cb },
- { "12", 0, (Fl_Callback *)size_cb },
- { "14", 0, (Fl_Callback *)size_cb },
- { "18", 0, (Fl_Callback *)size_cb },
- { "24", 0, (Fl_Callback *)size_cb },
- { 0 },
-
{ "&Tags", 0, 0, 0, FL_SUBMENU },
{ "Show &Tags", FL_CTRL + 't', (Fl_Callback *)show_tags_cb, (void *)1, FL_MENU_RADIO|FL_MENU_VALUE},
{ "&Hide Tags", FL_CTRL + 'h', (Fl_Callback *)show_tags_cb, (void *)0, FL_MENU_RADIO},
@@ -296,7 +339,18 @@ Fl_Menu_Item menuitems[] = {
{ 0 }
};
-
+
+
+
+Fl_Menu_Item size_menu[] = {
+{ text_sizes[0].label, 0, (Fl_Callback *)size_cb },
+{ text_sizes[1].label, 0, (Fl_Callback *)size_cb },
+{ text_sizes[2].label, 0, (Fl_Callback *)size_cb },
+{ text_sizes[3].label, 0, (Fl_Callback *)size_cb },
+{ text_sizes[4].label, 0, (Fl_Callback *)size_cb },
+{ text_sizes[5].label, 0, (Fl_Callback *)size_cb },
+{ 0 }
+};
void usage() {
fprintf(stderr,
@@ -440,8 +494,22 @@ int main(int argc, char** argv) {
win = new Fl_Window(600,700);
m = new Fl_Menu_Bar(0, 0, 600, 30);
m->menu(menuitems);
- scroll = new Fl_Scroll(0, 30, win->w(), win->h()-30);
+
+ Fl_Box b(FL_UP_BOX, 0, 30, 600, 25, "");
+ size_c = new Fl_Choice(30, 32, 50, 21, NULL);
+ size_c->menu(size_menu);
+ size_c->callback(size_cb);
+ size_c->tooltip("Text Size");
+
+ color_b = new Fl_Button(100, 32, 21, 21);
+ color_b->color(FL_BLACK);
+ color_b->callback(color_cb, color_b);
+ color_b->shortcut(FL_ALT + 'c');
+ color_b->tooltip("Text Color");
+
+ scroll = new Fl_Scroll(0, 55, win->w(), win->h()-55);
psed_p = new PSEditor(0, 0, 700, 900);
+ psed_p->property_changed_callback(property_changed_cb);
scroll->end();
fl_open_display();