// C++ code Copyright (C) David R. Evans G4AMJ/NQ0I

//  surface class for laserwriter

#ifndef SURF_LWH
#define SURF_LWH

#include <gf_lw.h>
#include <surface.h>
#include <DREstring.h>

#include <iostream.h>
#include <stdio.h>

class laserwriter : public surface
{ 
protected:

  enum { VM_trigger = 512 };

  FILE* postscript_file;
  char postscript_filename[L_tmpnam];
  grey_font_laserwriter* gflwp;
  int n_writes;

  void _init(void);
  void prologue(void);
  void _print(const char* printer_name);
  inline void _save(void) { *this << "/saveobject save def"; }
  inline void _restore(void) { *this << "saveobject restore"; }
  inline laserwriter& _flush(void)
    { fflush(postscript_file); return *this; }

  boolean printing_in_progress;         // do not delete file if true

  dot last_dot;

public:
  laserwriter(const int x0 = 0, const int y0 = 0, const int x1 = 3275,
              const int y1 = 2399, const int ofsx = 12, const int ofsy = 75);
  laserwriter(laserwriter&);
  virtual ~laserwriter(void);

  surface& operator<<(LINE&);
  surface& operator<<(dot&);
  surface& operator<<(text&);
  int width(void);
  int height(void);
  void set_font(DREstring&, const int = 0);
  void set_font_height(const int = 0);

  void print(const char* printer_name);

  inline laserwriter& close(void)
    { fclose(postscript_file); return *this; }
  inline void attach(FILE* fp) { postscript_file = fp; }
  inline FILE* attached(void) { return postscript_file; }

  void clear(void);

  int resize_font(const int width, const int height);

// output with newline
  inline laserwriter& operator<<(const DREstring& s)
  { *this < s < '\n';
    return *this;
  }

// output without newline
  laserwriter& operator<(const DREstring& s)
  { fputs((const char*)(s), postscript_file); 
    return *this;
  }

// output with newline
  inline laserwriter& operator<<(const char* c)
  { *this < c < '\n';
    return *this;
  }

// output without newline
  laserwriter& operator<(const char* c)
  { fputs(c, postscript_file); 
    return *this;
  }

// output without newline
  inline laserwriter& operator<(const char c)
  { fputc(c, postscript_file); 
    return *this;
  }

// detach from a file and attach to a new one
  void detach(void);
  void detach(const char*);
  void detach(ostream&);

// prepare to receive a special font
  surface& operator<<(grey_font&) { /* for now do nothing */ return *this; };

// move the current point
  void moveto(const int x, const int y);

// flush font buffers to the laser
  void flush(void);

  int small_dot_size(void) { return 4; }
  inline boolean hardcopy(void) { return true; }
};

// -------------------------  portrait_laserwriter  ------------------

// a portrait version of laserwriter
class portrait_laserwriter : public laserwriter
{  
public:
  portrait_laserwriter(int x0 = 0, int y0 = 0, int x1 = 2399,
		       int y1 = 3275, int ofsx = 75, int ofsy = 12);
  int height(void);
  int width(void);
};

#endif



