1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
2000-06-30 14:58:05 +00:00
|
|
|
* ======================================================
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "layout.h"
|
|
|
|
#include "lyxlex.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "lyx_gui_misc.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "gettext.h"
|
1999-11-04 01:40:20 +00:00
|
|
|
#include "support/LAssert.h"
|
2000-10-11 21:06:43 +00:00
|
|
|
#include "support/lyxfunctional.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
#include "support/lstrings.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::pair;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::make_pair;
|
|
|
|
using std::sort;
|
|
|
|
using std::endl;
|
2000-10-12 15:17:42 +00:00
|
|
|
using std::find_if;
|
|
|
|
using std::remove_if;
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
// Global variable: textclass table.
|
|
|
|
LyXTextClassList textclasslist;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Reads the style files
|
|
|
|
void LyXSetStyle()
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
lyxerr[Debug::TCLASS] << "LyXSetStyle: parsing configuration...\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
if (!textclasslist.Read()) {
|
|
|
|
lyxerr[Debug::TCLASS] << "LyXSetStyle: an error occured "
|
|
|
|
"during parsing.\n Exiting." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
lyxerr[Debug::TCLASS] << "LyXSetStyle: configuration parsed." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The order of the LayoutTags enum is no more important. [asierra300396]
|
1999-11-04 01:40:20 +00:00
|
|
|
// Tags indexes.
|
|
|
|
enum LayoutTags {
|
1999-12-01 00:57:31 +00:00
|
|
|
LT_ALIGN = 1,
|
|
|
|
LT_ALIGNPOSSIBLE,
|
|
|
|
LT_MARGIN,
|
|
|
|
LT_BOTTOMSEP,
|
|
|
|
LT_COPYSTYLE,
|
|
|
|
LT_OBSOLETEDBY,
|
|
|
|
//LT_EMPTY,
|
|
|
|
LT_END,
|
|
|
|
//LT_ENVIRONMENT_DEFAULT,
|
|
|
|
//LT_FANCYHDR,
|
|
|
|
LT_FILL_BOTTOM,
|
|
|
|
LT_FILL_TOP,
|
|
|
|
//LT_FIRST_COUNTER,
|
|
|
|
LT_FONT,
|
|
|
|
LT_FREE_SPACING,
|
2001-07-17 09:41:34 +00:00
|
|
|
LT_PASS_THRU,
|
1999-12-01 00:57:31 +00:00
|
|
|
//LT_HEADINGS,
|
|
|
|
LT_ITEMSEP,
|
|
|
|
LT_KEEPEMPTY,
|
|
|
|
LT_LABEL_BOTTOMSEP,
|
|
|
|
LT_LABELFONT,
|
|
|
|
LT_TEXTFONT,
|
|
|
|
LT_LABELINDENT,
|
|
|
|
LT_LABELSEP,
|
|
|
|
LT_LABELSTRING,
|
|
|
|
LT_LABELSTRING_APPENDIX,
|
2000-03-10 13:22:20 +00:00
|
|
|
LT_LABELTYPE,
|
2000-05-12 13:11:20 +00:00
|
|
|
LT_ENDLABELSTRING,
|
2000-03-10 13:22:20 +00:00
|
|
|
LT_ENDLABELTYPE,
|
1999-12-01 00:57:31 +00:00
|
|
|
LT_LATEXNAME,
|
|
|
|
LT_LATEXPARAM,
|
|
|
|
LT_LATEXTYPE,
|
|
|
|
LT_LEFTMARGIN,
|
|
|
|
LT_NEED_PROTECT,
|
|
|
|
LT_NEWLINE,
|
|
|
|
LT_NEXTNOINDENT,
|
|
|
|
LT_PARINDENT,
|
|
|
|
LT_PARSEP,
|
|
|
|
LT_PARSKIP,
|
|
|
|
//LT_PLAIN,
|
|
|
|
LT_PREAMBLE,
|
|
|
|
LT_RIGHTMARGIN,
|
|
|
|
LT_SPACING,
|
|
|
|
LT_TOPSEP,
|
|
|
|
LT_INTITLE
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
/////////////////////
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Constructor for layout
|
|
|
|
LyXLayout::LyXLayout ()
|
|
|
|
{
|
|
|
|
margintype = MARGIN_STATIC;
|
|
|
|
latextype = LATEX_PARAGRAPH;
|
|
|
|
intitle = false;
|
|
|
|
needprotect = false;
|
|
|
|
keepempty = false;
|
|
|
|
font = LyXFont(LyXFont::ALL_INHERIT);
|
|
|
|
labelfont = LyXFont(LyXFont::ALL_INHERIT);
|
|
|
|
resfont = LyXFont(LyXFont::ALL_SANE);
|
|
|
|
reslabelfont = LyXFont(LyXFont::ALL_SANE);
|
|
|
|
nextnoindent = false;
|
|
|
|
parskip = 0.0;
|
|
|
|
itemsep = 0;
|
|
|
|
topsep = 0.0;
|
|
|
|
bottomsep = 0.0;
|
|
|
|
labelbottomsep = 0.0;
|
|
|
|
parsep = 0;
|
|
|
|
align = LYX_ALIGN_BLOCK;
|
|
|
|
alignpossible = LYX_ALIGN_BLOCK;
|
|
|
|
labeltype = LABEL_NO_LABEL;
|
2000-03-10 13:22:20 +00:00
|
|
|
endlabeltype = END_LABEL_NO_LABEL;
|
1999-09-27 18:44:28 +00:00
|
|
|
// Should or should not. That is the question.
|
|
|
|
// spacing.set(Spacing::OneHalf);
|
|
|
|
fill_top = false;
|
|
|
|
fill_bottom = false;
|
|
|
|
newline_allowed = true;
|
|
|
|
free_spacing = false;
|
2001-07-17 09:41:34 +00:00
|
|
|
pass_thru = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
// Reads a layout definition from file
|
|
|
|
bool LyXLayout::Read (LyXLex & lexrc, LyXTextClass const & tclass)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-02-29 02:19:17 +00:00
|
|
|
// This table is sorted alphabetically [asierra 30March96]
|
|
|
|
keyword_item layoutTags[] = {
|
|
|
|
{ "align", LT_ALIGN },
|
|
|
|
{ "alignpossible", LT_ALIGNPOSSIBLE },
|
|
|
|
{ "bottomsep", LT_BOTTOMSEP },
|
|
|
|
{ "copystyle", LT_COPYSTYLE },
|
|
|
|
{ "end", LT_END },
|
2000-05-12 13:11:20 +00:00
|
|
|
{ "endlabelstring", LT_ENDLABELSTRING },
|
2000-03-10 13:22:20 +00:00
|
|
|
{ "endlabeltype", LT_ENDLABELTYPE },
|
2000-02-29 02:19:17 +00:00
|
|
|
{ "fill_bottom", LT_FILL_BOTTOM },
|
|
|
|
{ "fill_top", LT_FILL_TOP },
|
|
|
|
{ "font", LT_FONT },
|
|
|
|
{ "freespacing", LT_FREE_SPACING },
|
|
|
|
{ "intitle", LT_INTITLE },
|
|
|
|
{ "itemsep", LT_ITEMSEP },
|
|
|
|
{ "keepempty", LT_KEEPEMPTY },
|
|
|
|
{ "labelbottomsep", LT_LABEL_BOTTOMSEP },
|
|
|
|
{ "labelfont", LT_LABELFONT },
|
|
|
|
{ "labelindent", LT_LABELINDENT },
|
|
|
|
{ "labelsep", LT_LABELSEP },
|
|
|
|
{ "labelstring", LT_LABELSTRING },
|
|
|
|
{ "labelstringappendix", LT_LABELSTRING_APPENDIX },
|
|
|
|
{ "labeltype", LT_LABELTYPE },
|
|
|
|
{ "latexname", LT_LATEXNAME },
|
|
|
|
{ "latexparam", LT_LATEXPARAM },
|
|
|
|
{ "latextype", LT_LATEXTYPE },
|
|
|
|
{ "leftmargin", LT_LEFTMARGIN },
|
|
|
|
{ "margin", LT_MARGIN },
|
|
|
|
{ "needprotect", LT_NEED_PROTECT },
|
|
|
|
{ "newline", LT_NEWLINE },
|
|
|
|
{ "nextnoindent", LT_NEXTNOINDENT },
|
|
|
|
{ "obsoletedby", LT_OBSOLETEDBY },
|
|
|
|
{ "parindent", LT_PARINDENT },
|
|
|
|
{ "parsep", LT_PARSEP },
|
|
|
|
{ "parskip", LT_PARSKIP },
|
2001-07-17 09:41:34 +00:00
|
|
|
{ "passthru", LT_PASS_THRU },
|
2000-02-29 02:19:17 +00:00
|
|
|
{ "preamble", LT_PREAMBLE },
|
|
|
|
{ "rightmargin", LT_RIGHTMARGIN },
|
|
|
|
{ "spacing", LT_SPACING },
|
|
|
|
{ "textfont", LT_TEXTFONT },
|
|
|
|
{ "topsep", LT_TOPSEP }
|
|
|
|
};
|
2000-04-24 20:58:23 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
bool error = false;
|
|
|
|
bool finished = false;
|
1999-12-01 00:57:31 +00:00
|
|
|
lexrc.pushTable(layoutTags, LT_INTITLE);
|
1999-11-04 01:40:20 +00:00
|
|
|
// parse style section
|
2001-08-06 19:12:46 +00:00
|
|
|
while (!finished && lexrc.isOK() && !error) {
|
1999-12-01 00:57:31 +00:00
|
|
|
int le = lexrc.lex();
|
|
|
|
// See comment in lyxrc.C.
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (le) {
|
1999-12-01 00:57:31 +00:00
|
|
|
case LyXLex::LEX_FEOF:
|
1999-12-13 15:31:52 +00:00
|
|
|
continue;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case LyXLex::LEX_UNDEF: // parse error
|
|
|
|
lexrc.printError("Unknown layout tag `$$Token'");
|
1999-09-27 18:44:28 +00:00
|
|
|
error = true;
|
1999-12-13 15:31:52 +00:00
|
|
|
continue;
|
1999-12-01 00:57:31 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (static_cast<LayoutTags>(le)) {
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_END: // end of structure
|
1999-09-27 18:44:28 +00:00
|
|
|
finished = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_COPYSTYLE: // initialize with a known style
|
|
|
|
if (lexrc.next()) {
|
2001-08-06 19:12:46 +00:00
|
|
|
if (tclass.hasLayout(lexrc.getString())) {
|
|
|
|
string const tmpname = name_;
|
|
|
|
this->operator= (tclass.GetLayout(lexrc.getString()));
|
1999-11-04 01:40:20 +00:00
|
|
|
name_ = tmpname;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
1999-11-04 01:40:20 +00:00
|
|
|
lexrc.printError("Cannot copy known "
|
|
|
|
"style `$$Token'");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_OBSOLETEDBY: // replace with a known style
|
|
|
|
if (lexrc.next()) {
|
2001-08-06 19:12:46 +00:00
|
|
|
if (tclass.hasLayout(lexrc.getString())) {
|
|
|
|
string const tmpname = name_;
|
|
|
|
this->operator= (tclass.GetLayout(lexrc.getString()));
|
1999-11-04 01:40:20 +00:00
|
|
|
name_ = tmpname;
|
|
|
|
if (obsoleted_by().empty())
|
2001-08-06 19:12:46 +00:00
|
|
|
obsoleted_by_ = lexrc.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
|
|
|
lexrc.printError("Cannot replace with"
|
|
|
|
" unknown style "
|
|
|
|
"`$$Token'");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_MARGIN: // Margin style definition.
|
1999-12-01 00:57:31 +00:00
|
|
|
readMargin(lexrc);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_LATEXTYPE: // Latex style definition.
|
1999-12-01 00:57:31 +00:00
|
|
|
readLatexType(lexrc);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_INTITLE:
|
2001-08-06 19:12:46 +00:00
|
|
|
intitle = lexrc.next() && lexrc.getInteger();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_NEED_PROTECT:
|
2001-08-06 19:12:46 +00:00
|
|
|
needprotect = lexrc.next() && lexrc.getInteger();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_KEEPEMPTY:
|
2001-08-06 19:12:46 +00:00
|
|
|
keepempty = lexrc.next() && lexrc.getInteger();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_FONT:
|
|
|
|
font.lyxRead(lexrc);
|
1999-11-15 12:01:38 +00:00
|
|
|
labelfont= font;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_TEXTFONT:
|
|
|
|
font.lyxRead(lexrc);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_LABELFONT:
|
|
|
|
labelfont.lyxRead(lexrc);
|
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_NEXTNOINDENT: // Indent next paragraph?
|
2001-08-06 19:12:46 +00:00
|
|
|
if (lexrc.next() && lexrc.getInteger())
|
1999-09-27 18:44:28 +00:00
|
|
|
nextnoindent = true;
|
|
|
|
else
|
|
|
|
nextnoindent = false;
|
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_LATEXNAME:
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
latexname_ = lexrc.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_LATEXPARAM:
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
latexparam_ = lexrc.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_PREAMBLE:
|
1999-11-04 01:40:20 +00:00
|
|
|
preamble_ = lexrc.getLongString("EndPreamble");
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_LABELTYPE:
|
1999-12-01 00:57:31 +00:00
|
|
|
readLabelType(lexrc);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
2000-03-10 13:22:20 +00:00
|
|
|
|
|
|
|
case LT_ENDLABELTYPE:
|
|
|
|
readEndLabelType(lexrc);
|
|
|
|
break;
|
1999-12-01 00:57:31 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_LEFTMARGIN: // left margin type
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
leftmargin = lexrc.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_RIGHTMARGIN: // right margin type
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
rightmargin = lexrc.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_LABELINDENT: // label indenting flag
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
labelindent = lexrc.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_PARINDENT: // paragraph indent. flag
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
parindent = lexrc.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_PARSKIP: // paragraph skip size
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
parskip = lexrc.getFloat();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_ITEMSEP: // item separation size
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
itemsep = lexrc.getFloat();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_TOPSEP: // top separation size
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
topsep = lexrc.getFloat();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_BOTTOMSEP: // bottom separation size
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
bottomsep = lexrc.getFloat();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_LABEL_BOTTOMSEP: // label bottom separation size
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
labelbottomsep = lexrc.getFloat();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_LABELSEP: // label separator
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next()) {
|
2001-08-06 19:12:46 +00:00
|
|
|
labelsep = subst(lexrc.getString(), 'x', ' ');
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_PARSEP: // par. separation size
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
parsep = lexrc.getFloat();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_FILL_TOP: // fill top flag
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
fill_top = lexrc.getInteger();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_FILL_BOTTOM: // fill bottom flag
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
fill_bottom = lexrc.getInteger();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_NEWLINE: // newlines allowed?
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
newline_allowed = lexrc.getInteger();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_ALIGN: // paragraph align
|
1999-12-01 00:57:31 +00:00
|
|
|
readAlign(lexrc);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_ALIGNPOSSIBLE: // paragraph allowed align
|
1999-12-01 00:57:31 +00:00
|
|
|
readAlignPossible(lexrc);
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_LABELSTRING: // label string definition
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
labelstring_ = lexrc.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
2000-05-12 13:11:20 +00:00
|
|
|
case LT_ENDLABELSTRING: // endlabel string definition
|
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
endlabelstring_ = lexrc.getString();
|
2000-05-12 13:11:20 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_LABELSTRING_APPENDIX: // label string appendix definition
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
labelstring_appendix_ = lexrc.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_FREE_SPACING: // Allow for free spacing.
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
free_spacing = lexrc.getInteger();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
2001-07-17 09:41:34 +00:00
|
|
|
case LT_PASS_THRU: // Allow for pass thru.
|
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
pass_thru = lexrc.getInteger();
|
2001-07-17 09:41:34 +00:00
|
|
|
break;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
case LT_SPACING: // setspace.sty
|
1999-12-01 00:57:31 +00:00
|
|
|
readSpacing(lexrc);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
1999-12-01 00:57:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
lexrc.popTable();
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
enum AlignTags {
|
|
|
|
AT_BLOCK = 1,
|
|
|
|
AT_LEFT,
|
|
|
|
AT_RIGHT,
|
|
|
|
AT_CENTER,
|
|
|
|
AT_LAYOUT
|
|
|
|
};
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
void LyXLayout::readAlign(LyXLex & lexrc)
|
|
|
|
{
|
2000-02-29 02:19:17 +00:00
|
|
|
keyword_item alignTags[] = {
|
|
|
|
{ "block", AT_BLOCK },
|
|
|
|
{ "center", AT_CENTER },
|
|
|
|
{ "layout", AT_LAYOUT },
|
|
|
|
{ "left", AT_LEFT },
|
|
|
|
{ "right", AT_RIGHT }
|
|
|
|
};
|
2000-04-24 20:58:23 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
pushpophelper pph(lexrc, alignTags, AT_LAYOUT);
|
|
|
|
int le = lexrc.lex();
|
|
|
|
switch (le) {
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown alignment `$$Token'");
|
1999-12-20 17:38:37 +00:00
|
|
|
return;
|
1999-12-01 00:57:31 +00:00
|
|
|
default: break;
|
|
|
|
};
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (static_cast<AlignTags>(le)) {
|
1999-12-01 00:57:31 +00:00
|
|
|
case AT_BLOCK:
|
|
|
|
align = LYX_ALIGN_BLOCK;
|
|
|
|
break;
|
|
|
|
case AT_LEFT:
|
|
|
|
align = LYX_ALIGN_LEFT;
|
|
|
|
break;
|
|
|
|
case AT_RIGHT:
|
|
|
|
align = LYX_ALIGN_RIGHT;
|
|
|
|
break;
|
|
|
|
case AT_CENTER:
|
|
|
|
align = LYX_ALIGN_CENTER;
|
|
|
|
break;
|
|
|
|
case AT_LAYOUT:
|
|
|
|
align = LYX_ALIGN_LAYOUT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LyXLayout::readAlignPossible(LyXLex & lexrc)
|
|
|
|
{
|
2000-02-29 02:19:17 +00:00
|
|
|
keyword_item alignTags[] = {
|
|
|
|
{ "block", AT_BLOCK },
|
|
|
|
{ "center", AT_CENTER },
|
|
|
|
{ "layout", AT_LAYOUT },
|
|
|
|
{ "left", AT_LEFT },
|
|
|
|
{ "right", AT_RIGHT }
|
|
|
|
};
|
2000-04-24 20:58:23 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
lexrc.pushTable(alignTags, AT_LAYOUT);
|
|
|
|
alignpossible = LYX_ALIGN_NONE;
|
2001-08-06 19:12:46 +00:00
|
|
|
int lineno = lexrc.getLineNo();
|
1999-12-01 00:57:31 +00:00
|
|
|
do {
|
|
|
|
int le = lexrc.lex();
|
|
|
|
switch (le) {
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown alignment `$$Token'");
|
1999-12-13 15:31:52 +00:00
|
|
|
continue;
|
1999-12-01 00:57:31 +00:00
|
|
|
default: break;
|
|
|
|
};
|
|
|
|
switch (static_cast<AlignTags>(le)) {
|
|
|
|
case AT_BLOCK:
|
|
|
|
alignpossible |= LYX_ALIGN_BLOCK;
|
|
|
|
break;
|
|
|
|
case AT_LEFT:
|
|
|
|
alignpossible |= LYX_ALIGN_LEFT;
|
|
|
|
break;
|
|
|
|
case AT_RIGHT:
|
|
|
|
alignpossible |= LYX_ALIGN_RIGHT;
|
|
|
|
break;
|
|
|
|
case AT_CENTER:
|
|
|
|
alignpossible |= LYX_ALIGN_CENTER;
|
|
|
|
break;
|
|
|
|
case AT_LAYOUT:
|
|
|
|
alignpossible |= LYX_ALIGN_LAYOUT;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-08-06 19:12:46 +00:00
|
|
|
} while (lineno == lexrc.getLineNo());
|
1999-12-01 00:57:31 +00:00
|
|
|
lexrc.popTable();
|
|
|
|
}
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
enum LabelTypeTags {
|
|
|
|
LA_NO_LABEL = 1,
|
|
|
|
LA_MANUAL,
|
|
|
|
LA_TOP_ENVIRONMENT,
|
|
|
|
LA_CENTERED_TOP_ENVIRONMENT,
|
|
|
|
LA_STATIC,
|
|
|
|
LA_SENSITIVE,
|
|
|
|
LA_COUNTER_CHAPTER,
|
|
|
|
LA_COUNTER_SECTION,
|
|
|
|
LA_COUNTER_SUBSECTION,
|
|
|
|
LA_COUNTER_SUBSUBSECTION,
|
|
|
|
LA_COUNTER_PARAGRAPH,
|
|
|
|
LA_COUNTER_SUBPARAGRAPH,
|
|
|
|
LA_COUNTER_ENUMI,
|
|
|
|
LA_COUNTER_ENUMII,
|
|
|
|
LA_COUNTER_ENUMIII,
|
|
|
|
LA_COUNTER_ENUMIV,
|
|
|
|
LA_BIBLIO
|
|
|
|
};
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
void LyXLayout::readLabelType(LyXLex & lexrc)
|
|
|
|
{
|
2000-02-29 02:19:17 +00:00
|
|
|
keyword_item labelTypeTags[] = {
|
|
|
|
{ "bibliography", LA_BIBLIO },
|
|
|
|
{ "centered_top_environment", LA_CENTERED_TOP_ENVIRONMENT },
|
|
|
|
{ "counter_chapter", LA_COUNTER_CHAPTER },
|
|
|
|
{ "counter_enumi", LA_COUNTER_ENUMI },
|
|
|
|
{ "counter_enumii", LA_COUNTER_ENUMII },
|
|
|
|
{ "counter_enumiii", LA_COUNTER_ENUMIII },
|
|
|
|
{ "counter_enumiv", LA_COUNTER_ENUMIV },
|
|
|
|
{ "counter_paragraph", LA_COUNTER_PARAGRAPH },
|
|
|
|
{ "counter_section", LA_COUNTER_SECTION },
|
|
|
|
{ "counter_subparagraph", LA_COUNTER_SUBPARAGRAPH },
|
|
|
|
{ "counter_subsection", LA_COUNTER_SUBSECTION },
|
|
|
|
{ "counter_subsubsection", LA_COUNTER_SUBSUBSECTION },
|
|
|
|
{ "manual", LA_MANUAL },
|
|
|
|
{ "no_label", LA_NO_LABEL },
|
|
|
|
{ "sensitive", LA_SENSITIVE },
|
|
|
|
{ "static", LA_STATIC },
|
|
|
|
{ "top_environment", LA_TOP_ENVIRONMENT }
|
|
|
|
};
|
2000-04-24 20:58:23 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
pushpophelper pph(lexrc, labelTypeTags, LA_BIBLIO);
|
|
|
|
int le = lexrc.lex();
|
|
|
|
switch (le) {
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown labeltype tag `$$Token'");
|
1999-12-20 17:38:37 +00:00
|
|
|
return;
|
1999-12-01 00:57:31 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
switch (static_cast<LabelTypeTags>(le)) {
|
|
|
|
case LA_NO_LABEL:
|
|
|
|
labeltype = LABEL_NO_LABEL;
|
|
|
|
break;
|
|
|
|
case LA_MANUAL:
|
|
|
|
labeltype = LABEL_MANUAL;
|
|
|
|
break;
|
|
|
|
case LA_TOP_ENVIRONMENT:
|
|
|
|
labeltype = LABEL_TOP_ENVIRONMENT;
|
|
|
|
break;
|
|
|
|
case LA_CENTERED_TOP_ENVIRONMENT:
|
|
|
|
labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
|
|
|
|
break;
|
|
|
|
case LA_STATIC:
|
|
|
|
labeltype = LABEL_STATIC;
|
|
|
|
break;
|
|
|
|
case LA_SENSITIVE:
|
|
|
|
labeltype = LABEL_SENSITIVE;
|
|
|
|
break;
|
|
|
|
case LA_COUNTER_CHAPTER:
|
|
|
|
labeltype = LABEL_COUNTER_CHAPTER;
|
|
|
|
break;
|
|
|
|
case LA_COUNTER_SECTION:
|
|
|
|
labeltype = LABEL_COUNTER_SECTION;
|
|
|
|
break;
|
|
|
|
case LA_COUNTER_SUBSECTION:
|
|
|
|
labeltype = LABEL_COUNTER_SUBSECTION;
|
|
|
|
break;
|
|
|
|
case LA_COUNTER_SUBSUBSECTION:
|
|
|
|
labeltype = LABEL_COUNTER_SUBSUBSECTION;
|
|
|
|
break;
|
|
|
|
case LA_COUNTER_PARAGRAPH:
|
|
|
|
labeltype = LABEL_COUNTER_PARAGRAPH;
|
|
|
|
break;
|
|
|
|
case LA_COUNTER_SUBPARAGRAPH:
|
|
|
|
labeltype = LABEL_COUNTER_SUBPARAGRAPH;
|
|
|
|
break;
|
|
|
|
case LA_COUNTER_ENUMI:
|
|
|
|
labeltype = LABEL_COUNTER_ENUMI;
|
|
|
|
break;
|
|
|
|
case LA_COUNTER_ENUMII:
|
|
|
|
labeltype = LABEL_COUNTER_ENUMII;
|
|
|
|
break;
|
|
|
|
case LA_COUNTER_ENUMIII:
|
|
|
|
labeltype = LABEL_COUNTER_ENUMIII;
|
|
|
|
break;
|
|
|
|
case LA_COUNTER_ENUMIV:
|
|
|
|
labeltype = LABEL_COUNTER_ENUMIV;
|
|
|
|
break;
|
|
|
|
case LA_BIBLIO:
|
|
|
|
labeltype = LABEL_BIBLIO;
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-12-01 00:57:31 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
keyword_item endlabelTypeTags[] = {
|
2000-03-10 13:22:20 +00:00
|
|
|
{ "box", END_LABEL_BOX },
|
|
|
|
{ "filled_box", END_LABEL_FILLED_BOX },
|
2000-05-12 13:11:20 +00:00
|
|
|
{ "no_label", END_LABEL_NO_LABEL },
|
|
|
|
{ "static", END_LABEL_STATIC }
|
2000-03-10 13:22:20 +00:00
|
|
|
};
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
2000-03-10 13:22:20 +00:00
|
|
|
void LyXLayout::readEndLabelType(LyXLex & lexrc)
|
|
|
|
{
|
|
|
|
pushpophelper pph(lexrc, endlabelTypeTags,
|
|
|
|
END_LABEL_ENUM_LAST-END_LABEL_ENUM_FIRST+1);
|
|
|
|
int le = lexrc.lex();
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (le) {
|
2000-03-10 13:22:20 +00:00
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown labeltype tag `$$Token'");
|
|
|
|
break;
|
2000-05-12 13:11:20 +00:00
|
|
|
case END_LABEL_STATIC:
|
2000-03-10 13:22:20 +00:00
|
|
|
case END_LABEL_BOX:
|
|
|
|
case END_LABEL_FILLED_BOX:
|
|
|
|
case END_LABEL_NO_LABEL:
|
|
|
|
endlabeltype = static_cast<LYX_END_LABEL_TYPES>(le);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lyxerr << "Unhandled value " << le
|
|
|
|
<< " in LyXLayout::readEndLabelType." << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-12-13 21:59:26 +00:00
|
|
|
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
void LyXLayout::readMargin(LyXLex & lexrc)
|
|
|
|
{
|
2000-02-29 02:19:17 +00:00
|
|
|
keyword_item marginTags[] = {
|
|
|
|
{ "dynamic", MARGIN_DYNAMIC },
|
|
|
|
{ "first_dynamic", MARGIN_FIRST_DYNAMIC },
|
|
|
|
{ "manual", MARGIN_MANUAL },
|
|
|
|
{ "right_address_box", MARGIN_RIGHT_ADDRESS_BOX },
|
|
|
|
{ "static", MARGIN_STATIC }
|
|
|
|
};
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
pushpophelper pph(lexrc, marginTags, MARGIN_RIGHT_ADDRESS_BOX);
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
int le = lexrc.lex();
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (le) {
|
1999-12-01 00:57:31 +00:00
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown margin type tag `$$Token'");
|
2000-02-29 02:19:17 +00:00
|
|
|
return;
|
|
|
|
case MARGIN_STATIC:
|
|
|
|
case MARGIN_MANUAL:
|
|
|
|
case MARGIN_DYNAMIC:
|
|
|
|
case MARGIN_FIRST_DYNAMIC:
|
|
|
|
case MARGIN_RIGHT_ADDRESS_BOX:
|
|
|
|
margintype = static_cast<LYX_MARGIN_TYPE>(le);
|
1999-12-01 00:57:31 +00:00
|
|
|
break;
|
2000-02-29 02:19:17 +00:00
|
|
|
default:
|
|
|
|
lyxerr << "Unhandled value " << le
|
|
|
|
<< " in LyXLayout::readMargin." << endl;
|
1999-12-01 00:57:31 +00:00
|
|
|
break;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
void LyXLayout::readLatexType(LyXLex & lexrc)
|
|
|
|
{
|
2000-02-29 02:19:17 +00:00
|
|
|
keyword_item latexTypeTags[] = {
|
|
|
|
{ "command", LATEX_COMMAND },
|
|
|
|
{ "environment", LATEX_ENVIRONMENT },
|
|
|
|
{ "item_environment", LATEX_ITEM_ENVIRONMENT },
|
|
|
|
{ "list_environment", LATEX_LIST_ENVIRONMENT },
|
|
|
|
{ "paragraph", LATEX_PARAGRAPH }
|
2000-04-24 20:58:23 +00:00
|
|
|
};
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
pushpophelper pph(lexrc, latexTypeTags, LATEX_LIST_ENVIRONMENT);
|
1999-12-01 00:57:31 +00:00
|
|
|
int le = lexrc.lex();
|
|
|
|
switch (le) {
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown latextype tag `$$Token'");
|
2000-02-29 02:19:17 +00:00
|
|
|
return;
|
|
|
|
case LATEX_PARAGRAPH:
|
|
|
|
case LATEX_COMMAND:
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
|
|
|
case LATEX_LIST_ENVIRONMENT:
|
|
|
|
latextype = static_cast<LYX_LATEX_TYPES>(le);
|
1999-12-01 00:57:31 +00:00
|
|
|
break;
|
2000-02-29 02:19:17 +00:00
|
|
|
default:
|
|
|
|
lyxerr << "Unhandled value " << le
|
|
|
|
<< " in LyXLayout::readLatexType." << endl;
|
1999-12-01 00:57:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
enum SpacingTags {
|
|
|
|
ST_SPACING_SINGLE = 1,
|
|
|
|
ST_SPACING_ONEHALF,
|
|
|
|
ST_SPACING_DOUBLE,
|
|
|
|
ST_OTHER
|
|
|
|
};
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
void LyXLayout::readSpacing(LyXLex & lexrc)
|
|
|
|
{
|
2000-02-29 02:19:17 +00:00
|
|
|
keyword_item spacingTags[] = {
|
|
|
|
{"double", ST_SPACING_DOUBLE },
|
|
|
|
{"onehalf", ST_SPACING_ONEHALF },
|
|
|
|
{"other", ST_OTHER },
|
|
|
|
{"single", ST_SPACING_SINGLE }
|
|
|
|
};
|
2000-04-24 20:58:23 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
pushpophelper pph(lexrc, spacingTags, ST_OTHER);
|
|
|
|
int le = lexrc.lex();
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (le) {
|
1999-12-01 00:57:31 +00:00
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown spacing token `$$Token'");
|
1999-12-20 17:38:37 +00:00
|
|
|
return;
|
1999-12-01 00:57:31 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (static_cast<SpacingTags>(le)) {
|
1999-12-01 00:57:31 +00:00
|
|
|
case ST_SPACING_SINGLE:
|
|
|
|
spacing.set(Spacing::Single);
|
|
|
|
break;
|
|
|
|
case ST_SPACING_ONEHALF:
|
|
|
|
spacing.set(Spacing::Onehalf);
|
|
|
|
break;
|
|
|
|
case ST_SPACING_DOUBLE:
|
|
|
|
spacing.set(Spacing::Double);
|
|
|
|
break;
|
|
|
|
case ST_OTHER:
|
|
|
|
lexrc.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
spacing.set(Spacing::Other, lexrc.getFloat());
|
1999-12-01 00:57:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/* ******************************************************************* */
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
LyXTextClass::LyXTextClass(string const & fn, string const & cln,
|
|
|
|
string const & desc)
|
|
|
|
: name_(fn), latexname_(cln), description_(desc)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
outputType_ = LATEX;
|
|
|
|
columns_ = 1;
|
|
|
|
sides_ = OneSide;
|
|
|
|
secnumdepth_ = 3;
|
|
|
|
tocdepth_ = 3;
|
|
|
|
pagestyle_ = "default";
|
|
|
|
maxcounter_ = LABEL_COUNTER_CHAPTER;
|
|
|
|
defaultfont_ = LyXFont(LyXFont::ALL_SANE);
|
|
|
|
opt_fontsize_ = "10|11|12";
|
|
|
|
opt_pagestyle_ = "empty|plain|headings|fancy";
|
|
|
|
provides_ = nothing;
|
1999-09-27 18:44:28 +00:00
|
|
|
loaded = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
|
|
|
|
if (!lay.Read(lexrc, *this)) {
|
|
|
|
// Reslove fonts
|
|
|
|
lay.resfont = lay.font;
|
2001-08-11 18:31:14 +00:00
|
|
|
#ifndef INHERIT_LANGUAGE
|
|
|
|
lay.resfont.realize(defaultfont());
|
|
|
|
lay.reslabelfont = lay.labelfont;
|
|
|
|
lay.reslabelfont.realize(defaultfont());
|
|
|
|
#else
|
2001-07-27 12:03:36 +00:00
|
|
|
lay.resfont.realize(defaultfont(), default_language);
|
1999-11-04 01:40:20 +00:00
|
|
|
lay.reslabelfont = lay.labelfont;
|
2001-07-27 12:03:36 +00:00
|
|
|
lay.reslabelfont.realize(defaultfont(), default_language);
|
2001-08-11 18:31:14 +00:00
|
|
|
#endif
|
1999-11-04 01:40:20 +00:00
|
|
|
return false; // no errors
|
|
|
|
}
|
|
|
|
lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
enum TextClassTags {
|
|
|
|
TC_OUTPUTTYPE = 1,
|
|
|
|
TC_INPUT,
|
|
|
|
TC_STYLE,
|
|
|
|
TC_NOSTYLE,
|
|
|
|
TC_COLUMNS,
|
|
|
|
TC_SIDES,
|
|
|
|
TC_PAGESTYLE,
|
|
|
|
TC_DEFAULTFONT,
|
|
|
|
TC_MAXCOUNTER,
|
|
|
|
TC_SECNUMDEPTH,
|
|
|
|
TC_TOCDEPTH,
|
|
|
|
TC_CLASSOPTIONS,
|
|
|
|
TC_PREAMBLE,
|
|
|
|
TC_PROVIDESAMSMATH,
|
|
|
|
TC_PROVIDESMAKEIDX,
|
|
|
|
TC_PROVIDESURL,
|
|
|
|
TC_LEFTMARGIN,
|
|
|
|
TC_RIGHTMARGIN
|
|
|
|
};
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
// Reads a textclass structure from file.
|
|
|
|
bool LyXTextClass::Read(string const & filename, bool merge)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-02-29 02:19:17 +00:00
|
|
|
keyword_item textClassTags[] = {
|
|
|
|
{ "classoptions", TC_CLASSOPTIONS },
|
|
|
|
{ "columns", TC_COLUMNS },
|
|
|
|
{ "defaultfont", TC_DEFAULTFONT },
|
|
|
|
{ "input", TC_INPUT },
|
|
|
|
{ "leftmargin", TC_LEFTMARGIN },
|
|
|
|
{ "maxcounter", TC_MAXCOUNTER },
|
|
|
|
{ "nostyle", TC_NOSTYLE },
|
|
|
|
{ "outputtype", TC_OUTPUTTYPE },
|
|
|
|
{ "pagestyle", TC_PAGESTYLE },
|
|
|
|
{ "preamble", TC_PREAMBLE },
|
|
|
|
{ "providesamsmath", TC_PROVIDESAMSMATH },
|
|
|
|
{ "providesmakeidx", TC_PROVIDESMAKEIDX },
|
|
|
|
{ "providesurl", TC_PROVIDESURL },
|
|
|
|
{ "rightmargin", TC_RIGHTMARGIN },
|
|
|
|
{ "secnumdepth", TC_SECNUMDEPTH },
|
|
|
|
{ "sides", TC_SIDES },
|
|
|
|
{ "style", TC_STYLE },
|
|
|
|
{ "tocdepth", TC_TOCDEPTH }
|
2000-04-24 20:58:23 +00:00
|
|
|
};
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
if (!merge)
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::TCLASS] << "Reading textclass "
|
|
|
|
<< MakeDisplayPath(filename)
|
|
|
|
<< endl;
|
1999-11-04 01:40:20 +00:00
|
|
|
else
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::TCLASS] << "Reading input file "
|
1999-11-04 01:40:20 +00:00
|
|
|
<< MakeDisplayPath(filename)
|
|
|
|
<< endl;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
LyXLex lexrc(textClassTags, TC_RIGHTMARGIN);
|
1999-09-27 18:44:28 +00:00
|
|
|
bool error = false;
|
|
|
|
|
|
|
|
lexrc.setFile(filename);
|
2001-08-06 19:12:46 +00:00
|
|
|
if (!lexrc.isOK()) error = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
// parsing
|
2001-08-06 19:12:46 +00:00
|
|
|
while (lexrc.isOK() && !error) {
|
1999-12-01 00:57:31 +00:00
|
|
|
int le = lexrc.lex();
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (le) {
|
1999-12-01 00:57:31 +00:00
|
|
|
case LyXLex::LEX_FEOF:
|
1999-12-13 15:31:52 +00:00
|
|
|
continue;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown TextClass tag `$$Token'");
|
1999-09-27 18:44:28 +00:00
|
|
|
error = true;
|
1999-12-13 15:31:52 +00:00
|
|
|
continue;
|
1999-12-01 00:57:31 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (static_cast<TextClassTags>(le)) {
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_OUTPUTTYPE: // output type definition
|
|
|
|
readOutputType(lexrc);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_INPUT: // Include file
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next()) {
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp = LibFileSearch("layouts",
|
2001-08-06 19:12:46 +00:00
|
|
|
lexrc.getString(),
|
1999-09-27 18:44:28 +00:00
|
|
|
"layout");
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
if (Read(tmp, true)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
lexrc.printError("Error reading input"
|
|
|
|
"file: "+tmp);
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_STYLE:
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next()) {
|
2001-08-06 19:12:46 +00:00
|
|
|
string name = subst(lexrc.getString(),
|
1999-11-04 01:40:20 +00:00
|
|
|
'_', ' ');
|
|
|
|
if (hasLayout(name)) {
|
|
|
|
LyXLayout & lay = GetLayout(name);
|
|
|
|
error = do_readStyle(lexrc, lay);
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
1999-11-04 01:40:20 +00:00
|
|
|
LyXLayout lay;
|
2000-10-12 00:11:06 +00:00
|
|
|
lay.setName(name);
|
1999-11-15 12:01:38 +00:00
|
|
|
if (!(error = do_readStyle(lexrc, lay)))
|
1999-11-04 01:40:20 +00:00
|
|
|
layoutlist.push_back(lay);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lexrc.printError("No name given for style: `$$Token'.");
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_NOSTYLE:
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next()) {
|
2001-08-06 19:12:46 +00:00
|
|
|
string const style = subst(lexrc.getString(),
|
1999-11-04 01:40:20 +00:00
|
|
|
'_', ' ');
|
|
|
|
if (!delete_layout(style))
|
|
|
|
lexrc.printError("Cannot delete style"
|
|
|
|
" `$$Token'");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_COLUMNS:
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
columns_ = lexrc.getInteger();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_SIDES:
|
1999-11-04 01:40:20 +00:00
|
|
|
if (lexrc.next()) {
|
2001-08-06 19:12:46 +00:00
|
|
|
switch (lexrc.getInteger()) {
|
1999-11-04 01:40:20 +00:00
|
|
|
case 1: sides_ = OneSide; break;
|
|
|
|
case 2: sides_ = TwoSides; break;
|
|
|
|
default:
|
|
|
|
lyxerr << "Impossible number of page"
|
|
|
|
" sides, setting to one."
|
|
|
|
<< endl;
|
|
|
|
sides_ = OneSide;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_PAGESTYLE:
|
1999-09-27 18:44:28 +00:00
|
|
|
lexrc.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
pagestyle_ = strip(lexrc.getString());
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_DEFAULTFONT:
|
1999-11-04 01:40:20 +00:00
|
|
|
defaultfont_.lyxRead(lexrc);
|
|
|
|
if (!defaultfont_.resolved()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
lexrc.printError("Warning: defaultfont should "
|
|
|
|
"be fully instantiated!");
|
2001-08-11 18:31:14 +00:00
|
|
|
#ifndef INHERIT_LANGUAGE
|
|
|
|
defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
|
|
|
|
#else
|
2001-07-27 12:03:36 +00:00
|
|
|
defaultfont_.realize(LyXFont(LyXFont::ALL_SANE),
|
|
|
|
default_language);
|
2001-08-11 18:31:14 +00:00
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_MAXCOUNTER:
|
|
|
|
readMaxCounter(lexrc);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_SECNUMDEPTH:
|
1999-09-27 18:44:28 +00:00
|
|
|
lexrc.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
secnumdepth_ = lexrc.getInteger();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_TOCDEPTH:
|
1999-09-27 18:44:28 +00:00
|
|
|
lexrc.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
tocdepth_ = lexrc.getInteger();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
// First step to support options
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_CLASSOPTIONS:
|
|
|
|
readClassOptions(lexrc);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_PREAMBLE:
|
1999-11-04 01:40:20 +00:00
|
|
|
preamble_ = lexrc.getLongString("EndPreamble");
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_PROVIDESAMSMATH:
|
2001-08-06 19:12:46 +00:00
|
|
|
if (lexrc.next() && lexrc.getInteger())
|
1999-11-04 01:40:20 +00:00
|
|
|
provides_ |= amsmath;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_PROVIDESMAKEIDX:
|
2001-08-06 19:12:46 +00:00
|
|
|
if (lexrc.next() && lexrc.getInteger())
|
1999-11-04 01:40:20 +00:00
|
|
|
provides_ |= makeidx;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_PROVIDESURL:
|
2001-08-06 19:12:46 +00:00
|
|
|
if (lexrc.next() && lexrc.getInteger())
|
1999-11-04 01:40:20 +00:00
|
|
|
provides_ = url;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_LEFTMARGIN: // left margin type
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
leftmargin_ = lexrc.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
case TC_RIGHTMARGIN: // right margin type
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next())
|
2001-08-06 19:12:46 +00:00
|
|
|
rightmargin_ = lexrc.getString();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
if (!merge) { // we are at top level here.
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::TCLASS] << "Finished reading textclass "
|
|
|
|
<< MakeDisplayPath(filename)
|
|
|
|
<< endl;
|
1999-11-04 01:40:20 +00:00
|
|
|
} else
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::TCLASS] << "Finished reading input file "
|
|
|
|
<< MakeDisplayPath(filename)
|
|
|
|
<< endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
void LyXTextClass::readOutputType(LyXLex & lexrc)
|
|
|
|
{
|
2000-02-29 02:19:17 +00:00
|
|
|
keyword_item outputTypeTags[] = {
|
|
|
|
{ "docbook", DOCBOOK },
|
|
|
|
{ "latex", LATEX },
|
|
|
|
{ "linuxdoc", LINUXDOC },
|
|
|
|
{ "literate", LITERATE }
|
2000-04-24 20:58:23 +00:00
|
|
|
};
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
pushpophelper pph(lexrc, outputTypeTags, LITERATE);
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
int le = lexrc.lex();
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (le) {
|
1999-12-01 00:57:31 +00:00
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown output type `$$Token'");
|
2000-02-29 02:19:17 +00:00
|
|
|
return;
|
|
|
|
case LATEX:
|
|
|
|
case LINUXDOC:
|
|
|
|
case DOCBOOK:
|
|
|
|
case LITERATE:
|
|
|
|
outputType_ = static_cast<OutputType>(le);
|
1999-12-01 00:57:31 +00:00
|
|
|
break;
|
2000-02-29 02:19:17 +00:00
|
|
|
default:
|
|
|
|
lyxerr << "Unhandled value " << le
|
|
|
|
<< " in LyXTextClass::readOutputType." << endl;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
enum MaxCounterTags {
|
|
|
|
MC_COUNTER_CHAPTER = 1,
|
|
|
|
MC_COUNTER_SECTION,
|
|
|
|
MC_COUNTER_SUBSECTION,
|
|
|
|
MC_COUNTER_SUBSUBSECTION,
|
|
|
|
MC_COUNTER_PARAGRAPH,
|
|
|
|
MC_COUNTER_SUBPARAGRAPH,
|
|
|
|
MC_COUNTER_ENUMI,
|
|
|
|
MC_COUNTER_ENUMII,
|
|
|
|
MC_COUNTER_ENUMIII,
|
|
|
|
MC_COUNTER_ENUMIV
|
|
|
|
};
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
void LyXTextClass::readMaxCounter(LyXLex & lexrc)
|
|
|
|
{
|
2000-02-29 02:19:17 +00:00
|
|
|
keyword_item maxCounterTags[] = {
|
|
|
|
{"counter_chapter", MC_COUNTER_CHAPTER },
|
|
|
|
{"counter_enumi", MC_COUNTER_ENUMI },
|
|
|
|
{"counter_enumii", MC_COUNTER_ENUMII },
|
|
|
|
{"counter_enumiii", MC_COUNTER_ENUMIII },
|
|
|
|
{"counter_enumiv", MC_COUNTER_ENUMIV },
|
|
|
|
{"counter_paragraph", MC_COUNTER_PARAGRAPH },
|
|
|
|
{"counter_section", MC_COUNTER_SECTION },
|
|
|
|
{"counter_subparagraph", MC_COUNTER_SUBPARAGRAPH },
|
|
|
|
{"counter_subsection", MC_COUNTER_SUBSECTION },
|
|
|
|
{"counter_subsubsection", MC_COUNTER_SUBSUBSECTION }
|
|
|
|
};
|
2000-04-24 20:58:23 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
pushpophelper pph(lexrc, maxCounterTags, MC_COUNTER_ENUMIV);
|
|
|
|
int le = lexrc.lex();
|
2000-11-04 10:00:12 +00:00
|
|
|
switch (le) {
|
1999-12-01 00:57:31 +00:00
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown MaxCounter tag `$$Token'");
|
1999-12-20 17:38:37 +00:00
|
|
|
return;
|
1999-12-01 00:57:31 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
switch (static_cast<MaxCounterTags>(le)) {
|
|
|
|
case MC_COUNTER_CHAPTER:
|
|
|
|
maxcounter_ = LABEL_COUNTER_CHAPTER;
|
|
|
|
break;
|
|
|
|
case MC_COUNTER_SECTION:
|
|
|
|
maxcounter_ = LABEL_COUNTER_SECTION;
|
|
|
|
break;
|
|
|
|
case MC_COUNTER_SUBSECTION:
|
|
|
|
maxcounter_ = LABEL_COUNTER_SUBSECTION;
|
|
|
|
break;
|
|
|
|
case MC_COUNTER_SUBSUBSECTION:
|
|
|
|
maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
|
|
|
|
break;
|
|
|
|
case MC_COUNTER_PARAGRAPH:
|
|
|
|
maxcounter_ = LABEL_COUNTER_PARAGRAPH;
|
|
|
|
break;
|
|
|
|
case MC_COUNTER_SUBPARAGRAPH:
|
|
|
|
maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
|
|
|
|
break;
|
|
|
|
case MC_COUNTER_ENUMI:
|
|
|
|
maxcounter_ = LABEL_COUNTER_ENUMI;
|
|
|
|
break;
|
|
|
|
case MC_COUNTER_ENUMII:
|
|
|
|
maxcounter_ = LABEL_COUNTER_ENUMII;
|
|
|
|
break;
|
|
|
|
case MC_COUNTER_ENUMIII:
|
|
|
|
maxcounter_ = LABEL_COUNTER_ENUMIII;
|
|
|
|
break;
|
|
|
|
case MC_COUNTER_ENUMIV:
|
|
|
|
maxcounter_ = LABEL_COUNTER_ENUMIV;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
enum ClassOptionsTags {
|
|
|
|
CO_FONTSIZE = 1,
|
|
|
|
CO_PAGESTYLE,
|
|
|
|
CO_OTHER,
|
|
|
|
CO_END
|
|
|
|
};
|
|
|
|
|
1999-12-13 21:59:26 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
void LyXTextClass::readClassOptions(LyXLex & lexrc)
|
|
|
|
{
|
2000-02-29 02:19:17 +00:00
|
|
|
keyword_item classOptionsTags[] = {
|
|
|
|
{"end", CO_END },
|
|
|
|
{"fontsize", CO_FONTSIZE },
|
|
|
|
{"other", CO_OTHER },
|
|
|
|
{"pagestyle", CO_PAGESTYLE }
|
|
|
|
};
|
2000-04-24 20:58:23 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
lexrc.pushTable(classOptionsTags, CO_END);
|
|
|
|
bool getout = false;
|
2001-08-06 19:12:46 +00:00
|
|
|
while (!getout && lexrc.isOK()) {
|
1999-12-01 00:57:31 +00:00
|
|
|
int le = lexrc.lex();
|
|
|
|
switch (le) {
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
lexrc.printError("Unknown ClassOption tag `$$Token'");
|
1999-12-13 15:31:52 +00:00
|
|
|
continue;
|
1999-12-01 00:57:31 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
switch (static_cast<ClassOptionsTags>(le)) {
|
|
|
|
case CO_FONTSIZE:
|
|
|
|
lexrc.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
opt_fontsize_ = strip(lexrc.getString());
|
1999-12-01 00:57:31 +00:00
|
|
|
break;
|
|
|
|
case CO_PAGESTYLE:
|
|
|
|
lexrc.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
opt_pagestyle_ = strip(lexrc.getString());
|
1999-12-01 00:57:31 +00:00
|
|
|
break;
|
|
|
|
case CO_OTHER:
|
|
|
|
lexrc.next();
|
2001-08-06 19:12:46 +00:00
|
|
|
options_ = lexrc.getString();
|
1999-12-01 00:57:31 +00:00
|
|
|
break;
|
|
|
|
case CO_END:
|
|
|
|
getout = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lexrc.popTable();
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
bool LyXTextClass::hasLayout(string const & name) const
|
|
|
|
{
|
2000-10-11 21:06:43 +00:00
|
|
|
return find_if(layoutlist.begin(), layoutlist.end(),
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::compare_memfun(&LyXLayout::name, name))
|
2000-10-11 21:06:43 +00:00
|
|
|
!= layoutlist.end();
|
1999-11-04 01:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXLayout const & LyXTextClass::GetLayout (string const & name) const
|
|
|
|
{
|
2000-10-11 21:06:43 +00:00
|
|
|
LayoutList::const_iterator cit =
|
|
|
|
find_if(layoutlist.begin(),
|
|
|
|
layoutlist.end(),
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::compare_memfun(&LyXLayout::name, name));
|
|
|
|
lyx::Assert(cit != layoutlist.end()); // we require the name to exist
|
2000-10-11 21:06:43 +00:00
|
|
|
return (*cit);
|
1999-11-04 01:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXLayout & LyXTextClass::GetLayout(string const & name)
|
|
|
|
{
|
2000-10-11 21:06:43 +00:00
|
|
|
LayoutList::iterator it =
|
|
|
|
find_if(layoutlist.begin(),
|
|
|
|
layoutlist.end(),
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::compare_memfun(&LyXLayout::name, name));
|
|
|
|
lyx::Assert(it != layoutlist.end()); // we require the name to exist
|
2000-10-11 21:06:43 +00:00
|
|
|
return (*it);
|
1999-11-04 01:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
bool LyXTextClass::delete_layout(string const & name)
|
1999-11-04 01:40:20 +00:00
|
|
|
{
|
2000-10-11 21:06:43 +00:00
|
|
|
LayoutList::iterator it =
|
|
|
|
remove_if(layoutlist.begin(), layoutlist.end(),
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::compare_memfun(&LyXLayout::name, name));
|
2000-10-11 21:06:43 +00:00
|
|
|
LayoutList::iterator end = layoutlist.end();
|
|
|
|
bool const ret = (it != end);
|
|
|
|
layoutlist.erase(it, end);
|
|
|
|
return ret;
|
1999-11-04 01:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Load textclass info if not loaded yet
|
|
|
|
void LyXTextClass::load()
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
if (loaded) return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Read style-file
|
2000-10-11 21:06:43 +00:00
|
|
|
string const real_file = LibFileSearch("layouts", name_, "layout");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (Read(real_file)) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Error reading `"
|
|
|
|
<< MakeDisplayPath(real_file)
|
1999-11-04 01:40:20 +00:00
|
|
|
<< "'\n(Check `" << name_
|
1999-10-07 18:44:17 +00:00
|
|
|
<< "')\nCheck your installation and "
|
|
|
|
"try Options/Reconfigure..." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
loaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
//////////////////////////////////////////
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Gets textclass number from name
|
2000-09-14 17:53:12 +00:00
|
|
|
pair<bool, LyXTextClassList::size_type> const
|
1999-11-04 01:40:20 +00:00
|
|
|
LyXTextClassList::NumberOfClass(string const & textclass) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-10-11 21:06:43 +00:00
|
|
|
ClassList::const_iterator cit =
|
|
|
|
find_if(classlist.begin(), classlist.end(),
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::compare_memfun(&LyXTextClass::name, textclass));
|
2000-10-11 21:06:43 +00:00
|
|
|
return cit != classlist.end() ?
|
|
|
|
make_pair(true, size_type(cit - classlist.begin())) :
|
|
|
|
make_pair(false, size_type(0));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gets layout structure from style number and textclass number
|
1999-11-04 01:40:20 +00:00
|
|
|
LyXLayout const &
|
2000-01-06 02:44:26 +00:00
|
|
|
LyXTextClassList::Style(LyXTextClassList::size_type textclass,
|
|
|
|
LyXTextClass::size_type layout) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
classlist[textclass].load();
|
|
|
|
if (layout < classlist[textclass].numLayouts())
|
|
|
|
return classlist[textclass][layout];
|
|
|
|
return classlist[textclass][0];
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gets layout number from name and textclass number
|
2000-09-14 17:53:12 +00:00
|
|
|
pair<bool, LyXTextClass::size_type> const
|
2000-01-06 02:44:26 +00:00
|
|
|
LyXTextClassList::NumberOfLayout(LyXTextClassList::size_type textclass,
|
|
|
|
string const & name) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
classlist[textclass].load();
|
2000-11-04 10:00:12 +00:00
|
|
|
for (unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
|
1999-11-04 01:40:20 +00:00
|
|
|
if (classlist[textclass][i].name() == name)
|
|
|
|
return make_pair(true, i);
|
|
|
|
}
|
|
|
|
if (name == "dummy")
|
2000-05-19 19:46:23 +00:00
|
|
|
return make_pair(true, LyXTextClassList::size_type(LYX_DUMMY_LAYOUT));
|
|
|
|
return make_pair(false, LyXTextClass::size_type(0)); // not found
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gets a layout (style) name from layout number and textclass number
|
1999-11-04 01:40:20 +00:00
|
|
|
string const &
|
2000-01-06 02:44:26 +00:00
|
|
|
LyXTextClassList::NameOfLayout(LyXTextClassList::size_type textclass,
|
|
|
|
LyXTextClass::size_type layout) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-04 23:57:32 +00:00
|
|
|
static string const dummy("dummy");
|
1999-11-04 01:40:20 +00:00
|
|
|
classlist[textclass].load();
|
|
|
|
if (layout < classlist[textclass].numLayouts())
|
|
|
|
return classlist[textclass][layout].name();
|
1999-12-24 01:30:26 +00:00
|
|
|
return dummy;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gets a textclass name from number
|
1999-11-04 01:40:20 +00:00
|
|
|
string const &
|
2000-01-06 02:44:26 +00:00
|
|
|
LyXTextClassList::NameOfClass(LyXTextClassList::size_type number) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-04 23:57:32 +00:00
|
|
|
static string const dummy("dummy");
|
1999-11-04 01:40:20 +00:00
|
|
|
if (classlist.size() == 0) {
|
1999-12-24 01:30:26 +00:00
|
|
|
return dummy;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::Assert(number < classlist.size());
|
1999-12-24 01:30:26 +00:00
|
|
|
return classlist[number].name();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Gets a textclass latexname from number
|
1999-11-04 01:40:20 +00:00
|
|
|
string const &
|
2000-01-06 02:44:26 +00:00
|
|
|
LyXTextClassList::LatexnameOfClass(LyXTextClassList::size_type number) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-04 23:57:32 +00:00
|
|
|
static string const dummy("dummy");
|
1999-11-04 01:40:20 +00:00
|
|
|
classlist[number].load();
|
|
|
|
if (classlist.size() == 0) {
|
1999-12-24 01:30:26 +00:00
|
|
|
return dummy;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::Assert(number < classlist.size());
|
1999-12-24 01:30:26 +00:00
|
|
|
return classlist[number].latexname();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// Gets a textclass description from number
|
1999-11-04 01:40:20 +00:00
|
|
|
string const &
|
2000-01-06 02:44:26 +00:00
|
|
|
LyXTextClassList::DescOfClass(LyXTextClassList::size_type number) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-04 23:57:32 +00:00
|
|
|
static string const dummy("dummy");
|
1999-11-04 01:40:20 +00:00
|
|
|
if (classlist.size() == 0) {
|
1999-12-24 01:30:26 +00:00
|
|
|
return dummy;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::Assert(number < classlist.size());
|
1999-12-24 01:30:26 +00:00
|
|
|
return classlist[number].description();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gets a textclass structure from number
|
1999-11-04 01:40:20 +00:00
|
|
|
LyXTextClass const &
|
2000-01-06 02:44:26 +00:00
|
|
|
LyXTextClassList::TextClass(LyXTextClassList::size_type textclass) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
classlist[textclass].load();
|
|
|
|
if (textclass < classlist.size())
|
|
|
|
return classlist[textclass];
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
1999-11-04 01:40:20 +00:00
|
|
|
return classlist[0];
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
void LyXTextClassList::Add(LyXTextClass const & t)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
classlist.push_back(t);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
// used when sorting the textclass list.
|
|
|
|
class less_textclass_desc {
|
|
|
|
public:
|
|
|
|
int operator()(LyXTextClass const & tc1, LyXTextClass const & tc2) {
|
|
|
|
return tc1.description() < tc2.description();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
};
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Reads LyX textclass definitions according to textclass config file
|
|
|
|
bool LyXTextClassList::Read ()
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
LyXLex lex(0, 0);
|
|
|
|
string real_file = LibFileSearch("", "textclass.lst");
|
2000-01-07 03:42:16 +00:00
|
|
|
lyxerr[Debug::TCLASS] << "Reading textclasses from `"
|
|
|
|
<< real_file << "'" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (real_file.empty()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "LyXTextClassList::Read: unable to find "
|
|
|
|
"textclass file `" << MakeDisplayPath(real_file, 1000)
|
|
|
|
<< "'. Exiting." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
WriteAlert(_("LyX wasn't able to find its layout descriptions!"),
|
|
|
|
_("Check that the file \"textclass.lst\""),
|
|
|
|
_("is installed correctly. Sorry, has to exit :-("));
|
|
|
|
return false;
|
|
|
|
// This causes LyX to end... Not a desirable behaviour. Lgb
|
|
|
|
// What do you propose? That the user gets a file dialog
|
|
|
|
// and is allowed to hunt for the file? (Asger)
|
1999-12-24 01:30:26 +00:00
|
|
|
// more that we have a layout for minimal.cls statically
|
|
|
|
// compiled in... (Lgb)
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
if (!lex.setFile(real_file)) {
|
|
|
|
lyxerr << "LyXTextClassList::Read: "
|
|
|
|
"lyxlex was not able to set file: "
|
|
|
|
<< real_file << endl;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-08-06 19:12:46 +00:00
|
|
|
if (!lex.isOK()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "LyXTextClassList::Read: unable to open "
|
|
|
|
"textclass file `" << MakeDisplayPath(real_file, 1000)
|
1999-12-01 00:57:31 +00:00
|
|
|
<< "'\nCheck your installation. LyX can't continue."
|
1999-10-07 18:44:17 +00:00
|
|
|
<< endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2001-08-06 19:12:46 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
bool finished = false;
|
|
|
|
// Parse config-file
|
2000-01-07 03:42:16 +00:00
|
|
|
lyxerr[Debug::TCLASS] << "Starting parsing of textclass.lst" << endl;
|
2001-08-06 19:12:46 +00:00
|
|
|
while (lex.isOK() && !finished) {
|
2000-01-07 03:42:16 +00:00
|
|
|
lyxerr[Debug::TCLASS] << "\tline by line" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
switch (lex.lex()) {
|
|
|
|
case LyXLex::LEX_FEOF:
|
|
|
|
finished = true;
|
|
|
|
break;
|
|
|
|
default:
|
2001-08-06 19:12:46 +00:00
|
|
|
string const fname = lex.getString();
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::TCLASS] << "Fname: " << fname << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lex.next()) {
|
2001-08-06 19:12:46 +00:00
|
|
|
string const clname = lex.getString();
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::TCLASS]
|
|
|
|
<< "Clname: " << clname << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lex.next()) {
|
2001-08-06 19:12:46 +00:00
|
|
|
string const desc = lex.getString();
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr[Debug::TCLASS]
|
|
|
|
<< "Desc: " << desc << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
// This code is run when we have
|
|
|
|
// fname, clname and desc
|
1999-11-04 01:40:20 +00:00
|
|
|
LyXTextClass tmpl(fname,
|
|
|
|
clname,
|
|
|
|
desc);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lyxerr.
|
1999-10-07 18:44:17 +00:00
|
|
|
debugging(Debug::TCLASS)) {
|
1999-11-04 01:40:20 +00:00
|
|
|
tmpl.load();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
Add (tmpl);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-01-07 03:42:16 +00:00
|
|
|
lyxerr[Debug::TCLASS] << "End of parsing of textclass.lst" << endl;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
if (classlist.size() == 0) {
|
2000-01-07 03:42:16 +00:00
|
|
|
lyxerr << "LyXTextClassList::Read: no textclasses found!"
|
1999-11-04 01:40:20 +00:00
|
|
|
<< endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
WriteAlert(_("LyX wasn't able to find any layout description!"),
|
|
|
|
_("Check the contents of the file \"textclass.lst\""),
|
|
|
|
_("Sorry, has to exit :-("));
|
|
|
|
return false;
|
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
// Ok everything loaded ok, now sort the list.
|
|
|
|
sort(classlist.begin(), classlist.end(), less_textclass_desc());
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
/* Load textclass
|
|
|
|
Returns false if this fails
|
|
|
|
*/
|
|
|
|
bool
|
2000-01-06 02:44:26 +00:00
|
|
|
LyXTextClassList::Load (LyXTextClassList::size_type number) const
|
1999-11-04 01:40:20 +00:00
|
|
|
{
|
|
|
|
bool result = true;
|
|
|
|
if (number < classlist.size()) {
|
|
|
|
classlist[number].load();
|
|
|
|
if (classlist[number].numLayouts() == 0) {
|
|
|
|
result = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
} else {
|
1999-11-04 01:40:20 +00:00
|
|
|
result = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
std::ostream & operator<<(std::ostream & os, LyXTextClass::PageSides p)
|
|
|
|
{
|
|
|
|
switch (p) {
|
|
|
|
case LyXTextClass::OneSide:
|
|
|
|
os << "1";
|
|
|
|
break;
|
|
|
|
case LyXTextClass::TwoSides:
|
|
|
|
os << "2";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
2000-09-14 17:53:12 +00:00
|
|
|
|