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 &&
53 f1.shape == f2.shape &&
54 f1.language == f2.language;
58 void output_font_change(ostream & os, TeXFont const & oldfont,
59 TeXFont const & newfont)
61 if (oldfont.family != newfont.family)
62 os << "\n\\family " << newfont.family << '\n';
63 if (oldfont.series != newfont.series)
64 os << "\n\\series " << newfont.series << '\n';
65 if (oldfont.shape != newfont.shape)
66 os << "\n\\shape " << newfont.shape << '\n';
67 if (oldfont.size != newfont.size)
68 os << "\n\\size " << newfont.size << '\n';
69 if (oldfont.language != newfont.language)
70 os << "\n\\lang " << newfont.language << '\n';
74 TeXFont Context::normalfont;
75 bool Context::empty = true;
78 Context::Context(bool need_layout_,
79 TeX2LyXDocClass const & textclass_,
80 Layout const * layout_, Layout const * parent_layout_,
82 : need_layout(need_layout_),
83 need_end_layout(false), need_end_deeper(false),
84 has_item(false), deeper_paragraph(false),
85 new_layout_allowed(true), textclass(textclass_),
86 layout(layout_), parent_layout(parent_layout_),
90 layout = &textclass.defaultLayout();
92 parent_layout = &textclass.defaultLayout();
98 if (!par_extra_stuff.empty())
99 cerr << "Bug: Ignoring par-level extra stuff '"
100 << par_extra_stuff << '\'' << endl;
104 void Context::begin_layout(ostream & os, Layout const * const & l)
106 os << "\n\\begin_layout " << to_utf8(l->name()) << "\n";
107 if (!extra_stuff.empty()) {
110 if (!par_extra_stuff.empty()) {
111 os << par_extra_stuff;
112 par_extra_stuff.erase();
114 // FIXME: This is not enough for things like
115 // \\Huge par1 \\par par2
116 // FIXME: If the document language is not english this outputs a
117 // superflous language change. Fortunately this is only file format
118 // bloat an does not change the TeX export of LyX.
119 output_font_change(os, normalfont, font);
123 void Context::check_layout(ostream & os)
126 check_end_layout(os);
128 // are we in a list-like environment?
129 if (layout->isEnvironment()
130 && layout->latextype != LATEX_ENVIRONMENT) {
131 // A list-like environment
133 // a new item. If we had a standard
134 // paragraph before, we have to end it.
135 if (deeper_paragraph) {
137 deeper_paragraph = false;
139 begin_layout(os, layout);
142 // a standard paragraph in an
143 // enumeration. We have to recognize
144 // that this may require a begin_deeper.
145 if (!deeper_paragraph)
147 begin_layout(os, &textclass.defaultLayout());
148 deeper_paragraph = true;
151 // No list-like environment
152 begin_layout(os, layout);
155 need_end_layout = true;
162 void Context::check_end_layout(ostream & os)
164 if (need_end_layout) {
166 need_end_layout = false;
171 void Context::check_deeper(ostream & os)
173 if (parent_layout->isEnvironment()) {
174 // We start a nested environment.
175 // We need to increase the depth.
176 if (need_end_deeper) {
177 // no need to have \end_deeper \begin_deeper
178 need_end_deeper = false;
181 need_end_deeper = true;
184 check_end_deeper(os);
188 void Context::check_end_deeper(ostream & os)
190 if (need_end_deeper) {
192 need_end_deeper = false;
194 if (deeper_paragraph) {
196 deeper_paragraph = false;
201 void Context::set_item()
208 void Context::new_paragraph(ostream & os)
210 check_end_layout(os);
215 void Context::add_extra_stuff(string const & stuff)
217 if (!contains(extra_stuff, stuff))
218 extra_stuff += stuff;
222 void Context::add_par_extra_stuff(string const & stuff)
224 if (!contains(par_extra_stuff, stuff))
225 par_extra_stuff += stuff;
229 void Context::dump(ostream & os, string const & desc) const
231 os << "\n" << desc <<" [";
233 os << "need_layout ";
235 os << "need_end_layout ";
237 os << "need_end_deeper ";
240 if (deeper_paragraph)
241 os << "deeper_paragraph ";
242 if (new_layout_allowed)
243 os << "new_layout_allowed ";
244 if (!extra_stuff.empty())
245 os << "extrastuff=[" << extra_stuff << "] ";
246 if (!par_extra_stuff.empty())
247 os << "parextrastuff=[" << par_extra_stuff << "] ";
248 os << "textclass=" << textclass.name()
249 << " layout=" << to_utf8(layout->name())
250 << " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["
251 << font.size << ' ' << font.family << ' ' << font.series << ' '
252 << font.shape << ']' << endl;