1 /*
2  * FTGL - OpenGL font library
3  *
4  * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 #include "config.h"
27 
28 #include "FTGL/FTLibrary.h"
29 #include "FTCleanup.h"
30 #include <stdexcept>
31 
Instance()32 FTLibrary& FTLibrary::Instance()
33 {
34     static FTLibrary ftlib;
35     return ftlib;
36 }
37 
38 
~FTLibrary()39 FTLibrary::~FTLibrary()
40 {
41     FTCleanup::Instance()->DestroyAll();
42 
43     if(library != 0)
44     {
45         FT_Done_FreeType(*library);
46 
47         delete library;
48         library= 0;
49     }
50 }
51 
52 
FTLibrary()53 FTLibrary::FTLibrary()
54 :   library(0),
55     err(0),
56     LegacyOpenGLStateHandling(-1)
57 {
58     Initialise();
59 }
60 
61 
Initialise()62 bool FTLibrary::Initialise()
63 {
64     if(library != 0)
65         return true;
66 
67     library = new FT_Library;
68 
69     err = FT_Init_FreeType(library);
70     if(err)
71     {
72         delete library;
73         library = 0;
74         return false;
75     }
76 
77     FTCleanup::Instance();
78 
79     return true;
80 }
81 
82 
LegacyOpenGLState(bool On)83 void FTLibrary::LegacyOpenGLState(bool On)
84 {
85   int Old = LegacyOpenGLStateHandling.exchange(On);
86   if (Old >= 0 && Old != On)
87     throw std::logic_error
88       ("FTGL: inconsistent LegacyOpenGLState setting, see README-LegacyOpenGLState");
89 }
90