1 // This is core/vul/vul_psfile.h 2 #ifndef vul_psfile_h_ 3 #define vul_psfile_h_ 4 //: 5 // \file 6 // \brief write out images, points, lines, circles and/or ellipses to PostScript 7 // \author Alan S. Liu 8 // 9 // \verbatim 10 // Modifications 11 // 7 Jan 2003 - Peter Vanroose - bug fix in image output: complete rewrite of 12 // print_greyscale_image() & print_color_image() 13 // \endverbatim 14 15 #include <string> 16 #include <fstream> 17 #ifdef _MSC_VER 18 # include <vcl_msvc_warnings.h> 19 #endif 20 21 //: Write a PostScript file 22 class vul_psfile: public std::ofstream 23 { 24 public: 25 enum paper_type { 26 US_NORMAL, 27 A4, 28 B5, 29 A3, 30 US_LEGAL, 31 ELEVEN_BY_SEVENTEEN, 32 FOUR_BY_FIVE, 33 THIRTY_FIVE_mm}; 34 enum paper_orientation{ 35 PORTRAIT, 36 LANDSCAPE }; 37 enum paper_layout{ 38 CENTER, 39 MAX }; 40 41 vul_psfile(char const* filename, bool debug_output=false); 42 ~vul_psfile() override; 43 operator bool() { return static_cast<bool>(output_filestream); } 44 set_paper_type(vul_psfile::paper_type type)45 void set_paper_type(vul_psfile::paper_type type){printer_paper_type = type;} set_paper_layout(vul_psfile::paper_layout layout)46 void set_paper_layout(vul_psfile::paper_layout layout) {printer_paper_layout = layout;} set_paper_orientation(vul_psfile::paper_orientation o)47 void set_paper_orientation(vul_psfile::paper_orientation o) {printer_paper_orientation = o;} set_reduction_factor(int rf)48 void set_reduction_factor(int rf) {reduction_factor = rf;} 49 //: set the horizontal scaling (in percent); no scaling is 100. set_scale_x(float sx)50 void set_scale_x(float sx) {scale_x = sx * .01f;} 51 //: set the vertical scaling (in percent); no scaling is 100. set_scale_y(float sy)52 void set_scale_y(float sy) {scale_y = sy * .01f;} set_fg_color(float r,float g,float b)53 void set_fg_color(float r, float g, float b) {fg_r = r; fg_g = g; fg_b = b;} set_bg_color(float r,float g,float b)54 void set_bg_color(float r, float g, float b) {bg_r = r; bg_g = g; bg_b = b;} set_line_width(float f_width)55 void set_line_width(float f_width) {line_width_ = f_width;} line_width()56 float line_width() const { return line_width_; } 57 58 //: Write 8 bit grey scale image. 59 void print_greyscale_image(const unsigned char* data, int sizex, int sizey); 60 //: Write 24 bit colour image. 61 void print_color_image(const unsigned char* data, int sizex, int sizey); 62 63 //: Add a line between the given points to the Postscript file. 64 void line(float x1, float y1, float x2, float y2); 65 //: Add a point at the given coordinates to the Postscript file. 66 void point(float x, float y, float point_size = 0); 67 //: Add an ellipse to the Postscript file. 68 void ellipse(float x, float y, float a_axis, float b_axis, int angle = 0); 69 //: Add a circle with the given centre point and radius to the Postscript file. 70 void circle(float x, float y, float radius); 71 72 void reset_bounding_box(); 73 74 protected: 75 void set_min_max_xy(float x, float y); 76 void set_min_max_xy(int x, int y); 77 bool set_parameters(int sizex, int sizey); 78 79 //: PostScript file header. Automatically called by the constructor. 80 void postscript_header(); 81 82 //: Set graphic coordinate (translate and rotate to local coordinate). 83 void graphic_header(); 84 //: Utility program used in point(), line(), ellipse() and circle() 85 void sobj_rgb_params(char const* str, bool filled); 86 //: the defined procedure for PostScript script use. 87 void print_graphics_prolog(); 88 89 private: 90 void compute_bounding_box(); 91 92 void reset_postscript_header(); 93 void image_translate_and_scale(); 94 void object_translate_and_scale(); 95 void done(); 96 97 std::ofstream output_filestream; 98 99 float fg_r, fg_g, fg_b; 100 float bg_r, bg_g, bg_b; 101 float line_width_; 102 float scale_x, scale_y; 103 int ox, oy, iw, ih; 104 double iwf, ihf; 105 double psizex, psizey; /* current paper size, in inches */ 106 double pos_inx, pos_iny; /* top-left offset of image, in inches */ 107 int width, height; /* image width and height */ 108 std::string filename; /* postscript path/filename */ 109 paper_type printer_paper_type; 110 paper_orientation printer_paper_orientation; 111 paper_layout printer_paper_layout; 112 int reduction_factor; 113 bool doneps; 114 int min_x, min_y; 115 int max_x, max_y; 116 int box_width, box_height; 117 118 private: /*even more*/ 119 120 std::streampos translate_pos; 121 std::streampos sobj_t_pos; 122 std::streampos header_pos; 123 124 bool graphics_prolog_exists; 125 bool exist_image; 126 bool exist_objs; 127 }; 128 129 #endif // vul_psfile_h_ 130