📄 gvcprn.c
字号:
fputs("%%PageOrder: Descend\r\n", f);
else
fputs("%%PageOrder: Special\r\n", f);
/* pageorder_written = TRUE; */
}
}
ps_copy(f, psfile.file, dsc->beginpreview, dsc->endpreview);
ps_copy(f, psfile.file, dsc->begindefaults, dsc->enddefaults);
ps_copy(f, psfile.file, dsc->beginprolog, dsc->endprolog);
copy_setup(f, psfile.file, copies);
page = 1;
i = reverse ? dsc->page_count - 1 : 0;
while ( reverse ? (i >= 0) : (i < (int)dsc->page_count) ) {
if (psfile.page_list.select[map_page(i)]) {
char buf[MAXSTR];
/* modify ordinal of %%Page: comment */
position = gfile_seek(psfile.file, dsc->page[i].begin, gfile_begin);
if (ps_fgets(buf, sizeof(buf)-1, psfile.file) == 0)
return FALSE;
/* reached end of %%Page: line */
if (dsc->page[i].label)
fprintf(f, "%%%%Page: %s %d\r\n",
dsc->page[i].label, page);
else
fprintf(f, "%%%%Page: %d %d\r\n", page, page);
page++;
ps_copy(f, psfile.file, -1, dsc->page[i].end);
}
i += reverse ? -1 : 1;
}
/* copy trailer, removing %%Pages: and %%PageOrder: */
position = gfile_seek(psfile.file, dsc->begintrailer, gfile_begin);
while ( position < dsc->endtrailer ) {
if (ps_fgets(line, sizeof(line), psfile.file) == 0)
return FALSE;
position = gfile_seek(psfile.file, 0, gfile_current);
if (strncmp(line, "%%Pages:", 8) == 0) {
continue; /* has already been written in header */
}
else if (strncmp(line, "%%PageOrder:", 12) == 0) {
continue; /* has already been written in header */
}
else {
fputs(line, f);
}
}
return TRUE;
}
#ifdef _MSC_VER
/* Brain damaged Microsoft C doesn't support POSIX directory operations.
* Implement a subset of these ourselves to keep the uniprint
* enumeration code happy.
*/
struct dirent
{
char d_name[260];
};
typedef struct
{
BOOL finished;
HANDLE hff;
WIN32_FIND_DATA wfd;
TCHAR pattern[1024];
struct dirent de;
} DIR;
DIR * opendir(const char *dirname);
struct dirent *readdir(DIR *dir);
int closedir (DIR *dir);
DIR * opendir(const char *dirname)
{
DIR *dp = (DIR *)malloc(sizeof(DIR));
int i;
TCHAR *p;
if (dp == NULL)
return NULL;
memset((char *)dp, 0, sizeof(DIR));
convert_multibyte(dp->pattern, dirname,
sizeof(dp->pattern)/sizeof(TCHAR)-1);
i = lstrlen(dp->pattern);
for (p = dp->pattern; *p; p++)
if (*p == '/')
*p = '\\';
if (i && dp->pattern[i-1]!='\\')
lstrcat(dp->pattern, TEXT("\\"));
lstrcat(dp->pattern, TEXT("*"));
dp->finished = FALSE;
dp->hff = NULL;
return dp;
}
int closedir (DIR *dir)
{
if ((dir->hff) && (dir->hff != INVALID_HANDLE_VALUE))
FindClose(dir->hff);
free(dir);
return 0;
}
struct dirent *readdir(DIR *dir)
{
if (dir->finished)
return NULL;
if (dir->hff == NULL) {
dir->hff = FindFirstFile(dir->pattern, &dir->wfd);
if (dir->hff == INVALID_HANDLE_VALUE) {
dir->finished = TRUE;
return NULL;
}
}
else {
if (!FindNextFile(dir->hff, &dir->wfd)) {
dir->finished = TRUE;
return NULL;
}
}
convert_widechar(dir->de.d_name, dir->wfd.cFileName,
sizeof(dir->de.d_name)-1);
return &(dir->de);
}
#endif
/* Add the file name and description to the list
* Return new offset.
* If not enough space, don't copy name/description but
* still return offset as if data was copied.
* This allows caller to work out what buffer size is required.
*/
int
upp_add_list(char *name, char *buffer, int len, int offset)
{
char *pd;
FILE *f;
char desc[MAXSTR];
int needed, remaining;
if ( (f = fopen(name, "r")) != (FILE *)NULL ) {
if (fgets(desc, sizeof(desc)-1, f)) {
strtok(desc, "\042\n");
pd = strtok(NULL, "\042\n");
if (pd && strlen(pd)) {
needed = strlen(name) + strlen(pd) + 3;
remaining = len - offset;
if (needed < remaining) {
strcpy(buffer+offset, name);
offset += strlen(name) + 1;
strcpy(buffer+offset, pd);
offset += strlen(pd) + 1;
buffer[offset] = '\0'; /* double trailing null */
}
else {
/* don't copy data, but tell caller how much */
/* space it needs */
offset += strlen(name) + 1;
offset += strlen(pd) + 1;
}
}
}
fclose(f);
}
return offset;
}
/* search path for any uniprint configuration files (*.upp),
* appending the filename and description of any found to
* buffer at offset. Return updated offset.
* If offset > len, then not all data was placed in buffer.
*/
int
enum_upp(char *path, char *buffer, int len, int offset)
{
DIR *dirp;
struct dirent* de;
struct stat st;
char name[MAXSTR];
char *p;
dirp = opendir(path);
if (dirp == NULL)
return 2;
while ( (de = readdir(dirp)) != NULL) {
if (strlen(path) + strlen(de->d_name) + 1 < MAXSTR) {
strcpy(name, path);
strcat(name, PATHSEP);
strcat(name, de->d_name);
if (stat(name, &st) != -1) {
if (st.st_mode & S_IFDIR) {
/* don't recurse into subdirectories */
}
else {
/* an ordinary file */
p = strrchr(name,'.');
if (p && (stricmp(p, ".upp") == 0)) {
offset = upp_add_list(name, buffer, len, offset);
}
}
}
}
}
closedir(dirp);
return offset;
}
/* return number of bytes needed */
int
enum_upp_path(char *path, char *buffer, int len)
{
char pbuf[1024];
char *p, *q, *r;
int offset = 0;
if (buffer == (char *)NULL)
len = 0;
if (len >= 2) {
buffer[0] = '\0';
buffer[1] = '\0';
}
p = path;
while (p) {
q = strchr(p, ';');
if (q) {
strncpy(pbuf, p, (int)(q-p));
pbuf[(int)(q-p)] = '\0';
}
else
strcpy(pbuf, p);
if (strlen(pbuf)) {
r = pbuf + strlen(pbuf) - 1;
if ( (*r == '\\') || (*r == '/') )
*r = '\0'; /* trailing slash will be added later */
offset = enum_upp(pbuf, buffer, len, offset);
}
if (q)
p = q+1;
else
p = NULL;
}
return offset + 2;
}
char *
uppmodel_to_name(char *buffer, char *model)
{
char *p, *desc;
for (p=buffer; *p; p+=strlen(p)+1) {
desc = p + strlen(p) + 1;
if (strcmp(desc, model) == 0)
return p;
p = desc;
}
return NULL;
}
char *
uppname_to_model(char *buffer, char *name)
{
char *p, *desc;
for (p=buffer; *p; p+=strlen(p)+1) {
desc = p + strlen(p) + 1;
if (strcmp(p, name) == 0)
return desc;
p = desc;
}
return NULL;
}
void
psfile_epsf_print(FILE *f, int copies)
{
int llx, lly, urx, ury;
int original_llx, original_lly;
float scale = 1.0;
int rescale = FALSE;
int width, height;
int j;
CDSC *dsc = psfile.dsc;
width = get_paper_width();
height = get_paper_height();
if (psfile.dsc->bbox != (CDSCBBOX *)NULL) {
llx = psfile.dsc->bbox->llx;
lly = psfile.dsc->bbox->lly;
urx = psfile.dsc->bbox->urx;
ury = psfile.dsc->bbox->ury;
}
else {
llx = lly = 0;
urx = width;
ury = height;
}
original_llx = llx;
original_lly = lly;
/* If EPS file isn't going to fit on the page, rescale it */
if ( (llx < 0) || (llx > width) ||
(lly < 0) || (lly > height) ||
(urx < 0) || (urx > width) ||
(ury < 0) || (lly > height) )
rescale = TRUE;
#define MARGIN 36 /* 12.5mm gap */
if (rescale) {
/* leave minimum 12.5mm gap on each side */
scale = min( ((float)(width - 2 * MARGIN)/(urx - llx)),
((float)(height - 2 * MARGIN)/(ury - lly)) );
urx = MARGIN + (int)((urx - llx)*scale + 0.999999);
ury = MARGIN + (int)((ury - lly)*scale + 0.999999);
llx = MARGIN;
lly = MARGIN;
}
fprintf(f, "%%!PS-Adobe-3.0 EPSF-3.0\r\n");
fprintf(f, "%%%%BoundingBox: %d %d %d %d\r\n", llx, lly, urx, ury);
fprintf(f, "%%%%Pages: 1\r\n%%%%EndComments\r\n%%%%BeginProlog\r\n");
fprintf(f, "%%%%EndProlog\r\n");
if (copies > 1) {
fputs("%%BeginSetup\r\n", f);
add_copies(f, copies);
fputs("%%EndSetup\r\n", f);
}
fprintf(f, "%%%%Page: 1 1\r\n");
fprintf(f, " /EPSTOOL_save save def\r\n /showpage {} def\r\n");
fprintf(f, " count /EPSTOOL_count exch def\r\n");
fprintf(f, " /EPSTOOL_countdictstack countdictstack def\r\n");
if (rescale)
fprintf(f, " %d %d translate\r\n %g %g scale\r\n %d %d translate\r\n",
MARGIN, MARGIN, /* add new offset */
scale, scale,
-original_llx, -original_lly /* remove old offset */ );
fprintf(f, "%%%%BeginDocument: %s\r\n", psfile.name);
ps_copy(f, psfile.file, dsc->begincomments, dsc->endcomments);
ps_copy(f, psfile.file, dsc->begindefaults, dsc->enddefaults);
ps_copy(f, psfile.file, dsc->beginprolog, dsc->endprolog);
ps_copy(f, psfile.file, dsc->beginsetup, dsc->endsetup);
for (j=0; j<(int)dsc->page_count; j++)
ps_copy(f, psfile.file, dsc->page[j].begin, dsc->page[j].end);
ps_copy(f, psfile.file, dsc->begintrailer, dsc->endtrailer);
fprintf(f, "\r\n%%%%EndDocument\r\n");
fprintf(f, " count EPSTOOL_count sub {pop} repeat\r\n");
fprintf(f, " countdictstack EPSTOOL_countdictstack sub {end} repeat\r\n");
fprintf(f," EPSTOOL_save restore\r\n showpage\r\n%%%%Trailer\r\n%%%%EOF\r\n");
#undef MARGIN
}
BOOL
gsview_copygfile(FILE *outfile, GFile *infile)
{
char *buffer;
int count;
/* create buffer for PS file copy */
buffer = (char *)malloc(COPY_BUF_SIZE);
if (buffer == (char *)NULL)
return FALSE;
while ( (count = gfile_read(infile, buffer, COPY_BUF_SIZE)) != 0 ) {
fwrite(buffer, 1, count, outfile);
}
free(buffer);
return TRUE;
}
BOOL
gsview_copyfile(FILE *outfile, FILE *infile)
{
char *buffer;
int count;
/* create buffer for PS file copy */
buffer = (char *)malloc(COPY_BUF_SIZE);
if (buffer == (char *)NULL)
return FALSE;
while ( (count = fread(buffer, 1, COPY_BUF_SIZE, infile)) != 0 ) {
fwrite(buffer, 1, count, outfile);
}
free(buffer);
return TRUE;
}
BOOL
copy_for_printer(FILE *pcfile, BOOL convert)
{
int copies = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -