]> git.lyx.org Git - features.git/commitdiff
Bug 5562: Fix command line output of subfigure insets by introducing new OutputParams...
authorJürgen Spitzmüller <spitz@lyx.org>
Sat, 7 Feb 2009 12:27:24 +0000 (12:27 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Sat, 7 Feb 2009 12:27:24 +0000 (12:27 +0000)
Later, this can be replaces by a backpointer approach, as proposed at bugzilla (note that there are already similar cases such as InComment or InTableCell, so a backpointer approach would need to adapt the OutputParams methos anyway).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28382 a592a061-630c-0410-9148-cb99ea01b6c8

src/LaTeXFeatures.cpp
src/LaTeXFeatures.h
src/OutputParams.cpp
src/OutputParams.h
src/insets/InsetCaption.cpp
src/insets/InsetCaption.h
src/insets/InsetFloat.cpp
src/insets/InsetWrap.cpp

index 577df7473de5f0c87183a2faa17d84a494d84fda..606f2d862f43490dc532a1e083787f9cddb32aed 100644 (file)
@@ -266,7 +266,7 @@ LaTeXFeatures::Packages LaTeXFeatures::packages_;
 
 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
                             OutputParams const & r)
-       : buffer_(&b), params_(p), runparams_(r)
+       : buffer_(&b), params_(p), runparams_(r), in_float_(false)
 {}
 
 
index 635376c8a12359a87e47b940d5e61501eb11a217..a381e62ef79174f9c2aa97f85bcb98b962e27691 100644 (file)
@@ -103,6 +103,10 @@ public:
        BufferParams const & bufferParams() const;
        /// the return value is dependent upon both LyXRC and LaTeXFeatures.
        bool useBabel() const;
+       /// are we in a float?
+       bool inFloat() const { return in_float_; }
+       /// are we in a float?
+       void inFloat(bool const b) { in_float_ = b; }
        /// Runparams that will be used for exporting this file.
        OutputParams const & runparams() const { return runparams_; }
 
@@ -145,6 +149,8 @@ private:
         *  in validate().
         */
        OutputParams const & runparams_;
+       ///
+       bool in_float_;
 };
 
 
index 7966ad712d37eb382ef106acab74677cf76176b8..498c65148c7f46f75f0bf4013e8f6117de4a41f8 100644 (file)
@@ -23,7 +23,7 @@ OutputParams::OutputParams(Encoding const * enc)
          local_font(0), encoding(enc), free_spacing(false), use_babel(false),
          use_japanese(false), linelen(0), depth(0),
          exportdata(new ExportData),
-         inComment(false), inTableCell(NO),
+         inComment(false), inTableCell(NO), inFloat(NONFLOAT),
          inDeletedInset(0), changeOfDeletedInset(Change::UNCHANGED),
          par_begin(0), par_end(0), isLastPar(false),
          dryrun(false), verbatim(false)
index f0816d6e4eafc9dab5907458a5b31eecaa48d63a..00a1e11030e896b973a35a4ddc372b82a91f0fdd 100644 (file)
@@ -41,6 +41,12 @@ public:
                ALIGNED
        };
 
+       enum Float {
+               NONFLOAT,
+               MAINFLOAT,
+               SUBFLOAT
+       };
+
        OutputParams(Encoding const *);
        ~OutputParams();
 
@@ -136,6 +142,11 @@ public:
          */
        TableCell inTableCell;
 
+       /** Whether we are inside a float or subfloat.
+        *  Needed for subfloat detection on the command line.
+        */
+       Float inFloat;
+
        /** Whether we are inside an inset that is logically deleted.
         *  A value > 0 indicates a deleted inset.
          */
