Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ascii text to postscript converter

0 views
Skip to first unread message

Takanori Oshiro

unread,
Apr 15, 2023, 8:40:03 PM4/15/23
to
ASCIIテキストファイルをポストスクリプト言語に変換するフィルターです
自分で使うためのものなのでエラーチェックは一切行っておりません
今時ポストスクリプトプリンタで文書を印刷する必要性もなくなっているでしょ
うが自分の書いた文章を印刷するためにまだ使っています
ご使用の際はソースコードをご覧下さい
大城貴紀

/* a2ps - A program that converts text file to postscript language */
/* print 66 lines a page */
/* for A4 paper only */
/* font size is 10 point */
/* font is Times Roman */
/* written by Takanori Oshiro */

#include <stdio.h>

#define MAXLINE 66
#define MAXLINELEN 1000 /* maximum input line size */

int mygetline(char *, int);

int main(void){
int len; /* current line length */
char line[MAXLINELEN]; /* current input line */
int nline = 0; /* current line number */

printf("%%!PS-Adobe-3.0 EPSF-3.0\n");
printf("%%Definition of mm\n");
printf("/mm {2.834645669 mul} def\n");
printf("/verticalPosition 297 mm 20 mm sub def\n"); /* head and foot margin 20 mm */
printf("/horizontalPosition 25 mm def\n"); /* left margin 25 mm */
printf("/newline {/verticalPosition verticalPosition 3.89393939 mm sub def\n");
printf("\thorizontalPosition verticalPosition moveto } def\n");

printf("horizontalPosition verticalPosition moveto\n");
printf("/Times-Roman findfont 10 scalefont setfont\n");

while((len = mygetline(line, MAXLINELEN)) > 0){
if ( line[len-1] == '\n')
line[len-1] = '\0';
if (len != 1)
printf("(%s) show\n", line);
printf("newline\n");
nline++;
if(nline == MAXLINE){
printf("showpage\n");
printf("/verticalPosition 297 mm 20 mm sub def\n");
printf("horizontalPosition verticalPosition moveto\n");
nline = 0;
}
}
printf("showpage\n");
return 0;
}

int mygetline(char s[],int lim) /* get line into s, return length */
{
int c,i;

for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i){
if(c == '('){
s[i] = '\\';
++i;
s[i] = c;
} else if(c == ')'){
s[i] = '\\';
++i;
s[i] = c;
} else if(c == '\\'){
s[i] = '\\';
++i;
s[i] = '\\';
} else {
s[i] = c;
}
}
if ( c == '\n'){
s[i] = c;
++i;
}
s[i] = '\0';
return(i);
}
0 new messages