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
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
* \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
|
2007-10-19 16:22:36 +00:00
|
|
|
|
#include "Color.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"
|
2003-09-09 22:13:45 +00:00
|
|
|
|
|
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 {
|
|
|
|
|
|
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"),
|
2006-11-13 17:35:18 +00:00
|
|
|
|
"cmr", "cmsy", "cmm", "cmex", "msa", "msb", "eufrak", "wasy", "esint",
|
2001-08-30 22:42:26 +00:00
|
|
|
|
N_("Inherit"), N_("Ignore") };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
char const * GUISeriesNames[4] =
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{ N_("Medium"), N_("Bold"), N_("Inherit"), N_("Ignore") };
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
char const * GUIShapeNames[6] =
|
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
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
char const * GUISizeNames[14] =
|
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") };
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
//
|
|
|
|
|
// Strings used to read and write .lyx format files
|
|
|
|
|
//
|
2007-10-28 18:51:54 +00:00
|
|
|
|
char const * LyXFamilyNames[NUM_FAMILIES + 2 /* default & error */] =
|
2001-08-31 11:36:32 +00:00
|
|
|
|
{ "roman", "sans", "typewriter", "symbol",
|
2006-11-13 17:35:18 +00:00
|
|
|
|
"cmr", "cmsy", "cmm", "cmex", "msa", "msb", "eufrak", "wasy", "esint",
|
2001-08-31 11:36:32 +00:00
|
|
|
|
"default", "error" };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
char const * LyXSeriesNames[4] =
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{ "medium", "bold", "default", "error" };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
char const * LyXShapeNames[6] =
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{ "up", "italic", "slanted", "smallcaps", "default", "error" };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
char const * LyXSizeNames[14] =
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{ "tiny", "scriptsize", "footnotesize", "small", "normal", "large",
|
2002-03-21 17:27:08 +00:00
|
|
|
|
"larger", "largest", "huge", "giant",
|
2001-09-27 16:51:34 +00:00
|
|
|
|
"increase", "decrease", "default", "error" };
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
char const * LyXMiscNames[5] =
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{ "off", "on", "toggle", "default", "error" };
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Strings used to write LaTeX files
|
|
|
|
|
//
|
2002-03-21 17:27:08 +00:00
|
|
|
|
char const * LaTeXFamilyNames[6] =
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{ "textrm", "textsf", "texttt", "error1", "error2", "error3" };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
char const * LaTeXSeriesNames[4] =
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{ "textmd", "textbf", "error4", "error5" };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
char const * LaTeXShapeNames[6] =
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{ "textup", "textit", "textsl", "textsc", "error6", "error7" };
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
char const * LaTeXSizeNames[14] =
|
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
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
} // namespace anon
|
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)
|
|
|
|
|
: 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);
|
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()]));
|
|
|
|
|
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)
|
2006-12-21 14:31:19 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set family according to lyx format string
|
2007-10-28 18:51:54 +00:00
|
|
|
|
void setLyXFamily(string const & fam, FontInfo & f)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-16 21:17:10 +00:00
|
|
|
|
string const s = ascii_lowercase(fam);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
1999-12-15 06:12:28 +00:00
|
|
|
|
int i = 0;
|
2005-01-20 22:00:17 +00:00
|
|
|
|
while (LyXFamilyNames[i] != s &&
|
|
|
|
|
LyXFamilyNames[i] != string("error"))
|
2003-05-19 17:03:12 +00:00
|
|
|
|
++i;
|
|
|
|
|
if (s == LyXFamilyNames[i])
|
2007-10-28 18:51:54 +00:00
|
|
|
|
f.setFamily(FontFamily(i));
|
2003-05-19 17:03:12 +00:00
|
|
|
|
else
|
2007-10-28 18:51:54 +00:00
|
|
|
|
lyxerr << "setLyXFamily: Unknown family `"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
<< s << '\'' << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set series according to lyx format string
|
2007-10-28 18:51:54 +00:00
|
|
|
|
void setLyXSeries(string const & ser, FontInfo & f)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-16 21:17:10 +00:00
|
|
|
|
string const s = ascii_lowercase(ser);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
1999-12-15 06:12:28 +00:00
|
|
|
|
int i = 0;
|
2005-01-20 22:00:17 +00:00
|
|
|
|
while (LyXSeriesNames[i] != s &&
|
|
|
|
|
LyXSeriesNames[i] != string("error")) ++i;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (s == LyXSeriesNames[i]) {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
f.setSeries(FontSeries(i));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else
|
2007-10-28 18:51:54 +00:00
|
|
|
|
lyxerr << "setLyXSeries: Unknown series `"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
<< s << '\'' << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set shape according to lyx format string
|
2007-10-28 18:51:54 +00:00
|
|
|
|
void setLyXShape(string const & sha, FontInfo & f)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-16 21:17:10 +00:00
|
|
|
|
string const s = ascii_lowercase(sha);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
1999-12-15 06:12:28 +00:00
|
|
|
|
int i = 0;
|
2005-07-16 10:35:43 +00:00
|
|
|
|
while (LyXShapeNames[i] != s && LyXShapeNames[i] != string("error"))
|
|
|
|
|
++i;
|
|
|
|
|
if (s == LyXShapeNames[i])
|
2007-10-28 18:51:54 +00:00
|
|
|
|
f.setShape(FontShape(i));
|
2005-07-16 10:35:43 +00:00
|
|
|
|
else
|
2007-04-29 18:17:15 +00:00
|
|
|
|
lyxerr << "Font::setLyXShape: Unknown shape `"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
<< s << '\'' << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set size according to lyx format string
|
2007-10-28 18:51:54 +00:00
|
|
|
|
void setLyXSize(string const & siz, FontInfo & f)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-16 21:17:10 +00:00
|
|
|
|
string const s = ascii_lowercase(siz);
|
1999-12-15 06:12:28 +00:00
|
|
|
|
int i = 0;
|
2005-07-16 10:35:43 +00:00
|
|
|
|
while (LyXSizeNames[i] != s && LyXSizeNames[i] != string("error"))
|
|
|
|
|
++i;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (s == LyXSizeNames[i]) {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
f.setSize(FontSize(i));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else
|
2007-04-29 18:17:15 +00:00
|
|
|
|
lyxerr << "Font::setLyXSize: Unknown size `"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
<< s << '\'' << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Set size according to lyx format string
|
2007-10-28 18:51:54 +00:00
|
|
|
|
FontState Font::setLyXMisc(string const & siz)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-07-16 21:17:10 +00:00
|
|
|
|
string const s = ascii_lowercase(siz);
|
2000-04-04 00:19:15 +00:00
|
|
|
|
int i = 0;
|
2005-01-20 22:00:17 +00:00
|
|
|
|
while (LyXMiscNames[i] != s &&
|
|
|
|
|
LyXMiscNames[i] != string("error")) ++i;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (s == LyXMiscNames[i])
|
2007-10-28 18:51:54 +00:00
|
|
|
|
return FontState(i);
|
2007-04-29 18:17:15 +00:00
|
|
|
|
lyxerr << "Font::setLyXMisc: Unknown misc flag `"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
<< s << '\'' << endl;
|
2007-10-28 18:51:54 +00:00
|
|
|
|
return FONT_OFF;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
/// Sets color after LyX text format
|
2007-10-28 18:51:54 +00:00
|
|
|
|
void setLyXColor(string const & col, FontInfo & f)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-10-28 18:51:54 +00:00
|
|
|
|
f.setColor(lcolor.getFromLyXName(col));
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Read a font definition from given file in lyx format
|
|
|
|
|
// Used for layouts
|
2007-11-01 06:25:47 +00:00
|
|
|
|
FontInfo lyxRead(Lexer & lex, FontInfo const & fi)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2007-11-01 06:25:47 +00:00
|
|
|
|
FontInfo f = fi;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
bool error = false;
|
|
|
|
|
bool finished = false;
|
2001-08-06 19:12:46 +00:00
|
|
|
|
while (!finished && lex.isOK() && !error) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lex.next();
|
2002-07-16 21:17:10 +00:00
|
|
|
|
string const tok = ascii_lowercase(lex.getString());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
if (tok.empty()) {
|
|
|
|
|
continue;
|
|
|
|
|
} else if (tok == "endfont") {
|
|
|
|
|
finished = true;
|
|
|
|
|
} else if (tok == "family") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const ttok = lex.getString();
|
2007-10-28 18:51:54 +00:00
|
|
|
|
setLyXFamily(ttok, f);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else if (tok == "series") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const ttok = lex.getString();
|
2007-10-28 18:51:54 +00:00
|
|
|
|
setLyXSeries(ttok, f);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else if (tok == "shape") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const ttok = lex.getString();
|
2007-10-28 18:51:54 +00:00
|
|
|
|
setLyXShape(ttok, f);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else if (tok == "size") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const ttok = lex.getString();
|
2007-10-28 18:51:54 +00:00
|
|
|
|
setLyXSize(ttok, f);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else if (tok == "misc") {
|
|
|
|
|
lex.next();
|
2002-07-16 21:17:10 +00:00
|
|
|
|
string const ttok = ascii_lowercase(lex.getString());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-06 14:07:14 +00:00
|
|
|
|
if (ttok == "no_bar") {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
f.setUnderbar(FONT_OFF);
|
2001-03-06 14:07:14 +00:00
|
|
|
|
} else if (ttok == "no_emph") {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
f.setEmph(FONT_OFF);
|
2001-03-06 14:07:14 +00:00
|
|
|
|
} else if (ttok == "no_noun") {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
f.setNoun(FONT_OFF);
|
2001-03-06 14:07:14 +00:00
|
|
|
|
} else if (ttok == "emph") {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
f.setEmph(FONT_ON);
|
2001-03-06 14:07:14 +00:00
|
|
|
|
} else if (ttok == "underbar") {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
f.setUnderbar(FONT_ON);
|
2001-03-06 14:07:14 +00:00
|
|
|
|
} else if (ttok == "noun") {
|
2007-10-28 18:51:54 +00:00
|
|
|
|
f.setNoun(FONT_ON);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2008-04-05 21:24:57 +00:00
|
|
|
|
lex.printError("Illegal misc type");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
} else if (tok == "color") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
|
string const ttok = lex.getString();
|
2007-10-28 18:51:54 +00:00
|
|
|
|
setLyXColor(ttok, f);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2008-04-05 21:24:57 +00:00
|
|
|
|
lex.printError("Unknown tag");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
|
return f;
|
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
|
|
|
|
}
|
|
|
|
|
}
|
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;
|
2000-10-10 12:36:36 +00:00
|
|
|
|
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();
|
2007-05-06 20:26:02 +00:00
|
|
|
|
} else {
|
|
|
|
|
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-05-10 09:25:44 +00:00
|
|
|
|
// When 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
|
2007-05-14 09:34:53 +00:00
|
|
|
|
// reorders the number automatically but the packages used
|
|
|
|
|
// for Hebrew and Farsi (Arabi) do not.
|
2007-10-28 18:51:54 +00:00
|
|
|
|
if (bits_.number() == FONT_ON && prev.fontInfo().number() != FONT_ON
|
2007-05-28 22:27:45 +00:00
|
|
|
|
&& (language()->lang() == "hebrew"
|
2007-07-17 19:06:33 +00:00
|
|
|
|
|| language()->lang() == "farsi"
|
|
|
|
|
|| language()->lang() == "arabic_arabi")) {
|
2000-10-09 12:30:52 +00:00
|
|
|
|
os << "{\\beginL ";
|
|
|
|
|
count += 9;
|
|
|
|
|
}
|
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
|
FontInfo f = bits_;
|
|
|
|
|
f.reduce(base.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) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "\\textcolor{"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< from_ascii(lcolor.getLaTeXName(f.color()))
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< "}{";
|
|
|
|
|
count += lcolor.getLaTeXName(f.color()).length() + 13;
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
|
if (f.underbar() == FONT_ON) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "\\underbar{";
|
|
|
|
|
count += 10;
|
|
|
|
|
env = true; //We have opened a new environment
|
|
|
|
|
}
|
|
|
|
|
// \noun{} is a LyX special macro
|
2007-10-28 18:51:54 +00:00
|
|
|
|
if (f.noun() == FONT_ON) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "\\noun{";
|
2003-05-27 13:32:32 +00:00
|
|
|
|
count += 6;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
env = true; //We have opened a new environment
|
|
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
|
if (f.size() != FONT_SIZE_INHERIT) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// If we didn't open an environment above, we open one here
|
|
|
|
|
if (!env) {
|
|
|
|
|
os << '{';
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
os << '\\'
|
|
|
|
|
<< LaTeXSizeNames[f.size()]
|
|
|
|
|
<< ' ';
|
2001-06-01 10:53:24 +00:00
|
|
|
|
count += strlen(LaTeXSizeNames[f.size()]) + 2;
|
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)
|
2007-05-06 20:26:02 +00:00
|
|
|
|
int Font::latexWriteEndChanges(odocstream & 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,
|
|
|
|
|
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.
|
|
|
|
|
}
|
2007-10-25 12:41:02 +00:00
|
|
|
|
if (f.color() != Color_inherit && f.color() != Color_ignore) {
|
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.
|
|
|
|
|
}
|
2007-10-28 18:51:54 +00:00
|
|
|
|
if (f.underbar() == FONT_ON) {
|
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.noun() == FONT_ON) {
|
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.size() != FONT_SIZE_INHERIT) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// We only have to close if only size changed
|
|
|
|
|
if (!env) {
|
|
|
|
|
os << '}';
|
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-03-17 10:14:46 +00:00
|
|
|
|
|
2007-05-10 09:25:44 +00:00
|
|
|
|
// When 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
|
2007-05-14 09:34:53 +00:00
|
|
|
|
// reorders the number automatically but the packages used
|
|
|
|
|
// for Hebrew and Farsi (Arabi) do not.
|
2007-10-28 18:51:54 +00:00
|
|
|
|
if (bits_.number() == FONT_ON && next.fontInfo().number() != FONT_ON
|
2007-05-28 22:27:45 +00:00
|
|
|
|
&& (language()->lang() == "hebrew"
|
2007-07-17 19:06:33 +00:00
|
|
|
|
|| language()->lang() == "farsi"
|
|
|
|
|
|| language()->lang() == "arabic_arabi")) {
|
2000-10-09 12:30:52 +00:00
|
|
|
|
os << "\\endL}";
|
|
|
|
|
count += 6;
|
|
|
|
|
}
|
|
|
|
|
|
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");
|
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, *ascii);
|
2007-07-05 19:19:41 +00:00
|
|
|
|
BOOST_ASSERT(c.first);
|
|
|
|
|
count += c.second;
|
2007-05-06 20:26:02 +00:00
|
|
|
|
runparams.encoding = ascii;
|
|
|
|
|
open_encoding_ = false;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-20 01:28:20 +00:00
|
|
|
|
if (closeLanguage &&
|
|
|
|
|
language() != base.language() && language() != next.language()) {
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '}';
|
2000-10-09 12:30:52 +00:00
|
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
string lang = "ignore";
|
|
|
|
|
if (language())
|
|
|
|
|
lang = language()->lang();
|
|
|
|
|
|
|
|
|
|
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'
|
|
|
|
|
<< "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
|
|
|
|
|
|
|
|
|
} else if (token == "emph" || token == "underbar" ||
|
|
|
|
|
token == "noun" || token == "number") {
|
|
|
|
|
|
|
|
|
|
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);
|
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();
|
|
|
|
|
if (next == "ignore")
|
|
|
|
|
setLanguage(ignore_language);
|
|
|
|
|
else
|
|
|
|
|
setLanguage(languages.getLanguage(next));
|
|
|
|
|
|
|
|
|
|
} 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
|
|
|
|
}
|
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;
|
|
|
|
|
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?
|
|
|
|
|
|
|
|
|
|
if (lang_->babel() != doc_language->babel() &&
|
|
|
|
|
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()
|
|
|
|
|
<< " 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
|