index ad3ef8462aee3fcc9f7e2489bf6843dc512b2c56..e66b728d4ecd4c2bd927fe96f0ec2eee4994db2e 100644 (file)
@@ -214,7 +214,7 @@ bool InsetCaption::getStatus(Cursor & cur, FuncRequest const & cmd,
 int InsetCaption::latex(odocstream & os,
                        OutputParams const & runparams_in) const
 {
-       if (in_subfloat_)
+       if (runparams_in.inFloat == OutputParams::SUBFLOAT)
                // caption is output as an optional argument
                return 0;
        // This is a bit too simplistic to take advantage of
@@ -288,7 +288,6 @@ void InsetCaption::updateLabels(ParIterator const & it)
        string const & type = cnts.current_float();
        // Memorize type for addToToc().
        type_ = type;
-       in_subfloat_ = cnts.isSubfloat();
        if (type.empty())
                full_label_ = master.B_("Senseless!!! ");
        else {
@@ -300,7 +299,7 @@ void InsetCaption::updateLabels(ParIterator const & it)
                else
                        name = master.B_(tclass.floats().getType(type).name());
                docstring counter = from_utf8(type);
-               if (in_subfloat_) {
+               if (cnts.isSubfloat()) {
                        counter = "sub-" + from_utf8(type);
                        name = bformat(_("Sub-%1$s"),
                                       master.B_(tclass.floats().getType(type).name()));
index 950edbac61c7061c4d2b1317d890f80a3a6dc790..e8582b61fb1e6121b3dbe728bd9c8156be1194ab 100644 (file)
@@ -86,8 +86,6 @@ private:
        ///
        std::string type_;
        ///
-       bool in_subfloat_;
-       ///
        docstring custom_label_;
 };
 
index f9c0a4d61189f5b188bee22c1e22867707f3fb88..0dfe34326bbaf41fde0267d214aa92cc3be60b2d 100644 (file)
@@ -194,7 +194,8 @@ bool InsetFloat::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 void InsetFloat::updateLabels(ParIterator const & it)
 {
-       Counters & cnts = buffer().masterBuffer()->params().documentClass().counters();
+       Counters & cnts =
+               buffer().masterBuffer()->params().documentClass().counters();
        string const saveflt = cnts.current_float();
        bool const savesubflt = cnts.isSubfloat();
 
@@ -268,11 +269,13 @@ void InsetFloat::validate(LaTeXFeatures & features) const
        if (params_.sideways)
                features.require("rotfloat");
 
-       if (params_.subfloat)
+       if (features.inFloat())
                features.require("subfig");
 
-       features.useFloat(params_.type, params_.subfloat);
+       features.useFloat(params_.type, features.inFloat());
+       features.inFloat(true);
        InsetCollapsable::validate(features);
+       features.inFloat(false);
 }
 
 
@@ -282,24 +285,27 @@ docstring InsetFloat::editMessage() const
 }
 
 
-int InsetFloat::latex(odocstream & os, OutputParams const & runparams) const
+int InsetFloat::latex(odocstream & os, OutputParams const & runparams_in) const
 {
-       if (params_.subfloat) {
-               if (runparams.moving_arg)
+       if (runparams_in.inFloat != OutputParams::NONFLOAT) {
+               if (runparams_in.moving_arg)
                        os << "\\protect";
                os << "\\subfloat";
        
-               OutputParams rp = runparams;
+               OutputParams rp = runparams_in;
                docstring const caption = getCaption(rp);
                if (!caption.empty()) {
                        os << caption;
                }
                os << '{';
-               int const i = InsetText::latex(os, runparams);
+               rp.inFloat = OutputParams::SUBFLOAT;
+               int const i = InsetText::latex(os, rp);
                os << "}";
        
                return i + 1;
        }
+       OutputParams runparams(runparams_in);
+       runparams.inFloat = OutputParams::MAINFLOAT;
 
        FloatList const & floats = buffer().params().documentClass().floats();
        string tmptype = params_.type;
index a8926ee92e7822205bd31bec33a095a5f3a9af07..566ba91d732b9426a8fc7d29775167c017dd9d52 100644 (file)
@@ -170,7 +170,9 @@ void InsetWrap::read(Lexer & lex)
 void InsetWrap::validate(LaTeXFeatures & features) const
 {
        features.require("wrapfig");
+       features.inFloat(true);
        InsetCollapsable::validate(features);
+       features.inFloat(false);
 }
 
 
@@ -180,8 +182,10 @@ docstring InsetWrap::editMessage() const
 }
 
 
-int InsetWrap::latex(odocstream & os, OutputParams const & runparams) const
+int InsetWrap::latex(odocstream & os, OutputParams const & runparams_in) const
 {
+       OutputParams runparams(runparams_in);
+       runparams.inFloat = OutputParams::MAINFLOAT;
        os << "\\begin{wrap" << from_ascii(params_.type) << '}';
        // no optional argument when lines are zero
        if (params_.lines != 0)