2003-08-23 00:17:00 +00:00
|
|
|
/**
|
2007-04-29 18:17:15 +00:00
|
|
|
* \file src/Font.cpp
|
2003-08-23 00:17:00 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
* \author Angus Leeming
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Dekel Tsur
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
#include "Font.h"
|
2003-09-09 22:13:45 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "BufferParams.h" // stateText
|
2009-02-09 23:30:24 +00:00
|
|
|
#include "ColorSet.h"
|
2007-05-06 20:26:02 +00:00
|
|
|
#include "Encoding.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Language.h"
|
2007-10-19 16:22:36 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyXRC.h"
|
2007-05-06 20:26:02 +00:00
|
|
|
#include "output_latex.h"
|
|
|
|
#include "OutputParams.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "texstream.h"
|
2003-09-09 22:13:45 +00:00
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2007-09-29 11:00:18 +00:00
|
|
|
#include "support/convert.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
|
|
|
#include "support/gettext.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/lstrings.h"
|
2004-07-24 10:55:30 +00:00
|
|
|
|
2008-02-07 17:04:06 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-07-17 17:46:54 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2009-10-27 16:16:15 +00:00
|
|
|
//
|
|
|
|
// Strings used to read and write .lyx format files
|
|
|
|
//
|
|
|
|
// These are defined in FontInfo.cpp
|
2009-10-30 14:57:21 +00:00
|
|
|
extern char const * LyXFamilyNames[NUM_FAMILIES + 2];
|
2012-12-09 12:04:29 +00:00
|
|
|
extern char const * LyXSeriesNames[NUM_SERIES + 2];
|
|
|
|
extern char const * LyXShapeNames[NUM_SHAPE + 2];
|
|
|
|
extern char const * LyXSizeNames[NUM_SIZE + 4];
|
2009-10-30 14:57:21 +00:00
|
|
|
extern char const * LyXMiscNames[5];
|
2009-10-27 16:16:15 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
//
|
|
|
|
// Names for the GUI
|
|
|
|
//
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
char const * GUIFamilyNames[NUM_FAMILIES + 2 /* default & error */] =
|
2003-01-23 16:23:43 +00:00
|
|
|
{ N_("Roman"), N_("Sans Serif"), N_("Typewriter"), N_("Symbol"),
|
2020-06-12 21:58:32 +00:00
|
|
|
"cmr", "cmsy", "cmm", "cmex", "msa", "msb", "ds", "eufrak", "rsfs", "stmry",
|
2012-12-15 12:02:40 +00:00
|
|
|
"wasy", "esint", N_("Inherit"), N_("Ignore") };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2012-12-09 12:04:29 +00:00
|
|
|
char const * GUISeriesNames[NUM_SERIES + 2 /* default & error */] =
|
1999-09-27 18:44:28 +00:00
|
|
|
{ N_("Medium"), N_("Bold"), N_("Inherit"), N_("Ignore") };
|
|
|
|
|
2012-12-09 12:04:29 +00:00
|
|
|
char const * GUIShapeNames[NUM_SHAPE + 2 /* default & error */] =
|
1999-09-27 18:44:28 +00:00
|
|
|
{ N_("Upright"), N_("Italic"), N_("Slanted"), N_("Smallcaps"), N_("Inherit"),
|
1999-12-07 00:44:53 +00:00
|
|
|
N_("Ignore") };
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2012-12-09 12:04:29 +00:00
|
|
|
char const * GUISizeNames[NUM_SIZE + 4 /* increase, decrease, default & error */] =
|
1999-09-27 18:44:28 +00:00
|
|
|
{ N_("Tiny"), N_("Smallest"), N_("Smaller"), N_("Small"), N_("Normal"), N_("Large"),
|
2002-03-21 17:27:08 +00:00
|
|
|
N_("Larger"), N_("Largest"), N_("Huge"), N_("Huger"), N_("Increase"), N_("Decrease"),
|
1999-09-27 18:44:28 +00:00
|
|
|
N_("Inherit"), N_("Ignore") };
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
|
|
char const * GUIMiscNames[5] =
|
1999-09-27 18:44:28 +00:00
|
|
|
{ N_("Off"), N_("On"), N_("Toggle"), N_("Inherit"), N_("Ignore") };
|
|
|
|
|
|
|
|
//
|
|
|
|
// Strings used to write LaTeX files
|
|
|
|
//
|
2012-12-09 12:04:29 +00:00
|
|
|
char const * LaTeXFamilyNames[NUM_FAMILIES + 2] =
|
|
|
|
{ "textrm", "textsf", "texttt", "error1", "error2", "error3", "error4",
|
|
|
|
"error5", "error6", "error7", "error8", "error9", "error10", "error11",
|
2020-06-12 21:58:32 +00:00
|
|
|
"error12", "error13", "error14" };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2012-12-09 12:04:29 +00:00
|
|
|
char const * LaTeXSeriesNames[NUM_SERIES + 2] =
|
1999-09-27 18:44:28 +00:00
|
|
|
{ "textmd", "textbf", "error4", "error5" };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2012-12-09 12:04:29 +00:00
|
|
|
char const * LaTeXShapeNames[NUM_SHAPE + 2] =
|
1999-09-27 18:44:28 +00:00
|
|
|
{ "textup", "textit", "textsl", "textsc", "error6", "error7" };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2012-12-09 12:04:29 +00:00
|
|
|
char const * LaTeXSizeNames[NUM_SIZE + 4] =
|
1999-09-27 18:44:28 +00:00
|
|
|
{ "tiny", "scriptsize", "footnotesize", "small", "normalsize", "large",
|
|
|
|
"Large", "LARGE", "huge", "Huge", "error8", "error9", "error10", "error11" };
|
2000-02-10 17:53:36 +00:00
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2000-02-23 16:39:03 +00:00
|
|
|
|
2001-03-06 14:07:14 +00:00
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
Font::Font(FontInfo bits, Language const * l)
|
2010-09-14 05:24:04 +00:00
|
|
|
: bits_(bits), lang_(l), open_encoding_(false)
|
2000-04-04 00:19:15 +00:00
|
|
|
{
|
2007-10-28 18:51:54 +00:00
|
|
|
if (!lang_)
|
|
|
|
lang_ = default_language;
|
2001-03-06 14:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
bool Font::isRightToLeft() const
|
2001-03-06 14:07:14 +00:00
|
|
|
{
|
2007-10-28 18:51:54 +00:00
|
|
|
return lang_->rightToLeft();
|
2001-03-06 14:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
bool Font::isVisibleRightToLeft() const
|
2001-03-06 14:07:14 +00:00
|
|
|
{
|
2007-10-28 18:51:54 +00:00
|
|
|
return (lang_->rightToLeft() &&
|
|
|
|
bits_.number() != FONT_ON);
|
2001-03-06 14:07:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
void Font::setLanguage(Language const * l)
|
2001-03-06 14:07:14 +00:00
|
|
|
{
|
2007-10-28 18:51:54 +00:00
|
|
|
lang_ = l;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Updates font settings according to request
|
2007-04-29 18:17:15 +00:00
|
|
|
void Font::update(Font const & newfont,
|
2001-08-11 18:31:14 +00:00
|
|
|
Language const * document_language,
|
|
|
|
bool toggleall)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2007-10-28 18:51:54 +00:00
|
|
|
bits_.update(newfont.fontInfo(), toggleall);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-17 14:00:18 +00:00
|
|
|
if (newfont.language() == language() && toggleall)
|
2001-08-11 18:31:14 +00:00
|
|
|
if (language() == document_language)
|
|
|
|
setLanguage(default_language);
|
|
|
|
else
|
|
|
|
setLanguage(document_language);
|
2008-05-07 23:33:56 +00:00
|
|
|
else if (newfont.language() == reset_language)
|
|
|
|
setLanguage(document_language);
|
2000-04-17 14:00:18 +00:00
|
|
|
else if (newfont.language() != ignore_language)
|
|
|
|
setLanguage(newfont.language());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
docstring const stateText(FontInfo const & f)
|
2001-07-27 12:03:36 +00:00
|
|
|
{
|
2007-10-28 18:51:54 +00:00
|
|
|
odocstringstream os;
|
|
|
|
if (f.family() != INHERIT_FAMILY)
|
|
|
|
os << _(GUIFamilyNames[f.family()]) << ", ";
|
|
|
|
if (f.series() != INHERIT_SERIES)
|
|
|
|
os << _(GUISeriesNames[f.series()]) << ", ";
|
|
|
|
if (f.shape() != INHERIT_SHAPE)
|
|
|
|
os << _(GUIShapeNames[f.shape()]) << ", ";
|
|
|
|
if (f.size() != FONT_SIZE_INHERIT)
|
|
|
|
os << _(GUISizeNames[f.size()]) << ", ";
|
|
|
|
if (f.color() != Color_inherit)
|
|
|
|
os << lcolor.getGUIName(f.color()) << ", ";
|
|
|
|
// FIXME: uncomment this when we support background.
|
|
|
|
//if (f.background() != Color_inherit)
|
|
|
|
// os << lcolor.getGUIName(f.background()) << ", ";
|
|
|
|
if (f.emph() != FONT_INHERIT)
|
|
|
|
os << bformat(_("Emphasis %1$s, "),
|
|
|
|
_(GUIMiscNames[f.emph()]));
|
|
|
|
if (f.underbar() != FONT_INHERIT)
|
|
|
|
os << bformat(_("Underline %1$s, "),
|
|
|
|
_(GUIMiscNames[f.underbar()]));
|
2009-05-03 22:45:14 +00:00
|
|
|
if (f.strikeout() != FONT_INHERIT)
|
2017-04-04 22:01:19 +00:00
|
|
|
os << bformat(_("Strike out %1$s, "),
|
2009-05-05 09:26:40 +00:00
|
|
|
_(GUIMiscNames[f.strikeout()]));
|
2017-04-04 22:01:19 +00:00
|
|
|
if (f.xout() != FONT_INHERIT)
|
|
|
|
os << bformat(_("Cross out %1$s, "),
|
|
|
|
_(GUIMiscNames[f.xout()]));
|
2009-05-05 09:26:28 +00:00
|
|
|
if (f.uuline() != FONT_INHERIT)
|
|
|
|
os << bformat(_("Double underline %1$s, "),
|
2009-05-05 09:26:40 +00:00
|
|
|
_(GUIMiscNames[f.uuline()]));
|
2009-05-05 09:26:28 +00:00
|
|
|
if (f.uwave() != FONT_INHERIT)
|
|
|
|
os << bformat(_("Wavy underline %1$s, "),
|
2009-05-05 09:26:40 +00:00
|
|
|
_(GUIMiscNames[f.uwave()]));
|
2007-10-28 18:51:54 +00:00
|
|
|
if (f.noun() != FONT_INHERIT)
|
|
|
|
os << bformat(_("Noun %1$s, "),
|
|
|
|
_(GUIMiscNames[f.noun()]));
|
|
|
|
if (f == inherit_font)
|
|
|
|
os << _("Default") << ", ";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
return os.str();
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
docstring const Font::stateText(BufferParams * params) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2006-12-21 14:31:19 +00:00
|
|
|
odocstringstream os;
|
2007-10-28 18:51:54 +00:00
|
|
|
os << lyx::stateText(bits_);
|
2003-05-13 09:48:57 +00:00
|
|
|
if (!params || (language() != params->language))
|
2006-12-21 14:31:19 +00:00
|
|
|
os << bformat(_("Language: %1$s, "),
|
2007-05-28 22:27:45 +00:00
|
|
|
_(language()->display()));
|
2007-10-28 18:51:54 +00:00
|
|
|
if (bits_.number() != FONT_OFF)
|
2010-11-27 03:04:53 +00:00
|
|
|
os << " " << bformat(_("Number %1$s"),
|
2007-10-28 18:51:54 +00:00
|
|
|
_(GUIMiscNames[bits_.number()]));
|
2003-09-15 11:00:00 +00:00
|
|
|
return rtrim(os.str(), ", ");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns size in latex format
|
2007-04-29 18:17:15 +00:00
|
|
|
string const Font::latexSize() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2007-10-28 18:51:54 +00:00
|
|
|
return LaTeXSizeNames[bits_.size()];
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Writes the changes from this font to orgfont in .lyx format in file
|
2007-04-29 18:17:15 +00:00
|
|
|
void Font::lyxWriteChanges(Font const & orgfont,
|
2001-08-11 18:31:14 +00:00
|
|
|
ostream & os) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-12-07 00:44:53 +00:00
|
|
|
os << "\n";
|
2007-10-28 18:51:54 +00:00
|
|
|
if (orgfont.fontInfo().family() != bits_.family())
|
|
|
|
os << "\\family " << LyXFamilyNames[bits_.family()] << "\n";
|
|
|
|
if (orgfont.fontInfo().series() != bits_.series())
|
|
|
|
os << "\\series " << LyXSeriesNames[bits_.series()] << "\n";
|
|
|
|
if (orgfont.fontInfo().shape() != bits_.shape())
|
|
|
|
os << "\\shape " << LyXShapeNames[bits_.shape()] << "\n";
|
|
|
|
if (orgfont.fontInfo().size() != bits_.size())
|
|
|
|
os << "\\size " << LyXSizeNames[bits_.size()] << "\n";
|
|
|
|
if (orgfont.fontInfo().emph() != bits_.emph())
|
|
|
|
os << "\\emph " << LyXMiscNames[bits_.emph()] << "\n";
|
|
|
|
if (orgfont.fontInfo().number() != bits_.number())
|
|
|
|
os << "\\numeric " << LyXMiscNames[bits_.number()] << "\n";
|
|
|
|
if (orgfont.fontInfo().underbar() != bits_.underbar()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// This is only for backwards compatibility
|
2007-10-28 18:51:54 +00:00
|
|
|
switch (bits_.underbar()) {
|
|
|
|
case FONT_OFF: os << "\\bar no\n"; break;
|
|
|
|
case FONT_ON: os << "\\bar under\n"; break;
|
|
|
|
case FONT_TOGGLE: lyxerr << "Font::lyxWriteFontChanges: "
|
|
|
|
"FONT_TOGGLE should not appear here!"
|
1999-10-07 18:44:17 +00:00
|
|
|
<< endl;
|
1999-12-07 00:44:53 +00:00
|
|
|
break;
|
2007-10-28 18:51:54 +00:00
|
|
|
case FONT_INHERIT: os << "\\bar default\n"; break;
|
|
|
|
case FONT_IGNORE: lyxerr << "Font::lyxWriteFontChanges: "
|
1999-10-07 18:44:17 +00:00
|
|
|
"IGNORE should not appear here!"
|
|
|
|
<< endl;
|
1999-12-07 00:44:53 +00:00
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-03 22:45:14 +00:00
|
|
|
if (orgfont.fontInfo().strikeout() != bits_.strikeout()) {
|
|
|
|
os << "\\strikeout " << LyXMiscNames[bits_.strikeout()] << "\n";
|
|
|
|
}
|
2017-04-04 22:01:19 +00:00
|
|
|
if (orgfont.fontInfo().xout() != bits_.xout()) {
|
|
|
|
os << "\\xout " << LyXMiscNames[bits_.xout()] << "\n";
|
|
|
|
}
|
2009-05-05 09:26:28 +00:00
|
|
|
if (orgfont.fontInfo().uuline() != bits_.uuline()) {
|
|
|
|
os << "\\uuline " << LyXMiscNames[bits_.uuline()] << "\n";
|
|
|
|
}
|
|
|
|
if (orgfont.fontInfo().uwave() != bits_.uwave()) {
|
|
|
|
os << "\\uwave " << LyXMiscNames[bits_.uwave()] << "\n";
|
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
if (orgfont.fontInfo().noun() != bits_.noun()) {
|
|
|
|
os << "\\noun " << LyXMiscNames[bits_.noun()] << "\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
if (orgfont.fontInfo().color() != bits_.color())
|
|
|
|
os << "\\color " << lcolor.getLyXName(bits_.color()) << '\n';
|
|
|
|
// FIXME: uncomment this when we support background.
|
|
|
|
//if (orgfont.fontInfo().background() != bits_.background())
|
|
|
|
// os << "\\color " << lcolor.getLyXName(bits_.background()) << '\n';
|
2006-02-27 12:22:36 +00:00
|
|
|
if (orgfont.language() != language() &&
|
|
|
|
language() != latex_language) {
|
2001-08-11 18:31:14 +00:00
|
|
|
if (language())
|
2000-06-08 23:16:16 +00:00
|
|
|
os << "\\lang " << language()->lang() << "\n";
|
2000-03-17 10:14:46 +00:00
|
|
|
else
|
|
|
|
os << "\\lang unknown\n";
|
2000-02-03 19:51:27 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Writes the head of the LaTeX needed to impose this font
|
|
|
|
// Returns number of chars written.
|
2007-05-06 20:26:02 +00:00
|
|
|
int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const & runparams,
|
|
|
|
Font const & base,
|
|
|
|
Font const & prev) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
|
|
|
bool env = false;
|
|
|
|
|
2007-03-18 10:59:16 +00:00
|
|
|
int count = 0;
|
2010-11-22 12:10:16 +00:00
|
|
|
|
|
|
|
// polyglossia or babel?
|
2010-11-23 09:59:31 +00:00
|
|
|
if (runparams.use_polyglossia
|
2010-11-23 10:18:46 +00:00
|
|
|
&& language()->lang() != base.language()->lang()
|
2010-11-23 09:59:31 +00:00
|
|
|
&& language() != prev.language()) {
|
2010-11-22 12:10:16 +00:00
|
|
|
if (!language()->polyglossia().empty()) {
|
|
|
|
string tmp = "\\text" + language()->polyglossia();
|
2020-04-05 13:23:22 +00:00
|
|
|
if (!language()->polyglossiaOpts().empty()) {
|
2010-11-22 12:10:16 +00:00
|
|
|
tmp += "[" + language()->polyglossiaOpts() + "]";
|
2020-04-05 13:23:22 +00:00
|
|
|
if (runparams.use_hyperref && runparams.moving_arg)
|
|
|
|
// We need to strip the command for
|
|
|
|
// the pdf string, see #11813
|
|
|
|
tmp = "\\texorpdfstring{" + tmp + "}{}";
|
|
|
|
}
|
2010-11-22 12:10:16 +00:00
|
|
|
tmp += "{";
|
|
|
|
os << from_ascii(tmp);
|
|
|
|
count += tmp.length();
|
2017-05-30 15:49:59 +00:00
|
|
|
pushLanguageName(language()->polyglossia(), true);
|
2013-10-11 10:19:41 +00:00
|
|
|
} else if (language()->encoding()->package() != Encoding::CJK) {
|
2013-07-12 14:57:34 +00:00
|
|
|
os << '{';
|
|
|
|
count += 1;
|
2010-11-22 12:10:16 +00:00
|
|
|
}
|
|
|
|
} else if (language()->babel() != base.language()->babel() &&
|
2002-04-11 13:35:03 +00:00
|
|
|
language() != prev.language()) {
|
2007-05-14 09:34:53 +00:00
|
|
|
if (language()->lang() == "farsi") {
|
|
|
|
os << "\\textFR{";
|
|
|
|
count += 8;
|
2007-05-28 22:27:45 +00:00
|
|
|
} else if (!isRightToLeft() &&
|
2007-05-14 09:34:53 +00:00
|
|
|
base.language()->lang() == "farsi") {
|
|
|
|
os << "\\textLR{";
|
|
|
|
count += 8;
|
2007-06-26 00:11:03 +00:00
|
|
|
} else if (language()->lang() == "arabic_arabi") {
|
|
|
|
os << "\\textAR{";
|
|
|
|
count += 8;
|
|
|
|
} else if (!isRightToLeft() &&
|
|
|
|
base.language()->lang() == "arabic_arabi") {
|
|
|
|
os << "\\textLR{";
|
|
|
|
count += 8;
|
|
|
|
// currently the remaining RTL languages are arabic_arabtex and hebrew
|
2007-05-14 09:34:53 +00:00
|
|
|
} else if (isRightToLeft() != prev.isRightToLeft()) {
|
2000-03-17 10:14:46 +00:00
|
|
|
if (isRightToLeft()) {
|
|
|
|
os << "\\R{";
|
|
|
|
count += 3;
|
|
|
|
} else {
|
|
|
|
os << "\\L{";
|
|
|
|
count += 3;
|
|
|
|
}
|
2007-05-05 19:18:34 +00:00
|
|
|
} else if (!language()->babel().empty()) {
|
2001-03-06 14:07:14 +00:00
|
|
|
string const tmp =
|
2001-02-25 10:22:54 +00:00
|
|
|
subst(lyxrc.language_command_local,
|
2000-10-10 12:36:36 +00:00
|
|
|
"$$lang", language()->babel());
|
2006-10-21 00:16:43 +00:00
|
|
|
os << from_ascii(tmp);
|
2000-03-17 10:14:46 +00:00
|
|
|
count += tmp.length();
|
2017-05-30 15:49:59 +00:00
|
|
|
if (!lyxrc.language_command_end.empty())
|
|
|
|
pushLanguageName(language()->babel(), true);
|
2013-10-11 10:19:41 +00:00
|
|
|
} else if (language()->encoding()->package() != Encoding::CJK) {
|
2007-05-06 20:26:02 +00:00
|
|
|
os << '{';
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (language()->encoding()->package() == Encoding::CJK) {
|
2007-07-05 19:19:41 +00:00
|
|
|
pair<bool, int> const c = switchEncoding(os, bparams,
|
2007-12-17 10:53:38 +00:00
|
|
|
runparams, *(language()->encoding()));
|
2007-07-05 19:19:41 +00:00
|
|
|
if (c.first) {
|
2007-05-06 20:26:02 +00:00
|
|
|
open_encoding_ = true;
|
2007-07-05 19:19:41 +00:00
|
|
|
count += c.second;
|
2007-05-06 20:26:02 +00:00
|
|
|
runparams.encoding = language()->encoding();
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
FontInfo f = bits_;
|
|
|
|
f.reduce(base.bits_);
|
2018-01-03 12:20:05 +00:00
|
|
|
FontInfo p = bits_;
|
|
|
|
p.reduce(prev.bits_);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
if (f.family() != INHERIT_FAMILY) {
|
|
|
|
os << '\\'
|
|
|
|
<< LaTeXFamilyNames[f.family()]
|
2000-03-07 01:14:37 +00:00
|
|
|
<< '{';
|
2001-06-01 10:53:24 +00:00
|
|
|
count += strlen(LaTeXFamilyNames[f.family()]) + 2;
|
2000-03-06 02:42:40 +00:00
|
|
|
env = true; //We have opened a new environment
|
|
|
|
}
|
|
|
|
if (f.series() != INHERIT_SERIES) {
|
|
|
|
os << '\\'
|
|
|
|
<< LaTeXSeriesNames[f.series()]
|
|
|
|
<< '{';
|
2001-06-01 10:53:24 +00:00
|
|
|
count += strlen(LaTeXSeriesNames[f.series()]) + 2;
|
2000-03-06 02:42:40 +00:00
|
|
|
env = true; //We have opened a new environment
|
|
|
|
}
|
|
|
|
if (f.shape() != INHERIT_SHAPE) {
|
|
|
|
os << '\\'
|
|
|
|
<< LaTeXShapeNames[f.shape()]
|
|
|
|
<< '{';
|
2001-06-01 10:53:24 +00:00
|
|
|
count += strlen(LaTeXShapeNames[f.shape()]) + 2;
|
2000-03-06 02:42:40 +00:00
|
|
|
env = true; //We have opened a new environment
|
|
|
|
}
|
2007-10-25 12:41:02 +00:00
|
|
|
if (f.color() != Color_inherit && f.color() != Color_ignore) {
|
2018-01-03 12:20:05 +00:00
|
|
|
if (f.color() == Color_none && p.color() != Color_none) {
|
|
|
|
// Color none: Close previous color, if any
|
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
} else if (f.color() != Color_none) {
|
|
|
|
os << "\\textcolor{"
|
|
|
|
<< from_ascii(lcolor.getLaTeXName(f.color()))
|
|
|
|
<< "}{";
|
|
|
|
count += lcolor.getLaTeXName(f.color()).length() + 13;
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
env = true; //We have opened a new environment
|
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
// FIXME: uncomment this when we support background.
|
|
|
|
/*
|
|
|
|
if (f.background() != Color_inherit && f.background() != Color_ignore) {
|
|
|
|
os << "\\textcolor{"
|
|
|
|
<< from_ascii(lcolor.getLaTeXName(f.background()))
|
|
|
|
<< "}{";
|
|
|
|
count += lcolor.getLaTeXName(f.background()).length() + 13;
|
|
|
|
env = true; //We have opened a new environment
|
|
|
|
}
|
|
|
|
*/
|
2018-07-21 13:50:35 +00:00
|
|
|
// If the current language is Hebrew, Arabic, or Farsi
|
|
|
|
// the numbers are written Left-to-Right. ArabTeX package
|
2019-07-11 07:54:28 +00:00
|
|
|
// and bidi (polyglossia with XeTeX) reorder the number automatically
|
2018-07-21 13:50:35 +00:00
|
|
|
// but the packages used for Hebrew and Farsi (Arabi) do not.
|
2019-07-11 07:54:28 +00:00
|
|
|
if (!(runparams.use_polyglossia && runparams.flavor == OutputParams::XETEX)
|
2018-07-21 13:50:35 +00:00
|
|
|
&& !runparams.pass_thru
|
|
|
|
&& bits_.number() == FONT_ON
|
|
|
|
&& prev.fontInfo().number() != FONT_ON
|
|
|
|
&& (language()->lang() == "hebrew"
|
|
|
|
|| language()->lang() == "farsi"
|
|
|
|
|| language()->lang() == "arabic_arabi")) {
|
2019-07-11 07:54:28 +00:00
|
|
|
if (runparams.use_polyglossia) {
|
|
|
|
// LuaTeX/luabidi
|
|
|
|
os << "\\LR{";
|
|
|
|
count += 5;
|
|
|
|
} else {
|
|
|
|
os << "{\\beginL ";
|
|
|
|
count += 9;
|
|
|
|
}
|
2018-07-21 13:50:35 +00:00
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
if (f.emph() == FONT_ON) {
|
2000-03-06 02:42:40 +00:00
|
|
|
os << "\\emph{";
|
|
|
|
count += 6;
|
|
|
|
env = true; //We have opened a new environment
|
|
|
|
}
|
2013-07-11 09:37:49 +00:00
|
|
|
// \noun{} is a LyX special macro
|
|
|
|
if (f.noun() == FONT_ON) {
|
|
|
|
os << "\\noun{";
|
|
|
|
count += 6;
|
|
|
|
env = true; //We have opened a new environment
|
|
|
|
}
|
|
|
|
if (f.size() != FONT_SIZE_INHERIT) {
|
|
|
|
// If we didn't open an environment above, we open one here
|
|
|
|
if (!env) {
|
|
|
|
os << '{';
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
os << '\\'
|
|
|
|
<< LaTeXSizeNames[f.size()]
|
|
|
|
<< "{}";
|
|
|
|
count += strlen(LaTeXSizeNames[f.size()]) + 3;
|
|
|
|
}
|
|
|
|
// The ulem commands need to be on the deepest nesting level
|
|
|
|
// because ulem puts every nested group or macro in a box,
|
|
|
|
// which prevents linebreaks (#8424, #8733)
|
2007-10-28 18:51:54 +00:00
|
|
|
if (f.underbar() == FONT_ON) {
|
2009-05-07 10:57:52 +00:00
|
|
|
os << "\\uline{";
|
2000-03-06 02:42:40 +00:00
|
|
|
count += 10;
|
2014-03-22 11:25:25 +00:00
|
|
|
++runparams.inulemcmd;
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
2018-05-04 17:32:38 +00:00
|
|
|
if (f.uuline() == FONT_ON) {
|
|
|
|
os << "\\uuline{";
|
|
|
|
count += 11;
|
|
|
|
++runparams.inulemcmd;
|
|
|
|
}
|
2009-05-03 22:45:14 +00:00
|
|
|
if (f.strikeout() == FONT_ON) {
|
2009-05-07 10:57:52 +00:00
|
|
|
os << "\\sout{";
|
2009-05-06 10:20:40 +00:00
|
|
|
count += 9;
|
2014-03-22 11:25:25 +00:00
|
|
|
++runparams.inulemcmd;
|
2009-05-03 22:45:14 +00:00
|
|
|
}
|
2017-04-04 22:01:19 +00:00
|
|
|
if (f.xout() == FONT_ON) {
|
|
|
|
os << "\\xout{";
|
|
|
|
count += 9;
|
|
|
|
++runparams.inulemcmd;
|
|
|
|
}
|
2009-05-05 09:26:28 +00:00
|
|
|
if (f.uwave() == FONT_ON) {
|
2018-05-04 17:32:38 +00:00
|
|
|
if (runparams.inulemcmd) {
|
|
|
|
// needed with nested uwave in xout
|
|
|
|
// see https://tex.stackexchange.com/a/263042
|
|
|
|
os << "\\ULdepth=1000pt";
|
|
|
|
count += 15;
|
|
|
|
}
|
2009-05-07 10:57:52 +00:00
|
|
|
os << "\\uwave{";
|
2009-05-06 10:20:40 +00:00
|
|
|
count += 10;
|
2014-03-22 11:25:25 +00:00
|
|
|
++runparams.inulemcmd;
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
/// Writes ending block of LaTeX needed to close use of this font
|
|
|
|
// Returns number of chars written
|
|
|
|
// This one corresponds to latexWriteStartChanges(). (Asger)
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
int Font::latexWriteEndChanges(otexstream & os, BufferParams const & bparams,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const & runparams,
|
|
|
|
Font const & base,
|
2007-07-20 01:28:20 +00:00
|
|
|
Font const & next,
|
2017-06-03 15:26:05 +00:00
|
|
|
bool & needPar,
|
2007-07-20 01:28:20 +00:00
|
|
|
bool const & closeLanguage) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
bool env = false;
|
|
|
|
|
2002-08-24 22:02:30 +00:00
|
|
|
// reduce the current font to changes against the base
|
|
|
|
// font (of the layout). We use a temporary for this to
|
|
|
|
// avoid changing this font instance, as that would break
|
2007-10-28 18:51:54 +00:00
|
|
|
FontInfo f = bits_;
|
|
|
|
f.reduce(base.bits_);
|
2000-10-09 12:30:52 +00:00
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
if (f.family() != INHERIT_FAMILY) {
|
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
env = true; // Size change need not bother about closing env.
|
|
|
|
}
|
|
|
|
if (f.series() != INHERIT_SERIES) {
|
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
env = true; // Size change need not bother about closing env.
|
|
|
|
}
|
|
|
|
if (f.shape() != INHERIT_SHAPE) {
|
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
env = true; // Size change need not bother about closing env.
|
|
|
|
}
|
2018-01-03 12:20:05 +00:00
|
|
|
if (f.color() != Color_inherit && f.color() != Color_ignore && f.color() != Color_none) {
|
2000-03-06 02:42:40 +00:00
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
env = true; // Size change need not bother about closing env.
|
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
if (f.emph() == FONT_ON) {
|
2000-03-06 02:42:40 +00:00
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
env = true; // Size change need not bother about closing env.
|
|
|
|
}
|
2013-07-11 09:37:49 +00:00
|
|
|
if (f.noun() == FONT_ON) {
|
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
env = true; // Size change need not bother about closing env.
|
|
|
|
}
|
|
|
|
if (f.size() != FONT_SIZE_INHERIT) {
|
|
|
|
// We only have to close if only size changed
|
|
|
|
if (!env) {
|
2017-06-04 01:12:41 +00:00
|
|
|
if (needPar && !closeLanguage) {
|
2017-06-03 15:26:05 +00:00
|
|
|
os << "\\par";
|
|
|
|
count += 4;
|
|
|
|
needPar = false;
|
|
|
|
}
|
2013-07-11 09:37:49 +00:00
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
if (f.underbar() == FONT_ON) {
|
2000-03-06 02:42:40 +00:00
|
|
|
os << '}';
|
|
|
|
++count;
|
2014-03-22 11:25:25 +00:00
|
|
|
--runparams.inulemcmd;
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
2009-05-03 22:45:14 +00:00
|
|
|
if (f.strikeout() == FONT_ON) {
|
|
|
|
os << '}';
|
|
|
|
++count;
|
2014-03-22 11:25:25 +00:00
|
|
|
--runparams.inulemcmd;
|
2009-05-03 22:45:14 +00:00
|
|
|
}
|
2017-04-04 22:01:19 +00:00
|
|
|
if (f.xout() == FONT_ON) {
|
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
--runparams.inulemcmd;
|
|
|
|
}
|
2009-05-05 09:26:28 +00:00
|
|
|
if (f.uuline() == FONT_ON) {
|
|
|
|
os << '}';
|
|
|
|
++count;
|
2014-03-22 11:25:25 +00:00
|
|
|
--runparams.inulemcmd;
|
2009-05-05 09:26:28 +00:00
|
|
|
}
|
|
|
|
if (f.uwave() == FONT_ON) {
|
|
|
|
os << '}';
|
|
|
|
++count;
|
2014-03-22 11:25:25 +00:00
|
|
|
--runparams.inulemcmd;
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
2000-03-17 10:14:46 +00:00
|
|
|
|
2013-07-11 09:37:49 +00:00
|
|
|
// If the current language is Hebrew, Arabic, or Farsi
|
2007-05-28 22:27:45 +00:00
|
|
|
// the numbers are written Left-to-Right. ArabTeX package
|
2019-07-11 07:54:28 +00:00
|
|
|
// and bidi (polyglossia with XeTeX) reorder the number automatically
|
2018-02-26 16:06:31 +00:00
|
|
|
// but the packages used for Hebrew and Farsi (Arabi) do not.
|
2019-07-11 07:54:28 +00:00
|
|
|
if (!(runparams.use_polyglossia && runparams.flavor == OutputParams::XETEX)
|
2018-02-26 16:06:31 +00:00
|
|
|
&& !runparams.pass_thru
|
|
|
|
&& bits_.number() == FONT_ON
|
2016-10-21 08:40:19 +00:00
|
|
|
&& next.fontInfo().number() != FONT_ON
|
|
|
|
&& (language()->lang() == "hebrew"
|
|
|
|
|| language()->lang() == "farsi"
|
|
|
|
|| language()->lang() == "arabic_arabi")) {
|
2019-07-11 07:54:28 +00:00
|
|
|
if (runparams.use_polyglossia) {
|
|
|
|
// LuaTeX/luabidi
|
|
|
|
os << "}";
|
|
|
|
count += 1;
|
|
|
|
} else {
|
|
|
|
os << "\\endL}";
|
|
|
|
count += 6;
|
|
|
|
}
|
2000-10-09 12:30:52 +00:00
|
|
|
}
|
|
|
|
|
2007-05-06 20:26:02 +00:00
|
|
|
if (open_encoding_) {
|
|
|
|
// We need to close the encoding even if it does not change
|
|
|
|
// to do correct environment nesting
|
2008-03-21 21:47:37 +00:00
|
|
|
Encoding const * const ascii = encodings.fromLyXName("ascii");
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
pair<bool, int> const c = switchEncoding(os.os(), bparams,
|
2007-12-17 10:53:38 +00:00
|
|
|
runparams, *ascii);
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(c.first);
|
2007-07-05 19:19:41 +00:00
|
|
|
count += c.second;
|
2007-05-06 20:26:02 +00:00
|
|
|
runparams.encoding = ascii;
|
|
|
|
open_encoding_ = false;
|
|
|
|
}
|
|
|
|
|
2012-06-24 13:14:31 +00:00
|
|
|
if (closeLanguage
|
|
|
|
&& language() != base.language() && language() != next.language()
|
|
|
|
&& language()->encoding()->package() != Encoding::CJK) {
|
2002-11-27 10:30:28 +00:00
|
|
|
os << '}';
|
2000-10-09 12:30:52 +00:00
|
|
|
++count;
|
2017-05-30 15:49:59 +00:00
|
|
|
bool const using_begin_end =
|
|
|
|
runparams.use_polyglossia ||
|
|
|
|
!lyxrc.language_command_end.empty();
|
|
|
|
if (using_begin_end)
|
|
|
|
popLanguageName();
|
2000-10-09 12:30:52 +00:00
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
string Font::toString(bool const toggle) const
|
2007-09-29 11:00:18 +00:00
|
|
|
{
|
2008-05-07 23:33:56 +00:00
|
|
|
string const lang = (language() == reset_language)
|
|
|
|
? "reset" : language()->lang();
|
2007-09-29 11:00:18 +00:00
|
|
|
|
|
|
|
ostringstream os;
|
2007-10-29 22:03:59 +00:00
|
|
|
os << "family " << bits_.family() << '\n'
|
2007-10-28 18:51:54 +00:00
|
|
|
<< "series " << bits_.series() << '\n'
|
|
|
|
<< "shape " << bits_.shape() << '\n'
|
|
|
|
<< "size " << bits_.size() << '\n'
|
|
|
|
<< "emph " << bits_.emph() << '\n'
|
|
|
|
<< "underbar " << bits_.underbar() << '\n'
|
2009-05-03 22:45:14 +00:00
|
|
|
<< "strikeout " << bits_.strikeout() << '\n'
|
2017-04-04 22:01:19 +00:00
|
|
|
<< "xout " << bits_.xout() << '\n'
|
2009-05-05 09:26:28 +00:00
|
|
|
<< "uuline " << bits_.uuline() << '\n'
|
|
|
|
<< "uwave " << bits_.uwave() << '\n'
|
2007-10-28 18:51:54 +00:00
|
|
|
<< "noun " << bits_.noun() << '\n'
|
|
|
|
<< "number " << bits_.number() << '\n'
|
|
|
|
<< "color " << bits_.color() << '\n'
|
2007-09-29 11:00:18 +00:00
|
|
|
<< "language " << lang << '\n'
|
|
|
|
<< "toggleall " << convert<string>(toggle);
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Font::fromString(string const & data, bool & toggle)
|
|
|
|
{
|
|
|
|
istringstream is(data);
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lex;
|
2007-09-29 11:00:18 +00:00
|
|
|
lex.setStream(is);
|
|
|
|
|
|
|
|
int nset = 0;
|
|
|
|
while (lex.isOK()) {
|
|
|
|
string token;
|
|
|
|
if (lex.next())
|
|
|
|
token = lex.getString();
|
|
|
|
|
|
|
|
if (token.empty() || !lex.next())
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (token == "family") {
|
|
|
|
int const next = lex.getInteger();
|
2007-10-28 18:51:54 +00:00
|
|
|
bits_.setFamily(FontFamily(next));
|
2007-09-29 11:00:18 +00:00
|
|
|
|
|
|
|
} else if (token == "series") {
|
|
|
|
int const next = lex.getInteger();
|
2007-10-28 18:51:54 +00:00
|
|
|
bits_.setSeries(FontSeries(next));
|
2007-09-29 11:00:18 +00:00
|
|
|
|
|
|
|
} else if (token == "shape") {
|
|
|
|
int const next = lex.getInteger();
|
2007-10-28 18:51:54 +00:00
|
|
|
bits_.setShape(FontShape(next));
|
2007-09-29 11:00:18 +00:00
|
|
|
|
|
|
|
} else if (token == "size") {
|
|
|
|
int const next = lex.getInteger();
|
2007-10-28 18:51:54 +00:00
|
|
|
bits_.setSize(FontSize(next));
|
2007-09-29 11:00:18 +00:00
|
|
|
|
2017-04-04 22:01:19 +00:00
|
|
|
} else if (token == "emph" || token == "underbar"
|
|
|
|
|| token == "noun" || token == "number"
|
|
|
|
|| token == "uuline" || token == "uwave"
|
|
|
|
|| token == "strikeout" || token == "xout") {
|
2007-09-29 11:00:18 +00:00
|
|
|
|
|
|
|
int const next = lex.getInteger();
|
2007-10-28 18:51:54 +00:00
|
|
|
FontState const misc = FontState(next);
|
2007-09-29 11:00:18 +00:00
|
|
|
|
|
|
|
if (token == "emph")
|
2007-10-28 18:51:54 +00:00
|
|
|
bits_.setEmph(misc);
|
2007-09-29 11:00:18 +00:00
|
|
|
else if (token == "underbar")
|
2007-10-28 18:51:54 +00:00
|
|
|
bits_.setUnderbar(misc);
|
2009-05-03 22:45:14 +00:00
|
|
|
else if (token == "strikeout")
|
|
|
|
bits_.setStrikeout(misc);
|
2017-04-04 22:01:19 +00:00
|
|
|
else if (token == "xout")
|
|
|
|
bits_.setXout(misc);
|
2009-05-05 09:26:28 +00:00
|
|
|
else if (token == "uuline")
|
|
|
|
bits_.setUuline(misc);
|
|
|
|
else if (token == "uwave")
|
|
|
|
bits_.setUwave(misc);
|
2007-09-29 11:00:18 +00:00
|
|
|
else if (token == "noun")
|
2007-10-28 18:51:54 +00:00
|
|
|
bits_.setNoun(misc);
|
2007-09-29 11:00:18 +00:00
|
|
|
else if (token == "number")
|
2007-10-28 18:51:54 +00:00
|
|
|
bits_.setNumber(misc);
|
2007-09-29 11:00:18 +00:00
|
|
|
|
|
|
|
} else if (token == "color") {
|
|
|
|
int const next = lex.getInteger();
|
2007-10-28 18:51:54 +00:00
|
|
|
bits_.setColor(ColorCode(next));
|
|
|
|
|
|
|
|
/**
|
|
|
|
} else if (token == "background") {
|
|
|
|
int const next = lex.getInteger();
|
|
|
|
bits_.setBackground(ColorCode(next));
|
|
|
|
*/
|
2007-09-29 11:00:18 +00:00
|
|
|
|
|
|
|
} else if (token == "language") {
|
|
|
|
string const next = lex.getString();
|
2008-05-07 23:33:56 +00:00
|
|
|
setLanguage(languages.getLanguage(next));
|
2007-09-29 11:00:18 +00:00
|
|
|
|
|
|
|
} else if (token == "toggleall") {
|
|
|
|
toggle = lex.getBool();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Unrecognised token
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++nset;
|
|
|
|
}
|
|
|
|
return (nset > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-19 16:22:36 +00:00
|
|
|
void Font::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
BufferParams const & bparams = features.bufferParams();
|
|
|
|
Language const * doc_language = bparams.language;
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
if (bits_.noun() == FONT_ON) {
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::LATEX, "font.noun: " << bits_.noun());
|
2007-10-19 16:22:36 +00:00
|
|
|
features.require("noun");
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::LATEX, "Noun enabled. Font: " << to_utf8(stateText(0)));
|
2007-10-19 16:22:36 +00:00
|
|
|
}
|
2009-05-05 11:51:55 +00:00
|
|
|
if (bits_.underbar() == FONT_ON) {
|
2009-05-06 10:20:40 +00:00
|
|
|
LYXERR(Debug::LATEX, "font.underline: " << bits_.underbar());
|
2009-05-05 11:51:55 +00:00
|
|
|
features.require("ulem");
|
|
|
|
LYXERR(Debug::LATEX, "Underline enabled. Font: " << to_utf8(stateText(0)));
|
|
|
|
}
|
2009-05-03 22:45:14 +00:00
|
|
|
if (bits_.strikeout() == FONT_ON) {
|
|
|
|
LYXERR(Debug::LATEX, "font.strikeout: " << bits_.strikeout());
|
|
|
|
features.require("ulem");
|
2017-04-04 22:01:19 +00:00
|
|
|
LYXERR(Debug::LATEX, "Strike out enabled. Font: " << to_utf8(stateText(0)));
|
|
|
|
}
|
|
|
|
if (bits_.xout() == FONT_ON) {
|
|
|
|
LYXERR(Debug::LATEX, "font.xout: " << bits_.xout());
|
|
|
|
features.require("ulem");
|
|
|
|
LYXERR(Debug::LATEX, "Cross out enabled. Font: " << to_utf8(stateText(0)));
|
2009-05-03 22:45:14 +00:00
|
|
|
}
|
2009-05-05 09:26:28 +00:00
|
|
|
if (bits_.uuline() == FONT_ON) {
|
|
|
|
LYXERR(Debug::LATEX, "font.uuline: " << bits_.uuline());
|
|
|
|
features.require("ulem");
|
|
|
|
LYXERR(Debug::LATEX, "Double underline enabled. Font: " << to_utf8(stateText(0)));
|
|
|
|
}
|
|
|
|
if (bits_.uwave() == FONT_ON) {
|
|
|
|
LYXERR(Debug::LATEX, "font.uwave: " << bits_.uwave());
|
|
|
|
features.require("ulem");
|
|
|
|
LYXERR(Debug::LATEX, "Wavy underline enabled. Font: " << to_utf8(stateText(0)));
|
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
switch (bits_.color()) {
|
2007-10-25 12:41:02 +00:00
|
|
|
case Color_none:
|
|
|
|
case Color_inherit:
|
|
|
|
case Color_ignore:
|
2007-10-19 16:22:36 +00:00
|
|
|
// probably we should put here all interface colors used for
|
|
|
|
// font displaying! For now I just add this ones I know of (Jug)
|
2007-10-25 12:41:02 +00:00
|
|
|
case Color_latex:
|
2008-03-01 23:50:08 +00:00
|
|
|
case Color_notelabel:
|
2007-10-19 16:22:36 +00:00
|
|
|
break;
|
2015-05-14 20:23:44 +00:00
|
|
|
case Color_brown:
|
|
|
|
case Color_darkgray:
|
|
|
|
case Color_gray:
|
|
|
|
case Color_lightgray:
|
|
|
|
case Color_lime:
|
|
|
|
case Color_olive:
|
|
|
|
case Color_orange:
|
|
|
|
case Color_pink:
|
|
|
|
case Color_purple:
|
|
|
|
case Color_teal:
|
|
|
|
case Color_violet:
|
|
|
|
features.require("xcolor");
|
2015-09-12 20:29:25 +00:00
|
|
|
break;
|
2007-10-19 16:22:36 +00:00
|
|
|
default:
|
|
|
|
features.require("color");
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::LATEX, "Color enabled. Font: " << to_utf8(stateText(0)));
|
2007-10-19 16:22:36 +00:00
|
|
|
}
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
// FIXME: Do something for background and soul package?
|
|
|
|
|
2012-06-23 11:50:40 +00:00
|
|
|
if (((features.usePolyglossia() && lang_->polyglossia() != doc_language->polyglossia())
|
2013-05-20 09:07:47 +00:00
|
|
|
|| (features.useBabel() && lang_->babel() != doc_language->babel())
|
|
|
|
|| (doc_language->encoding()->package() == Encoding::CJK && lang_ != doc_language))
|
2012-06-23 11:50:40 +00:00
|
|
|
&& lang_ != ignore_language
|
|
|
|
&& lang_ != latex_language)
|
2007-10-19 16:22:36 +00:00
|
|
|
{
|
2007-10-28 18:51:54 +00:00
|
|
|
features.useLanguage(lang_);
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::LATEX, "Found language " << lang_->lang());
|
2007-10-19 16:22:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
ostream & operator<<(ostream & os, FontState fms)
|
2003-10-21 16:15:14 +00:00
|
|
|
{
|
|
|
|
return os << int(fms);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
ostream & operator<<(ostream & os, FontInfo const & f)
|
1999-10-07 18:44:17 +00:00
|
|
|
{
|
2003-10-21 16:15:14 +00:00
|
|
|
return os << "font:"
|
2007-10-28 18:51:54 +00:00
|
|
|
<< " family " << f.family()
|
|
|
|
<< " series " << f.series()
|
|
|
|
<< " shape " << f.shape()
|
|
|
|
<< " size " << f.size()
|
|
|
|
<< " color " << f.color()
|
|
|
|
// FIXME: uncomment this when we support background.
|
|
|
|
//<< " background " << f.background()
|
|
|
|
<< " emph " << f.emph()
|
|
|
|
<< " underbar " << f.underbar()
|
2009-05-03 22:45:14 +00:00
|
|
|
<< " strikeout " << f.strikeout()
|
2017-04-04 22:01:19 +00:00
|
|
|
<< " xout " << f.xout()
|
2009-05-05 09:26:28 +00:00
|
|
|
<< " uuline " << f.uuline()
|
|
|
|
<< " uwave " << f.uwave()
|
2007-10-28 18:51:54 +00:00
|
|
|
<< " noun " << f.noun()
|
|
|
|
<< " number " << f.number();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
ostream & operator<<(ostream & os, Font const & font)
|
2007-10-28 18:51:54 +00:00
|
|
|
{
|
|
|
|
return os << font.bits_
|
|
|
|
<< " lang: " << (font.lang_ ? font.lang_->lang() : 0);
|
1999-10-07 18:44:17 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|