From 1f58d53deb3ace7b9df0b3202bda3ef006249777 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Sat, 7 Feb 2009 12:27:24 +0000 Subject: [PATCH] Bug 5562: Fix command line output of subfigure insets by introducing new OutputParams and LaTeXFeatures members that tell the insets whether they are in a (sub)float. 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 | 2 +- src/LaTeXFeatures.h | 6 ++++++ src/OutputParams.cpp | 2 +- src/OutputParams.h | 11 +++++++++++ src/insets/InsetCaption.cpp | 5 ++--- src/insets/InsetCaption.h | 2 -- src/insets/InsetFloat.cpp | 22 ++++++++++++++-------- src/insets/InsetWrap.cpp | 6 +++++- 8 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 577df7473d..606f2d862f 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -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) {} diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index 635376c8a1..a381e62ef7 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -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_; }; diff --git a/src/OutputParams.cpp b/src/OutputParams.cpp index 7966ad712d..498c65148c 100644 --- a/src/OutputParams.cpp +++ b/src/OutputParams.cpp @@ -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) diff --git a/src/OutputParams.h b/src/OutputParams.h index f0816d6e4e..00a1e11030 100644 --- a/src/OutputParams.h +++ b/src/OutputParams.h @@ -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. */ diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index ad3ef8462a..e66b728d4e 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -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())); diff --git a/src/insets/InsetCaption.h b/src/insets/InsetCaption.h index 950edbac61..e8582b61fb 100644 --- a/src/insets/InsetCaption.h +++ b/src/insets/InsetCaption.h @@ -86,8 +86,6 @@ private: /// std::string type_; /// - bool in_subfloat_; - /// docstring custom_label_; }; diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index f9c0a4d611..0dfe34326b 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -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; diff --git a/src/insets/InsetWrap.cpp b/src/insets/InsetWrap.cpp index a8926ee92e..566ba91d73 100644 --- a/src/insets/InsetWrap.cpp +++ b/src/insets/InsetWrap.cpp @@ -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) -- 2.39.2