/*----------------------------------------------------------------------------*/ /* gccIMfont.c */ /*----------------------------------------------------------------------------*/ #include #include #include /*----------------------------------------------------------------------------*/ /* gccIMfont.c cソースファイル */ /* gccIMfont.exe c実行ファイル */ /* */ /* font_dir.txt フォント名書出結果 */ /* w_fon.txt 描画フォント書出ファイル */ /* subIMfont.html html書出結果 */ /* */ /* imfdat\inp.txt 画像用文字列 (UTF8N:事前準備) */ /* imfdat\a.bat ImageMagick実行用バッチファイル */ /* imfdat\imf000.png フォント画像pngファイル */ /* imfdat\temp.prn 画像情報書出結果 */ /*----------------------------------------------------------------------------*/ int main() { FILE *fin,*fout,*fp; char fnameR[50]=""; char fnameW[50]=""; char fnameF[50]=""; char fnameI[50]=""; int i,nd; char dat[256]=""; char sv1[50]=""; char sv2[50]=""; char *p; int iflg; int ww[1000],hh[1000]; char dirR[100]="c:\\Windows\\Fonts"; char dirW[100]="c:\\DATA1\\GNUpro\\gcc7IMfont"; /*フォント名書出用コマンド実行*/ strcpy(fnameW,"font_dir.txt"); fp=popen("cmd.exe","w"); fprintf(fp,"dir %s > %s\\%s\n",dirR,dirW,fnameW); fprintf(fp,"exit\n"); fflush(fp); pclose(fp); /*描画フォント書出ファイル作成*/ /* ポインター p と strstr 関数を用いて拡張子ttfおよびttcを選別*/ strcpy(fnameR,"font_dir.txt"); strcpy(fnameW,"w_fon.txt"); fin=fopen(fnameR,"r"); fout=fopen(fnameW,"w"); fgets(dat,sizeof dat,fin); fgets(dat,sizeof dat,fin); fgets(dat,sizeof dat,fin); fgets(dat,sizeof dat,fin); fgets(dat,sizeof dat,fin); i=0; while(fgets(dat,sizeof dat,fin)!=NULL){ strtok(dat," "); strtok(NULL," "); strtok(NULL," "); strcpy(sv1,""); strcpy(sv2,""); strcpy(sv1,strtok(NULL," ")); strncat(sv2,sv1,strlen(sv1)-1); iflg=0; p=strstr(sv2,".ttf");if(p!=NULL)iflg=1; p=strstr(sv2,".TTF");if(p!=NULL)iflg=1; p=strstr(sv2,".ttc");if(p!=NULL)iflg=2; p=strstr(sv2,".TTC");if(p!=NULL)iflg=2; if(iflg!=0){ i=i+1; fprintf(fout,"%s\n",sv2); } } fclose(fin); fclose(fout); nd=i-1; printf("nd=%d\n",nd); /*ImageMagick実行*/ strcpy(fnameR,"w_fon.txt"); fin=fopen(fnameR,"r"); fp=popen("cmd.exe","w"); i=0; while(fgets(dat,sizeof dat,fin)!=NULL){ strcpy(fnameF,""); strncat(fnameF,dat,strlen(dat)-1); fprintf(fp,"convert -trim -background white -fill navy -font c:\\Windows\\Fonts\\%s -pointsize 32 label:@inp.txt %s\\imfdat\\imf%03d.png\n",fnameF,dirW,i); fprintf(fp,"convert -bordercolor \"#ffffff\" -border 5 %s\\imfdat\\imf%03d.png %s\\imfdat\\temp.png\n",dirW,i,dirW); fprintf(fp,"del %s\\imfdat\\imf%03d.png\n",dirW,i); fprintf(fp,"rename %s\\imfdat\\temp.png imf%03d.png\n",dirW,i); if(i==0)fprintf(fp,"identify %s\\imfdat\\imf%03d.png > %s\\imfdat\\temp.prn\n",dirW,i,dirW); if(1<=i)fprintf(fp,"identify %s\\imfdat\\imf%03d.png >> %s\\imfdat\\temp.prn\n",dirW,i,dirW); i=i+1; } fprintf(fp,"cd ..\n"); fprintf(fp,"exit\n"); fflush(fp); pclose(fp); fclose(fin); nd=i-1; printf("nd=%d\n",nd); /*画像情報取得*/ strcpy(dat,""); strcat(dat,dirW); strcat(dat,"\\imfdat\\temp.prn"); strcpy(fnameR,dat); printf("%s\n",fnameR); fin=fopen(fnameR,"r"); for(i=0;i<=nd;i++){ fgets(dat,sizeof dat,fin); strtok(dat," "); strtok(NULL," "); strcpy(sv1,strtok(NULL," ")); ww[i]=atoi(strtok(sv1,"x")); hh[i]=atoi(strtok(NULL,"x")); } fclose(fin); /*htmlファイル書き出し*/ strcpy(dat,""); strcat(dat,dirW); strcat(dat,"\\w_fon.txt"); strcpy(fnameR,dat); strcpy(dat,""); strcat(dat,dirW); strcat(dat,"\\subIMfont.html"); strcpy(fnameW,dat); printf("%s\n",fnameR); printf("%s\n",fnameW); fin=fopen(fnameR,"r"); fout=fopen(fnameW,"w"); fprintf(fout,"\n"); fprintf(fout,"\n"); fprintf(fout,"\n"); for(i=0;i<=nd;i++){ fgets(dat,sizeof dat,fin); strcpy(fnameF,""); strncat(fnameF,dat,strlen(dat)-1); fprintf(fout,"\n"); fprintf(fout,"\n"); fprintf(fout,"\n"); fprintf(fout,"\n"); fprintf(fout,"\n"); } fprintf(fout,"
\n"); fprintf(fout,"%s\n",fnameF); fprintf(fout,"\n"); fprintf(fout,"\"imf%03d.png\"\n",i,i,ww[i],hh[i]); fprintf(fout,"\n"); fprintf(fout,"%dx%d\n",ww[i],hh[i]); fprintf(fout,"
\n"); fprintf(fout,"\n"); fprintf(fout,"\n"); fclose(fin); fclose(fout); return 0; } /*----------------------------------------------------------------------------*/