]> git.lyx.org Git - features.git/commitdiff
Fix bug 4806
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 7 May 2008 13:55:03 +0000 (13:55 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 7 May 2008 13:55:03 +0000 (13:55 +0000)
* Context.cpp (begin_layout): make it a (private) method, and output
the extra stuff here.
(add_par_extra_stuff): this is used for stuff that is only for next
paragraph (like extra_stuff used to be); add_extra_stuff is now for
code that is output for all paragraphs in the context.

* text.cpp: update to new Context methods. Every user of add_extra_stuff
uses add_par_extra_stuff, except alignment (which has to be repeated
to fix bug 4806).

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

src/tex2lyx/Context.cpp
src/tex2lyx/Context.h
src/tex2lyx/text.cpp

index 1e05984bcfb7a4371ce1b8ee8517e0a35e23dea7..33050489a09f003deacaecb2a09b2bcf6da62eb7 100644 (file)
@@ -24,16 +24,6 @@ namespace lyx {
 
 namespace {
 
-void begin_layout(ostream & os, Layout const * const & layout, TeXFont const & font,
-                 TeXFont const & normalfont)
-{
-       os << "\n\\begin_layout " << to_utf8(layout->name()) << "\n";
-       // FIXME: This is not enough for things like
-       // \\Huge par1 \\par par2
-       output_font_change(os, normalfont, font);
-}
-
-
 void end_layout(ostream & os)
 {
        os << "\n\\end_layout\n";
@@ -102,9 +92,25 @@ Context::Context(bool need_layout_,
 
 Context::~Context()
 {
-       if (!extra_stuff.empty())
-               cerr << "Bug: Ignoring extra stuff '" << extra_stuff
-                         << '\'' << endl;
+       if (!par_extra_stuff.empty())
+               cerr << "Bug: Ignoring par-level extra stuff '" 
+                    << par_extra_stuff << '\'' << endl;
+}
+
+
+void Context::begin_layout(ostream & os, Layout const * const & l)
+{
+       os << "\n\\begin_layout " << to_utf8(l->name()) << "\n";
+       if (!extra_stuff.empty()) {
+               os << extra_stuff;
+       }
+       if (!par_extra_stuff.empty()) {
+               os << par_extra_stuff;
+               par_extra_stuff.erase();
+       }
+       // FIXME: This is not enough for things like
+       // \\Huge par1 \\par par2
+       output_font_change(os, normalfont, font);
 }
 
 
@@ -124,7 +130,7 @@ void Context::check_layout(ostream & os)
                                        end_deeper(os);
                                        deeper_paragraph = false;
                                }
-                               begin_layout(os, layout, font, normalfont);
+                               begin_layout(os, layout);
                                has_item = false;
                        } else {
                                // a standard paragraph in an
@@ -132,20 +138,15 @@ void Context::check_layout(ostream & os)
                                // that this may require a begin_deeper.
                                if (!deeper_paragraph)
                                        begin_deeper(os);
-                               begin_layout(os, &textclass.defaultLayout(),
-                                            font, normalfont);
+                               begin_layout(os, &textclass.defaultLayout());
                                deeper_paragraph = true;
                        }
                } else {
                        // No list-like environment
-                       begin_layout(os, layout, font, normalfont);
+                       begin_layout(os, layout);
                }
                need_layout = false;
                need_end_layout = true;
-               if (!extra_stuff.empty()) {
-                       os << extra_stuff;
-                       extra_stuff.erase();
-               }
                os << "\n";
                empty = false;
        }
@@ -212,6 +213,13 @@ void Context::add_extra_stuff(string const & stuff)
 }
 
 
