comparison src/txt-eng-ft.cc @ 14003:1555c5a177c9

better fix for fontconfig segfault * txt-eng-ft.cc (ft_manager::fontconfig_initialized): Rename from fc_init_done. Always declare and define. (ft_manager::freetype_initialized): New data member. (ft_manager::ft_manager): Set freetype_initialized. (ft_manager::~ft_manager): Call FT_Done_FreeType if freetype is initialized. Comment out code to conditionally call FcFini. (ft_manager::instance_ok): Do delete instance.
author John W. Eaton <jwe@octave.org>
date Wed, 07 Dec 2011 04:16:27 -0500
parents 1221086f1ba5
children 72c96de7a403
comparison
equal deleted inserted replaced
14002:82f5f76726a2 14003:1555c5a177c9
22 22
23 #ifdef HAVE_CONFIG_H 23 #ifdef HAVE_CONFIG_H
24 #include <config.h> 24 #include <config.h>
25 #endif 25 #endif
26 26
27 #if HAVE_FREETYPE 27 #if defined (HAVE_FREETYPE)
28 28
29 #if HAVE_FONTCONFIG 29 #if defined (HAVE_FONTCONFIG)
30 #include <fontconfig/fontconfig.h> 30 #include <fontconfig/fontconfig.h>
31 #endif 31 #endif
32 32
33 #include <iostream> 33 #include <iostream>
34 34
75 75
76 if (! instance) 76 if (! instance)
77 { 77 {
78 instance = new ft_manager (); 78 instance = new ft_manager ();
79 79
80 // FIXME -- there seem to be some memory management errors
81 // related to fontconfig that cause segfaults when Octave
82 // exits if ft_manager::instance is explicitly deleted. So
83 // skip doing that for now.
84 #if 0
85 if (instance) 80 if (instance)
86 singleton_cleanup_list::add (cleanup_instance); 81 singleton_cleanup_list::add (cleanup_instance);
87 #endif
88 } 82 }
89 83
90 if (! instance) 84 if (! instance)
91 { 85 {
92 ::error ("unable to create ft_manager!"); 86 ::error ("unable to create ft_manager!");
115 109
116 ft_manager (const ft_manager&); 110 ft_manager (const ft_manager&);
117 111
118 ft_manager& operator = (const ft_manager&); 112 ft_manager& operator = (const ft_manager&);
119 113
120 ft_manager (void) : library () 114 ft_manager (void)
121 #if HAVE_FONTCONFIG 115 : library (), freetype_initialized (false), fontconfig_initialized (false)
122 , fc_init_done (false) 116 {
117 if (FT_Init_FreeType (&library))
118 ::error ("unable to initialize freetype library");
119 else
120 freetype_initialized = true;
121
122 #if defined (HAVE_FONTCONFIG)
123 if (! FcInit ())
124 ::error ("unable to initialize fontconfig library");
125 else
126 fontconfig_initialized = true;
123 #endif 127 #endif
124 { 128 }
125 if (FT_Init_FreeType (&library)) 129
126 { 130 ~ft_manager (void)
127 ::error ("unable to initialize freetype library"); 131 {
128 } 132 if (freetype_initialized)
129 133 FT_Done_FreeType (library);
130 #if HAVE_FONTCONFIG 134
131 fc_init_done = false; 135 #if defined (HAVE_FONTCONFIG)
132 if (! FcInit ()) 136 // FIXME -- Skip the call to FcFini because it can trigger the
133 { 137 // assertion
134 ::error ("unable to initialize fontconfig library"); 138 //
135 } 139 // octave: fccache.c:507: FcCacheFini: Assertion `fcCacheChains[i] == ((void *)0)' failed.
136 else 140 //
137 { 141 // if (fontconfig_initialized)
138 fc_init_done = true; 142 // FcFini ();
139 }
140 #endif 143 #endif
141 } 144 }
142 145
143 ~ft_manager (void)
144 {
145 #if HAVE_FONTCONFIG
146 FcFini ();
147 fc_init_done = false;
148 #endif
149 }
150 146
151 FT_Face do_get_font (const std::string& name, const std::string& weight, 147 FT_Face do_get_font (const std::string& name, const std::string& weight,
152 const std::string& angle, double size) 148 const std::string& angle, double size)
153 { 149 {
154 FT_Face retval = 0; 150 FT_Face retval = 0;
155 151
156 std::string file; 152 std::string file;
157 153
158 #if HAVE_FONTCONFIG 154 #if defined (HAVE_FONTCONFIG)
159 if (fc_init_done) 155 if (fontconfig_initialized)
160 { 156 {
161 int fc_weight, fc_angle; 157 int fc_weight, fc_angle;
162 158
163 if (weight == "bold") 159 if (weight == "bold")
164 fc_weight = FC_WEIGHT_BOLD; 160 fc_weight = FC_WEIGHT_BOLD;
231 return retval; 227 return retval;
232 } 228 }
233 229
234 private: 230 private:
235 FT_Library library; 231 FT_Library library;
236 #if HAVE_FONTCONFIG 232 bool freetype_initialized;
237 bool fc_init_done; 233 bool fontconfig_initialized;
238 #endif
239 }; 234 };
240 235
241 ft_manager* ft_manager::instance = 0; 236 ft_manager* ft_manager::instance = 0;
242 237
243 // --------------------------------------------------------------------------- 238 // ---------------------------------------------------------------------------