2008-02-22 03:27:42 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file InsetLayout.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Martin Vermeer
|
|
|
|
* \author Richard Heck
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "InsetLayout.h"
|
|
|
|
|
2009-02-09 23:30:24 +00:00
|
|
|
#include "ColorSet.h"
|
2008-02-22 03:39:10 +00:00
|
|
|
#include "Lexer.h"
|
2008-07-28 15:14:37 +00:00
|
|
|
#include "TextClass.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
|
2008-07-28 15:14:37 +00:00
|
|
|
#include "support/debug.h"
|
2008-02-22 03:27:42 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
using std::set;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2010-01-14 23:45:53 +00:00
|
|
|
InsetLayout::InsetLayout() :
|
|
|
|
name_(from_ascii("undefined")), lyxtype_(STANDARD),
|
2009-12-18 00:29:22 +00:00
|
|
|
labelstring_(from_ascii("UNDEFINED")), contentaslabel_(false),
|
|
|
|
decoration_(DEFAULT), latextype_(NOLATEXTYPE), font_(sane_font),
|
2008-10-25 14:02:25 +00:00
|
|
|
labelfont_(sane_font), bgcolor_(Color_error),
|
2009-10-27 14:33:01 +00:00
|
|
|
htmlforcecss_ (false), htmlisblock_(true),
|
2009-10-30 00:33:56 +00:00
|
|
|
multipar_(true), custompars_(true), forceplain_(false),
|
2008-10-05 19:38:22 +00:00
|
|
|
passthru_(false), needprotect_(false), freespacing_(false),
|
2010-02-13 15:44:17 +00:00
|
|
|
keepempty_(false), forceltr_(false), intoc_(false), spellcheck_(true)
|
2008-02-22 03:27:42 +00:00
|
|
|
{
|
2008-10-05 19:38:22 +00:00
|
|
|
labelfont_.setColor(Color_error);
|
2008-02-22 03:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
namespace {
|
2008-02-22 03:27:42 +00:00
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
InsetLayout::InsetDecoration translateDecoration(std::string const & str)
|
|
|
|
{
|
2008-10-25 12:49:49 +00:00
|
|
|
if (support::compare_ascii_no_case(str, "classic") == 0)
|
2008-10-25 13:41:02 +00:00
|
|
|
return InsetLayout::CLASSIC;
|
2008-10-25 12:49:49 +00:00
|
|
|
if (support::compare_ascii_no_case(str, "minimalistic") == 0)
|
2008-10-25 13:41:02 +00:00
|
|
|
return InsetLayout::MINIMALISTIC;
|
2008-10-25 12:49:49 +00:00
|
|
|
if (support::compare_ascii_no_case(str, "conglomerate") == 0)
|
2008-10-25 13:41:02 +00:00
|
|
|
return InsetLayout::CONGLOMERATE;
|
|
|
|
return InsetLayout::DEFAULT;
|
2008-04-03 20:55:09 +00:00
|
|
|
}
|
2008-02-22 03:27:42 +00:00
|
|
|
|
2008-10-25 14:02:25 +00:00
|
|
|
InsetLayout::InsetLaTeXType translateLaTeXType(std::string const & str)
|
|
|
|
{
|
|
|
|
if (support::compare_ascii_no_case(str, "command") == 0)
|
|
|
|
return InsetLayout::COMMAND;
|
|
|
|
if (support::compare_ascii_no_case(str, "environment") == 0)
|
|
|
|
return InsetLayout::ENVIRONMENT;
|
|
|
|
if (support::compare_ascii_no_case(str, "none") == 0)
|
|
|
|
return InsetLayout::NOLATEXTYPE;
|
|
|
|
return InsetLayout::ILT_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-02-09 23:30:24 +00:00
|
|
|
} // namespace anon
|
2008-02-22 16:15:21 +00:00
|
|
|
|
|
|
|
|
2008-12-16 14:13:02 +00:00
|
|
|
bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
|
2008-02-22 03:27:42 +00:00
|
|
|
{
|
2008-04-03 20:55:09 +00:00
|
|
|
enum {
|
|
|
|
IL_BGCOLOR,
|
2009-12-18 00:29:22 +00:00
|
|
|
IL_CONTENTASLABEL,
|
2008-07-28 15:14:37 +00:00
|
|
|
IL_COPYSTYLE,
|
2009-06-06 03:02:43 +00:00
|
|
|
IL_COUNTER,
|
2008-10-05 19:38:22 +00:00
|
|
|
IL_CUSTOMPARS,
|
2008-04-03 20:55:09 +00:00
|
|
|
IL_DECORATION,
|
2008-07-28 15:14:37 +00:00
|
|
|
IL_FONT,
|
2008-04-03 20:55:09 +00:00
|
|
|
IL_FORCELTR,
|
2008-10-05 19:38:22 +00:00
|
|
|
IL_FORCEPLAIN,
|
2008-07-28 15:14:37 +00:00
|
|
|
IL_FREESPACING,
|
2009-06-05 17:36:51 +00:00
|
|
|
IL_HTMLTAG,
|
|
|
|
IL_HTMLATTR,
|
2009-10-27 14:33:01 +00:00
|
|
|
IL_HTMLFORCECSS,
|
2009-06-06 03:02:43 +00:00
|
|
|
IL_HTMLINNERTAG,
|
|
|
|
IL_HTMLINNERATTR,
|
2009-10-26 20:53:46 +00:00
|
|
|
IL_HTMLISBLOCK,
|
2009-06-06 03:02:43 +00:00
|
|
|
IL_HTMLLABEL,
|
2009-06-05 17:36:51 +00:00
|
|
|
IL_HTMLSTYLE,
|
2009-06-05 19:42:56 +00:00
|
|
|
IL_HTMLPREAMBLE,
|
2009-02-06 17:54:33 +00:00
|
|
|
IL_INTOC,
|
2008-04-03 20:55:09 +00:00
|
|
|
IL_LABELFONT,
|
|
|
|
IL_LABELSTRING,
|
|
|
|
IL_LATEXNAME,
|
|
|
|
IL_LATEXPARAM,
|
|
|
|
IL_LATEXTYPE,
|
|
|
|
IL_LYXTYPE,
|
|
|
|
IL_KEEPEMPTY,
|
|
|
|
IL_MULTIPAR,
|
|
|
|
IL_NEEDPROTECT,
|
|
|
|
IL_PASSTHRU,
|
|
|
|
IL_PREAMBLE,
|
|
|
|
IL_REQUIRES,
|
2010-02-13 15:44:17 +00:00
|
|
|
IL_SPELLCHECK,
|
2010-03-17 12:23:24 +00:00
|
|
|
IL_REFPREFIX,
|
2008-04-03 20:55:09 +00:00
|
|
|
IL_END
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-04-02 23:06:22 +00:00
|
|
|
LexerKeyword elementTags[] = {
|
2008-02-22 03:27:42 +00:00
|
|
|
{ "bgcolor", IL_BGCOLOR },
|
2009-12-18 00:29:22 +00:00
|
|
|
{ "contentaslabel", IL_CONTENTASLABEL },
|
2008-10-05 19:38:22 +00:00
|
|
|
{ "copystyle", IL_COPYSTYLE },
|
2009-06-06 03:02:43 +00:00
|
|
|
{ "counter", IL_COUNTER},
|
2008-10-05 19:38:22 +00:00
|
|
|
{ "custompars", IL_CUSTOMPARS },
|
2008-02-22 03:27:42 +00:00
|
|
|
{ "decoration", IL_DECORATION },
|
|
|
|
{ "end", IL_END },
|
|
|
|
{ "font", IL_FONT },
|
|
|
|
{ "forceltr", IL_FORCELTR },
|
2008-10-05 19:38:22 +00:00
|
|
|
{ "forceplain", IL_FORCEPLAIN },
|
2008-02-22 03:27:42 +00:00
|
|
|
{ "freespacing", IL_FREESPACING },
|
2009-06-05 17:36:51 +00:00
|
|
|
{ "htmlattr", IL_HTMLATTR },
|
2009-10-27 14:33:01 +00:00
|
|
|
{ "htmlforcecss", IL_HTMLFORCECSS },
|
2009-06-06 03:02:43 +00:00
|
|
|
{ "htmlinnerattr", IL_HTMLINNERATTR},
|
|
|
|
{ "htmlinnertag", IL_HTMLINNERTAG},
|
2009-10-26 20:53:46 +00:00
|
|
|
{ "htmlisblock", IL_HTMLISBLOCK},
|
2009-06-06 03:02:43 +00:00
|
|
|
{ "htmllabel", IL_HTMLLABEL },
|
2009-06-05 19:42:56 +00:00
|
|
|
{ "htmlpreamble", IL_HTMLPREAMBLE },
|
2009-06-05 17:36:51 +00:00
|
|
|
{ "htmlstyle", IL_HTMLSTYLE },
|
|
|
|
{ "htmltag", IL_HTMLTAG },
|
2009-02-06 17:54:33 +00:00
|
|
|
{ "intoc", IL_INTOC },
|
2008-02-22 03:27:42 +00:00
|
|
|
{ "keepempty", IL_KEEPEMPTY },
|
|
|
|
{ "labelfont", IL_LABELFONT },
|
|
|
|
{ "labelstring", IL_LABELSTRING },
|
|
|
|
{ "latexname", IL_LATEXNAME },
|
|
|
|
{ "latexparam", IL_LATEXPARAM },
|
|
|
|
{ "latextype", IL_LATEXTYPE },
|
|
|
|
{ "lyxtype", IL_LYXTYPE },
|
|
|
|
{ "multipar", IL_MULTIPAR },
|
|
|
|
{ "needprotect", IL_NEEDPROTECT },
|
|
|
|
{ "passthru", IL_PASSTHRU },
|
|
|
|
{ "preamble", IL_PREAMBLE },
|
2010-03-17 12:23:24 +00:00
|
|
|
{ "refprefix", IL_REFPREFIX },
|
2010-02-13 15:44:17 +00:00
|
|
|
{ "requires", IL_REQUIRES },
|
|
|
|
{ "spellcheck", IL_SPELLCHECK }
|
2008-02-22 03:27:42 +00:00
|
|
|
};
|
|
|
|
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.pushTable(elementTags);
|
2008-02-22 03:27:42 +00:00
|
|
|
|
|
|
|
FontInfo font = inherit_font;
|
|
|
|
labelfont_ = inherit_font;
|
2008-10-25 10:47:38 +00:00
|
|
|
bgcolor_ = Color_none;
|
2008-02-22 03:27:42 +00:00
|
|
|
bool getout = false;
|
2008-10-05 19:38:22 +00:00
|
|
|
// whether we've read the CustomPars or ForcePlain tag
|
|
|
|
// for issuing a warning in case MultiPars comes later
|
|
|
|
bool readCustomOrPlain = false;
|
2008-04-05 10:34:29 +00:00
|
|
|
|
|
|
|
string tmp;
|
|
|
|
while (!getout && lex.isOK()) {
|
|
|
|
int le = lex.lex();
|
2008-02-22 03:27:42 +00:00
|
|
|
switch (le) {
|
|
|
|
case Lexer::LEX_UNDEF:
|
2008-04-05 21:24:57 +00:00
|
|
|
lex.printError("Unknown InsetLayout tag");
|
2008-02-22 03:27:42 +00:00
|
|
|
continue;
|
2008-04-05 21:24:57 +00:00
|
|
|
default:
|
|
|
|
break;
|
2008-02-22 03:27:42 +00:00
|
|
|
}
|
2008-04-03 20:55:09 +00:00
|
|
|
switch (le) {
|
2008-10-25 15:25:46 +00:00
|
|
|
// FIXME
|
2008-12-16 14:13:02 +00:00
|
|
|
// Perhaps a more elegant way to deal with the next two would be the
|
2008-10-25 15:25:46 +00:00
|
|
|
// way this sort of thing is handled in Layout::read(), namely, by
|
|
|
|
// using the Lexer.
|
2008-10-25 13:32:54 +00:00
|
|
|
case IL_LYXTYPE: {
|
|
|
|
string lt;
|
|
|
|
lex >> lt;
|
|
|
|
lyxtype_ = translateLyXType(lt);
|
|
|
|
if (lyxtype_ == NOLYXTYPE)
|
|
|
|
LYXERR0("Unknown LyXType `" << lt << "'.");
|
2010-01-14 21:43:44 +00:00
|
|
|
if (lyxtype_ == CHARSTYLE)
|
|
|
|
multipar_ = false;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
2008-10-25 13:32:54 +00:00
|
|
|
}
|
2008-10-25 14:02:25 +00:00
|
|
|
case IL_LATEXTYPE: {
|
|
|
|
string lt;
|
|
|
|
lex >> lt;
|
|
|
|
latextype_ = translateLaTeXType(lt);
|
|
|
|
if (latextype_ == ILT_ERROR)
|
|
|
|
LYXERR0("Unknown LaTeXType `" << lt << "'.");
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
2008-10-25 14:02:25 +00:00
|
|
|
}
|
2008-02-22 03:27:42 +00:00
|
|
|
case IL_LABELSTRING:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> labelstring_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_DECORATION:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> tmp;
|
|
|
|
decoration_ = translateDecoration(tmp);
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_LATEXNAME:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> latexname_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_LATEXPARAM:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> tmp;
|
|
|
|
latexparam_ = support::subst(tmp, """, "\"");
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_LABELFONT:
|
2008-04-05 10:34:29 +00:00
|
|
|
labelfont_ = lyxRead(lex, inherit_font);
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_FORCELTR:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> forceltr_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
2009-02-06 17:54:33 +00:00
|
|
|
case IL_INTOC:
|
|
|
|
lex >> intoc_;
|
|
|
|
break;
|
2008-02-22 03:27:42 +00:00
|
|
|
case IL_MULTIPAR:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> multipar_;
|
2008-10-05 19:38:22 +00:00
|
|
|
// the defaults for these depend upon multipar_
|
|
|
|
if (readCustomOrPlain)
|
|
|
|
LYXERR0("Warning: Read MultiPar after CustomPars or ForcePlain. "
|
|
|
|
"Previous value may be overwritten!");
|
|
|
|
readCustomOrPlain = false;
|
|
|
|
custompars_ = multipar_;
|
|
|
|
forceplain_ = !multipar_;
|
|
|
|
break;
|
2009-06-06 03:02:43 +00:00
|
|
|
case IL_COUNTER:
|
|
|
|
lex >> counter_;
|
|
|
|
break;
|
2008-10-05 19:38:22 +00:00
|
|
|
case IL_CUSTOMPARS:
|
|
|
|
lex >> custompars_;
|
|
|
|
readCustomOrPlain = true;
|
|
|
|
break;
|
|
|
|
case IL_FORCEPLAIN:
|
|
|
|
lex >> forceplain_;
|
2010-08-08 14:34:59 +00:00
|
|
|
readCustomOrPlain = true;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_PASSTHRU:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> passthru_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_KEEPEMPTY:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> keepempty_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_FREESPACING:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> freespacing_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_NEEDPROTECT:
|
2008-04-05 10:34:29 +00:00
|
|
|
lex >> needprotect_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
2009-12-18 00:29:22 +00:00
|
|
|
case IL_CONTENTASLABEL:
|
|
|
|
lex >> contentaslabel_;
|
|
|
|
break;
|
2008-07-28 15:14:37 +00:00
|
|
|
case IL_COPYSTYLE: { // initialize with a known style
|
|
|
|
docstring style;
|
|
|
|
lex >> style;
|
|
|
|
style = support::subst(style, '_', ' ');
|
|
|
|
|
|
|
|
// We don't want to apply the algorithm in DocumentClass::insetLayout()
|
|
|
|
// here. So we do it the long way.
|
|
|
|
TextClass::InsetLayouts::const_iterator it =
|
|
|
|
tclass.insetLayouts().find(style);
|
|
|
|
if (it != tclass.insetLayouts().end()) {
|
|
|
|
docstring const tmpname = name_;
|
|
|
|
this->operator=(it->second);
|
|
|
|
name_ = tmpname;
|
|
|
|
} else {
|
|
|
|
LYXERR0("Cannot copy unknown InsetLayout `"
|
|
|
|
<< style << "'\n"
|
|
|
|
<< "All InsetLayouts so far:");
|
|
|
|
TextClass::InsetLayouts::const_iterator lit =
|
|
|
|
tclass.insetLayouts().begin();
|
|
|
|
TextClass::InsetLayouts::const_iterator len =
|
|
|
|
tclass.insetLayouts().end();
|
|
|
|
for (; lit != len; ++lit)
|
|
|
|
lyxerr << lit->second.name() << "\n";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-22 03:27:42 +00:00
|
|
|
case IL_FONT: {
|
2008-04-05 10:34:29 +00:00
|
|
|
font_ = lyxRead(lex, inherit_font);
|
2008-03-03 04:19:50 +00:00
|
|
|
// If you want to define labelfont, you need to do so after
|
|
|
|
// font is defined.
|
|
|
|
labelfont_ = font_;
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-04-05 10:34:29 +00:00
|
|
|
case IL_BGCOLOR:
|
|
|
|
lex >> tmp;
|
|
|
|
bgcolor_ = lcolor.getFromLyXName(tmp);
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
|
|
|
case IL_PREAMBLE:
|
2009-06-03 23:44:31 +00:00
|
|
|
preamble_ = from_utf8(lex.getLongString("EndPreamble"));
|
2008-02-22 03:27:42 +00:00
|
|
|
break;
|
2010-03-17 12:23:24 +00:00
|
|
|
case IL_REFPREFIX:
|
|
|
|
lex >> refprefix_;
|
|
|
|
break;
|
2009-06-05 17:36:51 +00:00
|
|
|
case IL_HTMLTAG:
|
|
|
|
lex >> htmltag_;
|
|
|
|
break;
|
|
|
|
case IL_HTMLATTR:
|
|
|
|
lex >> htmlattr_;
|
|
|
|
break;
|
2009-10-27 14:33:01 +00:00
|
|
|
case IL_HTMLFORCECSS:
|
|
|
|
lex >> htmlforcecss_;
|
|
|
|
break;
|
2009-06-06 03:02:43 +00:00
|
|
|
case IL_HTMLINNERTAG:
|
|
|
|
lex >> htmlinnertag_;
|
|
|
|
break;
|
|
|
|
case IL_HTMLINNERATTR:
|
|
|
|
lex >> htmlinnerattr_;
|
|
|
|
break;
|
|
|
|
case IL_HTMLLABEL:
|
|
|
|
lex >> htmllabel_;
|
|
|
|
break;
|
2009-10-26 20:53:46 +00:00
|
|
|
case IL_HTMLISBLOCK:
|
|
|
|
lex >> htmlisblock_;
|
|
|
|
break;
|
2009-06-05 17:36:51 +00:00
|
|
|
case IL_HTMLSTYLE:
|
|
|
|
htmlstyle_ = from_utf8(lex.getLongString("EndHTMLStyle"));
|
|
|
|
break;
|
2009-06-05 19:42:56 +00:00
|
|
|
case IL_HTMLPREAMBLE:
|
|
|
|
htmlpreamble_ = from_utf8(lex.getLongString("EndPreamble"));
|
|
|
|
break;
|
2008-02-22 03:27:42 +00:00
|
|
|
case IL_REQUIRES: {
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.eatLine();
|
2008-02-22 03:27:42 +00:00
|
|
|
vector<string> const req
|
2008-04-05 10:34:29 +00:00
|
|
|
= support::getVectorFromString(lex.getString());
|
2008-02-22 03:27:42 +00:00
|
|
|
requires_.insert(req.begin(), req.end());
|
|
|
|
break;
|
|
|
|
}
|
2010-02-13 15:44:17 +00:00
|
|
|
case IL_SPELLCHECK:
|
|
|
|
lex >> spellcheck_;
|
|
|
|
break;
|
2008-02-22 03:27:42 +00:00
|
|
|
case IL_END:
|
|
|
|
getout = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Here add element to list if getout == true
|
|
|
|
if (!getout)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The label font is generally used as-is without
|
|
|
|
// any realization against a given context.
|
|
|
|
labelfont_.realize(sane_font);
|
|
|
|
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.popTable();
|
2008-02-22 03:27:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-10-25 13:32:54 +00:00
|
|
|
|
|
|
|
InsetLayout::InsetLyXType translateLyXType(std::string const & str)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (support::compare_ascii_no_case(str, "charstyle") == 0)
|
|
|
|
return InsetLayout::CHARSTYLE;
|
|
|
|
if (support::compare_ascii_no_case(str, "custom") == 0)
|
|
|
|
return InsetLayout::CUSTOM;
|
|
|
|
if (support::compare_ascii_no_case(str, "element") == 0)
|
|
|
|
return InsetLayout::ELEMENT;
|
|
|
|
if (support::compare_ascii_no_case(str, "end") == 0)
|
|
|
|
return InsetLayout::END;
|
|
|
|
if (support::compare_ascii_no_case(str, "standard") == 0)
|
|
|
|
return InsetLayout::STANDARD;
|
|
|
|
return InsetLayout::NOLYXTYPE;
|
|
|
|
}
|
|
|
|
|
2009-10-27 14:33:01 +00:00
|
|
|
|
2009-10-27 19:46:47 +00:00
|
|
|
string const & InsetLayout::htmltag() const
|
|
|
|
{
|
|
|
|
if (htmltag_.empty())
|
2009-11-19 22:49:30 +00:00
|
|
|
htmltag_ = multipar_ ? "div" : "span";
|
2009-10-27 19:46:47 +00:00
|
|
|
return htmltag_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-27 19:17:52 +00:00
|
|
|
string const & InsetLayout::htmlattr() const
|
|
|
|
{
|
|
|
|
if (htmlattr_.empty())
|
|
|
|
htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
|
|
|
|
return htmlattr_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const & InsetLayout::htmlinnerattr() const
|
|
|
|
{
|
|
|
|
if (htmlinnerattr_.empty())
|
|
|
|
htmlinnerattr_ = "class=\"" + defaultCSSClass() + "_inner\"";
|
|
|
|
return htmlinnerattr_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-27 14:33:01 +00:00
|
|
|
string InsetLayout::defaultCSSClass() const
|
|
|
|
{
|
|
|
|
if (!defaultcssclass_.empty())
|
|
|
|
return defaultcssclass_;
|
2009-10-27 19:17:52 +00:00
|
|
|
string d;
|
|
|
|
string n = to_utf8(name());
|
|
|
|
string::const_iterator it = n.begin();
|
|
|
|
string::const_iterator en = n.end();
|
2009-10-27 14:33:01 +00:00
|
|
|
for (; it != en; ++it) {
|
|
|
|
if (!isalpha(*it))
|
2009-10-27 19:17:52 +00:00
|
|
|
d += "_";
|
|
|
|
else if (islower(*it))
|
2009-10-27 14:33:01 +00:00
|
|
|
d += *it;
|
2009-10-27 19:17:52 +00:00
|
|
|
else
|
2009-10-27 14:33:01 +00:00
|
|
|
d += support::lowercase(*it);
|
|
|
|
}
|
|
|
|
// are there other characters we need to remove?
|
2009-10-27 19:17:52 +00:00
|
|
|
defaultcssclass_ = d;
|
2009-10-27 14:33:01 +00:00
|
|
|
return defaultcssclass_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetLayout::makeDefaultCSS() const
|
|
|
|
{
|
|
|
|
if (!htmldefaultstyle_.empty())
|
|
|
|
return;
|
2009-10-27 19:46:47 +00:00
|
|
|
docstring const mainfontCSS = font_.asCSS();
|
|
|
|
if (!mainfontCSS.empty())
|
|
|
|
htmldefaultstyle_ =
|
|
|
|
from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
|
|
|
|
mainfontCSS + from_ascii("\n}\n");
|
2009-10-27 14:33:01 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 19:46:47 +00:00
|
|
|
|
2009-10-27 14:33:01 +00:00
|
|
|
docstring InsetLayout::htmlstyle() const
|
|
|
|
{
|
|
|
|
if (!htmlstyle_.empty() && !htmlforcecss_)
|
|
|
|
return htmlstyle_;
|
2009-10-27 19:46:47 +00:00
|
|
|
if (htmldefaultstyle_.empty())
|
2009-10-27 14:33:01 +00:00
|
|
|
makeDefaultCSS();
|
|
|
|
docstring retval = htmldefaultstyle_;
|
|
|
|
if (!htmlstyle_.empty())
|
2009-10-27 19:46:47 +00:00
|
|
|
retval += '\n' + htmlstyle_ + '\n';
|
2009-10-27 14:33:01 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 03:27:42 +00:00
|
|
|
} //namespace lyx
|