Commit 6d8d1923 authored by claes's avatar claes

Postscript print in xtt

parent 0450aeb9
...@@ -1390,7 +1390,14 @@ static void ge_activate_exit( Widget w, ge_tCtx gectx, XmAnyCallbackStruct *data ...@@ -1390,7 +1390,14 @@ static void ge_activate_exit( Widget w, ge_tCtx gectx, XmAnyCallbackStruct *data
static void ge_activate_print( Widget w, ge_tCtx gectx, XmAnyCallbackStruct *data) static void ge_activate_print( Widget w, ge_tCtx gectx, XmAnyCallbackStruct *data)
{ {
gectx->graph->print( "pwrp_tmp:graph.ps"); pwr_tFileName fname;
pwr_tCmd cmd;
dcli_translate_filename( fname, "$pwrp_tmp/graph.ps");
gectx->graph->print( fname);
sprintf( cmd, "$pwr_exe/rt_print.sh %s 1", fname);
system(cmd);
} }
static void ge_activate_new( Widget w, ge_tCtx gectx, XmAnyCallbackStruct *data) static void ge_activate_new( Widget w, ge_tCtx gectx, XmAnyCallbackStruct *data)
......
...@@ -69,6 +69,18 @@ static void gec_activate_configure( Widget w, GeCurve *curve, XmAnyCallbackStruc ...@@ -69,6 +69,18 @@ static void gec_activate_configure( Widget w, GeCurve *curve, XmAnyCallbackStruc
curve->configure_axes(); curve->configure_axes();
} }
static void gec_activate_print( Widget w, GeCurve *curve, XmAnyCallbackStruct *data)
{
pwr_tFileName fname;
pwr_tCmd cmd;
dcli_translate_filename( fname, "$pwrp_tmp/curve.ps");
curve->print( fname);
sprintf( cmd, "$pwr_exe/rt_print.sh %s 1", fname);
system(cmd);
}
static void gec_activate_zoomin( Widget w, GeCurve *curve, XmAnyCallbackStruct *data) static void gec_activate_zoomin( Widget w, GeCurve *curve, XmAnyCallbackStruct *data)
{ {
curve_Zoom( curve->growcurve_ctx, 2.0); curve_Zoom( curve->growcurve_ctx, 2.0);
...@@ -448,6 +460,9 @@ static int ge_init_growaxis_cb( GlowCtx *fctx, void *client_data) ...@@ -448,6 +460,9 @@ static int ge_init_growaxis_cb( GlowCtx *fctx, void *client_data)
curve->growaxis_ctx = (GrowCtx *) fctx; curve->growaxis_ctx = (GrowCtx *) fctx;
mask = 0; mask = 0;
// Double buffer is used to avoid pulldown menu at print
mask |= grow_eAttr_double_buffer_on;
grow_attr.double_buffer_on = 1;
mask |= grow_eAttr_grid_on; mask |= grow_eAttr_grid_on;
grow_attr.grid_on = 0; grow_attr.grid_on = 0;
mask |= grow_eAttr_hot_mode; mask |= grow_eAttr_hot_mode;
...@@ -478,6 +493,9 @@ static int ge_init_grownames_cb( GlowCtx *fctx, void *client_data) ...@@ -478,6 +493,9 @@ static int ge_init_grownames_cb( GlowCtx *fctx, void *client_data)
curve->grownames_ctx = (GrowCtx *) fctx; curve->grownames_ctx = (GrowCtx *) fctx;
mask = 0; mask = 0;
// Double buffer is used for print
mask |= grow_eAttr_double_buffer_on;
grow_attr.double_buffer_on = 1;
mask |= grow_eAttr_grid_on; mask |= grow_eAttr_grid_on;
grow_attr.grid_on = 0; grow_attr.grid_on = 0;
mask |= grow_eAttr_hot_mode; mask |= grow_eAttr_hot_mode;
...@@ -512,6 +530,36 @@ static int ge_init_grownames_cb( GlowCtx *fctx, void *client_data) ...@@ -512,6 +530,36 @@ static int ge_init_grownames_cb( GlowCtx *fctx, void *client_data)
return 1; return 1;
} }
void GeCurve::print( char *filename)
{
double x;
int w1, w2, h1, h2;
glow_eDrawType c1, c2, c3;
grow_GetBackgroundColor( growaxis_ctx, &c1);
grow_GetBackgroundColor( growcurve_ctx, &c2);
grow_GetBackgroundColor( grownames_ctx, &c3);
grow_SetBackgroundColor( growaxis_ctx, glow_eDrawType_Color4);
grow_SetBackgroundColor( growcurve_ctx, glow_eDrawType_Color4);
grow_SetBackgroundColor( grownames_ctx, glow_eDrawType_Color4);
grow_Redraw( growaxis_ctx);
grow_Redraw( growcurve_ctx);
grow_Redraw( grownames_ctx);
grow_GetWindowSize( growaxis_ctx, &w1, &h1);
grow_GetWindowSize( growcurve_ctx, &w2, &h2);
if ( w1 + w2 == 0)
return;
x = double(w1) / (w1 + w2);
grow_Print( growaxis_ctx, filename, 0.0, x, 0);
grow_Print( growcurve_ctx, filename, x, 1.0, 0);
grow_Print( grownames_ctx, filename, 0, 0, 1);
grow_SetBackgroundColor( growaxis_ctx, c1);
grow_SetBackgroundColor( growcurve_ctx, c2);
grow_SetBackgroundColor( grownames_ctx, c3);
grow_Redraw( growaxis_ctx);
grow_Redraw( growcurve_ctx);
grow_Redraw( grownames_ctx);
}
int GeCurve::configure_axes() int GeCurve::configure_axes()
{ {
...@@ -854,6 +902,7 @@ GeCurve::GeCurve( void *gc_parent_ctx, ...@@ -854,6 +902,7 @@ GeCurve::GeCurve( void *gc_parent_ctx,
{ "gec_ctx", 0 }, { "gec_ctx", 0 },
{"gec_activate_exit",(caddr_t)gec_activate_exit }, {"gec_activate_exit",(caddr_t)gec_activate_exit },
{"gec_activate_configure",(caddr_t)gec_activate_configure }, {"gec_activate_configure",(caddr_t)gec_activate_configure },
{"gec_activate_print",(caddr_t)gec_activate_print },
{"gec_activate_zoomin",(caddr_t)gec_activate_zoomin }, {"gec_activate_zoomin",(caddr_t)gec_activate_zoomin },
{"gec_activate_zoomout",(caddr_t)gec_activate_zoomout }, {"gec_activate_zoomout",(caddr_t)gec_activate_zoomout },
{"gec_activate_zoomreset",(caddr_t)gec_activate_zoomreset }, {"gec_activate_zoomreset",(caddr_t)gec_activate_zoomreset },
......
...@@ -125,6 +125,7 @@ class GeCurve { ...@@ -125,6 +125,7 @@ class GeCurve {
void pop(); void pop();
void set_title( char *str); void set_title( char *str);
void set_time( pwr_tTime time); void set_time( pwr_tTime time);
void print( char *filename);
~GeCurve(); ~GeCurve();
}; };
......
...@@ -235,7 +235,7 @@ GraphGrow::~GraphGrow() ...@@ -235,7 +235,7 @@ GraphGrow::~GraphGrow()
// //
void Graph::print( char *filename) void Graph::print( char *filename)
{ {
grow_Print( grow->ctx, filename); grow_Print( grow->ctx, filename, 0, 0, 1);
} }
int Graph::create_navigator( Widget parent) int Graph::create_navigator( Widget parent)
......
...@@ -536,6 +536,11 @@ void GlowCtx::print( double ll_x, double ll_y, double ur_x, double ur_y) ...@@ -536,6 +536,11 @@ void GlowCtx::print( double ll_x, double ll_y, double ur_x, double ur_y)
} }
} }
void GlowCtx::print( char *filename, double x0, double x1, int end)
{
glow_print( this, filename, x0, x1, end);
}
void GlowCtx::draw( int ll_x, int ll_y, int ur_x, int ur_y) void GlowCtx::draw( int ll_x, int ll_y, int ur_x, int ur_y)
{ {
int i; int i;
......
...@@ -389,6 +389,9 @@ class GlowCtx { ...@@ -389,6 +389,9 @@ class GlowCtx {
//! Print to postscript. Not implemented. //! Print to postscript. Not implemented.
void print( double ll_x, double ll_y, double ur_x, double ur_y); void print( double ll_x, double ll_y, double ur_x, double ur_y);
//! Print to postscript.
void print( char *filename, double x0, double x1, int end);
//! Redraw an area of the window. //! Redraw an area of the window.
/*! /*!
\param ll_x x coordiate for lower left corner of area to draw in pixel. \param ll_x x coordiate for lower left corner of area to draw in pixel.
......
#include "glow_std.h" #include "glow_std.h"
using namespace std;
#include <iostream.h>
#include <fstream.h>
#include <stdio.h> #include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <Xm/Xm.h> #include <Xm/Xm.h>
#include <Xm/XmP.h> #include <Xm/XmP.h>
#include <Mrm/MrmPublic.h> #include <Mrm/MrmPublic.h>
...@@ -3142,6 +3147,173 @@ void glow_draw_buffer_background( GlowCtx *ctx) ...@@ -3142,6 +3147,173 @@ void glow_draw_buffer_background( GlowCtx *ctx)
} }
} }
int glow_print( GlowCtx *ctx, char *filename, double x0, double x1, int end)
{
#if defined IMLIB
#define ps_cPageHeight 820
#define ps_cPageWidth 535
#define ps_cLeftMargin 100
#define ps_cTopMargin 100
draw_tCtx draw_ctx = (draw_tCtx) ctx->draw_ctx;
int width, height;
unsigned char *rgb;
unsigned char transp[3] = {255,0,255};
int i, j;
int grey;
int red, blue, green;
double scalex = 0.71;
double scaley = 0.78;
double x, y;
bool colorimage = true;
static DrawPs *ps = 0;
bool new_file = false;
x = ps_cLeftMargin;
y = ps_cPageHeight - ps_cTopMargin;
// draw_ctx->imlib = Imlib_init( draw_ctx->display);
ImlibImage *image;
if ( ctx->double_buffer_on)
image = Imlib_create_image_from_drawable( draw_ctx->imlib, draw_ctx->buffer,
0, 0, 0, draw_ctx->buffer_width,
draw_ctx->buffer_height);
else
image = Imlib_create_image_from_drawable( draw_ctx->imlib, draw_ctx->window,
0, 0, 0, ctx->window_width,
ctx->window_height);
if ( !image)
return 0;
if ( !ps) {
ps = new DrawPs( filename);
new_file = true;
ps->y = y;
}
else
y = ps->y;
width = image->rgb_width;
height = image->rgb_height;
if ( x0 != 0 || x1 != 0) {
double total_width = width / (x1 - x0);
if ( total_width * scalex > ps_cPageWidth - ps_cLeftMargin) {
x = ps_cPageWidth - total_width * scalex;
if ( x < 50) {
double scale_factor = (ps_cPageWidth - 50) / (total_width * scalex);
x = 50;
scalex = scalex * scale_factor;
scaley = scaley * scale_factor;
}
}
x += scalex * total_width * x0;
}
else if ( width * scalex > ps_cPageWidth - ps_cLeftMargin) {
x = ps_cPageWidth - width * scalex;
if ( x < 50) {
double scale_factor = (ps_cPageWidth - 50) / (width * scalex);
x = 50;
scalex = scalex * scale_factor;
scaley = scaley * scale_factor;
}
}
if ( (x0 == 0 && x1 == 0) || x1 == 1.0)
ps->y -= scaley * height;
if ( new_file) {
ps->fp <<
"%!PS-Adobe-2.0 EPSF-1.2" << endl <<
"%%Creator: Proview Glow" << endl <<
"%%EndComments" << endl << endl;
}
else
ps->fp <<
"restore" << endl;
ps->fp <<
"1.000000 1.000000 scale" << endl <<
"save" << endl <<
scalex * width << " " << scaley * height << " scale" << endl <<
"/oneline " << width << " string def" << endl <<
"/drawimage {" << endl <<
" " << width << " " << height << " 8 [" << width << " 0 0 -" << height << " 0 " << height << "]" << endl <<
" { currentfile oneline readhexstring pop }" << endl;
if ( colorimage) {
ps->fp <<
"false 3" << endl <<
"colorimage" << endl;
}
else
ps->fp <<
"image" << endl;
ps->fp <<
"} def" << endl <<
x/scalex/width << " " << (y - height*scaley)/scaley/height << " translate" << endl <<
"drawimage" << endl;
ps->fp.flags( (ps->fp.flags() & ~ios_base::dec) | ios_base::hex | ios_base::uppercase);
ps->fp.fill('0');
rgb = image->rgb_data;
j = 0;
for ( i = 0; i < image->rgb_height * image->rgb_width * 3; i+=3) {
if ( !colorimage) {
if ( *rgb == transp[0] && *(rgb+1) == transp[1] && *(rgb+2) == transp[2]) {
grey = 255;
}
else {
grey = (int) ((0.0 + *rgb + *(rgb+1) + *(rgb+2)) / 3 + 0.5);
}
rgb += 3;
ps->fp.width(2);
ps->fp << grey;
if ( ++j >= 40) {
j = 0;
ps->fp << endl;
}
}
else {
if ( *rgb == transp[0] && *(rgb+1) == transp[1] && *(rgb+2) == transp[2]) {
red = blue = green = 255;
}
else {
red = *rgb;
green = *(rgb+1);
blue = *(rgb+2);
}
rgb += 3;
ps->fp.width(2);
ps->fp << blue;
ps->fp.width(2);
ps->fp << green;
ps->fp.width(2);
ps->fp << red;
if ( ++j >= 20) {
j = 0;
ps->fp << endl;
}
}
}
if ( end) {
ps->fp << endl <<
"restore" << endl <<
"showpage" << endl;
delete ps;
ps = 0;
}
else {
ps->fp.flags( ((ps->fp.flags() & ~ios_base::hex) & ~ios_base::uppercase) | ios_base::dec);
}
Imlib_destroy_image( draw_ctx->imlib, image);
#endif
return 1;
}
...@@ -65,6 +65,15 @@ typedef struct { ...@@ -65,6 +65,15 @@ typedef struct {
int background_pixmap_height; int background_pixmap_height;
} draw_sCtx, *draw_tCtx; } draw_sCtx, *draw_tCtx;
class DrawPs {
public:
DrawPs( char *filename) : fp(filename), x(0), y(0)
{}
~DrawPs() { fp.close();}
ofstream fp;
double x;
double y;
};
int glow_draw_init( int glow_draw_init(
Widget toplevel, Widget toplevel,
...@@ -223,6 +232,7 @@ void glow_draw_set_click_sensitivity( GlowCtx *ctx, int value); ...@@ -223,6 +232,7 @@ void glow_draw_set_click_sensitivity( GlowCtx *ctx, int value);
void glow_draw_background( GlowCtx *ctx, int x, int y, int w, int h); void glow_draw_background( GlowCtx *ctx, int x, int y, int w, int h);
int glow_draw_create_buffer( GlowCtx *ctx); int glow_draw_create_buffer( GlowCtx *ctx);
void glow_draw_buffer_background( GlowCtx *ctx); void glow_draw_buffer_background( GlowCtx *ctx);
int glow_print( GlowCtx *ctx, char *filename, double x0, double x1, int end);
#endif #endif
......
...@@ -527,9 +527,9 @@ void grow_MeasureNode( grow_tNode node, double *ll_x, double *ll_y, ...@@ -527,9 +527,9 @@ void grow_MeasureNode( grow_tNode node, double *ll_x, double *ll_y,
((GlowNode *)node)->measure( ll_x, ll_y, ur_x, ur_y); ((GlowNode *)node)->measure( ll_x, ll_y, ur_x, ur_y);
} }
void grow_Print( grow_tCtx ctx, char *filename) void grow_Print( grow_tCtx ctx, char *filename, double x0, double x1, int end)
{ {
// ctx->print( filename); ctx->print( filename, x0, x1, end);
} }
void grow_GetUserData( grow_tObject object, void **user_data) void grow_GetUserData( grow_tObject object, void **user_data)
...@@ -4279,6 +4279,12 @@ int grow_SetFolderIndex( grow_tObject folder, int idx) ...@@ -4279,6 +4279,12 @@ int grow_SetFolderIndex( grow_tObject folder, int idx)
return ((GrowFolder *)folder)->set_folder( idx); return ((GrowFolder *)folder)->set_folder( idx);
} }
void grow_GetWindowSize( grow_tCtx ctx, int *width, int *height)
{
*width = ((GrowCtx *)ctx)->window_width;
*height = ((GrowCtx *)ctx)->window_height;
}
/*@}*/ /*@}*/
......
...@@ -556,8 +556,8 @@ typedef GlowTraceData glow_sTraceData; ...@@ -556,8 +556,8 @@ typedef GlowTraceData glow_sTraceData;
void grow_MeasureNode( grow_tNode node, double *ll_x, double *ll_y, void grow_MeasureNode( grow_tNode node, double *ll_x, double *ll_y,
double *ur_x, double *ur_y); double *ur_x, double *ur_y);
//! Print context to postscript file. Not implemented. //! Print context to postscript file.
void grow_Print( grow_tCtx ctx, char *filename); void grow_Print( grow_tCtx ctx, char *filename, double x0, double x1, int end);
//! Get user data of an object. //! Get user data of an object.
/*! /*!
...@@ -2813,6 +2813,7 @@ typedef GlowTraceData glow_sTraceData; ...@@ -2813,6 +2813,7 @@ typedef GlowTraceData glow_sTraceData;
void grow_GetSubmenuPosition( grow_tObject menu, int item, double *x, double *y); void grow_GetSubmenuPosition( grow_tObject menu, int item, double *x, double *y);
int grow_GetMenuParent( grow_tObject menu, grow_tObject *parent); int grow_GetMenuParent( grow_tObject menu, grow_tObject *parent);
int grow_SetFolderIndex( grow_tObject folder, int idx); int grow_SetFolderIndex( grow_tObject folder, int idx);
void grow_GetWindowSize( grow_tCtx ctx, int *width, int *height);
/*@}*/ /*@}*/
#if defined __cplusplus #if defined __cplusplus
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment