1 /*
2 * FTGL - OpenGL font library
3 *
4 * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
5 * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
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 "FTOutlineFontImpl.h"
33
34
35 //
36 // FTOutlineFont
37 //
38
39
FTOutlineFont(char const * fontFilePath)40 FTOutlineFont::FTOutlineFont(char const *fontFilePath) :
41 FTFont(new FTOutlineFontImpl(this, fontFilePath))
42 {}
43
44
FTOutlineFont(const unsigned char * pBufferBytes,size_t bufferSizeInBytes)45 FTOutlineFont::FTOutlineFont(const unsigned char *pBufferBytes,
46 size_t bufferSizeInBytes) :
47 FTFont(new FTOutlineFontImpl(this, pBufferBytes, bufferSizeInBytes))
48 {}
49
50
~FTOutlineFont()51 FTOutlineFont::~FTOutlineFont()
52 {}
53
54
MakeGlyph(FT_GlyphSlot ftGlyph)55 FTGlyph* FTOutlineFont::MakeGlyph(FT_GlyphSlot ftGlyph)
56 {
57 FTOutlineFontImpl *myimpl = dynamic_cast<FTOutlineFontImpl *>(impl);
58 if(!myimpl)
59 {
60 return NULL;
61 }
62
63 return new FTOutlineGlyph(ftGlyph, myimpl->outset,
64 myimpl->useDisplayLists);
65 }
66
67
68 //
69 // FTOutlineFontImpl
70 //
71
72
FTOutlineFontImpl(FTFont * ftFont,const char * fontFilePath)73 FTOutlineFontImpl::FTOutlineFontImpl(FTFont *ftFont, const char* fontFilePath)
74 : FTFontImpl(ftFont, fontFilePath),
75 outset(0.0f)
76 {
77 load_flags = FT_LOAD_NO_HINTING;
78 }
79
80
FTOutlineFontImpl(FTFont * ftFont,const unsigned char * pBufferBytes,size_t bufferSizeInBytes)81 FTOutlineFontImpl::FTOutlineFontImpl(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 FTOutlineFontImpl::RenderI(const T* string, const int len,
93 FTPoint position, FTPoint spacing,
94 int renderMode)
95 {
96 // Protect GL_TEXTURE_2D, glHint(), GL_LINE_SMOOTH and blending functions
97 glPushAttrib(GL_ENABLE_BIT | GL_HINT_BIT | GL_LINE_BIT
98 | GL_COLOR_BUFFER_BIT);
99
100 glDisable(GL_TEXTURE_2D);
101 glEnable(GL_LINE_SMOOTH);
102 glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
103 glEnable(GL_BLEND);
104 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // GL_ONE
105
106 FTPoint tmp = FTFontImpl::Render(string, len,
107 position, spacing, renderMode);
108
109 glPopAttrib();
110
111 return tmp;
112 }
113
114
Render(const char * string,const int len,FTPoint position,FTPoint spacing,int renderMode)115 FTPoint FTOutlineFontImpl::Render(const char * string, const int len,
116 FTPoint position, FTPoint spacing,
117 int renderMode)
118 {
119 return RenderI(string, len, position, spacing, renderMode);
120 }
121
122
Render(const wchar_t * string,const int len,FTPoint position,FTPoint spacing,int renderMode)123 FTPoint FTOutlineFontImpl::Render(const wchar_t * string, const int len,
124 FTPoint position, FTPoint spacing,
125 int renderMode)
126 {
127 return RenderI(string, len, position, spacing, renderMode);
128 }
129
130