00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef __BETA35__
00027 #define _DLL
00028 #endif
00029 #include <ctype.h>
00030 #include <stdlib.h>
00031 #include <stdio.h>
00032 #include <math.h>
00033 #include <setjmp.h>
00034 #include <windows.h>
00035 #include <windowsx.h>
00036 #if __HELP_WS__
00037 #include "..\help_ws\include\htmlhelp.h"
00038 #endif
00039
00040 #include "struct.h"
00041 #include "dstruct.h"
00042 #include "atm.h"
00043 #include "atmdlg.h"
00044
00045 #ifndef PI
00046 #define PI 3.1415926
00047 #endif
00048
00049 #if __X__MIPS__
00050 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00051 #endif
00052
00053 typedef struct FOUR_INTEGERS {
00054 long x1,y1,x2,y2;
00055 float dx,dy;
00056 } four_integers;
00057
00058 #define OK 1
00059 #define FAIL 0
00060 #define LINESIZE 256
00061 #define cgetc() cdecrypt(egetc())
00062 #define SP type1_stackpointer
00063
00064 static void MakeNewPSletter(HWND);
00065 static void DrawATMfontShapePreview(HDC hdc,RECT rc);
00066 static void DrawATMfontProfilePreview(HDC hdc,RECT rc);
00067 static void LoadATMfontPreviewCharacter(HWND hwnd);
00068 static BOOL CALLBACK AtmDlgProc(HWND hwnd, UINT msg,
00069 WPARAM wparam, LPARAM lparam);
00070 static BOOL GetATMfontfile(HWND parent, char *szdir);
00071 static void output_token(char *token);
00072 static short decode_build_type1(int tc, char *PSfile);
00073 static int eexec_scanner(char c);
00074 static int hexval(char c);
00075 static int bgetc(void);
00076 static byte edecrypt(byte cipher);
00077 static byte cdecrypt(byte cipher);
00078 static int immediate_eexec(void);
00079 static int egetc(void);
00080 static void egetline(void);
00081 static void set_lenIV(void);
00082 static int get_character_name(void);
00083 static short add_build_command(int b, int com);
00084 static short do_charstring(void);
00085 static int get_subroutine_number(void);
00086 static int get_Subroutines(void);
00087 static void process_pseudo_routine(character_program Cp);
00088 static void PseudoCurveUpto(point *p, double d, long n, long xx, long yy);
00089 static void CreateCharacterEdge(long x1, long y1, long x2, long y2);
00090 static void Casteljau2(point p, point *va, long i, long j, double mu);
00091
00092 static BITMAP AtmHelpBitmap;
00093 static HBITMAP hBitmap=NULL;
00094 static HINSTANCE hThisInstance=NULL;
00095 static HWND hwndParent=NULL;
00096 static FILE *ifp;
00097 static ATM_STRUCTURE *lpAtm;
00098 static char load_line[LINESIZE],ATMfontDir[255],*szRoot;
00099 static char character_name[64],this_character[64];
00100 static int PS_fail=0,*type1_stack,type1_stack_size=512,SP;
00101 static long nATM_preview_list=0,nATM_preview_piece=0;
00102 static four_integers *ATM_preview_list=NULL;
00103 static long IVP,IVF,XX,YY,Cwidthx,Cwidthy,Scale=32,Nmax=40;
00104 static double MaxScale=1000.0;
00105
00106 #include "atm1.c"
00107
00108 PSTR FileInPath(PSTR pstrPath){
00109 PSTR pstr;
00110 pstr = pstrPath + strlen(pstrPath);
00111 while (pstr > pstrPath) {
00112 pstr = (AnsiPrev(pstrPath, pstr));
00113 if (*pstr == '\\' || *pstr == ':' || *pstr == '/') {
00114 pstr = (AnsiNext(pstr));
00115 break;
00116 }
00117 }
00118 return pstr;
00119 }
00120
00121 static BOOL GetATMfontfile(HWND parent, char *szdir){
00122 int i;
00123 OPENFILENAME ofn;
00124 char szFilter[80],szdummy[255];
00125 szdummy[0]='\0';
00126 strcpy(szFilter,"(*.PFB)|*.pfb|(*.PFA)|*.pfa|");
00127 i=0; while(szFilter[i] != '\0'){
00128 if(szFilter[i] == '|')szFilter[i]='\0'; i++;
00129 }
00130 memset(&ofn,0,sizeof(OPENFILENAME));
00131 ofn.lStructSize=sizeof(OPENFILENAME);
00132 ofn.hwndOwner=parent;
00133 ofn.lpstrFilter=szFilter;
00134 ofn.nFilterIndex=1;
00135 ofn.lpstrFile=lpAtm->last_ATM_font;
00136 ofn.nMaxFile=255;
00137 ofn.lpstrFileTitle=szdummy;
00138 ofn.nMaxFileTitle=255;
00139 ofn.lpstrInitialDir=szdir;
00140 ofn.lpstrTitle="PFB Program to Execute";
00141 ofn.Flags=OFN_HIDEREADONLY|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST;
00142 i=(int)(GetOpenFileName(&ofn));
00143 if(i){
00144 strcpy(szdummy,lpAtm->last_ATM_font);
00145 *AnsiPrev(szdummy,FileInPath(szdummy)) = '\0';
00146 strcpy(szdir,szdummy);
00147 return TRUE;
00148 }
00149 return FALSE;
00150 }
00151
00152 #if __WATCOMC__
00153 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00154 #else
00155 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00156 #endif
00157 switch (dwReason) {
00158 case DLL_PROCESS_ATTACH: {
00159 #if __X__MIPS__
00160 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00161
00162 #endif
00163 hThisInstance=hDLL;
00164 break;
00165 }
00166 case DLL_PROCESS_DETACH:
00167 #if __X__MIPS__
00168 if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00169
00170 #endif
00171 break;
00172 }
00173 return TRUE;
00174 }
00175
00176 #if __SC__
00177 #pragma startaddress(DllMain)
00178 #endif
00179
00180 BOOL _ATMbuilder(
00181 HWND parent, char *szdir, X__STRUCTURE *lpevi, ATM_STRUCTURE *lpatm){
00182 int i;
00183 szRoot=szdir;
00184 hwndParent=parent;
00185 lpAtm=lpatm;
00186 lpEVI=lpevi;
00187 strcpy(ATMfontDir,szdir);
00188 strcat(ATMfontDir,"fonts");
00189 if(lpAtm->last_ATM_font[0] == 0){
00190 if(!GetATMfontfile(parent,ATMfontDir))return FALSE;
00191 }
00192 else{
00193 strcpy(ATMfontDir,lpAtm->last_ATM_font);
00194 *AnsiPrev(ATMfontDir,FileInPath(ATMfontDir)) = '\0';
00195 }
00196 if(DialogBox(hThisInstance,MAKEINTRESOURCE(DLG_ATM),hwndParent,
00197 (DLGPROC)AtmDlgProc) == OK){
00198
00199 MakeNewPSletter(parent);
00200 return TRUE;
00201 }
00202 return FALSE;
00203 }
00204
00205 static char *ColorSelectDlgString;
00206
00207 static BOOL CALLBACK ColorSelectDlgProc(HWND hwnd, UINT msg, WPARAM wparam,
00208 LPARAM lparam){
00209 switch( msg ) {
00210 case WM_INITDIALOG:
00211 SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)ColorSelectDlgString);
00212 return TRUE;
00213 default:
00214 break;
00215 }
00216 return FALSE;
00217 }
00218
00219 static void SetAtmColour(unsigned char colour[], char *Title, HWND parent){
00220 CHOOSECOLOR cc;
00221 static COLORREF CustColours[16]={
00222 RGB(255,255,255), RGB(239,239,239), RGB(223,223,223), RGB(207,207,207),
00223 RGB(191,191,191), RGB(175,175,175), RGB(159,159,159), RGB(143,143,143),
00224 RGB(127,127,127), RGB(111,111,111), RGB( 95, 95, 95), RGB( 79, 79, 79),
00225 RGB( 63, 63, 63), RGB( 47, 47, 47), RGB( 31, 31, 31), RGB( 15, 15, 15) };
00226 cc.lStructSize=sizeof(CHOOSECOLOR);
00227 cc.hwndOwner=parent;
00228 cc.rgbResult=RGB(colour[0],colour[1],colour[2]);
00229 cc.lpCustColors=(LPDWORD)CustColours;
00230 cc.Flags=CC_FULLOPEN | CC_RGBINIT | CC_ENABLEHOOK;
00231 cc.lCustData=(DWORD)0;
00232 ColorSelectDlgString=Title;
00233 cc.lpfnHook=(LPCCHOOKPROC)ColorSelectDlgProc;
00234 if(ChooseColor(&cc)){
00235 colour[0]=GetRValue(cc.rgbResult);
00236 colour[1]=GetGValue(cc.rgbResult);
00237 colour[2]=GetBValue(cc.rgbResult);
00238 }
00239 }
00240
00241 static void UpdateAtmSlider(HWND hwnd,int sliderID,int valueID,int value){
00242 char str[16];
00243 SetScrollPos(GetDlgItem(hwnd,sliderID),SB_CTL,value,TRUE);
00244 sprintf(str,"%ld",value);
00245 SendDlgItemMessage(hwnd,valueID,WM_SETTEXT,0,(LPARAM)str);
00246 }
00247
00248 static void UpdateAdobeName(HWND hwnd){
00249 SendDlgItemMessage(hwnd,DLG_ATM_ADOBE_NAME,WM_SETTEXT,0,(LPARAM)load_line);
00250 }
00251
00252 static BOOL CALLBACK AtmDlgProc(HWND hwnd, UINT msg,
00253 WPARAM wparam, LPARAM lparam){
00254 RECT rc;
00255 char str[16];
00256 int iMin,iMax;
00257 int hp[7]={DLG_ATM_CPDL,DLG_ATM_CPDC,DLG_ATM_CPDR,DLG_ATM_CPCC,
00258 DLG_ATM_CPUL,DLG_ATM_CPUC,DLG_ATM_CPUR};
00259 HWND hctl;
00260 BITMAP bmp;
00261 switch( msg ) {
00262 case WM_INITDIALOG:
00263 hBitmap=LoadBitmap(hThisInstance,MAKEINTRESOURCE(IDBM_HELP));
00264 if(hBitmap != NULL){
00265 GetObject(hBitmap,sizeof(BITMAP),&AtmHelpBitmap);
00266 }
00267 LoadATMfontPreviewCharacter(hwnd);
00268 EnableWindow(GetDlgItem(hwnd,DLG_ATM_ADOBE_NAME),FALSE);
00269 SetScrollRange(GetDlgItem(hwnd,DLG_ATM_BEVEL_ANGLE),SB_CTL,5,80,FALSE);
00270 SetScrollRange(GetDlgItem(hwnd,DLG_ATM_BEVEL_DEPTH),SB_CTL,0,100,FALSE);
00271 SetScrollRange(GetDlgItem(hwnd,DLG_ATM_CHAR_WIDTH),SB_CTL,0,100,FALSE);
00272 SendDlgItemMessage(hwnd,hp[lpAtm->ATM_offset],BM_SETCHECK,TRUE,0);
00273 UpdateAtmSlider(hwnd,DLG_ATM_BEVEL_ANGLE,DLG_ATM_BEVEL_ANGLEN,
00274 lpAtm->ATM_bevel_angle);
00275 UpdateAtmSlider(hwnd,DLG_ATM_BEVEL_DEPTH,DLG_ATM_BEVEL_DEPTHN,
00276 lpAtm->ATM_bevel_width);
00277 UpdateAtmSlider(hwnd,DLG_ATM_CHAR_WIDTH,DLG_ATM_CHAR_WIDTHN,
00278 lpAtm->ATM_chara_width);
00279 sprintf(str,"%c",lpAtm->ATM_char_preview);
00280 SendDlgItemMessage(hwnd,DLG_ATM_PREVIEW,WM_SETTEXT,0,(LPARAM)str);
00281 SendDlgItemMessage(hwnd,DLG_ATM_FONTID,WM_SETTEXT,0,(LPARAM)lpAtm->last_ATM_font);
00282 if(lpAtm->FORB > 0)
00283 SendDlgItemMessage(hwnd,DLG_ATM_LR,BM_SETCHECK,TRUE,0);
00284 else SendDlgItemMessage(hwnd,DLG_ATM_RL,BM_SETCHECK,TRUE,0);
00285 if(lpAtm->ATM_bevel_back)
00286 SendDlgItemMessage(hwnd,DLG_ATM_BEVEL_BACK,BM_SETCHECK,TRUE,0);
00287 if(lpAtm->ATM_bevel_front)
00288 SendDlgItemMessage(hwnd,DLG_ATM_BEVEL_FRONT,BM_SETCHECK,TRUE,0);
00289 if(lpAtm->ATM_cap)
00290 SendDlgItemMessage(hwnd,DLG_ATM_FILL,BM_SETCHECK,TRUE,0);
00291 else SendDlgItemMessage(hwnd,DLG_ATM_NOFILL,BM_SETCHECK,TRUE,0);
00292 sprintf(str,"%s",lpAtm->ATM_Letters);
00293 SendDlgItemMessage(hwnd,DLG_ATM_TEXT,WM_SETTEXT,0,(LPARAM)str);
00294 SendDlgItemMessage(hwnd,DLG_ATM_TEXT,EM_LIMITTEXT,(WPARAM)60,0);
00295 EnableWindow(GetDlgItem(hwnd,DLG_ATM_MAKE),
00296 Edit_LineLength(GetDlgItem(hwnd,DLG_ATM_TEXT), 0) > 0);
00297 GetWindowRect(hwnd, &rc);
00298 SetWindowPos(hwnd, NULL,
00299 (GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2,
00300 (GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2,
00301 0, 0, SWP_NOSIZE | SWP_NOZORDER);
00302 return (TRUE);
00303 case WM_DRAWITEM:{
00304 LPDRAWITEMSTRUCT lpdis;
00305 HBRUSH hbr,hbrold;
00306 BYTE r,g,b;
00307 lpdis=(LPDRAWITEMSTRUCT)lparam;
00308 if(lpdis->CtlID == DLG_ATM_COLOUR_FACES ||
00309 lpdis->CtlID == DLG_ATM_COLOUR_SIDES ||
00310 lpdis->CtlID == DLG_ATM_COLOUR_BEVEL){
00311 if(lpdis->CtlID == DLG_ATM_COLOUR_FACES){
00312 r=lpAtm->ATM_face_colour[0];
00313 g=lpAtm->ATM_face_colour[1];
00314 b=lpAtm->ATM_face_colour[2];
00315 }
00316 else if(lpdis->CtlID == DLG_ATM_COLOUR_SIDES){
00317 r=lpAtm->ATM_side_colour[0];
00318 g=lpAtm->ATM_side_colour[1];
00319 b=lpAtm->ATM_side_colour[2];
00320 }
00321 else if(lpdis->CtlID == DLG_ATM_COLOUR_BEVEL){
00322 r=lpAtm->ATM_beve_colour[0];
00323 g=lpAtm->ATM_beve_colour[1];
00324 b=lpAtm->ATM_beve_colour[2];
00325 }
00326 if(lpdis->itemState & ODS_SELECTED)
00327 InvertRect(lpdis->hDC,&(lpdis->rcItem));
00328 else{
00329 hbr=CreateSolidBrush(RGB(r,g,b));
00330 hbrold=SelectObject(lpdis->hDC,hbr);
00331 Rectangle(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,
00332 lpdis->rcItem.right,lpdis->rcItem.bottom);
00333 SelectObject(lpdis->hDC,hbrold);
00334 DeleteObject(hbr);
00335 }
00336 }
00337 else if(lpdis->CtlID == DLG_ATM_SHAPE)
00338 DrawATMfontShapePreview(lpdis->hDC,lpdis->rcItem);
00339 else if(lpdis->CtlID == DLG_ATM_PROFILE)
00340 DrawATMfontProfilePreview(lpdis->hDC,lpdis->rcItem);
00341 else if(lpdis->CtlID == DLG_ATM_INFO && hBitmap != NULL){
00342 HDC hMemDC;
00343 HBITMAP hbmOld;
00344 hMemDC = CreateCompatibleDC(lpdis->hDC);
00345 hbmOld = SelectObject(hMemDC,hBitmap);
00346 BitBlt(lpdis->hDC,lpdis->rcItem.left
00347 ,lpdis->rcItem.top
00348 ,AtmHelpBitmap.bmWidth
00349 ,AtmHelpBitmap.bmHeight
00350 ,hMemDC,0,0,SRCCOPY);
00351 SelectObject(hMemDC,hbmOld);
00352 DeleteDC(hMemDC);
00353 }
00354 }
00355 return TRUE;
00356 case WM_HSCROLL:
00357 if((HWND)lparam == (hctl=GetDlgItem(hwnd,DLG_ATM_BEVEL_ANGLE))){
00358 GetScrollRange(hctl,SB_CTL,&iMin,&iMax);
00359 switch (LOWORD(wparam)) {
00360 case SB_PAGEDOWN:
00361 case SB_LINEDOWN:
00362 lpAtm->ATM_bevel_angle = min(iMax,lpAtm->ATM_bevel_angle+1);
00363 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00364 break;
00365 case SB_PAGEUP:
00366 case SB_LINEUP:
00367 lpAtm->ATM_bevel_angle = max(iMin,lpAtm->ATM_bevel_angle-1);
00368 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00369 break;
00370 case SB_THUMBTRACK:
00371 case SB_THUMBPOSITION:
00372 lpAtm->ATM_bevel_angle=HIWORD(wparam);
00373 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00374 break;
00375 default: break;
00376 }
00377 UpdateAtmSlider(hwnd,DLG_ATM_BEVEL_ANGLE,DLG_ATM_BEVEL_ANGLEN,
00378 lpAtm->ATM_bevel_angle);
00379 }
00380 else if((HWND)lparam == (hctl=GetDlgItem(hwnd,DLG_ATM_BEVEL_DEPTH))){
00381 GetScrollRange(hctl,SB_CTL,&iMin,&iMax);
00382 switch (LOWORD(wparam)) {
00383 case SB_PAGEDOWN:
00384 case SB_LINEDOWN:
00385 lpAtm->ATM_bevel_width = min(iMax,lpAtm->ATM_bevel_width+1);
00386 if(lpAtm->ATM_bevel_front || lpAtm->ATM_bevel_back)
00387 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_SHAPE),NULL,FALSE);
00388 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00389 break;
00390 case SB_PAGEUP:
00391 case SB_LINEUP:
00392 lpAtm->ATM_bevel_width = max(iMin,lpAtm->ATM_bevel_width-1);
00393 if(lpAtm->ATM_bevel_front || lpAtm->ATM_bevel_back)
00394 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_SHAPE),NULL,FALSE);
00395 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00396 break;
00397 case SB_THUMBTRACK:
00398 case SB_THUMBPOSITION:
00399 lpAtm->ATM_bevel_width=HIWORD(wparam);
00400 if(lpAtm->ATM_bevel_front || lpAtm->ATM_bevel_back)
00401 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_SHAPE),NULL,FALSE);
00402 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00403 break;
00404 default: break;
00405 }
00406 UpdateAtmSlider(hwnd,DLG_ATM_BEVEL_DEPTH,DLG_ATM_BEVEL_DEPTHN,
00407 lpAtm->ATM_bevel_width);
00408 }
00409 else if((HWND)lparam == (hctl=GetDlgItem(hwnd,DLG_ATM_CHAR_WIDTH))){
00410 GetScrollRange(hctl,SB_CTL,&iMin,&iMax);
00411 switch (LOWORD(wparam)) {
00412 case SB_PAGEDOWN:
00413 case SB_LINEDOWN:
00414 lpAtm->ATM_chara_width = min(iMax,lpAtm->ATM_chara_width+1);
00415 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00416 break;
00417 case SB_PAGEUP:
00418 case SB_LINEUP:
00419 lpAtm->ATM_chara_width = max(iMin,lpAtm->ATM_chara_width-1);
00420 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00421 break;
00422 case SB_THUMBTRACK:
00423 case SB_THUMBPOSITION:
00424 lpAtm->ATM_chara_width=HIWORD(wparam);
00425 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00426 break;
00427 default: break;
00428 }
00429 UpdateAtmSlider(hwnd,DLG_ATM_CHAR_WIDTH,DLG_ATM_CHAR_WIDTHN,
00430 lpAtm->ATM_chara_width);
00431 }
00432 break;
00433 case WM_COMMAND:
00434 switch(LOWORD(wparam)){
00435 case DLG_ATM_CPDL: lpAtm->ATM_offset=0; break;
00436 case DLG_ATM_CPDC: lpAtm->ATM_offset=1; break;
00437 case DLG_ATM_CPDR: lpAtm->ATM_offset=2; break;
00438 case DLG_ATM_CPCC: lpAtm->ATM_offset=3; break;
00439 case DLG_ATM_CPUL: lpAtm->ATM_offset=4; break;
00440 case DLG_ATM_CPUC: lpAtm->ATM_offset=5; break;
00441 case DLG_ATM_CPUR: lpAtm->ATM_offset=6; break;
00442 case DLG_ATM_BEVEL_FRONT:
00443 lpAtm->ATM_bevel_front ^= 1;
00444 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_SHAPE),NULL,FALSE);
00445 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00446 break;
00447 case DLG_ATM_BEVEL_BACK:
00448 lpAtm->ATM_bevel_back ^= 1;
00449 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_SHAPE),NULL,FALSE);
00450 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00451 break;
00452 case DLG_ATM_FILL:
00453 lpAtm->ATM_cap=1;
00454 break;
00455 case DLG_ATM_NOFILL:
00456 lpAtm->ATM_cap=0;
00457 break;
00458 case DLG_ATM_PREVIEW:
00459 if(Edit_LineLength(GetDlgItem(hwnd,DLG_ATM_PREVIEW),0) > 0){
00460 GetDlgItemText(hwnd,DLG_ATM_PREVIEW,str,10);
00461 if(lpAtm->ATM_char_preview != (int)str[0]){
00462 lpAtm->ATM_char_preview=(int)str[0];
00463 LoadATMfontPreviewCharacter(hwnd);
00464 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_SHAPE),NULL,FALSE);
00465 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00466 }
00467 }
00468 break;
00469 case DLG_ATM_TEXT:
00470 EnableWindow(GetDlgItem(hwnd,DLG_ATM_MAKE),
00471 Edit_LineLength((HWND)(lparam), 0) > 0);
00472 break;
00473 case DLG_ATM_CHOOSE:
00474 if(!GetATMfontfile(hwnd,ATMfontDir)){
00475 break;
00476 }
00477 LoadATMfontPreviewCharacter(hwnd);
00478 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_SHAPE),NULL,FALSE);
00479 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_PROFILE),NULL,FALSE);
00480 SendDlgItemMessage(hwnd,DLG_ATM_FONTID,WM_SETTEXT,0,
00481 (LPARAM)lpAtm->last_ATM_font);
00482 break;
00483 case DLG_ATM_HELP:{
00484 char lname[256],res_str1[256],res_str2[256];
00485 GetModuleFileName(hThisInstance,lname,225);
00486 *FileInPath(lname) = '\0';
00487 strcat(lname,"help\\");
00488 strcpy(res_str1,lname);
00489 #if !__HELP_WS__
00490 strcat(res_str1,"des_help.chm");
00491 ShellExecute(hwnd,NULL,res_str1,
00492 NULL,lname,SW_SHOW);
00493 #else
00494 {
00495 HH_WINTYPE hhwin;
00496 memset(&hhwin,0,sizeof(HH_WINTYPE));
00497 hhwin.cbStruct=sizeof(HH_WINTYPE);
00498 hhwin.nShowState=SW_SHOW;
00499 hhwin.pszType="MyHelp";
00500 hhwin.pszCaption="OpenFX Help";
00501 hhwin.fsValidMembers = HHWIN_PARAM_SHOWSTATE |
00502 HHWIN_PARAM_PROPERTIES|
00503 HHWIN_PARAM_CUR_TAB|
00504 HHWIN_PARAM_EXPANSION|
00505 HHWIN_PARAM_RECT;
00506 hhwin.rcWindowPos.top=0;
00507 hhwin.rcWindowPos.left=0;
00508 hhwin.rcWindowPos.right=500;
00509 hhwin.rcWindowPos.bottom=500;
00510 hhwin.nShowState=SW_SHOW;
00511 strcat(res_str1,"des_help.chm");
00512 hhwin.fNotExpanded = TRUE;
00513 hhwin.fsWinProperties = HHWIN_PROP_TRI_PANE|HHWIN_PROP_TAB_SEARCH;
00514 hhwin.curNavType=HHWIN_NAVTYPE_TOC;
00515 strcpy(res_str2,res_str1);
00516 strcat(res_str2,"::toc.hhc");
00517 hhwin.pszToc=res_str2;
00518 strcat(res_str1,"::/Add_Postscript_Text.htm");
00519 HtmlHelp(hwnd,NULL,HH_SET_WIN_TYPE,(DWORD)&hhwin);
00520 HtmlHelp(hwnd,">MyHelp",HH_DISPLAY_TOPIC,(DWORD)res_str1);
00521 }
00522 #endif
00523 }
00524 break;
00525 case DLG_ATM_COLOUR_FACES:
00526 SetAtmColour(lpAtm->ATM_face_colour,"Set Face Color",hwnd);
00527 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_COLOUR_FACES),NULL,FALSE);
00528 break;
00529 case DLG_ATM_COLOUR_BEVEL:
00530 SetAtmColour(lpAtm->ATM_beve_colour,"Set Bevel Color",hwnd);
00531 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_COLOUR_BEVEL),NULL,FALSE);
00532 break;
00533 case DLG_ATM_COLOUR_SIDES:
00534 SetAtmColour(lpAtm->ATM_side_colour,"Set Side Color",hwnd);
00535 InvalidateRect(GetDlgItem(hwnd,DLG_ATM_COLOUR_SIDES),NULL,FALSE);
00536 break;
00537 case DLG_ATM_LR:
00538 lpAtm->FORB = 1;
00539 break;
00540 case DLG_ATM_RL:
00541 lpAtm->FORB = -1;
00542 break;
00543 case DLG_ATM_MAKE:
00544 case DLG_ATM_CANCEL:
00545 if(hBitmap != NULL)DeleteObject(hBitmap);
00546 hBitmap=NULL;
00547 if(ATM_preview_list != NULL)X__Free(ATM_preview_list);
00548 ATM_preview_list=NULL; nATM_preview_list=0;
00549 if(LOWORD(wparam) == DLG_ATM_MAKE){
00550 GetDlgItemText(hwnd,DLG_ATM_TEXT,lpAtm->ATM_Letters,21);
00551 EndDialog(hwnd, OK);
00552 }
00553 else EndDialog(hwnd, FAIL);
00554 return(TRUE);
00555 default:
00556 break;
00557 }
00558 break;
00559 default: break;
00560 }
00561 return(FALSE);
00562 }
00563
00564 static void LoadATMfontPreviewCharacter(HWND hwnd){
00565 int i,ifail;
00566 if(ATM_preview_list != NULL)X__Free(ATM_preview_list);
00567 ATM_preview_list=NULL; nATM_preview_list=0; nATM_preview_piece=0;
00568 n_Subroutines = 0; C_Subs=NULL; Cprogram.n=0; Cprogram.p=NULL;
00569 if((type1_stack=(int *)X__Malloc(512*sizeof(int))) == NULL){
00570 MessageBox(hwnd,"Out of memory","ATM",MB_OK);
00571 return;
00572 }
00573 if((ifp = fopen(lpAtm->last_ATM_font,"rb")) != NULL){
00574 p_key = 0; first_byte = 1; is_pfa = 0; is_pfb = 0; pfb_remaining = 0;
00575 reported = 0; in_eexec = 0; start = 1; start_charstring = 0; lenIV = 4;
00576 in_EncodingArray = 0; in_Subroutines = 0; in_charstring = 0; PS_fail=0;
00577 StandardEncoding=0;
00578 egetline();
00579 for(i=0;i<60;i++)if(load_line[i] == 13 || load_line[i] == 10){
00580 load_line[i]=0; break;
00581 }
00582 load_line[60]=0;
00583 UpdateAdobeName(hwnd);
00584 fclose(ifp);
00585 }
00586 if((ifail=decode_build_type1(lpAtm->ATM_char_preview,
00587 lpAtm->last_ATM_font)) != OK){
00588 if(ifail == FAIL)MessageBox(hwnd,"Font corrupt","ATM",MB_OK);
00589 else if(ifail == MEMFAIL)MessageBox(hwnd,"Out of memory","ATM",MB_OK);
00590 goto FREEALL;
00591 }
00592 SP=0; Cwidthx=0; Cwidthy=0; XX=0; YY=0; IVP = -1; IVF = -1;
00593 process_pseudo_routine(Cprogram);
00594 FREEALL:
00595 X__Free(type1_stack);
00596 if(Cprogram.p != NULL)X__Free(Cprogram.p);
00597 if(C_Subs != NULL && n_Subroutines > 0){
00598 for(i=0;i<n_Subroutines;i++){
00599 if(C_Subs[i].p != NULL)X__Free(C_Subs[i].p);
00600 }
00601 X__Free(C_Subs);
00602 }
00603 C_Subs=NULL;
00604 n_Subroutines=0;
00605 if(nATM_preview_list > 0){
00606 long xmin=1000000, ymin=1000000, xmax = -1000000, ymax = -1000000;
00607 double sx,sy,s;
00608 for(i=0;i<nATM_preview_list;i++){
00609 if(ATM_preview_list[i].x1 < xmin)xmin=ATM_preview_list[i].x1;
00610 if(ATM_preview_list[i].y1 < ymin)ymin=ATM_preview_list[i].y1;
00611 if(ATM_preview_list[i].x2 > xmax)xmax=ATM_preview_list[i].x2;
00612 if(ATM_preview_list[i].y2 > ymax)ymax=ATM_preview_list[i].y2;
00613 sx=(double)(ATM_preview_list[i].x2-ATM_preview_list[i].x1);
00614 sy=(double)(ATM_preview_list[i].y2-ATM_preview_list[i].y1);
00615 s=1.0/sqrt(sx*sx+sy*sy);
00616 ATM_preview_list[i].dx = (float)(-sy*s);
00617 ATM_preview_list[i].dy = (float)( sx*s);
00618 }
00619 sx=(double)(xmax-xmin); sy=(double)(ymax-ymin); s=max(sx,sy);
00620 s=1050.0/s;
00621 for(i=0;i<nATM_preview_list;i++){
00622 ATM_preview_list[i].x1=(long)((double)(ATM_preview_list[i].x1-xmin)*s);
00623 ATM_preview_list[i].y1=(long)((double)(ATM_preview_list[i].y1-ymin)*s);
00624 ATM_preview_list[i].x2=(long)((double)(ATM_preview_list[i].x2-xmin)*s);
00625 ATM_preview_list[i].y2=(long)((double)(ATM_preview_list[i].y2-ymin)*s);
00626 }
00627 }
00628 }
00629
00630 static void process_pseudo_routine(character_program Cp){
00631 int i,com,sid;
00632 long u,v,w,x,y,z,XX1,YY1;
00633 for(i=0;i<Cp.n;i++){
00634 com=(int)Cp.p[i].i;
00635 if(Cp.p[i].com == 0)type1_stack[SP++] = com;
00636 else{
00637 switch(com){
00638 case 1: SP=0; break;
00639 case 3: SP=0; break;
00640 case 4:
00641 x = 0; y = (long)type1_stack[SP-1];
00642 goto MOVEJUMP;
00643 case 5:
00644 x = (long)type1_stack[SP-2];
00645 y = (long)type1_stack[SP-1];
00646 LINEJUMP:
00647 CreateCharacterEdge(XX,YY,XX+x*Scale,YY+y*Scale);
00648 if(IVF < 0)IVF=nATM_preview_list-1;
00649 IVP=nATM_preview_list-1;
00650 XX += x*Scale; YY += y*Scale;
00651 SP=0; break;
00652 case 6:
00653 y = 0; x = (long)type1_stack[SP-1];
00654 goto LINEJUMP;
00655 case 7:
00656 x = 0; y = (long)type1_stack[SP-1];
00657 goto LINEJUMP;
00658 case 8:
00659 u = (long)type1_stack[SP-6];
00660 v = (long)type1_stack[SP-5];
00661 w = (long)type1_stack[SP-4];
00662 x = (long)type1_stack[SP-3];
00663 y = (long)type1_stack[SP-2];
00664 z = (long)type1_stack[SP-1];
00665 CURVEJUMP:
00666 XX1=XX; YY1=YY;
00667 PP[0][0]=XX; PP[0][1]=YY; PP[0][2]=0; XX += u*Scale; YY += v*Scale;
00668 PP[1][0]=XX; PP[1][1]=YY; PP[1][2]=0; XX += w*Scale; YY += x*Scale;
00669 PP[2][0]=XX; PP[2][1]=YY; PP[2][2]=0; XX += y*Scale; YY += z*Scale;
00670 PP[3][0]=XX; PP[3][1]=YY; PP[3][2]=0;
00671 PseudoCurveUpto(PP,MaxScale*Scale,Nmax,XX1,YY1);
00672 IVP=nATM_preview_list-1;
00673 SP=0; break;
00674 case 9:
00675 if(IVF == IVP){
00676 SP=0; IVF=IVP = -1;
00677 nATM_preview_piece=0;
00678 break;
00679 }
00680 if(IVF >= 0 && IVP >= 0){
00681 CreateCharacterEdge(ATM_preview_list[IVP].x2,
00682 ATM_preview_list[IVP].y2,
00683 ATM_preview_list[IVF].x1,
00684 ATM_preview_list[IVF].y1);
00685 }
00686 nATM_preview_piece=0;
00687 IVF=IVP = -1;
00688 SP=0; break;
00689 case 10:
00690
00691 sid=type1_stack[SP-1];
00692 SP=0;
00693 if(sid >= 0 && sid < n_Subroutines)
00694 process_pseudo_routine(C_Subs[sid]);
00695 break;
00696 case 11:
00697 SP=0; return;
00698 case 13:
00699 XX = (long)type1_stack[SP-2]*Scale;
00700 Cwidthx=(long)type1_stack[SP-1]*Scale;
00701 SP=0; break;
00702 case 14:
00703 SP=0; break;
00704 case 21:
00705 x = (long)type1_stack[SP-2];
00706 y = (long)type1_stack[SP-1];
00707 MOVEJUMP:
00708 XX += x*Scale; YY += y*Scale;
00709 SP=0; break;
00710 case 22:
00711 y = 0; x = (long)type1_stack[SP-1];
00712 goto MOVEJUMP;
00713 case 30:
00714 u = 0;
00715 v = (long)type1_stack[SP-4];
00716 w = (long)type1_stack[SP-3];
00717 x = (long)type1_stack[SP-2];
00718 y = (long)type1_stack[SP-1];
00719 z = 0;
00720 goto CURVEJUMP;
00721 case 31:
00722 u = (long)type1_stack[SP-4];
00723 v = 0;
00724 w = (long)type1_stack[SP-3];
00725 x = (long)type1_stack[SP-2];
00726 y = 0;
00727 z = (long)type1_stack[SP-1];
00728 goto CURVEJUMP;
00729 case 12:
00730 i++; com=Cp.p[i].i;
00731 switch (com) {
00732 case 0: SP=0; break;
00733 case 1: SP=0; break;
00734 case 2: SP=0; break;
00735 case 6:
00736 SP=0; break;
00737 case 7:
00738 XX = (long)type1_stack[SP-4]*Scale;
00739 YY = (long)type1_stack[SP-3]*Scale;
00740 Cwidthx=(long)type1_stack[SP-2]*Scale;
00741 Cwidthy=(long)type1_stack[SP-1]*Scale;
00742 SP=0; break;
00743 case 12:
00744 x = (long)type1_stack[SP-2];
00745 y = (long)type1_stack[SP-1];
00746 SP -= 1;
00747 type1_stack[SP-1] = (int)((double)x/(double)y);
00748 break;
00749 case 16:
00750 SP=0; break;
00751 case 17:
00752 type1_stack[SP++] = -1;
00753 break;
00754 case 33:
00755 SP=0; break;
00756 default: SP=0; break;
00757 }
00758 break;
00759 default: SP=0; break;
00760 }
00761 }
00762 }
00763 }
00764
00765 static void PseudoCurveUpto(point *p, double d, long n, long xx, long yy){
00766 long i,j,N;
00767 double l=0,mu;
00768 point po;
00769 for(i=0;i<3;i++)for(j=0;j<2;j++){
00770 l += ((double)(p[i+1][j] - p[i][j]))*(double)((p[i+1][j] - p[i][j]));
00771 }
00772 N=(long)((sqrt(l)/d)*(double)n);
00773 N=max(N,2);
00774 for(i=1;i<=N;i++){
00775 mu=(double)i/(double)N;
00776 Casteljau2(po,p,0,3,mu);
00777 CreateCharacterEdge(xx,yy,po[0],po[1]);
00778 if(IVF < 0)IVF=nATM_preview_list-1;
00779 xx=po[0]; yy=po[1];
00780 }
00781 return;
00782 }
00783
00784 static void CreateCharacterEdge(long x1, long y1, long x2, long y2){
00785 four_integers *fouri;
00786 if(x1 == x2 && y1 == y2)return;
00787 if(nATM_preview_piece > 0 &&
00788 (ATM_preview_list[nATM_preview_list-1].x2 != x1 ||
00789 ATM_preview_list[nATM_preview_list-1].y2 != y1)){
00790 if(ATM_preview_list == NULL){
00791 if((fouri = (four_integers *)X__Malloc(
00792 sizeof(four_integers))) == NULL)return;
00793 }
00794 else {
00795 if((fouri = (four_integers *)X__Realloc(ATM_preview_list,
00796 (nATM_preview_list+1)*sizeof(four_integers))) == NULL)return;
00797 }
00798 fouri[nATM_preview_list].x1=fouri[nATM_preview_list-1].x2;
00799 fouri[nATM_preview_list].y1=fouri[nATM_preview_list-1].y2;
00800 fouri[nATM_preview_list].x2=x1;
00801 fouri[nATM_preview_list].y2=y1;
00802 nATM_preview_list++; nATM_preview_piece++;
00803 ATM_preview_list=fouri;
00804 }
00805 if(ATM_preview_list == NULL){
00806 if((fouri = (four_integers *)X__Malloc(sizeof(four_integers))) == NULL)return;
00807 }
00808 else {
00809 if((fouri = (four_integers *)X__Realloc(ATM_preview_list,
00810 (nATM_preview_list+1)*sizeof(four_integers))) == NULL)return;
00811 }
00812 fouri[nATM_preview_list].x1=x1;
00813 fouri[nATM_preview_list].y1=y1;
00814 fouri[nATM_preview_list].x2=x2;
00815 fouri[nATM_preview_list].y2=y2;
00816 nATM_preview_list++; nATM_preview_piece++;
00817 ATM_preview_list=fouri;
00818 }
00819
00820 static void Casteljau2(point p, point *va, long i, long j, double mu){
00821 point p1,p2;
00822 if(j == 1){
00823 p[0] = (long)((1.0 - mu)*(double)(va[i][0])
00824 + mu*(double)(va[i+1][0]));
00825 p[1] = (long)((1.0 - mu)*(double)(va[i][1])
00826 + mu*(double)(va[i+1][1]));
00827 }
00828 else{
00829 Casteljau2(p1,va,i,j-1,mu);
00830 Casteljau2(p2,va,i+1,j-1,mu);
00831 p[0]=(long)((1.0 - mu)*(double)p1[0] + mu*(double)p2[0]);
00832 p[1]=(long)((1.0 - mu)*(double)p1[1] + mu*(double)p2[1]);
00833 }
00834 }
00835
00836 static void DrawATMfontShapePreview(HDC hdc,RECT rc){
00837 HPEN hmyPen,holdPen;
00838 long i;
00839 int h,w,ww,hh=10,x1,y1,x2,y2,xl,xr,xx1,xx2,yy1,yy2;
00840 double x,y,dx,dy,bs;
00841 ww=rc.bottom-rc.top-2; h=ww-hh;
00842 w=(int)((double)h*(double)lpAtm->ATM_chara_width/100.0);
00843 x1=rc.left+1; x2=rc.right-1;
00844 y1=rc.top+1; y2=rc.bottom-1;
00845 Rectangle(hdc,rc.left,rc.top,rc.right,rc.bottom);
00846 hmyPen=CreatePen(PS_SOLID,0,RGB(255,0,0));
00847 holdPen=SelectObject(hdc,hmyPen);
00848 if(nATM_preview_list > 0 && ATM_preview_list != NULL){
00849 dy=dx=(double)h/1000.0;
00850 for(i=0;i<nATM_preview_list;i++){
00851 xx1=x1+(int)((double)ATM_preview_list[i].x1*dx);
00852 yy1=y2-(int)((double)ATM_preview_list[i].y1*dy);
00853 xx2=x1+(int)((double)ATM_preview_list[i].x2*dx);
00854 yy2=y2-(int)((double)ATM_preview_list[i].y2*dy);
00855 MoveToEx(hdc,xx1,yy1,NULL); LineTo(hdc,xx2,yy2);
00856 }
00857 if(lpAtm->ATM_bevel_width > 0 &&
00858 (lpAtm->ATM_bevel_back || lpAtm->ATM_bevel_front)){
00859 bs=1050.0*(double)lpAtm->ATM_bevel_width/4000.0;
00860 for(i=0;i<nATM_preview_list;i++){
00861 x=bs*(double)ATM_preview_list[i].dx;
00862 y=bs*(double)ATM_preview_list[i].dy;
00863 xx1=x1+(int)((double)ATM_preview_list[i].x1*dx);
00864 yy1=y2-(int)((double)ATM_preview_list[i].y1*dy);
00865 xx2=x1+(int)(((double)ATM_preview_list[i].x1+x)*dx);
00866 yy2=y2-(int)(((double)ATM_preview_list[i].y1+y)*dy);
00867 MoveToEx(hdc,xx1,yy1,NULL); LineTo(hdc,xx2,yy2);
00868 xx1=x1+(int)((double)ATM_preview_list[i].x2*dx);
00869 yy1=y2-(int)((double)ATM_preview_list[i].y2*dy);
00870 xx2=x1+(int)(((double)ATM_preview_list[i].x2+x)*dx);
00871 yy2=y2-(int)(((double)ATM_preview_list[i].y2+y)*dy);
00872 LineTo(hdc,xx2,yy2); LineTo(hdc,xx1,yy1);
00873 }
00874 }
00875 }
00876 SelectObject(hdc,holdPen);
00877 DeleteObject(hmyPen);
00878 }
00879
00880 static void DrawATMfontProfilePreview(HDC hdc,RECT rc){
00881 HPEN hmyPen,holdPen;
00882 long i;
00883 int h,w,ww,hh=10,x1,y1,x2,y2,xl,xr,xx1,xx2,yy1,yy2;
00884 double x,y,dx,dy,bs;
00885 ww=rc.bottom-rc.top-2; h=ww-hh;
00886 w=(int)((double)h*(double)lpAtm->ATM_chara_width/100.0);
00887 x1=rc.left+1; x2=rc.right-1;
00888 y1=rc.top+1; y2=rc.bottom-1;
00889 xl=x1+(ww-w)/2; xr=x1+(ww+w)/2;
00890 Rectangle(hdc,rc.left,rc.top,rc.right,rc.bottom);
00891 xl=x1+(ww-w)/2; xr=x1+(ww+w)/2+1;
00892 hmyPen=CreatePen(PS_SOLID,0,RGB(255,0,0));
00893 holdPen=SelectObject(hdc,hmyPen);
00894 Rectangle(hdc,xl,y1+hh/2,xr,y2-hh/2);
00895 if(lpAtm->ATM_bevel_width > 0){
00896 dy=(double)h*(double)lpAtm->ATM_bevel_width/4000.0;
00897 dx=dy/tan((double)lpAtm->ATM_bevel_angle/180.0*PI);
00898 if(lpAtm->ATM_bevel_front){
00899 MoveToEx(hdc,xr,y1+hh/2,NULL);
00900 LineTo(hdc,min(x2,xr+(int)dx),y1+hh/2+(int)dy);
00901 LineTo(hdc,min(x2,xr+(int)dx),y2-hh/2-(int)dy);
00902 LineTo(hdc,xr,y2-hh/2);
00903 }
00904 if(lpAtm->ATM_bevel_back){
00905 MoveToEx(hdc,xl,y1+hh/2,NULL);
00906 LineTo(hdc,max(x1,xl-(int)dx),y1+hh/2+(int)dy);
00907 LineTo(hdc,max(x1,xl-(int)dx),y2-hh/2-(int)dy);
00908 LineTo(hdc,xl,y2-hh/2);
00909 }
00910 }
00911 SelectObject(hdc,holdPen);
00912 DeleteObject(hmyPen);
00913 }
00914
00915 #include "atm2.c"