TTFX.C

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 1.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 OpenFX Development Team
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 You may contact the OpenFX development team via elecronic mail
00020 at core@openfx.org, or visit our website at http://openfx.org for
00021 further information and support details.
00022 -- */
00023 
00024 /*  TTFX.C  */
00025 #include <stdlib.h>
00026 #include <stdio.h>
00027 #include <math.h>
00028 #include <windows.h>
00029 
00030 #include "struct.h"
00031 #include "dstruct.h"
00032 
00033 #include "ttf.h"
00034 
00035 #define DESELECTED 0
00036 #define SELECTED   1
00037 
00038 #define UNITL 65536.0
00039 
00040 #ifndef min
00041 #define min(a,b)  ( ((a) < (b)) ? (a) : (b) )
00042 #endif
00043 #ifndef max
00044 #define max(a,b)  ( ((a) > (b)) ? (a) : (b) )
00045 #endif
00046 
00047 
00048 static HWND      hParent;
00049 static HINSTANCE hThisInstance;
00050 
00051 #if __WATCOMC__
00052 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00053 #else
00054 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00055 #endif
00056   switch (dwReason) {
00057     case DLL_PROCESS_ATTACH: {
00058       hThisInstance=hDLL;
00059       if(hDLL == NULL)MessageBox ( GetFocus()," NULL instance",NULL, MB_OK);
00060       break;
00061     }
00062     case DLL_PROCESS_DETACH:
00063       break;
00064   }
00065   return TRUE;
00066 }
00067 
00068 #if __SC__
00069 #pragma startaddress(DllMain)
00070 #endif
00071 
00072 BOOL _Xmodeler
00073  (HWND parent_window,HWND info_window,X__STRUCTURE *lpevi){
00074  CHOOSEFONT cf;
00075  LOGFONT    lf;
00076  char stxx[256],*pcc;
00077  lpEVI=lpevi;
00078  hParent=parent_window;
00079  memset(&cf,0,sizeof(CHOOSEFONT));
00080  memset(&lf,0,sizeof(LOGFONT));
00081  cf.lStructSize=sizeof(CHOOSEFONT);
00082  cf.hwndOwner=hParent;
00083  cf.lpLogFont=&lf;
00084  cf.iPointSize=10;
00085  cf.Flags=CF_SCREENFONTS|CF_TTONLY;
00086  cf.nFontType=SCREEN_FONTTYPE;
00087  if(ChooseFont(&cf)){
00088   HDC hdc;
00089   HFONT hfont,hfontOld;
00090   GLYPHMETRICS gm;
00091   static MAT2 m2;  // very important for strange bug !!!!!
00092   BYTE *buffer,c;
00093   long zpos,offset,dmax;
00094   long size,csize,npoints,ctype,i,j,vc,vl,vf,maxx;
00095   vertex *vp;
00096   hdc=GetDC(hParent);
00097   hfont=CreateFontIndirect(cf.lpLogFont);
00098   hfontOld=SelectObject(hdc,hfont);
00099 
00100   strcpy(stxx,"RSF 1234 abc");
00101 
00102   offset=NpointerY; zpos=NpointerZ;
00103 
00104   pcc=stxx;
00105 
00106   while((c = (BYTE)(*pcc++)) > 0){
00107   if(c == ' '){
00108     offset += 2*(long)(UNITL*0.1);
00109   }
00110   else{
00111 
00112   maxx=offset; dmax=(long)(UNITL*0.1);
00113   if((size=GetGlyphOutline(hdc,c,GGO_NATIVE,&gm,0,NULL,&m2)) > 0){
00114     if((buffer = (BYTE *)X__Malloc(size)) != NULL){
00115       memset(buffer,0,size);
00116       if((size=GetGlyphOutline(hdc,c,GGO_NATIVE,&gm,size,buffer,&m2)) > 0){
00117         //FILE *ff;
00118         TTPOLYGONHEADER *lpTT;
00119         //ff=fopen("d:\\debug","w");
00120         lpTT=(TTPOLYGONHEADER *)buffer;
00121         //fprintf(ff,"Size %ld\n",size);
00122         while(size > 0){
00123           TTPOLYCURVE *lpTP;
00124           POINTFX *lpPFX;
00125           FIXED fx,fy;
00126           double x,y,last_x,last_y,off_x,off_y,mid_x,mid_y;
00127           long x_f,y_f;
00128           //fprintf(ff,"Polygon Header %ld bytes  Type %ld\n",lpTT->cb,lpTT->dwType);
00129           lpPFX = (POINTFX *)(((BYTE *)lpTT) +(2*sizeof(DWORD)));
00130           memcpy(&fx,&(lpPFX->x),sizeof(FIXED));
00131           memcpy(&fy,&(lpPFX->y),sizeof(FIXED));
00132           //fprintf(ff,"%ld %ld     %ld %ld\n",fx.value,fx.fract,fy.value,fy.fract);
00133           x=(double)fx.value + (((double)fx.fract)/65525.0);
00134           y=(double)fy.value + (((double)fy.fract)/65525.0);
00135           //fprintf(ff,"Start Point x=%lf y=%lf\n",x,y);
00136           UpdateVertexHeap(Nvert+1);
00137           CreateVertex();    // First point
00138           vl=Nvert-1;
00139           vp=(MainVp+vl);
00140           vp->xyz[0]=NpointerX;
00141           x_f=vp->xyz[1]=offset+(long)(x*UNITL);
00142           y_f=vp->xyz[2]=zpos+(long)(y*UNITL);
00143           maxx=max(maxx,vp->xyz[1]);
00144           vc=vf=vl;
00145           last_x=x; last_y=y;
00146           csize=lpTT->cb - sizeof(TTPOLYGONHEADER);
00147           lpTP=(TTPOLYCURVE *)(((BYTE*)lpTT)+sizeof(TTPOLYGONHEADER));
00148           while(csize > 0){
00149             npoints=(long)(lpTP->cpfx);
00150             ctype=(long)lpTP->wType;
00151             //fprintf(ff,"Curve type %ld with %ld points\n",(long)lpTP->wType,npoints);
00152             lpPFX = (POINTFX *)(((BYTE *)lpTP) +(2*sizeof(WORD)));
00153             for(i=0;i<npoints;i++){
00154               memcpy(&fx,&(lpPFX->x),sizeof(FIXED));
00155               memcpy(&fy,&(lpPFX->y),sizeof(FIXED));
00156               x=(double)fx.value + (((double)fx.fract)/65525.0);
00157               y=(double)fy.value + (((double)fy.fract)/65525.0);
00158               //fprintf(ff,"Point x=%lf y=%lf\n",x,y);
00159               if(ctype == 2){
00160                 if(i > 0){
00161                   if(i < npoints-1){
00162                     mid_x=(off_x + x)*0.5;
00163                     mid_y=(off_y + y)*0.5;
00164                   }
00165                   else{
00166                     mid_x=x;
00167                     mid_y=y;
00168                   }
00169                   //
00170                   // build spline last  - off  - mid
00171                   //
00172                   if(!(x_f == offset+(long)(mid_x*UNITL) &&
00173                        y_f == zpos+(long)(mid_y*UNITL) )){ // not back at start
00174                     UpdateVertexHeap(Nvert+1);
00175                     CreateVertex();
00176                     vc=Nvert-1;
00177                     vp=(MainVp+vc);
00178                     vp->xyz[0]=NpointerX;
00179                     vp->xyz[1]=offset+(long)(mid_x*UNITL);
00180                     vp->xyz[2]=zpos+(long)(mid_y*UNITL);
00181                     maxx=max(maxx,vp->xyz[1]);
00182                     UpdateEdgeHeap(Nedge+1);
00183                     CreateEdge(vc,vl);
00184                     vl=vc;
00185                   }
00186                   //
00187                   //
00188                   last_x=mid_x; last_y=mid_y;
00189                 }
00190                 off_x=x; off_y=y;
00191               }
00192               else{
00193                 UpdateVertexHeap(Nvert+1);
00194                 CreateVertex();
00195                 vc=Nvert-1;
00196                 vp=(MainVp+vc);
00197                 vp->xyz[0]=NpointerX;
00198                 vp->xyz[1]=offset+(long)(x*UNITL);
00199                 vp->xyz[2]=zpos+(long)(y*UNITL);
00200                 maxx=max(maxx,vp->xyz[1]);
00201                 UpdateEdgeHeap(Nedge+1);
00202                 CreateEdge(vc,vl);
00203                 vl=vc;
00204                 last_x=x; last_y=y;
00205               }
00206               lpPFX++;
00207             }
00208             csize -= (2*sizeof(WORD) + npoints*sizeof(POINTFX));
00209             lpTP = (TTPOLYCURVE *)(((BYTE *)lpTP) +
00210                    (2*sizeof(WORD) + npoints*sizeof(POINTFX)));
00211           }
00212           UpdateEdgeHeap(Nedge+1);
00213           CreateEdge(vl,vf);
00214           size -= lpTT->cb;
00215           lpTT=(TTPOLYGONHEADER *)(((BYTE *)lpTT) + lpTT->cb);
00216         }
00217         //fclose(ff);
00218       }
00219       X__Free(buffer);
00220     }
00221   }
00222   offset=maxx+dmax;
00223 
00224   }
00225   }
00226 
00227   SelectObject(hdc,hfontOld);
00228   DeleteObject(hfont);
00229   ReleaseDC(hParent,hdc);
00230  }
00231  return TRUE;
00232 }

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