2 * \file output_plaintext.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
13 #include "output_plaintext.h"
16 #include "bufferparams.h"
20 #include "outputparams.h"
21 #include "paragraph.h"
22 #include "ParagraphList.h"
23 #include "ParagraphParameters.h"
25 #include "support/lstrings.h"
30 using support::ascii_lowercase;
31 using support::compare_ascii_no_case;
32 using support::compare_no_case;
33 using support::contains;
42 void writeFileAscii(Buffer const & buf, string const & fname,
43 OutputParams const & runparams)
46 if (!openFileWrite(ofs, fname))
48 writeFileAscii(buf, ofs, runparams);
52 void writeFileAscii(Buffer const & buf, odocstream & os,
53 OutputParams const & runparams)
55 bool ref_printed = false;
56 ParagraphList const par = buf.paragraphs();
57 ParagraphList::const_iterator beg = par.begin();
58 ParagraphList::const_iterator end = par.end();
59 ParagraphList::const_iterator it = beg;
60 for (; it != end; ++it) {
61 asciiParagraph(buf, *it, os, runparams, ref_printed);
69 pair<int, docstring> const addDepth(int depth, int ldepth)
73 d += (ldepth - depth) * 2;
74 return make_pair(d, docstring(d, ' '));
80 void asciiParagraph(Buffer const & buf,
81 Paragraph const & par,
83 OutputParams const & runparams,
87 depth_type ltype_depth = 0;
88 depth_type depth = par.params().depth();
90 // First write the layout
91 string const & tmp = par.layout()->name();
92 if (compare_no_case(tmp, "itemize") == 0) {
94 ltype_depth = depth + 1;
95 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
97 ltype_depth = depth + 1;
98 } else if (contains(ascii_lowercase(tmp), "ection")) {
100 ltype_depth = depth + 1;
101 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
103 ltype_depth = depth + 1;
104 } else if (compare_ascii_no_case(tmp, "description") == 0) {
106 ltype_depth = depth + 1;
107 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
110 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
118 /* maybe some vertical spaces */
120 /* the labelwidthstring used in lists */
124 /* some pagebreaks? */
128 /* what about the alignment */
130 // runparams.linelen <= 0 is special and means we don't have paragraph breaks
132 string::size_type currlinelen = 0;
134 if (runparams.linelen > 0)
137 os << docstring(depth * 2, ' ');
138 currlinelen += depth * 2;
141 // we should probably change to the paragraph language in the
142 // gettext here (if possible) so that strings are output in
143 // the correct language! (20012712 Jug)
147 case 4: // (Sub)Paragraph
148 case 5: // Description
152 if (runparams.linelen > 0) {
153 os << _("Abstract") << "\n\n";
156 docstring const abst = _("Abstract: ");
158 currlinelen += abst.length();
162 case 7: // Bibliography
164 if (runparams.linelen > 0) {
165 os << _("References") << "\n\n";
168 docstring const refs = _("References: ");
170 currlinelen += refs.length();
177 docstring const label = par.params().labelString();
179 currlinelen += label.length() + 1;
186 pair<int, docstring> p = addDepth(depth, ltype_depth);
188 currlinelen += p.first;
191 // this is to change the linebreak to do it by word a bit more
192 // intelligent hopefully! (only in the case where we have a
193 // max runparams.linelength!) (Jug)
197 for (pos_type i = 0; i < par.size(); ++i) {
198 char_type c = par.getUChar(buf.params(), i);
200 case Paragraph::META_INSET: {
201 InsetBase const * inset = par.getInset(i);
202 if (runparams.linelen > 0) {
204 currlinelen += word.length();
207 OutputParams rp = runparams;
208 rp.depth = par.params().depth();
209 if (inset->plaintext(buf, os, rp)) {
210 // to be sure it breaks paragraph
211 currlinelen += runparams.linelen;
217 if (runparams.linelen > 0 &&
218 currlinelen + word.length() > runparams.linelen - 10) {
220 pair<int, docstring> p = addDepth(depth, ltype_depth);
222 currlinelen = p.first;
225 currlinelen += word.length() + 1;
230 lyxerr[Debug::INFO] <<
231 "writeAsciiFile: NULL char in structure." << endl;
236 if (runparams.linelen > 0 &&
237 currlinelen + word.length() > runparams.linelen)
240 pair<int, docstring> p = addDepth(depth, ltype_depth);
242 currlinelen = p.first;