Mercurial > octave
comparison libinterp/corefcn/ft-text-renderer.cc @ 24126:2390079a8aed
Provide default font files and use them (bug #52150)
* ft-text-renderer.cc (ft_manager::do_get_font): Look for FreeSans font files in
oct_etc_dir by default when OCTAVE_FONT_DIR is not set. Use this font as
default ("*") or fallback when fontconfig is unable to find a suitable font
by name.
* run-octave.in: export OCTAVE_FONT_DIR
* etc/fonts: new directory containing default font files FreeSans.otf,
FreeSansBold.otf, FreeSansBoldOblique.otf and FreeSansOblique.otf.
* etc/module.mk (etc_fontsdir, etc_fonts_DATA): New variables. Include
$(etc_fonts_DATA) in the source distribution.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Tue, 03 Oct 2017 11:11:21 +0200 |
parents | 1b7e49a72c62 |
children | 53ca76c5cc8d |
comparison
equal
deleted
inserted
replaced
24125:ed746cbfce24 | 24126:2390079a8aed |
---|---|
52 #include <map> | 52 #include <map> |
53 #include <utility> | 53 #include <utility> |
54 | 54 |
55 #include "singleton-cleanup.h" | 55 #include "singleton-cleanup.h" |
56 | 56 |
57 #include "defaults.h" | |
57 #include "error.h" | 58 #include "error.h" |
59 #include "file-ops.h" | |
60 #include "oct-env.h" | |
58 #include "pr-output.h" | 61 #include "pr-output.h" |
59 #include "text-renderer.h" | 62 #include "text-renderer.h" |
60 | 63 |
61 // FIXME: maybe issue at most one warning per glyph/font/size/weight | 64 // FIXME: maybe issue at most one warning per glyph/font/size/weight |
62 // combination. | 65 // combination. |
201 FT_Reference_Face (it->second); | 204 FT_Reference_Face (it->second); |
202 return it->second; | 205 return it->second; |
203 } | 206 } |
204 #endif | 207 #endif |
205 | 208 |
209 static std::string font_dir; | |
210 | |
211 if (font_dir.empty ()) | |
212 { | |
213 font_dir = sys::env::getenv ("OCTAVE_FONT_DIR"); | |
214 | |
215 if (font_dir.empty ()) | |
216 font_dir = config::oct_etc_dir () + sys::file_ops::dir_sep_str () | |
217 + "fonts"; | |
218 } | |
219 | |
220 | |
221 // Default font file | |
206 std::string file; | 222 std::string file; |
207 | 223 |
224 if (! font_dir.empty ()) | |
225 { | |
226 file = font_dir + octave::sys::file_ops::dir_sep_str () + "FreeSans"; | |
227 | |
228 if (weight == "bold") | |
229 file += "Bold"; | |
230 | |
231 if (angle == "italic" || angle == "oblique") | |
232 file += "Oblique"; | |
233 | |
234 file += ".otf"; | |
235 } | |
236 | |
208 #if defined (HAVE_FONTCONFIG) | 237 #if defined (HAVE_FONTCONFIG) |
209 if (fontconfig_initialized) | 238 if (name != "*" && fontconfig_initialized) |
210 { | 239 { |
211 int fc_weight, fc_angle; | 240 int fc_weight, fc_angle; |
212 | 241 |
213 if (weight == "bold") | 242 if (weight == "bold") |
214 fc_weight = FC_WEIGHT_BOLD; | 243 fc_weight = FC_WEIGHT_BOLD; |
228 | 257 |
229 FcPattern *pat = FcPatternCreate (); | 258 FcPattern *pat = FcPatternCreate (); |
230 | 259 |
231 FcPatternAddString (pat, FC_FAMILY, | 260 FcPatternAddString (pat, FC_FAMILY, |
232 (reinterpret_cast<const FcChar8 *> | 261 (reinterpret_cast<const FcChar8 *> |
233 (name == "*" ? "sans" : name.c_str ()))); | 262 (name.c_str ()))); |
234 | 263 |
235 FcPatternAddInteger (pat, FC_WEIGHT, fc_weight); | 264 FcPatternAddInteger (pat, FC_WEIGHT, fc_weight); |
236 FcPatternAddInteger (pat, FC_SLANT, fc_angle); | 265 FcPatternAddInteger (pat, FC_SLANT, fc_angle); |
237 FcPatternAddDouble (pat, FC_PIXEL_SIZE, size); | 266 FcPatternAddDouble (pat, FC_PIXEL_SIZE, size); |
238 | 267 |
252 | 281 |
253 FcPatternGetString (match, FC_FILE, 0, &tmp); | 282 FcPatternGetString (match, FC_FILE, 0, &tmp); |
254 file = reinterpret_cast<char *> (tmp); | 283 file = reinterpret_cast<char *> (tmp); |
255 } | 284 } |
256 else | 285 else |
257 ::warning ("could not match any font: %s-%s-%s-%g", | 286 ::warning ("could not match any font: %s-%s-%s-%g, using default font", |
258 name.c_str (), weight.c_str (), angle.c_str (), | 287 name.c_str (), weight.c_str (), angle.c_str (), |
259 size); | 288 size); |
260 | 289 |
261 if (match) | 290 if (match) |
262 FcPatternDestroy (match); | 291 FcPatternDestroy (match); |
265 FcPatternDestroy (pat); | 294 FcPatternDestroy (pat); |
266 } | 295 } |
267 #endif | 296 #endif |
268 | 297 |
269 if (file.empty ()) | 298 if (file.empty ()) |
270 { | 299 ::warning ("unable to find default font files"); |
271 #if defined (OCTAVE_USE_WINDOWS_API) | 300 else |
272 file = "C:/WINDOWS/Fonts/verdana.ttf"; | |
273 #else | |
274 // FIXME: find a "standard" font for UNIX platforms | |
275 #endif | |
276 } | |
277 | |
278 if (! file.empty ()) | |
279 { | 301 { |
280 if (FT_New_Face (library, file.c_str (), 0, &retval)) | 302 if (FT_New_Face (library, file.c_str (), 0, &retval)) |
281 ::warning ("ft_manager: unable to load font: %s", file.c_str ()); | 303 ::warning ("ft_manager: unable to load font: %s", file.c_str ()); |
282 #if defined (HAVE_FT_REFERENCE_FACE) | 304 #if defined (HAVE_FT_REFERENCE_FACE) |
283 else | 305 else |