FTExtrdGlyph.cpp

Go to the documentation of this file.
00001 #include    <math.h>
00002 
00003 #include    "FTExtrdGlyph.h"
00004 #include    "FTVectoriser.h"
00005 
00006 
00007 FTExtrdGlyph::FTExtrdGlyph( FT_GlyphSlot glyph, float d)
00008 :   FTGlyph( glyph),
00009     glList(0),
00010     depth(d)
00011 {
00012     bBox.SetDepth( -depth);
00013         
00014     if( ft_glyph_format_outline != glyph->format)
00015     {
00016         err = 0x14; // Invalid_Outline
00017         return;
00018     }
00019 
00020     FTVectoriser vectoriser( glyph);
00021     if ( ( vectoriser.ContourCount() < 1) || ( vectoriser.PointCount() < 3))
00022     {
00023         return;
00024     }
00025 
00026     unsigned int tesselationIndex;
00027     glList = glGenLists(1);
00028     glNewList( glList, GL_COMPILE);
00029 
00030         vectoriser.MakeMesh( 1.0);
00031         glNormal3d(0.0, 0.0, 1.0);
00032         
00033         const FTMesh* mesh = vectoriser.GetMesh();
00034         for( tesselationIndex = 0; tesselationIndex < mesh->TesselationCount(); ++tesselationIndex)
00035         {
00036             const FTTesselation* subMesh = mesh->Tesselation( tesselationIndex);
00037             unsigned int polyonType = subMesh->PolygonType();
00038 
00039             glBegin( polyonType);
00040                 for( unsigned int pointIndex = 0; pointIndex < subMesh->PointCount(); ++pointIndex)
00041                 {
00042                     glVertex3f( subMesh->Point( pointIndex).x / 64.0f,
00043                                 subMesh->Point( pointIndex).y / 64.0f,
00044                                 0.0f);
00045                 }
00046             glEnd();
00047         }
00048         
00049         vectoriser.MakeMesh( -1.0);
00050         glNormal3d(0.0, 0.0, -1.0);
00051         
00052         mesh = vectoriser.GetMesh();
00053         for( tesselationIndex = 0; tesselationIndex < mesh->TesselationCount(); ++tesselationIndex)
00054         {
00055             const FTTesselation* subMesh = mesh->Tesselation( tesselationIndex);
00056             unsigned int polyonType = subMesh->PolygonType();
00057 
00058             glBegin( polyonType);
00059                 for( unsigned int pointIndex = 0; pointIndex < subMesh->PointCount(); ++pointIndex)
00060                 {
00061                     glVertex3f( subMesh->Point( pointIndex).x / 64.0f,
00062                                 subMesh->Point( pointIndex).y / 64.0f,
00063                                 -depth);
00064                 }
00065             glEnd();
00066         }
00067         
00068         int contourFlag = vectoriser.ContourFlag();
00069         
00070         for( size_t c = 0; c < vectoriser.ContourCount(); ++c)
00071         {
00072             const FTContour* contour = vectoriser.Contour(c);
00073             unsigned int numberOfPoints = contour->PointCount();
00074             
00075             glBegin( GL_QUAD_STRIP);
00076                 for( unsigned int j = 0; j <= numberOfPoints; ++j)
00077                 {
00078                     unsigned int index = ( j == numberOfPoints) ? 0 : j;
00079                     unsigned int nextIndex = ( index == numberOfPoints - 1) ? 0 : index + 1;
00080                     
00081                     FTPoint normal = GetNormal( contour->Point(index), contour->Point(nextIndex));
00082                     glNormal3f( normal.x, normal.y, 0.0f);
00083                     
00084                     if( contourFlag & ft_outline_reverse_fill)
00085                     {
00086                         glVertex3f( contour->Point(index).x / 64.0f, contour->Point(index).y / 64.0f, 0.0f);
00087                         glVertex3f( contour->Point(index).x / 64.0f, contour->Point(index).y / 64.0f, -depth);
00088                     }
00089                     else
00090                     {
00091                         glVertex3f( contour->Point(index).x / 64.0f, contour->Point(index).y / 64.0f, -depth);
00092                         glVertex3f( contour->Point(index).x / 64.0f, contour->Point(index).y / 64.0f, 0.0f);
00093                     }
00094                 }
00095             glEnd();
00096         }
00097         
00098     glEndList();
00099 }
00100 
00101 
00102 FTExtrdGlyph::~FTExtrdGlyph()
00103 {
00104     glDeleteLists( glList, 1);
00105 }
00106 
00107 
00108 float FTExtrdGlyph::Render( const FTPoint& pen)
00109 {
00110     if( glList)
00111     {
00112         glTranslatef( pen.x, pen.y, 0);
00113             glCallList( glList);    
00114         glTranslatef( -pen.x, -pen.y, 0);
00115     }
00116     
00117     return advance;
00118 }
00119 
00120 
00121 FTPoint FTExtrdGlyph::GetNormal( const FTPoint &a, const FTPoint &b)
00122 {
00123     float vectorX = a.x - b.x;
00124     float vectorY = a.y - b.y;
00125                               
00126     float length = sqrt( vectorX * vectorX + vectorY * vectorY );
00127     
00128     if( length > 0.0f)
00129     {
00130         length = 1 / length;
00131     }
00132     else
00133     {
00134         length = 0.0f;
00135     }
00136     
00137     return FTPoint( -vectorY * length,
00138                      vectorX * length,
00139                      0.0f);
00140 }
00141 

Generated on Wed Aug 23 05:11:42 2006 for FTGL by  doxygen 1.4.7