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];
|
2019-05-10 08:43:01 +00:00
|
|
|
extern char const * GUIMiscNames[5];
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
//
|
|
|
|
// Strings used to write LaTeX files
|
|
|
|
//
|
2020-07-29 14:25:19 +00:00
|
|
|
char const * LaTeXFamilyCommandNames[NUM_FAMILIES + 2] =
|
2012-12-09 12:04:29 +00:00
|
|
|
{ "textrm", "textsf", "texttt", "error1", "error2", "error3", "error4",
|
|
|
|
"error5", "error6", "error7", "error8", "error9", "error10", "error11",
|
2020-06-12 09:50:58 +00:00
|
|
|
"error12", "error13", "error14" };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2020-07-29 14:25:19 +00:00
|
|
|
char const * LaTeXFamilySwitchNames[NUM_FAMILIES + 2] =
|
|
|
|
{ "rmfamily", "sffamily", "ttfamily", "error1", "error2", "error3", "error4",
|
|
|
|
"error5", "error6", "error7", "error8", "error9", "error10", "error11",
|
|
|
|
"error12", "error13", "error14" };
|
|
|
|
|
|
|
|
char const * LaTeXSeriesCommandNames[NUM_SERIES + 2] =
|
1999-09-27 18:44:28 +00:00
|
|
|
{ "textmd", "textbf", "error4", "error5" };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2020-07-29 14:25:19 +00:00
|
|
|
char const * LaTeXSeriesSwitchNames[NUM_SERIES + 2] =
|
|
|
|
{ "mdseries", "bfseries", "error4", "error5" };
|
|
|
|
|
|
|
|
char const * LaTeXShapeCommandNames[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
|
|
|
|
2020-07-29 14:25:19 +00:00
|
|
|
char const * LaTeXShapeSwitchNames[NUM_SHAPE + 2] =
|
|
|
|
{ "upshape", "itshape", "slshape", "scshape", "error6", "error7" };
|
|
|
|
|
|
|
|
char const * LaTeXSizeSwitchNames[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,
|
2020-10-31 17:18:51 +00:00
|
|
|
Language const * default_lang,
|
2001-08-11 18:31:14 +00:00
|
|
|
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)
|
2020-10-31 17:18:51 +00:00
|
|
|
if (language() == default_lang)
|
2001-08-11 18:31:14 +00:00
|
|
|
setLanguage(default_language);
|
|
|
|
else
|
2020-10-31 17:18:51 +00:00
|
|
|
setLanguage(default_lang);
|
2008-05-07 23:33:56 +00:00
|
|
|
else if (newfont.language() == reset_language)
|
2020-10-31 17:18:51 +00:00
|
|
|
setLanguage(default_lang);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-26 14:46:14 +00:00
|
|
|
docstring const Font::stateText(BufferParams * params, bool const terse) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2006-12-21 14:31:19 +00:00
|
|
|
odocstringstream os;
|
2019-05-10 08:43:01 +00:00
|
|
|
os << bits_.stateText(terse);
|
2018-12-26 14:46:14 +00:00
|
|
|
if ((!params || (language() != params->language))
|
|
|
|
&& (!terse || language() != ignore_language)) {
|
2018-12-26 13:38:02 +00:00
|
|
|
// reset_language is a null pointer!
|
2006-12-21 14:31:19 +00:00
|
|
|
os << bformat(_("Language: %1$s, "),
|
2018-12-26 13:38:02 +00:00
|
|
|
(language() == reset_language) ? _("Default")
|
|
|
|
: _(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
|
|
|
{
|
2020-07-29 14:25:19 +00:00
|
|
|
return LaTeXSizeSwitchNames[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";
|
2019-03-22 14:19:27 +00:00
|
|
|
// FIXME: shall style be handled there? Probably not.
|
2007-10-28 18:51:54 +00:00
|
|
|
if (orgfont.fontInfo().emph() != bits_.emph())
|
|
|
|
os << "\\emph " << LyXMiscNames[bits_.emph()] << "\n";
|
|
|
|
if (orgfont.fontInfo().number() != bits_.number())
|
|
|
|
os << "\\numeric " << LyXMiscNames[bits_.number()] << "\n";
|
2018-05-06 17:48:21 +00:00
|
|
|
if (orgfont.fontInfo().nospellcheck() != bits_.nospellcheck())
|
|
|
|
os << "\\nospellcheck " << LyXMiscNames[bits_.nospellcheck()] << "\n";
|
2007-10-28 18:51:54 +00:00
|
|
|
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.
|
2020-07-29 14:25:19 +00:00
|
|
|
int Font::latexWriteStartChanges(otexstream & os, BufferParams const & bparams,
|
2007-05-28 22:27:45 +00:00
|
|
|
OutputParams const & runparams,
|
|
|
|
Font const & base,
|
2020-07-29 14:25:19 +00:00
|
|
|
Font const & prev,
|
2020-10-16 07:19:34 +00:00
|
|
|
bool non_inherit_inset,
|
|
|
|
bool needs_cprotection) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
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()) {
|
2020-08-12 13:26:23 +00:00
|
|
|
string tmp;
|
2020-08-12 16:08:49 +00:00
|
|
|
if (needs_cprotection)
|
2020-08-12 13:26:23 +00:00
|
|
|
tmp += "\\cprotect";
|
|
|
|
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-08-12 13:26:23 +00:00
|
|
|
if (runparams.use_hyperref && runparams.moving_arg) {
|
2020-04-05 13:23:22 +00:00
|
|
|
// We need to strip the command for
|
|
|
|
// the pdf string, see #11813
|
2020-08-12 13:26:23 +00:00
|
|
|
string tmpp;
|
2020-08-12 16:08:49 +00:00
|
|
|
if (needs_cprotection)
|
2020-08-12 13:26:23 +00:00
|
|
|
tmpp = "\\cprotect";
|
|
|
|
tmp = tmpp + "\\texorpdfstring{" + tmp + "}{}";
|
|
|
|
}
|
2020-04-05 13:23:22 +00:00
|
|
|
}
|
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") {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2007-05-14 09:34:53 +00:00
|
|
|
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") {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2007-05-14 09:34:53 +00:00
|
|
|
os << "\\textLR{";
|
|
|
|
count += 8;
|
2007-06-26 00:11:03 +00:00
|
|
|
} else if (language()->lang() == "arabic_arabi") {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2007-06-26 00:11:03 +00:00
|
|
|
os << "\\textAR{";
|
|
|
|
count += 8;
|
|
|
|
} else if (!isRightToLeft() &&
|
|
|
|
base.language()->lang() == "arabic_arabi") {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2007-06-26 00:11:03 +00:00
|
|
|
os << "\\textLR{";
|
|
|
|
count += 8;
|
|
|
|
// currently the remaining RTL languages are arabic_arabtex and hebrew
|
2022-12-23 09:04:41 +00:00
|
|
|
} else if (isRightToLeft() != prev.isRightToLeft() && !runparams.isFullUnicode()) {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
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) {
|
2020-07-29 14:25:19 +00:00
|
|
|
pair<bool, int> const c = switchEncoding(os.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
|
|
|
|
2020-07-15 07:11:05 +00:00
|
|
|
if (f.size() != INHERIT_SIZE) {
|
2022-05-09 20:06:02 +00:00
|
|
|
if (!runparams.find_effective()) {
|
2022-04-30 07:30:15 +00:00
|
|
|
os << '{';
|
|
|
|
++count;
|
|
|
|
os << '\\'
|
|
|
|
<< LaTeXSizeSwitchNames[f.size()] << termcmd;
|
|
|
|
count += strlen(LaTeXSizeSwitchNames[f.size()]) + 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
os << '\\'
|
|
|
|
<< LaTeXSizeSwitchNames[f.size()] << '{';
|
|
|
|
count += strlen(LaTeXSizeSwitchNames[f.size()]) + 2;
|
|
|
|
}
|
2020-07-15 07:11:05 +00:00
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
if (f.family() != INHERIT_FAMILY) {
|
2020-08-14 16:01:26 +00:00
|
|
|
if (non_inherit_inset) {
|
2020-07-29 14:25:19 +00:00
|
|
|
os << '{';
|
|
|
|
++count;
|
|
|
|
os << '\\' << LaTeXFamilySwitchNames[f.family()] << termcmd;
|
|
|
|
count += strlen(LaTeXFamilySwitchNames[f.family()]) + 1;
|
|
|
|
} else {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2020-07-29 14:25:19 +00:00
|
|
|
os << '\\'
|
|
|
|
<< LaTeXFamilyCommandNames[f.family()]
|
|
|
|
<< '{';
|
|
|
|
count += strlen(LaTeXFamilyCommandNames[f.family()]) + 2;
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
if (f.series() != INHERIT_SERIES) {
|
2020-08-14 16:01:26 +00:00
|
|
|
if (non_inherit_inset) {
|
2020-07-29 14:25:19 +00:00
|
|
|
os << '{';
|
|
|
|
++count;
|
|
|
|
os << '\\' << LaTeXSeriesSwitchNames[f.series()] << termcmd;
|
|
|
|
count += strlen(LaTeXSeriesSwitchNames[f.series()]) + 1;
|
|
|
|
} else {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2020-07-29 14:25:19 +00:00
|
|
|
os << '\\'
|
|
|
|
<< LaTeXSeriesCommandNames[f.series()]
|
|
|
|
<< '{';
|
|
|
|
count += strlen(LaTeXSeriesCommandNames[f.series()]) + 2;
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
|
|
|
if (f.shape() != INHERIT_SHAPE) {
|
2020-08-14 16:01:26 +00:00
|
|
|
if (non_inherit_inset) {
|
2020-07-29 14:25:19 +00:00
|
|
|
os << '{';
|
|
|
|
++count;
|
|
|
|
os << '\\' << LaTeXShapeSwitchNames[f.shape()] << termcmd;
|
|
|
|
count += strlen(LaTeXShapeSwitchNames[f.shape()]) + 1;
|
|
|
|
} else {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2020-07-29 14:25:19 +00:00
|
|
|
os << '\\'
|
|
|
|
<< LaTeXShapeCommandNames[f.shape()]
|
|
|
|
<< '{';
|
|
|
|
count += strlen(LaTeXShapeCommandNames[f.shape()]) + 2;
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
2020-08-14 16:01:26 +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
|
|
|
}
|
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.
|
2023-08-17 12:25:33 +00:00
|
|
|
if (!bparams.useBidiPackage(runparams)
|
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
|
2023-04-10 13:16:20 +00:00
|
|
|
// \LR needs extra grouping
|
|
|
|
// (possibly a LuaTeX bug)
|
|
|
|
os << "{\\LR{";
|
|
|
|
count += 6;
|
2023-04-10 13:31:26 +00:00
|
|
|
} else if (!runparams.isFullUnicode()) {
|
|
|
|
// not needed with babel/lua|xetex
|
2019-07-11 07:54:28 +00:00
|
|
|
os << "{\\beginL ";
|
|
|
|
count += 9;
|
|
|
|
}
|
2018-07-21 13:50:35 +00:00
|
|
|
}
|
2020-08-14 16:01:26 +00:00
|
|
|
if (f.emph() == FONT_ON) {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
os << "\\emph{";
|
|
|
|
count += 6;
|
|
|
|
}
|
2013-07-11 09:37:49 +00:00
|
|
|
// \noun{} is a LyX special macro
|
2020-08-14 16:01:26 +00:00
|
|
|
if (f.noun() == FONT_ON) {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2013-07-11 09:37:49 +00:00
|
|
|
os << "\\noun{";
|
|
|
|
count += 6;
|
|
|
|
}
|
|
|
|
// 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)
|
2020-08-14 16:01:26 +00:00
|
|
|
if (f.underbar() == FONT_ON) {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2009-05-07 10:57:52 +00:00
|
|
|
os << "\\uline{";
|
2020-08-12 13:26:23 +00:00
|
|
|
count += 7;
|
2014-03-22 11:25:25 +00:00
|
|
|
++runparams.inulemcmd;
|
2000-03-06 02:42:40 +00:00
|
|
|
}
|
2020-08-14 16:01:26 +00:00
|
|
|
if (f.uuline() == FONT_ON) {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2018-05-04 17:32:38 +00:00
|
|
|
os << "\\uuline{";
|
2020-08-12 13:26:23 +00:00
|
|
|
count += 8;
|
2018-05-04 17:32:38 +00:00
|
|
|
++runparams.inulemcmd;
|
|
|
|
}
|
2020-08-14 16:01:26 +00:00
|
|
|
if (f.strikeout() == FONT_ON) {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2009-05-07 10:57:52 +00:00
|
|
|
os << "\\sout{";
|
2020-08-12 13:26:23 +00:00
|
|
|
count += 6;
|
2014-03-22 11:25:25 +00:00
|
|
|
++runparams.inulemcmd;
|
2009-05-03 22:45:14 +00:00
|
|
|
}
|
2020-08-14 16:01:26 +00:00
|
|
|
if (f.xout() == FONT_ON) {
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2017-04-04 22:01:19 +00:00
|
|
|
os << "\\xout{";
|
2020-08-12 13:26:23 +00:00
|
|
|
count += 6;
|
2017-04-04 22:01:19 +00:00
|
|
|
++runparams.inulemcmd;
|
|
|
|
}
|
2020-08-14 16:01:26 +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;
|
|
|
|
}
|
2020-08-12 13:26:23 +00:00
|
|
|
if (needs_cprotection) {
|
|
|
|
os << "\\cprotect";
|
|
|
|
count += 9;
|
|
|
|
}
|
2009-05-07 10:57:52 +00:00
|
|
|
os << "\\uwave{";
|
2020-08-12 13:26:23 +00:00
|
|
|
count += 7;
|
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,
|
2020-10-16 07:19:34 +00:00
|
|
|
bool closeLanguage) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
|
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
|
|
|
|
2020-08-14 16:01:26 +00:00
|
|
|
if (f.family() != INHERIT_FAMILY) {
|
2000-03-06 02:42:40 +00:00
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
}
|
2020-08-14 16:01:26 +00:00
|
|
|
if (f.series() != INHERIT_SERIES) {
|
2000-03-06 02:42:40 +00:00
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
}
|
2020-08-14 16:01:26 +00:00
|
|
|
if (f.shape() != INHERIT_SHAPE) {
|
2000-03-06 02:42:40 +00:00
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
}
|
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;
|
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
if (f.emph() == FONT_ON) {
|
2000-03-06 02:42:40 +00:00
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
}
|
2013-07-11 09:37:49 +00:00
|
|
|
if (f.noun() == FONT_ON) {
|
|
|
|
os << '}';
|
|
|
|
++count;
|
|
|
|
}
|
2019-06-14 14:42:02 +00:00
|
|
|
if (f.size() != INHERIT_SIZE) {
|
2020-07-15 07:11:05 +00:00
|
|
|
// We do not close size group in front of
|
2020-08-14 16:01:26 +00:00
|
|
|
// insets with InheritFont() false (as opposed
|
2020-07-15 07:11:05 +00:00
|
|
|
// to all other font properties) (#8384)
|
2020-08-14 16:01:26 +00:00
|
|
|
if (needPar && !closeLanguage) {
|
|
|
|
os << "\\par";
|
|
|
|
count += 4;
|
|
|
|
needPar = false;
|
2013-07-11 09:37:49 +00:00
|
|
|
}
|
2020-08-14 16:01:26 +00:00
|
|
|
os << '}';
|
|
|
|
++count;
|
2013-07-11 09:37:49 +00:00
|
|
|
}
|
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.
|
2023-08-17 12:25:33 +00:00
|
|
|
if (!bparams.useBidiPackage(runparams)
|
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
|
2023-04-10 13:16:20 +00:00
|
|
|
// luabidi's \LR needs extra grouping
|
|
|
|
// (possibly a LuaTeX bug)
|
|
|
|
os << "}}";
|
|
|
|
count += 2;
|
2023-04-10 13:31:26 +00:00
|
|
|
} else if (!runparams.isFullUnicode()) {
|
|
|
|
// not needed with babel/lua|xetex
|
2019-07-11 07:54:28 +00:00
|
|
|
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()
|
2019-08-21 10:33:13 +00:00
|
|
|
&& (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();
|
2022-02-04 16:23:52 +00:00
|
|
|
if (using_begin_end && !languageStackEmpty())
|
2017-05-30 15:49:59 +00:00
|
|
|
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'
|
2018-05-06 17:48:21 +00:00
|
|
|
<< "nospellcheck " << bits_.nospellcheck() << '\n'
|
2007-10-28 18:51:54 +00:00
|
|
|
<< "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));
|
2019-03-22 14:19:27 +00:00
|
|
|
// FIXME: shall style be handled there? Probably not.
|
2017-04-04 22:01:19 +00:00
|
|
|
} else if (token == "emph" || token == "underbar"
|
|
|
|
|| token == "noun" || token == "number"
|
|
|
|
|| token == "uuline" || token == "uwave"
|
2018-05-06 17:48:21 +00:00
|
|
|
|| token == "strikeout" || token == "xout"
|
|
|
|
|| token == "nospellcheck") {
|
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);
|
2018-05-06 17:48:21 +00:00
|
|
|
else if (token == "nospellcheck")
|
|
|
|
bits_.setNoSpellcheck(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) {
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "font.noun: " << bits_.noun());
|
2007-10-19 16:22:36 +00:00
|
|
|
features.require("noun");
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "Noun enabled. Font: " << to_utf8(stateText()));
|
2007-10-19 16:22:36 +00:00
|
|
|
}
|
2009-05-05 11:51:55 +00:00
|
|
|
if (bits_.underbar() == FONT_ON) {
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "font.underline: " << bits_.underbar());
|
2009-05-05 11:51:55 +00:00
|
|
|
features.require("ulem");
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "Underline enabled. Font: " << to_utf8(stateText()));
|
2009-05-05 11:51:55 +00:00
|
|
|
}
|
2009-05-03 22:45:14 +00:00
|
|
|
if (bits_.strikeout() == FONT_ON) {
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "font.strikeout: " << bits_.strikeout());
|
2009-05-03 22:45:14 +00:00
|
|
|
features.require("ulem");
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "Strike out enabled. Font: " << to_utf8(stateText()));
|
2017-04-04 22:01:19 +00:00
|
|
|
}
|
|
|
|
if (bits_.xout() == FONT_ON) {
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "font.xout: " << bits_.xout());
|
2017-04-04 22:01:19 +00:00
|
|
|
features.require("ulem");
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "Cross out enabled. Font: " << to_utf8(stateText()));
|
2009-05-03 22:45:14 +00:00
|
|
|
}
|
2009-05-05 09:26:28 +00:00
|
|
|
if (bits_.uuline() == FONT_ON) {
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "font.uuline: " << bits_.uuline());
|
2009-05-05 09:26:28 +00:00
|
|
|
features.require("ulem");
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "Double underline enabled. Font: " << to_utf8(stateText()));
|
2009-05-05 09:26:28 +00:00
|
|
|
}
|
|
|
|
if (bits_.uwave() == FONT_ON) {
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "font.uwave: " << bits_.uwave());
|
2009-05-05 09:26:28 +00:00
|
|
|
features.require("ulem");
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "Wavy underline enabled. Font: " << to_utf8(stateText()));
|
2009-05-05 09:26:28 +00:00
|
|
|
}
|
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");
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "Color enabled. Font: " << to_utf8(stateText()));
|
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_);
|
2022-02-27 19:35:58 +00:00
|
|
|
LYXERR(Debug::OUTFILE, "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()
|
2019-03-22 14:19:27 +00:00
|
|
|
<< " style " << f.style()
|
2007-10-28 18:51:54 +00:00
|
|
|
<< " 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()
|
2018-05-06 17:48:21 +00:00
|
|
|
<< " number " << f.number()
|
|
|
|
<< " nospellcheck " << f.nospellcheck();
|
2007-10-28 18:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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_
|
2020-10-05 10:38:09 +00:00
|
|
|
<< " lang: " << (font.lang_ ? font.lang_->lang() : "");
|
1999-10-07 18:44:17 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|