+void Context::add_par_extra_stuff(string const & stuff)
+{
+       if (!contains(par_extra_stuff, stuff))
+               par_extra_stuff += stuff;
+}
+
+
 void Context::dump(ostream & os, string const & desc) const
 {
        os << "\n" << desc <<" [";
@@ -229,6 +237,8 @@ void Context::dump(ostream & os, string const & desc) const
                os << "new_layout_allowed ";
        if (!extra_stuff.empty())
                os << "extrastuff=[" << extra_stuff << "] ";
+       if (!par_extra_stuff.empty())
+               os << "parextrastuff=[" << par_extra_stuff << "] ";
        os << "textclass=" << textclass.name()
           << " layout=" << to_utf8(layout->name())
           << " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["
index 4e0c75695c677cebe28ee8d82992e7c055eb04c8..c5c45b06fb67e172c867c2098a472c18e6dd95ec 100644 (file)
@@ -111,13 +111,21 @@ public:
        /// Add extra stuff if not already there
        void add_extra_stuff(std::string const &);
 
+       /*! 
+        *  Add paragraph-level extra stuff if not already there. This
+        *  will be reset at the next check_layout()
+        */
+       void add_par_extra_stuff(std::string const &);
+
        /// Do we need to output some \\begin_layout command before the
        /// next characters?
        bool need_layout;
        /// Do we need to output some \\end_layout command
        bool need_end_layout;
-       /// We may need to add something after this \\begin_layout command
+       /// We may need to add something after each \\begin_layout command
        std::string extra_stuff;
+       /// We may need to add something after this \\begin_layout command
+       std::string par_extra_stuff;
        /// If there has been an \\begin_deeper, we'll need a matching
        /// \\end_deeper
        bool need_end_deeper;
@@ -149,6 +157,9 @@ public:
        TeXFont font;
        /// font attributes of normal text
        static TeXFont normalfont;
+
+private:
+       void begin_layout(std::ostream & os, Layout const * const & l);
 };
 
 
index 9314cdeb5f1aaccd26c94b7a855c79d7449fd55f..2e502f798675c6e424e495400ebf03b9bde38e91 100644 (file)
@@ -56,8 +56,8 @@ void parse_text_snippet(Parser & p, ostream & os, unsigned flags, bool outer,
                Context & context)
 {
        Context newcontext(context);
-       // Don't inherit the extra stuff
-       newcontext.extra_stuff.clear();
+       // Don't inherit the paragraph-level extra stuff
+       newcontext.par_extra_stuff.clear();
        parse_text(p, os, flags, outer, newcontext);
        // Make sure that we don't create invalid .lyx files
        context.need_layout = newcontext.need_layout;
@@ -82,7 +82,7 @@ string parse_text_snippet(Parser & p, unsigned flags, const bool outer,
        newcontext.need_end_layout = false;
        newcontext.new_layout_allowed = false;
        // Avoid warning by Context::~Context()
-       newcontext.extra_stuff.clear();
+       newcontext.par_extra_stuff.clear();
        ostringstream os;
        parse_text_snippet(p, os, flags, outer, newcontext);
        return os.str();
@@ -845,8 +845,8 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                parent_context.check_end_layout(os);
                switch (context.layout->latextype) {
                case  LATEX_LIST_ENVIRONMENT:
-                       context.extra_stuff = "\\labelwidthstring "
-                               + p.verbatim_item() + '\n';
+                       context.add_par_extra_stuff("\\labelwidthstring "
+                                                   + p.verbatim_item() + '\n');
                        p.skip_spaces();
                        break;
                case  LATEX_BIB_ENVIRONMENT:
@@ -1506,11 +1506,11 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (t.cs() == "noindent") {
                        p.skip_spaces();
-                       context.add_extra_stuff("\\noindent\n");
+                       context.add_par_extra_stuff("\\noindent\n");
                }
 
                else if (t.cs() == "appendix") {
-                       context.add_extra_stuff("\\start_of_appendix\n");
+                       context.add_par_extra_stuff("\\start_of_appendix\n");
                        // We need to start a new paragraph. Otherwise the
                        // appendix in 'bla\appendix\chapter{' would start
                        // too late.