3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jean-Marc Lasgouttes
8 * Full author contact details are available in file CREDITS.
16 #include "support/lstrings.h"
21 using namespace lyx::support;
27 void end_layout(ostream & os)
29 os << "\n\\end_layout\n";
33 void begin_deeper(ostream & os)
35 os << "\n\\begin_deeper";
39 void end_deeper(ostream & os)
41 os << "\n\\end_deeper";
47 bool operator==(TeXFont const & f1, TeXFont const & f2)
51 f1.family == f2.family &&
52 f1.series == f2.series &&
57 void output_font_change(ostream & os, TeXFont const & oldfont,
58 TeXFont const & newfont)
60 if (oldfont.family != newfont.family)
61 os << "\n\\family " << newfont.family << '\n';
62 if (oldfont.series != newfont.series)
63 os << "\n\\series " << newfont.series << '\n';
64 if (oldfont.shape != newfont.shape)
65 os << "\n\\shape " << newfont.shape << '\n';
66 if (oldfont.size != newfont.size)
67 os << "\n\\size " << newfont.size << '\n';
71 TeXFont Context::normalfont;
72 bool Context::empty = true;
75 Context::Context(bool need_layout_,
76 TeX2LyXDocClass const & textclass_,
77 Layout const * layout_, Layout const * parent_layout_,
79 : need_layout(need_layout_),
80 need_end_layout(false), need_end_deeper(false),
81 has_item(false), deeper_paragraph(false),
82 new_layout_allowed(true), textclass(textclass_),
83 layout(layout_), parent_layout(parent_layout_),
87 layout = &textclass.defaultLayout();
89 parent_layout = &textclass.defaultLayout();
95 if (!par_extra_stuff.empty())
96 cerr << "Bug: Ignoring par-level extra stuff '"
97 << par_extra_stuff << '\'' << endl;
101 void Context::begin_layout(ostream & os, Layout const * const & l)
103 os << "\n\\begin_layout " << to_utf8(l->name()) << "\n";
104 if (!extra_stuff.empty()) {
107 if (!par_extra_stuff.empty()) {
108 os << par_extra_stuff;
109 par_extra_stuff.erase();
111 // FIXME: This is not enough for things like
112 // \\Huge par1 \\par par2
113 output_font_change(os, normalfont, font);
117 void Context::check_layout(ostream & os)
120 check_end_layout(os);
122 // are we in a list-like environment?
123 if (layout->isEnvironment()
124 && layout->latextype != LATEX_ENVIRONMENT) {
125 // A list-like environment
127 // a new item. If we had a standard
128 // paragraph before, we have to end it.
129 if (deeper_paragraph) {
131 deeper_paragraph = false;
133 begin_layout(os, layout);
136 // a standard paragraph in an
137 // enumeration. We have to recognize
138 // that this may require a begin_deeper.
139 if (!deeper_paragraph)
141 begin_layout(os, &textclass.defaultLayout());
142 deeper_paragraph = true;
145 // No list-like environment
146 begin_layout(os, layout);
149 need_end_layout = true;
156 void Context::check_end_layout(ostream & os)
158 if (need_end_layout) {
160 need_end_layout = false;
165 void Context::check_deeper(ostream & os)
167 if (parent_layout->isEnvironment()) {
168 // We start a nested environment.
169 // We need to increase the depth.
170 if (need_end_deeper) {
171 // no need to have \end_deeper \begin_deeper
172 need_end_deeper = false;
175 need_end_deeper = true;
178 check_end_deeper(os);
182 void Context::check_end_deeper(ostream & os)
184 if (need_end_deeper) {
186 need_end_deeper = false;
188 if (deeper_paragraph) {
190 deeper_paragraph = false;
195 void Context::set_item()
202 void Context::new_paragraph(ostream & os)
204 check_end_layout(os);
209 void Context::add_extra_stuff(string const & stuff)
211 if (!contains(extra_stuff, stuff))
212 extra_stuff += stuff;
216 void Context::add_par_extra_stuff(string const & stuff)
218 if (!contains(par_extra_stuff, stuff))
219 par_extra_stuff += stuff;
223 void Context::dump(ostream & os, string const & desc) const
225 os << "\n" << desc <<" [";
227 os << "need_layout ";
229 os << "need_end_layout ";
231 os << "need_end_deeper ";
234 if (deeper_paragraph)
235 os << "deeper_paragraph ";
236 if (new_layout_allowed)
237 os << "new_layout_allowed ";
238 if (!extra_stuff.empty())
239 os << "extrastuff=[" << extra_stuff << "] ";
240 if (!par_extra_stuff.empty())
241 os << "parextrastuff=[" << par_extra_stuff << "] ";
242 os << "textclass=" << textclass.name()
243 << " layout=" << to_utf8(layout->name())
244 << " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["
245 << font.size << ' ' << font.family << ' ' << font.series << ' '
246 << font.shape << ']' << endl;