TTF.C

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 2.x  - Modelling, Animation and Rendering Package
00003 -- */
00004 
00005 /* file TTF.C  TTF font DLL */
00006 
00007 #ifdef __BETA35__
00008 #define _DLL
00009 #endif
00010 #include <stdlib.h>
00011 #include <stdio.h>
00012 #include <math.h>
00013 #include <setjmp.h>
00014 #include <windows.h>
00015 #include <windowsx.h>
00016 #if __HELP_WS__
00017 #include "..\help_ws\include\htmlhelp.h"
00018 #endif
00019 
00020 #include "struct.h"
00021 #include "dstruct.h"
00022 #include "ttf.h"
00023 #include "ttfdlg.h"
00024 
00025 #ifndef PI
00026 #define PI 3.1415926
00027 #endif
00028 #ifndef min
00029 #define min(a,b)  ( ((a) < (b)) ? (a) : (b) )
00030 #endif
00031 #ifndef max
00032 #define max(a,b)  ( ((a) > (b)) ? (a) : (b) )
00033 #endif
00034 
00035 typedef struct FOUR_INTEGERS {  /* each edge in the preview  integers */
00036   long x1,y1,x2,y2;
00037   float dx,dy;
00038 } four_integers;
00039 
00040 #define OK         1
00041 #define FAIL       0
00042 
00043 static void MakeNewTTFletter(HWND);
00044 static void DrawTTFfontShapePreview(HDC hdc,RECT rc);
00045 static void DrawTTFfontProfilePreview(HDC hdc,RECT rc);
00046 static void LoadTTFfontPreviewCharacter(HWND hwnd);
00047 static BOOL CALLBACK TtfDlgProc(HWND hwnd, UINT msg,
00048                                 WPARAM wparam, LPARAM lparam);
00049 static void BuildTTFchar(BOOL preview, UINT c);
00050 
00051 static BITMAP    TtfHelpBitmap;
00052 static HBITMAP   hBitmap=NULL;
00053 static HINSTANCE hThisInstance=NULL;
00054 static HWND      hwndParent=NULL;
00055 static TTF_STRUCTURE *lpTtf;
00056 static long  nTTF_preview_list=0,nTTF_preview_piece=0;
00057 static four_integers *TTF_preview_list=NULL;
00058 static long Cwidthx,Cwidthy,Scale=32;
00059 static double MaxScale=1000.0;
00060 
00061 PSTR FileInPath(PSTR pstrPath){
00062  PSTR pstr;
00063  pstr = pstrPath + strlen(pstrPath);
00064  while (pstr > pstrPath) {
00065      pstr = (AnsiPrev(pstrPath, pstr));
00066      if (*pstr == '\\' || *pstr == ':' || *pstr == '/') {
00067          pstr = (AnsiNext(pstr));
00068          break;
00069      }
00070  }
00071  return pstr;
00072 }
00073 
00074 #if __WATCOMC__
00075 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00076 #else
00077 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00078 #endif
00079   switch (dwReason) {
00080     case DLL_PROCESS_ATTACH: {
00081       hThisInstance=hDLL;
00082       break;
00083     }
00084     case DLL_PROCESS_DETACH:
00085       break;
00086   }
00087   return TRUE;
00088 }
00089 
00090 #if __SC__
00091 #pragma startaddress(DllMain)
00092 #endif
00093 
00094 //void TTFthread(void *vvv){
00095 BOOL _TTFbuilder(
00096   HWND parent_window, char *szdir, X__STRUCTURE *lpevi, TTF_STRUCTURE *lpatm){
00097   int i;
00098   hwndParent=parent_window;
00099   lpTtf=lpatm;
00100   lpEVI=lpevi;
00101   if(lpTtf->cf.lStructSize == 0){
00102     lpTtf->cf.lStructSize=sizeof(CHOOSEFONT);
00103     lpTtf->cf.hwndOwner=hwndParent;
00104     lpTtf->cf.lpLogFont=&(lpTtf->lf);
00105     lpTtf->cf.iPointSize=10;
00106     lpTtf->cf.Flags=CF_SCREENFONTS|CF_TTONLY;
00107     lpTtf->cf.nFontType=SCREEN_FONTTYPE;
00108     if(!ChooseFont(&(lpTtf->cf)))return FALSE;
00109 //    if(!ChooseFont(&(lpTtf->cf))){_endthread(); return;}
00110   }
00111   if(DialogBox(hThisInstance,MAKEINTRESOURCE(DLG_TTF),hwndParent,
00112             (DLGPROC)TtfDlgProc) == OK){
00113     MakeNewTTFletter(hwndParent);
00114     return TRUE;
00115   }
00116   return FALSE;
00117 //  PostMessage(hwndParent,WM_QUIT,0,0);
00118 //  _endthread();
00119 }
00120 
00121 #if 0
00122 BOOL _TTFbuilder(
00123   HWND parent_window, char *szdir, X__STRUCTURE *lpevi, TTF_STRUCTURE *lpatm){
00124   void (*fp)(void *);
00125   hwndParent=parent_window;
00126   lpTtf=lpatm;
00127   lpEVI=lpevi;
00128   fp=TTFthread;
00129 #if  __WATCOMC__ && __WATCOMC__ < 1100
00130   _beginthread(fp,0,65536,(void *)0);
00131 #else
00132   _beginthread(fp,0,(void *)0);
00133 #endif
00134   {
00135    MSG msg;
00136    while(GetMessage(&msg,NULL,0,0)){
00137      TranslateMessage(&msg);
00138      DispatchMessage(&msg);
00139    }
00140   }
00141 //  MessageBox(NULL,"Terminating Thread",NULL,MB_OK);
00142   return TRUE;
00143 }
00144 #endif
00145 
00146 static char *ColorSelectDlgString;
00147 
00148 static BOOL CALLBACK ColorSelectDlgProc(HWND hwnd, UINT msg, WPARAM wparam,
00149                                         LPARAM lparam){
00150  switch( msg ) {
00151    case WM_INITDIALOG:
00152      SendMessage(hwnd,WM_SETTEXT,0,(LPARAM)ColorSelectDlgString);
00153      return TRUE;
00154    default:
00155      break;
00156  }
00157  return FALSE;
00158 }
00159 
00160 static void SetTtfColour(unsigned char colour[], char *Title, HWND parent){
00161  CHOOSECOLOR cc;
00162  static COLORREF CustColours[16]={
00163    RGB(255,255,255), RGB(239,239,239), RGB(223,223,223), RGB(207,207,207),
00164    RGB(191,191,191), RGB(175,175,175), RGB(159,159,159), RGB(143,143,143),
00165    RGB(127,127,127), RGB(111,111,111), RGB( 95, 95, 95), RGB( 79, 79, 79),
00166    RGB( 63, 63, 63), RGB( 47, 47, 47), RGB( 31, 31, 31), RGB( 15, 15, 15) };
00167  cc.lStructSize=sizeof(CHOOSECOLOR);
00168  cc.hwndOwner=parent;
00169  cc.rgbResult=RGB(colour[0],colour[1],colour[2]);
00170  cc.lpCustColors=(LPDWORD)CustColours;
00171  cc.Flags=CC_FULLOPEN | CC_RGBINIT | CC_ENABLEHOOK;
00172  cc.lCustData=(DWORD)0;
00173  ColorSelectDlgString=Title;
00174  cc.lpfnHook=(LPCCHOOKPROC)ColorSelectDlgProc;
00175  if(ChooseColor(&cc)){
00176    colour[0]=GetRValue(cc.rgbResult);
00177    colour[1]=GetGValue(cc.rgbResult);
00178    colour[2]=GetBValue(cc.rgbResult);
00179  }
00180 }
00181 
00182 static void UpdateTtfSlider(HWND hwnd,int sliderID,int valueID,int value){
00183  char str[16];
00184  SetScrollPos(GetDlgItem(hwnd,sliderID),SB_CTL,value,TRUE);
00185  sprintf(str,"%ld",value);
00186  SendDlgItemMessage(hwnd,valueID,WM_SETTEXT,0,(LPARAM)str);
00187 }
00188 
00189 //static void UpdateAdobeName(HWND hwnd){
00190 // SendDlgItemMessage(hwnd,DLG_TTF_ADOBE_NAME,WM_SETTEXT,0,(LPARAM)load_line);
00191 //}
00192 
00193 static BOOL CALLBACK TtfDlgProc(HWND hwnd, UINT msg,
00194                                     WPARAM wparam, LPARAM lparam){
00195  RECT rc;
00196  char str[16],*nn;
00197  int iMin,iMax;
00198  int hp[7]={DLG_TTF_CPDL,DLG_TTF_CPDC,DLG_TTF_CPDR,DLG_TTF_CPCC,
00199             DLG_TTF_CPUL,DLG_TTF_CPUC,DLG_TTF_CPUR};
00200  HWND hctl;
00201  BITMAP bmp;
00202  switch( msg ) {
00203    case WM_INITDIALOG:
00204      hBitmap=LoadBitmap(hThisInstance,MAKEINTRESOURCE(IDBM_HELP));
00205      if(hBitmap != NULL){
00206        GetObject(hBitmap,sizeof(BITMAP),&TtfHelpBitmap);
00207      }
00208      LoadTTFfontPreviewCharacter(hwnd);
00209 //     EnableWindow(GetDlgItem(hwnd,DLG_TTF_ADOBE_NAME),FALSE);
00210      SetScrollRange(GetDlgItem(hwnd,DLG_TTF_BEVEL_ANGLE),SB_CTL,5,80,FALSE);
00211      SetScrollRange(GetDlgItem(hwnd,DLG_TTF_BEVEL_DEPTH),SB_CTL,0,100,FALSE);
00212      SetScrollRange(GetDlgItem(hwnd,DLG_TTF_CHAR_WIDTH),SB_CTL,0,100,FALSE);
00213      SendDlgItemMessage(hwnd,hp[lpTtf->TTF_offset],BM_SETCHECK,TRUE,0);
00214      UpdateTtfSlider(hwnd,DLG_TTF_BEVEL_ANGLE,DLG_TTF_BEVEL_ANGLEN,
00215                      lpTtf->TTF_bevel_angle);
00216      UpdateTtfSlider(hwnd,DLG_TTF_BEVEL_DEPTH,DLG_TTF_BEVEL_DEPTHN,
00217                      lpTtf->TTF_bevel_width);
00218      UpdateTtfSlider(hwnd,DLG_TTF_CHAR_WIDTH,DLG_TTF_CHAR_WIDTHN,
00219                      lpTtf->TTF_chara_width);
00220      sprintf(str,"%c",lpTtf->TTF_char_preview);
00221      SendDlgItemMessage(hwnd,DLG_TTF_PREVIEW,WM_SETTEXT,0,(LPARAM)str);
00222      if((nn=lpTtf->lf.lfFaceName) != NULL){
00223        SendDlgItemMessage(hwnd,DLG_TTF_FONTID,WM_SETTEXT,0,(LPARAM)nn);
00224      }
00225      if(lpTtf->FORB > 0)
00226        SendDlgItemMessage(hwnd,DLG_TTF_LR,BM_SETCHECK,TRUE,0);
00227      else SendDlgItemMessage(hwnd,DLG_TTF_RL,BM_SETCHECK,TRUE,0);
00228      if(lpTtf->TTF_bevel_back)
00229        SendDlgItemMessage(hwnd,DLG_TTF_BEVEL_BACK,BM_SETCHECK,TRUE,0);
00230      if(lpTtf->TTF_bevel_front)
00231        SendDlgItemMessage(hwnd,DLG_TTF_BEVEL_FRONT,BM_SETCHECK,TRUE,0);
00232      if(lpTtf->TTF_cap)
00233        SendDlgItemMessage(hwnd,DLG_TTF_FILL,BM_SETCHECK,TRUE,0);
00234      else  SendDlgItemMessage(hwnd,DLG_TTF_NOFILL,BM_SETCHECK,TRUE,0);
00235      sprintf(str,"%s",lpTtf->TTF_Letters);
00236      SendDlgItemMessage(hwnd,DLG_TTF_TEXT,WM_SETTEXT,0,(LPARAM)str);
00237      SendDlgItemMessage(hwnd,DLG_TTF_TEXT,EM_LIMITTEXT,(WPARAM)60,0);
00238      EnableWindow(GetDlgItem(hwnd,DLG_TTF_MAKE),
00239                   Edit_LineLength(GetDlgItem(hwnd,DLG_TTF_TEXT), 0) > 0);
00240      GetWindowRect(hwnd, &rc);
00241      SetWindowPos(hwnd, NULL,
00242        (GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2,
00243        (GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2,
00244         0, 0, SWP_NOSIZE | SWP_NOZORDER);
00245      return (TRUE);
00246    case WM_DRAWITEM:{
00247        LPDRAWITEMSTRUCT lpdis;
00248        HBRUSH   hbr,hbrold;
00249        BYTE r,g,b;
00250        lpdis=(LPDRAWITEMSTRUCT)lparam;
00251        if(lpdis->CtlID == DLG_TTF_COLOUR_FACES ||
00252           lpdis->CtlID == DLG_TTF_COLOUR_SIDES ||
00253           lpdis->CtlID == DLG_TTF_COLOUR_BEVEL){
00254          if(lpdis->CtlID == DLG_TTF_COLOUR_FACES){
00255            r=lpTtf->TTF_face_colour[0];
00256            g=lpTtf->TTF_face_colour[1];
00257            b=lpTtf->TTF_face_colour[2];
00258          }
00259          else if(lpdis->CtlID == DLG_TTF_COLOUR_SIDES){
00260            r=lpTtf->TTF_side_colour[0];
00261            g=lpTtf->TTF_side_colour[1];
00262            b=lpTtf->TTF_side_colour[2];
00263          }
00264          else if(lpdis->CtlID == DLG_TTF_COLOUR_BEVEL){
00265            r=lpTtf->TTF_beve_colour[0];
00266            g=lpTtf->TTF_beve_colour[1];
00267            b=lpTtf->TTF_beve_colour[2];
00268          }
00269          if(lpdis->itemState & ODS_SELECTED)
00270             InvertRect(lpdis->hDC,&(lpdis->rcItem));
00271          else{
00272            hbr=CreateSolidBrush(RGB(r,g,b));
00273            hbrold=SelectObject(lpdis->hDC,hbr);
00274            Rectangle(lpdis->hDC,lpdis->rcItem.left,lpdis->rcItem.top,
00275                          lpdis->rcItem.right,lpdis->rcItem.bottom);
00276            SelectObject(lpdis->hDC,hbrold);
00277            DeleteObject(hbr);
00278          }
00279        }
00280        else if(lpdis->CtlID == DLG_TTF_SHAPE)
00281          DrawTTFfontShapePreview(lpdis->hDC,lpdis->rcItem);
00282        else if(lpdis->CtlID == DLG_TTF_PROFILE)
00283          DrawTTFfontProfilePreview(lpdis->hDC,lpdis->rcItem);
00284        else if(lpdis->CtlID == DLG_TTF_INFO && hBitmap != NULL){
00285          HDC hMemDC;
00286          HBITMAP hbmOld;
00287          hMemDC = CreateCompatibleDC(lpdis->hDC);
00288          hbmOld = SelectObject(hMemDC,hBitmap);
00289          BitBlt(lpdis->hDC,lpdis->rcItem.left
00290                           ,lpdis->rcItem.top
00291                           ,TtfHelpBitmap.bmWidth
00292                           ,TtfHelpBitmap.bmHeight
00293                           ,hMemDC,0,0,SRCCOPY);
00294          SelectObject(hMemDC,hbmOld);
00295          DeleteDC(hMemDC);
00296        }
00297      }
00298      return TRUE;
00299    case WM_HSCROLL:
00300      if((HWND)lparam == (hctl=GetDlgItem(hwnd,DLG_TTF_BEVEL_ANGLE))){
00301        GetScrollRange(hctl,SB_CTL,&iMin,&iMax);
00302        switch (LOWORD(wparam)) {
00303          case SB_PAGEDOWN:
00304          case SB_LINEDOWN:
00305            lpTtf->TTF_bevel_angle = min(iMax,lpTtf->TTF_bevel_angle+1);
00306            InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00307            break;
00308          case SB_PAGEUP:
00309          case SB_LINEUP:
00310            lpTtf->TTF_bevel_angle = max(iMin,lpTtf->TTF_bevel_angle-1);
00311            InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00312            break;
00313          case SB_THUMBTRACK:
00314          case SB_THUMBPOSITION:
00315            lpTtf->TTF_bevel_angle=HIWORD(wparam);
00316            InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00317            break;
00318          default: break;
00319        }
00320        UpdateTtfSlider(hwnd,DLG_TTF_BEVEL_ANGLE,DLG_TTF_BEVEL_ANGLEN,
00321                        lpTtf->TTF_bevel_angle);
00322      }
00323      else if((HWND)lparam == (hctl=GetDlgItem(hwnd,DLG_TTF_BEVEL_DEPTH))){
00324        GetScrollRange(hctl,SB_CTL,&iMin,&iMax);
00325        switch (LOWORD(wparam)) {
00326          case SB_PAGEDOWN:
00327          case SB_LINEDOWN:
00328            lpTtf->TTF_bevel_width = min(iMax,lpTtf->TTF_bevel_width+1);
00329            if(lpTtf->TTF_bevel_front || lpTtf->TTF_bevel_back)
00330              InvalidateRect(GetDlgItem(hwnd,DLG_TTF_SHAPE),NULL,FALSE);
00331            InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00332            break;
00333          case SB_PAGEUP:
00334          case SB_LINEUP:
00335            lpTtf->TTF_bevel_width = max(iMin,lpTtf->TTF_bevel_width-1);
00336            if(lpTtf->TTF_bevel_front || lpTtf->TTF_bevel_back)
00337              InvalidateRect(GetDlgItem(hwnd,DLG_TTF_SHAPE),NULL,FALSE);
00338            InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00339            break;
00340          case SB_THUMBTRACK:
00341          case SB_THUMBPOSITION:
00342            lpTtf->TTF_bevel_width=HIWORD(wparam);
00343            if(lpTtf->TTF_bevel_front || lpTtf->TTF_bevel_back)
00344              InvalidateRect(GetDlgItem(hwnd,DLG_TTF_SHAPE),NULL,FALSE);
00345            InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00346            break;
00347          default: break;
00348        }
00349        UpdateTtfSlider(hwnd,DLG_TTF_BEVEL_DEPTH,DLG_TTF_BEVEL_DEPTHN,
00350                        lpTtf->TTF_bevel_width);
00351      }
00352      else if((HWND)lparam == (hctl=GetDlgItem(hwnd,DLG_TTF_CHAR_WIDTH))){
00353        GetScrollRange(hctl,SB_CTL,&iMin,&iMax);
00354        switch (LOWORD(wparam)) {
00355          case SB_PAGEDOWN:
00356          case SB_LINEDOWN:
00357            lpTtf->TTF_chara_width = min(iMax,lpTtf->TTF_chara_width+1);
00358            InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00359            break;
00360          case SB_PAGEUP:
00361          case SB_LINEUP:
00362            lpTtf->TTF_chara_width = max(iMin,lpTtf->TTF_chara_width-1);
00363            InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00364            break;
00365          case SB_THUMBTRACK:
00366          case SB_THUMBPOSITION:
00367            lpTtf->TTF_chara_width=HIWORD(wparam);
00368            InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00369            break;
00370          default: break;
00371        }
00372        UpdateTtfSlider(hwnd,DLG_TTF_CHAR_WIDTH,DLG_TTF_CHAR_WIDTHN,
00373                        lpTtf->TTF_chara_width);
00374      }
00375      break;
00376    case WM_COMMAND:
00377       switch(LOWORD(wparam)){
00378         case DLG_TTF_CPDL: lpTtf->TTF_offset=0; break;
00379         case DLG_TTF_CPDC: lpTtf->TTF_offset=1; break;
00380         case DLG_TTF_CPDR: lpTtf->TTF_offset=2; break;
00381         case DLG_TTF_CPCC: lpTtf->TTF_offset=3; break;
00382         case DLG_TTF_CPUL: lpTtf->TTF_offset=4; break;
00383         case DLG_TTF_CPUC: lpTtf->TTF_offset=5; break;
00384         case DLG_TTF_CPUR: lpTtf->TTF_offset=6; break;
00385         case DLG_TTF_BEVEL_FRONT:
00386           lpTtf->TTF_bevel_front ^= 1;
00387           InvalidateRect(GetDlgItem(hwnd,DLG_TTF_SHAPE),NULL,FALSE);
00388           InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00389           break;
00390         case DLG_TTF_BEVEL_BACK:
00391           lpTtf->TTF_bevel_back ^= 1;
00392           InvalidateRect(GetDlgItem(hwnd,DLG_TTF_SHAPE),NULL,FALSE);
00393           InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00394           break;
00395         case DLG_TTF_FILL:
00396           lpTtf->TTF_cap=1;
00397           break;
00398         case DLG_TTF_NOFILL:
00399           lpTtf->TTF_cap=0;
00400           break;
00401         case DLG_TTF_PREVIEW:
00402           if(Edit_LineLength(GetDlgItem(hwnd,DLG_TTF_PREVIEW),0) > 0){
00403             GetDlgItemText(hwnd,DLG_TTF_PREVIEW,str,10);
00404             if(lpTtf->TTF_char_preview != (int)str[0]){
00405               lpTtf->TTF_char_preview=(int)str[0];
00406               LoadTTFfontPreviewCharacter(hwnd);
00407               InvalidateRect(GetDlgItem(hwnd,DLG_TTF_SHAPE),NULL,FALSE);
00408               InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00409             }
00410           }
00411           break;
00412         case DLG_TTF_TEXT:
00413           EnableWindow(GetDlgItem(hwnd,DLG_TTF_MAKE),
00414                   Edit_LineLength((HWND)(lparam), 0) > 0);
00415           break;
00416         case DLG_TTF_CHOOSE:
00417           if(!ChooseFont(&(lpTtf->cf)))break;
00418           LoadTTFfontPreviewCharacter(hwnd);
00419           InvalidateRect(GetDlgItem(hwnd,DLG_TTF_SHAPE),NULL,FALSE);
00420           InvalidateRect(GetDlgItem(hwnd,DLG_TTF_PROFILE),NULL,FALSE);
00421           if((nn=lpTtf->lf.lfFaceName) != NULL){
00422             SendDlgItemMessage(hwnd,DLG_TTF_FONTID,WM_SETTEXT,0,(LPARAM)nn);
00423           }
00424           break;
00425         case DLG_TTF_HELP:{
00426             char lname[256],res_str1[256],res_str2[256];
00427             GetModuleFileName(hThisInstance,lname,225);
00428             *FileInPath(lname) = '\0';
00429             strcat(lname,"help\\");
00430             strcpy(res_str1,lname);
00431 #if !__HELP_WS__
00432             strcat(res_str1,"des_help.chm");
00433             ShellExecute(hwnd,NULL,res_str1,
00434                     NULL,lname,SW_SHOW);
00435 #else
00436             {
00437               HH_WINTYPE hhwin;
00438               memset(&hhwin,0,sizeof(HH_WINTYPE));
00439               hhwin.cbStruct=sizeof(HH_WINTYPE);
00440               hhwin.nShowState=SW_SHOW;
00441               hhwin.pszType="MyHelp";
00442               hhwin.pszCaption="OpenFX Help";
00443               hhwin.fsValidMembers = HHWIN_PARAM_SHOWSTATE |
00444                                      HHWIN_PARAM_PROPERTIES|
00445                                      HHWIN_PARAM_CUR_TAB|
00446                                      HHWIN_PARAM_EXPANSION|
00447                                      HHWIN_PARAM_RECT;
00448               hhwin.rcWindowPos.top=0;
00449               hhwin.rcWindowPos.left=0;
00450               hhwin.rcWindowPos.right=500;
00451               hhwin.rcWindowPos.bottom=500;
00452               hhwin.nShowState=SW_SHOW;
00453               strcat(res_str1,"des_help.chm");
00454               hhwin.fNotExpanded = TRUE;
00455               hhwin.fsWinProperties = HHWIN_PROP_TRI_PANE|HHWIN_PROP_TAB_SEARCH;
00456               hhwin.curNavType=HHWIN_NAVTYPE_TOC;
00457               strcpy(res_str2,res_str1);
00458               strcat(res_str2,"::toc.hhc");
00459               hhwin.pszToc=res_str2;
00460               strcat(res_str1,"::/TTF_Text_Builder.htm");
00461               HtmlHelp(hwnd,NULL,HH_SET_WIN_TYPE,(DWORD)&hhwin);
00462               HtmlHelp(hwnd,">MyHelp",HH_DISPLAY_TOPIC,(DWORD)res_str1);
00463             }
00464 #endif
00465 //            WinHelp(hwnd,lname,HELP_INDEX,0L);
00466 //            EnableWindow(GetDlgItem(hwnd,DLG_TTF_HELP),FALSE);
00467           }
00468           break;
00469         case DLG_TTF_COLOUR_FACES:
00470           SetTtfColour(lpTtf->TTF_face_colour,"Set Face Color",hwnd);
00471           InvalidateRect(GetDlgItem(hwnd,DLG_TTF_COLOUR_FACES),NULL,FALSE);
00472           break;
00473         case DLG_TTF_COLOUR_BEVEL:
00474           SetTtfColour(lpTtf->TTF_beve_colour,"Set Bevel Color",hwnd);
00475           InvalidateRect(GetDlgItem(hwnd,DLG_TTF_COLOUR_BEVEL),NULL,FALSE);
00476           break;
00477         case DLG_TTF_COLOUR_SIDES:
00478           SetTtfColour(lpTtf->TTF_side_colour,"Set Side Color",hwnd);
00479           InvalidateRect(GetDlgItem(hwnd,DLG_TTF_COLOUR_SIDES),NULL,FALSE);
00480           break;
00481         case DLG_TTF_LR:
00482           lpTtf->FORB =  1;
00483           break;
00484         case DLG_TTF_RL:
00485           lpTtf->FORB = -1;
00486           break;
00487         case DLG_TTF_MAKE:
00488         case DLG_TTF_CANCEL:
00489           if(hBitmap != NULL)DeleteObject(hBitmap);
00490           hBitmap=NULL;
00491           if(TTF_preview_list != NULL)X__Free(TTF_preview_list);
00492           TTF_preview_list=NULL; nTTF_preview_list=0;
00493           if(LOWORD(wparam) == DLG_TTF_MAKE){
00494             GetDlgItemText(hwnd,DLG_TTF_TEXT,lpTtf->TTF_Letters,21);
00495             EndDialog(hwnd, OK);
00496           }
00497           else EndDialog(hwnd, FAIL);
00498           return(TRUE);
00499         default:
00500           break;
00501       }
00502       break;
00503     default: break;
00504  }
00505  return(FALSE);
00506 }
00507 
00508 static void LoadTTFfontPreviewCharacter(HWND hwnd){
00509  UINT cch;
00510  if(TTF_preview_list != NULL)X__Free(TTF_preview_list);
00511  TTF_preview_list=NULL; nTTF_preview_list=0; nTTF_preview_piece=0;
00512  cch=(UINT)lpTtf->TTF_char_preview;
00513  BuildTTFchar(TRUE,cch);
00514  if(nTTF_preview_list > 0){
00515    long i;
00516    long xmin=1000000, ymin=1000000, xmax = -1000000, ymax = -1000000;
00517    double sx,sy,s;
00518    for(i=0;i<nTTF_preview_list;i++){
00519      if(TTF_preview_list[i].x1 < xmin)xmin=TTF_preview_list[i].x1;
00520      if(TTF_preview_list[i].y1 < ymin)ymin=TTF_preview_list[i].y1;
00521      if(TTF_preview_list[i].x2 > xmax)xmax=TTF_preview_list[i].x2;
00522      if(TTF_preview_list[i].y2 > ymax)ymax=TTF_preview_list[i].y2;
00523      sx=(double)(TTF_preview_list[i].x2-TTF_preview_list[i].x1);
00524      sy=(double)(TTF_preview_list[i].y2-TTF_preview_list[i].y1);
00525      s=1.0/sqrt(sx*sx+sy*sy);    /* these are the inward pointing normals */
00526 //     TTF_preview_list[i].dx = (float)(-sy*s);
00527 //     TTF_preview_list[i].dy = (float)( sx*s);
00528      TTF_preview_list[i].dx = (float)( sy*s);
00529      TTF_preview_list[i].dy = (float)(-sx*s);
00530    }
00531    sx=(double)(xmax-xmin); sy=(double)(ymax-ymin); s=max(sx,sy);
00532    s=1050.0/s;
00533    for(i=0;i<nTTF_preview_list;i++){
00534      TTF_preview_list[i].x1=(long)((double)(TTF_preview_list[i].x1-xmin)*s);
00535      TTF_preview_list[i].y1=(long)((double)(TTF_preview_list[i].y1-ymin)*s);
00536      TTF_preview_list[i].x2=(long)((double)(TTF_preview_list[i].x2-xmin)*s);
00537      TTF_preview_list[i].y2=(long)((double)(TTF_preview_list[i].y2-ymin)*s);
00538    }
00539  }
00540 }
00541 
00542 static void CreateCharacterEdge(long x1, long y1, long x2, long y2){
00543  four_integers *fouri;
00544  if(x1 == x2 && y1 == y2)return; /* dont add a zero size edge */
00545  if(TTF_preview_list == NULL){
00546    if((fouri = (four_integers *)X__Malloc(sizeof(four_integers))) == NULL)return;
00547  }
00548  else {
00549    if((fouri = (four_integers *)X__Realloc(TTF_preview_list,
00550      (nTTF_preview_list+1)*sizeof(four_integers))) == NULL)return;
00551  }
00552  fouri[nTTF_preview_list].x1=x1;
00553  fouri[nTTF_preview_list].y1=y1;
00554  fouri[nTTF_preview_list].x2=x2;
00555  fouri[nTTF_preview_list].y2=y2;
00556  nTTF_preview_list++; nTTF_preview_piece++;
00557  TTF_preview_list=fouri;
00558 }
00559 
00560 static void DrawTTFfontShapePreview(HDC hdc,RECT rc){
00561  HPEN hmyPen,holdPen;
00562  long i;
00563  int h,w,ww,hh=10,x1,y1,x2,y2,xl,xr,xx1,xx2,yy1,yy2;
00564  double x,y,dx,dy,bs;
00565  ww=rc.bottom-rc.top-2; h=ww-hh;
00566  w=(int)((double)h*(double)lpTtf->TTF_chara_width/100.0);
00567  x1=rc.left+1;  x2=rc.right-1;
00568  y1=rc.top+1;   y2=rc.bottom-1;
00569  Rectangle(hdc,rc.left,rc.top,rc.right,rc.bottom);
00570  hmyPen=CreatePen(PS_SOLID,0,RGB(255,0,0));
00571  holdPen=SelectObject(hdc,hmyPen);
00572  if(nTTF_preview_list > 0 && TTF_preview_list != NULL){
00573    dy=dx=(double)h/1000.0;
00574    for(i=0;i<nTTF_preview_list;i++){
00575      xx1=x1+(int)((double)TTF_preview_list[i].x1*dx);
00576      yy1=y2-(int)((double)TTF_preview_list[i].y1*dy);
00577      xx2=x1+(int)((double)TTF_preview_list[i].x2*dx);
00578      yy2=y2-(int)((double)TTF_preview_list[i].y2*dy);
00579      MoveToEx(hdc,xx1,yy1,NULL); LineTo(hdc,xx2,yy2);
00580    }
00581    if(lpTtf->TTF_bevel_width > 0 &&
00582      (lpTtf->TTF_bevel_back || lpTtf->TTF_bevel_front)){
00583      bs=1050.0*(double)lpTtf->TTF_bevel_width/4000.0;
00584      for(i=0;i<nTTF_preview_list;i++){
00585        x=bs*(double)TTF_preview_list[i].dx;
00586        y=bs*(double)TTF_preview_list[i].dy;
00587        xx1=x1+(int)((double)TTF_preview_list[i].x1*dx);
00588        yy1=y2-(int)((double)TTF_preview_list[i].y1*dy);
00589        xx2=x1+(int)(((double)TTF_preview_list[i].x1+x)*dx);
00590        yy2=y2-(int)(((double)TTF_preview_list[i].y1+y)*dy);
00591        MoveToEx(hdc,xx1,yy1,NULL); LineTo(hdc,xx2,yy2);
00592        xx1=x1+(int)((double)TTF_preview_list[i].x2*dx);
00593        yy1=y2-(int)((double)TTF_preview_list[i].y2*dy);
00594        xx2=x1+(int)(((double)TTF_preview_list[i].x2+x)*dx);
00595        yy2=y2-(int)(((double)TTF_preview_list[i].y2+y)*dy);
00596        LineTo(hdc,xx2,yy2); LineTo(hdc,xx1,yy1);
00597      }
00598    }
00599  }
00600  SelectObject(hdc,holdPen);
00601  DeleteObject(hmyPen);
00602 }
00603 
00604 static void DrawTTFfontProfilePreview(HDC hdc,RECT rc){
00605  HPEN hmyPen,holdPen;
00606  long i;
00607  int h,w,ww,hh=10,x1,y1,x2,y2,xl,xr,xx1,xx2,yy1,yy2;
00608  double x,y,dx,dy,bs;
00609  ww=rc.bottom-rc.top-2; h=ww-hh;
00610  w=(int)((double)h*(double)lpTtf->TTF_chara_width/100.0);
00611  x1=rc.left+1;  x2=rc.right-1;
00612  y1=rc.top+1;   y2=rc.bottom-1;
00613  xl=x1+(ww-w)/2; xr=x1+(ww+w)/2;
00614  Rectangle(hdc,rc.left,rc.top,rc.right,rc.bottom);
00615  xl=x1+(ww-w)/2; xr=x1+(ww+w)/2+1;
00616  hmyPen=CreatePen(PS_SOLID,0,RGB(255,0,0));
00617  holdPen=SelectObject(hdc,hmyPen);
00618  Rectangle(hdc,xl,y1+hh/2,xr,y2-hh/2);
00619  if(lpTtf->TTF_bevel_width > 0){
00620    dy=(double)h*(double)lpTtf->TTF_bevel_width/4000.0;
00621    dx=dy/tan((double)lpTtf->TTF_bevel_angle/180.0*PI);
00622    if(lpTtf->TTF_bevel_front){
00623      MoveToEx(hdc,xr,y1+hh/2,NULL);
00624      LineTo(hdc,min(x2,xr+(int)dx),y1+hh/2+(int)dy);
00625      LineTo(hdc,min(x2,xr+(int)dx),y2-hh/2-(int)dy);
00626      LineTo(hdc,xr,y2-hh/2);
00627    }
00628    if(lpTtf->TTF_bevel_back){
00629      MoveToEx(hdc,xl,y1+hh/2,NULL);
00630      LineTo(hdc,max(x1,xl-(int)dx),y1+hh/2+(int)dy);
00631      LineTo(hdc,max(x1,xl-(int)dx),y2-hh/2-(int)dy);
00632      LineTo(hdc,xl,y2-hh/2);
00633    }
00634  }
00635  SelectObject(hdc,holdPen);
00636  DeleteObject(hmyPen);
00637 }
00638 
00639 #define SELECTED   1
00640 #define DESELECTED 0
00641 
00642 static long VP,VF;
00643 
00644 static void GetTTFholdPoint(long *x, long *y, long cx, long cy, short pt);
00645 
00646 static void DeselectVertexSet(long vs, long vf){
00647  vertex *Vs;
00648  while(vs < vf){
00649    Vs=(MainVp+vs);
00650    if(Vs->status == SELECTED){
00651       Vs->status = DESELECTED; NvertSelect--; NvertDeselect++;
00652    }
00653    vs++;
00654  }
00655 }
00656 
00657 static void SelectVertexSet(long vs, long vf){
00658  vertex *Vs;
00659  while(vs < vf){
00660    Vs=(MainVp+vs);
00661    if(Vs->status == DESELECTED){
00662       Vs->status = SELECTED; NvertSelect++; NvertDeselect--;
00663    }
00664    vs++;
00665  }
00666 }
00667 
00668 static void MakeNewTTFletter(HWND hwnd){
00669  long i,j,char_id,Depth,Opx,Opy,Opz;
00670  int ifail=OK,capped=0;
00671  long Vstart,Vstop,BackStart,BackStop,fBevelStart,fBevelStop,Vfirst;
00672  long ep,Estart=-1;
00673  long fp,LastFace;
00674  skel *sp;
00675  Vfirst=Nvert;
00676  char_id=0;
00677  Opx=NpointerX; Opy=NpointerY; Opz=NpointerZ;
00678  DeselectVertexSet(0,Nvert);
00679  while ((j=(long)lpTtf->TTF_Letters[char_id++]) > 0){
00680    Cwidthx=0; Cwidthy=0; Vstart=Nvert; Estart=Nedge; VF=VP= -1;
00681    if(lpTtf->TTF_chara_width > 0){
00682      Depth=MaxScale*(double)lpTtf->TTF_chara_width/100.0*Scale;
00683    }
00684    else Depth=0;
00685    BuildTTFchar(FALSE,j);
00686    if(j == 32){
00687      UpdateVertexHeap(Nvert+2);
00688      CreateVertex();
00689      (MainVp+Nvert-1)->xyz[0]=NpointerX-Depth/2;
00690      (MainVp+Nvert-1)->xyz[1]=NpointerY;
00691      (MainVp+Nvert-1)->xyz[2]=NpointerZ;
00692      CreateVertex();
00693      (MainVp+Nvert-1)->xyz[0]=NpointerX-Depth/2;
00694      (MainVp+Nvert-1)->xyz[1]=NpointerY+Cwidthx*lpTtf->FORB;
00695      (MainVp+Nvert-1)->xyz[2]=NpointerZ+Cwidthy;
00696      UpdateEdgeHeap(Nedge+1);
00697      CreateEdge(Nvert-1,Nvert-2);
00698    }
00699    NpointerY += Cwidthx*lpTtf->FORB; NpointerZ += Cwidthy;
00700 //   FREEALL:
00701    Vstop=Nvert; VP=Vstart; while(VP < Nvert){
00702      (MainVp+VP)->xyz[1] += rand()%4-2;  /* NB this helps fools the filling */
00703                                 /* which can fail on some cases    */
00704      VP++;
00705    }
00706    if(Vstop == Vstart)ifail=FAIL;
00707    if(ifail == FAIL)break;
00708    CreateSkeleton(FirstSp);  sp=MainSp;
00709    if(j == 32){
00710      strcpy(MainSp->name,"Space");
00711    }
00712    else{
00713      if(j > 64 && j < 91)sprintf(MainSp->name,"%c%ld-C",j,char_id);
00714      else                sprintf(MainSp->name,"%c%ld",j,char_id);
00715    }
00716    MainSp->xyz[0]=NpointerX-Depth/2;
00717    GetTTFholdPoint(&MainSp->xyz[1],&MainSp->xyz[2],Cwidthx,Cwidthy,0);
00718    CreateSkeleton(MainSp);
00719    strcpy(MainSp->name,"F.Pt.");
00720    MainSp->xyz[0]=NpointerX-Depth/2;
00721    GetTTFholdPoint(&MainSp->xyz[1],&MainSp->xyz[2],Cwidthx,Cwidthy,1);
00722    DeselectVertexSet(Vstart,Vstop);
00723    Estart=Nedge;
00724    LastFace=Nface;
00725    if(j == 32)goto SPACEBREAK;
00726    if(lpTtf->TTF_cap && !lpTtf->TTF_bevel_front && !lpTtf->TTF_bevel_back){
00727      capped=1;
00728      SelectVertexSet(Vstart,Vstop);
00729      LastFace=Nface;
00730      if(AutoFacetCurveWithHoles(0,0,1,0.0,0.0) == FAIL)break;
00731      DeselectVertexSet(Vstart,Vstop);
00732      fp=LastFace; while(fp < Nface){
00733        for(i=0;i<3;i++)(MainFp+fp)->color[i]=lpTtf->TTF_face_colour[i];
00734        fp++;
00735      }
00736      LastFace=Nface;
00737    }
00738    if(lpTtf->TTF_chara_width > 0){
00739      SelectVertexSet(Vstart,Vstop);
00740      BackStart=Nvert; LastFace=Nface;
00741      if(!CreateAttachedCopy(1))break; /* copy failed */
00742      BackStop=Nvert;
00743      DeselectVertexSet(BackStart,BackStop);
00744      VP=BackStart; while(VP < BackStop){
00745        (MainVp+VP)->xyz[0] -= Depth;
00746        VP++;
00747      }
00748      fp=LastFace; while(fp < Nface){
00749        for(i=0;i<3;i++)(MainFp+fp)->color[i]=lpTtf->TTF_side_colour[i];
00750 //       (MainFp+fp)->attrib |= 0x80;
00751        fp++;
00752      }
00753      LastFace=Nface;
00754    }
00755    else{BackStart=Vstart; BackStop=Vstop;}
00756    if((lpTtf->FORB > 0 && lpTtf->TTF_bevel_front) ||
00757       (lpTtf->FORB < 0 && lpTtf->TTF_bevel_back)){
00758      SelectVertexSet(Vstart,Vstop);
00759      fBevelStart=Nvert; LastFace=Nface;
00760      if(AutoFacetCurveWithHoles(3,0,1,(double)lpTtf->TTF_bevel_angle,
00761        (double)lpTtf->TTF_bevel_width/2000.0*MaxScale*Scale) == FAIL)break;
00762      fBevelStop=Nvert;
00763      fp=LastFace; while(fp < Nface){
00764        for(i=0;i<3;i++)(MainFp+fp)->color[i]=lpTtf->TTF_beve_colour[i];
00765 //       (MainFp+fp)->attrib |= 0x80;
00766        fp++;
00767      }
00768      LastFace=Nface;
00769      if(lpTtf->TTF_cap){
00770        if(AutoFacetCurveWithHoles(0,0,1,0.0,0.0) == FAIL)break;
00771        fp=LastFace; while(fp < Nface){
00772          for(i=0;i<3;i++)(MainFp+fp)->color[i]=lpTtf->TTF_face_colour[i];
00773          fp++;
00774        }
00775        LastFace=Nface;
00776      }
00777      DeselectVertexSet(fBevelStart,fBevelStop);
00778    }
00779    else if(lpTtf->TTF_cap && !capped){
00780      SelectVertexSet(Vstart,Vstop);
00781      LastFace=Nface;
00782      if(AutoFacetCurveWithHoles(0,0,1,0.0,0.0) == FAIL)break;
00783      DeselectVertexSet(Vstart,Vstop);
00784      fp=LastFace; while(fp < Nface){
00785        for(i=0;i<3;i++)(MainFp+fp)->color[i]=lpTtf->TTF_face_colour[i];
00786        fp++;
00787      }
00788      LastFace=Nface;
00789    }
00790    if((lpTtf->FORB > 0 && lpTtf->TTF_bevel_back) ||
00791       (lpTtf->FORB < 0 && lpTtf->TTF_bevel_front)){
00792      SelectVertexSet(BackStart,BackStop);
00793      fBevelStart=Nvert; LastFace=Nface;
00794      if(AutoFacetCurveWithHoles(3,0,1,(double)(lpTtf->TTF_bevel_angle * -1),
00795        (double)lpTtf->TTF_bevel_width/2000.0*MaxScale*Scale) == FAIL)break;
00796      fBevelStop=Nvert;
00797      fp=LastFace; while(fp < Nface){
00798        for(i=0;i<3;i++)(MainFp+fp)->color[i]=lpTtf->TTF_beve_colour[i];
00799 //       (MainFp+fp)->attrib |= 0x80;
00800        fp++;
00801      }
00802      LastFace=Nface;
00803      if(lpTtf->TTF_cap){
00804        if(AutoFacetCurveWithHoles(0,0,1,0.0,0.0) == FAIL)break;
00805        fp=LastFace; while(fp < Nface){
00806          for(i=0;i<3;i++)(MainFp+fp)->color[i]=lpTtf->TTF_face_colour[i];
00807          fp++;
00808        }
00809        LastFace=Nface;
00810      }
00811      DeselectVertexSet(fBevelStart,fBevelStop);
00812    }
00813    else if(lpTtf->TTF_cap && !capped){
00814      SelectVertexSet(BackStart,BackStop);
00815      LastFace=Nface;
00816      if(AutoFacetCurveWithHoles(0,0,1,0.0,0.0) == FAIL)break;
00817      DeselectVertexSet(BackStart,BackStop);
00818      fp=LastFace; while(fp < Nface){
00819        for(i=0;i<3;i++)(MainFp+fp)->color[i]=lpTtf->TTF_face_colour[i];
00820        fp++;
00821      }
00822      LastFace=Nface;
00823    }
00824    SPACEBREAK:
00825    VP=Vstart; while(VP < Nvert){
00826      (MainVp+VP)->sp=sp;
00827      VP++;
00828    }
00829    DrawModel();
00830  }
00831  SelectVertexSet(Vfirst,Nvert);
00832  NpointerX=Opx; NpointerY=Opy; NpointerZ=Opz;
00833  return;
00834 }
00835 
00836 static void GetTTFholdPoint(long *x, long *y, long cx, long cy, short pt){
00837   long x0,y0;
00838   double offx[]={0.0,0.5,1.0,  0.5,  0.0  ,0.5,  1.0};
00839   double offy[]={0.0,0.0,0.0,300.0,600.0,600.0,600.0};
00840   x0=NpointerY-cx*lpTtf->FORB;
00841   y0=NpointerZ-cy;
00842   if(pt == 0){
00843    *x=x0+(long)(offx[lpTtf->TTF_offset]*(double)cx)*lpTtf->FORB;
00844    *y=y0+(long)(offy[lpTtf->TTF_offset]*Scale);
00845   }
00846   else{ /* follow point */
00847    *x=x0+(long)((offx[lpTtf->TTF_offset]+1.0)*(double)cx)*lpTtf->FORB;
00848    *y=y0+(long)(offy[lpTtf->TTF_offset]*Scale+(double)cy);
00849   }
00850 }
00851 
00852 //#define UNITL 65536.0
00853 #define UNITL 32000.0
00854 #define UNITP 1000.0
00855 
00856 static void BuildTTFchar(BOOL preview, UINT c){
00857   HDC hdc;
00858   HFONT hfont,hfontOld;
00859   GLYPHMETRICS gm;
00860 //  static MAT2 m2;  // very important for strange bug !!!!!
00861   MAT2 mymatrix;
00862   FIXED val_0,val_1;
00863   BYTE *buffer;
00864   long zpos,offset;
00865   long size,csize,npoints,ctype,i,j,vc,vl,vf,maxx;
00866   long vc_x,vc_y,vl_x,vl_y,vf_x,vf_y;
00867   vertex *vp;
00868   val_0.fract=0;val_0.value=0;
00869   val_1.fract=0;val_1.value=1;
00870   memset(&mymatrix,0,sizeof(MAT2));
00871   mymatrix.eM11=val_1;
00872   mymatrix.eM12=val_0;
00873   mymatrix.eM21=val_0;
00874   mymatrix.eM22=val_1;
00875   if(c == ' '){
00876     Cwidthx = 2*(long)(UNITL*0.1);
00877     return;
00878   }
00879   hdc=GetDC(hwndParent);
00880   hfont=CreateFontIndirect(lpTtf->cf.lpLogFont);
00881   hfontOld=SelectObject(hdc,hfont);
00882   offset=NpointerY; zpos=NpointerZ;
00883   maxx=offset;
00884   if((size=GetGlyphOutline(hdc,c,GGO_NATIVE,&gm,0,NULL,&mymatrix)) > 0){
00885     if((buffer = (BYTE *)X__Malloc(size)) != NULL){
00886       memset(buffer,0,size);
00887       if((size=GetGlyphOutline(hdc,c,GGO_NATIVE,&gm,size,buffer,&mymatrix)) > 0){
00888         TTPOLYGONHEADER *lpTT;
00889         lpTT=(TTPOLYGONHEADER *)buffer;
00890         while(size > 0){
00891           TTPOLYCURVE *lpTP;
00892           POINTFX *lpPFX;
00893           FIXED fx,fy;
00894           double x,y,last_x,last_y,off_x,off_y,mid_x,mid_y;
00895           long x_f,y_f;
00896           lpPFX = (POINTFX *)(((BYTE *)lpTT) +(2*sizeof(DWORD)));
00897           memcpy(&fx,&(lpPFX->x),sizeof(FIXED));
00898           memcpy(&fy,&(lpPFX->y),sizeof(FIXED));
00899           x=(double)fx.value + (((double)fx.fract)/65525.0);
00900           y=(double)fy.value + (((double)fy.fract)/65525.0);
00901           // First point
00902           if(preview){
00903            vc_x=vl_x=vf_x=(long)(x*UNITP);
00904            vc_y=vl_y=vf_y=(long)(y*UNITP);
00905           }
00906           else{
00907             UpdateVertexHeap(Nvert+1);
00908             CreateVertex();
00909             vl=Nvert-1;
00910             vp=(MainVp+vl);
00911             vp->xyz[0]=NpointerX;
00912             x_f=vp->xyz[1]=offset+(long)(x*UNITL);
00913             y_f=vp->xyz[2]=zpos+(long)(y*UNITL);
00914             maxx=max(maxx,vp->xyz[1]);
00915             vc=vf=vl;
00916           }
00917           last_x=x; last_y=y;
00918           csize=lpTT->cb - sizeof(TTPOLYGONHEADER);
00919           lpTP=(TTPOLYCURVE *)(((BYTE*)lpTT)+sizeof(TTPOLYGONHEADER));
00920           while(csize > 0){
00921             npoints=(long)(lpTP->cpfx);
00922             ctype=(long)lpTP->wType;
00923             lpPFX = (POINTFX *)(((BYTE *)lpTP) +(2*sizeof(WORD)));
00924             for(i=0;i<npoints;i++){
00925               memcpy(&fx,&(lpPFX->x),sizeof(FIXED));
00926               memcpy(&fy,&(lpPFX->y),sizeof(FIXED));
00927               x=(double)fx.value + (((double)fx.fract)/65525.0);
00928               y=(double)fy.value + (((double)fy.fract)/65525.0);
00929               if(ctype == 2){
00930                 if(i > 0){
00931                   if(i < npoints-1){
00932                     mid_x=(off_x + x)*0.5;
00933                     mid_y=(off_y + y)*0.5;
00934                   }
00935                   else{
00936                     mid_x=x;
00937                     mid_y=y;
00938                   }
00939                   //
00940                   // build spline last  - off  - mid
00941                   //
00942                   if(!(x_f == offset+(long)(mid_x*UNITL) &&
00943                        y_f == zpos+(long)(mid_y*UNITL) )){ // not back at start
00944                     float ax,bx,cx,ay,by,cy,t,step;
00945                     ax=(mid_x - 2.0*off_x + last_x);
00946                     bx=2.0*(off_x - last_x);
00947                     cx=last_x;
00948                     ay=(mid_y - 2.0*off_y + last_y);
00949                     by=2.0*(off_y - last_y);
00950                     cy=last_y;
00951                     t=0.0;
00952                     if(preview)step=5;
00953                     else       step=3;
00954                     for(j=0;j<step;j++){
00955                       t += 1.0/(double)step;
00956                       mid_x = t*(t*ax + bx) + cx;
00957                       mid_y = t*(t*ay + by) + cy;
00958                       if(preview){
00959                         vc_x=(long)(mid_x*UNITP);
00960                         vc_y=(long)(mid_y*UNITP);
00961                         CreateCharacterEdge(vl_x,vl_y,vc_x,vc_y);
00962                         vl_x=vc_x;
00963                         vl_y=vc_y;
00964                       }
00965                       else{
00966                         UpdateVertexHeap(Nvert+1);
00967                         CreateVertex();
00968                         vc=Nvert-1;
00969                         vp=(MainVp+vc);
00970                         vp->xyz[0]=NpointerX;
00971                         vp->xyz[1]=offset+(long)(mid_x*UNITL);
00972                         vp->xyz[2]=zpos+(long)(mid_y*UNITL);
00973                         maxx=max(maxx,vp->xyz[1]);
00974                         UpdateEdgeHeap(Nedge+1);
00975                         CreateEdge(vc,vl);
00976                         vl=vc;
00977                       }
00978                     }
00979                   }
00980                   //
00981                   //
00982                   last_x=mid_x; last_y=mid_y;
00983                 }
00984                 off_x=x; off_y=y;
00985               }
00986               else{
00987                 if(preview){
00988                   vc_x=(long)(x*UNITP);
00989                   vc_y=(long)(y*UNITP);
00990                   CreateCharacterEdge(vl_x,vl_y,vc_x,vc_y);
00991                   vl_x=vc_x;
00992                   vl_y=vc_y;
00993                 }
00994                 else{
00995                   UpdateVertexHeap(Nvert+1);
00996                   CreateVertex();
00997                   vc=Nvert-1;
00998                   vp=(MainVp+vc);
00999                   vp->xyz[0]=NpointerX;
01000                   vp->xyz[1]=offset+(long)(x*UNITL);
01001                   vp->xyz[2]=zpos+(long)(y*UNITL);
01002                   maxx=max(maxx,vp->xyz[1]);
01003                   UpdateEdgeHeap(Nedge+1);
01004                   CreateEdge(vc,vl);
01005                   vl=vc;
01006                 }
01007                 last_x=x; last_y=y;
01008               }
01009               lpPFX++;
01010             }
01011             csize -= (2*sizeof(WORD) + npoints*sizeof(POINTFX));
01012             lpTP = (TTPOLYCURVE *)(((BYTE *)lpTP) +
01013                    (2*sizeof(WORD) + npoints*sizeof(POINTFX)));
01014           }
01015           if(preview){
01016             CreateCharacterEdge(vf_x,vf_y,vl_x,vl_y);
01017           }
01018           else{
01019             UpdateEdgeHeap(Nedge+1);
01020             CreateEdge(vl,vf);
01021           }
01022           size -= lpTT->cb;
01023           lpTT=(TTPOLYGONHEADER *)(((BYTE *)lpTT) + lpTT->cb);
01024         }
01025       }
01026       X__Free(buffer);
01027     }
01028   }
01029   Cwidthx = maxx-offset;
01030   SelectObject(hdc,hfontOld);
01031   DeleteObject(hfont);
01032   ReleaseDC(hwndParent,hdc);
01033   return;
01034 }
01035 
01036 #if 0
01037 float ax,bx,cx,ay,by,cy,t;
01038 #if 0
01039 cx=3.0*(0.6*(off_x-last_x)+last_x - last_x);
01040 bx=3.0*(0.4*(mid_x-off_x)+off_x - 0.6*(off_x-last_x) - last_x) - cx;
01041 ax=(mid_x - last_x)-bx-cx;
01042 cy=3.0*(0.6*(off_y-last_y)+last_y - last_y);
01043 by=3.0*(0.4*(mid_y-off_y)+off_y - 0.6*(off_y-last_y) - last_y) - cy;
01044 ay=(mid_y - last_y)-by-cy;
01045 #else
01046 ax=(mid_x - 2.0*off_x + last_x);
01047 bx=2.0*(off_x - last_x);
01048 cx=last_x;
01049 ay=(mid_y - 2.0*off_y + last_y);
01050 by=2.0*(off_y - last_y);
01051 cy=last_y;
01052 #endif
01053 t=0.0;
01054 for(j=0;j<5;j++){
01055   t += 0.2;
01056 //   mid_x = t*(t*(t*ax + bx) + cx) + last_x;
01057 //  mid_y = t*(t*(t*ay + by) + cy) + last_y;
01058   mid_x = t*(t*ax + bx) + cx;
01059   mid_y = t*(t*ay + by) + cy;
01060   vc_x=(long)(mid_x*UNITP);
01061   vc_y=(long)(mid_y*UNITP);
01062   CreateCharacterEdge(vl_x,vl_y,vc_x,vc_y);
01063   vl_x=vc_x;
01064   vl_y=vc_y;
01065 }
01066                       vc_x=(long)(mid_x*UNITP);
01067                       vc_y=(long)(mid_y*UNITP);
01068                       CreateCharacterEdge(vl_x,vl_y,vc_x,vc_y);
01069                       vl_x=vc_x;
01070                       vl_y=vc_y;
01071 #endif
01072 
01073 #if 0
01074 static TTF_STRUCTURE TtfStructure;
01075 
01076 BOOL _Xmodeler
01077  (HWND parent_window,HWND info_window,X__STRUCTURE *lpevi){
01078   hwndParent=parent_window;
01079   lpTtf=&TtfStructure;
01080 
01081   ZeroMemory(lpTtf,sizeof(TTF_STRUCTURE));
01082   lpTtf->TTF_face_colour[0]=255;
01083   lpTtf->TTF_side_colour[2]=255;
01084   lpTtf->TTF_beve_colour[0]=255;
01085   lpTtf->TTF_beve_colour[1]=255;
01086   lpTtf->TTF_bevel_angle=45;
01087   lpTtf->TTF_char_preview='Q';
01088   lpTtf->FORB=1;
01089   lpTtf->TTF_cap=1;
01090   strcpy(lpTtf->TTF_Letters,"");
01091 
01092 #endif

Generated on Sun Apr 27 14:20:12 2014 for OpenFX by  doxygen 1.5.6