1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-1999 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-11-04 01:40:20 +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-11-08 13:54:04 +00:00
|
|
|
using std::make_pair;
|
|
|
|
using std::sort;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "definitions.h"
|
|
|
|
#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"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
// Global variable: textclass table.
|
|
|
|
LyXTextClassList textclasslist;
|
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-09-27 18:44:28 +00:00
|
|
|
LT_ALIGN, LT_ALIGNPOSSIBLE,
|
|
|
|
LT_BLOCK, LT_MARGIN,
|
|
|
|
LT_BOTTOMSEP, LT_CENTER, LT_CENTERED_TOP_ENVIRONMENT, LT_COLUMNS,
|
|
|
|
LT_COPYSTYLE, LT_OBSOLETEDBY,
|
|
|
|
LT_COMMAND, LT_COUNTER_CHAPTER, LT_COUNTER_ENUMI, LT_COUNTER_ENUMII,
|
|
|
|
LT_COUNTER_ENUMIII, LT_COUNTER_ENUMIV, LT_COUNTER_PARAGRAPH,
|
|
|
|
LT_COUNTER_SECTION, LT_COUNTER_SUBPARAGRAPH, LT_COUNTER_SUBSECTION,
|
|
|
|
LT_COUNTER_SUBSUBSECTION, LT_DEFAULTFONT, LT_DYNAMIC, LT_EMPTY,
|
|
|
|
LT_END, LT_ENVIRONMENT, LT_ENVIRONMENT_DEFAULT,
|
|
|
|
LT_FANCYHDR, LT_FILL_BOTTOM, LT_FILL_TOP, LT_FIRST_COUNTER,
|
|
|
|
LT_FIRST_DYNAMIC, LT_FONT, LT_FREE_SPACING, LT_HEADINGS, LT_INPUT,
|
|
|
|
LT_ITEM_ENVIRONMENT, LT_ITEMSEP, LT_KEEPEMPTY,
|
|
|
|
LT_LABEL_BOTTOMSEP, LT_LABELFONT, LT_TEXTFONT,
|
|
|
|
LT_LABELINDENT, LT_LABELSEP, LT_LABELSTRING,
|
|
|
|
LT_LABELSTRING_APPENDIX, LT_LABELTYPE,
|
|
|
|
LT_LATEXNAME, LT_LATEXPARAM, LT_LATEXTYPE, LT_LAYOUT, LT_LEFT,
|
|
|
|
LT_LEFTMARGIN,
|
|
|
|
LT_LIST_ENVIRONMENT , LT_MANUAL, LT_MAXCOUNTER,
|
|
|
|
LT_NEED_PROTECT, LT_NEWLINE,
|
|
|
|
LT_NEXTNOINDENT, LT_NO_LABEL, LT_NOSTYLE,
|
|
|
|
LT_PAGESTYLE, LT_PARAGRAPH,
|
|
|
|
LT_PARINDENT, LT_PARSEP, LT_PARSKIP, LT_PLAIN, LT_PREAMBLE,
|
|
|
|
LT_PROVIDESAMSMATH, LT_PROVIDESMAKEIDX, LT_PROVIDESURL, LT_RIGHT,
|
|
|
|
LT_RIGHT_ADDRESS_BOX, LT_RIGHTMARGIN, LT_SENSITIVE, LT_SIDES,
|
|
|
|
LT_SPACING, LT_SPACING_SINGLE, LT_SPACING_ONEHALF,
|
|
|
|
LT_SPACING_DOUBLE, LT_OTHER, LT_CLASSOPTIONS, LT_FONTSIZE,
|
|
|
|
LT_STATIC, LT_STYLE, LT_TOP_ENVIRONMENT, LT_TOPSEP, LT_BIBLIO,
|
|
|
|
LT_INTITLE, LT_SECNUMDEPTH, LT_TOCDEPTH,
|
|
|
|
LT_OUTPUTTYPE, LT_OTLATEX, LT_OTLINUXDOC, LT_OTDOCBOOK, LT_OTLITERATE
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This table is sorted alphabetically [asierra 30March96]
|
|
|
|
static keyword_item layoutTags[] = {
|
|
|
|
{ "align", LT_ALIGN },
|
|
|
|
{ "alignpossible", LT_ALIGNPOSSIBLE },
|
|
|
|
{ "bibliography", LT_BIBLIO },
|
|
|
|
{ "block", LT_BLOCK },
|
|
|
|
{ "bottomsep", LT_BOTTOMSEP },
|
|
|
|
{ "center", LT_CENTER },
|
|
|
|
{ "centered_top_environment", LT_CENTERED_TOP_ENVIRONMENT },
|
|
|
|
{ "classoptions", LT_CLASSOPTIONS },
|
|
|
|
{ "columns", LT_COLUMNS },
|
|
|
|
{ "command", LT_COMMAND },
|
|
|
|
{ "copystyle", LT_COPYSTYLE },
|
|
|
|
{ "counter_chapter", LT_COUNTER_CHAPTER },
|
|
|
|
{ "counter_enumi", LT_COUNTER_ENUMI },
|
|
|
|
{ "counter_enumii", LT_COUNTER_ENUMII },
|
|
|
|
{ "counter_enumiii", LT_COUNTER_ENUMIII },
|
|
|
|
{ "counter_enumiv", LT_COUNTER_ENUMIV },
|
|
|
|
{ "counter_paragraph", LT_COUNTER_PARAGRAPH },
|
|
|
|
{ "counter_section", LT_COUNTER_SECTION },
|
|
|
|
{ "counter_subparagraph", LT_COUNTER_SUBPARAGRAPH },
|
|
|
|
{ "counter_subsection", LT_COUNTER_SUBSECTION },
|
|
|
|
{ "counter_subsubsection", LT_COUNTER_SUBSUBSECTION },
|
|
|
|
{ "defaultfont", LT_DEFAULTFONT },
|
|
|
|
{ "docbook", LT_OTDOCBOOK },
|
|
|
|
{ "double", LT_SPACING_DOUBLE },
|
|
|
|
{ "dynamic", LT_DYNAMIC },
|
|
|
|
{ "empty", LT_EMPTY },
|
|
|
|
{ "end", LT_END },
|
|
|
|
{ "environment", LT_ENVIRONMENT },
|
|
|
|
{ "environment_default", LT_ENVIRONMENT_DEFAULT },
|
|
|
|
{ "fancyhdr", LT_FANCYHDR },
|
|
|
|
{ "fill_bottom", LT_FILL_BOTTOM },
|
|
|
|
{ "fill_top", LT_FILL_TOP },
|
|
|
|
{ "first_counter", LT_FIRST_COUNTER },
|
|
|
|
{ "first_dynamic", LT_FIRST_DYNAMIC },
|
|
|
|
{ "font", LT_FONT },
|
|
|
|
{ "fontsize", LT_FONTSIZE },
|
|
|
|
{ "freespacing", LT_FREE_SPACING },
|
|
|
|
{ "headings", LT_HEADINGS },
|
|
|
|
{ "input", LT_INPUT },
|
|
|
|
{ "intitle", LT_INTITLE },
|
|
|
|
{ "item_environment", LT_ITEM_ENVIRONMENT },
|
|
|
|
{ "itemsep", LT_ITEMSEP },
|
|
|
|
{ "keepempty", LT_KEEPEMPTY },
|
|
|
|
{ "labelbottomsep", LT_LABEL_BOTTOMSEP },
|
|
|
|
{ "labelfont", LT_LABELFONT },
|
|
|
|
{ "labelindent", LT_LABELINDENT },
|
|
|
|
{ "labelsep", LT_LABELSEP },
|
|
|
|
{ "labelstring", LT_LABELSTRING },
|
1999-11-04 01:40:20 +00:00
|
|
|
{ "labelstringappendix", LT_LABELSTRING_APPENDIX },
|
1999-09-27 18:44:28 +00:00
|
|
|
{ "labeltype", LT_LABELTYPE },
|
|
|
|
{ "latex", LT_OTLATEX },
|
|
|
|
{ "latexname", LT_LATEXNAME },
|
|
|
|
{ "latexparam", LT_LATEXPARAM }, //arrae970411
|
|
|
|
{ "latextype", LT_LATEXTYPE },
|
|
|
|
{ "layout", LT_LAYOUT },
|
|
|
|
{ "left", LT_LEFT },
|
|
|
|
{ "leftmargin", LT_LEFTMARGIN },
|
|
|
|
{ "linuxdoc", LT_OTLINUXDOC },
|
|
|
|
{ "list_environment", LT_LIST_ENVIRONMENT },
|
|
|
|
{ "literate", LT_OTLITERATE },
|
|
|
|
{ "manual", LT_MANUAL },
|
|
|
|
{ "margin", LT_MARGIN },
|
|
|
|
{ "maxcounter", LT_MAXCOUNTER },
|
|
|
|
{ "needprotect", LT_NEED_PROTECT },
|
|
|
|
{ "newline", LT_NEWLINE },
|
|
|
|
{ "nextnoindent", LT_NEXTNOINDENT },
|
|
|
|
{ "no_label", LT_NO_LABEL },
|
|
|
|
{ "nostyle", LT_NOSTYLE },
|
|
|
|
{ "obsoletedby", LT_OBSOLETEDBY },
|
|
|
|
{ "onehalf", LT_SPACING_ONEHALF },
|
|
|
|
{ "other", LT_OTHER },
|
|
|
|
{ "outputtype", LT_OUTPUTTYPE },
|
|
|
|
{ "pagestyle", LT_PAGESTYLE },
|
|
|
|
{ "paragraph", LT_PARAGRAPH },
|
|
|
|
{ "parindent", LT_PARINDENT },
|
|
|
|
{ "parsep", LT_PARSEP },
|
|
|
|
{ "parskip", LT_PARSKIP },
|
|
|
|
{ "plain", LT_PLAIN },
|
|
|
|
{ "preamble", LT_PREAMBLE },
|
|
|
|
{ "providesamsmath", LT_PROVIDESAMSMATH },
|
|
|
|
{ "providesmakeidx", LT_PROVIDESMAKEIDX },
|
|
|
|
{ "providesurl", LT_PROVIDESURL },
|
|
|
|
{ "right", LT_RIGHT },
|
|
|
|
{ "right_address_box", LT_RIGHT_ADDRESS_BOX },
|
|
|
|
{ "rightmargin", LT_RIGHTMARGIN },
|
|
|
|
{ "secnumdepth", LT_SECNUMDEPTH },
|
|
|
|
{ "sensitive", LT_SENSITIVE },
|
|
|
|
{ "sides", LT_SIDES },
|
|
|
|
{ "single", LT_SPACING_SINGLE },
|
|
|
|
{ "spacing", LT_SPACING },
|
|
|
|
{ "static", LT_STATIC },
|
|
|
|
{ "style", LT_STYLE },
|
|
|
|
{ "textfont", LT_TEXTFONT },
|
|
|
|
{ "tocdepth", LT_TOCDEPTH },
|
|
|
|
{ "top_environment", LT_TOP_ENVIRONMENT },
|
|
|
|
{ "topsep", LT_TOPSEP }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
// Should or should not. That is the question.
|
|
|
|
// spacing.set(Spacing::OneHalf);
|
|
|
|
fill_top = false;
|
|
|
|
fill_bottom = false;
|
|
|
|
newline_allowed = true;
|
|
|
|
free_spacing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
bool error = false;
|
|
|
|
bool finished = false;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
// parse style section
|
1999-09-27 18:44:28 +00:00
|
|
|
while (!finished && lexrc.IsOK() && !error) {
|
|
|
|
switch(lexrc.lex()) {
|
|
|
|
|
|
|
|
case -2:
|
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case -1: // parse error
|
1999-09-27 18:44:28 +00:00
|
|
|
lexrc.printError("Unknown tag `$$Token'");
|
|
|
|
error = true;
|
|
|
|
break;
|
|
|
|
|
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()) {
|
1999-11-04 01:40:20 +00:00
|
|
|
if (tclass.hasLayout(lexrc.GetString())) {
|
|
|
|
string tmpname = name_;
|
|
|
|
this->operator=(tclass.GetLayout(lexrc.GetString()));
|
|
|
|
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()) {
|
1999-11-04 01:40:20 +00:00
|
|
|
if (tclass.hasLayout(lexrc.GetString())) {
|
|
|
|
string tmpname = name_;
|
|
|
|
this->operator=(tclass.GetLayout(lexrc.GetString()));
|
|
|
|
name_ = tmpname;
|
|
|
|
if (obsoleted_by().empty())
|
|
|
|
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-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
switch(lexrc.lex()) {
|
|
|
|
case LT_STATIC:
|
|
|
|
margintype = MARGIN_STATIC;
|
|
|
|
break;
|
|
|
|
case LT_MANUAL:
|
|
|
|
margintype = MARGIN_MANUAL;
|
|
|
|
break;
|
|
|
|
case LT_DYNAMIC:
|
|
|
|
margintype = MARGIN_DYNAMIC;
|
|
|
|
break;
|
|
|
|
case LT_FIRST_DYNAMIC:
|
|
|
|
margintype = MARGIN_FIRST_DYNAMIC;
|
|
|
|
break;
|
|
|
|
case LT_RIGHT_ADDRESS_BOX:
|
|
|
|
margintype = MARGIN_RIGHT_ADDRESS_BOX;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lexrc.printError("Unknown margin type `$$Token'");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_LATEXTYPE: // Latex style definition.
|
1999-09-27 18:44:28 +00:00
|
|
|
switch (lexrc.lex()) {
|
|
|
|
case LT_PARAGRAPH:
|
|
|
|
latextype=LATEX_PARAGRAPH;
|
|
|
|
break;
|
|
|
|
case LT_COMMAND:
|
|
|
|
latextype=LATEX_COMMAND;
|
|
|
|
break;
|
|
|
|
case LT_ENVIRONMENT:
|
|
|
|
latextype=LATEX_ENVIRONMENT;
|
|
|
|
break;
|
|
|
|
case LT_ITEM_ENVIRONMENT:
|
|
|
|
latextype=LATEX_ITEM_ENVIRONMENT;
|
|
|
|
break;
|
|
|
|
case LT_LIST_ENVIRONMENT:
|
|
|
|
latextype=LATEX_LIST_ENVIRONMENT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lexrc.printError("Unknown latextype `$$Token'");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_INTITLE:
|
|
|
|
intitle = lexrc.next() && lexrc.GetInteger();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_NEED_PROTECT:
|
|
|
|
needprotect = lexrc.next() && lexrc.GetInteger();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_KEEPEMPTY:
|
|
|
|
keepempty = lexrc.next() && lexrc.GetInteger();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_FONT:
|
|
|
|
font.lyxRead(lexrc);
|
|
|
|
labelfont=font;
|
|
|
|
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?
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lexrc.next() && lexrc.GetInteger())
|
|
|
|
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())
|
1999-11-04 01:40:20 +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())
|
1999-11-04 01:40:20 +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-09-27 18:44:28 +00:00
|
|
|
switch (lexrc.lex()) {
|
|
|
|
case LT_NO_LABEL:
|
|
|
|
labeltype = LABEL_NO_LABEL;
|
|
|
|
break;
|
|
|
|
case LT_MANUAL:
|
|
|
|
labeltype = LABEL_MANUAL;
|
|
|
|
break;
|
|
|
|
case LT_TOP_ENVIRONMENT:
|
|
|
|
labeltype = LABEL_TOP_ENVIRONMENT;
|
|
|
|
break;
|
|
|
|
case LT_CENTERED_TOP_ENVIRONMENT:
|
|
|
|
labeltype = LABEL_CENTERED_TOP_ENVIRONMENT;
|
|
|
|
break;
|
|
|
|
case LT_STATIC:
|
|
|
|
labeltype = LABEL_STATIC;
|
|
|
|
break;
|
|
|
|
case LT_SENSITIVE:
|
|
|
|
labeltype = LABEL_SENSITIVE;
|
|
|
|
break;
|
|
|
|
case LT_COUNTER_CHAPTER:
|
|
|
|
labeltype = LABEL_COUNTER_CHAPTER;
|
|
|
|
break;
|
|
|
|
case LT_COUNTER_SECTION:
|
|
|
|
labeltype = LABEL_COUNTER_SECTION;
|
|
|
|
break;
|
|
|
|
case LT_COUNTER_SUBSECTION:
|
|
|
|
labeltype = LABEL_COUNTER_SUBSECTION;
|
|
|
|
break;
|
|
|
|
case LT_COUNTER_SUBSUBSECTION:
|
|
|
|
labeltype = LABEL_COUNTER_SUBSUBSECTION;
|
|
|
|
break;
|
|
|
|
case LT_COUNTER_PARAGRAPH:
|
|
|
|
labeltype = LABEL_COUNTER_PARAGRAPH;
|
|
|
|
break;
|
|
|
|
case LT_COUNTER_SUBPARAGRAPH:
|
|
|
|
labeltype = LABEL_COUNTER_SUBPARAGRAPH;
|
|
|
|
break;
|
|
|
|
case LT_COUNTER_ENUMI:
|
|
|
|
labeltype = LABEL_COUNTER_ENUMI;
|
|
|
|
break;
|
|
|
|
case LT_COUNTER_ENUMII:
|
|
|
|
labeltype = LABEL_COUNTER_ENUMII;
|
|
|
|
break;
|
|
|
|
case LT_COUNTER_ENUMIII:
|
|
|
|
labeltype = LABEL_COUNTER_ENUMIII;
|
|
|
|
break;
|
|
|
|
case LT_COUNTER_ENUMIV:
|
|
|
|
labeltype = LABEL_COUNTER_ENUMIV;
|
|
|
|
break;
|
|
|
|
case LT_BIBLIO:
|
|
|
|
labeltype = LABEL_BIBLIO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lexrc.printError("Unknown labeltype `$$Token'");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
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())
|
|
|
|
leftmargin = lexrc.GetString();
|
|
|
|
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())
|
|
|
|
rightmargin = lexrc.GetString();
|
|
|
|
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())
|
|
|
|
labelindent = lexrc.GetString();
|
|
|
|
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())
|
|
|
|
parindent = lexrc.GetString();
|
|
|
|
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())
|
|
|
|
parskip = lexrc.GetFloat();
|
|
|
|
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())
|
|
|
|
itemsep = lexrc.GetFloat();
|
|
|
|
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())
|
|
|
|
topsep = lexrc.GetFloat();
|
|
|
|
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())
|
|
|
|
bottomsep = lexrc.GetFloat();
|
|
|
|
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())
|
|
|
|
labelbottomsep = lexrc.GetFloat();
|
|
|
|
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()) {
|
1999-10-26 23:33:30 +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())
|
|
|
|
parsep = lexrc.GetFloat();
|
|
|
|
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())
|
|
|
|
fill_top = lexrc.GetInteger();
|
|
|
|
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())
|
|
|
|
fill_bottom = lexrc.GetInteger();
|
|
|
|
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())
|
|
|
|
newline_allowed = lexrc.GetInteger();
|
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_ALIGN: // paragraph align
|
1999-09-27 18:44:28 +00:00
|
|
|
switch (lexrc.lex()) {
|
|
|
|
case LT_BLOCK:
|
|
|
|
align = LYX_ALIGN_BLOCK;
|
|
|
|
break;
|
|
|
|
case LT_LEFT:
|
|
|
|
align = LYX_ALIGN_LEFT;
|
|
|
|
break;
|
|
|
|
case LT_RIGHT:
|
|
|
|
align = LYX_ALIGN_RIGHT;
|
|
|
|
break;
|
|
|
|
case LT_CENTER:
|
|
|
|
align = LYX_ALIGN_CENTER;
|
|
|
|
break;
|
|
|
|
case LT_LAYOUT:
|
|
|
|
align = LYX_ALIGN_LAYOUT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lexrc.printError("Unknown alignment `$$Token'");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
case LT_ALIGNPOSSIBLE: // paragraph allowed align
|
|
|
|
{ alignpossible = LYX_ALIGN_NONE;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
int lineno = lexrc.GetLineNo();
|
|
|
|
do {
|
|
|
|
switch (lexrc.lex()) {
|
|
|
|
case LT_BLOCK:
|
|
|
|
alignpossible |= LYX_ALIGN_BLOCK;
|
|
|
|
break;
|
|
|
|
case LT_LEFT:
|
|
|
|
alignpossible |= LYX_ALIGN_LEFT;
|
|
|
|
break;
|
|
|
|
case LT_RIGHT:
|
|
|
|
alignpossible |= LYX_ALIGN_RIGHT;
|
|
|
|
break;
|
|
|
|
case LT_CENTER:
|
|
|
|
alignpossible |= LYX_ALIGN_CENTER;
|
|
|
|
break;
|
|
|
|
case LT_LAYOUT:
|
|
|
|
alignpossible |= LYX_ALIGN_LAYOUT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lexrc.printError("Unknown alignment `$$Token'");
|
|
|
|
|
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
} while (lineno == lexrc.GetLineNo());
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
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())
|
1999-11-04 01:40:20 +00:00
|
|
|
labelstring_ = lexrc.GetString();
|
1999-09-27 18:44:28 +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())
|
1999-11-04 01:40:20 +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())
|
|
|
|
free_spacing = lexrc.GetInteger();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_SPACING: // setspace.sty
|
|
|
|
switch(lexrc.lex()) {
|
|
|
|
case LT_SPACING_SINGLE:
|
|
|
|
spacing.set(Spacing::Single);
|
|
|
|
break;
|
|
|
|
case LT_SPACING_ONEHALF:
|
|
|
|
spacing.set(Spacing::Onehalf);
|
|
|
|
break;
|
|
|
|
case LT_SPACING_DOUBLE:
|
|
|
|
spacing.set(Spacing::Double);
|
|
|
|
break;
|
|
|
|
case LT_OTHER:
|
|
|
|
lexrc.next();
|
|
|
|
spacing.set(Spacing::Other, lexrc.GetFloat());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lexrc.printError("Unknown spacing `$$Token'");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: /* context error */
|
|
|
|
lexrc.printError("Tag `$$Token' is not "
|
|
|
|
"allowed in layout");
|
|
|
|
error = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ******************************************************************* */
|
|
|
|
|
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;
|
|
|
|
lay.resfont.realize(defaultfont());
|
|
|
|
lay.reslabelfont = lay.labelfont;
|
|
|
|
lay.reslabelfont.realize(defaultfont());
|
|
|
|
return false; // no errors
|
|
|
|
}
|
|
|
|
lyxerr << "Error parsing style `" << lay.name() << "'" << endl;
|
|
|
|
return true;
|
1999-09-27 18:44:28 +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
|
|
|
{
|
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-09-27 18:44:28 +00:00
|
|
|
LyXLex lexrc(layoutTags, sizeof(layoutTags)/sizeof(keyword_item));
|
|
|
|
bool error = false;
|
|
|
|
|
|
|
|
lexrc.setFile(filename);
|
1999-11-04 01:40:20 +00:00
|
|
|
if (!lexrc.IsOK()) error = true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
// parsing
|
1999-09-27 18:44:28 +00:00
|
|
|
while (lexrc.IsOK() && !error) {
|
|
|
|
switch(lexrc.lex()) {
|
|
|
|
case -2:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
lexrc.printError("Unknown tag `$$Token'");
|
|
|
|
error = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_OUTPUTTYPE: // output type definition
|
|
|
|
switch(lexrc.lex()) {
|
|
|
|
case LT_OTLATEX:
|
1999-11-04 01:40:20 +00:00
|
|
|
outputType_ = LATEX;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_OTLINUXDOC:
|
1999-11-04 01:40:20 +00:00
|
|
|
outputType_ = LINUXDOC;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_OTDOCBOOK:
|
1999-11-04 01:40:20 +00:00
|
|
|
outputType_ = DOCBOOK;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_OTLITERATE:
|
1999-11-04 01:40:20 +00:00
|
|
|
outputType_ = LITERATE;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lexrc.printError("Unknown output type `$$Token'");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_INPUT: // Include file
|
|
|
|
if (lexrc.next()) {
|
1999-10-02 16:21:10 +00:00
|
|
|
string tmp = LibFileSearch("layouts",
|
1999-09-27 18:44:28 +00:00
|
|
|
lexrc.GetString(),
|
|
|
|
"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;
|
|
|
|
|
|
|
|
case LT_STYLE:
|
|
|
|
if (lexrc.next()) {
|
1999-11-04 01:40:20 +00:00
|
|
|
string name = subst(lexrc.GetString(),
|
|
|
|
'_', ' ');
|
|
|
|
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;
|
|
|
|
lay.name(name);
|
|
|
|
if (!(error =do_readStyle(lexrc, lay)))
|
|
|
|
layoutlist.push_back(lay);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lexrc.printError("No name given for style: `$$Token'.");
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_NOSTYLE:
|
|
|
|
if (lexrc.next()) {
|
1999-11-04 01:40:20 +00:00
|
|
|
string style = subst(lexrc.GetString(),
|
|
|
|
'_', ' ');
|
|
|
|
if (!delete_layout(style))
|
|
|
|
lexrc.printError("Cannot delete style"
|
|
|
|
" `$$Token'");
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_COLUMNS:
|
|
|
|
if (lexrc.next())
|
1999-11-04 01:40:20 +00:00
|
|
|
columns_ = lexrc.GetInteger();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_SIDES:
|
1999-11-04 01:40:20 +00:00
|
|
|
if (lexrc.next()) {
|
|
|
|
switch(lexrc.GetInteger()) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
case LT_PAGESTYLE:
|
|
|
|
lexrc.next();
|
1999-11-04 01:40:20 +00:00
|
|
|
pagestyle_ = strip(lexrc.GetString());
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_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!");
|
1999-11-04 01:40:20 +00:00
|
|
|
defaultfont_.realize(LyXFont::ALL_SANE);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_MAXCOUNTER:
|
|
|
|
switch (lexrc.lex()) {
|
|
|
|
case LT_COUNTER_CHAPTER:
|
1999-11-04 01:40:20 +00:00
|
|
|
maxcounter_ = LABEL_COUNTER_CHAPTER;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_COUNTER_SECTION:
|
1999-11-04 01:40:20 +00:00
|
|
|
maxcounter_ = LABEL_COUNTER_SECTION;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_COUNTER_SUBSECTION:
|
1999-11-04 01:40:20 +00:00
|
|
|
maxcounter_ = LABEL_COUNTER_SUBSECTION;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_COUNTER_SUBSUBSECTION:
|
1999-11-04 01:40:20 +00:00
|
|
|
maxcounter_ = LABEL_COUNTER_SUBSUBSECTION;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_COUNTER_PARAGRAPH:
|
1999-11-04 01:40:20 +00:00
|
|
|
maxcounter_ = LABEL_COUNTER_PARAGRAPH;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_COUNTER_SUBPARAGRAPH:
|
1999-11-04 01:40:20 +00:00
|
|
|
maxcounter_ = LABEL_COUNTER_SUBPARAGRAPH;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_COUNTER_ENUMI:
|
1999-11-04 01:40:20 +00:00
|
|
|
maxcounter_ = LABEL_COUNTER_ENUMI;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_COUNTER_ENUMII:
|
1999-11-04 01:40:20 +00:00
|
|
|
maxcounter_ = LABEL_COUNTER_ENUMII;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_COUNTER_ENUMIII:
|
1999-11-04 01:40:20 +00:00
|
|
|
maxcounter_ = LABEL_COUNTER_ENUMIII;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_COUNTER_ENUMIV:
|
1999-11-04 01:40:20 +00:00
|
|
|
maxcounter_ = LABEL_COUNTER_ENUMIV;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_SECNUMDEPTH:
|
|
|
|
lexrc.next();
|
1999-11-04 01:40:20 +00:00
|
|
|
secnumdepth_ = lexrc.GetInteger();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_TOCDEPTH:
|
|
|
|
lexrc.next();
|
1999-11-04 01:40:20 +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-09-27 18:44:28 +00:00
|
|
|
case LT_CLASSOPTIONS:
|
|
|
|
{
|
|
|
|
bool getout = true;
|
|
|
|
while (getout && lexrc.IsOK()) {
|
|
|
|
switch (lexrc.lex()) {
|
|
|
|
case LT_FONTSIZE:
|
|
|
|
lexrc.next();
|
1999-11-04 01:40:20 +00:00
|
|
|
opt_fontsize_ = strip(lexrc.GetString());
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_PAGESTYLE:
|
|
|
|
lexrc.next();
|
1999-11-04 01:40:20 +00:00
|
|
|
opt_pagestyle_ = strip(lexrc.GetString());
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_OTHER:
|
|
|
|
lexrc.next();
|
1999-11-04 01:40:20 +00:00
|
|
|
options_ = lexrc.GetString();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case LT_END: getout = false; break;
|
|
|
|
default:
|
|
|
|
lexrc.printError("Out of context tag `$$Token'");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
case LT_PROVIDESAMSMATH:
|
1999-11-04 01:40:20 +00:00
|
|
|
if (lexrc.next() && lexrc.GetInteger())
|
|
|
|
provides_ |= amsmath;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_PROVIDESMAKEIDX:
|
1999-11-04 01:40:20 +00:00
|
|
|
if (lexrc.next() && lexrc.GetInteger())
|
|
|
|
provides_ |= makeidx;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LT_PROVIDESURL:
|
1999-11-04 01:40:20 +00:00
|
|
|
if (lexrc.next() && lexrc.GetInteger())
|
|
|
|
provides_ = url;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
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())
|
1999-11-04 01:40:20 +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())
|
1999-11-04 01:40:20 +00:00
|
|
|
rightmargin_ = lexrc.GetString();
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
lexrc.printError("Out of context tag `$$Token'");
|
|
|
|
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-11-04 01:40:20 +00:00
|
|
|
bool LyXTextClass::hasLayout(string const & name) const
|
|
|
|
{
|
|
|
|
for (LayoutList::const_iterator cit = layoutlist.begin();
|
|
|
|
cit != layoutlist.end(); ++cit) {
|
|
|
|
if ((*cit).name() == name)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXLayout const & LyXTextClass::GetLayout (string const & name) const
|
|
|
|
{
|
|
|
|
for (LayoutList::const_iterator cit = layoutlist.begin();
|
|
|
|
cit != layoutlist.end(); ++cit) {
|
|
|
|
if ((*cit).name() == name)
|
|
|
|
return (*cit);
|
|
|
|
}
|
|
|
|
Assert(false); // we actually require the name to exist.
|
|
|
|
return layoutlist.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LyXLayout & LyXTextClass::GetLayout(string const & name)
|
|
|
|
{
|
|
|
|
for (LayoutList::iterator it = layoutlist.begin();
|
|
|
|
it != layoutlist.end(); ++it) {
|
|
|
|
if ((*it).name() == name)
|
|
|
|
return (*it);
|
|
|
|
}
|
|
|
|
Assert(false); // we actually require the name to exist.
|
|
|
|
return layoutlist.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXTextClass::delete_layout (string const & name)
|
|
|
|
{
|
|
|
|
for(LayoutList::iterator it = layoutlist.begin();
|
|
|
|
it != layoutlist.end(); ++it) {
|
|
|
|
if ((*it).name() == name) {
|
|
|
|
layoutlist.erase(it);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
1999-11-04 01:40:20 +00:00
|
|
|
string 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
|
1999-11-04 01:40:20 +00:00
|
|
|
pair<bool, LyXTextClassList::ClassList::size_type>
|
|
|
|
LyXTextClassList::NumberOfClass(string const & textclass) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
for (ClassList::const_iterator cit = classlist.begin();
|
|
|
|
cit != classlist.end(); ++cit) {
|
|
|
|
if ((*cit).name() == textclass)
|
|
|
|
return make_pair(true, cit - classlist.begin());
|
|
|
|
}
|
|
|
|
return make_pair(false, 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 &
|
|
|
|
LyXTextClassList::Style(LyXTextClassList::ClassList::size_type textclass,
|
|
|
|
LyXTextClass::LayoutList::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
|
1999-11-04 01:40:20 +00:00
|
|
|
pair<bool, LyXTextClass::LayoutList::size_type>
|
|
|
|
LyXTextClassList::NumberOfLayout(LyXTextClassList::ClassList::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();
|
|
|
|
for(unsigned int i = 0; i < classlist[textclass].numLayouts(); ++i) {
|
|
|
|
if (classlist[textclass][i].name() == name)
|
|
|
|
return make_pair(true, i);
|
|
|
|
}
|
|
|
|
if (name == "dummy")
|
|
|
|
return make_pair(true, LYX_DUMMY_LAYOUT);
|
|
|
|
return make_pair(false, 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 &
|
|
|
|
LyXTextClassList::NameOfLayout(LyXTextClassList::ClassList::size_type textclass,
|
|
|
|
LyXTextClass::LayoutList::size_type layout) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
static string dummy("dummy");
|
|
|
|
static string end("@@end@@");
|
|
|
|
classlist[textclass].load();
|
|
|
|
if (layout < classlist[textclass].numLayouts())
|
|
|
|
return classlist[textclass][layout].name();
|
1999-09-27 18:44:28 +00:00
|
|
|
else if (layout == LYX_DUMMY_LAYOUT)
|
1999-11-04 01:40:20 +00:00
|
|
|
return dummy;
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
1999-11-04 01:40:20 +00:00
|
|
|
return end;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gets a textclass name from number
|
1999-11-04 01:40:20 +00:00
|
|
|
string const &
|
|
|
|
LyXTextClassList::NameOfClass(LyXTextClassList::ClassList::size_type number) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
static string dummy("dummy");
|
|
|
|
static string end("@@end@@");
|
|
|
|
if (classlist.size() == 0) {
|
|
|
|
if (number == 0) return dummy;
|
|
|
|
else return end;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
if (number < classlist.size())
|
|
|
|
return classlist[number].name();
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
1999-11-04 01:40:20 +00:00
|
|
|
return end;
|
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 &
|
|
|
|
LyXTextClassList::LatexnameOfClass(LyXTextClassList::ClassList::size_type number) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
static string dummy("dummy");
|
|
|
|
static string end("@@end@@");
|
|
|
|
classlist[number].load();
|
|
|
|
if (classlist.size() == 0) {
|
|
|
|
if (number == 0) return dummy;
|
|
|
|
else return end;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
if (number < classlist.size())
|
|
|
|
return classlist[number].latexname();
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
1999-11-04 01:40:20 +00:00
|
|
|
return end;
|
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 &
|
|
|
|
LyXTextClassList::DescOfClass(LyXTextClassList::ClassList::size_type number) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
static string dummy("dummy");
|
|
|
|
static string end("@@end@@");
|
|
|
|
if (classlist.size() == 0) {
|
|
|
|
if (number == 0) return dummy;
|
|
|
|
else return end;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
if (number < classlist.size())
|
|
|
|
return classlist[number].description();
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
1999-11-04 01:40:20 +00:00
|
|
|
return end;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Gets a textclass structure from number
|
1999-11-04 01:40:20 +00:00
|
|
|
LyXTextClass const &
|
|
|
|
LyXTextClassList::TextClass(LyXTextClassList::ClassList::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");
|
1999-10-07 18:44:17 +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)
|
|
|
|
}
|
|
|
|
|
|
|
|
lex.setFile(real_file);
|
|
|
|
|
|
|
|
if (!lex.IsOK()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "LyXTextClassList::Read: unable to open "
|
|
|
|
"textclass file `" << MakeDisplayPath(real_file, 1000)
|
|
|
|
<< "\'\nCheck your installation. LyX can't continue."
|
|
|
|
<< endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool finished = false;
|
1999-10-02 16:21:10 +00:00
|
|
|
string fname, clname, desc;
|
1999-09-27 18:44:28 +00:00
|
|
|
// Parse config-file
|
|
|
|
while (lex.IsOK() && !finished) {
|
|
|
|
switch (lex.lex()) {
|
|
|
|
case LyXLex::LEX_FEOF:
|
|
|
|
finished = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
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()) {
|
|
|
|
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()) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
if (classlist.size() == 0) {
|
|
|
|
lyxerr << "LyXTextClassList::Read: no textclass found!"
|
|
|
|
<< 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
|
|
|
|
LyXTextClassList::Load (LyXTextClassList::ClassList::size_type number) const
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|