Improved Postscript output handling.
[account.git] / postscript.h
index 10c619e..31d7967 100644 (file)
@@ -1,7 +1,20 @@
 
 #include <iostream>
+#include <exception>
 #include <libps/pslib.h>
 
+// Exception class to handle runtime errors
+
+class psexception : public std::exception
+{
+public:
+  virtual const char* what() const throw()
+  {
+    return "PostScript error";
+  }
+
+};
+
 // A Postscript document as used in pslib
 
 extern bool postscript_started;
@@ -22,11 +35,19 @@ public:
          postscript_started = true;
       }
       psdoc = PS_new();
-      PS_open_file(psdoc, filename);
+      if (PS_open_file(psdoc, filename) == -1)
+      {
+         throw psexception();
+      }
       //PS_set_info(psdoc, "BoundingBox", "0 0 842 596");
+      PS_set_parameter(psdoc, "SearchPath", "/usr/local/share/afm");
       PS_set_parameter(psdoc, "SearchPath", "/usr/lib/openoffice/basis3.1/share/psprint/fontmetric");
       PS_set_parameter(psdoc, "SearchPath", "/usr/lib/openoffice/basis3.2/share/psprint/fontmetric");
       psfont = PS_findfont(psdoc, "Courier", NULL, 0);
+      if (psfont == 0)
+      {
+         throw psexception();
+      }
       page = 0;
    }