Mercurial > octave
changeset 31293:17c8048a187b
doc: use a default monospace font in Qt doc browser (bug #63204)
* octave.css: Add FreeMono to the font stack for code blocks.
* FreeMono.otf, FreeMonoBold.otf, FreeMonoBoldOblique.otf, FreeMonoOblique.otf:
Add fonts to be distributed with Octave.
* etc/module.mk: Add new fonts to distribution.
* documentation.cc (documentation_browser::documentation_browser): Check
whether one of the monospace fonts listed in octave.css can be found by Qt.
If not, load the default FreeMono.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Wed, 12 Oct 2022 22:58:52 +0200 |
parents | 7713b2b5084b |
children | f21b233f3274 |
files | doc/interpreter/octave.css etc/fonts/FreeMono.otf etc/fonts/FreeMonoBold.otf etc/fonts/FreeMonoBoldOblique.otf etc/fonts/FreeMonoOblique.otf etc/module.mk libgui/src/documentation.cc |
diffstat | 7 files changed, 44 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/interpreter/octave.css Wed Oct 12 19:45:48 2022 +0200 +++ b/doc/interpreter/octave.css Wed Oct 12 22:58:52 2022 +0200 @@ -65,7 +65,7 @@ /* Import web font Fantasque Sans Mono, Font Library Version 2016-04-05 */ @font-face { - font-family: 'Fantasque Sans Mono', 'Courier New', Cousine, Courier, monospace; + font-family: 'Fantasque Sans Mono', FreeMono, 'Courier New', Cousine, Courier, monospace; src: local('Fantasque Sans Mono Bold'), local('FantasqueSansMono-Bold'), url('https://fontlibrary.org/assets/fonts/fantasque-sans-mono/b0cbb25e73a9f8354e96d89524f613e7/a46033d3a07d9385620dc83b7655203f/FantasqueSansMonoBold.ttf') format('truetype'); @@ -75,7 +75,7 @@ @font-face { - font-family: 'Fantasque Sans Mono', 'Courier New', Cousine, Courier, 'monospace'; + font-family: 'Fantasque Sans Mono', FreeMono, 'Courier New', Cousine, Courier, 'monospace'; src: local('Fantasque Sans Mono Bold Italic'), local('FantasqueSansMono-BoldItalic'), url('https://fontlibrary.org/assets/fonts/fantasque-sans-mono/b0cbb25e73a9f8354e96d89524f613e7/b0683ef4c834908aa372ec78dea42349/FantasqueSansMonoBoldItalic.ttf') format('truetype'); @@ -85,7 +85,7 @@ @font-face { - font-family: 'Fantasque Sans Mono', 'Courier New', Cousine, Courier, monospace; + font-family: 'Fantasque Sans Mono', FreeMono, 'Courier New', Cousine, Courier, monospace; src: local('Fantasque Sans Mono Italic'), local('FantasqueSansMono-Italic'), url('https://fontlibrary.org/assets/fonts/fantasque-sans-mono/b0cbb25e73a9f8354e96d89524f613e7/b78d0a48e4443f797e8d45dcf97594f7/FantasqueSansMonoItalic.ttf') format('truetype'); @@ -95,7 +95,7 @@ @font-face { - font-family: 'Fantasque Sans Mono', 'Courier New', Cousine, Courier, monospace; + font-family: 'Fantasque Sans Mono', FreeMono, 'Courier New', Cousine, Courier, monospace; src: local('Fantasque Sans Mono Regular'), local('FantasqueSansMono-Regular'), url('https://fontlibrary.org/assets/fonts/fantasque-sans-mono/b0cbb25e73a9f8354e96d89524f613e7/f3fdc4f0f26e4431f54e8b552d55480c/FantasqueSansMonoRegular.ttf') format('truetype'); @@ -104,7 +104,7 @@ } /* Use custom fonts */ -code, kbd, samp, tt, pre { font-family: 'Fantasque Sans Mono', 'Courier New', Cousine, Courier, monospace; } +code, kbd, samp, tt, pre { font-family: 'Fantasque Sans Mono', FreeMono, 'Courier New', Cousine, Courier, monospace; } code, kbd, samp, tt { font-style: italic;
--- a/etc/module.mk Wed Oct 12 19:45:48 2022 +0200 +++ b/etc/module.mk Wed Oct 12 22:58:52 2022 +0200 @@ -26,6 +26,10 @@ %reldir%/OLD-ChangeLogs/test-ChangeLog fallback_FONT_FILES = \ + %reldir%/fonts/FreeMono.otf \ + %reldir%/fonts/FreeMonoBold.otf \ + %reldir%/fonts/FreeMonoBoldOblique.otf \ + %reldir%/fonts/FreeMonoOblique.otf \ %reldir%/fonts/FreeSans.otf \ %reldir%/fonts/FreeSansBold.otf \ %reldir%/fonts/FreeSansBoldOblique.otf \
--- a/libgui/src/documentation.cc Wed Oct 12 19:45:48 2022 +0200 +++ b/libgui/src/documentation.cc Wed Oct 12 22:58:52 2022 +0200 @@ -34,6 +34,7 @@ #include <QDir> #include <QFile> #include <QFileInfo> +#include <QFontDatabase> #include <QHelpContentWidget> #include <QHelpIndexWidget> #if defined (HAVE_NEW_QHELPINDEXWIDGET_API) \ @@ -995,6 +996,40 @@ setOpenLinks (false); connect (this, &documentation_browser::anchorClicked, this, [=] (const QUrl& url) { handle_index_clicked (url); }); + + // Make sure we have access to one of the monospace fonts listed in + // octave.css for rendering formated code blocks + QStringList fonts = {"Fantasque Sans Mono", "FreeMono", "Courier New", + "Cousine", "Courier"}; + + bool load_default_font = true; + + for (int i = 0; i < fonts.size (); ++i) + { + QFont font (fonts.at (i)); + if (font.exactMatch ()) + { + load_default_font = false; + break; + } + } + + if (load_default_font) + { + QString fonts_dir = + QString::fromStdString (sys::env::getenv ("OCTAVE_FONTS_DIR") + + sys::file_ops::dir_sep_str ()); + + QStringList default_fonts = {"FreeMono", "FreeMonoBold", + "FreeMonoBoldOblique", "FreeMonoOblique"}; + + for (int i = 0; i < default_fonts.size (); ++i) + { + QString fontpath = + fonts_dir + default_fonts.at(i) + QString (".otf"); + QFontDatabase::addApplicationFont (fontpath); + } + } } void documentation_browser::handle_index_clicked (const QUrl& url,