#include "frontends/Alert.h"
#include "support/lyxalgo.h" // for lyx::count
-#include "support/tostr.h"
+#include "support/convert.h"
#include "support/translator.h"
#include <boost/array.hpp>
}
-// Quote times
-typedef Translator<int, InsetQuotes::quote_times> QuotesTimesTranslator;
-
-
-QuotesTimesTranslator const init_quotestimestranslator()
-{
- QuotesTimesTranslator translator(1, InsetQuotes::SingleQ);
- translator.addPair(2, InsetQuotes::DoubleQ);
- return translator;
-}
-
-
-QuotesTimesTranslator const & quotestimestranslator()
-{
- static QuotesTimesTranslator translator = init_quotestimestranslator();
- return translator;
-}
-
-
// Paper size
-typedef Translator<std::string, VMARGIN_PAPER_TYPE> PaperSizeTranslator;
+typedef Translator<std::string, PAPER_SIZE> PaperSizeTranslator;
PaperSizeTranslator const init_papersizetranslator()
{
- PaperSizeTranslator translator(string_papersize[0], VM_PAPER_DEFAULT);
- translator.addPair(string_papersize[1], VM_PAPER_CUSTOM);
- translator.addPair(string_papersize[2], VM_PAPER_USLETTER);
- translator.addPair(string_papersize[3], VM_PAPER_USLEGAL);
- translator.addPair(string_papersize[4], VM_PAPER_USEXECUTIVE);
- translator.addPair(string_papersize[5], VM_PAPER_A3);
- translator.addPair(string_papersize[6], VM_PAPER_A4);
- translator.addPair(string_papersize[7], VM_PAPER_A5);
- translator.addPair(string_papersize[8], VM_PAPER_B3);
- translator.addPair(string_papersize[9], VM_PAPER_B4);
- translator.addPair(string_papersize[10], VM_PAPER_B5);
+ PaperSizeTranslator translator(string_papersize[0], PAPER_DEFAULT);
+ translator.addPair(string_papersize[1], PAPER_CUSTOM);
+ translator.addPair(string_papersize[2], PAPER_USLETTER);
+ translator.addPair(string_papersize[3], PAPER_USLEGAL);
+ translator.addPair(string_papersize[4], PAPER_USEXECUTIVE);
+ translator.addPair(string_papersize[5], PAPER_A3);
+ translator.addPair(string_papersize[6], PAPER_A4);
+ translator.addPair(string_papersize[7], PAPER_A5);
+ translator.addPair(string_papersize[8], PAPER_B3);
+ translator.addPair(string_papersize[9], PAPER_B4);
+ translator.addPair(string_papersize[10], PAPER_B5);
return translator;
}
}
-// Paper packages
-typedef Translator<string, PAPER_PACKAGES> PaperPackagesTranslator;
-
-
-PaperPackagesTranslator const init_paperpackagestranslator()
-{
- PaperPackagesTranslator translator(string_paperpackages[0], PACKAGE_NONE);
- translator.addPair(string_paperpackages[1], PACKAGE_A4);
- translator.addPair(string_paperpackages[2], PACKAGE_A4WIDE);
- translator.addPair(string_paperpackages[3], PACKAGE_WIDEMARGINSA4);
- return translator;
-}
-
-
-PaperPackagesTranslator const & paperpackagestranslator()
-{
- static PaperPackagesTranslator translator = init_paperpackagestranslator();
- return translator;
-}
-
-
// Paper orientation
typedef Translator<string, PAPER_ORIENTATION> PaperOrientationTranslator;
}
-struct BufferParams::Impl
+class BufferParams::Impl
{
+public:
Impl();
AuthorList authorlist;
// true in the returned pair, then `second' is the textclass
// number; if it is false, second is 0. In both cases, second
// is what we want.
- textclass(textclasslist.NumberOfClass("article").second),
+ textclass(textclasslist.numberOfClass("article").second),
pimpl_(new Impl)
{
paragraph_separation = PARSEP_INDENT;
quotes_language = InsetQuotes::EnglishQ;
- quotes_times = InsetQuotes::DoubleQ;
fontsize = "default";
/* PaperLayout */
papersize = PAPER_DEFAULT;
- papersize2 = VM_PAPER_DEFAULT; /* DEFAULT */
- paperpackage = PACKAGE_NONE;
orientation = ORIENTATION_PORTRAIT;
use_geometry = false;
use_amsmath = AMS_AUTO;
cite_engine = biblio::ENGINE_BASIC;
use_bibtopic = false;
tracking_changes = false;
+ output_changes = false;
secnumdepth = 3;
tocdepth = 3;
language = default_language;
lex.next();
string const classname = lex.getString();
pair<bool, lyx::textclass_type> pp =
- textclasslist.NumberOfClass(classname);
+ textclasslist.numberOfClass(classname);
if (pp.first) {
textclass = pp.second;
} else {
- textclass = 0;
- return classname;
+ // if text class does not exist, try to load it from filepath
+ pp = textclasslist.addTextClass(classname, filepath);
+ if (pp.first) {
+ textclass = pp.second;
+ } else {
+ textclass = 0;
+ return classname;
+ }
}
+ // FIXME: isTeXClassAvailable will try to load the layout file, but will
+ // fail because of the lack of path info. Warnings will be given although
+ // the layout file will be correctly loaded later.
if (!getLyXTextClass().isTeXClassAvailable()) {
string const msg =
bformat(_("The document uses a missing "
"TeX class \"%1$s\".\n"), classname);
Alert::warning(_("Document class not available"),
- msg + _("LyX will not be able to produce output."));
+ msg + _("LyX will not be able to produce output."));
}
} else if (token == "\\begin_preamble") {
readPreamble(lex);
string quotes_lang;
lex >> quotes_lang;
quotes_language = quoteslangtranslator().find(quotes_lang);
- } else if (token == "\\quotes_times") {
- int qtimes;
- lex >> qtimes;
- quotes_times = quotestimestranslator().find(qtimes);
} else if (token == "\\papersize") {
string ppsize;
lex >> ppsize;
- papersize2 = papersizetranslator().find(ppsize);
- } else if (token == "\\paperpackage") {
- string ppackage;
- lex >> ppackage;
- paperpackage = paperpackagestranslator().find(ppackage);
+ papersize = papersizetranslator().find(ppsize);
} else if (token == "\\use_geometry") {
lex >> use_geometry;
} else if (token == "\\use_amsmath") {
lex >> use_bibtopic;
} else if (token == "\\tracking_changes") {
lex >> tracking_changes;
+ } else if (token == "\\output_changes") {
+ lex >> output_changes;
} else if (token == "\\branch") {
lex.next();
string branch = lex.getString();
spacing().writeFile(os);
- os << "\\papersize " << string_papersize[papersize2]
- << "\n\\paperpackage " << string_paperpackages[paperpackage]
- << "\n\\use_geometry " << tostr(use_geometry)
+ os << "\\papersize " << string_papersize[papersize]
+ << "\n\\use_geometry " << convert<string>(use_geometry)
<< "\n\\use_amsmath " << use_amsmath
<< "\n\\cite_engine " << citeenginetranslator().find(cite_engine)
- << "\n\\use_bibtopic " << tostr(use_bibtopic)
+ << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
<< "\n\\paperorientation " << string_orientation[orientation]
<< '\n';
- std::list<Branch>::const_iterator it = branchlist().begin();
- std::list<Branch>::const_iterator end = branchlist().end();
+ BranchList::const_iterator it = branchlist().begin();
+ BranchList::const_iterator end = branchlist().end();
for (; it != end; ++it) {
os << "\\branch " << it->getBranch()
<< "\n\\selected " << it->getSelected()
- << "\n\\color " << it->getColor()
+ << "\n\\color " << lyx::X11hexname(it->getColor())
<< "\n\\end_branch"
<< "\n";
}
<< string_paragraph_separation[paragraph_separation]
<< "\n\\defskip " << getDefSkip().asLyXCommand()
<< "\n\\quotes_language "
- << string_quotes_language[quotes_language] << '\n'
- << "\\quotes_times "
- << quotestimestranslator().find(quotes_times)
+ << string_quotes_language[quotes_language]
<< "\n\\papercolumns " << columns
<< "\n\\papersides " << sides
<< "\n\\paperpagestyle " << pagestyle << '\n';
}
}
- os << "\\tracking_changes " << tostr(tracking_changes) << "\n";
+ os << "\\tracking_changes " << convert<string>(tracking_changes) << "\n";
+ os << "\\output_changes " << convert<string>(output_changes) << "\n";
if (tracking_changes) {
AuthorList::Authors::const_iterator it = pimpl_->authorlist.begin();
clsoptions << fontsize << "pt,";
}
+ // custom, A3, B3 and B4 paper sizes need geometry
+ bool nonstandard_papersize = (papersize == PAPER_B3) ||
+ (papersize == PAPER_B4) ||
+ (papersize == PAPER_A3) ||
+ (papersize == PAPER_CUSTOM);
- if (!use_geometry &&
- (paperpackage == PACKAGE_NONE)) {
+ if (!use_geometry) {
switch (papersize) {
- case PAPER_A3PAPER:
- clsoptions << "a3paper,";
- break;
- case PAPER_A4PAPER:
+ case PAPER_A4:
clsoptions << "a4paper,";
break;
case PAPER_USLETTER:
clsoptions << "letterpaper,";
break;
- case PAPER_A5PAPER:
+ case PAPER_A5:
clsoptions << "a5paper,";
break;
- case PAPER_B5PAPER:
+ case PAPER_B5:
clsoptions << "b5paper,";
break;
- case PAPER_EXECUTIVEPAPER:
+ case PAPER_USEXECUTIVE:
clsoptions << "executivepaper,";
break;
- case PAPER_LEGALPAPER:
+ case PAPER_USLEGAL:
clsoptions << "legalpaper,";
break;
case PAPER_DEFAULT:
+ case PAPER_A3:
+ case PAPER_B3:
+ case PAPER_B4:
+ case PAPER_CUSTOM:
break;
}
}
if (inputenc == "auto") {
string const doc_encoding =
- language->encoding()->LatexName();
+ language->encoding()->latexName();
// Create a list with all the input encodings used
// in the document
texrow.newline();
}
- // At the very beginning the text parameters.
- if (paperpackage != PACKAGE_NONE) {
- switch (paperpackage) {
- case PACKAGE_NONE:
- break;
- case PACKAGE_A4:
- os << "\\usepackage{a4}\n";
- texrow.newline();
- break;
- case PACKAGE_A4WIDE:
- os << "\\usepackage{a4wide}\n";
- texrow.newline();
- break;
- case PACKAGE_WIDEMARGINSA4:
- os << "\\usepackage[widemargins]{a4}\n";
- texrow.newline();
- break;
- }
- }
- if (use_geometry) {
+ if (use_geometry || nonstandard_papersize) {
os << "\\usepackage{geometry}\n";
texrow.newline();
os << "\\geometry{verbose";
if (orientation == ORIENTATION_LANDSCAPE)
os << ",landscape";
- switch (papersize2) {
- case VM_PAPER_CUSTOM:
+ switch (papersize) {
+ case PAPER_CUSTOM:
if (!paperwidth.empty())
os << ",paperwidth="
<< paperwidth;
os << ",paperheight="
<< paperheight;
break;
- case VM_PAPER_USLETTER:
+ case PAPER_USLETTER:
os << ",letterpaper";
break;
- case VM_PAPER_USLEGAL:
+ case PAPER_USLEGAL:
os << ",legalpaper";
break;
- case VM_PAPER_USEXECUTIVE:
+ case PAPER_USEXECUTIVE:
os << ",executivepaper";
break;
- case VM_PAPER_A3:
+ case PAPER_A3:
os << ",a3paper";
break;
- case VM_PAPER_A4:
+ case PAPER_A4:
os << ",a4paper";
break;
- case VM_PAPER_A5:
+ case PAPER_A5:
os << ",a5paper";
break;
- case VM_PAPER_B3:
+ case PAPER_B3:
os << ",b3paper";
break;
- case VM_PAPER_B4:
+ case PAPER_B4:
os << ",b4paper";
break;
- case VM_PAPER_B5:
+ case PAPER_B5:
os << ",b5paper";
break;
default:
- // default papersize ie VM_PAPER_DEFAULT
+ // default papersize ie PAPER_DEFAULT
switch (lyxrc.default_papersize) {
case PAPER_DEFAULT: // keep compiler happy
case PAPER_USLETTER:
os << ",letterpaper";
break;
- case PAPER_LEGALPAPER:
+ case PAPER_USLEGAL:
os << ",legalpaper";
break;
- case PAPER_EXECUTIVEPAPER:
+ case PAPER_USEXECUTIVE:
os << ",executivepaper";
break;
- case PAPER_A3PAPER:
+ case PAPER_A3:
os << ",a3paper";
break;
- case PAPER_A4PAPER:
+ case PAPER_A4:
os << ",a4paper";
break;
- case PAPER_A5PAPER:
+ case PAPER_A5:
os << ",a5paper";
break;
- case PAPER_B5PAPER:
+ case PAPER_B5:
os << ",b5paper";
break;
+ case PAPER_B3:
+ case PAPER_B4:
+ case PAPER_CUSTOM:
+ break;
}
}
if (!topmargin.empty())
texrow.newline();
}
- if (secnumdepth != tclass.secnumdepth()) {
- os << "\\setcounter{secnumdepth}{"
- << secnumdepth
- << "}\n";
- texrow.newline();
- }
- if (tocdepth != tclass.tocdepth()) {
- os << "\\setcounter{tocdepth}{"
- << tocdepth
- << "}\n";
- texrow.newline();
+ // Only if class has a ToC hierarchy
+ if (tclass.hasTocLevels()) {
+ if (secnumdepth != tclass.secnumdepth()) {
+ os << "\\setcounter{secnumdepth}{"
+ << secnumdepth
+ << "}\n";
+ texrow.newline();
+ }
+ if (tocdepth != tclass.tocdepth()) {
+ os << "\\setcounter{tocdepth}{"
+ << tocdepth
+ << "}\n";
+ texrow.newline();
+ }
}
if (paragraph_separation) {
if (user_defined_bullet(i) != ITEMIZE_DEFAULTS[i]) {
if (bullets_def.empty())
bullets_def="\\AtBeginDocument{\n";
- bullets_def += " \\renewcommand{\\labelitemi";
+ bullets_def += " \\def\\labelitemi";
switch (i) {
// `i' is one less than the item to modify
case 0:
bullets_def += 'v';
break;
}
- bullets_def += "}{" +
+ bullets_def += '{' +
user_defined_bullet(i).getText()
+ "}\n";
}
lyxpreamble += "\\makeatother\n";
// dvipost settings come after everything else
- if (tracking_changes) {
+ if (features.isAvailable("dvipost") && tracking_changes && output_changes) {
lyxpreamble +=
"\\dvipostlayout\n"
"\\dvipost{osstart color push Red}\n"
}
-void BufferParams::setPaperStuff()
-{
- papersize = PAPER_DEFAULT;
- char const c1 = paperpackage;
- if (c1 == PACKAGE_NONE) {
- char const c2 = papersize2;
- if (c2 == VM_PAPER_USLETTER)
- papersize = PAPER_USLETTER;
- else if (c2 == VM_PAPER_USLEGAL)
- papersize = PAPER_LEGALPAPER;
- else if (c2 == VM_PAPER_USEXECUTIVE)
- papersize = PAPER_EXECUTIVEPAPER;
- else if (c2 == VM_PAPER_A3)
- papersize = PAPER_A3PAPER;
- else if (c2 == VM_PAPER_A4)
- papersize = PAPER_A4PAPER;
- else if (c2 == VM_PAPER_A5)
- papersize = PAPER_A5PAPER;
- else if ((c2 == VM_PAPER_B3) || (c2 == VM_PAPER_B4) ||
- (c2 == VM_PAPER_B5))
- papersize = PAPER_B5PAPER;
- } else if ((c1 == PACKAGE_A4) || (c1 == PACKAGE_A4WIDE) ||
- (c1 == PACKAGE_WIDEMARGINSA4))
- papersize = PAPER_A4PAPER;
-}
-
-
void BufferParams::useClassDefaults()
{
LyXTextClass const & tclass = textclasslist[textclass];
columns = tclass.columns();
pagestyle = tclass.pagestyle();
options = tclass.options();
- secnumdepth = tclass.secnumdepth();
- tocdepth = tclass.tocdepth();
+ // Only if class has a ToC hierarchy
+ if (tclass.hasTocLevels()) {
+ secnumdepth = tclass.secnumdepth();
+ tocdepth = tclass.tocdepth();
+ }
}
}
+LyXFont const BufferParams::getFont() const
+{
+ LyXFont f = getLyXTextClass().defaultfont();
+ f.setLanguage(language);
+ return f;
+}
+
+
void BufferParams::readPreamble(LyXLex & lex)
{
if (lex.getString() != "\\begin_preamble")
if (test == tmptok) {
graphicsDriver = tmptok;
break;
- } else if (test == "last_item") {
+ } else if (test == "") {
lex.printError(
"Warning: graphics driver `$$Token' not recognized!\n"
" Setting graphics driver to `default'.\n");
real_papersize = lyxrc.default_papersize;
switch (real_papersize) {
- case PAPER_A3PAPER:
+ case PAPER_A3:
return "a3";
- case PAPER_A4PAPER:
+ case PAPER_A4:
return "a4";
- case PAPER_A5PAPER:
+ case PAPER_A5:
return "a5";
- case PAPER_B5PAPER:
+ case PAPER_B5:
return "b5";
- case PAPER_EXECUTIVEPAPER:
+ case PAPER_USEXECUTIVE:
return "foolscap";
- case PAPER_LEGALPAPER:
+ case PAPER_USLEGAL:
return "legal";
case PAPER_USLETTER:
default:
string result;
if (use_geometry
- && papersize2 == VM_PAPER_CUSTOM
+ && papersize == PAPER_CUSTOM
&& !lyxrc.print_paper_dimension_flag.empty()
&& !paperwidth.empty()
&& !paperheight.empty()) {
}
}
if (orientation == ORIENTATION_LANDSCAPE &&
- papersize2 != VM_PAPER_CUSTOM)
+ papersize != PAPER_CUSTOM)
result += ' ' + lyxrc.print_landscape_flag;
return result;
}