mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-05 13:26:21 +00:00
Issue a warning if a LaTeX font is not available
Also output font in source preview notwithstanding availability.
This commit is contained in:
parent
292f48d6b5
commit
03943ef730
@ -2859,14 +2859,22 @@ string const BufferParams::loadFonts(string const & rm,
|
||||
|
||||
// Tex Fonts
|
||||
bool const ot1 = (font_encoding() == "default" || font_encoding() == "OT1");
|
||||
bool const dryrun = features.runparams().dryrun;
|
||||
|
||||
// ROMAN FONTS
|
||||
LaTeXFont roman = theLaTeXFonts().getLaTeXFont(from_ascii(rm));
|
||||
if (roman.switchdefault())
|
||||
os << "\\renewcommand{\\rmdefault}{" << to_ascii(roman.name()) << "}\n";
|
||||
else {
|
||||
if (roman.switchdefault()) {
|
||||
if (roman.available(ot1) || dryrun)
|
||||
os << "\\renewcommand{\\rmdefault}{" << to_ascii(roman.name()) << "}\n";
|
||||
else
|
||||
frontend::Alert::warning(_("Font not available"),
|
||||
bformat(_("The LaTeX package `%1$s' needed for the font `%2$s'\n"
|
||||
"is not available on your system. LyX will fall back to the default font."),
|
||||
roman.requires(), roman.guiname()), true);
|
||||
} else {
|
||||
bool const complete = (sf == "default" && tt == "default");
|
||||
string const package = roman.getAvailablePackage(ot1, complete);
|
||||
string const package =
|
||||
roman.getAvailablePackage(dryrun, ot1, complete);
|
||||
string const packageopts = roman.getPackageOptions(ot1, sc, osf);
|
||||
if (packageopts.empty() && !package.empty())
|
||||
os << "\\usepackage{" << package << "}\n";
|
||||
@ -2878,10 +2886,16 @@ string const BufferParams::loadFonts(string const & rm,
|
||||
|
||||
// SANS SERIF
|
||||
LaTeXFont sans = theLaTeXFonts().getLaTeXFont(from_ascii(sf));
|
||||
if (sans.switchdefault())
|
||||
os << "\\renewcommand{\\sfdefault}{" << to_ascii(sans.name()) << "}\n";
|
||||
else {
|
||||
string const package = sans.getAvailablePackage(ot1);
|
||||
if (sans.switchdefault()) {
|
||||
if (sans.available(ot1) || dryrun)
|
||||
os << "\\renewcommand{\\sfdefault}{" << to_ascii(sans.name()) << "}\n";
|
||||
else
|
||||
frontend::Alert::warning(_("Font not available"),
|
||||
bformat(_("The LaTeX package `%1$s' needed for the font `%2$s'\n"
|
||||
"is not available on your system. LyX will fall back to the default font."),
|
||||
sans.requires(), sans.guiname()), true);
|
||||
} else {
|
||||
string const package = sans.getAvailablePackage(dryrun, ot1);
|
||||
string const packageopts = sans.getPackageOptions(ot1, sc, osf, sfscale);
|
||||
if (packageopts.empty() && !package.empty())
|
||||
os << "\\usepackage{" << package << "}\n";
|
||||
@ -2891,10 +2905,16 @@ string const BufferParams::loadFonts(string const & rm,
|
||||
|
||||
// MONOSPACED/TYPEWRITER
|
||||
LaTeXFont mono = theLaTeXFonts().getLaTeXFont(from_ascii(tt));
|
||||
if (mono.switchdefault())
|
||||
os << "\\renewcommand{\\ttdefault}{" << to_ascii(mono.name()) << "}\n";
|
||||
else {
|
||||
string const package = mono.getAvailablePackage(ot1);
|
||||
if (mono.switchdefault()) {
|
||||
if (mono.available(ot1) || dryrun)
|
||||
os << "\\renewcommand{\\ttdefault}{" << to_ascii(mono.name()) << "}\n";
|
||||
else
|
||||
frontend::Alert::warning(_("Font not available"),
|
||||
bformat(_("The LaTeX package `%1$s' needed for the font `%2$s'\n"
|
||||
"is not available on your system. LyX will fall back to the default font."),
|
||||
mono.requires(), mono.guiname()), true);
|
||||
} else {
|
||||
string const package = mono.getAvailablePackage(dryrun, ot1);
|
||||
string const packageopts = mono.getPackageOptions(ot1, sc, osf, ttscale);
|
||||
if (packageopts.empty() && !package.empty())
|
||||
os << "\\usepackage{" << package << "}\n";
|
||||
|
@ -15,10 +15,13 @@
|
||||
#include "LaTeXFeatures.h"
|
||||
#include "Lexer.h"
|
||||
|
||||
#include "frontends/alert.h"
|
||||
|
||||
#include "support/convert.h"
|
||||
#include "support/debug.h"
|
||||
#include "support/FileName.h"
|
||||
#include "support/filetools.h"
|
||||
#include "support/gettext.h"
|
||||
#include "support/lstrings.h"
|
||||
|
||||
|
||||
@ -76,15 +79,22 @@ bool LaTeXFont::providesScale(bool ot1) const
|
||||
}
|
||||
|
||||
|
||||
string const LaTeXFont::getAvailablePackage(bool ot1, bool complete)
|
||||
string const LaTeXFont::getAvailablePackage(bool dryrun, bool ot1, bool complete)
|
||||
{
|
||||
if (ot1 && !ot1package_.empty()) {
|
||||
if (ot1package_ != "none" && LaTeXFeatures::isAvailable(to_ascii(ot1package_)))
|
||||
if (ot1package_ != "none"
|
||||
&& (LaTeXFeatures::isAvailable(to_ascii(ot1package_)) || dryrun))
|
||||
return to_ascii(ot1package_);
|
||||
if (!dryrun && ot1package_ != "none")
|
||||
frontend::Alert::warning(_("Font not available"),
|
||||
bformat(_("The LaTeX package `%1$s' needed for the font `%2$s'\n"
|
||||
"is not available on your system. LyX will fall back to the default font."),
|
||||
ot1package_, guiname_), true);
|
||||
return string();
|
||||
}
|
||||
docstring dryrunpackage;
|
||||
if (complete && !completepackage_.empty()) {
|
||||
if (LaTeXFeatures::isAvailable(to_ascii(completepackage_)))
|
||||
if (LaTeXFeatures::isAvailable(to_ascii(completepackage_)) || dryrun)
|
||||
return to_ascii(completepackage_);
|
||||
}
|
||||
if (!package_.empty()) {
|
||||
@ -98,6 +108,14 @@ string const LaTeXFont::getAvailablePackage(bool ot1, bool complete)
|
||||
return to_ascii(altpackages_[i]);
|
||||
}
|
||||
}
|
||||
// Output unavailable packages in source preview
|
||||
if (dryrun)
|
||||
return to_ascii(package_);
|
||||
docstring const req = requires_.empty() ? package_ : requires_;
|
||||
frontend::Alert::warning(_("Font not available"),
|
||||
bformat(_("The LaTeX package `%1$s' needed for the font `%2$s'\n"
|
||||
"is not available on your system. LyX will fall back to the default font."),
|
||||
req, guiname_), true);
|
||||
}
|
||||
return string();
|
||||
}
|
||||
|
@ -64,7 +64,9 @@ public:
|
||||
/// Does this font provide scaling?
|
||||
bool providesScale(bool ot1 = false) const;
|
||||
/// Return the preferred available package
|
||||
std::string const getAvailablePackage(bool ot1 = false, bool complete = false);
|
||||
std::string const getAvailablePackage(bool dryrun = false,
|
||||
bool ot1 = false,
|
||||
bool complete = false);
|
||||
/// Return the package options
|
||||
std::string const getPackageOptions(bool const & ot1,
|
||||
bool const & sc,
|
||||
|
Loading…
Reference in New Issue
Block a user