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"
|
|
|
|
#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);
|
2012-09-22 08:59:53 +00:00
|
|
|
else if (requires_.empty() && package_.empty())
|
|
|
|
return true;
|
|
|
|
else if (!requires_.empty()
|
|
|
|
&& LaTeXFeatures::isAvailable(to_ascii(requires_)))
|
|
|
|
return true;
|
2012-09-24 06:41:44 +00:00
|
|
|
else if (requires_.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
|
|
|
{
|
2012-09-22 15:44:00 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, 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)
|
|
|
|
{
|
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath);
|
|
|
|
|
|
|
|
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-09-22 08:59:53 +00:00
|
|
|
else if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_)))
|
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
|
|
|
{
|
2012-09-22 15:44:00 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath);
|
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-09-22 08:59:53 +00:00
|
|
|
else if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_)))
|
2012-08-16 11:23:39 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return (!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
|
|
|
{
|
2012-09-22 15:44:00 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath);
|
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-09-22 08:59:53 +00:00
|
|
|
else if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_)))
|
2012-08-16 11:23:39 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return (!scaleoption_.empty());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-09-22 15:44:00 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath);
|
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
|
|
|
|
2012-09-22 15:44:00 +00:00
|
|
|
docstring const LaTeXFont::getUsedFont(bool ot1, bool complete, bool nomath)
|
2012-08-16 11:23:39 +00:00
|
|
|
{
|
2012-09-22 15:44:00 +00:00
|
|
|
if (nomath && !nomathfont_.empty() && available(ot1, true))
|
|
|
|
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_) {
|
|
|
|
if (requires_.empty()
|
|
|
|
|| (!requires_.empty()
|
|
|
|
&& LaTeXFeatures::isAvailable(to_ascii(requires_))))
|
|
|
|
return name_;
|
2012-08-16 11:23:39 +00:00
|
|
|
}
|
2012-09-22 08:59:53 +00:00
|
|
|
else if (!requires_.empty()
|
|
|
|
&& LaTeXFeatures::isAvailable(to_ascii(requires_)))
|
|
|
|
return name_;
|
|
|
|
else if (!package_.empty()
|
|
|
|
&& LaTeXFeatures::isAvailable(to_ascii(package_)))
|
|
|
|
return name_;
|
|
|
|
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))
|
|
|
|
return altf.getUsedFont(ot1, complete, nomath);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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_);
|
|
|
|
if (!requires_.empty() && LaTeXFeatures::isAvailable(to_ascii(requires_)))
|
|
|
|
return package;
|
|
|
|
else if (LaTeXFeatures::isAvailable(package))
|
|
|
|
return package;
|
|
|
|
// Output unavailable packages in source preview
|
|
|
|
else if (dryrun)
|
|
|
|
return 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-22 15:44:00 +00:00
|
|
|
string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool sc, bool osf,
|
|
|
|
int scale, 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);
|
2012-09-22 08:59:53 +00:00
|
|
|
|
2012-08-18 11:10:34 +00:00
|
|
|
if (!packageoption_.empty())
|
|
|
|
os << to_ascii(packageoption_);
|
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 << ',';
|
|
|
|
os << subst(to_ascii(scaleoption_), "$$val",
|
|
|
|
convert<std::string>(float(scale) / 100));
|
|
|
|
}
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-18 09:57:16 +00:00
|
|
|
string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool sc,
|
2012-09-22 15:44:00 +00:00
|
|
|
bool osf, bool nomath, int const & scale)
|
2012-08-18 09:57:16 +00:00
|
|
|
{
|
|
|
|
ostringstream os;
|
|
|
|
|
2012-09-22 15:44:00 +00:00
|
|
|
docstring const usedfont = getUsedFont(ot1, complete, nomath);
|
2012-09-22 08:59:53 +00:00
|
|
|
if (usedfont.empty())
|
|
|
|
return string();
|
|
|
|
else if (usedfont != name_)
|
2012-09-22 15:44:00 +00:00
|
|
|
return altFont(usedfont).getLaTeXCode(dryrun, ot1, complete, sc, osf, nomath, 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."),
|
|
|
|
requires_, guiname_), true);
|
|
|
|
} else {
|
|
|
|
string const package =
|
2012-09-22 08:59:53 +00:00
|
|
|
getAvailablePackage(dryrun);
|
2012-09-22 15:44:00 +00:00
|
|
|
string const packageopts = getPackageOptions(ot1, complete, sc, osf, scale, 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())
|
|
|
|
os << altFont(osffont_).getLaTeXCode(dryrun, ot1, complete, sc, osf, nomath, scale);
|
2012-08-18 09:57:16 +00:00
|
|
|
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
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,
|
2012-08-16 11:23:39 +00:00
|
|
|
LF_OSFOPTION,
|
|
|
|
LF_OSFSCOPTION,
|
2012-09-22 08:59:53 +00:00
|
|
|
LF_OT1_FONT,
|
2012-08-16 11:23:39 +00:00
|
|
|
LF_PACKAGE,
|
2012-08-18 11:10:34 +00:00
|
|
|
LF_PACKAGEOPTION,
|
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 },
|
|
|
|
{ "guiname", LF_GUINAME },
|
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 },
|
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 },
|
2012-08-18 11:10:34 +00:00
|
|
|
{ "packageoption", LF_PACKAGEOPTION },
|
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;
|
|
|
|
|
|
|
|
default:
|
|
|
|
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;
|
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;
|
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;
|
2012-08-18 11:10:34 +00:00
|
|
|
case LF_PACKAGEOPTION:
|
|
|
|
lex >> packageoption_;
|
|
|
|
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:
|
|
|
|
lex >> requires_;
|
|
|
|
break;
|
|
|
|
case LF_SCALEOPTION:
|
|
|
|
lex >> scaleoption_;
|
|
|
|
break;
|
|
|
|
case LF_SCOPTION:
|
|
|
|
lex >> scoption_;
|
|
|
|
break;
|
|
|
|
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;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|