From dfbd44997a2f52d0caf06d73348bc4da579ae5b3 Mon Sep 17 00:00:00 2001 From: Alfredo Braunstein Date: Thu, 17 Jul 2003 08:23:33 +0000 Subject: [PATCH] moved some converter/format functions to more appropriate places git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7300 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/ChangeLog | 6 ++ src/buffer_funcs.h | 4 +- src/bufferparams.C | 57 ++++++++++++++++++ src/bufferparams.h | 4 ++ src/converter.C | 73 +++++++----------------- src/converter.h | 4 -- src/format.C | 27 +-------- src/format.h | 2 - src/frontends/controllers/ControlPrint.C | 4 +- 9 files changed, 93 insertions(+), 88 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 16de892ce5..a0b2ae0559 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2003-07-17 Alfredo Braunstein + + * 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é Pönitz diff --git a/src/buffer_funcs.h b/src/buffer_funcs.h index 334b63f644..ccf37d01b0 100644 --- a/src/buffer_funcs.h +++ b/src/buffer_funcs.h @@ -32,9 +32,9 @@ Buffer * newFile(string const & filename, string const & templatename, ///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 diff --git a/src/bufferparams.C b/src/bufferparams.C index bf70b6a66d..7743aa2c69 100644 --- a/src/bufferparams.C +++ b/src/bufferparams.C @@ -959,3 +959,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; +} diff --git a/src/bufferparams.h b/src/bufferparams.h index 8aa0b4a671..23ba28c271 100644 --- a/src/bufferparams.h +++ b/src/bufferparams.h @@ -238,6 +238,10 @@ public: /// map of the file's author IDs to buffer author IDs std::vector author_map; + /// + string const dvips_options() const; + /// + string const paperSizeName() const; private: /// the author list diff --git a/src/converter.C b/src/converter.C index 0f28bba8cf..e585ed64e8 100644 --- a/src/converter.C +++ b/src/converter.C @@ -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 & command, string const & options) 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, Converter const & b) } - class compare_Converter { public: compare_Converter(string const & f, string const & t) @@ -327,10 +344,10 @@ bool Converters::convert(Buffer const * buffer, 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) @@ -545,56 +562,6 @@ bool Converters::runLaTeX(Buffer const * buffer, string const & command, } -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() { diff --git a/src/converter.h b/src/converter.h index e69a769ad0..b247d363a3 100644 --- a/src/converter.h +++ b/src/converter.h @@ -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); diff --git a/src/format.C b/src/format.C index 20caaf8d69..b8a0844bd1 100644 --- a/src/format.C +++ b/src/format.C @@ -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, string const & filename, 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 const & name) const } -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; diff --git a/src/format.h b/src/format.h index e5e62cf9c1..da7c0e3cc4 100644 --- a/src/format.h +++ b/src/format.h @@ -23,8 +23,6 @@ class Buffer; -string const papersize(Buffer const * buffer) ; - class Format { public: /// diff --git a/src/frontends/controllers/ControlPrint.C b/src/frontends/controllers/ControlPrint.C index 66642c6a87..d85c74f1d0 100644 --- a/src/frontends/controllers/ControlPrint.C +++ b/src/frontends/controllers/ControlPrint.C @@ -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()); -- 2.39.2