]> git.lyx.org Git - lyx.git/blobdiff - src/converter.C
try this for distinguishing inner and outer tabs
[lyx.git] / src / converter.C
index 23a9fcad7770fdd6e066aa84fd12f91813247d27..cb1b84653b3cf94a665c6a792c077e26d74fb584 100644 (file)
@@ -173,24 +173,28 @@ bool Formats::View(Buffer const * buffer, string const & filename,
        if (format_name == "dvi" &&
            !lyxrc.view_dvi_paper_option.empty()) {
                command += " " + lyxrc.view_dvi_paper_option;
-               command += " " + converters.dvi_papersize(buffer);
+               string paper_size = converters.papersize(buffer);
+               if (paper_size == "letter")
+                       paper_size = "us";
+               command += " " + paper_size;
                if (buffer->params.orientation 
                    == BufferParams::ORIENTATION_LANDSCAPE)
                        command += 'r';
         }
 
-       string command2 = command + " " + OnlyFilename(filename);
-       lyxerr << "Executing command: " << command2 << endl;
-       ShowMessage(buffer, _("Executing command:"), command2);
+       command += " " + QuoteName(OnlyFilename((filename)));
 
-       command += " " + QuoteName(filename);
+       lyxerr << "Executing command: " << command << endl;
+       ShowMessage(buffer, _("Executing command:"), command);
+
+       Path p(OnlyPath(filename));
        Systemcalls one;
-       int res = one.startscript(Systemcalls::SystemDontWait, command);
+       int const res = one.startscript(Systemcalls::SystemDontWait, command);
 
        if (res) {
                WriteAlert(_("Can not view file"),
                           _("Error while executing"),
-                          command2.substr(0, 50));
+                          command.substr(0, 50));
                return false;
        }
        return true;
@@ -248,7 +252,8 @@ void Converter::ReadFlags()
 
 bool operator<(Converter const & a, Converter const & b)
 {
-       int i = compare_no_case(a.From->prettyname(), b.From->prettyname());
+       int const i = compare_no_case(a.From->prettyname(),
+                                     b.From->prettyname());
        if (i == 0)
                return compare_no_case(a.To->prettyname(), b.To->prettyname())
                        < 0;
@@ -266,8 +271,8 @@ public:
                return c.from == from && c.to == to;
        }
 private:
-       string from;
-       string to;
+       string const & from;
+       string const & to;
 };
 
 
