-
Notifications
You must be signed in to change notification settings - Fork 8
/
ps.cpp
58 lines (46 loc) · 1011 Bytes
/
ps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ps.cpp
#include <stdarg.h>
#include "ps.h"
bool CPostscript::open(char filename[])
{
if (isOpen()) return false;
psf = fopen(filename, "wt");
nPages=0;
return isOpen();
}
void CPostscript::printf(const char fmt[], ...)
{
if (!isOpen()) return;
va_list va;
va_start(va,fmt);
vfprintf(psf, fmt, va);
va_end(va);
}
bool CPostscript::putTempl(const char filename[])
{
if (!isOpen()) return false;
char *buffer = new char[1024];
FILE *tf = fopen(filename, "rt");
if (tf==NULL) { delete[] buffer; return false; }
size_t count;
do
{
count = fread(buffer,1,1024,tf);
if (ferror(psf)) { fclose(tf); delete[] buffer; return false; }
if (count>0) fwrite(buffer,1,count,psf);
} while (!feof(tf));
fclose(tf);
delete[] buffer;
return true;
}
void CPostscript::addPage()
{
if (!isOpen()) return;
nPages++;
fprintf(psf,"%%%%Page: %i %i\n", nPages, nPages);
}
void CPostscript::addTrailer()
{
if (!isOpen()) return;
fprintf(psf,"%%%%Trailer\n%%%%Pages: %i\n%%%%EOF\n", nPages);
}