Mercurial > jwe > octave
changeset 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 | ed746cbfce24 |
children | b188be2b962b |
files | etc/fonts/FreeSans.otf etc/fonts/FreeSansBold.otf etc/fonts/FreeSansBoldOblique.otf etc/fonts/FreeSansOblique.otf etc/module.mk libinterp/corefcn/ft-text-renderer.cc run-octave.in |
diffstat | 7 files changed, 46 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/etc/module.mk Thu Oct 05 17:45:58 2017 -0400 +++ b/etc/module.mk Tue Oct 03 11:11:21 2017 +0200 @@ -21,6 +21,17 @@ %reldir%/OLD-ChangeLogs/src-ChangeLog \ %reldir%/OLD-ChangeLogs/test-ChangeLog +etc_fontsdir = $(octetcdir)/fonts + +etc_fonts_DATA = \ + %reldir%/fonts/FreeSans.otf \ + %reldir%/fonts/FreeSansBold.otf \ + %reldir%/fonts/FreeSansBoldOblique.otf \ + %reldir%/fonts/FreeSansOblique.otf + +%canon_reldir%_EXTRA_DIST += \ + $(etc_fonts_DATA) + icon_IMAGE_FILES = \ %reldir%/icons/octave-logo.svg \ %reldir%/icons/octave-sombrero.png
--- a/libinterp/corefcn/ft-text-renderer.cc Thu Oct 05 17:45:58 2017 -0400 +++ b/libinterp/corefcn/ft-text-renderer.cc Tue Oct 03 11:11:21 2017 +0200 @@ -54,7 +54,10 @@ #include "singleton-cleanup.h" +#include "defaults.h" #include "error.h" +#include "file-ops.h" +#include "oct-env.h" #include "pr-output.h" #include "text-renderer.h" @@ -203,10 +206,36 @@ } #endif + static std::string font_dir; + + if (font_dir.empty ()) + { + font_dir = sys::env::getenv ("OCTAVE_FONT_DIR"); + + if (font_dir.empty ()) + font_dir = config::oct_etc_dir () + sys::file_ops::dir_sep_str () + + "fonts"; + } + + + // Default font file std::string file; + if (! font_dir.empty ()) + { + file = font_dir + octave::sys::file_ops::dir_sep_str () + "FreeSans"; + + if (weight == "bold") + file += "Bold"; + + if (angle == "italic" || angle == "oblique") + file += "Oblique"; + + file += ".otf"; + } + #if defined (HAVE_FONTCONFIG) - if (fontconfig_initialized) + if (name != "*" && fontconfig_initialized) { int fc_weight, fc_angle; @@ -230,7 +259,7 @@ FcPatternAddString (pat, FC_FAMILY, (reinterpret_cast<const FcChar8 *> - (name == "*" ? "sans" : name.c_str ()))); + (name.c_str ()))); FcPatternAddInteger (pat, FC_WEIGHT, fc_weight); FcPatternAddInteger (pat, FC_SLANT, fc_angle); @@ -254,7 +283,7 @@ file = reinterpret_cast<char *> (tmp); } else - ::warning ("could not match any font: %s-%s-%s-%g", + ::warning ("could not match any font: %s-%s-%s-%g, using default font", name.c_str (), weight.c_str (), angle.c_str (), size); @@ -267,15 +296,8 @@ #endif if (file.empty ()) - { -#if defined (OCTAVE_USE_WINDOWS_API) - file = "C:/WINDOWS/Fonts/verdana.ttf"; -#else - // FIXME: find a "standard" font for UNIX platforms -#endif - } - - if (! file.empty ()) + ::warning ("unable to find default font files"); + else { if (FT_New_Face (library, file.c_str (), 0, &retval)) ::warning ("ft_manager: unable to load font: %s", file.c_str ());
--- a/run-octave.in Thu Oct 05 17:45:58 2017 -0400 +++ b/run-octave.in Tue Oct 03 11:11:21 2017 +0200 @@ -104,6 +104,7 @@ OCTAVE_ARCHLIBDIR="$builddir/src"; export OCTAVE_ARCHLIBDIR OCTAVE_BINDIR="$builddir/src"; export OCTAVE_BINDIR OCTAVE_DEFAULT_QT_SETTINGS="$builddir/libgui/default-qt-settings"; export OCTAVE_DEFAULT_QT_SETTINGS +OCTAVE_FONT_DIR="$top_srcdir/etc/fonts"; export OCTAVE_FONT_DIR OCTAVE_JAVA_DIR="$builddir/scripts/java"; export OCTAVE_JAVA_DIR OCTAVE_LOCALE_DIR="$builddir/libgui/languages"; export OCTAVE_LOCALE_DIR OCTAVE_SITE_INITFILE="$top_srcdir/scripts/startup/site-rcfile"; export OCTAVE_SITE_INITFILE