2003-08-04 10:26:10 +00:00
|
|
|
// -*- C++ -*-
|
2003-08-19 10:04:35 +00:00
|
|
|
/**
|
|
|
|
* \file context.h
|
|
|
|
* 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
|
|
|
|
|
|
|
|
#include "lyxtextclass.h"
|
|
|
|
|
2005-07-13 11:38:55 +00:00
|
|
|
#include <iosfwd>
|
|
|
|
|
2004-06-28 06:53:12 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Small helper struct that holds font properties.
|
|
|
|
* The names are in LyX language, not LaTeX.
|
|
|
|
* We don't use LyXFont, because it pulls in a lot of dependencies and has
|
|
|
|
* more strings than needed (e.g. font family error1 etc.).
|
|
|
|
* If more font related stuff is needed, it might be good to change to
|
|
|
|
* LyXFont.
|
|
|
|
*/
|
2005-02-25 22:13:13 +00:00
|
|
|
class Font {
|
|
|
|
public:
|
2004-06-28 06:53:12 +00:00
|
|
|
Font()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
void init()
|
|
|
|
{
|
|
|
|
size = "normal";
|
|
|
|
family = "default";
|
|
|
|
series = "default";
|
|
|
|
shape = "default";
|
|
|
|
}
|
|
|
|
std::string size;
|
|
|
|
std::string family;
|
|
|
|
std::string series;
|
|
|
|
std::string shape;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-07-26 11:58:43 +00:00
|
|
|
bool operator==(Font const &, Font const &);
|
|
|
|
|
|
|
|
|
|
|
|
inline bool operator!=(Font const & f1, Font const & f2)
|
|
|
|
{
|
|
|
|
return !operator==(f1, f2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-13 11:38:55 +00:00
|
|
|
/// Output changed font parameters if \p oldfont and \p newfont differ
|
|
|
|
void output_font_change(std::ostream & os, Font const & oldfont,
|
2006-04-05 23:56:29 +00:00
|
|
|
Font 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_,
|
|
|
|
LyXTextClass const & textclass_,
|
|
|
|
LyXLayout_ptr layout_ = LyXLayout_ptr(),
|
2004-06-28 06:53:12 +00:00
|
|
|
LyXLayout_ptr parent_layout_= LyXLayout_ptr(),
|
2006-04-05 23:56:29 +00:00
|
|
|
Font font_ = Font());
|
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
|
2003-08-04 10:26:10 +00:00
|
|
|
LyXTextClass const & textclass;
|
2005-07-13 11:38:55 +00:00
|
|
|
/// The layout of the current paragraph
|
2003-08-04 10:26:10 +00:00
|
|
|
LyXLayout_ptr layout;
|
2005-07-13 11:38:55 +00:00
|
|
|
/// The layout of the outer paragraph (for environment layouts)
|
2003-08-04 10:26:10 +00:00
|
|
|
LyXLayout_ptr parent_layout;
|
2004-06-28 06:53:12 +00:00
|
|
|
/// font attributes of this context
|
|
|
|
Font font;
|
2005-07-13 11:38:55 +00:00
|
|
|
/// font attributes of normal text
|
|
|
|
static Font normalfont;
|
2003-08-04 10:26:10 +00:00
|
|
|
};
|
2003-09-09 18:27:24 +00:00
|
|
|
|
2003-08-04 10:26:10 +00:00
|
|
|
#endif
|