2003-08-04 10:26:10 +00:00
|
|
|
// -*- C++ -*-
|
2003-08-19 10:04:35 +00:00
|
|
|
/**
|
2007-04-26 04:53:06 +00:00
|
|
|
* \file Context.h
|
2003-08-19 10:04:35 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-08-19 10:04:35 +00:00
|
|
|
*/
|
|
|
|
|
2003-08-04 10:26:10 +00:00
|
|
|
#ifndef CONTEXT_H
|
|
|
|
#define CONTEXT_H
|
|
|
|
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
#include "tex2lyx.h"
|
2003-08-04 10:26:10 +00:00
|
|
|
|
2005-07-13 11:38:55 +00:00
|
|
|
#include <iosfwd>
|
|
|
|
|
2004-06-28 06:53:12 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
2004-06-28 06:53:12 +00:00
|
|
|
/*!
|
|
|
|
* Small helper struct that holds font properties.
|
|
|
|
* The names are in LyX language, not LaTeX.
|
2007-04-29 18:17:15 +00:00
|
|
|
* We don't use Font, because it pulls in a lot of dependencies and has
|
2004-06-28 06:53:12 +00:00
|
|
|
* more strings than needed (e.g. font family error1 etc.).
|
|
|
|
* If more font related stuff is needed, it might be good to change to
|
2007-04-29 18:17:15 +00:00
|
|
|
* Font.
|
2004-06-28 06:53:12 +00:00
|
|
|
*/
|
2007-04-29 18:17:15 +00:00
|
|
|
class TeXFont {
|
2005-02-25 22:13:13 +00:00
|
|
|
public:
|
2007-04-29 18:17:15 +00:00
|
|
|
TeXFont()
|
2004-06-28 06:53:12 +00:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
void init()
|
|
|
|
{
|
2007-12-05 20:02:49 +00:00
|
|
|
size = "default";
|
2004-06-28 06:53:12 +00:00
|
|
|
family = "default";
|
|
|
|
series = "default";
|
|
|
|
shape = "default";
|
|
|
|
}
|
|
|
|
std::string size;
|
|
|
|
std::string family;
|
|
|
|
std::string series;
|
|
|
|
std::string shape;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
bool operator==(TeXFont const &, TeXFont const &);
|
2005-07-26 11:58:43 +00:00
|
|
|
|
|
|
|
|
2007-04-29 18:17:15 +00:00
|
|
|
inline bool operator!=(TeXFont const & f1, TeXFont const & f2)
|
2005-07-26 11:58:43 +00:00
|
|
|
{
|
|
|
|
return !operator==(f1, f2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-13 11:38:55 +00:00
|
|
|
/// Output changed font parameters if \p oldfont and \p newfont differ
|
2007-04-29 18:17:15 +00:00
|
|
|
void output_font_change(std::ostream & os, TeXFont const & oldfont,
|
|
|
|
TeXFont const & newfont);
|
2005-07-13 11:38:55 +00:00
|
|
|
|
|
|
|
|
2005-07-26 11:58:43 +00:00
|
|
|
/*!
|
|
|
|
* 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.
|
|
|
|
*/
|
2005-02-25 22:13:13 +00:00
|
|
|
class Context {
|
|
|
|
public:
|
2003-08-04 10:26:10 +00:00
|
|
|
Context(bool need_layout_,
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
TeX2LyXDocClass const & textclass_,
|
2007-08-23 19:59:07 +00:00
|
|
|
LayoutPtr layout_ = LayoutPtr(),
|
|
|
|
LayoutPtr parent_layout_= LayoutPtr(),
|
2007-04-29 18:17:15 +00:00
|
|
|
TeXFont font_ = TeXFont());
|
2005-07-26 11:58:43 +00:00
|
|
|
~Context();
|
2003-08-04 10:26:10 +00:00
|
|
|
|
2005-07-13 11:38:55 +00:00
|
|
|
/// Output a \\begin_layout if requested
|
2003-08-04 10:26:10 +00:00
|
|
|
void check_layout(std::ostream & os);
|
|
|
|
|
2005-07-13 11:38:55 +00:00
|
|
|
/// Output a \\end_layout if needed
|
2003-08-04 10:26:10 +00:00
|
|
|
void check_end_layout(std::ostream & os);
|
|
|
|
|
2005-07-13 11:38:55 +00:00
|
|
|
/// Output a \\begin_deeper if needed
|
2003-08-05 21:55:41 +00:00
|
|
|
void check_deeper(std::ostream & os);
|
2003-08-05 21:46:51 +00:00
|
|
|
|
2005-07-13 11:38:55 +00:00
|
|
|
/// Output a \\end_deeper if needed
|
2003-08-05 21:55:41 +00:00
|
|
|
void check_end_deeper(std::ostream & os);
|
2003-09-09 18:27:24 +00:00
|
|
|
|
2005-07-13 11:38:55 +00:00
|
|
|
/// dump content on stream (for debugging purpose), with
|
|
|
|
/// description \c desc.
|
2003-08-04 10:26:10 +00:00
|
|
|
void dump(std::ostream &, std::string const & desc = "context") const;
|
|
|
|
|
2003-11-05 10:14:13 +00:00
|
|
|
/// Are we just beginning a new paragraph?
|
|
|
|
bool atParagraphStart() const { return need_layout; }
|
|
|
|
|
|
|
|
/// Begin an item in a list environment
|
|
|
|
void set_item();
|
|
|
|
|
|
|
|
/// Start a new paragraph
|
|
|
|
void new_paragraph(std::ostream & os);
|
|
|
|
|
2003-12-19 10:40:07 +00:00
|
|
|
/// Add extra stuff if not already there
|
|
|
|
void add_extra_stuff(std::string const &);
|
|
|
|
|
2005-07-13 11:38:55 +00:00
|
|
|
/// Do we need to output some \\begin_layout command before the
|
|
|
|
/// next characters?
|
2003-08-04 10:26:10 +00:00
|
|
|
bool need_layout;
|
2005-07-13 11:38:55 +00:00
|
|
|
/// Do we need to output some \\end_layout command
|
2003-08-04 10:26:10 +00:00
|
|
|
bool need_end_layout;
|
2005-07-13 11:38:55 +00:00
|
|
|
/// We may need to add something after this \\begin_layout command
|
2003-08-04 10:26:10 +00:00
|
|
|
std::string extra_stuff;
|
2005-07-13 11:38:55 +00:00
|
|
|
/// If there has been an \\begin_deeper, we'll need a matching
|
|
|
|
/// \\end_deeper
|
2003-08-04 10:26:10 +00:00
|
|
|
bool need_end_deeper;
|
2005-07-26 11:58:43 +00:00
|
|
|
/// If we are in an itemize-like environment, we need an \item
|
2005-07-13 11:38:55 +00:00
|
|
|
/// for each paragraph, otherwise this has to be a deeper
|
|
|
|
/// paragraph.
|
2003-08-06 22:47:22 +00:00
|
|
|
bool has_item;
|
2005-07-13 11:38:55 +00:00
|
|
|
/// we are handling a standard paragraph in an itemize-like
|
|
|
|
/// environment
|
2003-08-06 22:47:22 +00:00
|
|
|
bool deeper_paragraph;
|
2005-07-26 11:58:43 +00:00
|
|
|
/*!
|
|
|
|
* 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;
|
2006-07-16 13:04:59 +00:00
|
|
|
/// Did we output anything yet in any context?
|
|
|
|
static bool empty;
|
2003-09-09 18:27:24 +00:00
|
|
|
|
2005-07-13 11:38:55 +00:00
|
|
|
/// The textclass of the document. Could actually be a global variable
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
TeX2LyXDocClass const & textclass;
|
2005-07-13 11:38:55 +00:00
|
|
|
/// The layout of the current paragraph
|
2007-08-23 19:59:07 +00:00
|
|
|
LayoutPtr layout;
|
2005-07-13 11:38:55 +00:00
|
|
|
/// The layout of the outer paragraph (for environment layouts)
|
2007-08-23 19:59:07 +00:00
|
|
|
LayoutPtr parent_layout;
|
2004-06-28 06:53:12 +00:00
|
|
|
/// font attributes of this context
|
2007-04-29 18:17:15 +00:00
|
|
|
TeXFont font;
|
2005-07-13 11:38:55 +00:00
|
|
|
/// font attributes of normal text
|
2007-04-29 18:17:15 +00:00
|
|
|
static TeXFont normalfont;
|
2003-08-04 10:26:10 +00:00
|
|
|
};
|
2003-09-09 18:27:24 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2003-08-04 10:26:10 +00:00
|
|
|
#endif
|