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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
char *charstrs[34][256];
int charlens[34][256];
char *version_str="001.001";
int kcode_high;
char *StdHW="32";
char *StdVW="32";
char *UniqueId="9876";
char *FontBase="dm";
char fontname[256];
FILE *ofp;
int ecol=0;
char *jsf_names[] = {
"",
"jsy",
"jroma",
"jhira",
"jkata",
"jgreek",
"jrussian",
"jkeisen",
"jka",
"jkb",
"jkc",
"jkd",
"jke",
"jkf",
"jkg",
"jkh",
"jki",
"jkj",
"jkk",
"jkl",
"jkm",
"jkn",
"jko",
"jkp",
"jkq",
"jkr",
"jks",
"jkt",
"jku",
"jkv",
"jkw",
"jkx",
"jky",
"jkz",
NULL
};
#define kushift(c) c+0x20
#define tenshift(c) c+0x20
compute_fc(ku, ten, f, c)
register short ku, ten;
unsigned short *f, *c;
{
register int n;
ku -= 0x20;
ten -= 0x20;
*f = 1;
*c = 1;
if (ku <= 0 || (9 <= ku && ku <= 15) || ku > 84) {
fprintf(stderr,"invalid ku in jis (%x, %x)", ku+0x20, ten+0x20);
return;
}
if (ten < 1 || ten > 94) {
fprintf(stderr,"invalid ten in jis (%x, %x)", ku+0x20, ten+0x20);
return;
}
if (ku <= 8) {
if (ku == 1) {
*f = 1;
*c = ten;
} else if (ku == 2) {
*f = 1;
*c = ten+100;
} else if (ku == 3) {
*f = 2;
*c = ten+32;
} else {
*f = ku-1;
*c = ten;
}
} else if (ku <= 47) { /* Daiich Suijun */
n = (ku-16)*94+ten-1;
*f = (n/256)+8;
*c = n%256;
} else { /* Daini Suijun */
n = (ku-48)*94+ten-1;
*f = (n/256)+20;
*c = n%256;
}
}
readfiles(filename)
char *filename;
{
FILE *fd;
char buf[4096],*cptr;
int kcode_low,i,len,kcode,c1;
unsigned short f,c;
if((fd=fopen(filename,"r"))==NULL){
fprintf(stderr,"File %s is not found\n",filename);
exit(1);
}
while(fgets(buf,4096,fd)!=NULL){
len=strlen(buf);
if(buf[0]=='<' && !strncmp(buf+len-6 ,"CompD",5)){
kcode=strtol(buf+len-12,NULL,16);
compute_fc((kcode>>8)&255, (kcode&255), &f, &c);
charlens[f][c]=(len-16)/2;
cptr=charstrs[f][c]=(char *)malloc((len-16)/2);
for(i=0;i<(len-16)/2;i++){
c1=buf[i*2+1];c=buf[i*2+2];
*cptr++ = ((c1>='a' ? c1-'a'+10 : c1-'0')<<4)
|(c>='a' ? c-'a'+10 : c-'0');
}
}
}
fclose(fd);
}
main(ac,ag)
char **ag;
{
int i,j;
for(i=1;i<ac;i++){
if(*ag[i]!='-')break;
if(!strcmp(ag[i]+1,"version")){
version_str=ag[++i];
}
else if(!strcmp(ag[i]+1,"StdHW")){
StdHW=ag[++i];
}
else if(!strcmp(ag[i]+1,"StdVW")){
StdVW=ag[++i];
}
else if(!strcmp(ag[i]+1,"UniqueId")){
UniqueId=ag[++i];
}
else if(!strcmp(ag[i]+1,"FontBase")){
FontBase=ag[++i];
}
}
for(;i<ac;i++)
readfiles(ag[i]);
for(i=1;i<sizeof(jsf_names)/sizeof(char *)-1;i++){
for(j=0;j<256;j++)
if(charstrs[i][j])break;
if(j<256){
sprintf(fontname,"%s%s",FontBase,jsf_names[i]);
output_pfa(i);
output_afm(i);
}
}
return 0;
}
output_afm(file)
{
int i;
char filename[256];
sprintf(filename,"%s.afm",fontname);
if((ofp=fopen(filename,"w"))==NULL){
fprintf(stderr,"Failed opening file %s\n",filename);
exit(1);
}
fprintf(ofp,"StartFontMetrics 2.0\n");
fprintf(ofp,"FontName %s\n",fontname);
fprintf(ofp,"FullName %s\n",fontname);
fprintf(ofp,"FamilyName %s\n",FontBase);
fprintf(ofp,"Weight Regular\n");
fprintf(ofp,"ItalicAngle 0\n");
fprintf(ofp,"IsFixedPitch true\n");
fprintf(ofp,"FontBBox 0 0 1000 1000\n");
fprintf(ofp,"UnderlinePosition 0\n");
fprintf(ofp,"UnderlineThickness 0\n");
fprintf(ofp,"Version 001.001\n");
fprintf(ofp,"EncodingScheme DmEncoding\n");
fprintf(ofp,"StartCharMetrics 256\n");
for(i=0;i<256;i++)
if(charstrs[file][i])
fprintf(ofp,"C %d ; WX 1000 ; N c%02X ; B 0 0 1000 1000 ;\n",i,i);
fprintf(ofp,"EndCharMetrics\n");
fprintf(ofp,"EndFontMetrics\n");
fclose(ofp);
}
output_header(file)
{
int i,j;
time_t now=time(0);
fprintf(ofp,"%%!PS-AdobeFont-1.0: %s %s\n",fontname,version_str);
fprintf(ofp,"%%%%Creation Date: %s",ctime(&now));
fprintf(ofp,"%%%%VMusage: 100000 100000\n"); /* dummy */
fprintf(ofp,"12 dict begin\n");
fprintf(ofp,"/FontInfo 8 dict dup begin\n");
fprintf(ofp,"/version (%s) readonly def\n",version_str);
fprintf(ofp,"/FullName (%s) readonly def\n",fontname);
fprintf(ofp,"/FamilyName (%s) readonly def\n",FontBase);
fprintf(ofp,"/Weight (Regular) readonly def\n");
fprintf(ofp,"/ItalicAngle 0 def\n");
fprintf(ofp,"/isFixedPitch true def\n");
fprintf(ofp,"/UnderlinePosition 0 def\n");
fprintf(ofp,"/UnderlineThickness 0 def\n");
fprintf(ofp,"end readonly def\n");
fprintf(ofp,"/FontName /%s def\n",fontname);
fprintf(ofp,"/Encoding 256 array\n");
fprintf(ofp,"0 1 255 {1 index exch /.notdef put} for\n");
for(i=0;i<16;i++){
for(j=0;j<16;j++)
fprintf(ofp,"dup %d /c%02X put\n",i*16+j,i*16+j);
}
fprintf(ofp,"readonly def\n");
fprintf(ofp,"/PaintType 0 def\n");
fprintf(ofp,"/FontType 1 def\n");
fprintf(ofp,"/FontMatrix [.001 0 0 .001 0 -0.16] readonly def\n");
fprintf(ofp,"/UniqueId %s def\n",UniqueId);
fprintf(ofp,"/FontBBox [0 0 1000 1000] readonly def \n");
fprintf(ofp,"currentdict end\n");
fprintf(ofp,"currentfile eexec\n");
}
output_pfa(file)
{
int i,j,len,charlen;
/* new integer ii for counting characters */
int ii=1;
char filename[256];
sprintf(filename,"%s.pfa",fontname);
if((ofp=fopen(filename,"w"))==NULL){
fprintf(stderr,"Failed opening file %s\n",filename);
exit(1);
}
output_header(file);
init_crypt();
e_putchar(0);
e_putchar(0);
e_putchar(0);
e_putchar(0);
e_printf("dup /Private 17 dict dup begin\n");
e_printf("/-|{string currentfile exch readstring pop}executeonly def\n");
e_printf("/|-{noaccess def}executeonly def\n");
e_printf("/|{noaccess put}executeonly def\n");
e_printf("/BlueValues [] |-\n");
e_printf("/OtherBlues [] |-\n");
e_printf("/MinFeature{16 16} |-\n");
e_printf("/StdHW [ %s ] |-\n",StdHW);
e_printf("/StdVW [ %s ] |-\n",StdVW);
e_printf("/ForceBold false def\n");
e_printf("/password 5839 def\n");
e_printf("/UniqueId %s def\n",UniqueId);
e_printf("/OtherSubrs [] |-\n");
e_printf("/Subrs 5 array\n");
e_printf("dup 0 15 -| \020\2771p|\020\024\020=-\223D\\\342R |\n");
e_printf("dup 1 9 -| \020\2771py\274\366Uz |\n");
e_printf("dup 2 9 -| \020\2771py\275\304\236i |\n");
e_printf("dup 3 5 -| \020\2771p\371 |\n");
e_printf("dup 4 12 -| \020\2771p~\266+6\034\3446z |\n");
e_printf("|-\n");
for(i=0;i<256;i++){
if(charstrs[file][i]!=NULL)
ii++;
}
e_printf("2 index /CharStrings %i dict dup begin\n",ii);
e_printf("/.notdef 10 -| \020\277\061\160\171\312\070\217\347\143 |-\n");
for(i=0;i<256;i++){
if(charstrs[file][i]!=NULL){
e_printf("/c%02X %d -| ",i,charlens[file][i]);
for(j=0;j<charlens[file][i];j++)
e_putchar(*(charstrs[file][i]+j));
e_printf(" |-\n");
}
}
e_printf("end\n");
e_printf("end\n");
e_printf("readonly put\n");
e_printf("noaccess put\n");
e_printf("dup/FontName get exch definefont pop\n");
e_printf("mark currentfile closefile\n");
putc('\n',ofp);
fprintf(ofp,"0000000000000000000000000000000000000000000000000000000000000000\n");
fprintf(ofp,"0000000000000000000000000000000000000000000000000000000000000000\n");
fprintf(ofp,"0000000000000000000000000000000000000000000000000000000000000000\n");
fprintf(ofp,"0000000000000000000000000000000000000000000000000000000000000000\n");
fprintf(ofp,"0000000000000000000000000000000000000000000000000000000000000000\n");
fprintf(ofp,"0000000000000000000000000000000000000000000000000000000000000000\n");
fprintf(ofp,"0000000000000000000000000000000000000000000000000000000000000000\n");
fprintf(ofp,"0000000000000000000000000000000000000000000000000000000000000000\n");
fprintf(ofp,"cleartomark\n");
fclose(ofp);
}
e_printf(form,i0,i1,i2,i3,i4,i5,i6,i7,i8,i9)
char *form;
long i0;
{
int len,i;
unsigned char buf[4096];
sprintf(buf,form,i0,i1,i2,i3,i4,i5,i6,i7,i8,i9);
len=strlen(buf);
for(i=0;i<len;i++)
e_putchar(buf[i]);
}
e_putchar(plain)
unsigned char plain;
{
fprintf(ofp,"%02X",encrypt_char(plain));
ecol+=2;
if(ecol==64){putc('\n',ofp);ecol=0;}
}
unsigned short r,c1,c2;
init_crypt()
{
r=55665,c1=52845,c2=22719;
ecol=0;
}
encrypt_char(plain)
unsigned char plain;
{
unsigned char cipher;
cipher=(plain ^ (r>>8));
r=(cipher+r)*c1+c2;
return cipher;
}
|