1 /*
2  * FTGL - OpenGL font library
3  *
4  * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
5  * Copyright (c) 2008-2010 Sam Hocevar <sam@hocevar.net>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 
27 #include "config.h"
28 
29 #include "FTGL/ftgl.h"
30 
31 #include "FTInternals.h"
32 #include "FTPolygonFontImpl.h"
33 
34 
35 //
36 //  FTPolygonFont
37 //
38 
39 
FTPolygonFont(char const * fontFilePath)40 FTPolygonFont::FTPolygonFont(char const *fontFilePath) :
41     FTFont(new FTPolygonFontImpl(this, fontFilePath))
42 {}
43 
44 
FTPolygonFont(const unsigned char * pBufferBytes,size_t bufferSizeInBytes)45 FTPolygonFont::FTPolygonFont(const unsigned char *pBufferBytes,
46                              size_t bufferSizeInBytes) :
47     FTFont(new FTPolygonFontImpl(this, pBufferBytes, bufferSizeInBytes))
48 {}
49 
50 
~FTPolygonFont()51 FTPolygonFont::~FTPolygonFont()
52 {}
53 
54 
MakeGlyph(FT_GlyphSlot ftGlyph)55 FTGlyph* FTPolygonFont::MakeGlyph(FT_GlyphSlot ftGlyph)
56 {
57     FTPolygonFontImpl *myimpl = dynamic_cast<FTPolygonFontImpl *>(impl);
58     if(!myimpl)
59     {
60         return NULL;
61     }
62 
63     return new FTPolygonGlyph(ftGlyph, myimpl->outset,
64                               myimpl->useDisplayLists);
65 }
66 
67 
68 //
69 //  FTPolygonFontImpl
70 //
71 
72 
FTPolygonFontImpl(FTFont * ftFont,const char * fontFilePath)73 FTPolygonFontImpl::FTPolygonFontImpl(FTFont *ftFont, const char* fontFilePath)
74 : FTFontImpl(ftFont, fontFilePath),
75   outset(0.0f)
76 {
77     load_flags = FT_LOAD_NO_HINTING;
78 }
79 
80 
FTPolygonFontImpl(FTFont * ftFont,const unsigned char * pBufferBytes,size_t bufferSizeInBytes)81 FTPolygonFontImpl::FTPolygonFontImpl(FTFont *ftFont,
82                                      const unsigned char *pBufferBytes,
83                                      size_t bufferSizeInBytes)
84 : FTFontImpl(ftFont, pBufferBytes, bufferSizeInBytes),
85   outset(0.0f)
86 {
87     load_flags = FT_LOAD_NO_HINTING;
88 }
89 
90 
91 template <typename T>
RenderI(const T * string,const int len,FTPoint position,FTPoint spacing,int renderMode)92 inline FTPoint FTPolygonFontImpl::RenderI(const T* string, const int len,
93                                           FTPoint position, FTPoint spacing,
94                                           int renderMode)
95 {
96     // Protect GL_POLYGON
97     glPushAttrib(GL_POLYGON_BIT);
98 
99     // Activate front and back face filling. If the caller wants only
100     // front face, it can set proper culling.
101     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
102 
103     FTPoint tmp = FTFontImpl::Render(string, len,
104                                      position, spacing, renderMode);
105 
106     glPopAttrib();
107 
108     return tmp;
109 }
110 
111 
Render(const char * string,const int len,FTPoint position,FTPoint spacing,int renderMode)112 FTPoint FTPolygonFontImpl::Render(const char * string, const int len,
113                                   FTPoint position, FTPoint spacing,
114                                   int renderMode)
115 {
116     return RenderI(string, len, position, spacing, renderMode);
117 }
118 
119 
Render(const wchar_t * string,const int len,FTPoint position,FTPoint spacing,int renderMode)120 FTPoint FTPolygonFontImpl::Render(const wchar_t * string, const int len,
121                                   FTPoint position, FTPoint spacing,
122                                   int renderMode)
123 {
124     return RenderI(string, len, position, spacing, renderMode);
125 }
126 
127