Andre Poenitz wrote: >> Yes, but don't kill the messenger ;^) > > I won't. That's what the 'I'd think so' was good for...
I want to remark that I was joking, and I really apreciate your comments (I think that we are in a state that, if someone reads and understand a piece of code, it's a pitty if he doesn't do the appropriate cleaning as well... I was just being lazy) How about this? Index: ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.1421 diff -u -p -u -r1.1421 ChangeLog --- ChangeLog 17 Jul 2003 06:45:36 -0000 1.1421 +++ ChangeLog 17 Jul 2003 08:01:20 -0000 @@ -1,3 +1,9 @@ +2003-07-17 Alfredo Braunstein <[EMAIL PROTECTED]> + + * format.[Ch] (papersize): moved to BufferParams + * converter.[Ch] (dvips_options): moved to BufferParams + (dvipdfm_options): moved to anon namespace + * bufferparams.[Ch]: added above functions. 2003-07-17 Andr�Pnitz <[EMAIL PROTECTED]> Index: buffer_funcs.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer_funcs.h,v retrieving revision 1.3 diff -u -p -u -r1.3 buffer_funcs.h --- buffer_funcs.h 7 Jul 2003 08:36:57 -0000 1.3 +++ buffer_funcs.h 17 Jul 2003 08:01:20 -0000 @@ -32,9 +32,9 @@ Buffer * newFile(string const & filename ///return the format of the buffer on a string string const BufferFormat(Buffer const & buffer); - +/// void bufferErrors(Buffer const &, TeXErrors const &); - +/// void bufferErrors(Buffer const &, ErrorList const &); #endif // BUFFER_FUNCS_H Index: bufferparams.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/bufferparams.C,v retrieving revision 1.56 diff -u -p -u -r1.56 bufferparams.C --- bufferparams.C 30 Jun 2003 23:55:51 -0000 1.56 +++ bufferparams.C 17 Jul 2003 08:01:22 -0000 @@ -959,3 +959,62 @@ void BufferParams::readGraphicsDriver(Ly } } } + + + + +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; +} Index: bufferparams.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/bufferparams.h,v retrieving revision 1.33 diff -u -p -u -r1.33 bufferparams.h --- bufferparams.h 10 Jun 2003 14:39:42 -0000 1.33 +++ bufferparams.h 17 Jul 2003 08:01:22 -0000 @@ -238,6 +238,10 @@ public: /// map of the file's author IDs to buffer author IDs std::vector<int> author_map; + /// + string const dvips_options() const; + /// + string const paperSizeName() const; private: /// the author list Index: converter.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/converter.C,v retrieving revision 1.80 diff -u -p -u -r1.80 converter.C --- converter.C 7 Jul 2003 08:36:57 -0000 1.80 +++ converter.C 17 Jul 2003 08:01:23 -0000 @@ -15,6 +15,7 @@ #include "format.h" #include "lyxrc.h" #include "buffer.h" +#include "bufferparams.h" #include "buffer_funcs.h" #include "bufferview_funcs.h" #include "errorlist.h" @@ -62,6 +63,23 @@ string const add_options(string const & return head + ' ' + options + ' ' + tail; } + +string const dvipdfm_options(BufferParams const & bp) +{ + string result; + + if (bp.papersize2 != BufferParams::VM_PAPER_CUSTOM) { + string const paper_size = bp.paperSizeName(); + if (paper_size != "b5" && paper_size != "foolscap") + result = "-p "+ paper_size; + + if (bp.orientation == BufferParams::ORIENTATION_LANDSCAPE) + result += " -l"; + } + + return result; +} + } // namespace anon @@ -115,7 +133,6 @@ bool operator<(Converter const & a, Conv } - class compare_Converter { public: compare_Converter(string const & f, string const & t) @@ -327,10 +344,10 @@ bool Converters::convert(Buffer const * if (conv.from == "dvi" && conv.to == "ps") command = add_options(command, - dvips_options(buffer)); + buffer->params.dvips_options()); else if (conv.from == "dvi" && prefixIs(conv.to, "pdf")) command = add_options(command, - dvipdfm_options(buffer)); + dvipdfm_options(buffer->params)); lyxerr[Debug::FILES] << "Calling " << command << endl; if (buffer) @@ -544,56 +561,6 @@ bool Converters::runLaTeX(Buffer const * } - -string const Converters::dvips_options(Buffer const * buffer) -{ - string result; - if (!buffer) - return result; - - if (buffer->params.use_geometry - && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM - && !lyxrc.print_paper_dimension_flag.empty() - && !buffer->params.paperwidth.empty() - && !buffer->params.paperheight.empty()) { - // using a custom papersize - result = lyxrc.print_paper_dimension_flag; - result += ' ' + buffer->params.paperwidth; - result += ',' + buffer->params.paperheight; - } else { - string const 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 - // cases, include the paper size explicitly. - result = lyxrc.print_paper_flag; - result += ' ' + paper_option; - } - } - 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 const 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; -} void Converters::buildGraph() Index: converter.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/converter.h,v retrieving revision 1.26 diff -u -p -u -r1.26 converter.h --- converter.h 22 May 2003 18:58:55 -0000 1.26 +++ converter.h 17 Jul 2003 08:01:23 -0000 @@ -108,10 +108,6 @@ public: string const & from_file, string const & to_file_base, string const & from_format, string const & to_format); /// - string const dvips_options(Buffer const * buffer); - /// - string const dvipdfm_options(Buffer const * buffer); - /// void update(Formats const & formats); /// void updateLast(Formats const & formats); Index: format.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/format.C,v retrieving revision 1.10 diff -u -p -u -r1.10 format.C --- format.C 7 Jul 2003 08:36:58 -0000 1.10 +++ format.C 17 Jul 2003 08:01:23 -0000 @@ -12,6 +12,7 @@ #include "format.h" #include "buffer.h" +#include "buffer_funcs.h" #include "lyxrc.h" #include "debug.h" #include "gettext.h" @@ -173,7 +174,7 @@ bool Formats::view(Buffer const * buffer if (format_name == "dvi" && !lyxrc.view_dvi_paper_option.empty()) { command += ' ' + lyxrc.view_dvi_paper_option; - string paper_size = papersize(buffer); + string paper_size = buffer->params.paperSizeName(); if (paper_size == "letter") paper_size = "us"; command += ' ' + paper_size; @@ -226,30 +227,6 @@ string const Formats::extension(string c } -string const papersize(Buffer const * buffer) -{ - char real_papersize = buffer->params.papersize; - if (real_papersize == BufferParams::PAPER_DEFAULT) - real_papersize = lyxrc.default_papersize; - - switch (real_papersize) { - case BufferParams::PAPER_A3PAPER: - return "a3"; - case BufferParams::PAPER_A4PAPER: - return "a4"; - case BufferParams::PAPER_A5PAPER: - return "a5"; - case BufferParams::PAPER_B5PAPER: - return "b5"; - case BufferParams::PAPER_EXECUTIVEPAPER: - return "foolscap"; - case BufferParams::PAPER_LEGALPAPER: - return "legal"; - case BufferParams::PAPER_USLETTER: - default: - return "letter"; - } -} Formats formats; Index: format.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/format.h,v retrieving revision 1.2 diff -u -p -u -r1.2 format.h --- format.h 23 May 2003 13:54:07 -0000 1.2 +++ format.h 17 Jul 2003 08:01:23 -0000 @@ -23,8 +23,6 @@ class Buffer; -string const papersize(Buffer const * buffer) ; - class Format { public: /// Index: frontends/controllers/ControlPrint.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/controllers/ControlPrint.C,v retrieving revision 1.35 diff -u -p -u -r1.35 ControlPrint.C --- frontends/controllers/ControlPrint.C 30 Jun 2003 23:56:10 -0000 1.35 +++ frontends/controllers/ControlPrint.C 17 Jul 2003 08:01:24 -0000 @@ -16,11 +16,11 @@ #include "ButtonController.h" #include "buffer.h" +#include "bufferparams.h" #include "gettext.h" #include "helper_funcs.h" #include "PrinterParams.h" #include "exporter.h" -#include "converter.h" #include "frontends/Alert.h" @@ -154,7 +154,7 @@ void ControlPrint::apply() command += lyxrc.print_extra_options + ' '; } - command += converters.dvips_options(buffer()) + ' '; + command += buffer()->params.dvips_options() + ' '; if (!Exporter::Export(buffer(), "dvi", true)) { showPrintError(buffer()->fileName());