]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/context.h
Fix bug 2667
[lyx.git] / src / tex2lyx / context.h
index a4fd4a916a54d8e3070f0475f66279011b22d89c..e60ae785a785feb9ad4f3b2f258dba9b2ba06fc1 100644 (file)
@@ -14,6 +14,8 @@
 
 #include "lyxtextclass.h"
 
+#include <iosfwd>
+
 
 /*!
  * Small helper struct that holds font properties.
@@ -23,7 +25,8 @@
  * If more font related stuff is needed, it might be good to change to
  * LyXFont.
  */
-struct Font {
+class Font {
+public:
        Font()
        {
                init();
@@ -42,28 +45,55 @@ struct Font {
 };
 
 
-// A helper struct
-struct Context {
+bool operator==(Font const &, Font const &);
+
+
+inline bool operator!=(Font const & f1, Font const & f2)
+{
+       return !operator==(f1, f2);
+}
+
+
+/// Output changed font parameters if \p oldfont and \p newfont differ
+void output_font_change(std::ostream & os, Font const & oldfont,
+                       Font const & newfont);
+
+
+/*!
+ * A helper struct.
+ *
+ * Every bit of text has a corresponding context.
+ * Usage: Parsing begins with a global context. A new context is opened for
+ * every new LaTeX group, e.g. at the beginning of a new environment.
+ * The old context is used again after the group is closed.
+ *
+ * Since not all paragraph parameters in LyX have the same scoping as their
+ * LaTeX counterpart we may have to transfer context properties (e. g. the
+ * font) from and to the parent context.
+ */
+class Context {
+public:
        Context(bool need_layout_,
                LyXTextClass const & textclass_,
                LyXLayout_ptr layout_ = LyXLayout_ptr(),
                LyXLayout_ptr parent_layout_= LyXLayout_ptr(),
-               Font font_ = Font());
+               Font font_ = Font());
+       ~Context();
 
-       // Output a \begin_layout is requested
+       /// Output a \\begin_layout if requested
        void check_layout(std::ostream & os);
 
-       // Output a \end_layout if needed
+       /// Output a \\end_layout if needed
        void check_end_layout(std::ostream & os);
 
-       // Output a \begin_deeper if needed
+       /// Output a \\begin_deeper if needed
        void check_deeper(std::ostream & os);
 
-       // Output a \end_deeper if needed
+       /// Output a \\end_deeper if needed
        void check_end_deeper(std::ostream & os);
 
-       // dump content on stream (for debugging purpose), with
-       // description \c desc.
+       /// dump content on stream (for debugging purpose), with
+       /// description \c desc.
        void dump(std::ostream &, std::string const & desc = "context") const;
 
        /// Are we just beginning a new paragraph?
@@ -78,33 +108,44 @@ struct Context {
        /// Add extra stuff if not already there
        void add_extra_stuff(std::string const &);
 
-       // Do we need to output some \begin_layout command before the
-       // next characters?
+       /// 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
+       /// 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 this \\begin_layout command
        std::string extra_stuff;
-       // If there has been an \begin_deeper, we'll need a matching
-       // \end_deeper
+       /// If there has been an \\begin_deeper, we'll need a matching
+       /// \\end_deeper
        bool need_end_deeper;
-       // If we are in an itemize-like environment, we need an \item
-       // for each paragraph, otherwise this has to be a deeper
-       // paragraph.
+       /// If we are in an itemize-like environment, we need an \item
+       /// for each paragraph, otherwise this has to be a deeper
+       /// paragraph.
        bool has_item;
-       // we are handling a standard paragraph in an itemize-like
-       // environment
+       /// we are handling a standard paragraph in an itemize-like
+       /// environment
        bool deeper_paragraph;
-
-       // The textclass of the document. Could actually be a global variable
+       /*!
+        * Inside of unknown environments we may not allow font and layout
+        * changes.
+        * Otherwise things like
+        * \\large\\begin{foo}\\huge bar\\end{foo}
+        * would not work.
+        */
+       bool new_layout_allowed;
+       /// Did we output anything yet in any context?
+       static bool empty;
+
+       /// The textclass of the document. Could actually be a global variable
        LyXTextClass const & textclass;
-       // The layout of the current paragraph
+       /// The layout of the current paragraph
        LyXLayout_ptr layout;
-       // The layout of the outer paragraph (for environment layouts)
+       /// The layout of the outer paragraph (for environment layouts)
        LyXLayout_ptr parent_layout;
        /// font attributes of this context
        Font font;
+       /// font attributes of normal text
+       static Font normalfont;
 };
 
-
 #endif