@@ -376,7 +381,7 @@ void Converters::Sort()
 
 int Converters::BFS_init(string const & start, bool clear_visited)
 {
-       int s = formats.GetNumber(start);
+       int const s = formats.GetNumber(start);
        if (s < 0)
                return s;
 
@@ -395,12 +400,12 @@ vector<Format const *> const
 Converters::GetReachableTo(string const & target, bool clear_visited)
 {
        vector<Format const *> result;
-       int s = BFS_init(target, clear_visited);
+       int const s = BFS_init(target, clear_visited);
        if (s < 0)
                return result;
 
        while (!Q.empty()) {
-               int i = Q.front();
+               int const i = Q.front();
                Q.pop();
                if (i != s || target != "lyx")
                        result.push_back(&formats.Get(i));
@@ -426,7 +431,7 @@ Converters::GetReachable(string const & from, bool only_viewable,
                return result;
 
        while (!Q.empty()) {
-               int i = Q.front();
+               int const i = Q.front();
                Q.pop();
                Format const & format = formats.Get(i);
                if (format.name() == "lyx")
@@ -451,13 +456,13 @@ bool Converters::IsReachable(string const & from, string const & to)
        if (from == to)
                return true;
 
-       int s = BFS_init(from);
-       int t = formats.GetNumber(to);
+       int const s = BFS_init(from);
+       int const t = formats.GetNumber(to);
        if (s < 0 || t < 0)
                return false;
 
        while (!Q.empty()) {
-               int i = Q.front();
+               int const i = Q.front();
                Q.pop();
                if (i == t)
                        return true;
@@ -480,7 +485,7 @@ Converters::GetPath(string const & from, string const & to)
        if (from == to)
                return path;
 
-       int s = BFS_init(from);
+       int const s = BFS_init(from);
        int t = formats.GetNumber(to);
        if (s < 0 || t < 0)
                return path;
@@ -490,7 +495,7 @@ Converters::GetPath(string const & from, string const & to)
 
        bool found = false;
        while (!Q.empty()) {
-               int i = Q.front();
+               int const i = Q.front();
                Q.pop();
                if (i == t) {
                        found = true;
@@ -499,10 +504,10 @@ Converters::GetPath(string const & from, string const & to)
                for (vector<int>::iterator it = vertices[i].out_vertices.begin();
                     it != vertices[i].out_vertices.end(); ++it)
                        if (!visited[*it]) {
-                               int j = *it;
+                               int const j = *it;
                                visited[j] = true;
                                Q.push(j);
-                               int k = it - vertices[i].out_vertices.begin();
+                               int const k = it - vertices[i].out_vertices.begin();
                                prev_edge[j] = vertices[i].out_edges[k];
                                prev_vertex[j] = i;
                        }
@@ -604,6 +609,9 @@ bool Converters::Convert(Buffer const * buffer,
                        if (conv.from == "dvi" && conv.to == "ps")
                                command = add_options(command,
                                                      dvips_options(buffer));
+                       else if (conv.from == "dvi" && prefixIs(conv.to, "pdf"))
+                               command = add_options(command,
+                                                     dvipdfm_options(buffer));
 
                        lyxerr << "Calling " << command << endl;
                        if (buffer)
@@ -675,10 +683,10 @@ bool Converters::Move(string const & from, string const & to, bool copy)
                return true;
 
        bool no_errors = true;
-       string path = OnlyPath(from);
-       string base = OnlyFilename(ChangeExtension(from, ""));
-       string to_base = ChangeExtension(to, "");
-       string to_extension = GetExtension(to);
+       string const path = OnlyPath(from);
+       string const base = OnlyFilename(ChangeExtension(from, ""));
+       string const to_base = ChangeExtension(to, "");
+       string const to_extension = GetExtension(to);
 
        vector<string> files = DirList(OnlyPath(from), GetExtension(from));
        for (vector<string>::const_iterator it = files.begin();
@@ -870,7 +878,7 @@ bool Converters::runLaTeX(Buffer const * buffer, string const & command)
 }
 
 
-string const Converters::dvi_papersize(Buffer const * buffer)
+string const Converters::papersize(Buffer const * buffer)
 {
        char real_papersize = buffer->params.papersize;
        if (real_papersize == BufferParams::PAPER_DEFAULT)
@@ -891,7 +899,7 @@ string const Converters::dvi_papersize(Buffer const * buffer)
                return "legal";
        case BufferParams::PAPER_USLETTER:
        default:
-               return "us";
+               return "letter";
        }
 }
 
@@ -912,9 +920,7 @@ string const Converters::dvips_options(Buffer const * buffer)
                result += ' ' + buffer->params.paperwidth;
                result += ',' + buffer->params.paperheight;
        } else {
-               string paper_option = dvi_papersize(buffer);
-               if (paper_option == "us")
-                       paper_option = "letter";
+               string paper_option = papersize(buffer);
                if (paper_option != "letter" ||
                    buffer->params.orientation != BufferParams::ORIENTATION_LANDSCAPE) {
                        // dvips won't accept -t letter -t landscape.  In all other
@@ -923,11 +929,32 @@ string const Converters::dvips_options(Buffer const * buffer)
                        result += ' ' + paper_option;
                }
        }
-       if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
+       if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE &&
+           buffer->params.papersize2 != BufferParams::VM_PAPER_CUSTOM)
                result += ' ' + lyxrc.print_landscape_flag;
        return result;
 }
 
+
+string const Converters::dvipdfm_options(Buffer const * buffer)
+{
+       string result;
+       if (!buffer)
+               return result;
+
+       if (buffer->params.papersize2 != BufferParams::VM_PAPER_CUSTOM) {
+               string paper_size = papersize(buffer);
+               if (paper_size != "b5" && paper_size != "foolscap")
+                       result = "-p "+ paper_size;
+
+               if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
+                       result += " -l";
+       }
+
+       return result;
+}
+
+
 vector<Converters::Vertex> Converters::vertices;