mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Much more flexible implementation of alternative (LaTeX) fonts
The LaTeX font now do not specify simply alternative packages or packages for OT1 encoding etc., but they refer to complete AltFonts (which are not directly accessible via the GUI). This way, alternative fonts can also have options (osf, sc etc.), and they can use all sorts of initializing methods (\usepackage, \setrmfamily etc.).
This commit is contained in:
parent
b1a409be97
commit
a5151c92a9
@ -10,11 +10,12 @@
|
||||
# SwitchDefault <0|1>
|
||||
# Package <LaTeX package to be loaded>
|
||||
# Requires <LaTeX package to test for>
|
||||
# AltPackages <alternative packages (comma-separated)>
|
||||
# OT1Package <alternative package specifically for OT1 encoding>
|
||||
# CompletePackage <alternative package for the complete family>
|
||||
# AltFonts <alternative fonts (comma-separated)>
|
||||
# OT1Font <alternative font specifically for OT1 encoding>
|
||||
# CompleteFont <alternative package for the complete family>
|
||||
# PackageOptions <general options to be passed to the package>
|
||||
# OsfOption <option for oldstyle figure support>
|
||||
# OsfFont <extra font for oldstyle figures>
|
||||
# OsfDefault <0|1>
|
||||
# ScOption <option for true smallcaps support>
|
||||
# OsfScOption <option for combined osf and true smallcaps support>
|
||||
@ -33,23 +34,30 @@
|
||||
# Package <package> loads it via \usepackage{package}. Only one of these
|
||||
# options is used per font (SwitchDefault takes precendende). Note that
|
||||
# SwitchDefault uses the font name.
|
||||
# * If AltPackages are defined, LyX will try to load them in the defined
|
||||
# * In addition to normal fonts, you can also define alternative fonts
|
||||
# using the AltFont...EndFont tags. These alternative fonts will not
|
||||
# be added to the GUI, but LyX will fall back on them under specific
|
||||
# circumstances (e.g. if the main font is not available; see below).
|
||||
# * If AltFonts are defined, LyX will try to load them in the defined
|
||||
# order if the main package is not available. So
|
||||
# Package mathptmx
|
||||
# AltPackages mathptm,times
|
||||
# AltFonts mathptm,times
|
||||
# will try to load mathptm if mathptmx is not available and then times
|
||||
# if mathptm is not available either.
|
||||
# No options will be passed to alternative packages!
|
||||
# AltFonts need to be defined separately using AltFont ... EndFont tags.
|
||||
# * If Requires is set, LyX will check for this. If not, it will check
|
||||
# for Package and AltPackages.
|
||||
# * OT1Package will load the defined package instead of the default
|
||||
# package if the font encoding is OT1. This is necessary since some
|
||||
# newer packages for a font do not support this encoding.
|
||||
# for Package and AltFonts.
|
||||
# * OT1Font will load the defined font if the font encoding is OT1. This is
|
||||
# necessary since some newer font packages do not support this encoding.
|
||||
# The value "none" tells LyX not to load a package in OT1 encoding.
|
||||
# No options will be passed to OT1 packages!
|
||||
# * CompletePackage is a package that is loaded if the current font is
|
||||
# selected as rm and both sf and tt are set to "default" (this allows
|
||||
# f. ex. to load "bera" as opposed to "beraserif").
|
||||
# OT1Fonts need to be defined separately using AltFont ... EndFont tags.
|
||||
# * The CompleteFont is loaded if the current font is selected as rm and
|
||||
# both sf and tt are set to "default" (this allows f. ex. to load "bera"
|
||||
# as opposed to "beraserif").
|
||||
# CompleteFonts need to be defined separately using AltFont ... EndFont
|
||||
# tags.
|
||||
# * OsfFont is a font that is loaded additionally in and that provides
|
||||
# Old Style Figures for a given font (e.g. eco).
|
||||
# * OsfScOption overrides any OsfOption and ScOption if both features
|
||||
# are selected.
|
||||
# * Set OsfDefault to true for fonts which have Old Style Figures by
|
||||
@ -67,7 +75,7 @@ Font ae
|
||||
GuiName "AE (Almost European)"
|
||||
Family rm
|
||||
Package "ae,aecompl"
|
||||
OT1Package none
|
||||
OT1Font none
|
||||
Requires ae
|
||||
EndFont
|
||||
|
||||
@ -75,10 +83,16 @@ Font beraserif
|
||||
GuiName "Bera Serif"
|
||||
Family rm
|
||||
Package beraserif
|
||||
CompletePackage bera
|
||||
CompleteFont bera
|
||||
Requires bera
|
||||
EndFont
|
||||
|
||||
AltFont bera
|
||||
GuiName "Bera Serif"
|
||||
Family rm
|
||||
Package bera
|
||||
EndFont
|
||||
|
||||
Font bookman
|
||||
GuiName "Bookman"
|
||||
Family rm
|
||||
@ -107,7 +121,12 @@ Font cmr
|
||||
GuiName "Computer Modern Roman"
|
||||
Family rm
|
||||
SwitchDefault 1
|
||||
OsfPackage eco
|
||||
OsfFont eco
|
||||
EndFont
|
||||
|
||||
AltFont eco
|
||||
Family rm
|
||||
Package eco
|
||||
EndFont
|
||||
|
||||
Font libertine
|
||||
@ -181,18 +200,42 @@ Font palatino
|
||||
ScOption sc
|
||||
OsfScOption osf
|
||||
Package mathpazo
|
||||
AltPackages "mathpple,palatino"
|
||||
AltFonts mathpple,palatino
|
||||
Requires psnfss
|
||||
EndFont
|
||||
|
||||
AltFont mathpple
|
||||
GuiName "Palatino"
|
||||
Family rm
|
||||
Package mathpple
|
||||
EndFont
|
||||
|
||||
AltFont palatino
|
||||
GuiName "Palatino"
|
||||
Family rm
|
||||
Package palatino
|
||||
EndFont
|
||||
|
||||
Font times
|
||||
GuiName "Times Roman"
|
||||
Family rm
|
||||
Package mathptmx
|
||||
AltPackages "mathptm,times"
|
||||
AltFonts mathptm,times
|
||||
Requires psnfss
|
||||
EndFont
|
||||
|
||||
AltFont mathptm
|
||||
GuiName "Times Roman"
|
||||
Family rm
|
||||
Package mathptm
|
||||
EndFont
|
||||
|
||||
AltFont times
|
||||
GuiName "Times Roman"
|
||||
Family rm
|
||||
Package times
|
||||
EndFont
|
||||
|
||||
Font tgbonum
|
||||
GuiName "TeX Gyre Bonum"
|
||||
Family rm
|
||||
@ -231,8 +274,14 @@ Font utopia
|
||||
OsfOption oldstyle
|
||||
ScOption expert
|
||||
Package fourier
|
||||
AltPackages utopia
|
||||
OT1Package utopia
|
||||
AltFonts utopia-sty
|
||||
OT1Font utopia-sty
|
||||
EndFont
|
||||
|
||||
AltFont utopia-sty
|
||||
GuiName "Utopia (Fourier)"
|
||||
Family rm
|
||||
Package utopia
|
||||
EndFont
|
||||
|
||||
|
||||
|
@ -438,10 +438,17 @@ bool LaTeXFeatures::isRequired(string const & name) const
|
||||
|
||||
bool LaTeXFeatures::isProvided(string const & name) const
|
||||
{
|
||||
bool const ot1 = (params_.font_encoding() == "default"
|
||||
|| params_.font_encoding() == "OT1");
|
||||
bool const complete = (params_.fonts_sans == "default")
|
||||
&& (params_.fonts_typewriter == "default");
|
||||
return params_.documentClass().provides(name)
|
||||
|| theLaTeXFonts().getLaTeXFont(from_ascii(params_.fonts_roman)).provides(name)
|
||||
|| theLaTeXFonts().getLaTeXFont(from_ascii(params_.fonts_sans)).provides(name)
|
||||
|| theLaTeXFonts().getLaTeXFont(from_ascii(params_.fonts_typewriter)).provides(name);
|
||||
|| theLaTeXFonts().getLaTeXFont(
|
||||
from_ascii(params_.fonts_roman)).provides(name, ot1, complete)
|
||||
|| theLaTeXFonts().getLaTeXFont(
|
||||
from_ascii(params_.fonts_sans)).provides(name, ot1, complete)
|
||||
|| theLaTeXFonts().getLaTeXFont(
|
||||
from_ascii(params_.fonts_typewriter)).provides(name, ot1, complete);
|
||||
}
|
||||
|
||||
bool LaTeXFeatures::mustProvide(string const & name) const
|
||||
|
@ -34,54 +34,92 @@ namespace lyx {
|
||||
LaTeXFonts latexfonts;
|
||||
|
||||
|
||||
bool LaTeXFont::available(bool ot1) const
|
||||
LaTeXFont LaTeXFont::altFont(docstring const & name)
|
||||
{
|
||||
return ot1 ? available_ot1_ : available_;
|
||||
return theLaTeXFonts().getAltFont(name);
|
||||
}
|
||||
|
||||
|
||||
bool LaTeXFont::providesOSF(bool ot1) const
|
||||
bool LaTeXFont::available(bool ot1)
|
||||
{
|
||||
if (!osfpackage_.empty())
|
||||
return LaTeXFeatures::isAvailable(to_ascii(osfpackage_));
|
||||
|
||||
if (ot1 && !ot1package_.empty() && ot1package_ != "none")
|
||||
if (ot1 && !ot1font_.empty())
|
||||
return (ot1font_ == "none") ?
|
||||
true : altFont(ot1font_).available(ot1);
|
||||
else if (requires_.empty() && package_.empty())
|
||||
return true;
|
||||
else if (!requires_.empty()
|
||||
&& LaTeXFeatures::isAvailable(to_ascii(requires_)))
|
||||
return true;
|
||||
else if (!package_.empty()
|
||||
&& LaTeXFeatures::isAvailable(to_ascii(package_)))
|
||||
return true;
|
||||
else if (!altfonts_.empty()) {
|
||||
for (size_t i = 0; i < altfonts_.size(); ++i) {
|
||||
if (altFont(altfonts_[i]).available(ot1))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_)))
|
||||
|
||||
bool LaTeXFont::providesOSF(bool ot1, bool complete)
|
||||
{
|
||||
docstring const usedfont = getUsedFont(ot1, complete);
|
||||
|
||||
if (usedfont.empty())
|
||||
return false;
|
||||
else if (usedfont != name_)
|
||||
return altFont(usedfont).providesOSF(ot1, complete);
|
||||
else if (!osffont_.empty())
|
||||
return altFont(osffont_).available(ot1);
|
||||
else if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_)))
|
||||
return false;
|
||||
|
||||
return (!osfoption_.empty() || !osfscoption_.empty());
|
||||
}
|
||||
|
||||
|
||||
bool LaTeXFont::providesSC(bool ot1) const
|
||||
bool LaTeXFont::providesSC(bool ot1, bool complete)
|
||||
{
|
||||
if (ot1 && !ot1package_.empty() && ot1package_ != "none")
|
||||
return false;
|
||||
docstring const usedfont = getUsedFont(ot1, complete);
|
||||
|
||||
if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_)))
|
||||
if (usedfont.empty())
|
||||
return false;
|
||||
else if (usedfont != name_)
|
||||
return altFont(usedfont).providesSC(ot1, complete);
|
||||
else if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_)))
|
||||
return false;
|
||||
|
||||
return (!scoption_.empty() || !osfscoption_.empty());
|
||||
}
|
||||
|
||||
|
||||
bool LaTeXFont::providesScale(bool ot1) const
|
||||
bool LaTeXFont::providesScale(bool ot1, bool complete)
|
||||
{
|
||||
if (ot1 && !ot1package_.empty() && ot1package_ != "none")
|
||||
return false;
|
||||
docstring const usedfont = getUsedFont(ot1, complete);
|
||||
|
||||
if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_)))
|
||||
if (usedfont.empty())
|
||||
return false;
|
||||
else if (usedfont != name_)
|
||||
return altFont(usedfont).providesScale(ot1, complete);
|
||||
else if (!package_.empty() && !LaTeXFeatures::isAvailable(to_ascii(package_)))
|
||||
return false;
|
||||
|
||||
return (!scaleoption_.empty());
|
||||
}
|
||||
|
||||
bool LaTeXFont::provides(std::string const & name) const
|
||||
bool LaTeXFont::provides(std::string const & name, bool ot1, bool complete)
|
||||
{
|
||||
if (provides_.empty())
|
||||
docstring const usedfont = getUsedFont(ot1, complete);
|
||||
|
||||
if (usedfont.empty())
|
||||
return false;
|
||||
else if (usedfont != name_)
|
||||
return altFont(usedfont).provides(name, ot1, complete);
|
||||
else if (provides_.empty())
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < provides_.size(); ++i) {
|
||||
if (provides_[i] == name)
|
||||
return true;
|
||||
@ -90,75 +128,91 @@ bool LaTeXFont::provides(std::string const & name) const
|
||||
}
|
||||
|
||||
|
||||
string const LaTeXFont::getAvailablePackage(bool dryrun, bool ot1, bool complete, bool & alt)
|
||||
docstring const LaTeXFont::getUsedFont(bool ot1, bool complete)
|
||||
{
|
||||
if (ot1 && !ot1package_.empty()) {
|
||||
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);
|
||||
if (ot1 && !ot1font_.empty())
|
||||
return (ot1font_ == "none") ? docstring() : ot1font_;
|
||||
else if (family_ == "rm" && complete && !completefont_.empty()
|
||||
&& altFont(completefont_).available(ot1))
|
||||
return completefont_;
|
||||
else if (switchdefault_) {
|
||||
if (requires_.empty()
|
||||
|| (!requires_.empty()
|
||||
&& LaTeXFeatures::isAvailable(to_ascii(requires_))))
|
||||
return name_;
|
||||
}
|
||||
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]);
|
||||
if (altf.available(ot1))
|
||||
return altf.getUsedFont(ot1, complete);
|
||||
}
|
||||
}
|
||||
|
||||
return docstring();
|
||||
}
|
||||
|
||||
|
||||
string const LaTeXFont::getAvailablePackage(bool dryrun)
|
||||
{
|
||||
if (package_.empty())
|
||||
return string();
|
||||
}
|
||||
if (family_ == "rm" && complete && !completepackage_.empty()) {
|
||||
if (LaTeXFeatures::isAvailable(to_ascii(completepackage_)) || dryrun)
|
||||
return to_ascii(completepackage_);
|
||||
}
|
||||
if (!package_.empty()) {
|
||||
|
||||
string const package = to_ascii(package_);
|
||||
if (!requires_.empty() && LaTeXFeatures::isAvailable(to_ascii(requires_)))
|
||||
return to_ascii(package_);
|
||||
if (LaTeXFeatures::isAvailable(to_ascii(package_)))
|
||||
return to_ascii(package_);
|
||||
else if (!altpackages_.empty()) {
|
||||
for (size_t i = 0; i < altpackages_.size(); ++i) {
|
||||
if (LaTeXFeatures::isAvailable(to_ascii(altpackages_[i]))) {
|
||||
alt = true;
|
||||
return to_ascii(altpackages_[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return package;
|
||||
else if (LaTeXFeatures::isAvailable(package))
|
||||
return package;
|
||||
// Output unavailable packages in source preview
|
||||
if (dryrun)
|
||||
return to_ascii(package_);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
string const LaTeXFont::getPackageOptions(bool ot1, bool sc, bool osf, int scale)
|
||||
string const LaTeXFont::getPackageOptions(bool ot1, bool complete, bool sc, bool osf, int scale)
|
||||
{
|
||||
if (ot1 && !ot1package_.empty())
|
||||
return string();
|
||||
|
||||
ostringstream os;
|
||||
bool const needosfopt = (osf != osfdefault_);
|
||||
bool const has_osf = providesOSF(ot1, complete);
|
||||
bool const has_sc = providesSC(ot1, complete);
|
||||
|
||||
if (!packageoption_.empty())
|
||||
os << to_ascii(packageoption_);
|
||||
if (sc && needosfopt && providesOSF() && providesSC()) {
|
||||
|
||||
if (sc && needosfopt && has_osf && has_sc) {
|
||||
if (!os.str().empty())
|
||||
os << ',';
|
||||
if (!osfscoption_.empty())
|
||||
os << to_ascii(osfscoption_);
|
||||
else
|
||||
os << to_ascii(osfoption_) << ',' << to_ascii(scoption_);
|
||||
} else if (needosfopt && providesOSF()) {
|
||||
os << to_ascii(osfoption_)
|
||||
<< ',' << to_ascii(scoption_);
|
||||
} else if (needosfopt && has_osf) {
|
||||
if (!os.str().empty())
|
||||
os << ',';
|
||||
os << to_ascii(osfoption_);
|
||||
} else if (sc && providesSC()) {
|
||||
} else if (sc && has_sc) {
|
||||
if (!os.str().empty())
|
||||
os << ',';
|
||||
os << to_ascii(scoption_);
|
||||
}
|
||||
if (scale != 100 && !scaleoption_.empty()) {
|
||||
|
||||
if (scale != 100 && !scaleoption_.empty()
|
||||
&& providesScale(ot1, complete)) {
|
||||
if (!os.str().empty())
|
||||
os << ',';
|
||||
os << subst(to_ascii(scaleoption_), "$$val",
|
||||
@ -173,6 +227,12 @@ string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool
|
||||
{
|
||||
ostringstream os;
|
||||
|
||||
docstring const usedfont = getUsedFont(ot1, complete);
|
||||
if (usedfont.empty())
|
||||
return string();
|
||||
else if (usedfont != name_)
|
||||
return altFont(usedfont).getLaTeXCode(dryrun, ot1, complete, sc, osf, scale);
|
||||
|
||||
if (switchdefault_) {
|
||||
if (family_.empty()) {
|
||||
LYXERR0("Error: Font `" << name_ << "' has no family defined!");
|
||||
@ -187,18 +247,16 @@ string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool
|
||||
"is not available on your system. LyX will fall back to the default font."),
|
||||
requires_, guiname_), true);
|
||||
} else {
|
||||
bool alt = false;
|
||||
string const package =
|
||||
getAvailablePackage(dryrun, ot1, complete, alt);
|
||||
// Package options are not for alternative packages
|
||||
string const packageopts = alt ? string() : getPackageOptions(ot1, sc, osf, scale);
|
||||
getAvailablePackage(dryrun);
|
||||
string const packageopts = getPackageOptions(ot1, complete, sc, osf, scale);
|
||||
if (packageopts.empty() && !package.empty())
|
||||
os << "\\usepackage{" << package << "}\n";
|
||||
else if (!packageopts.empty() && !package.empty())
|
||||
os << "\\usepackage[" << packageopts << "]{" << package << "}\n";
|
||||
}
|
||||
if (osf && providesOSF(ot1) && !osfpackage_.empty())
|
||||
os << "\\usepackage{" << to_ascii(osfpackage_) << "}\n";
|
||||
if (osf && providesOSF(ot1, complete) && !osffont_.empty())
|
||||
os << altFont(osffont_).getLaTeXCode(dryrun, ot1, complete, sc, osf, scale);
|
||||
|
||||
return os.str();
|
||||
}
|
||||
@ -207,16 +265,16 @@ string const LaTeXFont::getLaTeXCode(bool dryrun, bool ot1, bool complete, bool
|
||||
bool LaTeXFont::readFont(Lexer & lex)
|
||||
{
|
||||
enum LaTeXFontTags {
|
||||
LF_ALT_PACKAGES = 1,
|
||||
LF_COMPLETE_PACKAGE,
|
||||
LF_ALT_FONTS = 1,
|
||||
LF_COMPLETE_FONT,
|
||||
LF_END,
|
||||
LF_FAMILY,
|
||||
LF_GUINAME,
|
||||
LF_OSFDEFAULT,
|
||||
LF_OSFFONT,
|
||||
LF_OSFOPTION,
|
||||
LF_OSFPACKAGE,
|
||||
LF_OSFSCOPTION,
|
||||
LF_OT1_PACKAGE,
|
||||
LF_OT1_FONT,
|
||||
LF_PACKAGE,
|
||||
LF_PACKAGEOPTION,
|
||||
LF_PROVIDES,
|
||||
@ -228,16 +286,16 @@ bool LaTeXFont::readFont(Lexer & lex)
|
||||
|
||||
// Keep these sorted alphabetically!
|
||||
LexerKeyword latexFontTags[] = {
|
||||
{ "altpackages", LF_ALT_PACKAGES },
|
||||
{ "completepackage", LF_COMPLETE_PACKAGE },
|
||||
{ "altfonts", LF_ALT_FONTS },
|
||||
{ "completefont", LF_COMPLETE_FONT },
|
||||
{ "endfont", LF_END },
|
||||
{ "family", LF_FAMILY },
|
||||
{ "guiname", LF_GUINAME },
|
||||
{ "osfdefault", LF_OSFDEFAULT },
|
||||
{ "osffont", LF_OSFFONT },
|
||||
{ "osfoption", LF_OSFOPTION },
|
||||
{ "osfpackage", LF_OSFPACKAGE },
|
||||
{ "osfscoption", LF_OSFSCOPTION },
|
||||
{ "ot1package", LF_OT1_PACKAGE },
|
||||
{ "ot1font", LF_OT1_FONT },
|
||||
{ "package", LF_PACKAGE },
|
||||
{ "packageoption", LF_PACKAGEOPTION },
|
||||
{ "provides", LF_PROVIDES },
|
||||
@ -270,14 +328,14 @@ bool LaTeXFont::readFont(Lexer & lex)
|
||||
case LF_END: // end of structure
|
||||
finished = true;
|
||||
break;
|
||||
case LF_ALT_PACKAGES: {
|
||||
case LF_ALT_FONTS: {
|
||||
lex.eatLine();
|
||||
docstring altp = lex.getDocString();
|
||||
altpackages_ = getVectorFromString(altp);
|
||||
altfonts_ = getVectorFromString(altp);
|
||||
break;
|
||||
}
|
||||
case LF_COMPLETE_PACKAGE:
|
||||
lex >> completepackage_;
|
||||
case LF_COMPLETE_FONT:
|
||||
lex >> completefont_;
|
||||
break;
|
||||
case LF_FAMILY:
|
||||
lex >> family_;
|
||||
@ -288,8 +346,8 @@ bool LaTeXFont::readFont(Lexer & lex)
|
||||
case LF_OSFOPTION:
|
||||
lex >> osfoption_;
|
||||
break;
|
||||
case LF_OSFPACKAGE:
|
||||
lex >> osfpackage_;
|
||||
case LF_OSFFONT:
|
||||
lex >> osffont_;
|
||||
break;
|
||||
case LF_OSFDEFAULT:
|
||||
lex >> osfdefault_;
|
||||
@ -297,8 +355,8 @@ bool LaTeXFont::readFont(Lexer & lex)
|
||||
case LF_OSFSCOPTION:
|
||||
lex >> osfscoption_;
|
||||
break;
|
||||
case LF_OT1_PACKAGE:
|
||||
lex >> ot1package_;
|
||||
case LF_OT1_FONT:
|
||||
lex >> ot1font_;
|
||||
break;
|
||||
case LF_PACKAGE:
|
||||
lex >> package_;
|
||||
@ -352,26 +410,6 @@ bool LaTeXFont::read(Lexer & lex)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool available = true;
|
||||
if (!requires_.empty())
|
||||
available = LaTeXFeatures::isAvailable(to_ascii(requires_));
|
||||
else if (!package_.empty()) {
|
||||
available = LaTeXFeatures::isAvailable(to_ascii(package_));
|
||||
if (!available && !altpackages_.empty()) {
|
||||
for (size_t i = 0; i < altpackages_.size(); ++i) {
|
||||
available = LaTeXFeatures::isAvailable(to_ascii(altpackages_[i]));
|
||||
if (available)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
available_ = available;
|
||||
|
||||
if (!ot1package_.empty() && ot1package_ != "none")
|
||||
available_ot1_ = LaTeXFeatures::isAvailable(to_ascii(ot1package_));
|
||||
else
|
||||
available_ot1_ = available;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -396,7 +434,8 @@ void LaTeXFonts::readLaTeXFonts()
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (lex.getString() != "Font") {
|
||||
string const type = lex.getString();
|
||||
if (type != "Font" && type != "AltFont") {
|
||||
lex.printError("Unknown LaTeXFont tag `$$Token'");
|
||||
continue;
|
||||
}
|
||||
@ -405,6 +444,9 @@ void LaTeXFonts::readLaTeXFonts()
|
||||
if (!lex)
|
||||
break;
|
||||
|
||||
if (type == "AltFont")
|
||||
texaltfontmap_[f.name()] = f;
|
||||
else
|
||||
texfontmap_[f.name()] = f;
|
||||
}
|
||||
}
|
||||
@ -432,4 +474,18 @@ LaTeXFont LaTeXFonts::getLaTeXFont(docstring const & name)
|
||||
}
|
||||
|
||||
|
||||
LaTeXFont LaTeXFonts::getAltFont(docstring const & name)
|
||||
{
|
||||
if (name == "default")
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
} // namespace lyx
|
||||
|
@ -35,14 +35,14 @@ public:
|
||||
docstring const & family() { return family_; }
|
||||
/// The package that provides this font
|
||||
docstring const & package() { return package_; }
|
||||
/// Alternative packages if package() is not available
|
||||
std::vector<docstring> const & altpackages() { return altpackages_; }
|
||||
/// A package that provides all families
|
||||
docstring const & completepackage() { return completepackage_; }
|
||||
/// A package specifically needed for OT1 font encoding
|
||||
docstring const & ot1package() { return ot1package_; }
|
||||
/// A package that provides Old Style Figures for this font
|
||||
docstring const & osfpackage() { return osfpackage_; }
|
||||
/// Alternative font if package() is not available
|
||||
std::vector<docstring> const & altfonts() { return altfonts_; }
|
||||
/// A font that provides all families
|
||||
docstring const & completefont() { return completefont_; }
|
||||
/// A font specifically needed for OT1 font encoding
|
||||
docstring const & ot1font() { return ot1font_; }
|
||||
/// A font that provides Old Style Figures for this type face
|
||||
docstring const & osffont() { return osffont_; }
|
||||
/// A package option needed to load this font
|
||||
docstring const & packageoption() { return packageoption_; }
|
||||
/// A package option for Old Style Figures
|
||||
@ -56,38 +56,40 @@ public:
|
||||
/// Alternative requirement to test for
|
||||
docstring const & requires() { return requires_; }
|
||||
/// Does this font provide a given \p feature
|
||||
bool provides(std::string const & name) const;
|
||||
bool provides(std::string const & name, bool ot1, bool complete);
|
||||
/// Issue the familydefault switch
|
||||
bool switchdefault() const { return switchdefault_; }
|
||||
/// Does the font provide Old Style Figures as default?
|
||||
bool osfDefault() const { return osfdefault_; }
|
||||
/// Is this font available?
|
||||
bool available(bool ot1 = false) const;
|
||||
bool available(bool ot1);
|
||||
/// Does this font provide Old Style Figures?
|
||||
bool providesOSF(bool ot1 = false) const;
|
||||
bool providesOSF(bool ot1, bool complete);
|
||||
/// Does this font provide optional true SmallCaps?
|
||||
bool providesSC(bool ot1 = false) const;
|
||||
bool providesSC(bool ot1, bool complete);
|
||||
/// Does this font provide scaling?
|
||||
bool providesScale(bool ot1 = false) const;
|
||||
bool providesScale(bool ot1, bool complete);
|
||||
/// Return the LaTeX Code
|
||||
std::string const getLaTeXCode(bool dryrun, bool ot1, bool complete,
|
||||
bool sc, bool osf,
|
||||
int const & scale = 100);
|
||||
/// Return the actually used font
|
||||
docstring const getUsedFont(bool ot1, bool complete);
|
||||
///
|
||||
bool read(Lexer & lex);
|
||||
///
|
||||
bool readFont(Lexer & lex);
|
||||
private:
|
||||
/// Return the preferred available package
|
||||
std::string const getAvailablePackage(bool dryrun,
|
||||
bool ot1,
|
||||
bool complete,
|
||||
bool & alt);
|
||||
std::string const getAvailablePackage(bool dryrun);
|
||||
/// Return the package options
|
||||
std::string const getPackageOptions(bool ot1,
|
||||
bool complete,
|
||||
bool sc,
|
||||
bool osf,
|
||||
int scale);
|
||||
/// Return an alternative font
|
||||
LaTeXFont altFont(docstring const & name);
|
||||
///
|
||||
docstring name_;
|
||||
///
|
||||
@ -97,13 +99,13 @@ private:
|
||||
///
|
||||
docstring package_;
|
||||
///
|
||||
std::vector<docstring> altpackages_;
|
||||
std::vector<docstring> altfonts_;
|
||||
///
|
||||
docstring completepackage_;
|
||||
docstring completefont_;
|
||||
///
|
||||
docstring ot1package_;
|
||||
docstring ot1font_;
|
||||
///
|
||||
docstring osfpackage_;
|
||||
docstring osffont_;
|
||||
///
|
||||
docstring packageoption_;
|
||||
///
|
||||
@ -122,10 +124,6 @@ private:
|
||||
bool osfdefault_;
|
||||
///
|
||||
bool switchdefault_;
|
||||
///
|
||||
bool available_;
|
||||
///
|
||||
bool available_ot1_;
|
||||
};
|
||||
|
||||
|
||||
@ -139,11 +137,15 @@ public:
|
||||
TexFontMap getLaTeXFonts();
|
||||
/// Get a specific LaTeXFont \p name
|
||||
LaTeXFont getLaTeXFont(docstring const & name);
|
||||
/// Get a specific AltFont \p name
|
||||
LaTeXFont getAltFont(docstring const & name);
|
||||
private:
|
||||
///
|
||||
void readLaTeXFonts();
|
||||
///
|
||||
TexFontMap texfontmap_;
|
||||
///
|
||||
TexFontMap texaltfontmap_;
|
||||
};
|
||||
|
||||
/// Implementation is in LyX.cpp
|
||||
|
@ -1832,6 +1832,15 @@ bool GuiDocument::ot1() const
|
||||
}
|
||||
|
||||
|
||||
bool GuiDocument::completeFontset() const
|
||||
{
|
||||
return (fontModule->fontsSansCO->itemData(
|
||||
fontModule->fontsSansCO->currentIndex()).toString() == "default"
|
||||
&& fontModule->fontsSansCO->itemData(
|
||||
fontModule->fontsSansCO->currentIndex()).toString() == "default");
|
||||
}
|
||||
|
||||
|
||||
void GuiDocument::updateTexFonts()
|
||||
{
|
||||
LaTeXFonts::TexFontMap texfontmap = theLaTeXFonts().getLaTeXFonts();
|
||||
@ -3622,7 +3631,8 @@ bool GuiDocument::providesOSF(QString const & font) const
|
||||
// FIXME: we should check if the fonts really
|
||||
// have OSF support. But how?
|
||||
return true;
|
||||
return theLaTeXFonts().getLaTeXFont(qstring_to_ucs4(font)).providesOSF(ot1());
|
||||
return theLaTeXFonts().getLaTeXFont(
|
||||
qstring_to_ucs4(font)).providesOSF(ot1(), completeFontset());
|
||||
}
|
||||
|
||||
|
||||
@ -3630,7 +3640,8 @@ bool GuiDocument::providesSC(QString const & font) const
|
||||
{
|
||||
if (fontModule->osFontsCB->isChecked())
|
||||
return false;
|
||||
return theLaTeXFonts().getLaTeXFont(qstring_to_ucs4(font)).providesSC(ot1());
|
||||
return theLaTeXFonts().getLaTeXFont(
|
||||
qstring_to_ucs4(font)).providesSC(ot1(), completeFontset());
|
||||
}
|
||||
|
||||
|
||||
@ -3638,7 +3649,8 @@ bool GuiDocument::providesScale(QString const & font) const
|
||||
{
|
||||
if (fontModule->osFontsCB->isChecked())
|
||||
return true;
|
||||
return theLaTeXFonts().getLaTeXFont(qstring_to_ucs4(font)).providesScale(ot1());
|
||||
return theLaTeXFonts().getLaTeXFont(
|
||||
qstring_to_ucs4(font)).providesScale(ot1(), completeFontset());
|
||||
}
|
||||
|
||||
|
||||
|
@ -250,6 +250,8 @@ private:
|
||||
///
|
||||
bool ot1() const;
|
||||
///
|
||||
bool completeFontset() const;
|
||||
///
|
||||
BufferParams bp_;
|
||||
/// List of names of available modules
|
||||
std::list<modInfoStruct> moduleNames_;
|
||||
|
Loading…
Reference in New Issue
Block a user