1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
20 #include "lyxparagraph.h"
21 #include "support/textutils.h"
24 #include "tex-strings.h"
25 #include "bufferparams.h"
26 #include "support/FileInfo.h"
27 #include "support/LAssert.h"
29 #include "LaTeXFeatures.h"
30 #include "insets/insetinclude.h"
31 #include "insets/insetbib.h"
32 #include "support/filetools.h"
33 #include "lyx_gui_misc.h"
35 #include "support/lyxmanip.h"
42 int tex_code_break_column = 72; // needs non-zero initialization. set later.
43 // this is a bad idea, but how can LyXParagraph find its buffer to get
44 // parameters? (JMarc)
45 extern BufferView * current_view;
49 extern string bibitemWidthest(Painter &);
51 // this is a minibuffer
52 static char minibuffer_char;
53 static LyXFont minibuffer_font;
54 static Inset * minibuffer_inset;
57 // Initialization of the counter for the paragraph id's,
58 // declared in lyxparagraph.h
59 unsigned int LyXParagraph::paragraph_id = 0;
62 LyXParagraph::LyXParagraph()
64 text.reserve(500); // is this number too big?
66 for (int i = 0; i < 10; ++i) setCounter(i , 0);
72 footnoteflag = LyXParagraph::NO_FOOTNOTE;
73 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
75 align = LYX_ALIGN_BLOCK;
77 /* table stuff -- begin*/
79 /* table stuff -- end*/
81 bibkey = 0; // ale970302
86 // This konstruktor inserts the new paragraph in a list.
87 LyXParagraph::LyXParagraph(LyXParagraph * par)
90 par->text.resize(par->text.size());
92 for (int i = 0; i < 10; ++i) setCounter(i, 0);
96 // double linked list begin
99 next->previous = this;
101 previous->next = this;
103 footnoteflag = LyXParagraph::NO_FOOTNOTE;
104 footnotekind = LyXParagraph::FOOTNOTE;
106 /* table stuff -- begin*/
108 /* table stuff -- end*/
109 id_ = paragraph_id++;
111 bibkey = 0; // ale970302
117 void LyXParagraph::writeFile(ostream & os, BufferParams const & params,
118 char footflag, char dth) const
120 LyXFont font1, font2;
125 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
127 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
129 // The beginning or the end of a footnote environment?
130 if (footflag != footnoteflag) {
131 footflag = footnoteflag;
133 os << "\n\\begin_float "
134 << string_footnotekinds[footnotekind]
137 os << "\n\\end_float ";
141 // The beginning or end of a deeper (i.e. nested) area?
144 while (depth > dth) {
145 os << "\n\\begin_deeper ";
149 while (depth < dth) {
150 os << "\n\\end_deeper ";
156 // First write the layout
158 << textclasslist.NameOfLayout(params.textclass, layout)
161 // Maybe some vertical spaces.
162 if (added_space_top.kind() != VSpace::NONE)
163 os << "\\added_space_top "
164 << added_space_top.asLyXCommand() << " ";
165 if (added_space_bottom.kind() != VSpace::NONE)
166 os << "\\added_space_bottom "
167 << added_space_bottom.asLyXCommand() << " ";
169 // The labelwidth string used in lists.
170 if (!labelwidthstring.empty())
171 os << "\\labelwidthstring "
172 << labelwidthstring << '\n';
174 // Lines above or below?
178 os << "\\line_bottom ";
180 // Pagebreaks above or below?
182 os << "\\pagebreak_top ";
183 if (pagebreak_bottom)
184 os << "\\pagebreak_bottom ";
186 // Start of appendix?
187 if (start_of_appendix)
188 os << "\\start_of_appendix ";
195 if (align != LYX_ALIGN_LAYOUT) {
197 case LYX_ALIGN_LEFT: h = 1; break;
198 case LYX_ALIGN_RIGHT: h = 2; break;
199 case LYX_ALIGN_CENTER: h = 3; break;
200 default: h = 0; break;
202 os << "\\align " << string_align[h] << " ";
204 if (pextra_type != PEXTRA_NONE) {
205 os << "\\pextra_type " << pextra_type;
206 if (pextra_type == PEXTRA_MINIPAGE) {
207 os << " \\pextra_alignment "
210 os << " \\pextra_hfill "
212 if (pextra_start_minipage)
213 os << " \\pextra_start_minipage "
214 << pextra_start_minipage;
216 if (!pextra_width.empty()) {
217 os << " \\pextra_width "
218 << VSpace(pextra_width).asLyXCommand();
219 } else if (!pextra_widthp.empty()) {
220 os << " \\pextra_widthp "
226 // Dummy layout. This means that a footnote ended.
227 os << "\n\\end_float ";
228 footflag = LyXParagraph::NO_FOOTNOTE;
231 // It might be a table.
233 os << "\\LyXTable\n";
241 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
244 for (size_type i = 0; i < size(); ++i) {
250 // Write font changes
251 font2 = GetFontSettings(i);
252 if (font2 != font1) {
253 font2.lyxWriteChanges(font1, os);
262 Inset const * inset = GetInset(i);
264 if (inset->DirectWrite()) {
265 // international char, let it write
266 // code directly so it's shorter in
270 os << "\n\\begin_inset ";
272 os << "\n\\end_inset \n\n";
278 os << "\n\\newline \n";
282 os << "\n\\hfill \n";
286 case META_PROTECTED_SEPARATOR:
287 os << "\n\\protected_separator \n";
292 os << "\n\\backslash \n";
296 if (i + 1 < size() && GetChar(i + 1) == ' ') {
303 if ((column > 70 && c == ' ')
308 // this check is to amend a bug. LyX sometimes
309 // inserts '\0' this could cause problems.
313 lyxerr << "ERROR (LyXParagraph::writeFile):"
314 " NULL char in structure." << endl;
320 // now write the next paragraph
322 next->writeFile(os, params, footflag, dth);
326 void LyXParagraph::validate(LaTeXFeatures & features) const
328 // this will be useful later
329 LyXLayout const & layout =
330 textclasslist.Style(current_view->buffer()->params.textclass,
334 if (line_top || line_bottom)
335 features.lyxline = true;
338 features.layout[GetLayout()] = true;
341 Language const * doc_language = current_view->buffer()->params.language_info;
342 for (FontList::const_iterator cit = fontlist.begin();
343 cit != fontlist.end(); ++cit) {
344 if ((*cit).font.noun() == LyXFont::ON) {
345 lyxerr[Debug::LATEX] << "font.noun: "
346 << (*cit).font.noun()
348 features.noun = true;
349 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
350 << (*cit).font.stateText()
353 switch ((*cit).font.color()) {
355 case LColor::inherit:
359 features.color = true;
360 lyxerr[Debug::LATEX] << "Color enabled. Font: "
361 << (*cit).font.stateText()
364 Language const * language = (*cit).font.language();
365 if (language != doc_language && language != default_language) {
366 features.UsedLanguages.insert(language);
367 lyxerr[Debug::LATEX] << "Found language "
368 << language->lang << endl;
373 for (InsetList::const_iterator cit = insetlist.begin();
374 cit != insetlist.end(); ++cit) {
376 (*cit).inset->Validate(features);
379 if (table && table->IsLongTable())
380 features.longtable = true;
381 if (pextra_type == PEXTRA_INDENT)
382 features.LyXParagraphIndent = true;
383 if (pextra_type == PEXTRA_FLOATFLT)
384 features.floatflt = true;
385 if (layout.needprotect
386 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
387 features.NeedLyXFootnoteCode = true;
388 if ((current_view->buffer()->params.paragraph_separation == BufferParams::PARSEP_INDENT) &&
389 (pextra_type == LyXParagraph::PEXTRA_MINIPAGE))
390 features.NeedLyXMinipageIndent = true;
391 if (table && table->NeedRotating())
392 features.rotating = true;
393 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
394 features.algorithm = true;
398 // First few functions needed for cut and paste and paragraph breaking.
399 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
401 minibuffer_char = GetChar(pos);
402 minibuffer_font = GetFontSettings(pos);
403 minibuffer_inset = 0;
404 if (minibuffer_char == LyXParagraph::META_INSET) {
406 minibuffer_inset = GetInset(pos)->Clone();
408 minibuffer_inset = 0;
409 minibuffer_char = ' ';
410 // This reflects what GetInset() does (ARRae)
416 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
418 minibuffer_char = GetChar(pos);
419 minibuffer_font = GetFontSettings(pos);
420 minibuffer_inset = 0;
421 if (minibuffer_char == LyXParagraph::META_INSET) {
423 minibuffer_inset = GetInset(pos);
424 // This is a little hack since I want exactly
425 // the inset, not just a clone. Otherwise
426 // the inset would be deleted when calling Erase(pos)
428 for (InsetList::iterator it = insetlist.begin();
429 it != insetlist.end(); ++it) {
430 if ((*it).pos == pos) {
437 minibuffer_inset = 0;
438 minibuffer_char = ' ';
439 // This reflects what GetInset() does (ARRae)
444 // Erase(pos); now the caller is responsible for that.
448 void LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
450 InsertChar(pos, minibuffer_char);
451 SetFont(pos, minibuffer_font);
452 if (minibuffer_char == LyXParagraph::META_INSET)
453 InsertInset(pos, minibuffer_inset);
460 void LyXParagraph::Clear()
465 pagebreak_top = false;
466 pagebreak_bottom = false;
468 added_space_top = VSpace(VSpace::NONE);
469 added_space_bottom = VSpace(VSpace::NONE);
471 align = LYX_ALIGN_LAYOUT;
475 pextra_type = PEXTRA_NONE;
476 pextra_width.clear();
477 pextra_widthp.clear();
478 pextra_alignment = MINIPAGE_ALIGN_TOP;
479 pextra_hfill = false;
480 pextra_start_minipage = false;
483 labelwidthstring.clear();
487 start_of_appendix = false;
491 // the destructor removes the new paragraph from the list
492 LyXParagraph::~LyXParagraph()
495 previous->next = next;
497 next->previous = previous;
499 for (InsetList::iterator it = insetlist.begin();
500 it != insetlist.end(); ++it) {
504 /* table stuff -- begin*/
506 /* table stuff -- end*/
513 void LyXParagraph::Erase(LyXParagraph::size_type pos)
515 // > because last is the next unused position, and you can
516 // use it if you want
518 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
519 NextAfterFootnote()->Erase(pos - text.size() - 1);
521 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
522 "position does not exist." << endl;
525 if (pos < size()) { // last is free for insertation, but should be empty
526 // if it is an inset, delete the inset entry
527 if (text[pos] == LyXParagraph::META_INSET) {
529 for (InsetList::iterator it = insetlist.begin();
530 it != insetlist.end(); ++it) {
531 if ((*it).pos == pos) {
538 text.erase(text.begin() + pos);
539 // Erase entries in the tables.
540 for (FontList::iterator it = fontlist.begin();
541 it != fontlist.end(); ++it) {
542 if (pos >= (*it).pos && pos <= (*it).pos_end) {
543 if ((*it).pos == (*it).pos_end) {
544 // If it is a multi-character font
545 // entry, we just make it smaller
546 // (see update below), otherwise we
553 // Update all other entries.
554 for (FontList::iterator it = fontlist.begin();
555 it != fontlist.end(); ++it) {
558 if ((*it).pos_end >= pos)
562 // Update the inset table.
563 for (InsetList::iterator it = insetlist.begin();
564 it != insetlist.end(); ++it) {
569 lyxerr << "ERROR (LyXParagraph::Erase): "
570 "can't erase non-existant char." << endl;
575 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
577 // > because last is the next unused position, and you can
578 // use it if you want
581 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
582 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
585 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
586 "position does not exist." << endl;
589 text.insert(text.begin() + pos, c);
590 // Update the font table.
591 for (FontList::iterator it = fontlist.begin();
592 it != fontlist.end(); ++it) {
593 if ((*it).pos >= pos)
595 if ((*it).pos_end >= pos)
599 // Update the inset table.
600 for (InsetList::iterator it = insetlist.begin();
601 it != insetlist.end(); ++it) {
602 if ((*it).pos >= pos)
608 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
611 // > because last is the next unused position, and you can
612 // use it if you want
615 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
617 ->InsertInset(pos - text.size() - 1, inset);
619 lyxerr << "ERROR (LyXParagraph::InsertInset): "
620 "position does not exist: " << pos << endl;
623 if (text[pos] != LyXParagraph::META_INSET) {
624 lyxerr << "ERROR (LyXParagraph::InsertInset): "
625 "there is no LyXParagraph::META_INSET" << endl;
630 // Add a new entry in the inset table.
631 InsetList::iterator it =
632 insetlist.insert(insetlist.begin(), InsetTable());
639 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
643 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
644 return NextAfterFootnote()
645 ->GetInset(pos - text.size() - 1);
647 lyxerr << "ERROR (LyXParagraph::GetInset): "
648 "position does not exist: "
654 for (InsetList::iterator it = insetlist.begin();
655 it != insetlist.end(); ++it) {
656 if ((*it).pos == pos) {
660 lyxerr << "ERROR (LyXParagraph::GetInset): "
661 "Inset does not exist: " << pos << endl;
662 text[pos] = ' '; // WHY!!! does this set the pos to ' '????
663 // Did this commenting out introduce a bug? So far I have not
664 // see any, please enlighten me. (Lgb)
665 // My guess is that since the inset does not exist, we might
666 // as well replace it with a space to prevent craches. (Asger)
671 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
675 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
676 return NextAfterFootnote()
677 ->GetInset(pos - text.size() - 1);
679 lyxerr << "ERROR (LyXParagraph::GetInset): "
680 "position does not exist: "
686 for (InsetList::const_iterator cit = insetlist.begin();
687 cit != insetlist.end(); ++cit) {
688 if ((*cit).pos == pos) {
692 lyxerr << "ERROR (LyXParagraph::GetInset): "
693 "Inset does not exist: " << pos << endl;
694 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
695 // Did this commenting out introduce a bug? So far I have not
696 // see any, please enlighten me. (Lgb)
697 // My guess is that since the inset does not exist, we might
698 // as well replace it with a space to prevent craches. (Asger)
703 // Gets uninstantiated font setting at position.
704 // Optimized after profiling. (Asger)
705 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
708 #ifdef SORTED_FONT_LIST
709 for (FontList::const_iterator cit = fontlist.begin();
710 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
711 if (pos >= (*cit).pos)
714 for (FontList::const_iterator cit = fontlist.begin();
715 cit != fontlist.end(); ++cit)
716 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
720 // > because last is the next unused position, and you can
721 // use it if you want
722 else if (pos > size()) {
724 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
725 return NextAfterFootnote()
726 ->GetFontSettings(pos - text.size() - 1);
728 // Why is it an error to ask for the font of a
729 // position that does not exist? Would it be
730 // enough for this to be enabled on debug?
731 // We want strict error checking, but it's ok to only
732 // have it when debugging. (Asger)
733 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
734 "position does not exist. "
735 << pos << " (" << static_cast<int>(pos)
738 } else if (pos > 0) {
739 return GetFontSettings(pos - 1);
740 } else // pos = size() = 0
741 return LyXFont(LyXFont::ALL_INHERIT,getParLanguage());
743 return LyXFont(LyXFont::ALL_INHERIT);
746 // Gets uninstantiated font setting at position 0
747 LyXFont LyXParagraph::GetFirstFontSettings() const
750 #ifdef SORTED_FONT_LIST
751 if (!fontlist.empty() && fontlist.front().pos == 0)
752 return fontlist.front().font;
754 for (FontList::const_iterator cit = fontlist.begin();
755 cit != fontlist.end(); ++cit)
756 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
760 return LyXFont(LyXFont::ALL_INHERIT);
763 // Gets the fully instantiated font at a given position in a paragraph
764 // This is basically the same function as LyXText::GetFont() in text2.C.
765 // The difference is that this one is used for generating the LaTeX file,
766 // and thus cosmetic "improvements" are disallowed: This has to deliver
767 // the true picture of the buffer. (Asger)
768 // If position is -1, we get the layout font of the paragraph.
769 // If position is -2, we get the font of the manual label of the paragraph.
770 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
773 LyXLayout const & layout =
774 textclasslist.Style(current_view->buffer()->params.textclass,
776 LyXParagraph::size_type main_body = 0;
777 if (layout.labeltype == LABEL_MANUAL)
778 main_body = BeginningOfMainBody();
783 layoutfont = layout.labelfont;
785 layoutfont = layout.font;
786 tmpfont = GetFontSettings(pos);
787 tmpfont.realize(layoutfont);
789 // process layoutfont for pos == -1 and labelfont for pos < -1
791 tmpfont = layout.font;
793 tmpfont = layout.labelfont;
794 tmpfont.setLanguage(getParLanguage());
797 // check for environment font information
798 char par_depth = GetDepth();
799 LyXParagraph const * par = this;
800 while (par && par_depth && !tmpfont.resolved()) {
801 par = par->DepthHook(par_depth - 1);
803 tmpfont.realize(textclasslist.
804 Style(current_view->buffer()->params.textclass,
805 par->GetLayout()).font);
806 par_depth = par->GetDepth();
810 tmpfont.realize(textclasslist
811 .TextClass(current_view->buffer()->params.textclass)
817 /// Returns the height of the highest font in range
819 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
820 LyXParagraph::size_type endpos) const
822 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
823 for (FontList::const_iterator cit = fontlist.begin();
824 cit != fontlist.end(); ++cit) {
825 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
826 LyXFont::FONT_SIZE size = (*cit).font.size();
827 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
835 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
842 // > because last is the next unused position, and you can
843 // use it if you want
844 else if (pos > size()) {
845 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
846 return NextAfterFootnote()
847 ->GetChar(pos - text.size() - 1);
849 lyxerr << "ERROR (LyXParagraph::GetChar): "
850 "position does not exist."
851 << pos << " (" << static_cast<int>(pos)
853 // Assert(false); // This triggers sometimes...
858 // We should have a footnote environment.
859 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
860 // Notice that LyX does request the
861 // last char from time to time. (Asger)
862 //lyxerr << "ERROR (LyXParagraph::GetChar): "
863 // "expected footnote." << endl;
866 switch (next->footnotekind) {
867 case LyXParagraph::FOOTNOTE:
868 return LyXParagraph::META_FOOTNOTE;
869 case LyXParagraph::MARGIN:
870 return LyXParagraph::META_MARGIN;
871 case LyXParagraph::FIG:
872 case LyXParagraph::WIDE_FIG:
873 return LyXParagraph::META_FIG;
874 case LyXParagraph::TAB:
875 case LyXParagraph::WIDE_TAB:
876 return LyXParagraph::META_TAB;
877 case LyXParagraph::ALGORITHM:
878 return LyXParagraph::META_ALGORITHM;
880 return '\0'; // to shut up gcc
885 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
892 // > because last is the next unused position, and you can
893 // use it if you want
894 else if (pos > size()) {
895 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
896 return NextAfterFootnote()
897 ->GetChar(pos - text.size() - 1);
899 lyxerr << "ERROR (LyXParagraph::GetChar const): "
900 "position does not exist."
901 << pos << " (" << static_cast<int>(pos)
907 // We should have a footnote environment.
908 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
909 // Notice that LyX does request the
910 // last char from time to time. (Asger)
911 //lyxerr << "ERROR (LyXParagraph::GetChar): "
912 // "expected footnote." << endl;
915 switch (next->footnotekind) {
916 case LyXParagraph::FOOTNOTE:
917 return LyXParagraph::META_FOOTNOTE;
918 case LyXParagraph::MARGIN:
919 return LyXParagraph::META_MARGIN;
920 case LyXParagraph::FIG:
921 case LyXParagraph::WIDE_FIG:
922 return LyXParagraph::META_FIG;
923 case LyXParagraph::TAB:
924 case LyXParagraph::WIDE_TAB:
925 return LyXParagraph::META_TAB;
926 case LyXParagraph::ALGORITHM:
927 return LyXParagraph::META_ALGORITHM;
929 return '\0'; // to shut up gcc
934 // return an string of the current word, and the end of the word in lastpos.
935 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
939 // the current word is defined as starting at the first character
940 // from the immediate left of lastpospos which meets the definition
941 // of IsLetter(), continuing to the last character to the right
942 // of this meeting IsLetter.
948 // move back until we have a letter
950 //there's no real reason to have firstpos & lastpos as
951 //separate variables as this is written, but maybe someon
952 // will want to return firstpos in the future.
954 //since someone might have typed a punctuation first
955 int firstpos = lastpos;
957 while ((firstpos >= 0) && !IsLetter(firstpos))
960 // now find the beginning by looking for a nonletter
962 while ((firstpos>= 0) && IsLetter(firstpos))
965 // the above is now pointing to the preceeding non-letter
969 // so copy characters into theword until we get a nonletter
970 // note that this can easily exceed lastpos, wich means
971 // that if used in the middle of a word, the whole word
974 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
981 LyXParagraph::size_type LyXParagraph::Last() const
983 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
984 return text.size() + NextAfterFootnote()->Last() + 1;
985 // the 1 is the symbol
992 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
994 // > because last is the next unused position, and you can
995 // use it if you want
998 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
999 return NextAfterFootnote()
1000 ->ParFromPos(pos - text.size() - 1);
1002 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1003 "position does not exist." << endl;
1010 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1012 // > because last is the next unused position, and you can
1013 // use it if you want
1016 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1017 return NextAfterFootnote()
1018 ->PositionInParFromPos(pos - text.size() - 1);
1021 "ERROR (LyXParagraph::PositionInParFromPos): "
1022 "position does not exist." << endl;
1030 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1031 LyXFont const & font)
1033 // > because last is the next unused position, and you can
1034 // use it if you want
1037 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1038 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1041 lyxerr << "ERROR (LyXParagraph::SetFont): "
1042 "position does not exist." << endl;
1046 LyXFont patternfont(LyXFont::ALL_INHERIT);
1048 // First, reduce font against layout/label font
1049 // Update: The SetCharFont() routine in text2.C already
1050 // reduces font, so we don't need to do that here. (Asger)
1051 // No need to simplify this because it will disappear
1052 // in a new kernel. (Asger)
1053 // Next search font table
1054 FontList::iterator tmp = fontlist.begin();
1055 for (; tmp != fontlist.end(); ++tmp) {
1056 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1060 if (tmp == fontlist.end()) { // !found
1061 // if we did not find a font entry, but if the font at hand
1062 // is the same as default, we just forget it
1063 if (font == patternfont) return;
1065 // ok, we did not find a font entry. But maybe there is exactly
1066 // the needed font ientry one position left
1067 FontList::iterator tmp2 = fontlist.begin();
1068 for (; tmp2 != fontlist.end(); ++tmp2) {
1069 if (pos - 1 >= (*tmp2).pos
1070 && pos - 1 <= (*tmp2).pos_end)
1073 if (tmp2 != fontlist.end()) {
1074 // ok there is one, maybe it is exactly
1076 if ((*tmp2).font == font) {
1077 // put the position under the font
1082 // Add a new entry in the
1083 // fontlist for the position
1087 ft.font = font; // or patternfont
1088 // It seems that using font instead of patternfont here
1089 // fixes all the problems. This also surfaces a "bug" in
1091 fontlist.insert(fontlist.begin(), ft);
1092 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1094 // more than one character
1095 if (pos == (*tmp).pos) {
1096 // maybe we should enlarge the left fonttable
1097 FontList::iterator tmp2 = fontlist.begin();
1098 for (; tmp2 != fontlist.end(); ++tmp2) {
1099 if (pos - 1 >= (*tmp2).pos
1100 && pos - 1 <= (*tmp2).pos_end)
1103 // Is there is one, and is it exactly
1105 if (tmp2 != fontlist.end() &&
1106 (*tmp2).font == font) {
1107 // Put the position under the font
1113 // Add a new entry in the
1114 // fontlist for the position
1117 ft.pos_end = (*tmp).pos_end;
1118 ft.font = (*tmp).font;
1119 (*tmp).pos_end = pos;
1121 fontlist.insert(fontlist.begin(), ft);
1122 } else if (pos == (*tmp).pos_end) {
1123 // Add a new entry in the
1124 // fontlist for the position
1126 ft.pos = (*tmp).pos;
1127 ft.pos_end = (*tmp).pos_end - 1;
1128 ft.font = (*tmp).font;
1129 (*tmp).pos = (*tmp).pos_end;
1131 fontlist.insert(fontlist.begin(), ft);
1133 // Add a new entry in the
1134 // fontlist for the position
1136 ft.pos = (*tmp).pos;
1137 ft.pos_end = pos - 1;
1138 ft.font = (*tmp).font;
1142 ft2.pos_end = (*tmp).pos_end;
1143 ft2.font = (*tmp).font;
1146 (*tmp).pos_end = pos;
1149 fontlist.insert(fontlist.begin(), ft);
1150 fontlist.insert(fontlist.begin(), ft2);
1158 // This function is able to hide closed footnotes.
1159 LyXParagraph * LyXParagraph::Next()
1161 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1162 LyXParagraph * tmp = next;
1164 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1166 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1167 return tmp->Next(); /* there can be more than one
1168 footnote in a logical
1171 return next; // This should never happen!
1177 LyXParagraph * LyXParagraph::NextAfterFootnote()
1179 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1180 LyXParagraph * tmp = next;
1181 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1183 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1184 return tmp; /* there can be more than one footnote
1185 in a logical paragraph */
1187 return next; // This should never happen!
1193 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1195 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1196 LyXParagraph * tmp = next;
1197 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1199 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1200 return tmp; /* there can be more than one footnote
1201 in a logical paragraph */
1203 return next; // This should never happen!
1209 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1212 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1214 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1215 tmp = tmp->previous;
1216 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1217 return tmp; /* there can be more than one footnote
1218 in a logical paragraph */
1220 return previous; // This should never happen!
1226 LyXParagraph * LyXParagraph::LastPhysicalPar()
1228 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1231 LyXParagraph * tmp = this;
1233 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1234 tmp = tmp->NextAfterFootnote();
1239 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1241 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1244 LyXParagraph const * tmp = this;
1246 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1247 tmp = tmp->NextAfterFootnote();
1252 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1256 LyXParagraph * tmppar = this;
1260 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1261 tmppar = tmppar->previous;
1270 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1274 LyXParagraph const * tmppar = this;
1278 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1279 tmppar = tmppar->previous;
1288 // This function is able to hide closed footnotes.
1289 LyXParagraph * LyXParagraph::Previous()
1291 LyXParagraph * tmp = previous;
1296 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1297 tmp = tmp->previous;
1299 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1300 tmp = tmp->previous;
1301 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1302 return tmp->next->Previous();
1311 // This function is able to hide closed footnotes.
1312 LyXParagraph const * LyXParagraph::Previous() const
1314 LyXParagraph * tmp = previous;
1319 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1320 tmp = tmp->previous;
1322 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1323 tmp = tmp->previous;
1324 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1325 return tmp->next->Previous();
1334 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1337 size_type i, pos_end, pos_first;
1338 // create a new paragraph
1339 LyXParagraph * par = ParFromPos(pos);
1340 LyXParagraph * firstpar = FirstPhysicalPar();
1342 LyXParagraph * tmp = new LyXParagraph(par);
1344 tmp->footnoteflag = footnoteflag;
1345 tmp->footnotekind = footnotekind;
1347 // this is an idea for a more userfriendly layout handling, I will
1348 // see what the users say
1350 // layout stays the same with latex-environments
1352 tmp->SetOnlyLayout(firstpar->layout);
1353 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1356 if (Last() > pos || !Last() || flag == 2) {
1357 tmp->SetOnlyLayout(firstpar->layout);
1358 tmp->align = firstpar->align;
1359 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1361 tmp->line_bottom = firstpar->line_bottom;
1362 firstpar->line_bottom = false;
1363 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1364 firstpar->pagebreak_bottom = false;
1365 tmp->added_space_bottom = firstpar->added_space_bottom;
1366 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1368 tmp->depth = firstpar->depth;
1369 tmp->noindent = firstpar->noindent;
1371 // copy everything behind the break-position
1372 // to the new paragraph
1374 while (ParFromPos(pos_first) != par)
1377 pos_end = pos_first + par->text.size() - 1;
1378 // The constructor has already reserved 500 elements
1379 //if (pos_end > pos)
1380 // tmp->text.reserve(pos_end - pos);
1382 for (i = pos; i <= pos_end; ++i) {
1383 par->CutIntoMinibuffer(i - pos_first);
1384 tmp->InsertFromMinibuffer(i - pos);
1386 tmp->text.resize(tmp->text.size());
1387 for (i = pos_end; i >= pos; --i)
1388 par->Erase(i - pos_first);
1390 par->text.resize(par->text.size());
1393 // just an idea of me
1395 tmp->line_top = firstpar->line_top;
1396 tmp->pagebreak_top = firstpar->pagebreak_top;
1397 tmp->added_space_top = firstpar->added_space_top;
1398 tmp->bibkey = firstpar->bibkey;
1400 // layout stays the same with latex-environments
1402 firstpar->SetOnlyLayout(tmp->layout);
1403 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1404 firstpar->depth = tmp->depth;
1410 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1412 par = par->FirstPhysicalPar();
1413 footnoteflag = par->footnoteflag;
1414 footnotekind = par->footnotekind;
1416 layout = par->layout;
1417 align = par-> align;
1418 SetLabelWidthString(par->labelwidthstring);
1420 line_bottom = par->line_bottom;
1421 pagebreak_bottom = par->pagebreak_bottom;
1422 added_space_bottom = par->added_space_bottom;
1424 line_top = par->line_top;
1425 pagebreak_top = par->pagebreak_top;
1426 added_space_top = par->added_space_top;
1428 pextra_type = par->pextra_type;
1429 pextra_width = par->pextra_width;
1430 pextra_widthp = par->pextra_widthp;
1431 pextra_alignment = par->pextra_alignment;
1432 pextra_hfill = par->pextra_hfill;
1433 pextra_start_minipage = par->pextra_start_minipage;
1435 noindent = par->noindent;
1440 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1442 LyXParagraph * tmppar = this;
1445 && tmppar->previous->footnoteflag ==
1446 LyXParagraph::CLOSED_FOOTNOTE)
1447 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1448 tmppar = tmppar->previous;
1451 return this; // This should never happen!
1457 LyXParagraph * LyXParagraph::Clone() const
1459 // create a new paragraph
1460 LyXParagraph * result = new LyXParagraph;
1462 result->MakeSameLayout(this);
1464 // this is because of the dummy layout of the paragraphs that
1466 result->layout = layout;
1468 /* table stuff -- begin*/
1470 result->table = table->Clone();
1473 /* table stuff -- end*/
1476 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1479 // copy everything behind the break-position to the new paragraph
1481 for (size_type i = 0; i < size(); ++i) {
1482 CopyIntoMinibuffer(i);
1483 result->InsertFromMinibuffer(i);
1485 result->text.resize(result->text.size());
1490 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1492 par = par->FirstPhysicalPar();
1495 par->footnoteflag == footnoteflag &&
1496 par->footnotekind == footnotekind &&
1498 par->layout == layout &&
1500 par->align == align &&
1502 par->line_bottom == line_bottom &&
1503 par->pagebreak_bottom == pagebreak_bottom &&
1504 par->added_space_bottom == added_space_bottom &&
1506 par->line_top == line_top &&
1507 par->pagebreak_top == pagebreak_top &&
1508 par->added_space_top == added_space_top &&
1510 par->pextra_type == pextra_type &&
1511 par->pextra_width == pextra_width &&
1512 par->pextra_widthp == pextra_widthp &&
1513 par->pextra_alignment == pextra_alignment &&
1514 par->pextra_hfill == pextra_hfill &&
1515 par->pextra_start_minipage == pextra_start_minipage &&
1517 par->table == table && // what means: NO TABLE AT ALL
1519 par->noindent == noindent &&
1520 par->depth == depth);
1524 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1526 // create a new paragraph
1527 LyXParagraph * par = ParFromPos(pos);
1529 LyXParagraph * tmp = new LyXParagraph(par);
1531 tmp->MakeSameLayout(par);
1533 // When can pos < Last()?
1534 // I guess pos == Last() is possible.
1536 // copy everything behind the break-position to the new
1538 size_type pos_first = 0;
1539 while (ParFromPos(pos_first) != par)
1541 size_type pos_end = pos_first + par->text.size() - 1;
1542 // make sure there is enough memory for the now larger
1543 // paragraph. This is not neccessary, because
1544 // InsertFromMinibuffer will enlarge the memory (it uses
1545 // InsertChar of course). But doing it by hand
1546 // is MUCH faster! (only one time, not thousend times!!)
1547 // Not needed since the constructor aleady have
1548 // reserved 500 elements in text.
1549 //if (pos_end > pos)
1550 // tmp->text.reserve(pos_end - pos);
1552 for (size_type i = pos; i <= pos_end; ++i) {
1553 par->CutIntoMinibuffer(i - pos_first);
1554 tmp->InsertFromMinibuffer(i - pos);
1556 tmp->text.resize(tmp->text.size());
1557 for (size_type i = pos_end; i >= pos; --i)
1558 par->Erase(i - pos_first);
1560 par->text.resize(par->text.size());
1565 // Be carefull, this does not make any check at all.
1566 void LyXParagraph::PasteParagraph()
1568 // copy the next paragraph to this one
1569 LyXParagraph * the_next = Next();
1571 LyXParagraph * firstpar = FirstPhysicalPar();
1573 // first the DTP-stuff
1574 firstpar->line_bottom = the_next->line_bottom;
1575 firstpar->added_space_bottom = the_next->added_space_bottom;
1576 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1578 size_type pos_end = the_next->text.size() - 1;
1579 size_type pos_insert = Last();
1581 // ok, now copy the paragraph
1582 for (size_type i = 0; i <= pos_end; ++i) {
1583 the_next->CutIntoMinibuffer(i);
1584 InsertFromMinibuffer(pos_insert + i);
1587 // delete the next paragraph
1592 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1594 LyXParagraph * par = ParFromPos(pos);
1596 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1597 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1603 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1605 LyXParagraph * par = ParFromPos(pos);
1607 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1608 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1613 int LyXParagraph::GetEndLabel() const
1615 LyXParagraph const * par = this;
1616 int par_depth = GetDepth();
1618 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1620 textclasslist.Style(current_view->buffer()->params.textclass,
1621 layout).endlabeltype;
1622 if (endlabeltype != END_LABEL_NO_LABEL) {
1623 LyXParagraph const * last = this;
1624 if( footnoteflag == NO_FOOTNOTE)
1625 last = LastPhysicalPar();
1626 else if (next->footnoteflag == NO_FOOTNOTE)
1627 return endlabeltype;
1629 if (!last || !last->next)
1630 return endlabeltype;
1632 int next_depth = last->next->GetDepth();
1633 if (par_depth > next_depth ||
1634 (par_depth == next_depth && layout != last->next->GetLayout() ))
1635 return endlabeltype;
1640 par = par->DepthHook(par_depth - 1);
1642 par_depth = par->GetDepth();
1644 return END_LABEL_NO_LABEL;
1647 LyXTextClass::size_type LyXParagraph::GetLayout() const
1649 return FirstPhysicalPar()->layout;
1653 char LyXParagraph::GetDepth() const
1655 return FirstPhysicalPar()->depth;
1659 char LyXParagraph::GetAlign() const
1661 return FirstPhysicalPar()->align;
1665 string LyXParagraph::GetLabestring() const
1667 return FirstPhysicalPar()->labelstring;
1671 int LyXParagraph::GetFirstCounter(int i) const
1673 return FirstPhysicalPar()->counter_[i];
1677 // the next two functions are for the manual labels
1678 string LyXParagraph::GetLabelWidthString() const
1680 if (!FirstPhysicalPar()->labelwidthstring.empty())
1681 return FirstPhysicalPar()->labelwidthstring;
1683 return _("Senseless with this layout!");
1687 void LyXParagraph::SetLabelWidthString(string const & s)
1689 LyXParagraph * par = FirstPhysicalPar();
1691 par->labelwidthstring = s;
1695 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1697 LyXParagraph * par = FirstPhysicalPar();
1698 LyXParagraph * ppar = 0;
1699 LyXParagraph * npar = 0;
1701 par->layout = new_layout;
1702 /* table stuff -- begin*/
1705 /* table stuff -- end*/
1706 if (par->pextra_type == PEXTRA_NONE) {
1707 if (par->Previous()) {
1708 ppar = par->Previous()->FirstPhysicalPar();
1711 && (ppar->depth > par->depth))
1712 ppar = ppar->Previous()->FirstPhysicalPar();
1715 npar = par->Next()->NextAfterFootnote();
1718 && (npar->depth > par->depth))
1719 npar = npar->Next()->NextAfterFootnote();
1721 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1723 p1 = ppar->pextra_width,
1724 p2 = ppar->pextra_widthp;
1725 ppar->SetPExtraType(ppar->pextra_type,
1726 p1.c_str(), p2.c_str());
1728 if ((par->pextra_type == PEXTRA_NONE) &&
1729 npar && (npar->pextra_type != PEXTRA_NONE)) {
1731 p1 = npar->pextra_width,
1732 p2 = npar->pextra_widthp;
1733 npar->SetPExtraType(npar->pextra_type,
1734 p1.c_str(), p2.c_str());
1740 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1743 * par = FirstPhysicalPar(),
1747 par->layout = new_layout;
1748 par->labelwidthstring.clear();
1749 par->align = LYX_ALIGN_LAYOUT;
1750 par->added_space_top = VSpace(VSpace::NONE);
1751 par->added_space_bottom = VSpace(VSpace::NONE);
1752 /* table stuff -- begin*/
1755 /* table stuff -- end*/
1756 if (par->pextra_type == PEXTRA_NONE) {
1757 if (par->Previous()) {
1758 ppar = par->Previous()->FirstPhysicalPar();
1761 && (ppar->depth > par->depth))
1762 ppar = ppar->Previous()->FirstPhysicalPar();
1765 npar = par->Next()->NextAfterFootnote();
1768 && (npar->depth > par->depth))
1769 npar = npar->Next()->NextAfterFootnote();
1771 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1773 p1 = ppar->pextra_width,
1774 p2 = ppar->pextra_widthp;
1775 ppar->SetPExtraType(ppar->pextra_type,
1776 p1.c_str(), p2.c_str());
1778 if ((par->pextra_type == PEXTRA_NONE) &&
1779 npar && (npar->pextra_type != PEXTRA_NONE)) {
1781 p1 = npar->pextra_width,
1782 p2 = npar->pextra_widthp;
1783 npar->SetPExtraType(npar->pextra_type,
1784 p1.c_str(), p2.c_str());
1790 // if the layout of a paragraph contains a manual label, the beginning of the
1791 // main body is the beginning of the second word. This is what the par-
1792 // function returns. If the layout does not contain a label, the main
1793 // body always starts with position 0. This differentiation is necessary,
1794 // because there cannot be a newline or a blank <= the beginning of the
1795 // main body in TeX.
1797 int LyXParagraph::BeginningOfMainBody() const
1799 if (FirstPhysicalPar() != this)
1802 // Unroll the first two cycles of the loop
1803 // and remember the previous character to
1804 // remove unnecessary GetChar() calls
1807 && GetChar(i) != LyXParagraph::META_NEWLINE
1810 char previous_char = 0, temp = 0;
1812 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1813 // Yes, this ^ is supposed to be "= " not "=="
1816 && previous_char != ' '
1817 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1819 previous_char = temp;
1824 if (i == 0 && i == size() &&
1825 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1826 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1827 ++i; /* the cursor should not jump
1828 * to the main body if there
1834 LyXParagraph * LyXParagraph::DepthHook(int deth)
1836 LyXParagraph * newpar = this;
1841 newpar = newpar->FirstPhysicalPar()->Previous();
1842 } while (newpar && newpar->GetDepth() > deth
1843 && newpar->footnoteflag == footnoteflag);
1846 if (Previous() || GetDepth())
1847 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1851 return newpar->FirstPhysicalPar();
1855 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1857 LyXParagraph const * newpar = this;
1862 newpar = newpar->FirstPhysicalPar()->Previous();
1863 } while (newpar && newpar->GetDepth() > deth
1864 && newpar->footnoteflag == footnoteflag);
1867 if (Previous() || GetDepth())
1868 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1872 return newpar->FirstPhysicalPar();
1876 int LyXParagraph::AutoDeleteInsets()
1878 vector<size_type> tmpvec;
1880 for (InsetList::iterator it = insetlist.begin();
1881 it != insetlist.end(); ++it) {
1882 if ((*it).inset && (*it).inset->AutoDelete()) {
1883 tmpvec.push_back((*it).pos);
1887 sort(tmpvec.begin(), tmpvec.end(), greater<size_type>());
1888 for (vector<size_type>::const_iterator cit = tmpvec.begin();
1889 cit != tmpvec.end(); ++cit) {
1896 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1898 InsetList::iterator it2 = insetlist.end();
1899 for (InsetList::iterator it = insetlist.begin();
1900 it != insetlist.end(); ++it) {
1901 if ((*it).pos >= pos) {
1902 if (it2 == insetlist.end() || (*it).pos < (*it2).pos)
1906 if (it2 != insetlist.end()) {
1908 return (*it2).inset;
1914 // returns -1 if inset not found
1915 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1918 for (InsetList::const_iterator cit = insetlist.begin();
1919 cit != insetlist.end(); ++cit) {
1920 if ((*cit).inset == inset) {
1924 // Think about footnotes.
1925 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1926 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1928 NextAfterFootnote()->GetPositionOfInset(inset);
1930 return text.size() + 1 + further;
1936 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1938 TexRow & foot_texrow,
1941 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1942 LyXLayout const & style =
1943 textclasslist.Style(current_view->buffer()->params.textclass,
1946 bool further_blank_line = false;
1948 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1950 if (start_of_appendix) {
1951 os << "\\appendix\n";
1955 if (tex_code_break_column && style.isCommand()){
1960 if (pagebreak_top) {
1962 further_blank_line = true;
1964 if (added_space_top.kind() != VSpace::NONE) {
1965 os << added_space_top.asLatexCommand(current_view->buffer()->params);
1966 further_blank_line = true;
1970 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
1971 << "\\vspace{-1\\parskip}";
1972 further_blank_line = true;
1975 if (further_blank_line){
1980 Language const * language = getParLanguage();
1981 Language const * doc_language = current_view->buffer()->params.language_info;
1982 if (language != doc_language) {
1983 os << subst(lyxrc.language_command_begin, "$$lang",
1989 switch (style.latextype) {
1992 << style.latexname()
1993 << style.latexparam();
1995 case LATEX_ITEM_ENVIRONMENT:
1997 bibkey->Latex(os, false, false);
2001 case LATEX_LIST_ENVIRONMENT:
2008 bool need_par = SimpleTeXOnePar(os, texrow);
2010 // Spit out footnotes
2011 LyXParagraph * par = next;
2012 if (lyxrc.rtl_support) {
2013 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2014 && next->footnoteflag != footnoteflag) {
2015 LyXParagraph * p = 0;
2016 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2017 if ( (p = NextAfterFootnote()) != 0 &&
2018 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2019 is_rtl = GetFontSettings(0).isRightToLeft();
2021 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2022 par->footnoteflag != footnoteflag) {
2023 LyXDirection dir = (is_rtl)
2024 ? LYX_DIR_RIGHT_TO_LEFT
2025 : LYX_DIR_LEFT_TO_RIGHT;
2026 par = par->TeXFootnote(os, texrow, foot,
2027 foot_texrow, foot_count,
2029 par->SimpleTeXOnePar(os, texrow);
2030 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2032 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2033 (p = par->NextAfterFootnote()) != 0 &&
2034 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2035 is_rtl = GetFontSettings(0).isRightToLeft();
2040 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2041 && par->footnoteflag != footnoteflag) {
2042 par = par->TeXFootnote(os, texrow,
2043 foot, foot_texrow, foot_count,
2044 LYX_DIR_LEFT_TO_RIGHT);
2045 par->SimpleTeXOnePar(os, texrow);
2050 // Make sure that \\par is done with the font of the last
2051 // character if this has another size as the default.
2052 // This is necessary because LaTeX (and LyX on the screen)
2053 // calculates the space between the baselines according
2054 // to this font. (Matthias)
2055 LyXFont font = getFont(Last() - 1);
2057 if (style.resfont.size() != font.size()) {
2063 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2064 GetLayout()).isCommand()){
2065 if (style.resfont.size() != font.size()) {
2071 } else if (style.resfont.size() != font.size()){
2072 os << "{\\" << font.latexSize() << " \\par}";
2075 if (language != doc_language) {
2077 << subst(lyxrc.language_command_end, "$$lang",
2078 doc_language->lang);
2081 switch (style.latextype) {
2082 case LATEX_ITEM_ENVIRONMENT:
2083 case LATEX_LIST_ENVIRONMENT:
2084 if (par && (depth < par->depth)) {
2089 case LATEX_ENVIRONMENT:
2090 // if its the last paragraph of the current environment
2091 // skip it otherwise fall through
2093 && (par->layout != layout
2094 || par->depth != depth
2095 || par->pextra_type != pextra_type))
2098 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2099 && footnotekind != LyXParagraph::FOOTNOTE
2100 && footnotekind != LyXParagraph::MARGIN
2104 // don't insert this if we would be adding it
2105 // before or after a table in a float. This
2106 // little trick is needed in order to allow
2107 // use of tables in \subfigures or \subtables.
2113 further_blank_line = false;
2115 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2116 further_blank_line = true;
2119 if (added_space_bottom.kind() != VSpace::NONE) {
2120 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2121 further_blank_line = true;
2124 if (pagebreak_bottom) {
2126 further_blank_line = true;
2129 if (further_blank_line){
2134 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2135 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2140 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2145 // This one spits out the text of the paragraph
2146 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow)
2148 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2151 return SimpleTeXOneTablePar(os, texrow);
2153 bool return_value = false;
2155 LyXLayout const & style =
2156 textclasslist.Style(current_view->buffer()->params.textclass,
2158 LyXFont basefont, last_font;
2160 // Maybe we have to create a optional argument.
2161 size_type main_body;
2162 if (style.labeltype != LABEL_MANUAL)
2165 main_body = BeginningOfMainBody();
2167 if (main_body > 0) {
2169 basefont = getFont(-2); // Get label font
2171 basefont = getFont(-1); // Get layout font
2179 if (style.isCommand()) {
2182 } else if (align != LYX_ALIGN_LAYOUT) {
2185 return_value = true;
2189 // Which font is currently active?
2190 LyXFont running_font(basefont);
2191 // Do we have an open font change?
2192 bool open_font = false;
2194 texrow.start(this, 0);
2196 for (size_type i = 0; i < size(); ++i) {
2198 // First char in paragraph or after label?
2199 if (i == main_body && !IsDummy()) {
2200 if (main_body > 0) {
2202 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2205 basefont = getFont(-1); // Now use the layout font
2206 running_font = basefont;
2210 if (style.isCommand()) {
2213 } else if (align != LYX_ALIGN_LAYOUT) {
2216 return_value = true;
2220 os << "\\noindent ";
2224 case LYX_ALIGN_NONE:
2225 case LYX_ALIGN_BLOCK:
2226 case LYX_ALIGN_LAYOUT:
2227 case LYX_ALIGN_SPECIAL:
2229 case LYX_ALIGN_LEFT:
2230 if (getParLanguage()->lang != "hebrew") {
2231 os << "\\raggedright ";
2234 os << "\\raggedleft ";
2238 case LYX_ALIGN_RIGHT:
2239 if (getParLanguage()->lang != "hebrew") {
2240 os << "\\raggedleft ";
2243 os << "\\raggedright ";
2247 case LYX_ALIGN_CENTER:
2248 os << "\\centering ";
2256 // Fully instantiated font
2257 LyXFont font = getFont(i);
2258 LyXParagraph * p = 0;
2259 if (i == 0 && previous &&
2260 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2261 (p = PreviousBeforeFootnote()) != 0)
2262 last_font = p->getFont(p->size()-1);
2264 last_font = running_font;
2266 // Spaces at end of font change are simulated to be
2267 // outside font change, i.e. we write "\textXX{text} "
2268 // rather than "\textXX{text }". (Asger)
2269 if (open_font && c == ' ' && i <= size() - 2
2270 && !getFont(i+1).equalExceptLatex(running_font)
2271 && !getFont(i+1).equalExceptLatex(font)) {
2272 font = getFont(i + 1);
2274 // We end font definition before blanks
2275 if (!font.equalExceptLatex(running_font) && open_font) {
2276 column += running_font.latexWriteEndChanges(os,
2278 (i == main_body-1) ? basefont : font);
2279 running_font = basefont;
2283 // Blanks are printed before start of fontswitch
2285 // Do not print the separation of the optional argument
2286 if (i != main_body - 1) {
2287 SimpleTeXBlanks(os, texrow, i,
2288 column, font, style);
2292 // Do we need to change font?
2293 if (!font.equalExceptLatex(running_font)
2294 && i != main_body-1) {
2295 column += font.latexWriteStartChanges(os, basefont,
2297 running_font = font;
2301 if (c == LyXParagraph::META_NEWLINE) {
2302 // newlines are handled differently here than
2303 // the default in SimpleTeXSpecialChars().
2304 if (!style.newline_allowed
2305 || font.latex() == LyXFont::ON) {
2309 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2312 basefont = getFont(-1);
2313 running_font = basefont;
2314 if (font.family() ==
2315 LyXFont::TYPEWRITER_FAMILY) {
2321 texrow.start(this, i + 1);
2324 SimpleTeXSpecialChars(os, texrow,
2325 font, running_font, basefont,
2326 open_font, style, i, column, c);
2330 // If we have an open font definition, we have to close it
2332 LyXParagraph * p = 0;
2333 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2334 && (p = NextAfterFootnote()) != 0)
2335 running_font.latexWriteEndChanges(os, basefont,
2338 running_font.latexWriteEndChanges(os, basefont, basefont);
2341 // Needed if there is an optional argument but no contents.
2342 if (main_body > 0 && main_body == size()) {
2344 return_value = false;
2347 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2348 return return_value;
2352 // This one spits out the text of a table paragraph
2353 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2355 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2357 bool return_value = false;
2359 LyXLayout const & style =
2360 textclasslist.Style(current_view->buffer()->params.textclass,
2364 if (!IsDummy()) { // it is dummy if it is in a float!!!
2365 if (style.isCommand()) {
2368 } else if (align != LYX_ALIGN_LAYOUT) {
2371 return_value = true;
2374 os << "\\noindent ";
2378 case LYX_ALIGN_NONE:
2379 case LYX_ALIGN_BLOCK:
2380 case LYX_ALIGN_LAYOUT:
2381 case LYX_ALIGN_SPECIAL: break;
2382 case LYX_ALIGN_LEFT:
2383 os << "\\raggedright ";
2386 case LYX_ALIGN_RIGHT:
2387 os << "\\raggedleft ";
2390 case LYX_ALIGN_CENTER:
2391 os << "\\centering ";
2397 LyXFont basefont = getFont(-1); // Get layout font
2398 // Which font is currently active?
2399 LyXFont running_font = basefont;
2401 // Do we have an open font change?
2402 bool open_font = false;
2403 int current_cell_number = -1;
2404 int tmp = table->TexEndOfCell(os, current_cell_number);
2405 for (; tmp > 0 ; --tmp)
2408 texrow.start(this, 0);
2410 for (size_type i = 0; i < size(); ++i) {
2411 char c = GetChar(i);
2412 if (table->IsContRow(current_cell_number + 1)) {
2413 if (c == LyXParagraph::META_NEWLINE)
2414 ++current_cell_number;
2419 // Fully instantiated font
2420 LyXFont font = getFont(i);
2421 last_font = running_font;
2423 // Spaces at end of font change are simulated to be
2424 // outside font change.
2425 // i.e. we write "\textXX{text} " rather than
2426 // "\textXX{text }". (Asger)
2427 if (open_font && c == ' ' && i <= size() - 2
2428 && getFont(i + 1) != running_font
2429 && getFont(i + 1) != font) {
2430 font = getFont(i + 1);
2433 // We end font definition before blanks
2434 if (font != running_font && open_font) {
2435 column += running_font.latexWriteEndChanges(os,
2438 running_font = basefont;
2441 // Blanks are printed before start of fontswitch
2443 SimpleTeXBlanks(os, texrow, i, column, font, style);
2445 // Do we need to change font?
2446 if (font != running_font) {
2447 column += font.latexWriteStartChanges(os, basefont,
2449 running_font = font;
2452 // Do we need to turn on LaTeX mode?
2453 if (font.latex() != running_font.latex()) {
2454 if (font.latex() == LyXFont::ON
2455 && style.needprotect) {
2460 if (c == LyXParagraph::META_NEWLINE) {
2461 // special case for inside a table
2462 // different from default case in
2463 // SimpleTeXSpecialChars()
2465 column += running_font
2466 .latexWriteEndChanges(os, basefont,
2470 basefont = getFont(-1);
2471 running_font = basefont;
2472 ++current_cell_number;
2473 if (table->CellHasContRow(current_cell_number) >= 0) {
2474 TeXContTableRows(os, i + 1,
2475 current_cell_number,
2478 // if this cell follow only ContRows till end don't
2479 // put the EndOfCell because it is put after the
2481 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2482 --current_cell_number;
2485 int tmp = table->TexEndOfCell(os,
2486 current_cell_number);
2489 } else if (tmp < 0) {
2495 texrow.start(this, i + 1);
2497 SimpleTeXSpecialChars(os, texrow,
2498 font, running_font, basefont,
2499 open_font, style, i, column, c);
2503 // If we have an open font definition, we have to close it
2505 running_font.latexWriteEndChanges(os, basefont, basefont);
2507 ++current_cell_number;
2508 tmp = table->TexEndOfCell(os, current_cell_number);
2509 for (; tmp > 0; --tmp)
2511 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2512 return return_value;
2516 // This one spits out the text off ContRows in tables
2517 bool LyXParagraph::TeXContTableRows(ostream & os,
2518 LyXParagraph::size_type i,
2519 int current_cell_number,
2520 int & column, TexRow & texrow)
2522 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2528 bool return_value = false;
2529 LyXLayout const & style =
2530 textclasslist.Style(current_view->buffer()->params.textclass,
2532 LyXFont basefont = getFont(-1); // Get layout font
2534 // Which font is currently active?
2535 LyXFont running_font = basefont;
2536 // Do we have an open font change?
2537 bool open_font = false;
2539 size_type lastpos = i;
2540 int cell = table->CellHasContRow(current_cell_number);
2541 ++current_cell_number;
2543 // first find the right position
2545 for (; (i < size()) && (current_cell_number<cell); ++i) {
2547 if (c == LyXParagraph::META_NEWLINE)
2548 ++current_cell_number;
2552 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2556 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2561 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2565 // Fully instantiated font
2566 LyXFont font = getFont(i);
2567 last_font = running_font;
2569 // Spaces at end of font change are simulated to
2570 // be outside font change. i.e. we write
2571 // "\textXX{text} " rather than "\textXX{text }".
2573 if (open_font && c == ' ' && i <= size() - 2
2574 && getFont(i + 1) != running_font
2575 && getFont(i + 1) != font) {
2576 font = getFont(i + 1);
2579 // We end font definition before blanks
2580 if (font != running_font && open_font) {
2581 column += running_font.latexWriteEndChanges(os, basefont, font);
2582 running_font = basefont;
2585 // Blanks are printed before start of fontswitch
2587 SimpleTeXBlanks(os, texrow, i,
2588 column, font, style);
2590 // Do we need to change font?
2591 if (font != running_font) {
2593 font.latexWriteStartChanges(os,
2596 running_font = font;
2599 // Do we need to turn on LaTeX mode?
2600 if (font.latex() != running_font.latex()) {
2601 if (font.latex() == LyXFont::ON
2602 && style.needprotect) {
2607 SimpleTeXSpecialChars(os, texrow, font,
2608 running_font, basefont,
2609 open_font, style, i, column, c);
2611 // If we have an open font definition, we have to close it
2613 running_font.latexWriteEndChanges(os, basefont,
2617 basefont = getFont(-1);
2618 running_font = basefont;
2619 cell = table->CellHasContRow(current_cell_number);
2621 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2622 return return_value;
2626 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2628 bool retval = false;
2630 case LyXParagraph::META_HFILL:
2631 sgml_string.clear();
2634 case LyXParagraph::META_PROTECTED_SEPARATOR:
2638 case LyXParagraph::META_NEWLINE:
2642 sgml_string = "&";
2645 sgml_string = "<";
2648 sgml_string = ">";
2651 sgml_string = "$";
2654 sgml_string = "#";
2657 sgml_string = "%";
2660 sgml_string = "[";
2663 sgml_string = "]";
2666 sgml_string = "{";
2669 sgml_string = "}";
2672 sgml_string = "˜";
2675 sgml_string = """;
2678 sgml_string = "\";
2684 case '\0': // Ignore :-)
2685 sgml_string.clear();
2695 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2696 int & desc_on, int depth)
2699 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2701 LyXFont font1, font2;
2704 size_type main_body;
2705 bool emph_flag = false;
2707 LyXLayout const & style =
2708 textclasslist.Style(current_view->buffer()->params.textclass,
2711 if (style.labeltype != LABEL_MANUAL)
2714 main_body = BeginningOfMainBody();
2716 // Gets paragraph main font.
2718 font1 = style.labelfont;
2722 int char_line_count = depth;
2723 os << newlineAndDepth(depth);
2724 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2725 os << "<INFORMALTABLE>"
2726 << newlineAndDepth(++depth);
2728 int current_cell_number = -1;
2729 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2731 // Parsing main loop.
2732 for (size_type i = 0; i < size(); ++i) {
2734 if (table->IsContRow(current_cell_number+1)) {
2735 if (c == LyXParagraph::META_NEWLINE)
2736 ++current_cell_number;
2741 // Fully instantiated font
2744 // Handle <emphasis> tag.
2745 if (font1.emph() != font2.emph() && i) {
2746 if (font2.emph() == LyXFont::ON) {
2749 } else if (emph_flag) {
2750 os << "</emphasis>";
2754 if (c == LyXParagraph::META_NEWLINE) {
2755 // We have only to control for emphasis open here!
2757 os << "</emphasis>";
2760 font1 = font2 = getFont(-1);
2761 ++current_cell_number;
2762 if (table->CellHasContRow(current_cell_number) >= 0) {
2763 DocBookContTableRows(os, extra, desc_on, i + 1,
2764 current_cell_number,
2767 // if this cell follow only ContRows till end don't
2768 // put the EndOfCell because it is put after the
2770 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2771 --current_cell_number;
2774 tmp = table->DocBookEndOfCell(os,
2775 current_cell_number,
2780 } else if (c == LyXParagraph::META_INSET) {
2781 inset = GetInset(i);
2784 inset->DocBook(ost);
2785 string tmp_out = ost.str().c_str();
2788 inset->DocBook(ost);
2790 char * ctmp = ost.str();
2791 string tmp_out(ctmp);
2795 // This code needs some explanation:
2796 // Two insets are treated specially
2797 // label if it is the first element in a
2798 // command paragraph
2800 // graphics inside tables or figure floats
2802 // title (the equivalente in latex for this
2804 // and title should come first
2807 if(desc_on != 3 || i != 0) {
2808 if(tmp_out[0] == '@') {
2810 extra += frontStrip(tmp_out,
2813 os << frontStrip(tmp_out,
2818 } else if (font2.latex() == LyXFont::ON) {
2819 // "TeX"-Mode on == > SGML-Mode on.
2825 if (linuxDocConvertChar(c, sgml_string)
2826 && !style.free_spacing) {
2827 // in freespacing mode, spaces are
2828 // non-breaking characters
2833 << "</term><listitem><para>";
2845 // Needed if there is an optional argument but no contents.
2846 if (main_body > 0 && main_body == size()) {
2851 os << "</emphasis>";
2854 ++current_cell_number;
2855 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2856 // Resets description flag correctly.
2859 // <term> not closed...
2863 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2864 os << "</INFORMALTABLE>";
2866 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2871 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2873 LyXParagraph::size_type i,
2874 int current_cell_number, int &column)
2879 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2884 //string emph = "emphasis";
2885 bool emph_flag = false;
2886 int char_line_count = 0;
2888 LyXLayout const & style =
2889 textclasslist.Style(current_view->buffer()->params.textclass,
2892 size_type main_body;
2893 if (style.labeltype != LABEL_MANUAL)
2896 main_body = BeginningOfMainBody();
2898 // Gets paragraph main font.
2901 font1 = style.labelfont;
2905 size_type lastpos = i;
2906 int cell = table->CellHasContRow(current_cell_number);
2907 ++current_cell_number;
2909 // first find the right position
2911 for (; i < size() && current_cell_number < cell; ++i) {
2913 if (c == LyXParagraph::META_NEWLINE)
2914 ++current_cell_number;
2918 // I don't know how to handle this so I comment it
2919 // for the moment (Jug)
2920 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2921 // file += " \\\\\n";
2924 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2929 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2933 // Fully instantiated font
2936 // Handle <emphasis> tag.
2937 if (font1.emph() != font2.emph() && i) {
2938 if (font2.emph() == LyXFont::ON) {
2941 } else if (emph_flag) {
2942 os << "</emphasis>";
2946 if (c == LyXParagraph::META_INSET) {
2947 inset = GetInset(i);
2950 inset->DocBook(ost);
2951 string tmp_out = ost.str().c_str();
2954 inset->DocBook(ost);
2956 char * ctmp = ost.str();
2957 string tmp_out(ctmp);
2961 // This code needs some explanation:
2962 // Two insets are treated specially
2963 // label if it is the first element in a
2964 // command paragraph
2966 // graphics inside tables or figure floats
2967 // can't go on title (the equivalente in
2968 // latex for this case is caption and title
2969 // should come first
2972 if(desc_on != 3 || i != 0) {
2973 if(tmp_out[0] == '@') {
2975 extra += frontStrip(tmp_out, '@');
2977 os << frontStrip(tmp_out, '@');
2981 } else if (font2.latex() == LyXFont::ON) {
2982 // "TeX"-Mode on == > SGML-Mode on.
2988 if (linuxDocConvertChar(c, sgml_string)
2989 && !style.free_spacing) {
2990 // in freespacing mode, spaces are
2991 // non-breaking characters
2996 << "</term><listitem><para>";
3006 // we have only to control for emphasis open here!
3008 os << "</emphasis>";
3011 font1 = font2 = getFont(-1);
3012 cell = table->CellHasContRow(current_cell_number);
3014 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3018 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3019 LyXParagraph::size_type const i,
3020 int & column, LyXFont const & font,
3021 LyXLayout const & style)
3023 if (column > tex_code_break_column
3025 && GetChar(i - 1) != ' '
3027 // In LaTeX mode, we don't want to
3028 // break lines since some commands
3030 && ! (font.latex() == LyXFont::ON)
3031 // same in FreeSpacing mode
3032 && !style.free_spacing
3033 // In typewriter mode, we want to avoid
3034 // ! . ? : at the end of a line
3035 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3036 && (GetChar(i-1) == '.'
3037 || GetChar(i-1) == '?'
3038 || GetChar(i-1) == ':'
3039 || GetChar(i-1) == '!'))) {
3040 if (tex_code_break_column == 0) {
3041 // in batchmode we need LaTeX to still
3042 // see it as a space not as an extra '\n'
3048 texrow.start(this, i + 1);
3050 } else if (font.latex() == LyXFont::OFF) {
3051 if (style.free_spacing) {
3060 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3062 LyXFont & running_font,
3065 LyXLayout const & style,
3066 LyXParagraph::size_type & i,
3067 int & column, char const c)
3069 // Two major modes: LaTeX or plain
3070 // Handle here those cases common to both modes
3071 // and then split to handle the two modes separately.
3073 case LyXParagraph::META_INSET: {
3074 Inset * inset = GetInset(i);
3077 int len = os.tellp();
3078 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3079 || inset->LyxCode() == Inset::MATH_CODE
3080 || inset->LyxCode() == Inset::URL_CODE)
3081 && running_font.isRightToLeft()) {
3086 int tmp = inset->Latex(os, style.isCommand(),
3087 style.free_spacing);
3095 column += os.tellp() - len;
3104 case LyXParagraph::META_NEWLINE:
3106 column += running_font.latexWriteEndChanges(os,
3111 basefont = getFont(-1);
3112 running_font = basefont;
3115 case LyXParagraph::META_HFILL:
3121 // And now for the special cases within each mode
3122 // Are we in LaTeX mode?
3123 if (font.latex() == LyXFont::ON) {
3124 // at present we only have one option
3125 // but I'll leave it as a switch statement
3126 // so its simpler to extend. (ARRae)
3129 case LyXParagraph::META_PROTECTED_SEPARATOR:
3134 // make sure that we will not print
3135 // error generating chars to the tex
3136 // file. This test would not be needed
3137 // if it were done in the buffer
3145 // Plain mode (i.e. not LaTeX)
3148 case LyXParagraph::META_PROTECTED_SEPARATOR:
3153 os << "\\textbackslash{}";
3157 case '°': case '±': case '²': case '³':
3158 case '×': case '÷': case '¹': case 'ª':
3159 case 'º': case '¬': case 'µ':
3160 if (current_view->buffer()->params.inputenc == "latin1") {
3161 os << "\\ensuremath{"
3170 case '|': case '<': case '>':
3171 // In T1 encoding, these characters exist
3172 if (lyxrc.fontenc == "T1") {
3174 //... but we should avoid ligatures
3175 if ((c == '>' || c == '<')
3177 && GetChar(i + 1) == c){
3178 os << "\\textcompwordmark{}";
3183 // Typewriter font also has them
3184 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3188 // Otherwise, we use what LaTeX
3192 os << "\\textless{}";
3196 os << "\\textgreater{}";
3200 os << "\\textbar{}";
3206 case '-': // "--" in Typewriter mode -> "-{}-"
3208 && GetChar(i + 1) == '-'
3209 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3218 os << "\\char`\\\"{}";
3223 if (current_view->buffer()->params.inputenc == "default") {
3232 case '%': case '#': case '{':
3239 os << "\\textasciitilde{}";
3244 os << "\\textasciicircum{}";
3248 case '*': case '[': case ']':
3249 // avoid being mistaken for optional arguments
3250 os << '{' << c << '}';
3255 // Blanks are printed before font switching.
3256 // Sure? I am not! (try nice-latex)
3257 // I am sure it's correct. LyX might be smarter
3258 // in the future, but for now, nothing wrong is
3263 /* idea for labels --- begin*/
3267 && font.family() != LyXFont::TYPEWRITER_FAMILY
3268 && GetChar(i + 1) == 'y'
3269 && GetChar(i + 2) == 'X') {
3277 && font.family() != LyXFont::TYPEWRITER_FAMILY
3278 && GetChar(i + 1) == 'e'
3279 && GetChar(i + 2) == 'X') {
3284 // Check for "LaTeX2e"
3287 && font.family() != LyXFont::TYPEWRITER_FAMILY
3288 && GetChar(i + 1) == 'a'
3289 && GetChar(i + 2) == 'T'
3290 && GetChar(i + 3) == 'e'
3291 && GetChar(i + 4) == 'X'
3292 && GetChar(i + 5) == '2'
3293 && GetChar(i + 6) == 'e') {
3298 // Check for "LaTeX"
3301 && font.family() != LyXFont::TYPEWRITER_FAMILY
3302 && GetChar(i + 1) == 'a'
3303 && GetChar(i + 2) == 'T'
3304 && GetChar(i + 3) == 'e'
3305 && GetChar(i + 4) == 'X') {
3309 /* idea for labels --- end*/
3310 } else if (c != '\0') {
3321 bool LyXParagraph::RoffContTableRows(ostream & os,
3322 LyXParagraph::size_type i,
3328 LyXFont font1(LyXFont::ALL_INHERIT);
3333 string fname2 = TmpFileName(string(), "RAT2");
3335 int cell = table->CellHasContRow(actcell);
3338 // first find the right position
3340 for (; i < size() && actcell < cell; ++i) {
3342 if (c == LyXParagraph::META_NEWLINE)
3347 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3350 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3352 font2 = GetFontSettings(i);
3353 if (font1.latex() != font2.latex()) {
3354 if (font2.latex() != LyXFont::OFF)
3359 case LyXParagraph::META_INSET:
3360 if ((inset = GetInset(i))) {
3363 stringstream ss(ios::in | ios::out);
3364 inset->Latex(ss, -1);
3376 inset->Latex(ss, -1);
3389 fstream fs(fname2.c_str(),
3392 WriteAlert(_("LYX_ERROR:"),
3393 _("Cannot open temporary file:"),
3397 inset->Latex(fs, -1);
3411 case LyXParagraph::META_NEWLINE:
3413 case LyXParagraph::META_HFILL:
3416 case LyXParagraph::META_PROTECTED_SEPARATOR:
3426 lyxerr.debug() << "RoffAsciiTable: "
3427 "NULL char in structure."
3432 cell = table->CellHasContRow(actcell);
3439 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3441 TexRow & foot_texrow,
3444 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3445 LyXParagraph * par = this;
3447 while (par && par->depth == depth) {
3449 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3450 if (textclasslist.Style(current_view->buffer()->params.textclass,
3451 par->layout).isEnvironment()
3452 || par->pextra_type != PEXTRA_NONE) {
3453 par = par->TeXEnvironment(os, texrow,
3457 par = par->TeXOnePar(os, texrow,
3462 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3468 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3470 TexRow & foot_texrow,
3473 bool eindent_open = false;
3474 bool foot_this_level = false;
3475 // flags when footnotetext should be appended to file.
3476 static bool minipage_open = false;
3477 static int minipage_open_depth = 0;
3478 char par_sep = current_view->buffer()->params.paragraph_separation;
3480 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3482 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3484 LyXLayout const & style =
3485 textclasslist.Style(current_view->buffer()->params.textclass,
3488 if (pextra_type == PEXTRA_INDENT) {
3489 if (!pextra_width.empty()) {
3490 os << "\\begin{LyXParagraphIndent}{"
3491 << pextra_width << "}\n";
3493 //float ib = atof(pextra_widthp.c_str())/100;
3494 // string can't handle floats at present (971109)
3495 // so I'll do a conversion by hand knowing that
3496 // the limits are 0.0 to 1.0. ARRae.
3497 os << "\\begin{LyXParagraphIndent}{";
3498 switch (pextra_widthp.length()) {
3510 os << "\\columnwidth}\n";
3513 eindent_open = true;
3515 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3516 if (pextra_hfill && Previous() &&
3517 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3518 os << "\\hfill{}\n";
3521 if (par_sep == BufferParams::PARSEP_INDENT) {
3522 os << "{\\setlength\\parindent{0pt}\n";
3525 os << "\\begin{minipage}";
3526 switch(pextra_alignment) {
3527 case MINIPAGE_ALIGN_TOP:
3530 case MINIPAGE_ALIGN_MIDDLE:
3533 case MINIPAGE_ALIGN_BOTTOM:
3537 if (!pextra_width.empty()) {
3538 os << '{' << pextra_width << "}\n";
3540 //float ib = atof(par->pextra_width.c_str())/100;
3541 // string can't handle floats at present
3542 // so I'll do a conversion by hand knowing that
3543 // the limits are 0.0 to 1.0. ARRae.
3545 switch (pextra_widthp.length()) {
3557 os << "\\columnwidth}\n";
3560 if (par_sep == BufferParams::PARSEP_INDENT) {
3561 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3564 minipage_open = true;
3565 minipage_open_depth = depth;
3568 #ifdef WITH_WARNINGS
3569 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3570 //I disabled it because it breaks when lists span on several
3573 if (style.isEnvironment()){
3574 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3575 #ifdef FANCY_FOOTNOTE_CODE
3576 if (foot_count < 0) {
3577 // flag that footnote[mark][text] should be
3578 // used for any footnotes from now on
3580 foot_this_level = true;
3583 os << "\\begin{" << style.latexname() << "}{"
3584 << labelwidthstring << "}\n";
3585 } else if (style.labeltype == LABEL_BIBLIO) {
3587 os << "\\begin{" << style.latexname() << "}{"
3588 << bibitemWidthest(current_view->painter())
3590 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3591 #ifdef FANCY_FOOTNOTE_CODE
3592 if (foot_count < 0) {
3593 // flag that footnote[mark][text] should be
3594 // used for any footnotes from now on
3596 foot_this_level = true;
3599 os << "\\begin{" << style.latexname() << '}'
3600 << style.latexparam() << '\n';
3602 os << "\\begin{" << style.latexname() << '}'
3603 << style.latexparam() << '\n';
3606 LyXParagraph * par = this;
3608 par = par->TeXOnePar(os, texrow,
3609 foot, foot_texrow, foot_count);
3611 if (minipage_open && par && !style.isEnvironment() &&
3612 (par->pextra_type == PEXTRA_MINIPAGE) &&
3613 par->pextra_start_minipage) {
3614 os << "\\end{minipage}\n";
3616 if (par_sep == BufferParams::PARSEP_INDENT) {
3620 minipage_open = false;
3622 if (par && par->depth > depth) {
3623 if (textclasslist.Style(current_view->buffer()->params.textclass,
3624 par->layout).isParagraph()
3627 // How to handle this? (Lgb)
3628 //&& !suffixIs(os, "\n\n")
3630 // There should be at least one '\n' already
3631 // but we need there to be two for Standard
3632 // paragraphs that are depth-increment'ed to be
3633 // output correctly. However, tables can
3634 // also be paragraphs so don't adjust them.
3637 // Will it ever harm to have one '\n' too
3638 // many? i.e. that we sometimes will have
3639 // three in a row. (Lgb)
3643 par = par->TeXDeeper(os, texrow,
3644 foot, foot_texrow, foot_count);
3646 if (par && par->layout == layout && par->depth == depth &&
3647 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3648 if (par->pextra_hfill && par->Previous() &&
3649 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3650 os << "\\hfill{}\n";
3653 if (par_sep == BufferParams::PARSEP_INDENT) {
3654 os << "{\\setlength\\parindent{0pt}\n";
3657 os << "\\begin{minipage}";
3658 switch(par->pextra_alignment) {
3659 case MINIPAGE_ALIGN_TOP:
3662 case MINIPAGE_ALIGN_MIDDLE:
3665 case MINIPAGE_ALIGN_BOTTOM:
3669 if (!par->pextra_width.empty()) {
3670 os << '{' << par->pextra_width << "}\n";
3672 //float ib = atof(par->pextra_widthp.c_str())/100;
3673 // string can't handle floats at present
3674 // so I'll do a conversion by hand knowing that
3675 // the limits are 0.0 to 1.0. ARRae.
3677 switch (par->pextra_widthp.length()) {
3682 os << "0." << par->pextra_widthp;
3685 os << "0.0" << par->pextra_widthp;
3687 os << "\\columnwidth}\n";
3690 if (par_sep == BufferParams::PARSEP_INDENT) {
3691 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3694 minipage_open = true;
3695 minipage_open_depth = par->depth;
3698 && par->layout == layout
3699 && par->depth == depth
3700 && par->pextra_type == pextra_type);
3702 if (style.isEnvironment()) {
3703 os << "\\end{" << style.latexname() << '}';
3704 // maybe this should go after the minipage closes?
3705 if (foot_this_level) {
3706 if (foot_count >= 1) {
3707 if (foot_count > 1) {
3708 os << "\\addtocounter{footnote}{-"
3713 texrow += foot_texrow;
3715 foot_texrow.reset();
3720 if (minipage_open && (minipage_open_depth == depth) &&
3721 (!par || par->pextra_start_minipage ||
3722 par->pextra_type != PEXTRA_MINIPAGE)) {
3723 os << "\\end{minipage}\n";
3725 if (par_sep == BufferParams::PARSEP_INDENT) {
3729 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3730 os << "\\medskip\n\n";
3734 minipage_open = false;
3737 os << "\\end{LyXParagraphIndent}\n";
3740 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3741 && par->pextra_hfill)) {
3745 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3746 return par; // ale970302
3750 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3751 ostream & foot, TexRow & foot_texrow,
3753 LyXDirection parent_direction)
3755 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3756 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3757 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3758 "No footnote!" << endl;
3760 LyXParagraph * par = this;
3761 LyXLayout const & style =
3762 textclasslist.Style(current_view->buffer()->params.textclass,
3763 previous->GetLayout());
3765 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3766 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3767 "Float other than footnote in command"
3768 " with moving argument is illegal" << endl;
3771 if (footnotekind != LyXParagraph::FOOTNOTE
3772 && footnotekind != LyXParagraph::MARGIN
3775 // How to solve this?
3776 //&& !suffixIs(file, '\n')
3778 // we need to ensure that real floats like tables and figures
3779 // have their \begin{} on a new line otherwise we can get
3780 // incorrect results when using the endfloat.sty package
3781 // especially if two floats follow one another. ARRae 981022
3782 // NOTE: if the file is length 0 it must have just been
3783 // written out so we assume it ended with a '\n'
3785 // As far as I can see there is never any harm in writing
3786 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3791 bool need_closing = false;
3792 LyXDirection direction = getParDirection();
3793 if (direction != parent_direction) {
3794 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3798 need_closing = true;
3801 BufferParams * params = ¤t_view->buffer()->params;
3802 bool footer_in_body = true;
3803 switch (footnotekind) {
3804 case LyXParagraph::FOOTNOTE:
3805 if (style.intitle) {
3806 os << "\\thanks{\n";
3807 footer_in_body = false;
3809 if (foot_count == -1) {
3810 // we're at depth 0 so we can use:
3811 os << "\\footnote{%\n";
3812 footer_in_body = false;
3814 os << "\\footnotemark{}%\n";
3816 // we only need this when there are
3817 // multiple footnotes
3818 os << "\\stepcounter{footnote}";
3820 os << "\\footnotetext{%\n";
3821 foot_texrow.start(this, 0);
3822 foot_texrow.newline();
3827 case LyXParagraph::MARGIN:
3828 os << "\\marginpar{\n";
3830 case LyXParagraph::FIG:
3831 if (pextra_type == PEXTRA_FLOATFLT
3832 && (!pextra_width.empty()
3833 || !pextra_widthp.empty())) {
3834 if (!pextra_width.empty())
3835 os << "\\begin{floatingfigure}{"
3836 << pextra_width << "}\n";
3838 os << "\\begin{floatingfigure}{"
3839 << atoi(pextra_widthp.c_str())/100.0
3840 << "\\textwidth}\n";
3842 os << "\\begin{figure}";
3843 if (!params->float_placement.empty()) {
3844 os << '[' << params->float_placement << "]\n";
3850 case LyXParagraph::TAB:
3851 os << "\\begin{table}";
3852 if (!params->float_placement.empty()) {
3853 os << '[' << params->float_placement << "]\n";
3858 case LyXParagraph::WIDE_FIG:
3859 os << "\\begin{figure*}";
3860 if (!params->float_placement.empty()) {
3861 os << '[' << params->float_placement << "]\n";
3866 case LyXParagraph::WIDE_TAB:
3867 os << "\\begin{table*}";
3868 if (!params->float_placement.empty()) {
3869 os << '[' << params->float_placement << "]\n";
3874 case LyXParagraph::ALGORITHM:
3875 os << "\\begin{algorithm}\n";
3880 if (footnotekind != LyXParagraph::FOOTNOTE
3881 || !footer_in_body) {
3882 // Process text for all floats except footnotes in body
3884 LyXLayout const & style =
3886 .Style(current_view->buffer()->params
3890 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3892 if (style.isEnvironment()
3893 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3894 // Allows the use of minipages within float
3895 // environments. Shouldn't be circular because
3896 // we don't support footnotes inside
3897 // floats (yet). ARRae
3898 par = par->TeXEnvironment(os, texrow,
3902 par = par->TeXOnePar(os, texrow,
3907 if (par && !par->IsDummy() && par->depth > depth) {
3908 par = par->TeXDeeper(os, texrow,
3912 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3914 // process footnotes > depth 0 or in environments separately
3915 // NOTE: Currently don't support footnotes within footnotes
3916 // even though that is possible using the \footnotemark
3918 ostringstream dummy;
3922 TexRow dummy_texrow;
3923 int dummy_count = 0;
3925 LyXLayout const & style =
3927 .Style(current_view->buffer()->params
3931 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3933 if (style.isEnvironment()
3934 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3935 // Allows the use of minipages within float
3936 // environments. Shouldn't be circular because
3937 // we don't support footnotes inside
3938 // floats (yet). ARRae
3939 par = par->TeXEnvironment(foot, foot_texrow,
3940 dummy, dummy_texrow,
3943 par = par->TeXOnePar(foot, foot_texrow,
3944 dummy, dummy_texrow,
3948 if (par && !par->IsDummy() && par->depth > depth) {
3949 par = par->TeXDeeper(foot, foot_texrow,
3950 dummy, dummy_texrow,
3954 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3956 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3957 "Footnote in a Footnote -- not supported"
3960 #ifndef HAVE_OSTREAM
3961 delete [] dummy.str();
3965 switch (footnotekind) {
3966 case LyXParagraph::FOOTNOTE:
3967 if (footer_in_body) {
3968 // This helps tell which of the multiple
3969 // footnotetexts an error was in.
3971 foot_texrow.newline();
3976 case LyXParagraph::MARGIN:
3979 case LyXParagraph::FIG:
3980 if (pextra_type == PEXTRA_FLOATFLT
3981 && (!pextra_width.empty()
3982 || !pextra_widthp.empty()))
3983 os << "\\end{floatingfigure}";
3985 os << "\\end{figure}";
3987 case LyXParagraph::TAB:
3988 os << "\\end{table}";
3990 case LyXParagraph::WIDE_FIG:
3991 os << "\\end{figure*}";
3993 case LyXParagraph::WIDE_TAB:
3994 os << "\\end{table*}";
3996 case LyXParagraph::ALGORITHM:
3997 os << "\\end{algorithm}";
4004 if (footnotekind != LyXParagraph::FOOTNOTE
4005 && footnotekind != LyXParagraph::MARGIN) {
4006 // we need to ensure that real floats like tables and figures
4007 // have their \end{} on a line of their own otherwise we can
4008 // get incorrect results when using the endfloat.sty package.
4013 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4018 void LyXParagraph::SetPExtraType(int type, char const * width,
4019 char const * widthp)
4022 pextra_width = width;
4023 pextra_widthp = widthp;
4025 if (textclasslist.Style(current_view->buffer()->params.textclass,
4026 layout).isEnvironment()) {
4031 while (par && (par->layout == layout)
4032 && (par->depth == depth)) {
4034 par = par->Previous();
4036 par = par->FirstPhysicalPar();
4037 while (par && par->depth > depth) {
4038 par = par->Previous();
4040 par = par->FirstPhysicalPar();
4044 while (par && (par->layout == layout)
4045 && (par->depth == depth)) {
4046 par->pextra_type = type;
4047 par->pextra_width = width;
4048 par->pextra_widthp = widthp;
4049 par = par->NextAfterFootnote();
4050 if (par && (par->depth > depth))
4051 par->SetPExtraType(type, width, widthp);
4052 while (par && ((par->depth > depth) || par->IsDummy()))
4053 par = par->NextAfterFootnote();
4059 void LyXParagraph::UnsetPExtraType()
4061 if (pextra_type == PEXTRA_NONE)
4064 pextra_type = PEXTRA_NONE;
4065 pextra_width.clear();
4066 pextra_widthp.clear();
4068 if (textclasslist.Style(current_view->buffer()->params.textclass,
4069 layout).isEnvironment()) {
4074 while (par && (par->layout == layout)
4075 && (par->depth == depth)) {
4077 par = par->Previous();
4079 par = par->FirstPhysicalPar();
4080 while (par && par->depth > depth) {
4081 par = par->Previous();
4083 par = par->FirstPhysicalPar();
4087 while (par && (par->layout == layout)
4088 && (par->depth == depth)) {
4089 par->pextra_type = PEXTRA_NONE;
4090 par->pextra_width.clear();
4091 par->pextra_widthp.clear();
4092 par = par->NextAfterFootnote();
4093 if (par && (par->depth > depth))
4094 par->UnsetPExtraType();
4095 while (par && ((par->depth > depth) || par->IsDummy()))
4096 par = par->NextAfterFootnote();
4102 bool LyXParagraph::IsHfill(size_type pos) const
4104 return IsHfillChar(GetChar(pos));
4108 bool LyXParagraph::IsInset(size_type pos) const
4110 return IsInsetChar(GetChar(pos));
4114 bool LyXParagraph::IsFloat(size_type pos) const
4116 return IsFloatChar(GetChar(pos));
4120 bool LyXParagraph::IsNewline(size_type pos) const
4122 return pos >= 0 && IsNewlineChar(GetChar(pos));
4126 bool LyXParagraph::IsSeparator(size_type pos) const
4128 return IsSeparatorChar(GetChar(pos));
4132 bool LyXParagraph::IsLineSeparator(size_type pos) const
4134 return IsLineSeparatorChar(GetChar(pos));
4138 bool LyXParagraph::IsKomma(size_type pos) const
4140 return IsKommaChar(GetChar(pos));
4144 /// Used by the spellchecker
4145 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4147 unsigned char c = GetChar(pos);
4148 if (IsLetterChar(c))
4150 // '\0' is not a letter, allthough every string contains "" (below)
4153 // We want to pass the ' and escape chars to ispell
4154 string extra = lyxrc.isp_esc_chars + '\'';
4158 return contains(extra, ch);
4162 bool LyXParagraph::IsWord(size_type pos ) const
4164 return IsWordChar(GetChar(pos)) ;
4167 Language const * LyXParagraph::getParLanguage() const
4169 if (!table && size() > 0)
4170 return FirstPhysicalPar()->GetFirstFontSettings().language();
4172 return previous->getParLanguage();
4174 return current_view->buffer()->params.language_info;
4177 Language const * LyXParagraph::getLetterLanguage(size_type pos) const
4179 return GetFontSettings(pos).language();
4182 LyXDirection LyXParagraph::getParDirection() const
4184 if (!lyxrc.rtl_support || table)
4185 return LYX_DIR_LEFT_TO_RIGHT;
4186 else if (getParLanguage()->RightToLeft)
4187 return LYX_DIR_RIGHT_TO_LEFT;
4189 return LYX_DIR_LEFT_TO_RIGHT;
4193 LyXParagraph::getLetterDirection(LyXParagraph::size_type pos) const
4195 if (!lyxrc.rtl_support)
4196 return LYX_DIR_LEFT_TO_RIGHT;
4197 else if (table && IsNewline(pos))
4198 return LYX_DIR_LEFT_TO_RIGHT;
4200 bool is_rtl = GetFontSettings(pos).isVisibleRightToLeft();
4201 if (IsLineSeparator(pos) && 0 < pos && pos < Last() - 1
4202 && !IsLineSeparator(pos + 1)
4203 && !(table && IsNewline(pos + 1))
4204 && ( GetFontSettings(pos - 1).isVisibleRightToLeft() != is_rtl
4205 || GetFontSettings(pos + 1).isVisibleRightToLeft() != is_rtl))
4206 return getParDirection();
4208 return (is_rtl) ? LYX_DIR_RIGHT_TO_LEFT
4209 : LYX_DIR_LEFT_TO_RIGHT;