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*/
82 bibkey = 0; // ale970302
87 // This konstruktor inserts the new paragraph in a list.
88 LyXParagraph::LyXParagraph(LyXParagraph * par)
91 par->text.resize(par->text.size());
93 for (int i = 0; i < 10; ++i) setCounter(i, 0);
97 // double linked list begin
100 next->previous = this;
102 previous->next = this;
104 footnoteflag = LyXParagraph::NO_FOOTNOTE;
105 footnotekind = LyXParagraph::FOOTNOTE;
107 /* table stuff -- begin*/
109 /* table stuff -- end*/
111 id_ = paragraph_id++;
113 bibkey = 0; // ale970302
119 void LyXParagraph::writeFile(ostream & os, BufferParams const & params,
120 char footflag, char dth) const
122 LyXFont font1, font2;
127 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
129 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
131 // The beginning or the end of a footnote environment?
132 if (footflag != footnoteflag) {
133 footflag = footnoteflag;
135 os << "\n\\begin_float "
136 << string_footnotekinds[footnotekind]
139 os << "\n\\end_float ";
143 // The beginning or end of a deeper (i.e. nested) area?
146 while (depth > dth) {
147 os << "\n\\begin_deeper ";
151 while (depth < dth) {
152 os << "\n\\end_deeper ";
158 // First write the layout
160 << textclasslist.NameOfLayout(params.textclass, layout)
163 // Maybe some vertical spaces.
164 if (added_space_top.kind() != VSpace::NONE)
165 os << "\\added_space_top "
166 << added_space_top.asLyXCommand() << " ";
167 if (added_space_bottom.kind() != VSpace::NONE)
168 os << "\\added_space_bottom "
169 << added_space_bottom.asLyXCommand() << " ";
171 // The labelwidth string used in lists.
172 if (!labelwidthstring.empty())
173 os << "\\labelwidthstring "
174 << labelwidthstring << '\n';
176 // Lines above or below?
180 os << "\\line_bottom ";
182 // Pagebreaks above or below?
184 os << "\\pagebreak_top ";
185 if (pagebreak_bottom)
186 os << "\\pagebreak_bottom ";
188 // Start of appendix?
189 if (start_of_appendix)
190 os << "\\start_of_appendix ";
197 if (align != LYX_ALIGN_LAYOUT) {
199 case LYX_ALIGN_LEFT: h = 1; break;
200 case LYX_ALIGN_RIGHT: h = 2; break;
201 case LYX_ALIGN_CENTER: h = 3; break;
202 default: h = 0; break;
204 os << "\\align " << string_align[h] << " ";
206 if (pextra_type != PEXTRA_NONE) {
207 os << "\\pextra_type " << pextra_type;
208 if (pextra_type == PEXTRA_MINIPAGE) {
209 os << " \\pextra_alignment "
212 os << " \\pextra_hfill "
214 if (pextra_start_minipage)
215 os << " \\pextra_start_minipage "
216 << pextra_start_minipage;
218 if (!pextra_width.empty()) {
219 os << " \\pextra_width "
220 << VSpace(pextra_width).asLyXCommand();
221 } else if (!pextra_widthp.empty()) {
222 os << " \\pextra_widthp "
228 // Dummy layout. This means that a footnote ended.
229 os << "\n\\end_float ";
230 footflag = LyXParagraph::NO_FOOTNOTE;
233 // It might be a table.
235 os << "\\LyXTable\n";
243 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
246 for (size_type i = 0; i < size(); ++i) {
252 // Write font changes
253 font2 = GetFontSettings(i);
254 if (font2 != font1) {
255 font2.lyxWriteChanges(font1, os);
264 Inset const * inset = GetInset(i);
266 if (inset->DirectWrite()) {
267 // international char, let it write
268 // code directly so it's shorter in
272 os << "\n\\begin_inset ";
274 os << "\n\\end_inset \n\n";
280 os << "\n\\newline \n";
284 os << "\n\\hfill \n";
288 case META_PROTECTED_SEPARATOR:
289 os << "\n\\protected_separator \n";
294 os << "\n\\backslash \n";
298 if (i + 1 < size() && GetChar(i + 1) == ' ') {
305 if ((column > 70 && c == ' ')
310 // this check is to amend a bug. LyX sometimes
311 // inserts '\0' this could cause problems.
315 lyxerr << "ERROR (LyXParagraph::writeFile):"
316 " NULL char in structure." << endl;
322 // now write the next paragraph
324 next->writeFile(os, params, footflag, dth);
328 void LyXParagraph::validate(LaTeXFeatures & features) const
330 // this will be useful later
331 LyXLayout const & layout =
332 textclasslist.Style(current_view->buffer()->params.textclass,
336 if (line_top || line_bottom)
337 features.lyxline = true;
340 features.layout[GetLayout()] = true;
343 Language const * doc_language = current_view->buffer()->params.language_info;
344 for (FontList::const_iterator cit = fontlist.begin();
345 cit != fontlist.end(); ++cit) {
346 if ((*cit).font.noun() == LyXFont::ON) {
347 lyxerr[Debug::LATEX] << "font.noun: "
348 << (*cit).font.noun()
350 features.noun = true;
351 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
352 << (*cit).font.stateText()
355 switch ((*cit).font.color()) {
357 case LColor::inherit:
361 features.color = true;
362 lyxerr[Debug::LATEX] << "Color enabled. Font: "
363 << (*cit).font.stateText()
366 Language const * language = (*cit).font.language();
367 if (language != doc_language && language != default_language) {
368 features.UsedLanguages.insert(language);
369 lyxerr[Debug::LATEX] << "Found language "
370 << language->lang << endl;
375 for (InsetList::const_iterator cit = insetlist.begin();
376 cit != insetlist.end(); ++cit) {
378 (*cit).inset->Validate(features);
381 if (table && table->IsLongTable())
382 features.longtable = true;
383 if (pextra_type == PEXTRA_INDENT)
384 features.LyXParagraphIndent = true;
385 if (pextra_type == PEXTRA_FLOATFLT)
386 features.floatflt = true;
387 if (layout.needprotect
388 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
389 features.NeedLyXFootnoteCode = true;
390 if ((current_view->buffer()->params.paragraph_separation == BufferParams::PARSEP_INDENT) &&
391 (pextra_type == LyXParagraph::PEXTRA_MINIPAGE))
392 features.NeedLyXMinipageIndent = true;
393 if (table && table->NeedRotating())
394 features.rotating = true;
395 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
396 features.algorithm = true;
400 // First few functions needed for cut and paste and paragraph breaking.
401 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
403 minibuffer_char = GetChar(pos);
404 minibuffer_font = GetFontSettings(pos);
405 minibuffer_inset = 0;
406 if (minibuffer_char == LyXParagraph::META_INSET) {
408 minibuffer_inset = GetInset(pos)->Clone();
410 minibuffer_inset = 0;
411 minibuffer_char = ' ';
412 // This reflects what GetInset() does (ARRae)
418 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
420 minibuffer_char = GetChar(pos);
421 minibuffer_font = GetFontSettings(pos);
422 minibuffer_inset = 0;
423 if (minibuffer_char == LyXParagraph::META_INSET) {
425 minibuffer_inset = GetInset(pos);
426 // This is a little hack since I want exactly
427 // the inset, not just a clone. Otherwise
428 // the inset would be deleted when calling Erase(pos)
430 InsetList::iterator it = lower_bound(insetlist.begin(),
433 if (it != insetlist.end() && (*it).pos == pos)
436 minibuffer_inset = 0;
437 minibuffer_char = ' ';
438 // This reflects what GetInset() does (ARRae)
443 // Erase(pos); now the caller is responsible for that.
447 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
449 if ((minibuffer_char == LyXParagraph::META_INSET) &&
450 !InsertInsetAllowed(minibuffer_inset))
452 InsertChar(pos, minibuffer_char);
453 SetFont(pos, minibuffer_font);
454 if (minibuffer_char == LyXParagraph::META_INSET)
455 InsertInset(pos, minibuffer_inset);
463 void LyXParagraph::Clear()
468 pagebreak_top = false;
469 pagebreak_bottom = false;
471 added_space_top = VSpace(VSpace::NONE);
472 added_space_bottom = VSpace(VSpace::NONE);
474 align = LYX_ALIGN_LAYOUT;
478 pextra_type = PEXTRA_NONE;
479 pextra_width.clear();
480 pextra_widthp.clear();
481 pextra_alignment = MINIPAGE_ALIGN_TOP;
482 pextra_hfill = false;
483 pextra_start_minipage = false;
486 labelwidthstring.clear();
490 start_of_appendix = false;
494 // the destructor removes the new paragraph from the list
495 LyXParagraph::~LyXParagraph()
498 previous->next = next;
500 next->previous = previous;
502 for (InsetList::iterator it = insetlist.begin();
503 it != insetlist.end(); ++it) {
507 /* table stuff -- begin*/
509 /* table stuff -- end*/
516 void LyXParagraph::Erase(LyXParagraph::size_type pos)
518 // > because last is the next unused position, and you can
519 // use it if you want
521 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
522 NextAfterFootnote()->Erase(pos - text.size() - 1);
524 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
525 "position does not exist." << endl;
528 if (pos < size()) { // last is free for insertation, but should be empty
529 // if it is an inset, delete the inset entry
530 if (text[pos] == LyXParagraph::META_INSET) {
532 InsetList::iterator it = lower_bound(insetlist.begin(),
535 if (it != insetlist.end() && (*it).pos == pos) {
540 text.erase(text.begin() + pos);
541 // Erase entries in the tables.
542 for (FontList::iterator it = fontlist.begin();
543 it != fontlist.end(); ++it) {
544 if (pos >= (*it).pos && pos <= (*it).pos_end) {
545 if ((*it).pos == (*it).pos_end) {
546 // If it is a multi-character font
547 // entry, we just make it smaller
548 // (see update below), otherwise we
555 // Update all other entries.
556 for (FontList::iterator it = fontlist.begin();
557 it != fontlist.end(); ++it) {
560 if ((*it).pos_end >= pos)
564 // Update the inset table.
565 for (InsetList::iterator it = upper_bound(insetlist.begin(),
568 it != insetlist.end(); ++it)
571 lyxerr << "ERROR (LyXParagraph::Erase): "
572 "can't erase non-existant char." << endl;
577 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
579 // > because last is the next unused position, and you can
580 // use it if you want
583 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
584 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
587 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
588 "position does not exist." << endl;
591 text.insert(text.begin() + pos, c);
592 // Update the font table.
593 for (FontList::iterator it = fontlist.begin();
594 it != fontlist.end(); ++it) {
595 if ((*it).pos >= pos)
597 if ((*it).pos_end >= pos)
601 // Update the inset table.
602 for (InsetList::iterator it = lower_bound(insetlist.begin(),
605 it != insetlist.end(); ++it)
610 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
613 // > because last is the next unused position, and you can
614 // use it if you want
617 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
619 ->InsertInset(pos - text.size() - 1, inset);
621 lyxerr << "ERROR (LyXParagraph::InsertInset): "
622 "position does not exist: " << pos << endl;
625 if (text[pos] != LyXParagraph::META_INSET) {
626 lyxerr << "ERROR (LyXParagraph::InsertInset): "
627 "there is no LyXParagraph::META_INSET" << endl;
632 // Add a new entry in the inset table.
633 InsetList::iterator it = lower_bound(insetlist.begin(),
636 if (it != insetlist.end() && (*it).pos == pos)
637 lyxerr << "ERROR (LyXParagraph::InsertInset): "
638 "there is an inset in position: " << pos << endl;
640 insetlist.insert(it,InsetTable(pos,inset));
645 bool LyXParagraph::InsertInsetAllowed(Inset *inset)
648 printf("CODE:%d\n",inset->LyxCode());
649 return inset_owner->InsertInsetAllowed(inset);
654 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
658 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
659 return NextAfterFootnote()
660 ->GetInset(pos - text.size() - 1);
662 lyxerr << "ERROR (LyXParagraph::GetInset): "
663 "position does not exist: "
669 InsetList::iterator it = lower_bound(insetlist.begin(),
672 if (it != insetlist.end() && (*it).pos == pos)
675 lyxerr << "ERROR (LyXParagraph::GetInset): "
676 "Inset does not exist: " << pos << endl;
677 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
678 // Did this commenting out introduce a bug? So far I have not
679 // see any, please enlighten me. (Lgb)
680 // My guess is that since the inset does not exist, we might
681 // as well replace it with a space to prevent craches. (Asger)
686 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
690 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
691 return NextAfterFootnote()
692 ->GetInset(pos - text.size() - 1);
694 lyxerr << "ERROR (LyXParagraph::GetInset): "
695 "position does not exist: "
701 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
704 if (cit != insetlist.end() && (*cit).pos == pos)
707 lyxerr << "ERROR (LyXParagraph::GetInset): "
708 "Inset does not exist: " << pos << endl;
709 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
710 // Did this commenting out introduce a bug? So far I have not
711 // see any, please enlighten me. (Lgb)
712 // My guess is that since the inset does not exist, we might
713 // as well replace it with a space to prevent craches. (Asger)
718 // Gets uninstantiated font setting at position.
719 // Optimized after profiling. (Asger)
720 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
723 #ifdef SORTED_FONT_LIST
724 for (FontList::const_iterator cit = fontlist.begin();
725 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
726 if (pos >= (*cit).pos)
729 for (FontList::const_iterator cit = fontlist.begin();
730 cit != fontlist.end(); ++cit)
731 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
735 // > because last is the next unused position, and you can
736 // use it if you want
737 else if (pos > size()) {
739 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
740 return NextAfterFootnote()
741 ->GetFontSettings(pos - text.size() - 1);
743 // Why is it an error to ask for the font of a
744 // position that does not exist? Would it be
745 // enough for this to be enabled on debug?
746 // We want strict error checking, but it's ok to only
747 // have it when debugging. (Asger)
748 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
749 "position does not exist. "
750 << pos << " (" << static_cast<int>(pos)
753 } else if (pos > 0) {
754 return GetFontSettings(pos - 1);
755 } else // pos = size() = 0
756 return LyXFont(LyXFont::ALL_INHERIT,getParLanguage());
758 return LyXFont(LyXFont::ALL_INHERIT);
761 // Gets uninstantiated font setting at position 0
762 LyXFont LyXParagraph::GetFirstFontSettings() const
765 #ifdef SORTED_FONT_LIST
766 if (!fontlist.empty() && fontlist.front().pos == 0)
767 return fontlist.front().font;
769 for (FontList::const_iterator cit = fontlist.begin();
770 cit != fontlist.end(); ++cit)
771 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
774 } else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
775 return NextAfterFootnote()->GetFirstFontSettings();
776 return LyXFont(LyXFont::ALL_INHERIT);
779 // Gets the fully instantiated font at a given position in a paragraph
780 // This is basically the same function as LyXText::GetFont() in text2.C.
781 // The difference is that this one is used for generating the LaTeX file,
782 // and thus cosmetic "improvements" are disallowed: This has to deliver
783 // the true picture of the buffer. (Asger)
784 // If position is -1, we get the layout font of the paragraph.
785 // If position is -2, we get the font of the manual label of the paragraph.
786 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
789 LyXLayout const & layout =
790 textclasslist.Style(current_view->buffer()->params.textclass,
792 LyXParagraph::size_type main_body = 0;
793 if (layout.labeltype == LABEL_MANUAL)
794 main_body = BeginningOfMainBody();
799 layoutfont = layout.labelfont;
801 layoutfont = layout.font;
802 tmpfont = GetFontSettings(pos);
803 tmpfont.realize(layoutfont);
805 // process layoutfont for pos == -1 and labelfont for pos < -1
807 tmpfont = layout.font;
809 tmpfont = layout.labelfont;
810 tmpfont.setLanguage(getParLanguage());
813 // check for environment font information
814 char par_depth = GetDepth();
815 LyXParagraph const * par = this;
816 while (par && par_depth && !tmpfont.resolved()) {
817 par = par->DepthHook(par_depth - 1);
819 tmpfont.realize(textclasslist.
820 Style(current_view->buffer()->params.textclass,
821 par->GetLayout()).font);
822 par_depth = par->GetDepth();
826 tmpfont.realize(textclasslist
827 .TextClass(current_view->buffer()->params.textclass)
833 /// Returns the height of the highest font in range
835 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
836 LyXParagraph::size_type endpos) const
838 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
839 for (FontList::const_iterator cit = fontlist.begin();
840 cit != fontlist.end(); ++cit) {
841 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
842 LyXFont::FONT_SIZE size = (*cit).font.size();
843 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
851 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
858 // > because last is the next unused position, and you can
859 // use it if you want
860 else if (pos > size()) {
861 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
862 return NextAfterFootnote()
863 ->GetChar(pos - text.size() - 1);
865 lyxerr << "ERROR (LyXParagraph::GetChar): "
866 "position does not exist."
867 << pos << " (" << static_cast<int>(pos)
869 // Assert(false); // This triggers sometimes...
874 // We should have a footnote environment.
875 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
876 // Notice that LyX does request the
877 // last char from time to time. (Asger)
878 //lyxerr << "ERROR (LyXParagraph::GetChar): "
879 // "expected footnote." << endl;
882 switch (next->footnotekind) {
883 case LyXParagraph::FOOTNOTE:
884 return LyXParagraph::META_FOOTNOTE;
885 case LyXParagraph::MARGIN:
886 return LyXParagraph::META_MARGIN;
887 case LyXParagraph::FIG:
888 case LyXParagraph::WIDE_FIG:
889 return LyXParagraph::META_FIG;
890 case LyXParagraph::TAB:
891 case LyXParagraph::WIDE_TAB:
892 return LyXParagraph::META_TAB;
893 case LyXParagraph::ALGORITHM:
894 return LyXParagraph::META_ALGORITHM;
896 return '\0'; // to shut up gcc
901 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
908 // > because last is the next unused position, and you can
909 // use it if you want
910 else if (pos > size()) {
911 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
912 return NextAfterFootnote()
913 ->GetChar(pos - text.size() - 1);
915 lyxerr << "ERROR (LyXParagraph::GetChar const): "
916 "position does not exist."
917 << pos << " (" << static_cast<int>(pos)
923 // We should have a footnote environment.
924 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
925 // Notice that LyX does request the
926 // last char from time to time. (Asger)
927 //lyxerr << "ERROR (LyXParagraph::GetChar): "
928 // "expected footnote." << endl;
931 switch (next->footnotekind) {
932 case LyXParagraph::FOOTNOTE:
933 return LyXParagraph::META_FOOTNOTE;
934 case LyXParagraph::MARGIN:
935 return LyXParagraph::META_MARGIN;
936 case LyXParagraph::FIG:
937 case LyXParagraph::WIDE_FIG:
938 return LyXParagraph::META_FIG;
939 case LyXParagraph::TAB:
940 case LyXParagraph::WIDE_TAB:
941 return LyXParagraph::META_TAB;
942 case LyXParagraph::ALGORITHM:
943 return LyXParagraph::META_ALGORITHM;
945 return '\0'; // to shut up gcc
950 // return an string of the current word, and the end of the word in lastpos.
951 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
955 // the current word is defined as starting at the first character
956 // from the immediate left of lastpospos which meets the definition
957 // of IsLetter(), continuing to the last character to the right
958 // of this meeting IsLetter.
964 // move back until we have a letter
966 //there's no real reason to have firstpos & lastpos as
967 //separate variables as this is written, but maybe someon
968 // will want to return firstpos in the future.
970 //since someone might have typed a punctuation first
971 int firstpos = lastpos;
973 while ((firstpos >= 0) && !IsLetter(firstpos))
976 // now find the beginning by looking for a nonletter
978 while ((firstpos>= 0) && IsLetter(firstpos))
981 // the above is now pointing to the preceeding non-letter
985 // so copy characters into theword until we get a nonletter
986 // note that this can easily exceed lastpos, wich means
987 // that if used in the middle of a word, the whole word
990 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
997 LyXParagraph::size_type LyXParagraph::Last() const
999 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1000 return text.size() + NextAfterFootnote()->Last() + 1;
1001 // the 1 is the symbol
1008 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1010 // > because last is the next unused position, and you can
1011 // use it if you want
1014 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1015 return NextAfterFootnote()
1016 ->ParFromPos(pos - text.size() - 1);
1018 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1019 "position does not exist." << endl;
1026 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1028 // > because last is the next unused position, and you can
1029 // use it if you want
1032 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1033 return NextAfterFootnote()
1034 ->PositionInParFromPos(pos - text.size() - 1);
1037 "ERROR (LyXParagraph::PositionInParFromPos): "
1038 "position does not exist." << endl;
1046 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1047 LyXFont const & font)
1049 // > because last is the next unused position, and you can
1050 // use it if you want
1053 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1054 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1057 lyxerr << "ERROR (LyXParagraph::SetFont): "
1058 "position does not exist." << endl;
1062 LyXFont patternfont(LyXFont::ALL_INHERIT);
1064 // First, reduce font against layout/label font
1065 // Update: The SetCharFont() routine in text2.C already
1066 // reduces font, so we don't need to do that here. (Asger)
1067 // No need to simplify this because it will disappear
1068 // in a new kernel. (Asger)
1069 // Next search font table
1070 FontList::iterator tmp = fontlist.begin();
1071 for (; tmp != fontlist.end(); ++tmp) {
1072 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1076 if (tmp == fontlist.end()) { // !found
1077 // if we did not find a font entry, but if the font at hand
1078 // is the same as default, we just forget it
1079 if (font == patternfont) return;
1081 // ok, we did not find a font entry. But maybe there is exactly
1082 // the needed font ientry one position left
1083 FontList::iterator tmp2 = fontlist.begin();
1084 for (; tmp2 != fontlist.end(); ++tmp2) {
1085 if (pos - 1 >= (*tmp2).pos
1086 && pos - 1 <= (*tmp2).pos_end)
1089 if (tmp2 != fontlist.end()) {
1090 // ok there is one, maybe it is exactly
1092 if ((*tmp2).font == font) {
1093 // put the position under the font
1098 // Add a new entry in the
1099 // fontlist for the position
1103 ft.font = font; // or patternfont
1104 // It seems that using font instead of patternfont here
1105 // fixes all the problems. This also surfaces a "bug" in
1107 fontlist.insert(fontlist.begin(), ft);
1108 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1110 // more than one character
1111 if (pos == (*tmp).pos) {
1112 // maybe we should enlarge the left fonttable
1113 FontList::iterator tmp2 = fontlist.begin();
1114 for (; tmp2 != fontlist.end(); ++tmp2) {
1115 if (pos - 1 >= (*tmp2).pos
1116 && pos - 1 <= (*tmp2).pos_end)
1119 // Is there is one, and is it exactly
1121 if (tmp2 != fontlist.end() &&
1122 (*tmp2).font == font) {
1123 // Put the position under the font
1129 // Add a new entry in the
1130 // fontlist for the position
1133 ft.pos_end = (*tmp).pos_end;
1134 ft.font = (*tmp).font;
1135 (*tmp).pos_end = pos;
1137 fontlist.insert(fontlist.begin(), ft);
1138 } else if (pos == (*tmp).pos_end) {
1139 // Add a new entry in the
1140 // fontlist for the position
1142 ft.pos = (*tmp).pos;
1143 ft.pos_end = (*tmp).pos_end - 1;
1144 ft.font = (*tmp).font;
1145 (*tmp).pos = (*tmp).pos_end;
1147 fontlist.insert(fontlist.begin(), ft);
1149 // Add a new entry in the
1150 // fontlist for the position
1152 ft.pos = (*tmp).pos;
1153 ft.pos_end = pos - 1;
1154 ft.font = (*tmp).font;
1158 ft2.pos_end = (*tmp).pos_end;
1159 ft2.font = (*tmp).font;
1162 (*tmp).pos_end = pos;
1165 fontlist.insert(fontlist.begin(), ft);
1166 fontlist.insert(fontlist.begin(), ft2);
1174 // This function is able to hide closed footnotes.
1175 LyXParagraph * LyXParagraph::Next()
1177 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1178 LyXParagraph * tmp = next;
1180 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1182 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1183 return tmp->Next(); /* there can be more than one
1184 footnote in a logical
1187 return next; // This should never happen!
1193 LyXParagraph * LyXParagraph::NextAfterFootnote()
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 const * LyXParagraph::NextAfterFootnote() const
1211 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1212 LyXParagraph * tmp = next;
1213 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1215 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1216 return tmp; /* there can be more than one footnote
1217 in a logical paragraph */
1219 return next; // This should never happen!
1225 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1228 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1230 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1231 tmp = tmp->previous;
1232 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1233 return tmp; /* there can be more than one footnote
1234 in a logical paragraph */
1236 return previous; // This should never happen!
1242 LyXParagraph * LyXParagraph::LastPhysicalPar()
1244 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1247 LyXParagraph * tmp = this;
1249 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1250 tmp = tmp->NextAfterFootnote();
1255 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1257 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1260 LyXParagraph const * tmp = this;
1262 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1263 tmp = tmp->NextAfterFootnote();
1268 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1272 LyXParagraph * tmppar = this;
1276 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1277 tmppar = tmppar->previous;
1286 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1290 LyXParagraph const * tmppar = this;
1294 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1295 tmppar = tmppar->previous;
1304 // This function is able to hide closed footnotes.
1305 LyXParagraph * LyXParagraph::Previous()
1307 LyXParagraph * tmp = previous;
1312 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1313 tmp = tmp->previous;
1315 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1316 tmp = tmp->previous;
1317 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1318 return tmp->next->Previous();
1327 // This function is able to hide closed footnotes.
1328 LyXParagraph const * LyXParagraph::Previous() const
1330 LyXParagraph * tmp = previous;
1335 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1336 tmp = tmp->previous;
1338 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1339 tmp = tmp->previous;
1340 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1341 return tmp->next->Previous();
1350 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1353 size_type i, j, pos_end, pos_first;
1354 // create a new paragraph
1355 LyXParagraph * par = ParFromPos(pos);
1356 LyXParagraph * firstpar = FirstPhysicalPar();
1358 LyXParagraph * tmp = new LyXParagraph(par);
1360 tmp->footnoteflag = footnoteflag;
1361 tmp->footnotekind = footnotekind;
1363 // this is an idea for a more userfriendly layout handling, I will
1364 // see what the users say
1366 // layout stays the same with latex-environments
1368 tmp->SetOnlyLayout(firstpar->layout);
1369 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1372 if (Last() > pos || !Last() || flag == 2) {
1373 tmp->SetOnlyLayout(firstpar->layout);
1374 tmp->align = firstpar->align;
1375 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1377 tmp->line_bottom = firstpar->line_bottom;
1378 firstpar->line_bottom = false;
1379 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1380 firstpar->pagebreak_bottom = false;
1381 tmp->added_space_bottom = firstpar->added_space_bottom;
1382 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1384 tmp->depth = firstpar->depth;
1385 tmp->noindent = firstpar->noindent;
1387 // copy everything behind the break-position
1388 // to the new paragraph
1390 while (ParFromPos(pos_first) != par)
1393 pos_end = pos_first + par->text.size() - 1;
1394 // The constructor has already reserved 500 elements
1395 //if (pos_end > pos)
1396 // tmp->text.reserve(pos_end - pos);
1398 for (i = j = pos; i <= pos_end; ++i) {
1399 par->CutIntoMinibuffer(i - pos_first);
1400 if (tmp->InsertFromMinibuffer(j - pos))
1403 tmp->text.resize(tmp->text.size());
1404 for (i = pos_end; i >= pos; --i)
1405 par->Erase(i - pos_first);
1407 par->text.resize(par->text.size());
1410 // just an idea of me
1412 tmp->line_top = firstpar->line_top;
1413 tmp->pagebreak_top = firstpar->pagebreak_top;
1414 tmp->added_space_top = firstpar->added_space_top;
1415 tmp->bibkey = firstpar->bibkey;
1417 // layout stays the same with latex-environments
1419 firstpar->SetOnlyLayout(tmp->layout);
1420 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1421 firstpar->depth = tmp->depth;
1427 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1429 par = par->FirstPhysicalPar();
1430 footnoteflag = par->footnoteflag;
1431 footnotekind = par->footnotekind;
1433 layout = par->layout;
1434 align = par-> align;
1435 SetLabelWidthString(par->labelwidthstring);
1437 line_bottom = par->line_bottom;
1438 pagebreak_bottom = par->pagebreak_bottom;
1439 added_space_bottom = par->added_space_bottom;
1441 line_top = par->line_top;
1442 pagebreak_top = par->pagebreak_top;
1443 added_space_top = par->added_space_top;
1445 pextra_type = par->pextra_type;
1446 pextra_width = par->pextra_width;
1447 pextra_widthp = par->pextra_widthp;
1448 pextra_alignment = par->pextra_alignment;
1449 pextra_hfill = par->pextra_hfill;
1450 pextra_start_minipage = par->pextra_start_minipage;
1452 noindent = par->noindent;
1457 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1459 LyXParagraph * tmppar = this;
1462 && tmppar->previous->footnoteflag ==
1463 LyXParagraph::CLOSED_FOOTNOTE)
1464 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1465 tmppar = tmppar->previous;
1468 return this; // This should never happen!
1474 LyXParagraph * LyXParagraph::Clone() const
1476 // create a new paragraph
1477 LyXParagraph * result = new LyXParagraph;
1479 result->MakeSameLayout(this);
1481 // this is because of the dummy layout of the paragraphs that
1483 result->layout = layout;
1485 /* table stuff -- begin*/
1487 result->table = table->Clone();
1490 /* table stuff -- end*/
1492 result->inset_owner = inset_owner;
1495 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1498 // copy everything behind the break-position to the new paragraph
1500 result->text = text;
1501 result->fontlist = fontlist;
1502 result->insetlist = insetlist;
1503 for (InsetList::iterator it = result->insetlist.begin();
1504 it != result->insetlist.end(); ++it)
1505 (*it).inset = (*it).inset->Clone();
1510 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1512 par = par->FirstPhysicalPar();
1515 par->footnoteflag == footnoteflag &&
1516 par->footnotekind == footnotekind &&
1518 par->layout == layout &&
1520 par->align == align &&
1522 par->line_bottom == line_bottom &&
1523 par->pagebreak_bottom == pagebreak_bottom &&
1524 par->added_space_bottom == added_space_bottom &&
1526 par->line_top == line_top &&
1527 par->pagebreak_top == pagebreak_top &&
1528 par->added_space_top == added_space_top &&
1530 par->pextra_type == pextra_type &&
1531 par->pextra_width == pextra_width &&
1532 par->pextra_widthp == pextra_widthp &&
1533 par->pextra_alignment == pextra_alignment &&
1534 par->pextra_hfill == pextra_hfill &&
1535 par->pextra_start_minipage == pextra_start_minipage &&
1537 par->table == table && // what means: NO TABLE AT ALL
1539 par->noindent == noindent &&
1540 par->depth == depth);
1544 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1546 // create a new paragraph
1547 LyXParagraph * par = ParFromPos(pos);
1549 LyXParagraph * tmp = new LyXParagraph(par);
1551 tmp->MakeSameLayout(par);
1553 // When can pos < Last()?
1554 // I guess pos == Last() is possible.
1556 // copy everything behind the break-position to the new
1558 size_type pos_first = 0;
1559 while (ParFromPos(pos_first) != par)
1561 size_type pos_end = pos_first + par->text.size() - 1;
1562 // make sure there is enough memory for the now larger
1563 // paragraph. This is not neccessary, because
1564 // InsertFromMinibuffer will enlarge the memory (it uses
1565 // InsertChar of course). But doing it by hand
1566 // is MUCH faster! (only one time, not thousend times!!)
1567 // Not needed since the constructor aleady have
1568 // reserved 500 elements in text.
1569 //if (pos_end > pos)
1570 // tmp->text.reserve(pos_end - pos);
1573 for (i = j = pos; i <= pos_end; ++i) {
1574 par->CutIntoMinibuffer(i - pos_first);
1575 if (tmp->InsertFromMinibuffer(j - pos))
1578 tmp->text.resize(tmp->text.size());
1579 for (size_type i = pos_end; i >= pos; --i)
1580 par->Erase(i - pos_first);
1582 par->text.resize(par->text.size());
1587 // Be carefull, this does not make any check at all.
1588 void LyXParagraph::PasteParagraph()
1590 // copy the next paragraph to this one
1591 LyXParagraph * the_next = Next();
1593 LyXParagraph * firstpar = FirstPhysicalPar();
1595 // first the DTP-stuff
1596 firstpar->line_bottom = the_next->line_bottom;
1597 firstpar->added_space_bottom = the_next->added_space_bottom;
1598 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1600 size_type pos_end = the_next->text.size() - 1;
1601 size_type pos_insert = Last();
1603 // ok, now copy the paragraph
1605 for (i = j = 0; i <= pos_end; ++i) {
1606 the_next->CutIntoMinibuffer(i);
1607 if (InsertFromMinibuffer(pos_insert + j))
1611 // delete the next paragraph
1616 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1618 LyXParagraph * par = ParFromPos(pos);
1620 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1621 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1627 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1629 LyXParagraph * par = ParFromPos(pos);
1631 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1632 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1637 int LyXParagraph::GetEndLabel() const
1639 LyXParagraph const * par = this;
1640 int par_depth = GetDepth();
1642 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1644 textclasslist.Style(current_view->buffer()->params.textclass,
1645 layout).endlabeltype;
1646 if (endlabeltype != END_LABEL_NO_LABEL) {
1647 LyXParagraph const * last = this;
1648 if( footnoteflag == NO_FOOTNOTE)
1649 last = LastPhysicalPar();
1650 else if (next->footnoteflag == NO_FOOTNOTE)
1651 return endlabeltype;
1653 if (!last || !last->next)
1654 return endlabeltype;
1656 int next_depth = last->next->GetDepth();
1657 if (par_depth > next_depth ||
1658 (par_depth == next_depth && layout != last->next->GetLayout() ))
1659 return endlabeltype;
1664 par = par->DepthHook(par_depth - 1);
1666 par_depth = par->GetDepth();
1668 return END_LABEL_NO_LABEL;
1671 LyXTextClass::size_type LyXParagraph::GetLayout() const
1673 return FirstPhysicalPar()->layout;
1677 char LyXParagraph::GetDepth() const
1679 return FirstPhysicalPar()->depth;
1683 char LyXParagraph::GetAlign() const
1685 return FirstPhysicalPar()->align;
1689 string LyXParagraph::GetLabelstring() const
1691 return FirstPhysicalPar()->labelstring;
1695 int LyXParagraph::GetFirstCounter(int i) const
1697 return FirstPhysicalPar()->counter_[i];
1701 // the next two functions are for the manual labels
1702 string LyXParagraph::GetLabelWidthString() const
1704 if (!FirstPhysicalPar()->labelwidthstring.empty())
1705 return FirstPhysicalPar()->labelwidthstring;
1707 return _("Senseless with this layout!");
1711 void LyXParagraph::SetLabelWidthString(string const & s)
1713 LyXParagraph * par = FirstPhysicalPar();
1715 par->labelwidthstring = s;
1719 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1721 LyXParagraph * par = FirstPhysicalPar();
1722 LyXParagraph * ppar = 0;
1723 LyXParagraph * npar = 0;
1725 par->layout = new_layout;
1726 /* table stuff -- begin*/
1729 /* table stuff -- end*/
1730 if (par->pextra_type == PEXTRA_NONE) {
1731 if (par->Previous()) {
1732 ppar = par->Previous()->FirstPhysicalPar();
1735 && (ppar->depth > par->depth))
1736 ppar = ppar->Previous()->FirstPhysicalPar();
1739 npar = par->Next()->NextAfterFootnote();
1742 && (npar->depth > par->depth))
1743 npar = npar->Next()->NextAfterFootnote();
1745 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1747 p1 = ppar->pextra_width,
1748 p2 = ppar->pextra_widthp;
1749 ppar->SetPExtraType(ppar->pextra_type,
1750 p1.c_str(), p2.c_str());
1752 if ((par->pextra_type == PEXTRA_NONE) &&
1753 npar && (npar->pextra_type != PEXTRA_NONE)) {
1755 p1 = npar->pextra_width,
1756 p2 = npar->pextra_widthp;
1757 npar->SetPExtraType(npar->pextra_type,
1758 p1.c_str(), p2.c_str());
1764 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1767 * par = FirstPhysicalPar(),
1771 par->layout = new_layout;
1772 par->labelwidthstring.clear();
1773 par->align = LYX_ALIGN_LAYOUT;
1774 par->added_space_top = VSpace(VSpace::NONE);
1775 par->added_space_bottom = VSpace(VSpace::NONE);
1776 /* table stuff -- begin*/
1779 /* table stuff -- end*/
1780 if (par->pextra_type == PEXTRA_NONE) {
1781 if (par->Previous()) {
1782 ppar = par->Previous()->FirstPhysicalPar();
1785 && (ppar->depth > par->depth))
1786 ppar = ppar->Previous()->FirstPhysicalPar();
1789 npar = par->Next()->NextAfterFootnote();
1792 && (npar->depth > par->depth))
1793 npar = npar->Next()->NextAfterFootnote();
1795 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1797 p1 = ppar->pextra_width,
1798 p2 = ppar->pextra_widthp;
1799 ppar->SetPExtraType(ppar->pextra_type,
1800 p1.c_str(), p2.c_str());
1802 if ((par->pextra_type == PEXTRA_NONE) &&
1803 npar && (npar->pextra_type != PEXTRA_NONE)) {
1805 p1 = npar->pextra_width,
1806 p2 = npar->pextra_widthp;
1807 npar->SetPExtraType(npar->pextra_type,
1808 p1.c_str(), p2.c_str());
1814 // if the layout of a paragraph contains a manual label, the beginning of the
1815 // main body is the beginning of the second word. This is what the par-
1816 // function returns. If the layout does not contain a label, the main
1817 // body always starts with position 0. This differentiation is necessary,
1818 // because there cannot be a newline or a blank <= the beginning of the
1819 // main body in TeX.
1821 int LyXParagraph::BeginningOfMainBody() const
1823 if (FirstPhysicalPar() != this)
1826 // Unroll the first two cycles of the loop
1827 // and remember the previous character to
1828 // remove unnecessary GetChar() calls
1831 && GetChar(i) != LyXParagraph::META_NEWLINE
1834 char previous_char = 0, temp = 0;
1836 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1837 // Yes, this ^ is supposed to be "= " not "=="
1840 && previous_char != ' '
1841 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1843 previous_char = temp;
1848 if (i == 0 && i == size() &&
1849 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1850 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1851 ++i; /* the cursor should not jump
1852 * to the main body if there
1858 LyXParagraph * LyXParagraph::DepthHook(int deth)
1860 LyXParagraph * newpar = this;
1865 newpar = newpar->FirstPhysicalPar()->Previous();
1866 } while (newpar && newpar->GetDepth() > deth
1867 && newpar->footnoteflag == footnoteflag);
1870 if (Previous() || GetDepth())
1871 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1875 return newpar->FirstPhysicalPar();
1879 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1881 LyXParagraph const * newpar = this;
1886 newpar = newpar->FirstPhysicalPar()->Previous();
1887 } while (newpar && newpar->GetDepth() > deth
1888 && newpar->footnoteflag == footnoteflag);
1891 if (Previous() || GetDepth())
1892 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1896 return newpar->FirstPhysicalPar();
1900 int LyXParagraph::AutoDeleteInsets()
1904 while (i < insetlist.size()) {
1905 if (insetlist[i].inset && insetlist[i].inset->AutoDelete()) {
1906 Erase(insetlist[i].pos);
1907 // Erase() calls to insetlist.erase(&insetlist[i])
1908 // so i shouldn't be increased.
1917 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1919 InsetList::iterator it = lower_bound(insetlist.begin(),
1921 InsetTable(pos, 0));
1922 if (it != insetlist.end()) {
1930 // returns -1 if inset not found
1931 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1934 for (InsetList::const_iterator cit = insetlist.begin();
1935 cit != insetlist.end(); ++cit) {
1936 if ((*cit).inset == inset) {
1940 // Think about footnotes.
1941 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1942 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1944 NextAfterFootnote()->GetPositionOfInset(inset);
1946 return text.size() + 1 + further;
1952 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1954 TexRow & foot_texrow,
1957 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1958 LyXLayout const & style =
1959 textclasslist.Style(current_view->buffer()->params.textclass,
1962 bool further_blank_line = false;
1964 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1966 if (start_of_appendix) {
1967 os << "\\appendix\n";
1971 if (tex_code_break_column && style.isCommand()){
1976 if (pagebreak_top) {
1978 further_blank_line = true;
1980 if (added_space_top.kind() != VSpace::NONE) {
1981 os << added_space_top.asLatexCommand(current_view->buffer()->params);
1982 further_blank_line = true;
1986 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
1987 << "\\vspace{-1\\parskip}";
1988 further_blank_line = true;
1991 if (further_blank_line){
1996 Language const * language = getParLanguage();
1997 Language const * doc_language = current_view->buffer()->params.language_info;
1998 if (language != doc_language) {
1999 os << subst(lyxrc.language_command_begin, "$$lang",
2005 switch (style.latextype) {
2008 << style.latexname()
2009 << style.latexparam();
2011 case LATEX_ITEM_ENVIRONMENT:
2013 bibkey->Latex(os, false, false);
2017 case LATEX_LIST_ENVIRONMENT:
2024 bool need_par = SimpleTeXOnePar(os, texrow);
2026 // Spit out footnotes
2027 LyXParagraph * par = next;
2028 if (lyxrc.rtl_support) {
2029 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2030 && next->footnoteflag != footnoteflag) {
2031 LyXParagraph * p = 0;
2032 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2033 if ( (p = NextAfterFootnote()) != 0 &&
2034 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2035 is_rtl = GetFontSettings(0).isRightToLeft();
2037 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2038 par->footnoteflag != footnoteflag) {
2039 LyXDirection dir = (is_rtl)
2040 ? LYX_DIR_RIGHT_TO_LEFT
2041 : LYX_DIR_LEFT_TO_RIGHT;
2042 par = par->TeXFootnote(os, texrow, foot,
2043 foot_texrow, foot_count,
2045 par->SimpleTeXOnePar(os, texrow);
2046 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2048 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2049 (p = par->NextAfterFootnote()) != 0 &&
2050 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2051 is_rtl = GetFontSettings(0).isRightToLeft();
2056 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2057 && par->footnoteflag != footnoteflag) {
2058 par = par->TeXFootnote(os, texrow,
2059 foot, foot_texrow, foot_count,
2060 LYX_DIR_LEFT_TO_RIGHT);
2061 par->SimpleTeXOnePar(os, texrow);
2066 // Make sure that \\par is done with the font of the last
2067 // character if this has another size as the default.
2068 // This is necessary because LaTeX (and LyX on the screen)
2069 // calculates the space between the baselines according
2070 // to this font. (Matthias)
2071 LyXFont font = getFont(Last() - 1);
2073 if (style.resfont.size() != font.size()) {
2079 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2080 GetLayout()).isCommand()){
2081 if (style.resfont.size() != font.size()) {
2087 } else if (style.resfont.size() != font.size()){
2088 os << "{\\" << font.latexSize() << " \\par}";
2091 if (language != doc_language) {
2093 << subst(lyxrc.language_command_end, "$$lang",
2094 doc_language->lang);
2097 switch (style.latextype) {
2098 case LATEX_ITEM_ENVIRONMENT:
2099 case LATEX_LIST_ENVIRONMENT:
2100 if (par && (depth < par->depth)) {
2105 case LATEX_ENVIRONMENT:
2106 // if its the last paragraph of the current environment
2107 // skip it otherwise fall through
2109 && (par->layout != layout
2110 || par->depth != depth
2111 || par->pextra_type != pextra_type))
2114 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2115 && footnotekind != LyXParagraph::FOOTNOTE
2116 && footnotekind != LyXParagraph::MARGIN
2120 // don't insert this if we would be adding it
2121 // before or after a table in a float. This
2122 // little trick is needed in order to allow
2123 // use of tables in \subfigures or \subtables.
2129 further_blank_line = false;
2131 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2132 further_blank_line = true;
2135 if (added_space_bottom.kind() != VSpace::NONE) {
2136 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2137 further_blank_line = true;
2140 if (pagebreak_bottom) {
2142 further_blank_line = true;
2145 if (further_blank_line){
2150 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2151 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2156 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2161 // This one spits out the text of the paragraph
2162 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow)
2164 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2167 return SimpleTeXOneTablePar(os, texrow);
2169 bool return_value = false;
2171 LyXLayout const & style =
2172 textclasslist.Style(current_view->buffer()->params.textclass,
2174 LyXFont basefont, last_font;
2176 // Maybe we have to create a optional argument.
2177 size_type main_body;
2178 if (style.labeltype != LABEL_MANUAL)
2181 main_body = BeginningOfMainBody();
2183 if (main_body > 0) {
2185 basefont = getFont(-2); // Get label font
2187 basefont = getFont(-1); // Get layout font
2195 if (style.isCommand()) {
2198 } else if (align != LYX_ALIGN_LAYOUT) {
2201 return_value = true;
2205 // Which font is currently active?
2206 LyXFont running_font(basefont);
2207 // Do we have an open font change?
2208 bool open_font = false;
2210 texrow.start(this, 0);
2212 for (size_type i = 0; i < size(); ++i) {
2214 // First char in paragraph or after label?
2215 if (i == main_body && !IsDummy()) {
2216 if (main_body > 0) {
2218 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2221 basefont = getFont(-1); // Now use the layout font
2222 running_font = basefont;
2226 if (style.isCommand()) {
2229 } else if (align != LYX_ALIGN_LAYOUT) {
2232 return_value = true;
2236 os << "\\noindent ";
2240 case LYX_ALIGN_NONE:
2241 case LYX_ALIGN_BLOCK:
2242 case LYX_ALIGN_LAYOUT:
2243 case LYX_ALIGN_SPECIAL:
2245 case LYX_ALIGN_LEFT:
2246 if (getParLanguage()->lang != "hebrew") {
2247 os << "\\raggedright ";
2250 os << "\\raggedleft ";
2254 case LYX_ALIGN_RIGHT:
2255 if (getParLanguage()->lang != "hebrew") {
2256 os << "\\raggedleft ";
2259 os << "\\raggedright ";
2263 case LYX_ALIGN_CENTER:
2264 os << "\\centering ";
2272 // Fully instantiated font
2273 LyXFont font = getFont(i);
2274 LyXParagraph * p = 0;
2275 if (i == 0 && previous &&
2276 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2277 (p = PreviousBeforeFootnote()) != 0)
2278 last_font = p->getFont(p->size()-1);
2280 last_font = running_font;
2282 // Spaces at end of font change are simulated to be
2283 // outside font change, i.e. we write "\textXX{text} "
2284 // rather than "\textXX{text }". (Asger)
2285 if (open_font && c == ' ' && i <= size() - 2
2286 && !getFont(i+1).equalExceptLatex(running_font)
2287 && !getFont(i+1).equalExceptLatex(font)) {
2288 font = getFont(i + 1);
2290 // We end font definition before blanks
2291 if (!font.equalExceptLatex(running_font) && open_font) {
2292 column += running_font.latexWriteEndChanges(os,
2294 (i == main_body-1) ? basefont : font);
2295 running_font = basefont;
2299 // Blanks are printed before start of fontswitch
2301 // Do not print the separation of the optional argument
2302 if (i != main_body - 1) {
2303 SimpleTeXBlanks(os, texrow, i,
2304 column, font, style);
2308 // Do we need to change font?
2309 if (!font.equalExceptLatex(running_font)
2310 && i != main_body-1) {
2311 column += font.latexWriteStartChanges(os, basefont,
2313 running_font = font;
2317 if (c == LyXParagraph::META_NEWLINE) {
2318 // newlines are handled differently here than
2319 // the default in SimpleTeXSpecialChars().
2320 if (!style.newline_allowed
2321 || font.latex() == LyXFont::ON) {
2325 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2328 basefont = getFont(-1);
2329 running_font = basefont;
2330 if (font.family() ==
2331 LyXFont::TYPEWRITER_FAMILY) {
2337 texrow.start(this, i + 1);
2340 SimpleTeXSpecialChars(os, texrow,
2341 font, running_font, basefont,
2342 open_font, style, i, column, c);
2346 // If we have an open font definition, we have to close it
2348 LyXParagraph * p = 0;
2349 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2350 && (p = NextAfterFootnote()) != 0)
2351 running_font.latexWriteEndChanges(os, basefont,
2354 running_font.latexWriteEndChanges(os, basefont, basefont);
2357 // Needed if there is an optional argument but no contents.
2358 if (main_body > 0 && main_body == size()) {
2360 return_value = false;
2363 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2364 return return_value;
2368 // This one spits out the text of a table paragraph
2369 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2371 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2373 bool return_value = false;
2375 LyXLayout const & style =
2376 textclasslist.Style(current_view->buffer()->params.textclass,
2380 if (!IsDummy()) { // it is dummy if it is in a float!!!
2381 if (style.isCommand()) {
2384 } else if (align != LYX_ALIGN_LAYOUT) {
2387 return_value = true;
2390 os << "\\noindent ";
2394 case LYX_ALIGN_NONE:
2395 case LYX_ALIGN_BLOCK:
2396 case LYX_ALIGN_LAYOUT:
2397 case LYX_ALIGN_SPECIAL: break;
2398 case LYX_ALIGN_LEFT:
2399 os << "\\raggedright ";
2402 case LYX_ALIGN_RIGHT:
2403 os << "\\raggedleft ";
2406 case LYX_ALIGN_CENTER:
2407 os << "\\centering ";
2413 LyXFont basefont = getFont(-1); // Get layout font
2414 // Which font is currently active?
2415 LyXFont running_font = basefont;
2417 // Do we have an open font change?
2418 bool open_font = false;
2419 int current_cell_number = -1;
2420 int tmp = table->TexEndOfCell(os, current_cell_number);
2421 for (; tmp > 0 ; --tmp)
2424 texrow.start(this, 0);
2426 for (size_type i = 0; i < size(); ++i) {
2427 char c = GetChar(i);
2428 if (table->IsContRow(current_cell_number + 1)) {
2429 if (c == LyXParagraph::META_NEWLINE)
2430 ++current_cell_number;
2435 // Fully instantiated font
2436 LyXFont font = getFont(i);
2437 last_font = running_font;
2439 // Spaces at end of font change are simulated to be
2440 // outside font change.
2441 // i.e. we write "\textXX{text} " rather than
2442 // "\textXX{text }". (Asger)
2443 if (open_font && c == ' ' && i <= size() - 2
2444 && getFont(i + 1) != running_font
2445 && getFont(i + 1) != font) {
2446 font = getFont(i + 1);
2449 // We end font definition before blanks
2450 if (font != running_font && open_font) {
2451 column += running_font.latexWriteEndChanges(os,
2454 running_font = basefont;
2457 // Blanks are printed before start of fontswitch
2459 SimpleTeXBlanks(os, texrow, i, column, font, style);
2461 // Do we need to change font?
2462 if (font != running_font) {
2463 column += font.latexWriteStartChanges(os, basefont,
2465 running_font = font;
2468 // Do we need to turn on LaTeX mode?
2469 if (font.latex() != running_font.latex()) {
2470 if (font.latex() == LyXFont::ON
2471 && style.needprotect) {
2476 if (c == LyXParagraph::META_NEWLINE) {
2477 // special case for inside a table
2478 // different from default case in
2479 // SimpleTeXSpecialChars()
2481 column += running_font
2482 .latexWriteEndChanges(os, basefont,
2486 basefont = getFont(-1);
2487 running_font = basefont;
2488 ++current_cell_number;
2489 if (table->CellHasContRow(current_cell_number) >= 0) {
2490 TeXContTableRows(os, i + 1,
2491 current_cell_number,
2494 // if this cell follow only ContRows till end don't
2495 // put the EndOfCell because it is put after the
2497 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2498 --current_cell_number;
2501 int tmp = table->TexEndOfCell(os,
2502 current_cell_number);
2505 } else if (tmp < 0) {
2511 texrow.start(this, i + 1);
2513 SimpleTeXSpecialChars(os, texrow,
2514 font, running_font, basefont,
2515 open_font, style, i, column, c);
2519 // If we have an open font definition, we have to close it
2521 running_font.latexWriteEndChanges(os, basefont, basefont);
2523 ++current_cell_number;
2524 tmp = table->TexEndOfCell(os, current_cell_number);
2525 for (; tmp > 0; --tmp)
2527 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2528 return return_value;
2532 // This one spits out the text off ContRows in tables
2533 bool LyXParagraph::TeXContTableRows(ostream & os,
2534 LyXParagraph::size_type i,
2535 int current_cell_number,
2536 int & column, TexRow & texrow)
2538 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2544 bool return_value = false;
2545 LyXLayout const & style =
2546 textclasslist.Style(current_view->buffer()->params.textclass,
2548 LyXFont basefont = getFont(-1); // Get layout font
2550 // Which font is currently active?
2551 LyXFont running_font = basefont;
2552 // Do we have an open font change?
2553 bool open_font = false;
2555 size_type lastpos = i;
2556 int cell = table->CellHasContRow(current_cell_number);
2557 ++current_cell_number;
2559 // first find the right position
2561 for (; (i < size()) && (current_cell_number<cell); ++i) {
2563 if (c == LyXParagraph::META_NEWLINE)
2564 ++current_cell_number;
2568 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2572 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2577 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2581 // Fully instantiated font
2582 LyXFont font = getFont(i);
2583 last_font = running_font;
2585 // Spaces at end of font change are simulated to
2586 // be outside font change. i.e. we write
2587 // "\textXX{text} " rather than "\textXX{text }".
2589 if (open_font && c == ' ' && i <= size() - 2
2590 && getFont(i + 1) != running_font
2591 && getFont(i + 1) != font) {
2592 font = getFont(i + 1);
2595 // We end font definition before blanks
2596 if (font != running_font && open_font) {
2597 column += running_font.latexWriteEndChanges(os, basefont, font);
2598 running_font = basefont;
2601 // Blanks are printed before start of fontswitch
2603 SimpleTeXBlanks(os, texrow, i,
2604 column, font, style);
2606 // Do we need to change font?
2607 if (font != running_font) {
2609 font.latexWriteStartChanges(os,
2612 running_font = font;
2615 // Do we need to turn on LaTeX mode?
2616 if (font.latex() != running_font.latex()) {
2617 if (font.latex() == LyXFont::ON
2618 && style.needprotect) {
2623 SimpleTeXSpecialChars(os, texrow, font,
2624 running_font, basefont,
2625 open_font, style, i, column, c);
2627 // If we have an open font definition, we have to close it
2629 running_font.latexWriteEndChanges(os, basefont,
2633 basefont = getFont(-1);
2634 running_font = basefont;
2635 cell = table->CellHasContRow(current_cell_number);
2637 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2638 return return_value;
2642 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2644 bool retval = false;
2646 case LyXParagraph::META_HFILL:
2647 sgml_string.clear();
2650 case LyXParagraph::META_PROTECTED_SEPARATOR:
2654 case LyXParagraph::META_NEWLINE:
2658 sgml_string = "&";
2661 sgml_string = "<";
2664 sgml_string = ">";
2667 sgml_string = "$";
2670 sgml_string = "#";
2673 sgml_string = "%";
2676 sgml_string = "[";
2679 sgml_string = "]";
2682 sgml_string = "{";
2685 sgml_string = "}";
2688 sgml_string = "˜";
2691 sgml_string = """;
2694 sgml_string = "\";
2700 case '\0': // Ignore :-)
2701 sgml_string.clear();
2711 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2712 int & desc_on, int depth)
2715 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2717 LyXFont font1, font2;
2720 size_type main_body;
2721 bool emph_flag = false;
2723 LyXLayout const & style =
2724 textclasslist.Style(current_view->buffer()->params.textclass,
2727 if (style.labeltype != LABEL_MANUAL)
2730 main_body = BeginningOfMainBody();
2732 // Gets paragraph main font.
2734 font1 = style.labelfont;
2738 int char_line_count = depth;
2739 os << newlineAndDepth(depth);
2740 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2741 os << "<INFORMALTABLE>"
2742 << newlineAndDepth(++depth);
2744 int current_cell_number = -1;
2745 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2747 // Parsing main loop.
2748 for (size_type i = 0; i < size(); ++i) {
2750 if (table->IsContRow(current_cell_number+1)) {
2751 if (c == LyXParagraph::META_NEWLINE)
2752 ++current_cell_number;
2757 // Fully instantiated font
2760 // Handle <emphasis> tag.
2761 if (font1.emph() != font2.emph() && i) {
2762 if (font2.emph() == LyXFont::ON) {
2765 } else if (emph_flag) {
2766 os << "</emphasis>";
2770 if (c == LyXParagraph::META_NEWLINE) {
2771 // We have only to control for emphasis open here!
2773 os << "</emphasis>";
2776 font1 = font2 = getFont(-1);
2777 ++current_cell_number;
2778 if (table->CellHasContRow(current_cell_number) >= 0) {
2779 DocBookContTableRows(os, extra, desc_on, i + 1,
2780 current_cell_number,
2783 // if this cell follow only ContRows till end don't
2784 // put the EndOfCell because it is put after the
2786 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2787 --current_cell_number;
2790 tmp = table->DocBookEndOfCell(os,
2791 current_cell_number,
2796 } else if (c == LyXParagraph::META_INSET) {
2797 inset = GetInset(i);
2799 std::ostringstream ost;
2800 inset->DocBook(ost);
2801 string tmp_out = ost.str().c_str();
2804 inset->DocBook(ost);
2806 char * ctmp = ost.str();
2807 string tmp_out(ctmp);
2811 // This code needs some explanation:
2812 // Two insets are treated specially
2813 // label if it is the first element in a
2814 // command paragraph
2816 // graphics inside tables or figure floats
2818 // title (the equivalente in latex for this
2820 // and title should come first
2823 if(desc_on != 3 || i != 0) {
2824 if(tmp_out[0] == '@') {
2826 extra += frontStrip(tmp_out,
2829 os << frontStrip(tmp_out,
2834 } else if (font2.latex() == LyXFont::ON) {
2835 // "TeX"-Mode on == > SGML-Mode on.
2841 if (linuxDocConvertChar(c, sgml_string)
2842 && !style.free_spacing) {
2843 // in freespacing mode, spaces are
2844 // non-breaking characters
2849 << "</term><listitem><para>";
2861 // Needed if there is an optional argument but no contents.
2862 if (main_body > 0 && main_body == size()) {
2867 os << "</emphasis>";
2870 ++current_cell_number;
2871 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2872 // Resets description flag correctly.
2875 // <term> not closed...
2879 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2880 os << "</INFORMALTABLE>";
2882 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2887 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2889 LyXParagraph::size_type i,
2890 int current_cell_number, int &column)
2895 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2900 //string emph = "emphasis";
2901 bool emph_flag = false;
2902 int char_line_count = 0;
2904 LyXLayout const & style =
2905 textclasslist.Style(current_view->buffer()->params.textclass,
2908 size_type main_body;
2909 if (style.labeltype != LABEL_MANUAL)
2912 main_body = BeginningOfMainBody();
2914 // Gets paragraph main font.
2917 font1 = style.labelfont;
2921 size_type lastpos = i;
2922 int cell = table->CellHasContRow(current_cell_number);
2923 ++current_cell_number;
2925 // first find the right position
2927 for (; i < size() && current_cell_number < cell; ++i) {
2929 if (c == LyXParagraph::META_NEWLINE)
2930 ++current_cell_number;
2934 // I don't know how to handle this so I comment it
2935 // for the moment (Jug)
2936 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2937 // file += " \\\\\n";
2940 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2945 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2949 // Fully instantiated font
2952 // Handle <emphasis> tag.
2953 if (font1.emph() != font2.emph() && i) {
2954 if (font2.emph() == LyXFont::ON) {
2957 } else if (emph_flag) {
2958 os << "</emphasis>";
2962 if (c == LyXParagraph::META_INSET) {
2963 inset = GetInset(i);
2965 std::ostringstream ost;
2966 inset->DocBook(ost);
2967 string tmp_out = ost.str().c_str();
2970 inset->DocBook(ost);
2972 char * ctmp = ost.str();
2973 string tmp_out(ctmp);
2977 // This code needs some explanation:
2978 // Two insets are treated specially
2979 // label if it is the first element in a
2980 // command paragraph
2982 // graphics inside tables or figure floats
2983 // can't go on title (the equivalente in
2984 // latex for this case is caption and title
2985 // should come first
2988 if(desc_on != 3 || i != 0) {
2989 if(tmp_out[0] == '@') {
2991 extra += frontStrip(tmp_out, '@');
2993 os << frontStrip(tmp_out, '@');
2997 } else if (font2.latex() == LyXFont::ON) {
2998 // "TeX"-Mode on == > SGML-Mode on.
3004 if (linuxDocConvertChar(c, sgml_string)
3005 && !style.free_spacing) {
3006 // in freespacing mode, spaces are
3007 // non-breaking characters
3012 << "</term><listitem><para>";
3022 // we have only to control for emphasis open here!
3024 os << "</emphasis>";
3027 font1 = font2 = getFont(-1);
3028 cell = table->CellHasContRow(current_cell_number);
3030 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3034 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3035 LyXParagraph::size_type const i,
3036 int & column, LyXFont const & font,
3037 LyXLayout const & style)
3039 if (column > tex_code_break_column
3041 && GetChar(i - 1) != ' '
3043 // In LaTeX mode, we don't want to
3044 // break lines since some commands
3046 && ! (font.latex() == LyXFont::ON)
3047 // same in FreeSpacing mode
3048 && !style.free_spacing
3049 // In typewriter mode, we want to avoid
3050 // ! . ? : at the end of a line
3051 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3052 && (GetChar(i-1) == '.'
3053 || GetChar(i-1) == '?'
3054 || GetChar(i-1) == ':'
3055 || GetChar(i-1) == '!'))) {
3056 if (tex_code_break_column == 0) {
3057 // in batchmode we need LaTeX to still
3058 // see it as a space not as an extra '\n'
3064 texrow.start(this, i + 1);
3066 } else if (font.latex() == LyXFont::OFF) {
3067 if (style.free_spacing) {
3076 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3078 LyXFont & running_font,
3081 LyXLayout const & style,
3082 LyXParagraph::size_type & i,
3083 int & column, char const c)
3085 // Two major modes: LaTeX or plain
3086 // Handle here those cases common to both modes
3087 // and then split to handle the two modes separately.
3089 case LyXParagraph::META_INSET: {
3090 Inset * inset = GetInset(i);
3093 int len = os.tellp();
3094 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3095 || inset->LyxCode() == Inset::MATH_CODE
3096 || inset->LyxCode() == Inset::URL_CODE)
3097 && running_font.isRightToLeft()) {
3100 } else if (inset->LyxCode() == Inset::NUMBER_CODE
3101 && running_font.isRightToLeft()) {
3106 int tmp = inset->Latex(os, style.isCommand(),
3107 style.free_spacing);
3110 if (inset->LyxCode() == Inset::NUMBER_CODE)
3118 column += os.tellp() - len;
3127 case LyXParagraph::META_NEWLINE:
3129 column += running_font.latexWriteEndChanges(os,
3134 basefont = getFont(-1);
3135 running_font = basefont;
3138 case LyXParagraph::META_HFILL:
3144 // And now for the special cases within each mode
3145 // Are we in LaTeX mode?
3146 if (font.latex() == LyXFont::ON) {
3147 // at present we only have one option
3148 // but I'll leave it as a switch statement
3149 // so its simpler to extend. (ARRae)
3152 case LyXParagraph::META_PROTECTED_SEPARATOR:
3157 // make sure that we will not print
3158 // error generating chars to the tex
3159 // file. This test would not be needed
3160 // if it were done in the buffer
3168 // Plain mode (i.e. not LaTeX)
3171 case LyXParagraph::META_PROTECTED_SEPARATOR:
3176 os << "\\textbackslash{}";
3180 case '°': case '±': case '²': case '³':
3181 case '×': case '÷': case '¹': case 'ª':
3182 case 'º': case '¬': case 'µ':
3183 if (current_view->buffer()->params.inputenc == "latin1") {
3184 os << "\\ensuremath{"
3193 case '|': case '<': case '>':
3194 // In T1 encoding, these characters exist
3195 if (lyxrc.fontenc == "T1") {
3197 //... but we should avoid ligatures
3198 if ((c == '>' || c == '<')
3200 && GetChar(i + 1) == c){
3201 os << "\\textcompwordmark{}";
3206 // Typewriter font also has them
3207 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3211 // Otherwise, we use what LaTeX
3215 os << "\\textless{}";
3219 os << "\\textgreater{}";
3223 os << "\\textbar{}";
3229 case '-': // "--" in Typewriter mode -> "-{}-"
3231 && GetChar(i + 1) == '-'
3232 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3241 os << "\\char`\\\"{}";
3246 if (current_view->buffer()->params.inputenc == "default") {
3255 case '%': case '#': case '{':
3262 os << "\\textasciitilde{}";
3267 os << "\\textasciicircum{}";
3271 case '*': case '[': case ']':
3272 // avoid being mistaken for optional arguments
3273 os << '{' << c << '}';
3278 // Blanks are printed before font switching.
3279 // Sure? I am not! (try nice-latex)
3280 // I am sure it's correct. LyX might be smarter
3281 // in the future, but for now, nothing wrong is
3286 /* idea for labels --- begin*/
3290 && font.family() != LyXFont::TYPEWRITER_FAMILY
3291 && GetChar(i + 1) == 'y'
3292 && GetChar(i + 2) == 'X') {
3300 && font.family() != LyXFont::TYPEWRITER_FAMILY
3301 && GetChar(i + 1) == 'e'
3302 && GetChar(i + 2) == 'X') {
3307 // Check for "LaTeX2e"
3310 && font.family() != LyXFont::TYPEWRITER_FAMILY
3311 && GetChar(i + 1) == 'a'
3312 && GetChar(i + 2) == 'T'
3313 && GetChar(i + 3) == 'e'
3314 && GetChar(i + 4) == 'X'
3315 && GetChar(i + 5) == '2'
3316 && GetChar(i + 6) == 'e') {
3321 // Check for "LaTeX"
3324 && font.family() != LyXFont::TYPEWRITER_FAMILY
3325 && GetChar(i + 1) == 'a'
3326 && GetChar(i + 2) == 'T'
3327 && GetChar(i + 3) == 'e'
3328 && GetChar(i + 4) == 'X') {
3332 /* idea for labels --- end*/
3333 } else if (c != '\0') {
3344 bool LyXParagraph::RoffContTableRows(ostream & os,
3345 LyXParagraph::size_type i,
3351 LyXFont font1(LyXFont::ALL_INHERIT);
3356 string fname2 = TmpFileName(string(), "RAT2");
3358 int cell = table->CellHasContRow(actcell);
3361 // first find the right position
3363 for (; i < size() && actcell < cell; ++i) {
3365 if (c == LyXParagraph::META_NEWLINE)
3370 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3373 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3375 font2 = GetFontSettings(i);
3376 if (font1.latex() != font2.latex()) {
3377 if (font2.latex() != LyXFont::OFF)
3382 case LyXParagraph::META_INSET:
3383 if ((inset = GetInset(i))) {
3386 stringstream ss(ios::in | ios::out);
3387 inset->Latex(ss, -1);
3399 inset->Latex(ss, -1);
3412 fstream fs(fname2.c_str(),
3415 WriteAlert(_("LYX_ERROR:"),
3416 _("Cannot open temporary file:"),
3420 inset->Latex(fs, -1);
3434 case LyXParagraph::META_NEWLINE:
3436 case LyXParagraph::META_HFILL:
3439 case LyXParagraph::META_PROTECTED_SEPARATOR:
3449 lyxerr.debug() << "RoffAsciiTable: "
3450 "NULL char in structure."
3455 cell = table->CellHasContRow(actcell);
3462 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3464 TexRow & foot_texrow,
3467 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3468 LyXParagraph * par = this;
3470 while (par && par->depth == depth) {
3472 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3473 if (textclasslist.Style(current_view->buffer()->params.textclass,
3474 par->layout).isEnvironment()
3475 || par->pextra_type != PEXTRA_NONE) {
3476 par = par->TeXEnvironment(os, texrow,
3480 par = par->TeXOnePar(os, texrow,
3485 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3491 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3493 TexRow & foot_texrow,
3496 bool eindent_open = false;
3497 bool foot_this_level = false;
3498 // flags when footnotetext should be appended to file.
3499 static bool minipage_open = false;
3500 static int minipage_open_depth = 0;
3501 char par_sep = current_view->buffer()->params.paragraph_separation;
3503 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3505 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3507 LyXLayout const & style =
3508 textclasslist.Style(current_view->buffer()->params.textclass,
3511 if (pextra_type == PEXTRA_INDENT) {
3512 if (!pextra_width.empty()) {
3513 os << "\\begin{LyXParagraphIndent}{"
3514 << pextra_width << "}\n";
3516 //float ib = atof(pextra_widthp.c_str())/100;
3517 // string can't handle floats at present (971109)
3518 // so I'll do a conversion by hand knowing that
3519 // the limits are 0.0 to 1.0. ARRae.
3520 os << "\\begin{LyXParagraphIndent}{";
3521 switch (pextra_widthp.length()) {
3533 os << "\\columnwidth}\n";
3536 eindent_open = true;
3538 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3539 if (pextra_hfill && Previous() &&
3540 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3541 os << "\\hfill{}\n";
3544 if (par_sep == BufferParams::PARSEP_INDENT) {
3545 os << "{\\setlength\\parindent{0pt}\n";
3548 os << "\\begin{minipage}";
3549 switch(pextra_alignment) {
3550 case MINIPAGE_ALIGN_TOP:
3553 case MINIPAGE_ALIGN_MIDDLE:
3556 case MINIPAGE_ALIGN_BOTTOM:
3560 if (!pextra_width.empty()) {
3561 os << '{' << pextra_width << "}\n";
3563 //float ib = atof(par->pextra_width.c_str())/100;
3564 // string can't handle floats at present
3565 // so I'll do a conversion by hand knowing that
3566 // the limits are 0.0 to 1.0. ARRae.
3568 switch (pextra_widthp.length()) {
3580 os << "\\columnwidth}\n";
3583 if (par_sep == BufferParams::PARSEP_INDENT) {
3584 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3587 minipage_open = true;
3588 minipage_open_depth = depth;
3591 #ifdef WITH_WARNINGS
3592 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3593 //I disabled it because it breaks when lists span on several
3596 if (style.isEnvironment()){
3597 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3598 #ifdef FANCY_FOOTNOTE_CODE
3599 if (foot_count < 0) {
3600 // flag that footnote[mark][text] should be
3601 // used for any footnotes from now on
3603 foot_this_level = true;
3606 os << "\\begin{" << style.latexname() << "}{"
3607 << labelwidthstring << "}\n";
3608 } else if (style.labeltype == LABEL_BIBLIO) {
3610 os << "\\begin{" << style.latexname() << "}{"
3611 << bibitemWidthest(current_view->painter())
3613 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3614 #ifdef FANCY_FOOTNOTE_CODE
3615 if (foot_count < 0) {
3616 // flag that footnote[mark][text] should be
3617 // used for any footnotes from now on
3619 foot_this_level = true;
3622 os << "\\begin{" << style.latexname() << '}'
3623 << style.latexparam() << '\n';
3625 os << "\\begin{" << style.latexname() << '}'
3626 << style.latexparam() << '\n';
3629 LyXParagraph * par = this;
3631 par = par->TeXOnePar(os, texrow,
3632 foot, foot_texrow, foot_count);
3634 if (minipage_open && par && !style.isEnvironment() &&
3635 (par->pextra_type == PEXTRA_MINIPAGE) &&
3636 par->pextra_start_minipage) {
3637 os << "\\end{minipage}\n";
3639 if (par_sep == BufferParams::PARSEP_INDENT) {
3643 minipage_open = false;
3645 if (par && par->depth > depth) {
3646 if (textclasslist.Style(current_view->buffer()->params.textclass,
3647 par->layout).isParagraph()
3650 // How to handle this? (Lgb)
3651 //&& !suffixIs(os, "\n\n")
3653 // There should be at least one '\n' already
3654 // but we need there to be two for Standard
3655 // paragraphs that are depth-increment'ed to be
3656 // output correctly. However, tables can
3657 // also be paragraphs so don't adjust them.
3660 // Will it ever harm to have one '\n' too
3661 // many? i.e. that we sometimes will have
3662 // three in a row. (Lgb)
3666 par = par->TeXDeeper(os, texrow,
3667 foot, foot_texrow, foot_count);
3669 if (par && par->layout == layout && par->depth == depth &&
3670 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3671 if (par->pextra_hfill && par->Previous() &&
3672 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3673 os << "\\hfill{}\n";
3676 if (par_sep == BufferParams::PARSEP_INDENT) {
3677 os << "{\\setlength\\parindent{0pt}\n";
3680 os << "\\begin{minipage}";
3681 switch(par->pextra_alignment) {
3682 case MINIPAGE_ALIGN_TOP:
3685 case MINIPAGE_ALIGN_MIDDLE:
3688 case MINIPAGE_ALIGN_BOTTOM:
3692 if (!par->pextra_width.empty()) {
3693 os << '{' << par->pextra_width << "}\n";
3695 //float ib = atof(par->pextra_widthp.c_str())/100;
3696 // string can't handle floats at present
3697 // so I'll do a conversion by hand knowing that
3698 // the limits are 0.0 to 1.0. ARRae.
3700 switch (par->pextra_widthp.length()) {
3705 os << "0." << par->pextra_widthp;
3708 os << "0.0" << par->pextra_widthp;
3710 os << "\\columnwidth}\n";
3713 if (par_sep == BufferParams::PARSEP_INDENT) {
3714 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3717 minipage_open = true;
3718 minipage_open_depth = par->depth;
3721 && par->layout == layout
3722 && par->depth == depth
3723 && par->pextra_type == pextra_type);
3725 if (style.isEnvironment()) {
3726 os << "\\end{" << style.latexname() << '}';
3727 // maybe this should go after the minipage closes?
3728 if (foot_this_level) {
3729 if (foot_count >= 1) {
3730 if (foot_count > 1) {
3731 os << "\\addtocounter{footnote}{-"
3736 texrow += foot_texrow;
3738 foot_texrow.reset();
3743 if (minipage_open && (minipage_open_depth == depth) &&
3744 (!par || par->pextra_start_minipage ||
3745 par->pextra_type != PEXTRA_MINIPAGE)) {
3746 os << "\\end{minipage}\n";
3748 if (par_sep == BufferParams::PARSEP_INDENT) {
3752 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3753 os << "\\medskip\n\n";
3757 minipage_open = false;
3760 os << "\\end{LyXParagraphIndent}\n";
3763 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3764 && par->pextra_hfill)) {
3768 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3769 return par; // ale970302
3773 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3774 ostream & foot, TexRow & foot_texrow,
3776 LyXDirection parent_direction)
3778 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3779 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3780 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3781 "No footnote!" << endl;
3783 LyXParagraph * par = this;
3784 LyXLayout const & style =
3785 textclasslist.Style(current_view->buffer()->params.textclass,
3786 previous->GetLayout());
3788 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3789 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3790 "Float other than footnote in command"
3791 " with moving argument is illegal" << endl;
3794 if (footnotekind != LyXParagraph::FOOTNOTE
3795 && footnotekind != LyXParagraph::MARGIN
3798 // How to solve this?
3799 //&& !suffixIs(file, '\n')
3801 // we need to ensure that real floats like tables and figures
3802 // have their \begin{} on a new line otherwise we can get
3803 // incorrect results when using the endfloat.sty package
3804 // especially if two floats follow one another. ARRae 981022
3805 // NOTE: if the file is length 0 it must have just been
3806 // written out so we assume it ended with a '\n'
3808 // As far as I can see there is never any harm in writing
3809 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3814 bool need_closing = false;
3815 LyXDirection direction = getParDirection();
3816 if (direction != parent_direction) {
3817 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3821 need_closing = true;
3824 BufferParams * params = ¤t_view->buffer()->params;
3825 bool footer_in_body = true;
3826 switch (footnotekind) {
3827 case LyXParagraph::FOOTNOTE:
3828 if (style.intitle) {
3829 os << "\\thanks{\n";
3830 footer_in_body = false;
3832 if (foot_count == -1) {
3833 // we're at depth 0 so we can use:
3834 os << "\\footnote{%\n";
3835 footer_in_body = false;
3837 os << "\\footnotemark{}%\n";
3839 // we only need this when there are
3840 // multiple footnotes
3841 os << "\\stepcounter{footnote}";
3843 os << "\\footnotetext{%\n";
3844 foot_texrow.start(this, 0);
3845 foot_texrow.newline();
3850 case LyXParagraph::MARGIN:
3851 os << "\\marginpar{\n";
3853 case LyXParagraph::FIG:
3854 if (pextra_type == PEXTRA_FLOATFLT
3855 && (!pextra_width.empty()
3856 || !pextra_widthp.empty())) {
3857 if (!pextra_width.empty())
3858 os << "\\begin{floatingfigure}{"
3859 << pextra_width << "}\n";
3861 os << "\\begin{floatingfigure}{"
3862 << atoi(pextra_widthp.c_str())/100.0
3863 << "\\textwidth}\n";
3865 os << "\\begin{figure}";
3866 if (!params->float_placement.empty()) {
3867 os << '[' << params->float_placement << "]\n";
3873 case LyXParagraph::TAB:
3874 os << "\\begin{table}";
3875 if (!params->float_placement.empty()) {
3876 os << '[' << params->float_placement << "]\n";
3881 case LyXParagraph::WIDE_FIG:
3882 os << "\\begin{figure*}";
3883 if (!params->float_placement.empty()) {
3884 os << '[' << params->float_placement << "]\n";
3889 case LyXParagraph::WIDE_TAB:
3890 os << "\\begin{table*}";
3891 if (!params->float_placement.empty()) {
3892 os << '[' << params->float_placement << "]\n";
3897 case LyXParagraph::ALGORITHM:
3898 os << "\\begin{algorithm}\n";
3903 if (footnotekind != LyXParagraph::FOOTNOTE
3904 || !footer_in_body) {
3905 // Process text for all floats except footnotes in body
3907 LyXLayout const & style =
3909 .Style(current_view->buffer()->params
3913 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3915 if (style.isEnvironment()
3916 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3917 // Allows the use of minipages within float
3918 // environments. Shouldn't be circular because
3919 // we don't support footnotes inside
3920 // floats (yet). ARRae
3921 par = par->TeXEnvironment(os, texrow,
3925 par = par->TeXOnePar(os, texrow,
3930 if (par && !par->IsDummy() && par->depth > depth) {
3931 par = par->TeXDeeper(os, texrow,
3935 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3937 // process footnotes > depth 0 or in environments separately
3938 // NOTE: Currently don't support footnotes within footnotes
3939 // even though that is possible using the \footnotemark
3941 std::ostringstream dummy;
3945 TexRow dummy_texrow;
3946 int dummy_count = 0;
3948 LyXLayout const & style =
3950 .Style(current_view->buffer()->params
3954 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3956 if (style.isEnvironment()
3957 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3958 // Allows the use of minipages within float
3959 // environments. Shouldn't be circular because
3960 // we don't support footnotes inside
3961 // floats (yet). ARRae
3962 par = par->TeXEnvironment(foot, foot_texrow,
3963 dummy, dummy_texrow,
3966 par = par->TeXOnePar(foot, foot_texrow,
3967 dummy, dummy_texrow,
3971 if (par && !par->IsDummy() && par->depth > depth) {
3972 par = par->TeXDeeper(foot, foot_texrow,
3973 dummy, dummy_texrow,
3977 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3979 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3980 "Footnote in a Footnote -- not supported"
3983 #ifndef HAVE_OSTREAM
3984 delete [] dummy.str();
3988 switch (footnotekind) {
3989 case LyXParagraph::FOOTNOTE:
3990 if (footer_in_body) {
3991 // This helps tell which of the multiple
3992 // footnotetexts an error was in.
3994 foot_texrow.newline();
3999 case LyXParagraph::MARGIN:
4002 case LyXParagraph::FIG:
4003 if (pextra_type == PEXTRA_FLOATFLT
4004 && (!pextra_width.empty()
4005 || !pextra_widthp.empty()))
4006 os << "\\end{floatingfigure}";
4008 os << "\\end{figure}";
4010 case LyXParagraph::TAB:
4011 os << "\\end{table}";
4013 case LyXParagraph::WIDE_FIG:
4014 os << "\\end{figure*}";
4016 case LyXParagraph::WIDE_TAB:
4017 os << "\\end{table*}";
4019 case LyXParagraph::ALGORITHM:
4020 os << "\\end{algorithm}";
4027 if (footnotekind != LyXParagraph::FOOTNOTE
4028 && footnotekind != LyXParagraph::MARGIN) {
4029 // we need to ensure that real floats like tables and figures
4030 // have their \end{} on a line of their own otherwise we can
4031 // get incorrect results when using the endfloat.sty package.
4036 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4041 bool LyXParagraph::IsDummy() const
4043 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4044 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4048 void LyXParagraph::SetPExtraType(int type, char const * width,
4049 char const * widthp)
4052 pextra_width = width;
4053 pextra_widthp = widthp;
4055 if (textclasslist.Style(current_view->buffer()->params.textclass,
4056 layout).isEnvironment()) {
4061 while (par && (par->layout == layout)
4062 && (par->depth == depth)) {
4064 par = par->Previous();
4066 par = par->FirstPhysicalPar();
4067 while (par && par->depth > depth) {
4068 par = par->Previous();
4070 par = par->FirstPhysicalPar();
4074 while (par && (par->layout == layout)
4075 && (par->depth == depth)) {
4076 par->pextra_type = type;
4077 par->pextra_width = width;
4078 par->pextra_widthp = widthp;
4079 par = par->NextAfterFootnote();
4080 if (par && (par->depth > depth))
4081 par->SetPExtraType(type, width, widthp);
4082 while (par && ((par->depth > depth) || par->IsDummy()))
4083 par = par->NextAfterFootnote();
4089 void LyXParagraph::UnsetPExtraType()
4091 if (pextra_type == PEXTRA_NONE)
4094 pextra_type = PEXTRA_NONE;
4095 pextra_width.clear();
4096 pextra_widthp.clear();
4098 if (textclasslist.Style(current_view->buffer()->params.textclass,
4099 layout).isEnvironment()) {
4104 while (par && (par->layout == layout)
4105 && (par->depth == depth)) {
4107 par = par->Previous();
4109 par = par->FirstPhysicalPar();
4110 while (par && par->depth > depth) {
4111 par = par->Previous();
4113 par = par->FirstPhysicalPar();
4117 while (par && (par->layout == layout)
4118 && (par->depth == depth)) {
4119 par->pextra_type = PEXTRA_NONE;
4120 par->pextra_width.clear();
4121 par->pextra_widthp.clear();
4122 par = par->NextAfterFootnote();
4123 if (par && (par->depth > depth))
4124 par->UnsetPExtraType();
4125 while (par && ((par->depth > depth) || par->IsDummy()))
4126 par = par->NextAfterFootnote();
4132 bool LyXParagraph::IsHfill(size_type pos) const
4134 return IsHfillChar(GetChar(pos));
4138 bool LyXParagraph::IsInset(size_type pos) const
4140 return IsInsetChar(GetChar(pos));
4144 bool LyXParagraph::IsFloat(size_type pos) const
4146 return IsFloatChar(GetChar(pos));
4150 bool LyXParagraph::IsNewline(size_type pos) const
4152 return pos >= 0 && IsNewlineChar(GetChar(pos));
4156 bool LyXParagraph::IsSeparator(size_type pos) const
4158 return IsSeparatorChar(GetChar(pos));
4162 bool LyXParagraph::IsLineSeparator(size_type pos) const
4164 return IsLineSeparatorChar(GetChar(pos));
4168 bool LyXParagraph::IsKomma(size_type pos) const
4170 return IsKommaChar(GetChar(pos));
4174 /// Used by the spellchecker
4175 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4177 unsigned char c = GetChar(pos);
4178 if (IsLetterChar(c))
4180 // '\0' is not a letter, allthough every string contains "" (below)
4183 // We want to pass the ' and escape chars to ispell
4184 string extra = lyxrc.isp_esc_chars + '\'';
4188 return contains(extra, ch);
4192 bool LyXParagraph::IsWord(size_type pos ) const
4194 return IsWordChar(GetChar(pos)) ;
4197 Language const * LyXParagraph::getParLanguage() const
4199 if (!table && size() > 0)
4200 return FirstPhysicalPar()->GetFirstFontSettings().language();
4202 return previous->getParLanguage();
4204 return current_view->buffer()->params.language_info;
4207 Language const * LyXParagraph::getLetterLanguage(size_type pos) const
4209 return GetFontSettings(pos).language();
4212 LyXDirection LyXParagraph::getParDirection() const
4214 if (!lyxrc.rtl_support || table)
4215 return LYX_DIR_LEFT_TO_RIGHT;
4216 else if (getParLanguage()->RightToLeft)
4217 return LYX_DIR_RIGHT_TO_LEFT;
4219 return LYX_DIR_LEFT_TO_RIGHT;
4223 LyXParagraph::getLetterDirection(LyXParagraph::size_type pos) const
4225 if (!lyxrc.rtl_support)
4226 return LYX_DIR_LEFT_TO_RIGHT;
4227 else if (table && IsNewline(pos))
4228 return LYX_DIR_LEFT_TO_RIGHT;
4230 bool is_rtl = GetFontSettings(pos).isVisibleRightToLeft();
4231 if (IsLineSeparator(pos) && 0 < pos && pos < Last() - 1
4232 && !IsLineSeparator(pos + 1)
4233 && !(table && IsNewline(pos + 1))
4234 && ( GetFontSettings(pos - 1).isVisibleRightToLeft() != is_rtl
4235 || GetFontSettings(pos + 1).isVisibleRightToLeft() != is_rtl))
4236 return getParDirection();
4238 return (is_rtl) ? LYX_DIR_RIGHT_TO_LEFT
4239 : LYX_DIR_LEFT_TO_RIGHT;