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