gcs8.c
0000/**************************************
0001 gcs8.c PostScript
0002**************************************/
0003#include <stdio.h>
0004#include <stdlib.h>
0005#include <string.h>
0006#include <math.h>
0007#include <sys/types.h>
0008#include <unistd.h>
0009#include <time.h>
0010#include <iconv.h>
0011#include "gcs7.h"
0012#include "gcs8.h"
0013
0014char tmpfle[20];
0015int tmpinit=0;
0016FILE *fpt;
0017int ifopen=0;
0018double vfsizh;
0019double vfsizv;
0020double vfang;
0021int vfdir;
0022double vfbody;
0023
0024int opentmp(char *mode)
0025{
0026 if(tmpinit==0){
0027 tmpinit=getppid()%1000;
0028 if(tmpinit==0) tmpinit=500;
0029 sprintf(tmpfle,"/tmp/gcs%03i.ps",tmpinit);
0030 }
0031 fpt=fopen(tmpfle,mode);
0032 ifopen=1;
0033 return 0;
0034}
0035
0036int psout(char *s)
0037{
0038 opentmp("a");
0039 fprintf(fpt,"%s",s);
0040 fflush(fpt);
0041 fclose(fpt);
0042 ifopen=0;
0043 return 0;
0044}
0045
0046int psmove(double x,double y)
0047{
0048 if(ifopen==0) opentmp("a");
0049 fprintf(fpt,"newpath\n");
0050 // sprintf(s,"%.1f 2.8346 mul %.1f 2.8346 mul moveto\n",*(double *)param[2],*(double *)param[3]);
0051 fprintf(fpt,"%.1f mm %.1f mm moveto\n",x,y);
0052 return 0;
0053}
0054
0055int psline(double x,double y)
0056{
0057 fprintf(fpt,"%.1f mm %.1f mm lineto\n",x,y);
0058 return 0;
0059}
0060
0061int psstroke(double line)
0062{
0063 fprintf(fpt,"%.1f mm setlinewidth\n",line);
0064 fprintf(fpt,"stroke\n");
0065 fflush(fpt);
0066 fclose(fpt);
0067 ifopen=0;
0068 return 0;
0069}
0070
0071int psfill()
0072{
0073 fprintf(fpt,"closepath\nfill\n");
0074 fflush(fpt);
0075 fclose(fpt);
0076 ifopen=0;
0077 return 0;
0078}
0079
0080int psvfont(int hsize,int vsize,double ang,int direc,int body)
0081{
0082 vfsizh=hsize;
0083 vfsizv=vsize;
0084 vfang=ang;
0085 vfdir=direc;
0086 vfbody=body;
0087 return 0;
0088}
0089
0090int pskanji(char *st,double x,double y,double dx)
0091{
0092 char s[300],s1[200],f[5];
0093 int i,j,k,l,m;
0094 iconv_t cd;
0095 char *s2;
0096 char *s3;
0097 char *sp;
0098 char *sp1;
0099 FILE *fontIDX;
0100 FILE *fontDAT;
0101 int posIDX,posDAT,posTMP;
0102 int ch;
0103 int k1,k2,k3,k4;
0104 double x0,y0,x1,y1,x2,y2,x3,y3;
0105 int penUp;
0106 double scalex,scaley,cosa,sina;
0107 size_t inleft,outleft;
0108 unsigned char a[200];
0109
0110 if(ifopen==0) opentmp("a");
0111 scalex=vfsizh/16.;
0112 scaley=vfsizv/16.;
0113 cosa=cos(0.017453293*vfang);
0114 sina=sin(0.017453293*vfang);
0115 strcpy(s,st);
0116 sp=&s[0];
0117 sp1=&s1[0];
0118 inleft=strlen(s);
0119 outleft=199;
0120 cd=iconv_open("SHIFT-JIS","UTF-8");
0121 iconv(cd,&sp,&inleft,&sp1,&outleft);
0122 iconv_close(cd);
0123 s1[199-outleft]='\0';
0124 outleft=strlen(s1); /* now converted to shift-JIS */
0125 x0=x;
0126 y0=y;
0127 x1=x0;
0128 y1=y0;
0129 for(i=0;i<outleft;i++){
0130 if((s1[i]&0x80)==0){
0131 s[0]=s1[i];
0132 s[1]='\0';
0133 }
0134 else{
0135 s[1]=s1[i];
0136 i++;
0137 s[0]=s1[i];
0138 s[2]='\0';
0139 }
0140 j=getVF16s(s,a);
0141 fprintf(fpt,"newpath\n");
0142 penUp=1;
0143 for(j=0;j<100;j++){
0144 ch=a[j];
0145 ch&=0xff;
0146 if(ch==0xff) break;
0147 if(ch!=0xfe) {
0148 k=ch/16;
0149 x3=k;
0150 y3=ch-16*k;
0151 x3=x3*scalex;
0152 y3=y3*scaley;
0153 x2=x1*2.8346+x3;
0154 y2=y1*2.8436+y3;
0155 if(vfang!=0.){
0156 x2=x0*2.8346+((x1-x0)*2.8346+x3)*cosa-((y1-y0)*2.8346+y3)*sina;
0157 y2=y0*2.8346+((x1-x0)*2.8346+x3)*sina+((y1-y0)*2.8346+y3)*cosa;
0158 }
0159 fprintf(fpt,"%.2f %.2f ",x2,y2);
0160 if(penUp) fprintf(fpt,"moveto\n");
0161 else fprintf(fpt,"lineto ");
0162 penUp=0;
0163 }
0164 else penUp=1;
0165 }
0166 fprintf(fpt,"%.3f setlinewidth stroke\n",vfbody*0.1*scalex);
0167 if(vfdir==0) x1=x1+dx;
0168 else y1=y1-dx;
0169 }
0170 fflush(fpt);
0171 fclose(fpt);
0172 ifopen=0;
0173 return 0;
0174}
0175