2012-08-16 11:23:39 +00:00
|
|
|
/**
|
|
|
|
* \file LaTeXFonts.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Jürgen Spitzmüller
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "LaTeXFonts.h"
|
|
|
|
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "Lexer.h"
|
|
|
|
|
2012-08-18 07:58:19 +00:00
|
|
|
#include "frontends/alert.h"
|
|
|
|
|
2012-08-16 11:23:39 +00:00
|
|
|
#include "support/convert.h"
|
|
|
|
#include "support/debug.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "support/docstream.h"
|
2012-08-16 11:23:39 +00:00
|
|
|
#include "support/FileName.h"
|
|
|
|
#include "support/filetools.h"
|
2012-08-18 07:58:19 +00:00
|
|
|
#include "support/gettext.h"
|
2012-08-16 11:23:39 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace lyx::support;
|
|
|
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
LaTeXFonts latexfonts;
|
|
|
|
|
|
|
|
|
2012-09-22 08:59:53 +00:00
|
|
|
LaTeXFont LaTeXFont::altFont(docstring const & name)
|
2012-08-16 11:23:39 +00:00
|
|
|
{
|
2012-09-22 08:59:53 +00:00
|
|
|
return theLaTeXFonts().getAltFont(name);
|
2012-08-16 11:23:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-22 15:44:00 +00:00
|
|
|
bool LaTeXFont::available(bool ot1, bool nomath)
|
2012-08-16 11:23:39 +00:00
|
|
|
{
|
2012-09-22 15:44:00 +00:00
|
|
|
if (nomath && !nomathfont_.empty())
|
|
|
|
return altFont(nomathfont_).available(ot1, nomath);
|
|
|
|
else if (ot1 && !ot1font_.empty())
|
2012-09-22 08:59:53 +00:00
|
|
|
return (ot1font_ == "none") ?
|
2012-09-22 15:44:00 +00:00
|
|
|
true : altFont(ot1font_).available(ot1, nomath);
|
2020-05-04 18:05:44 +00:00
|
|
|
else if (required_.empty() && package_.empty())
|
2012-09-22 08:59:53 +00:00
|
|
|
return true;
|
2020-05-04 18:05:44 +00:00
|
|
|
else if (!required_.empty()
|
|
|
|
&& LaTeXFeatures::isAvailable(to_ascii(required_)))
|
2012-09-22 08:59:53 +00:00
|
|
|
return true;
|
2020-05-04 18:05:44 +00:00
|
|
|
else if (required_.empty() && !package_.empty()
|
2012-09-22 08:59:53 +00:00
|
|
|
&& LaTeXFeatures::isAvailable(to_ascii(package_)))
|
|
|
|
return true;
|
|
|
|
else if (!altfonts_.empty()) {
|
|
|
|
for (size_t i = 0; i < altfonts_.size(); ++i) {
|
2012-09-22 15:44:00 +00:00
|
|
|
if (altFont(altfonts_[i]).available(ot1, nomath))
|
2012-09-22 08:59:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-16 11:23:39 +00:00
|
|
|
|
|
|
|
|
2012-09-22 15:44:00 +00:00
|
|
|
bool LaTeXFont::providesNoMath(bool ot1, bool complete)
|
2012-09-22 08:59:53 +00:00
|
|
|
{
|
2020-07-09 09:39:43 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, false, false);
|
2012-09-22 08:59:53 +00:00
|
|
|
|
|
|
|
if (usedfont.empty())
|
|
|
|
return false;
|
|
|
|
else if (usedfont != name_)
|
2012-09-22 15:44:00 +00:00
|
|
|
return altFont(usedfont).providesNoMath(ot1, complete);
|
|
|
|
|
|
|
|
return (!nomathfont_.empty() && available(ot1, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LaTeXFont::providesOSF(bool ot1, bool complete, bool nomath)
|
|
|
|
{
|
2020-07-09 09:39:43 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath, false);
|
2012-09-22 15:44:00 +00:00
|
|
|
|
|
|
|
if (usedfont.empty())
|
|
|
|
return false;
|
|
|
|
else if (usedfont != name_)
|
|
|
|
return altFont(usedfont).providesOSF(ot1, complete, nomath);
|
2012-09-22 08:59:53 +00:00
|
|
|
else if (!osffont_.empty())
|
2012-09-22 15:44:00 +00:00
|
|
|
return altFont(osffont_).available(ot1, nomath);
|
2012-12-31 09:51:37 +00:00
|
|
|
else if (!available(ot1, nomath))
|
2012-08-16 11:23:39 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return (!osfoption_.empty() || !osfscoption_.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-22 15:44:00 +00:00
|
|
|
bool LaTeXFont::providesSC(bool ot1, bool complete, bool nomath)
|
2012-08-16 11:23:39 +00:00
|
|
|
{
|
2020-07-09 09:39:43 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath, false);
|
2012-08-16 11:23:39 +00:00
|
|
|
|
2012-09-22 08:59:53 +00:00
|
|
|
if (usedfont.empty())
|
|
|
|
return false;
|
|
|
|
else if (usedfont != name_)
|
2012-09-22 15:44:00 +00:00
|
|
|
return altFont(usedfont).providesSC(ot1, complete, nomath);
|
2012-12-31 09:51:37 +00:00
|
|
|
else if (!available(ot1, nomath))
|
2012-08-16 11:23:39 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return (!scoption_.empty() || !osfscoption_.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-11 14:02:24 +00:00
|
|
|
bool LaTeXFont::hasMonolithicExpertSet(bool ot1, bool complete, bool nomath)
|
|
|
|
{
|
2020-07-09 09:39:43 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath, false);
|
2013-02-11 14:02:24 +00:00
|
|
|
|
|
|
|
if (usedfont.empty())
|
|
|
|
return false;
|
|
|
|
else if (usedfont != name_)
|
|
|
|
return altFont(usedfont).hasMonolithicExpertSet(ot1, complete, nomath);
|
|
|
|
return (!osfoption_.empty() && !scoption_.empty() && osfoption_ == scoption_)
|
|
|
|
|| (osfoption_.empty() && scoption_.empty() && !osfscoption_.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-22 15:44:00 +00:00
|
|
|
bool LaTeXFont::providesScale(bool ot1, bool complete, bool nomath)
|
2012-08-16 11:23:39 +00:00
|
|
|
{
|
2020-07-09 09:39:43 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath, false);
|
2012-08-16 11:23:39 +00:00
|
|
|
|
2012-09-22 08:59:53 +00:00
|
|
|
if (usedfont.empty())
|
|
|
|
return false;
|
|
|
|
else if (usedfont != name_)
|
2012-09-22 15:44:00 +00:00
|
|
|
return altFont(usedfont).providesScale(ot1, complete, nomath);
|
2012-12-31 09:51:37 +00:00
|
|
|
else if (!available(ot1, nomath))
|
2012-08-16 11:23:39 +00:00
|
|
|
return false;
|
|
|
|
return (!scaleoption_.empty());
|
|
|
|
}
|
|
|
|
|
2019-07-13 12:55:07 +00:00
|
|
|
|
|
|
|
bool LaTeXFont::providesMoreOptions(bool ot1, bool complete, bool nomath)
|
|
|
|
{
|
2020-07-09 09:39:43 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath, false);
|
2019-07-13 12:55:07 +00:00
|
|
|
|
|
|
|
if (usedfont.empty())
|
|
|
|
return false;
|
|
|
|
else if (usedfont != name_)
|
|
|
|
return altFont(usedfont).providesMoreOptions(ot1, complete, nomath);
|
|
|
|
else if (!available(ot1, nomath))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (moreopts_);
|
|
|
|
}
|
|
|
|
|
2012-09-22 15:44:00 +00:00
|
|
|
bool LaTeXFont::provides(std::string const & name, bool ot1, bool complete, bool nomath)
|
2012-09-19 13:46:19 +00:00
|
|
|
{
|
2020-07-09 09:39:43 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath, false);
|
2012-09-22 08:59:53 +00:00
|
|
|
|
|
|
|
if (usedfont.empty())
|
2012-09-19 13:46:19 +00:00
|
|
|
return false;
|
2012-09-22 08:59:53 +00:00
|
|
|
else if (usedfont != name_)
|
2012-09-22 15:44:00 +00:00
|
|
|
return altFont(usedfont).provides(name, ot1, complete, nomath);
|
2012-09-22 08:59:53 +00:00
|
|
|
else if (provides_.empty())
|
|
|
|
return false;
|
|
|
|
|
2012-09-19 13:46:19 +00:00
|
|
|
for (size_t i = 0; i < provides_.size(); ++i) {
|
|
|
|
if (provides_[i] == name)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-16 11:23:39 +00:00
|
|
|
|
2020-07-09 09:39:43 +00:00
|
|
|
docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath, bool osf)
|
2012-08-16 11:23:39 +00:00
|
|
|
{
|
2020-07-09 09:39:43 +00:00
|
|
|
if (osf && osfFontOnly())
|
|
|
|
return osffont_;
|
|
|
|
else if (nomath && !nomathfont_.empty() && available(ot1, true))
|
2012-09-22 15:44:00 +00:00
|
|
|
return nomathfont_;
|
|
|
|
else if (ot1 && !ot1font_.empty())
|
2012-09-22 08:59:53 +00:00
|
|
|
return (ot1font_ == "none") ? docstring() : ot1font_;
|
|
|
|
else if (family_ == "rm" && complete && !completefont_.empty()
|
2012-09-22 15:44:00 +00:00
|
|
|
&& altFont(completefont_).available(ot1, nomath))
|
2012-09-22 08:59:53 +00:00
|
|
|
return completefont_;
|
|
|
|
else if (switchdefault_) {
|
2020-05-04 18:05:44 +00:00
|
|
|
if (required_.empty()
|
|
|
|
|| (!required_.empty()
|
|
|
|
&& LaTeXFeatures::isAvailable(to_ascii(required_))))
|
2012-09-22 08:59:53 +00:00
|
|
|
return name_;
|
2012-08-16 11:23:39 +00:00
|
|
|
}
|
2020-05-04 18:05:44 +00:00
|
|
|
else if (!required_.empty()
|
|
|
|
&& LaTeXFeatures::isAvailable(to_ascii(required_)))
|
2012-09-22 08:59:53 +00:00
|
|
|
return name_;
|
|
|
|
else if (!package_.empty()
|
|
|
|
&& LaTeXFeatures::isAvailable(to_ascii(package_)))
|
|
|
|
return name_;
|
2013-02-10 13:31:49 +00:00
|
|
|
else if (!preamble_.empty() && package_.empty()
|
2020-05-04 18:05:44 +00:00
|
|
|
&& required_.empty() && !switchdefault_
|
2013-02-10 13:31:49 +00:00
|
|
|
&& altfonts_.empty()) {
|
|
|
|
return name_;
|
|
|
|
}
|
2012-09-22 08:59:53 +00:00
|
|
|
else if (!altfonts_.empty()) {
|
|
|
|
for (size_t i = 0; i < altfonts_.size(); ++i) {
|
|
|
|
LaTeXFont altf = altFont(altfonts_[i]);
|
2012-09-22 15:44:00 +00:00
|
|
|
if (altf.available(ot1, nomath))
|
2020-07-09 09:39:43 +00:00
|
|
|
return altf.getUsedFont(ot1, complete, nomath, osf);
|
2012-08-16 11:23:39 +00:00
|
|
|
}
|
|
|
|
}
|
2012-09-22 08:59:53 +00:00
|
|
|
|
|
|
|
return docstring();
|
2012-08-16 11:23:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-01 08:21:21 +00:00
|
|
|
docstring const LaTeXFont::getUsedPackage(bool ot1, bool complete, bool nomath)
|
|
|
|
{
|
2020-07-09 09:39:43 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath, false);
|
2013-09-01 08:21:21 +00:00
|
|
|
if (usedfont.empty())
|
|
|
|
return docstring();
|
|
|
|
return theLaTeXFonts().getLaTeXFont(usedfont).package();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-22 08:59:53 +00:00
|
|
|
string const LaTeXFont::getAvailablePackage(bool dryrun)
|
2012-08-16 11:23:39 +00:00
|
|
|
{
|
2012-09-22 08:59:53 +00:00
|
|
|
if (package_.empty())
|
2012-08-16 11:23:39 +00:00
|
|
|
return string();
|
|
|
|
|
2012-09-22 08:59:53 +00:00
|
|
|
string const package = to_ascii(package_);
|
2020-05-04 18:05:44 +00:00
|
|
|
if (!required_.empty() && LaTeXFeatures::isAvailable(to_ascii(required_)))
|
2012-09-22 08:59:53 +00:00
|
|
|
return package;
|
|
|
|
else if (LaTeXFeatures::isAvailable(package))
|
|
|
|
return package;
|
|
|
|
// Output unavailable packages in source preview
|
|
|
|
else if (dryrun)
|
|
|
|
return package;
|
|
|
|
|
2020-05-04 18:05:44 +00:00
|
|
|
docstring const req = required_.empty() ? package_ : required_;
|
2012-09-22 08:59:53 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-22 15:44:00 +00:00
|
|
|
string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool sc, bool osf,
|
2019-09-13 14:23:49 +00:00
|
|
|
int scale, string const & extraopts, bool nomath)
|
2012-09-22 08:59:53 +00:00
|
|
|
{
|
2012-08-16 11:23:39 +00:00
|
|
|
ostringstream os;
|
2012-09-19 15:46:55 +00:00
|
|
|
bool const needosfopt = (osf != osfdefault_);
|
2012-09-22 15:44:00 +00:00
|
|
|
bool const has_osf = providesOSF(ot1, complete, nomath);
|
|
|
|
bool const has_sc = providesSC(ot1, complete, nomath);
|
2019-07-13 13:33:20 +00:00
|
|
|
bool const moreopts = providesMoreOptions(ot1, complete, nomath);
|
2012-09-22 08:59:53 +00:00
|
|
|
|
2019-07-17 19:16:05 +00:00
|
|
|
if (!packageoptions_.empty())
|
|
|
|
os << to_ascii(packageoptions_);
|
2012-09-22 08:59:53 +00:00
|
|
|
|
|
|
|
if (sc && needosfopt && has_osf && has_sc) {
|
2012-08-18 11:10:34 +00:00
|
|
|
if (!os.str().empty())
|
|
|
|
os << ',';
|
2012-08-16 11:23:39 +00:00
|
|
|
if (!osfscoption_.empty())
|
|
|
|
os << to_ascii(osfscoption_);
|
|
|
|
else
|
2012-09-22 08:59:53 +00:00
|
|
|
os << to_ascii(osfoption_)
|
|
|
|
<< ',' << to_ascii(scoption_);
|
|
|
|
} else if (needosfopt && has_osf) {
|
2012-08-18 11:29:14 +00:00
|
|
|
if (!os.str().empty())
|
|
|
|
os << ',';
|
2012-08-16 11:23:39 +00:00
|
|
|
os << to_ascii(osfoption_);
|
2012-09-22 08:59:53 +00:00
|
|
|
} else if (sc && has_sc) {
|
2012-08-18 11:29:14 +00:00
|
|
|
if (!os.str().empty())
|
|
|
|
os << ',';
|
2012-08-16 11:23:39 +00:00
|
|
|
os << to_ascii(scoption_);
|
2012-08-18 11:29:14 +00:00
|
|
|
}
|
2012-09-22 08:59:53 +00:00
|
|
|
|
|
|
|
if (scale != 100 && !scaleoption_.empty()
|
2012-09-22 15:44:00 +00:00
|
|
|
&& providesScale(ot1, complete, nomath)) {
|
2012-08-16 11:23:39 +00:00
|
|
|
if (!os.str().empty())
|
|
|
|
os << ',';
|
2014-07-12 17:52:12 +00:00
|
|
|
os << subst(to_ascii(scaleoption_), "$$val",
|
|
|
|
convert<std::string>(float(scale) / 100));
|
2012-08-16 11:23:39 +00:00
|
|
|
}
|
2019-07-11 18:28:34 +00:00
|
|
|
|
2019-07-13 13:33:20 +00:00
|
|
|
if (moreopts && !extraopts.empty()) {
|
2019-07-11 18:28:34 +00:00
|
|
|
if (!os.str().empty())
|
|
|
|
os << ',';
|
|
|
|
os << extraopts;
|
|
|
|
}
|
2012-08-16 11:23:39 +00:00
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-18 09:57:16 +00:00
|
|
|
string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool sc,
|
2019-09-13 14:23:49 +00:00
|
|
|
bool osf, bool nomath, string const & extraopts,
|
2019-07-11 18:28:34 +00:00
|
|
|
int const & scale)
|
2012-08-18 09:57:16 +00:00
|
|
|
{
|
|
|
|
ostringstream os;
|
|
|
|
|
2020-07-09 09:39:43 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath, osf);
|
2012-09-22 08:59:53 +00:00
|
|
|
if (usedfont.empty())
|
|
|
|
return string();
|
|
|
|
else if (usedfont != name_)
|
2019-07-11 18:28:34 +00:00
|
|
|
return altFont(usedfont).getLaTeXCode(dryrun, ot1, complete, sc,
|
|
|
|
osf, nomath, extraopts, scale);
|
2012-09-22 08:59:53 +00:00
|
|
|
|
2012-08-18 09:57:16 +00:00
|
|
|
if (switchdefault_) {
|
|
|
|
if (family_.empty()) {
|
|
|
|
LYXERR0("Error: Font `" << name_ << "' has no family defined!");
|
|
|
|
return string();
|
|
|
|
}
|
2012-09-22 15:44:00 +00:00
|
|
|
if (available(ot1, nomath) || dryrun)
|
2012-08-18 09:57:16 +00:00
|
|
|
os << "\\renewcommand{\\" << to_ascii(family_) << "default}{"
|
2012-09-22 08:59:53 +00:00
|
|
|
<< to_ascii(name_) << "}\n";
|
2012-08-18 09:57:16 +00:00
|
|
|
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."),
|
2020-05-04 18:05:44 +00:00
|
|
|
required_, guiname_), true);
|
2012-08-18 09:57:16 +00:00
|
|
|
} else {
|
|
|
|
string const package =
|
2012-09-22 08:59:53 +00:00
|
|
|
getAvailablePackage(dryrun);
|
2019-07-11 18:28:34 +00:00
|
|
|
string const packageopts = getPackageOptions(ot1, complete, sc, osf, scale, extraopts, nomath);
|
2012-08-18 09:57:16 +00:00
|
|
|
if (packageopts.empty() && !package.empty())
|
|
|
|
os << "\\usepackage{" << package << "}\n";
|
|
|
|
else if (!packageopts.empty() && !package.empty())
|
|
|
|
os << "\\usepackage[" << packageopts << "]{" << package << "}\n";
|
|
|
|
}
|
2012-09-22 15:44:00 +00:00
|
|
|
if (osf && providesOSF(ot1, complete, nomath) && !osffont_.empty())
|
2019-07-11 18:28:34 +00:00
|
|
|
os << altFont(osffont_).getLaTeXCode(dryrun, ot1, complete, sc, osf,
|
|
|
|
nomath, extraopts, scale);
|
2012-08-18 09:57:16 +00:00
|
|
|
|
2013-02-09 10:00:42 +00:00
|
|
|
if (!preamble_.empty())
|
2016-09-25 10:37:40 +00:00
|
|
|
os << to_utf8(preamble_);
|
2013-02-09 10:00:42 +00:00
|
|
|
|
2012-08-18 09:57:16 +00:00
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-22 17:06:46 +00:00
|
|
|
bool LaTeXFont::hasFontenc(string const & name) const
|
|
|
|
{
|
|
|
|
for (auto const & fe : fontenc_) {
|
|
|
|
if (fe == name)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-16 11:23:39 +00:00
|
|
|
bool LaTeXFont::readFont(Lexer & lex)
|
|
|
|
{
|
|
|
|
enum LaTeXFontTags {
|
2012-09-22 08:59:53 +00:00
|
|
|
LF_ALT_FONTS = 1,
|
|
|
|
LF_COMPLETE_FONT,
|
2012-08-16 11:23:39 +00:00
|
|
|
LF_END,
|
|
|
|
LF_FAMILY,
|
2018-04-22 17:06:46 +00:00
|
|
|
LF_FONTENC,
|
2012-08-16 11:23:39 +00:00
|
|
|
LF_GUINAME,
|
2012-09-22 15:44:00 +00:00
|
|
|
LF_NOMATHFONT,
|
2012-09-19 15:46:55 +00:00
|
|
|
LF_OSFDEFAULT,
|
2012-09-22 08:59:53 +00:00
|
|
|
LF_OSFFONT,
|
2020-07-09 09:39:43 +00:00
|
|
|
LF_OSFFONTONLY,
|
2012-08-16 11:23:39 +00:00
|
|
|
LF_OSFOPTION,
|
|
|
|
LF_OSFSCOPTION,
|
2012-09-22 08:59:53 +00:00
|
|
|
LF_OT1_FONT,
|
2019-07-11 18:28:34 +00:00
|
|
|
LF_MOREOPTS,
|
2012-08-16 11:23:39 +00:00
|
|
|
LF_PACKAGE,
|
2019-07-17 16:52:58 +00:00
|
|
|
LF_PACKAGEOPTIONS,
|
2013-02-09 10:00:42 +00:00
|
|
|
LF_PREAMBLE,
|
2012-09-19 13:46:19 +00:00
|
|
|
LF_PROVIDES,
|
2012-08-16 11:23:39 +00:00
|
|
|
LF_REQUIRES,
|
|
|
|
LF_SCALEOPTION,
|
|
|
|
LF_SCOPTION,
|
|
|
|
LF_SWITCHDEFAULT
|
|
|
|
};
|
|
|
|
|
|
|
|
// Keep these sorted alphabetically!
|
|
|
|
LexerKeyword latexFontTags[] = {
|
2012-09-22 08:59:53 +00:00
|
|
|
{ "altfonts", LF_ALT_FONTS },
|
|
|
|
{ "completefont", LF_COMPLETE_FONT },
|
2012-08-16 11:23:39 +00:00
|
|
|
{ "endfont", LF_END },
|
|
|
|
{ "family", LF_FAMILY },
|
2018-04-22 17:06:46 +00:00
|
|
|
{ "fontencoding", LF_FONTENC },
|
2012-08-16 11:23:39 +00:00
|
|
|
{ "guiname", LF_GUINAME },
|
2019-07-11 18:28:34 +00:00
|
|
|
{ "moreoptions", LF_MOREOPTS },
|
2012-09-22 15:44:00 +00:00
|
|
|
{ "nomathfont", LF_NOMATHFONT },
|
2012-09-19 15:46:55 +00:00
|
|
|
{ "osfdefault", LF_OSFDEFAULT },
|
2012-09-22 08:59:53 +00:00
|
|
|
{ "osffont", LF_OSFFONT },
|
2020-07-09 09:39:43 +00:00
|
|
|
{ "osffontonly", LF_OSFFONTONLY },
|
2012-08-16 11:23:39 +00:00
|
|
|
{ "osfoption", LF_OSFOPTION },
|
|
|
|
{ "osfscoption", LF_OSFSCOPTION },
|
2012-09-22 08:59:53 +00:00
|
|
|
{ "ot1font", LF_OT1_FONT },
|
2012-08-16 11:23:39 +00:00
|
|
|
{ "package", LF_PACKAGE },
|
2019-07-17 16:52:58 +00:00
|
|
|
{ "packageoptions", LF_PACKAGEOPTIONS },
|
2013-02-09 10:00:42 +00:00
|
|
|
{ "preamble", LF_PREAMBLE },
|
2012-09-19 13:46:19 +00:00
|
|
|
{ "provides", LF_PROVIDES },
|
2012-08-16 11:23:39 +00:00
|
|
|
{ "requires", LF_REQUIRES },
|
|
|
|
{ "scaleoption", LF_SCALEOPTION },
|
|
|
|
{ "scoption", LF_SCOPTION },
|
|
|
|
{ "switchdefault", LF_SWITCHDEFAULT }
|
|
|
|
};
|
|
|
|
|
|
|
|
bool error = false;
|
|
|
|
bool finished = false;
|
|
|
|
lex.pushTable(latexFontTags);
|
|
|
|
// parse style section
|
|
|
|
while (!finished && lex.isOK() && !error) {
|
|
|
|
int le = lex.lex();
|
|
|
|
// See comment in LyXRC.cpp.
|
|
|
|
switch (le) {
|
|
|
|
case Lexer::LEX_FEOF:
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case Lexer::LEX_UNDEF: // parse error
|
|
|
|
lex.printError("Unknown LaTeXFont tag `$$Token'");
|
|
|
|
error = true;
|
|
|
|
continue;
|
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
default:
|
2012-08-16 11:23:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (static_cast<LaTeXFontTags>(le)) {
|
|
|
|
case LF_END: // end of structure
|
|
|
|
finished = true;
|
|
|
|
break;
|
2012-09-22 08:59:53 +00:00
|
|
|
case LF_ALT_FONTS: {
|
2012-09-19 13:46:19 +00:00
|
|
|
lex.eatLine();
|
|
|
|
docstring altp = lex.getDocString();
|
2012-09-22 08:59:53 +00:00
|
|
|
altfonts_ = getVectorFromString(altp);
|
2012-08-16 11:23:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-09-22 08:59:53 +00:00
|
|
|
case LF_COMPLETE_FONT:
|
|
|
|
lex >> completefont_;
|
2012-08-16 11:23:39 +00:00
|
|
|
break;
|
|
|
|
case LF_FAMILY:
|
|
|
|
lex >> family_;
|
|
|
|
break;
|
|
|
|
case LF_GUINAME:
|
|
|
|
lex >> guiname_;
|
|
|
|
break;
|
2018-04-22 17:06:46 +00:00
|
|
|
case LF_FONTENC: {
|
|
|
|
lex.eatLine();
|
|
|
|
string fe = lex.getString();
|
|
|
|
fontenc_ = getVectorFromString(fe);
|
|
|
|
break;
|
|
|
|
}
|
2012-09-22 15:44:00 +00:00
|
|
|
case LF_NOMATHFONT:
|
|
|
|
lex >> nomathfont_;
|
|
|
|
break;
|
2012-08-16 11:23:39 +00:00
|
|
|
case LF_OSFOPTION:
|
|
|
|
lex >> osfoption_;
|
|
|
|
break;
|
2012-09-22 08:59:53 +00:00
|
|
|
case LF_OSFFONT:
|
|
|
|
lex >> osffont_;
|
2012-08-16 11:23:39 +00:00
|
|
|
break;
|
2012-09-19 15:46:55 +00:00
|
|
|
case LF_OSFDEFAULT:
|
|
|
|
lex >> osfdefault_;
|
|
|
|
break;
|
2020-07-09 09:39:43 +00:00
|
|
|
case LF_OSFFONTONLY:
|
|
|
|
lex >> osffontonly_;
|
|
|
|
break;
|
2012-08-16 11:23:39 +00:00
|
|
|
case LF_OSFSCOPTION:
|
|
|
|
lex >> osfscoption_;
|
|
|
|
break;
|
2012-09-22 08:59:53 +00:00
|
|
|
case LF_OT1_FONT:
|
|
|
|
lex >> ot1font_;
|
2012-08-16 11:23:39 +00:00
|
|
|
break;
|
|
|
|
case LF_PACKAGE:
|
|
|
|
lex >> package_;
|
|
|
|
break;
|
2019-07-17 16:52:58 +00:00
|
|
|
case LF_PACKAGEOPTIONS:
|
2019-07-17 19:16:05 +00:00
|
|
|
lex >> packageoptions_;
|
2012-08-18 11:10:34 +00:00
|
|
|
break;
|
2013-02-09 10:00:42 +00:00
|
|
|
case LF_PREAMBLE:
|
2016-09-25 10:37:40 +00:00
|
|
|
preamble_ = lex.getLongString(from_ascii("EndPreamble"));
|
2013-02-09 10:00:42 +00:00
|
|
|
break;
|
2012-09-19 13:46:19 +00:00
|
|
|
case LF_PROVIDES: {
|
|
|
|
lex.eatLine();
|
|
|
|
string features = lex.getString();
|
|
|
|
provides_ = getVectorFromString(features);
|
|
|
|
break;
|
|
|
|
}
|
2012-08-16 11:23:39 +00:00
|
|
|
case LF_REQUIRES:
|
2020-05-04 18:05:44 +00:00
|
|
|
lex >> required_;
|
2012-08-16 11:23:39 +00:00
|
|
|
break;
|
|
|
|
case LF_SCALEOPTION:
|
|
|
|
lex >> scaleoption_;
|
|
|
|
break;
|
|
|
|
case LF_SCOPTION:
|
|
|
|
lex >> scoption_;
|
|
|
|
break;
|
2019-07-11 18:28:34 +00:00
|
|
|
case LF_MOREOPTS:
|
|
|
|
lex >> moreopts_;
|
|
|
|
break;
|
2012-08-16 11:23:39 +00:00
|
|
|
case LF_SWITCHDEFAULT:
|
|
|
|
lex >> switchdefault_;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!finished) {
|
|
|
|
lex.printError("No End tag found for LaTeXFont tag `$$Token'");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
lex.popTable();
|
|
|
|
return finished && !error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LaTeXFont::read(Lexer & lex)
|
|
|
|
{
|
|
|
|
switchdefault_ = 0;
|
2012-09-19 15:46:55 +00:00
|
|
|
osfdefault_ = 0;
|
2019-07-11 18:28:34 +00:00
|
|
|
moreopts_ = 0;
|
2020-07-09 09:39:43 +00:00
|
|
|
osffontonly_ = 0;
|
2012-08-16 11:23:39 +00:00
|
|
|
|
|
|
|
if (!lex.next()) {
|
|
|
|
lex.printError("No name given for LaTeX font: `$$Token'.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
name_ = lex.getDocString();
|
|
|
|
LYXERR(Debug::INFO, "Reading LaTeX font " << name_);
|
|
|
|
if (!readFont(lex)) {
|
|
|
|
LYXERR0("Error parsing LaTeX font `" << name_ << '\'');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-22 17:06:46 +00:00
|
|
|
if (fontenc_.empty())
|
|
|
|
fontenc_.push_back("T1");
|
|
|
|
|
2012-08-16 11:23:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LaTeXFonts::readLaTeXFonts()
|
|
|
|
{
|
|
|
|
// Read latexfonts file
|
|
|
|
FileName filename = libFileSearch(string(), "latexfonts");
|
|
|
|
if (filename.empty()) {
|
|
|
|
LYXERR0("Error: latexfonts file not found!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Lexer lex;
|
|
|
|
lex.setFile(filename);
|
|
|
|
lex.setContext("LaTeXFeatures::readLaTeXFonts");
|
|
|
|
while (lex.isOK()) {
|
|
|
|
int le = lex.lex();
|
|
|
|
switch (le) {
|
|
|
|
case Lexer::LEX_FEOF:
|
|
|
|
continue;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-09-22 08:59:53 +00:00
|
|
|
string const type = lex.getString();
|
|
|
|
if (type != "Font" && type != "AltFont") {
|
2012-08-16 11:23:39 +00:00
|
|
|
lex.printError("Unknown LaTeXFont tag `$$Token'");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
LaTeXFont f;
|
|
|
|
f.read(lex);
|
|
|
|
if (!lex)
|
|
|
|
break;
|
|
|
|
|
2012-09-22 08:59:53 +00:00
|
|
|
if (type == "AltFont")
|
|
|
|
texaltfontmap_[f.name()] = f;
|
|
|
|
else
|
|
|
|
texfontmap_[f.name()] = f;
|
2012-08-16 11:23:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LaTeXFonts::TexFontMap LaTeXFonts::getLaTeXFonts()
|
|
|
|
{
|
|
|
|
if (texfontmap_.empty())
|
|
|
|
readLaTeXFonts();
|
|
|
|
return texfontmap_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LaTeXFont LaTeXFonts::getLaTeXFont(docstring const & name)
|
|
|
|
{
|
2012-09-22 15:44:00 +00:00
|
|
|
if (name == "default" || name == "auto")
|
2012-08-25 08:48:37 +00:00
|
|
|
return LaTeXFont();
|
2012-08-16 11:23:39 +00:00
|
|
|
if (texfontmap_.empty())
|
|
|
|
readLaTeXFonts();
|
2012-08-25 08:48:37 +00:00
|
|
|
if (texfontmap_.find(name) == texfontmap_.end()) {
|
|
|
|
LYXERR0("LaTeXFonts::getLaTeXFont: font '" << name << "' not found!");
|
|
|
|
return LaTeXFont();
|
|
|
|
}
|
2012-08-16 11:23:39 +00:00
|
|
|
return texfontmap_[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-22 08:59:53 +00:00
|
|
|
LaTeXFont LaTeXFonts::getAltFont(docstring const & name)
|
|
|
|
{
|
2012-09-22 15:44:00 +00:00
|
|
|
if (name == "default" || name == "auto")
|
2012-09-22 08:59:53 +00:00
|
|
|
return LaTeXFont();
|
|
|
|
if (texaltfontmap_.empty())
|
|
|
|
readLaTeXFonts();
|
|
|
|
if (texaltfontmap_.find(name) == texaltfontmap_.end()) {
|
|
|
|
LYXERR0("LaTeXFonts::getAltFont: alternative font '" << name << "' not found!");
|
|
|
|
return LaTeXFont();
|
|
|
|
}
|
|
|
|
return texaltfontmap_[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-16 11:23:39 +00:00
|
|
|
} // namespace lyx
|