]> git.lyx.org Git - lyx.git/blobdiff - src/bufferparams.C
More 'standard conformant blurb' nonsense.
[lyx.git] / src / bufferparams.C
index f4bfd76fef46979b6637b4e1db9f427cdb165dcc..837e481f29f489c57a32b6db32e0e477984c5280 100644 (file)
@@ -24,6 +24,8 @@
 #include "author.h"
 #include "gettext.h"
 
+#include "LColor.h"
+
 #include "support/lyxalgo.h" // for lyx::count
 #include "support/lyxlib.h"
 #include "support/lstrings.h"
 #include <cstdlib>
 #include <algorithm>
 
+using namespace lyx::support;
+
 using std::ostream;
 using std::endl;
 using std::pair;
 
-#ifdef WITH_WARNINGS
-#warning Do we need this horrible thing? (JMarc)
-#endif
-bool use_babel;
-
 
 BufferParams::BufferParams()
        // Initialize textclass to point to article. if `first' is
@@ -76,6 +75,7 @@ BufferParams::BufferParams()
        sides = LyXTextClass::OneSide;
        columns = 1;
        pagestyle = "default";
+       compressed = false;
        for (int iter = 0; iter < 4; ++iter) {
                user_defined_bullets[iter] = ITEMIZE_DEFAULTS[iter];
                temp_bullets[iter] = ITEMIZE_DEFAULTS[iter];
@@ -122,7 +122,7 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
                if (tmpret == -1)
                        ++tmpret;
                paragraph_separation =
-                       static_cast<BufferParams::PARSEP>(tmpret);
+                       static_cast<PARSEP>(tmpret);
        } else if (token == "\\defskip") {
                lex.nextToken();
                defskip = VSpace(lex.getString());
@@ -170,20 +170,20 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
                if (tmpret == -1)
                        ++tmpret;
                else
-                       papersize2 = tmpret;
+                       papersize2 = VMARGIN_PAPER_TYPE(tmpret);
        } else if (token == "\\paperpackage") {
                int tmpret = lex.findToken(string_paperpackages);
                if (tmpret == -1) {
                        ++tmpret;
-                       paperpackage = BufferParams::PACKAGE_NONE;
+                       paperpackage = PACKAGE_NONE;
                } else
-                       paperpackage = tmpret;
+                       paperpackage = PAPER_PACKAGES(tmpret);
        } else if (token == "\\use_geometry") {
                lex.nextToken();
                use_geometry = lex.getInteger();
        } else if (token == "\\use_amsmath") {
                lex.nextToken();
-               use_amsmath = static_cast<BufferParams::AMS>(
+               use_amsmath = static_cast<AMS>(
                        lex.getInteger());
        } else if (token == "\\use_natbib") {
                lex.nextToken();
@@ -194,6 +194,31 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
        } else if (token == "\\tracking_changes") {
                lex.nextToken();
                tracking_changes = lex.getInteger();
+       } else if (token == "\\branch") {
+               lex.nextToken();
+               string branch = lex.getString();
+               branchlist.add(branch);
+               while (true) {
+                       lex.nextToken();
+                       string const tok = lex.getString();
+                       if (tok == "\\end_branch")
+                               break;
+                       if (tok == "\\selected") {
+                               lex.nextToken();
+                               branchlist.setSelected(branch, lex.getInteger());
+                       }
+                       // not yet operational
+                       if (tok == "\\color") {
+                               lex.nextToken();
+                               string color = lex.getString();
+                               branchlist.setColor(branch, color);
+                               // Update also the LColor table:
+                               if (color == "none") 
+                                       color = lcolor.getX11Name(LColor::background);
+                               lcolor.fill(static_cast<LColor::color>(lcolor.size()), 
+                                               branch, color);
+                       }
+               }
        } else if (token == "\\author") {
                lex.nextToken();
                istringstream ss(STRCONV(lex.getString()));
@@ -205,7 +230,7 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
                if (tmpret == -1)
                        ++tmpret;
                orientation =
-                       static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
+                       static_cast<PAPER_ORIENTATION>(tmpret);
        } else if (token == "\\paperwidth") {
                lex.next();
                paperwidth = lex.getString();
@@ -382,6 +407,17 @@ void BufferParams::writeFile(ostream & os) const
           << "\n\\use_numerical_citations " << use_numerical_citations
           << "\n\\paperorientation " << string_orientation[orientation]
           << '\n';
+
+       std::list<Branch>::const_iterator it = branchlist.begin();
+       std::list<Branch>::const_iterator end = branchlist.end();
+       for (; it != end; ++it) {
+               os << "\\branch " << it->getBranch()
+                  << "\n\\selected " << it->getSelected()      
+                  << "\n\\color " << it->getColor()    
+                  << "\n\\end_branch" 
+                  << "\n";
+       }
+
        if (!paperwidth.empty())
                os << "\\paperwidth "
                   << VSpace(paperwidth).asLyXCommand() << '\n';
@@ -478,6 +514,9 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
        if (!use_geometry &&
            (paperpackage == PACKAGE_NONE)) {
                switch (papersize) {
+               case PAPER_A3PAPER:
+                       clsoptions << "a3paper,";
+                       break;
                case PAPER_A4PAPER:
                        clsoptions << "a4paper,";
                        break;
@@ -496,6 +535,8 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
                case PAPER_LEGALPAPER:
                        clsoptions << "legalpaper,";
                        break;
+               case PAPER_DEFAULT:
+                       break;
                }
        }
 
@@ -524,17 +565,14 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
                clsoptions << "landscape,";
 
        // language should be a parameter to \documentclass
-       use_babel = false;
-       ostringstream language_options;
        if (language->babel() == "hebrew"
            && default_language->babel() != "hebrew")
                // This seems necessary
                features.useLanguage(default_language);
 
-       if (lyxrc.language_use_babel ||
-           language->lang() != lyxrc.default_language ||
-           features.hasLanguages()) {
-               use_babel = true;
+       ostringstream language_options;
+       bool const use_babel = features.useBabel();
+       if (use_babel) {
                language_options << features.getLanguages();
                language_options << language->babel();
                if (lyxrc.language_global_options)
@@ -597,6 +635,8 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
        // 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();
@@ -958,3 +998,60 @@ void BufferParams::readGraphicsDriver(LyXLex & lex)
                }
        }
 }
+
+
+string const BufferParams::paperSizeName() const
+{
+       char real_papersize = papersize;
+       if (real_papersize == PAPER_DEFAULT)
+               real_papersize = lyxrc.default_papersize;
+
+       switch (real_papersize) {
+       case PAPER_A3PAPER:
+               return "a3";
+       case PAPER_A4PAPER:
+               return "a4";
+       case PAPER_A5PAPER:
+               return "a5";
+       case PAPER_B5PAPER:
+               return "b5";
+       case PAPER_EXECUTIVEPAPER:
+               return "foolscap";
+       case PAPER_LEGALPAPER:
+               return "legal";
+       case PAPER_USLETTER:
+       default:
+               return "letter";
+       }
+}
+
+
+string const BufferParams::dvips_options() const
+{
+       string result;
+
+       if (use_geometry
+           && papersize2 == VM_PAPER_CUSTOM
+           && !lyxrc.print_paper_dimension_flag.empty()
+           && !paperwidth.empty()
+           && !paperheight.empty()) {
+               // using a custom papersize
+               result = lyxrc.print_paper_dimension_flag;
+               result += ' ' + paperwidth;
+               result += ',' + paperheight;
+       } else {
+               string const paper_option = paperSizeName();
+               if (paper_option != "letter" ||
+                   orientation != ORIENTATION_LANDSCAPE) {
+                       // dvips won't accept -t letter -t landscape.
+                       // In all other cases, include the paper size
+                       // explicitly.
+                       result = lyxrc.print_paper_flag;
+                       result += ' ' + paper_option;
+               }
+       }
+       if (orientation == ORIENTATION_LANDSCAPE &&
+           papersize2 != VM_PAPER_CUSTOM)
+               result += ' ' + lyxrc.print_landscape_flag;
+       return result;
+}