00001
00002 #ifndef vul_psfile_h_
00003 #define vul_psfile_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <vcl_string.h>
00016 #include <vcl_fstream.h>
00017
00018
00019 class vul_psfile: public vcl_ofstream
00020 {
00021 public:
00022 enum paper_type {
00023 US_NORMAL,
00024 A4,
00025 B5,
00026 A3,
00027 US_LEGAL,
00028 ELEVEN_BY_SEVENTEEN,
00029 FOUR_BY_FIVE,
00030 THIRTY_FIVE_mm};
00031 enum paper_orientation{
00032 PORTRAIT,
00033 LANDSCAPE };
00034 enum paper_layout{
00035 CENTER,
00036 MAX };
00037
00038 vul_psfile(char const* filename, bool debug_output=false);
00039 ~vul_psfile();
00040 operator bool() { return (void*)output_filestream!=(void*)0; }
00041
00042 void set_paper_type(vul_psfile::paper_type type){printer_paper_type = type;}
00043 void set_paper_layout(vul_psfile::paper_layout layout) {printer_paper_layout = layout;}
00044 void set_paper_orientation(vul_psfile::paper_orientation o) {printer_paper_orientation = o;}
00045 void set_reduction_factor(int rf) {reduction_factor = rf;}
00046
00047 void set_scale_x(float sx) {scale_x = sx * .01f;}
00048
00049 void set_scale_y(float sy) {scale_y = sy * .01f;}
00050 void set_fg_color(float r, float g, float b) {fg_r = r; fg_g = g; fg_b = b;}
00051 void set_bg_color(float r, float g, float b) {bg_r = r; bg_g = g; bg_b = b;}
00052 void set_line_width(float f_width) {line_width_ = f_width;}
00053 float line_width() const { return line_width_; }
00054
00055
00056 void print_greyscale_image(unsigned char* data, int sizex, int sizey);
00057
00058 void print_color_image(unsigned char* data, int sizex, int sizey);
00059
00060
00061 void line(float x1, float y1, float x2, float y2);
00062
00063 void point(float x, float y, float point_size = 0);
00064
00065 void ellipse(float x, float y, float a_axis, float b_axis, int angle = 0);
00066
00067 void circle(float x, float y, float radius);
00068
00069 protected:
00070 void set_min_max_xy(float x, float y);
00071 void set_min_max_xy(int x, int y);
00072 bool set_parameters(int sizex, int sizey);
00073
00074
00075 void postscript_header();
00076
00077
00078 void graphic_header();
00079
00080 void sobj_rgb_params(char const* str, bool filled);
00081
00082 void print_graphics_prolog();
00083
00084 private:
00085 void compute_bounding_box();
00086 void reset_bounding_box();
00087 void reset_postscript_header();
00088 void image_translate_and_scale();
00089 void object_translate_and_scale();
00090 void done();
00091
00092 vcl_ofstream output_filestream;
00093
00094 float fg_r, fg_g, fg_b;
00095 float bg_r, bg_g, bg_b;
00096 float line_width_;
00097 float scale_x, scale_y;
00098 int ox, oy, iw, ih;
00099 double iwf, ihf;
00100 double psizex, psizey;
00101 double pos_inx, pos_iny;
00102 int width, height;
00103 vcl_string filename;
00104 paper_type printer_paper_type;
00105 paper_orientation printer_paper_orientation;
00106 paper_layout printer_paper_layout;
00107 int reduction_factor;
00108 bool doneps;
00109 int min_x, min_y;
00110 int max_x, max_y;
00111 int box_width, box_height;
00112
00113 private:
00114
00115 vcl_streampos translate_pos;
00116 vcl_streampos sobj_t_pos;
00117 vcl_streampos header_pos;
00118
00119 bool graphics_prolog_exists;
00120 bool exist_image;
00121 bool exist_objs;
00122 };
00123
00124 #endif // vul_psfile_h_