090603 - print paragraphs of text in pseudo KANJI
As described in the book, in order to include this in the Book I start by writing a logical Paragraph that contextualize the sampled Page within the L-Mem Volume.
Cut and paste lost the tab space. In this case to match the 2 column printed version, it's actually fine
[TBC]
/* keep this comment block for formatted sub-title
* kanji -
* print paragraphs of text in pseudo KANJI
*
* Paul Haeberli - 1996
*/
#include "stdio.h"
#include "ctype.h"
#include "math.h"
#define KANJIFONTFILE ("/usr/lib/DPS/outline/base/KANJI.ps")
#define DEFFONTSIZE (24.0)
#define LEFTMARGIN (1.5*72.0)
#define TOPMARGIN (10.00*72.0)
#define BOTTOMMARGIN (1.0*72.0)
#define MAXLEN (4096)
float curfontsize;
char oneline[MAXLEN];
int randmode;
FILE *inf, *outf;
float xpos = LEFTMARGIN;
float ypos = TOPMARGIN;
int r(n)
int n;
{
if(randmode)
return random()%n;
else
return 0;
}
putletter(code)
int code;
{
if(islower(code))
code = toupper(code);
switch(code) {
case '-':
fprintf(outf,"45 ");
break;
case '\'':
fprintf(outf,"44 ");
break;
case '{':
fprintf(outf,"DE ");
break;
case '}':
fprintf(outf,"DF ");
break;
case '[':
fprintf(outf,"46 ");
break;
case ']':
fprintf(outf,"47 ");
break;
case '(':
fprintf(outf,"41 ");
break;
case ')':
fprintf(outf,"44 ");
break;
case '!':
fprintf(outf,"41 ");
break;
case '?':
fprintf(outf,"41 ");
break;
case '.':
fprintf(outf,"41 ");
break;
case ',':
fprintf(outf,"42 ");
break;
case ':':
fprintf(outf,"43 ");
break;
case ' ':
fprintf(outf,"40 ");
break;
case 'A':
switch(r(5)) {
case 0:
fprintf(outf,"D3 ");
break;
case 1:
fprintf(outf,"BE ");
break;
case 2:
fprintf(outf,"6E ");
break;
case 3:
fprintf(outf,"AF ");
break;
case 4:
fprintf(outf,"D6 ");
break;
}
break;
case 'B':
switch(r(6)) {
case 0:
fprintf(outf,"A4 ");
break;
case 1:
fprintf(outf,"AD ");
break;
case 2:
fprintf(outf,"BB ");
break;
case 3:
fprintf(outf,"C0 ");
break;
case 4:
fprintf(outf,"CB ");
break;
case 5:
fprintf(outf,"CC ");
break;
}
break;
case 'C':
switch(r(4)) {
case 0:
fprintf(outf,"4B ");
break;
case 1:
fprintf(outf,"CF ");
break;
case 2:
fprintf(outf,"BC ");
break;
case 3:
fprintf(outf,"D0 ");
break;
}
break;
case 'D':
switch(r(2)) {
case 0:
fprintf(outf,"50 ");
break;
case 1:
fprintf(outf,"DA ");
break;
}
break;
case 'E':
switch(r(9)) {
case 0:
fprintf(outf,"69 ");
break;
case 1:
fprintf(outf,"70 ");
break;
case 2:
fprintf(outf,"6F ");
break;
case 3:
fprintf(outf,"7A ");
break;
case 4:
fprintf(outf,"A0 ");
break;
case 5:
fprintf(outf,"A3 ");
break;
case 6:
fprintf(outf,"A7 ");
break;
case 7:
fprintf(outf,"A9 ");
break;
case 8:
fprintf(outf,"AA ");
break;
}
break;
case 'F':
switch(r(4)) {
case 0:
fprintf(outf,"CA ");
break;
case 1:
fprintf(outf,"6D ");
break;
case 2:
fprintf(outf,"73 ");
break;
case 3:
fprintf(outf,"AB ");
break;
}
break;
case 'G':
switch(r(3)) {
case 0:
fprintf(outf,"77 ");
break;
case 1:
fprintf(outf,"68 ");
break;
case 2:
fprintf(outf,"C3 ");
break;
}
break;
case 'H':
switch(r(5)) {
case 0:
fprintf(outf,"D8 ");
break;
case 1:
fprintf(outf,"4E ");
break;
case 2:
fprintf(outf,"59 ");
break;
case 3:
fprintf(outf,"5A ");
break;
case 4:
fprintf(outf,"AE ");
break;
}
break;
case 'I':
switch(r(2)) {
case 0:
fprintf(outf,"75 ");
break;
case 1:
fprintf(outf,"C9 ");
break;
}
break;
case 'J':
switch(r(2)) {
case 0:
fprintf(outf,"C7 ");
break;
case 1:
fprintf(outf,"60 ");
break;
}
break;
case 'K':
switch(r(2)) {
case 0:
fprintf(outf,"58 ");
break;
case 1:
fprintf(outf,"72 ");
break;
}
break;
case 'L':
switch(r(1)) {
case 0:
fprintf(outf,"D7 ");
break;
}
break;
case 'M':
switch(r(6)) {
case 0:
fprintf(outf,"B3 ");
break;
case 1:
fprintf(outf,"67 ");
break;
case 2:
fprintf(outf,"79 ");
break;
case 3:
fprintf(outf,"AC ");
break;
case 4:
fprintf(outf,"CD ");
break;
case 5:
fprintf(outf,"D1 ");
break;
}
break;
case 'N':
switch(r(2)) {
case 0:
fprintf(outf,"57 ");
break;
case 1:
fprintf(outf,"52 ");
break;
}
break;
case 'O':
switch(r(1)) {
case 0:
fprintf(outf,"74 ");
break;
}
break;
case 'P':
switch(r(1)) {
case 0:
fprintf(outf,"55 ");
break;
}
break;
case 'Q':
switch(r(2)) {
case 0:
fprintf(outf,"B0 ");
break;
case 1:
fprintf(outf,"A5 ");
break;
}
break;
case 'R':
switch(r(4)) {
case 0:
fprintf(outf,"7F ");
break;
case 1:
fprintf(outf,"B9 ");
break;
case 2:
fprintf(outf,"BF ");
break;
case 3:
fprintf(outf,"C2 ");
break;
}
break;
case 'S':
switch(r(4)) {
case 0:
fprintf(outf,"4A ");
break;
case 1:
fprintf(outf,"C4 ");
break;
case 2:
fprintf(outf,"4F ");
break;
case 3:
fprintf(outf,"DB ");
break;
}
break;
case 'T':
switch(r(3)) {
case 0:
fprintf(outf,"B1 ");
break;
case 1:
fprintf(outf,"5E ");
break;
case 2:
fprintf(outf,"7E ");
break;
}
break;
case 'U':
switch(r(2)) {
case 0:
fprintf(outf,"B5 ");
break;
case 1:
fprintf(outf,"CE ");
break;
}
break;
case 'V':
switch(r(1)) {
case 0:
fprintf(outf,"51 ");
break;
}
break;
case 'W':
switch(r(4)) {
case 0:
fprintf(outf,"7B ");
break;
case 1:
fprintf(outf,"C6 ");
break;
case 2:
fprintf(outf,"D2 ");
break;
case 3:
fprintf(outf,"D5 ");
break;
}
break;
case 'X':
switch(r(2)) {
case 0:
fprintf(outf,"C8 ");
break;
case 1:
fprintf(outf,"DC ");
break;
}
break;
case 'Y':
switch(r(3)) {
case 0:
fprintf(outf,"5C ");
break;
case 1:
fprintf(outf,"78 ");
break;
case 2:
fprintf(outf,"BA ");
break;
}
break;
case 'Z':
switch(r(1)) {
case 0:
fprintf(outf,"B8 ");
break;
}
break;
}
}
printline(buf)
char *buf;
{
int i;
fprintf(outf,"%f %f moveto\n",xpos,ypos);
fprintf(outf,"< ");
while(*buf) {
putletter(*buf);
buf++;
}
fprintf(outf,"> show\n");
ypos -= 1.5*curfontsize;
if(ypos
fprintf(outf,"showpage\n");
ypos = TOPMARGIN;
}
}
main(argc,argv)
int argc;
char **argv;
{
int i;
char *cptr;
FILE *ff;
if(argc<3) {
fprintf(stderr,"\nusage: kanji in.txt out.ps [[pntsize] -r]\n");
exit(1);
}
if(argc>3)
curfontsize = atof(argv[3]);
else
curfontsize = DEFFONTSIZE;
if(argc>4)
randmode = 1;
else
randmode = 0;
/* open the input file */
inf = fopen(argv[1],"r");
if(!inf) {
fprintf(stderr,"format: can't open input file %s\n",argv[1]);
exit(1);
}
/* open the output file */
outf = fopen(argv[2],"w");
if(!outf) {
fprintf(stderr,"format: can't open output file %s\n",argv[2]);
exit(1);
}
/* copy the font file to output */
ff = fopen(KANJIFONTFILE,"r");
if(!ff) {
fprintf(stderr,"kanji: can't open input file %s\n",KANJIFONTFILE);
exit(1);
}
fcopy(ff,outf);
fclose(ff);
fprintf(outf,"/KANJI findfont %f scalefont setfont\n",curfontsize);
while(fgets(oneline,MAXLEN,inf))
printline(oneline);
fclose(inf);
fprintf(outf,"showpage\n");
fclose(outf);
}
|
|
|
|