3 * \file InsetLayout.cpp
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Martin Vermeer
10 * Full author contact details are available in file CREDITS.
15 #include "InsetLayout.h"
20 #include "TextClass.h"
22 #include "support/debug.h"
23 #include "support/lstrings.h"
33 InsetLayout::InsetLayout() :
34 name_(from_ascii("undefined")), lyxtype_(STANDARD),
35 labelstring_(from_ascii("UNDEFINED")), decoration_(DEFAULT),
36 latextype_(NOLATEXTYPE), font_(sane_font),
37 labelfont_(sane_font), bgcolor_(Color_error),
38 multipar_(false), custompars_(false), forceplain_(true),
39 passthru_(false), needprotect_(false), freespacing_(false),
40 keepempty_(false), forceltr_(false), intoc_(false)
42 labelfont_.setColor(Color_error);
48 InsetLayout::InsetDecoration translateDecoration(std::string const & str)
50 if (support::compare_ascii_no_case(str, "classic") == 0)
51 return InsetLayout::CLASSIC;
52 if (support::compare_ascii_no_case(str, "minimalistic") == 0)
53 return InsetLayout::MINIMALISTIC;
54 if (support::compare_ascii_no_case(str, "conglomerate") == 0)
55 return InsetLayout::CONGLOMERATE;
56 return InsetLayout::DEFAULT;
59 InsetLayout::InsetLaTeXType translateLaTeXType(std::string const & str)
61 if (support::compare_ascii_no_case(str, "command") == 0)
62 return InsetLayout::COMMAND;
63 if (support::compare_ascii_no_case(str, "environment") == 0)
64 return InsetLayout::ENVIRONMENT;
65 if (support::compare_ascii_no_case(str, "none") == 0)
66 return InsetLayout::NOLATEXTYPE;
67 return InsetLayout::ILT_ERROR;
73 bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
105 LexerKeyword elementTags[] = {
106 { "bgcolor", IL_BGCOLOR },
107 { "copystyle", IL_COPYSTYLE },
108 { "custompars", IL_CUSTOMPARS },
109 { "decoration", IL_DECORATION },
112 { "forceltr", IL_FORCELTR },
113 { "forceplain", IL_FORCEPLAIN },
114 { "freespacing", IL_FREESPACING },
115 { "htmlattr", IL_HTMLATTR },
116 { "htmlpreamble", IL_HTMLPREAMBLE },
117 { "htmlstyle", IL_HTMLSTYLE },
118 { "htmltag", IL_HTMLTAG },
119 { "intoc", IL_INTOC },
120 { "keepempty", IL_KEEPEMPTY },
121 { "labelfont", IL_LABELFONT },
122 { "labelstring", IL_LABELSTRING },
123 { "latexname", IL_LATEXNAME },
124 { "latexparam", IL_LATEXPARAM },
125 { "latextype", IL_LATEXTYPE },
126 { "lyxtype", IL_LYXTYPE },
127 { "multipar", IL_MULTIPAR },
128 { "needprotect", IL_NEEDPROTECT },
129 { "passthru", IL_PASSTHRU },
130 { "preamble", IL_PREAMBLE },
131 { "requires", IL_REQUIRES }
134 lex.pushTable(elementTags);
136 FontInfo font = inherit_font;
137 labelfont_ = inherit_font;
138 bgcolor_ = Color_none;
140 // whether we've read the CustomPars or ForcePlain tag
141 // for issuing a warning in case MultiPars comes later
142 bool readCustomOrPlain = false;
145 while (!getout && lex.isOK()) {
148 case Lexer::LEX_UNDEF:
149 lex.printError("Unknown InsetLayout tag");
156 // Perhaps a more elegant way to deal with the next two would be the
157 // way this sort of thing is handled in Layout::read(), namely, by
162 lyxtype_ = translateLyXType(lt);
163 if (lyxtype_ == NOLYXTYPE)
164 LYXERR0("Unknown LyXType `" << lt << "'.");
170 latextype_ = translateLaTeXType(lt);
171 if (latextype_ == ILT_ERROR)
172 LYXERR0("Unknown LaTeXType `" << lt << "'.");
180 decoration_ = translateDecoration(tmp);
187 latexparam_ = support::subst(tmp, """, "\"");
190 labelfont_ = lyxRead(lex, inherit_font);
200 // the defaults for these depend upon multipar_
201 if (readCustomOrPlain)
202 LYXERR0("Warning: Read MultiPar after CustomPars or ForcePlain. "
203 "Previous value may be overwritten!");
204 readCustomOrPlain = false;
205 custompars_ = multipar_;
206 forceplain_ = !multipar_;
210 readCustomOrPlain = true;
217 readCustomOrPlain = true;
228 case IL_COPYSTYLE: { // initialize with a known style
231 style = support::subst(style, '_', ' ');
233 // We don't want to apply the algorithm in DocumentClass::insetLayout()
234 // here. So we do it the long way.
235 TextClass::InsetLayouts::const_iterator it =
236 tclass.insetLayouts().find(style);
237 if (it != tclass.insetLayouts().end()) {
238 docstring const tmpname = name_;
239 this->operator=(it->second);
242 LYXERR0("Cannot copy unknown InsetLayout `"
244 << "All InsetLayouts so far:");
245 TextClass::InsetLayouts::const_iterator lit =
246 tclass.insetLayouts().begin();
247 TextClass::InsetLayouts::const_iterator len =
248 tclass.insetLayouts().end();
249 for (; lit != len; ++lit)
250 lyxerr << lit->second.name() << "\n";
256 font_ = lyxRead(lex, inherit_font);
257 // If you want to define labelfont, you need to do so after
264 bgcolor_ = lcolor.getFromLyXName(tmp);
267 preamble_ = from_utf8(lex.getLongString("EndPreamble"));
276 htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
278 case IL_HTMLPREAMBLE:
279 htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
283 vector<string> const req
284 = support::getVectorFromString(lex.getString());
285 requires_.insert(req.begin(), req.end());
294 // Here add element to list if getout == true
298 // The label font is generally used as-is without
299 // any realization against a given context.
300 labelfont_.realize(sane_font);
307 InsetLayout::InsetLyXType translateLyXType(std::string const & str)
310 if (support::compare_ascii_no_case(str, "charstyle") == 0)
311 return InsetLayout::CHARSTYLE;
312 if (support::compare_ascii_no_case(str, "custom") == 0)
313 return InsetLayout::CUSTOM;
314 if (support::compare_ascii_no_case(str, "element") == 0)
315 return InsetLayout::ELEMENT;
316 if (support::compare_ascii_no_case(str, "end") == 0)
317 return InsetLayout::END;
318 if (support::compare_ascii_no_case(str, "standard") == 0)
319 return InsetLayout::STANDARD;
320 return InsetLayout::NOLYXTYPE;