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_fwd.h"
23 #include "ParagraphParameters.h"
25 #include "support/gzstream.h"
26 #include "support/lstrings.h"
31 using lyx::support::ascii_lowercase;
32 using lyx::support::compare_ascii_no_case;
33 using lyx::support::compare_no_case;
34 using lyx::support::contains;
44 void writeFileAscii(Buffer const & buf,
46 OutputParams const & runparams)
49 if (!::openFileWrite(ofs, fname))
51 writeFileAscii(buf, ofs, runparams);
55 void writeFileAscii(Buffer const & buf, ostream & os,
56 OutputParams const & runparams)
58 ParagraphList const par = buf.paragraphs();
59 ParagraphList::const_iterator beg = par.begin();
60 ParagraphList::const_iterator end = par.end();
61 ParagraphList::const_iterator it = beg;
62 for (; it != end; ++it) {
63 asciiParagraph(buf, *it, os, runparams, it == beg);
71 pair<int, string> const addDepth(int depth, int ldepth)
75 d += (ldepth - depth) * 2;
76 return make_pair(d, string(d, ' '));
82 void asciiParagraph(Buffer const & buf,
83 Paragraph const & par,
85 OutputParams const & runparams,
89 Paragraph::depth_type ltype_depth = 0;
90 bool ref_printed = false;
91 Paragraph::depth_type depth = par.params().depth();
93 // First write the layout
94 string const & tmp = par.layout()->name();
95 if (compare_no_case(tmp, "itemize") == 0) {
97 ltype_depth = depth + 1;
98 } else if (compare_ascii_no_case(tmp, "enumerate") == 0) {
100 ltype_depth = depth + 1;
101 } else if (contains(ascii_lowercase(tmp), "ection")) {
103 ltype_depth = depth + 1;
104 } else if (contains(ascii_lowercase(tmp), "aragraph")) {
106 ltype_depth = depth + 1;
107 } else if (compare_ascii_no_case(tmp, "description") == 0) {
109 ltype_depth = depth + 1;
110 } else if (compare_ascii_no_case(tmp, "abstract") == 0) {
113 } else if (compare_ascii_no_case(tmp, "bibliography") == 0) {
121 /* maybe some vertical spaces */
123 /* the labelwidthstring used in lists */
127 /* some pagebreaks? */
131 /* what about the alignment */
133 // runparams.linelen <= 0 is special and means we don't have paragraph breaks
135 string::size_type currlinelen = 0;
138 if (runparams.linelen > 0)
141 os << string(depth * 2, ' ');
142 currlinelen += depth * 2;
145 // we should probably change to the paragraph language in the
146 // gettext here (if possible) so that strings are output in
147 // the correct language! (20012712 Jug)
151 case 4: // (Sub)Paragraph
152 case 5: // Description
156 if (runparams.linelen > 0) {
157 os << _("Abstract") << "\n\n";
160 string const abst = _("Abstract: ");
162 currlinelen += abst.length();
166 case 7: // Bibliography
168 if (runparams.linelen > 0) {
169 os << _("References") << "\n\n";
172 string const refs = _("References: ");
174 currlinelen += refs.length();
181 string const label = par.params().labelString();
183 currlinelen += label.length() + 1;
191 pair<int, string> p = addDepth(depth, ltype_depth);
193 currlinelen += p.first;
196 // this is to change the linebreak to do it by word a bit more
197 // intelligent hopefully! (only in the case where we have a
198 // max runparams.linelength!) (Jug)
202 for (pos_type i = 0; i < par.size(); ++i) {
203 char c = par.getUChar(buf.params(), i);
205 case Paragraph::META_INSET: {
206 InsetBase const * inset = par.getInset(i);
207 if (runparams.linelen > 0) {
209 currlinelen += word.length();
212 if (inset->plaintext(buf, os, runparams)) {
213 // to be sure it breaks paragraph
214 currlinelen += runparams.linelen;
220 if (runparams.linelen > 0 &&
221 currlinelen + word.length() > runparams.linelen - 10) {
223 pair<int, string> p = addDepth(depth, ltype_depth);
225 currlinelen = p.first;
228 currlinelen += word.length() + 1;
233 lyxerr[Debug::INFO] <<
234 "writeAsciiFile: NULL char in structure." << endl;
239 if (runparams.linelen > 0 &&
240 currlinelen + word.length() > runparams.linelen)
243 pair<int, string> p = addDepth(depth, ltype_depth);
245 currlinelen = p.first;