using std::ostream;
-namespace { // anon
+namespace {
-struct compare_name {
-
- compare_name(string const & name)
+class LayoutNamesEqual : public std::unary_function<LyXLayout_ptr, bool> {
+public:
+ LayoutNamesEqual(string const & name)
: name_(name)
{}
-
- bool operator()(boost::shared_ptr<LyXLayout> const & c)
+ bool operator()(LyXLayout_ptr const & c) const
{
return c->name() == name_;
}
-
+private:
string name_;
-
};
-} // anon
+} // namespace anon
LyXTextClass::LyXTextClass(string const & fn, string const & cln,
string const & desc, bool texClassAvail )
: name_(fn), latexname_(cln), description_(desc),
- floatlist_(new FloatList), ctrs_(new Counters), texClassAvail_(texClassAvail)
+ floatlist_(new FloatList), ctrs_(new Counters),
+ texClassAvail_(texClassAvail)
{
outputType_ = LATEX;
columns_ = 1;
provides_ = nothing;
titletype_ = TITLE_COMMAND_AFTER;
titlename_ = "maketitle";
- loaded = false;
+ loaded_ = false;
}
TC_INPUT,
TC_STYLE,
TC_DEFAULTSTYLE,
+ TC_CHARSTYLE,
TC_ENVIRONMENT,
TC_NOSTYLE,
TC_COLUMNS,
bool LyXTextClass::Read(string const & filename, bool merge)
{
keyword_item textClassTags[] = {
+ { "charstyle", TC_CHARSTYLE },
{ "classoptions", TC_CLASSOPTIONS },
{ "columns", TC_COLUMNS },
{ "counter", TC_COUNTER },
if (le == TC_ENVIRONMENT)
lay.is_environment = true;
if (!(error = do_readStyle(lexrc, lay)))
- layoutlist_.push_back
- (boost::shared_ptr<LyXLayout>(new LyXLayout(lay)));
+ layoutlist_.push_back(
+ boost::shared_ptr<LyXLayout>(new LyXLayout(lay))
+ );
+
if (defaultlayout_.empty()) {
// We do not have a default
// layout yet, so we choose
if (lexrc.next())
rightmargin_ = lexrc.getString();
break;
+ case TC_CHARSTYLE:
+ if (lexrc.next()) {
+ string const name = subst(lexrc.getString(), '_', ' ');
+ readCharStyle(lexrc, name);
+ }
+ break;
case TC_FLOAT:
readFloat(lexrc);
break;
CO_FONTSIZE = 1,
CO_PAGESTYLE,
CO_OTHER,
+ CO_HEADER,
CO_END
};
keyword_item classOptionsTags[] = {
{"end", CO_END },
{"fontsize", CO_FONTSIZE },
+ {"header", CO_HEADER },
{"other", CO_OTHER },
{"pagestyle", CO_PAGESTYLE }
};
lexrc.next();
options_ = lexrc.getString();
break;
+ case CO_HEADER:
+ lexrc.next();
+ class_header_ = subst(lexrc.getString(), """, "\"");
+ break;
case CO_END:
getout = true;
break;
lexrc.popTable();
}
+enum CharStyleTags {
+ CS_FONT = 1,
+ CS_LABELFONT,
+ CS_LATEXTYPE,
+ CS_LATEXNAME,
+ CS_LATEXPARAM,
+ CS_PREAMBLE,
+ CS_END
+};
+
+
+void LyXTextClass::readCharStyle(LyXLex & lexrc, string const & name)
+{
+ keyword_item elementTags[] = {
+ { "end", CS_END },
+ { "font", CS_FONT },
+ { "labelfont", CS_LABELFONT },
+ { "latexname", CS_LATEXNAME },
+ { "latexparam", CS_LATEXPARAM },
+ { "latextype", CS_LATEXTYPE },
+ { "preamble", CS_PREAMBLE}
+ };
+
+ lexrc.pushTable(elementTags, CS_END);
+
+ string latextype;
+ string latexname;
+ string latexparam;
+ LyXFont font(LyXFont::ALL_INHERIT);
+ LyXFont labelfont(LyXFont::ALL_INHERIT);
+ string preamble;
+
+ bool getout = false;
+ while (!getout && lexrc.isOK()) {
+ int le = lexrc.lex();
+ switch (le) {
+ case LyXLex::LEX_UNDEF:
+ lexrc.printError("Unknown ClassOption tag `$$Token'");
+ continue;
+ default: break;
+ }
+ switch (static_cast<CharStyleTags>(le)) {
+ case CS_LATEXTYPE:
+ lexrc.next();
+ latextype = lexrc.getString();
+ break;
+ case CS_LATEXNAME:
+ lexrc.next();
+ latexname = lexrc.getString();
+ break;
+ case CS_LATEXPARAM:
+ lexrc.next();
+ latexparam = subst(lexrc.getString(), """, "\"");
+ break;
+ case CS_LABELFONT:
+ labelfont.lyxRead(lexrc);
+ break;
+ case CS_FONT:
+ font.lyxRead(lexrc);
+ labelfont = font;
+ break;
+ case CS_PREAMBLE:
+ preamble = lexrc.getLongString("EndPreamble");
+ break;
+ case CS_END:
+ getout = true;
+ break;
+ }
+ }
+
+ //
+ // Here add element to list if getout == true
+ if (getout) {
+ CharStyle cs;
+ cs.name = name;
+ cs.latextype = latextype;
+ cs.latexname = latexname;
+ cs.latexparam = latexparam;
+ cs.font = font;
+ cs.labelfont = labelfont;
+ cs.preamble = preamble;
+ charstyles().push_back(cs);
+ }
+
+ lexrc.popTable();
+}
+
enum FloatTags {
FT_TYPE = 1,
FT_END
};
+
void LyXTextClass::readFloat(LyXLex & lexrc)
{
keyword_item floatTags[] = {
string const name = (n.empty() ? defaultLayoutName() : n);
return find_if(layoutlist_.begin(), layoutlist_.end(),
- compare_name(name))
+ LayoutNamesEqual(name))
!= layoutlist_.end();
}
LayoutList::const_iterator cit =
find_if(layoutlist_.begin(),
layoutlist_.end(),
- compare_name(name));
+ LayoutNamesEqual(name));
if (cit == layoutlist_.end()) {
lyxerr << "We failed to find the layout '" << name
LayoutList::iterator it =
remove_if(layoutlist_.begin(), layoutlist_.end(),
- compare_name(name));
+ LayoutNamesEqual(name));
LayoutList::iterator end = layoutlist_.end();
bool const ret = (it != end);
// Load textclass info if not loaded yet
bool LyXTextClass::load() const
{
- if (loaded)
+ if (loaded_)
return true;
// Read style-file
string const real_file = LibFileSearch("layouts", name_, "layout");
+ loaded_ = const_cast<LyXTextClass*>(this)->Read(real_file) == 0;
- if (const_cast<LyXTextClass*>(this)->Read(real_file)) {
+ if (!loaded_) {
lyxerr << "Error reading `"
<< MakeDisplayPath(real_file)
<< "'\n(Check `" << name_
<< "')\nCheck your installation and "
"try Options/Reconfigure..." << endl;
- loaded = false;
}
- loaded = true;
- return loaded;
+
+ return loaded_;
}
}
+CharStyles::iterator LyXTextClass::charstyle(string const & s) const
+{
+ CharStyles::iterator cs = charstyles().begin();
+ CharStyles::iterator csend = charstyles().end();
+ for (; cs != csend; ++cs) {
+ if (cs->name == s)
+ return cs;
+ }
+ return csend;
+}
+
+
string const & LyXTextClass::defaultLayoutName() const
{
// This really should come from the actual layout... (Lgb)
}
+string const & LyXTextClass::class_header() const
+{
+ return class_header_;
+}
+
+
string const & LyXTextClass::pagestyle() const
{
return pagestyle_;