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 BufferParams const & params = features.bufferParams();
332 // this will be useful later
333 LyXLayout const & layout =
334 textclasslist.Style(params.textclass,
338 if (line_top || line_bottom)
339 features.lyxline = true;
342 features.layout[GetLayout()] = true;
345 Language const * doc_language = params.language_info;
347 for (FontList::const_iterator cit = fontlist.begin();
348 cit != fontlist.end(); ++cit) {
349 if ((*cit).font.noun() == LyXFont::ON) {
350 lyxerr[Debug::LATEX] << "font.noun: "
351 << (*cit).font.noun()
353 features.noun = true;
354 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
355 << (*cit).font.stateText()
358 switch ((*cit).font.color()) {
360 case LColor::inherit:
364 features.color = true;
365 lyxerr[Debug::LATEX] << "Color enabled. Font: "
366 << (*cit).font.stateText()
369 Language const * language = (*cit).font.language();
370 if (language != doc_language && language != default_language) {
371 features.UsedLanguages.insert(language);
372 lyxerr[Debug::LATEX] << "Found language "
373 << language->lang << endl;
378 for (InsetList::const_iterator cit = insetlist.begin();
379 cit != insetlist.end(); ++cit) {
381 (*cit).inset->Validate(features);
384 if (table && table->IsLongTable())
385 features.longtable = true;
386 if (pextra_type == PEXTRA_INDENT)
387 features.LyXParagraphIndent = true;
388 if (pextra_type == PEXTRA_FLOATFLT)
389 features.floatflt = true;
390 if (layout.needprotect
391 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
392 features.NeedLyXFootnoteCode = true;
393 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
394 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
395 features.NeedLyXMinipageIndent = true;
396 if (table && table->NeedRotating())
397 features.rotating = true;
398 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
399 features.algorithm = true;
403 // First few functions needed for cut and paste and paragraph breaking.
404 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
406 minibuffer_char = GetChar(pos);
407 minibuffer_font = GetFontSettings(pos);
408 minibuffer_inset = 0;
409 if (minibuffer_char == LyXParagraph::META_INSET) {
411 minibuffer_inset = GetInset(pos)->Clone();
413 minibuffer_inset = 0;
414 minibuffer_char = ' ';
415 // This reflects what GetInset() does (ARRae)
421 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
423 minibuffer_char = GetChar(pos);
424 minibuffer_font = GetFontSettings(pos);
425 minibuffer_inset = 0;
426 if (minibuffer_char == LyXParagraph::META_INSET) {
428 minibuffer_inset = GetInset(pos);
429 // This is a little hack since I want exactly
430 // the inset, not just a clone. Otherwise
431 // the inset would be deleted when calling Erase(pos)
433 InsetList::iterator it = lower_bound(insetlist.begin(),
436 if (it != insetlist.end() && (*it).pos == pos)
439 minibuffer_inset = 0;
440 minibuffer_char = ' ';
441 // This reflects what GetInset() does (ARRae)
446 // Erase(pos); now the caller is responsible for that.
450 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
452 if ((minibuffer_char == LyXParagraph::META_INSET) &&
453 !InsertInsetAllowed(minibuffer_inset))
455 InsertChar(pos, minibuffer_char);
456 SetFont(pos, minibuffer_font);
457 if (minibuffer_char == LyXParagraph::META_INSET)
458 InsertInset(pos, minibuffer_inset);
466 void LyXParagraph::Clear()
471 pagebreak_top = false;
472 pagebreak_bottom = false;
474 added_space_top = VSpace(VSpace::NONE);
475 added_space_bottom = VSpace(VSpace::NONE);
477 align = LYX_ALIGN_LAYOUT;
481 pextra_type = PEXTRA_NONE;
482 pextra_width.clear();
483 pextra_widthp.clear();
484 pextra_alignment = MINIPAGE_ALIGN_TOP;
485 pextra_hfill = false;
486 pextra_start_minipage = false;
489 labelwidthstring.clear();
493 start_of_appendix = false;
497 // the destructor removes the new paragraph from the list
498 LyXParagraph::~LyXParagraph()
501 previous->next = next;
503 next->previous = previous;
505 for (InsetList::iterator it = insetlist.begin();
506 it != insetlist.end(); ++it) {
510 /* table stuff -- begin*/
512 /* table stuff -- end*/
517 lyxerr << "LyXParagraph::paragraph_id = "
518 << LyXParagraph::paragraph_id << endl;
522 void LyXParagraph::Erase(LyXParagraph::size_type pos)
524 // > because last is the next unused position, and you can
525 // use it if you want
527 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
528 NextAfterFootnote()->Erase(pos - text.size() - 1);
530 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
531 "position does not exist." << endl;
534 if (pos < size()) { // last is free for insertation, but should be empty
535 // if it is an inset, delete the inset entry
536 if (text[pos] == LyXParagraph::META_INSET) {
538 InsetList::iterator it = lower_bound(insetlist.begin(),
541 if (it != insetlist.end() && (*it).pos == pos) {
546 text.erase(text.begin() + pos);
547 // Erase entries in the tables.
548 for (FontList::iterator it = fontlist.begin();
549 it != fontlist.end(); ++it) {
550 if (pos >= (*it).pos && pos <= (*it).pos_end) {
551 if ((*it).pos == (*it).pos_end) {
552 // If it is a multi-character font
553 // entry, we just make it smaller
554 // (see update below), otherwise we
561 // Update all other entries.
562 for (FontList::iterator it = fontlist.begin();
563 it != fontlist.end(); ++it) {
566 if ((*it).pos_end >= pos)
570 // Update the inset table.
571 for (InsetList::iterator it = upper_bound(insetlist.begin(),
574 it != insetlist.end(); ++it)
577 lyxerr << "ERROR (LyXParagraph::Erase): "
578 "can't erase non-existant char." << endl;
583 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
585 // > because last is the next unused position, and you can
586 // use it if you want
589 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
590 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
593 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
594 "position does not exist." << endl;
597 text.insert(text.begin() + pos, c);
598 // Update the font table.
599 for (FontList::iterator it = fontlist.begin();
600 it != fontlist.end(); ++it) {
601 if ((*it).pos >= pos)
603 if ((*it).pos_end >= pos)
607 // Update the inset table.
608 for (InsetList::iterator it = lower_bound(insetlist.begin(),
611 it != insetlist.end(); ++it)
616 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
619 // > because last is the next unused position, and you can
620 // use it if you want
623 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
625 ->InsertInset(pos - text.size() - 1, inset);
627 lyxerr << "ERROR (LyXParagraph::InsertInset): "
628 "position does not exist: " << pos << endl;
631 if (text[pos] != LyXParagraph::META_INSET) {
632 lyxerr << "ERROR (LyXParagraph::InsertInset): "
633 "there is no LyXParagraph::META_INSET" << endl;
638 // Add a new entry in the inset table.
639 InsetList::iterator it = lower_bound(insetlist.begin(),
642 if (it != insetlist.end() && (*it).pos == pos)
643 lyxerr << "ERROR (LyXParagraph::InsertInset): "
644 "there is an inset in position: " << pos << endl;
646 insetlist.insert(it, InsetTable(pos,inset));
651 bool LyXParagraph::InsertInsetAllowed(Inset *inset)
654 printf("CODE:%d\n",inset->LyxCode());
655 return inset_owner->InsertInsetAllowed(inset);
660 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
664 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
665 return NextAfterFootnote()
666 ->GetInset(pos - text.size() - 1);
668 lyxerr << "ERROR (LyXParagraph::GetInset): "
669 "position does not exist: "
675 InsetList::iterator it = lower_bound(insetlist.begin(),
678 if (it != insetlist.end() && (*it).pos == pos)
681 lyxerr << "ERROR (LyXParagraph::GetInset): "
682 "Inset does not exist: " << pos << endl;
683 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
684 // Did this commenting out introduce a bug? So far I have not
685 // see any, please enlighten me. (Lgb)
686 // My guess is that since the inset does not exist, we might
687 // as well replace it with a space to prevent craches. (Asger)
692 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
696 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
697 return NextAfterFootnote()
698 ->GetInset(pos - text.size() - 1);
700 lyxerr << "ERROR (LyXParagraph::GetInset): "
701 "position does not exist: "
707 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
710 if (cit != insetlist.end() && (*cit).pos == pos)
713 lyxerr << "ERROR (LyXParagraph::GetInset): "
714 "Inset does not exist: " << pos << endl;
715 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
716 // Did this commenting out introduce a bug? So far I have not
717 // see any, please enlighten me. (Lgb)
718 // My guess is that since the inset does not exist, we might
719 // as well replace it with a space to prevent craches. (Asger)
724 // Gets uninstantiated font setting at position.
725 // Optimized after profiling. (Asger)
726 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
729 #ifdef SORTED_FONT_LIST
730 for (FontList::const_iterator cit = fontlist.begin();
731 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
732 if (pos >= (*cit).pos)
735 for (FontList::const_iterator cit = fontlist.begin();
736 cit != fontlist.end(); ++cit)
737 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
741 // > because last is the next unused position, and you can
742 // use it if you want
743 else if (pos > size()) {
745 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
746 return NextAfterFootnote()
747 ->GetFontSettings(pos - text.size() - 1);
749 // Why is it an error to ask for the font of a
750 // position that does not exist? Would it be
751 // enough for this to be enabled on debug?
752 // We want strict error checking, but it's ok to only
753 // have it when debugging. (Asger)
754 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
755 "position does not exist. "
756 << pos << " (" << static_cast<int>(pos)
759 } else if (pos > 0) {
760 return GetFontSettings(pos - 1);
761 } else // pos = size() = 0
762 return LyXFont(LyXFont::ALL_INHERIT,getParLanguage());
764 return LyXFont(LyXFont::ALL_INHERIT);
767 // Gets uninstantiated font setting at position 0
768 LyXFont LyXParagraph::GetFirstFontSettings() const
771 #ifdef SORTED_FONT_LIST
772 if (!fontlist.empty() && fontlist.front().pos == 0)
773 return fontlist.front().font;
775 for (FontList::const_iterator cit = fontlist.begin();
776 cit != fontlist.end(); ++cit)
777 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
780 } else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
781 return NextAfterFootnote()->GetFirstFontSettings();
782 return LyXFont(LyXFont::ALL_INHERIT);
785 // Gets the fully instantiated font at a given position in a paragraph
786 // This is basically the same function as LyXText::GetFont() in text2.C.
787 // The difference is that this one is used for generating the LaTeX file,
788 // and thus cosmetic "improvements" are disallowed: This has to deliver
789 // the true picture of the buffer. (Asger)
790 // If position is -1, we get the layout font of the paragraph.
791 // If position is -2, we get the font of the manual label of the paragraph.
792 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
795 LyXLayout const & layout =
796 textclasslist.Style(current_view->buffer()->params.textclass,
798 LyXParagraph::size_type main_body = 0;
799 if (layout.labeltype == LABEL_MANUAL)
800 main_body = BeginningOfMainBody();
805 layoutfont = layout.labelfont;
807 layoutfont = layout.font;
808 tmpfont = GetFontSettings(pos);
809 tmpfont.realize(layoutfont);
811 // process layoutfont for pos == -1 and labelfont for pos < -1
813 tmpfont = layout.font;
815 tmpfont = layout.labelfont;
816 tmpfont.setLanguage(getParLanguage());
819 // check for environment font information
820 char par_depth = GetDepth();
821 LyXParagraph const * par = this;
822 while (par && par_depth && !tmpfont.resolved()) {
823 par = par->DepthHook(par_depth - 1);
825 tmpfont.realize(textclasslist.
826 Style(current_view->buffer()->params.textclass,
827 par->GetLayout()).font);
828 par_depth = par->GetDepth();
832 tmpfont.realize(textclasslist
833 .TextClass(current_view->buffer()->params.textclass)
839 /// Returns the height of the highest font in range
841 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
842 LyXParagraph::size_type endpos) const
844 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
845 for (FontList::const_iterator cit = fontlist.begin();
846 cit != fontlist.end(); ++cit) {
847 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
848 LyXFont::FONT_SIZE size = (*cit).font.size();
849 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
857 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
864 // > because last is the next unused position, and you can
865 // use it if you want
866 else if (pos > size()) {
867 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
868 return NextAfterFootnote()
869 ->GetChar(pos - text.size() - 1);
871 lyxerr << "ERROR (LyXParagraph::GetChar): "
872 "position does not exist."
873 << pos << " (" << static_cast<int>(pos)
875 // Assert(false); // This triggers sometimes...
880 // We should have a footnote environment.
881 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
882 // Notice that LyX does request the
883 // last char from time to time. (Asger)
884 //lyxerr << "ERROR (LyXParagraph::GetChar): "
885 // "expected footnote." << endl;
888 switch (next->footnotekind) {
889 case LyXParagraph::FOOTNOTE:
890 return LyXParagraph::META_FOOTNOTE;
891 case LyXParagraph::MARGIN:
892 return LyXParagraph::META_MARGIN;
893 case LyXParagraph::FIG:
894 case LyXParagraph::WIDE_FIG:
895 return LyXParagraph::META_FIG;
896 case LyXParagraph::TAB:
897 case LyXParagraph::WIDE_TAB:
898 return LyXParagraph::META_TAB;
899 case LyXParagraph::ALGORITHM:
900 return LyXParagraph::META_ALGORITHM;
902 return '\0'; // to shut up gcc
907 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
914 // > because last is the next unused position, and you can
915 // use it if you want
916 else if (pos > size()) {
917 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
918 return NextAfterFootnote()
919 ->GetChar(pos - text.size() - 1);
921 lyxerr << "ERROR (LyXParagraph::GetChar const): "
922 "position does not exist."
923 << pos << " (" << static_cast<int>(pos)
929 // We should have a footnote environment.
930 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
931 // Notice that LyX does request the
932 // last char from time to time. (Asger)
933 //lyxerr << "ERROR (LyXParagraph::GetChar): "
934 // "expected footnote." << endl;
937 switch (next->footnotekind) {
938 case LyXParagraph::FOOTNOTE:
939 return LyXParagraph::META_FOOTNOTE;
940 case LyXParagraph::MARGIN:
941 return LyXParagraph::META_MARGIN;
942 case LyXParagraph::FIG:
943 case LyXParagraph::WIDE_FIG:
944 return LyXParagraph::META_FIG;
945 case LyXParagraph::TAB:
946 case LyXParagraph::WIDE_TAB:
947 return LyXParagraph::META_TAB;
948 case LyXParagraph::ALGORITHM:
949 return LyXParagraph::META_ALGORITHM;
951 return '\0'; // to shut up gcc
956 // return an string of the current word, and the end of the word in lastpos.
957 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
961 // the current word is defined as starting at the first character
962 // from the immediate left of lastpospos which meets the definition
963 // of IsLetter(), continuing to the last character to the right
964 // of this meeting IsLetter.
970 // move back until we have a letter
972 //there's no real reason to have firstpos & lastpos as
973 //separate variables as this is written, but maybe someon
974 // will want to return firstpos in the future.
976 //since someone might have typed a punctuation first
977 int firstpos = lastpos;
979 while ((firstpos >= 0) && !IsLetter(firstpos))
982 // now find the beginning by looking for a nonletter
984 while ((firstpos>= 0) && IsLetter(firstpos))
987 // the above is now pointing to the preceeding non-letter
991 // so copy characters into theword until we get a nonletter
992 // note that this can easily exceed lastpos, wich means
993 // that if used in the middle of a word, the whole word
996 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1003 LyXParagraph::size_type LyXParagraph::Last() const
1005 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1006 return text.size() + NextAfterFootnote()->Last() + 1;
1007 // the 1 is the symbol
1014 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1016 // > because last is the next unused position, and you can
1017 // use it if you want
1020 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1021 return NextAfterFootnote()
1022 ->ParFromPos(pos - text.size() - 1);
1024 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1025 "position does not exist." << endl;
1032 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1034 // > because last is the next unused position, and you can
1035 // use it if you want
1038 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1039 return NextAfterFootnote()
1040 ->PositionInParFromPos(pos - text.size() - 1);
1043 "ERROR (LyXParagraph::PositionInParFromPos): "
1044 "position does not exist." << endl;
1052 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1053 LyXFont const & font)
1055 // > because last is the next unused position, and you can
1056 // use it if you want
1059 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1060 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1063 lyxerr << "ERROR (LyXParagraph::SetFont): "
1064 "position does not exist." << endl;
1068 LyXFont patternfont(LyXFont::ALL_INHERIT);
1070 // First, reduce font against layout/label font
1071 // Update: The SetCharFont() routine in text2.C already
1072 // reduces font, so we don't need to do that here. (Asger)
1073 // No need to simplify this because it will disappear
1074 // in a new kernel. (Asger)
1075 // Next search font table
1076 FontList::iterator tmp = fontlist.begin();
1077 for (; tmp != fontlist.end(); ++tmp) {
1078 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1082 if (tmp == fontlist.end()) { // !found
1083 // if we did not find a font entry, but if the font at hand
1084 // is the same as default, we just forget it
1085 if (font == patternfont) return;
1087 // ok, we did not find a font entry. But maybe there is exactly
1088 // the needed font ientry one position left
1089 FontList::iterator tmp2 = fontlist.begin();
1090 for (; tmp2 != fontlist.end(); ++tmp2) {
1091 if (pos - 1 >= (*tmp2).pos
1092 && pos - 1 <= (*tmp2).pos_end)
1095 if (tmp2 != fontlist.end()) {
1096 // ok there is one, maybe it is exactly
1098 if ((*tmp2).font == font) {
1099 // put the position under the font
1104 // Add a new entry in the
1105 // fontlist for the position
1109 ft.font = font; // or patternfont
1110 // It seems that using font instead of patternfont here
1111 // fixes all the problems. This also surfaces a "bug" in
1113 fontlist.insert(fontlist.begin(), ft);
1114 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1116 // more than one character
1117 if (pos == (*tmp).pos) {
1118 // maybe we should enlarge the left fonttable
1119 FontList::iterator tmp2 = fontlist.begin();
1120 for (; tmp2 != fontlist.end(); ++tmp2) {
1121 if (pos - 1 >= (*tmp2).pos
1122 && pos - 1 <= (*tmp2).pos_end)
1125 // Is there is one, and is it exactly
1127 if (tmp2 != fontlist.end() &&
1128 (*tmp2).font == font) {
1129 // Put the position under the font
1135 // Add a new entry in the
1136 // fontlist for the position
1139 ft.pos_end = (*tmp).pos_end;
1140 ft.font = (*tmp).font;
1141 (*tmp).pos_end = pos;
1143 fontlist.insert(fontlist.begin(), ft);
1144 } else if (pos == (*tmp).pos_end) {
1145 // Add a new entry in the
1146 // fontlist for the position
1148 ft.pos = (*tmp).pos;
1149 ft.pos_end = (*tmp).pos_end - 1;
1150 ft.font = (*tmp).font;
1151 (*tmp).pos = (*tmp).pos_end;
1153 fontlist.insert(fontlist.begin(), ft);
1155 // Add a new entry in the
1156 // fontlist for the position
1158 ft.pos = (*tmp).pos;
1159 ft.pos_end = pos - 1;
1160 ft.font = (*tmp).font;
1164 ft2.pos_end = (*tmp).pos_end;
1165 ft2.font = (*tmp).font;
1168 (*tmp).pos_end = pos;
1171 fontlist.insert(fontlist.begin(), ft);
1172 fontlist.insert(fontlist.begin(), ft2);
1180 // This function is able to hide closed footnotes.
1181 LyXParagraph * LyXParagraph::Next()
1183 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1184 LyXParagraph * tmp = next;
1186 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1188 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1189 return tmp->Next(); /* there can be more than one
1190 footnote in a logical
1193 return next; // This should never happen!
1199 LyXParagraph * LyXParagraph::NextAfterFootnote()
1201 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1202 LyXParagraph * tmp = next;
1203 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1205 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1206 return tmp; /* there can be more than one footnote
1207 in a logical paragraph */
1209 return next; // This should never happen!
1215 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1217 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1218 LyXParagraph * tmp = next;
1219 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1221 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1222 return tmp; /* there can be more than one footnote
1223 in a logical paragraph */
1225 return next; // This should never happen!
1231 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1234 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1236 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1237 tmp = tmp->previous;
1238 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1239 return tmp; /* there can be more than one footnote
1240 in a logical paragraph */
1242 return previous; // This should never happen!
1248 LyXParagraph * LyXParagraph::LastPhysicalPar()
1250 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1253 LyXParagraph * tmp = this;
1255 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1256 tmp = tmp->NextAfterFootnote();
1261 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1263 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1266 LyXParagraph const * tmp = this;
1268 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1269 tmp = tmp->NextAfterFootnote();
1274 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1278 LyXParagraph * tmppar = this;
1282 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1283 tmppar = tmppar->previous;
1292 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1296 LyXParagraph const * tmppar = this;
1300 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1301 tmppar = tmppar->previous;
1310 // This function is able to hide closed footnotes.
1311 LyXParagraph * LyXParagraph::Previous()
1313 LyXParagraph * tmp = previous;
1318 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1319 tmp = tmp->previous;
1321 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1322 tmp = tmp->previous;
1323 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1324 return tmp->next->Previous();
1333 // This function is able to hide closed footnotes.
1334 LyXParagraph const * LyXParagraph::Previous() const
1336 LyXParagraph * tmp = previous;
1341 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1342 tmp = tmp->previous;
1344 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1345 tmp = tmp->previous;
1346 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1347 return tmp->next->Previous();
1356 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1359 size_type i, j, pos_end, pos_first;
1360 // create a new paragraph
1361 LyXParagraph * par = ParFromPos(pos);
1362 LyXParagraph * firstpar = FirstPhysicalPar();
1364 LyXParagraph * tmp = new LyXParagraph(par);
1366 tmp->footnoteflag = footnoteflag;
1367 tmp->footnotekind = footnotekind;
1369 // this is an idea for a more userfriendly layout handling, I will
1370 // see what the users say
1372 // layout stays the same with latex-environments
1374 tmp->SetOnlyLayout(firstpar->layout);
1375 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1378 if (Last() > pos || !Last() || flag == 2) {
1379 tmp->SetOnlyLayout(firstpar->layout);
1380 tmp->align = firstpar->align;
1381 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1383 tmp->line_bottom = firstpar->line_bottom;
1384 firstpar->line_bottom = false;
1385 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1386 firstpar->pagebreak_bottom = false;
1387 tmp->added_space_bottom = firstpar->added_space_bottom;
1388 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1390 tmp->depth = firstpar->depth;
1391 tmp->noindent = firstpar->noindent;
1393 // copy everything behind the break-position
1394 // to the new paragraph
1396 while (ParFromPos(pos_first) != par)
1399 pos_end = pos_first + par->text.size() - 1;
1401 for (i = j = pos; i <= pos_end; ++i) {
1402 par->CutIntoMinibuffer(i - pos_first);
1403 if (tmp->InsertFromMinibuffer(j - pos))
1406 tmp->text.resize(tmp->text.size());
1407 for (i = pos_end; i >= pos; --i)
1408 par->Erase(i - pos_first);
1410 par->text.resize(par->text.size());
1413 // just an idea of me
1415 tmp->line_top = firstpar->line_top;
1416 tmp->pagebreak_top = firstpar->pagebreak_top;
1417 tmp->added_space_top = firstpar->added_space_top;
1418 tmp->bibkey = firstpar->bibkey;
1420 // layout stays the same with latex-environments
1422 firstpar->SetOnlyLayout(tmp->layout);
1423 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1424 firstpar->depth = tmp->depth;
1430 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1432 par = par->FirstPhysicalPar();
1433 footnoteflag = par->footnoteflag;
1434 footnotekind = par->footnotekind;
1436 layout = par->layout;
1437 align = par-> align;
1438 SetLabelWidthString(par->labelwidthstring);
1440 line_bottom = par->line_bottom;
1441 pagebreak_bottom = par->pagebreak_bottom;
1442 added_space_bottom = par->added_space_bottom;
1444 line_top = par->line_top;
1445 pagebreak_top = par->pagebreak_top;
1446 added_space_top = par->added_space_top;
1448 pextra_type = par->pextra_type;
1449 pextra_width = par->pextra_width;
1450 pextra_widthp = par->pextra_widthp;
1451 pextra_alignment = par->pextra_alignment;
1452 pextra_hfill = par->pextra_hfill;
1453 pextra_start_minipage = par->pextra_start_minipage;
1455 noindent = par->noindent;
1460 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1462 LyXParagraph * tmppar = this;
1465 && tmppar->previous->footnoteflag ==
1466 LyXParagraph::CLOSED_FOOTNOTE)
1467 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1468 tmppar = tmppar->previous;
1471 return this; // This should never happen!
1477 LyXParagraph * LyXParagraph::Clone() const
1479 // create a new paragraph
1480 LyXParagraph * result = new LyXParagraph;
1482 result->MakeSameLayout(this);
1484 // this is because of the dummy layout of the paragraphs that
1486 result->layout = layout;
1488 /* table stuff -- begin*/
1490 result->table = table->Clone();
1493 /* table stuff -- end*/
1495 result->inset_owner = inset_owner;
1498 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1501 // copy everything behind the break-position to the new paragraph
1503 result->text = text;
1504 result->fontlist = fontlist;
1505 result->insetlist = insetlist;
1506 for (InsetList::iterator it = result->insetlist.begin();
1507 it != result->insetlist.end(); ++it)
1508 (*it).inset = (*it).inset->Clone();
1513 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1515 par = par->FirstPhysicalPar();
1518 par->footnoteflag == footnoteflag &&
1519 par->footnotekind == footnotekind &&
1521 par->layout == layout &&
1523 par->align == align &&
1525 par->line_bottom == line_bottom &&
1526 par->pagebreak_bottom == pagebreak_bottom &&
1527 par->added_space_bottom == added_space_bottom &&
1529 par->line_top == line_top &&
1530 par->pagebreak_top == pagebreak_top &&
1531 par->added_space_top == added_space_top &&
1533 par->pextra_type == pextra_type &&
1534 par->pextra_width == pextra_width &&
1535 par->pextra_widthp == pextra_widthp &&
1536 par->pextra_alignment == pextra_alignment &&
1537 par->pextra_hfill == pextra_hfill &&
1538 par->pextra_start_minipage == pextra_start_minipage &&
1540 par->table == table && // what means: NO TABLE AT ALL
1542 par->noindent == noindent &&
1543 par->depth == depth);
1547 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1549 // create a new paragraph
1550 LyXParagraph * par = ParFromPos(pos);
1552 LyXParagraph * tmp = new LyXParagraph(par);
1554 tmp->MakeSameLayout(par);
1556 // When can pos < Last()?
1557 // I guess pos == Last() is possible.
1559 // copy everything behind the break-position to the new
1561 size_type pos_first = 0;
1562 while (ParFromPos(pos_first) != par)
1564 size_type pos_end = pos_first + par->text.size() - 1;
1567 for (i = j = pos; i <= pos_end; ++i) {
1568 par->CutIntoMinibuffer(i - pos_first);
1569 if (tmp->InsertFromMinibuffer(j - pos))
1572 tmp->text.resize(tmp->text.size());
1573 for (size_type i = pos_end; i >= pos; --i)
1574 par->Erase(i - pos_first);
1576 par->text.resize(par->text.size());
1581 // Be carefull, this does not make any check at all.
1582 void LyXParagraph::PasteParagraph()
1584 // copy the next paragraph to this one
1585 LyXParagraph * the_next = Next();
1587 LyXParagraph * firstpar = FirstPhysicalPar();
1589 // first the DTP-stuff
1590 firstpar->line_bottom = the_next->line_bottom;
1591 firstpar->added_space_bottom = the_next->added_space_bottom;
1592 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1594 size_type pos_end = the_next->text.size() - 1;
1595 size_type pos_insert = Last();
1597 // ok, now copy the paragraph
1599 for (i = j = 0; i <= pos_end; ++i) {
1600 the_next->CutIntoMinibuffer(i);
1601 if (InsertFromMinibuffer(pos_insert + j))
1605 // delete the next paragraph
1610 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1612 LyXParagraph * par = ParFromPos(pos);
1614 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1615 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1621 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1623 LyXParagraph * par = ParFromPos(pos);
1625 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1626 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1631 int LyXParagraph::GetEndLabel() const
1633 LyXParagraph const * par = this;
1634 int par_depth = GetDepth();
1636 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1638 textclasslist.Style(current_view->buffer()->params.textclass,
1639 layout).endlabeltype;
1640 if (endlabeltype != END_LABEL_NO_LABEL) {
1641 LyXParagraph const * last = this;
1642 if( footnoteflag == NO_FOOTNOTE)
1643 last = LastPhysicalPar();
1644 else if (next->footnoteflag == NO_FOOTNOTE)
1645 return endlabeltype;
1647 if (!last || !last->next)
1648 return endlabeltype;
1650 int next_depth = last->next->GetDepth();
1651 if (par_depth > next_depth ||
1652 (par_depth == next_depth && layout != last->next->GetLayout() ))
1653 return endlabeltype;
1658 par = par->DepthHook(par_depth - 1);
1660 par_depth = par->GetDepth();
1662 return END_LABEL_NO_LABEL;
1666 LyXTextClass::size_type LyXParagraph::GetLayout() const
1668 return FirstPhysicalPar()->layout;
1672 char LyXParagraph::GetDepth() const
1674 return FirstPhysicalPar()->depth;
1678 char LyXParagraph::GetAlign() const
1680 return FirstPhysicalPar()->align;
1684 string LyXParagraph::GetLabelstring() const
1686 return FirstPhysicalPar()->labelstring;
1690 int LyXParagraph::GetFirstCounter(int i) const
1692 return FirstPhysicalPar()->counter_[i];
1696 // the next two functions are for the manual labels
1697 string LyXParagraph::GetLabelWidthString() const
1699 if (!FirstPhysicalPar()->labelwidthstring.empty())
1700 return FirstPhysicalPar()->labelwidthstring;
1702 return _("Senseless with this layout!");
1706 void LyXParagraph::SetLabelWidthString(string const & s)
1708 LyXParagraph * par = FirstPhysicalPar();
1710 par->labelwidthstring = s;
1714 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1716 LyXParagraph * par = FirstPhysicalPar();
1717 LyXParagraph * ppar = 0;
1718 LyXParagraph * npar = 0;
1720 par->layout = new_layout;
1721 /* table stuff -- begin*/
1724 /* table stuff -- end*/
1725 if (par->pextra_type == PEXTRA_NONE) {
1726 if (par->Previous()) {
1727 ppar = par->Previous()->FirstPhysicalPar();
1730 && (ppar->depth > par->depth))
1731 ppar = ppar->Previous()->FirstPhysicalPar();
1734 npar = par->Next()->NextAfterFootnote();
1737 && (npar->depth > par->depth))
1738 npar = npar->Next()->NextAfterFootnote();
1740 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1742 p1 = ppar->pextra_width,
1743 p2 = ppar->pextra_widthp;
1744 ppar->SetPExtraType(ppar->pextra_type,
1745 p1.c_str(), p2.c_str());
1747 if ((par->pextra_type == PEXTRA_NONE) &&
1748 npar && (npar->pextra_type != PEXTRA_NONE)) {
1750 p1 = npar->pextra_width,
1751 p2 = npar->pextra_widthp;
1752 npar->SetPExtraType(npar->pextra_type,
1753 p1.c_str(), p2.c_str());
1759 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1762 * par = FirstPhysicalPar(),
1766 par->layout = new_layout;
1767 par->labelwidthstring.clear();
1768 par->align = LYX_ALIGN_LAYOUT;
1769 par->added_space_top = VSpace(VSpace::NONE);
1770 par->added_space_bottom = VSpace(VSpace::NONE);
1771 /* table stuff -- begin*/
1774 /* table stuff -- end*/
1775 if (par->pextra_type == PEXTRA_NONE) {
1776 if (par->Previous()) {
1777 ppar = par->Previous()->FirstPhysicalPar();
1780 && (ppar->depth > par->depth))
1781 ppar = ppar->Previous()->FirstPhysicalPar();
1784 npar = par->Next()->NextAfterFootnote();
1787 && (npar->depth > par->depth))
1788 npar = npar->Next()->NextAfterFootnote();
1790 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1792 p1 = ppar->pextra_width,
1793 p2 = ppar->pextra_widthp;
1794 ppar->SetPExtraType(ppar->pextra_type,
1795 p1.c_str(), p2.c_str());
1797 if ((par->pextra_type == PEXTRA_NONE) &&
1798 npar && (npar->pextra_type != PEXTRA_NONE)) {
1800 p1 = npar->pextra_width,
1801 p2 = npar->pextra_widthp;
1802 npar->SetPExtraType(npar->pextra_type,
1803 p1.c_str(), p2.c_str());
1809 // if the layout of a paragraph contains a manual label, the beginning of the
1810 // main body is the beginning of the second word. This is what the par-
1811 // function returns. If the layout does not contain a label, the main
1812 // body always starts with position 0. This differentiation is necessary,
1813 // because there cannot be a newline or a blank <= the beginning of the
1814 // main body in TeX.
1816 int LyXParagraph::BeginningOfMainBody() const
1818 if (FirstPhysicalPar() != this)
1821 // Unroll the first two cycles of the loop
1822 // and remember the previous character to
1823 // remove unnecessary GetChar() calls
1826 && GetChar(i) != LyXParagraph::META_NEWLINE
1829 char previous_char = 0, temp = 0;
1831 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1832 // Yes, this ^ is supposed to be "= " not "=="
1835 && previous_char != ' '
1836 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1838 previous_char = temp;
1843 if (i == 0 && i == size() &&
1844 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1845 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1846 ++i; /* the cursor should not jump
1847 * to the main body if there
1853 LyXParagraph * LyXParagraph::DepthHook(int deth)
1855 LyXParagraph * newpar = this;
1860 newpar = newpar->FirstPhysicalPar()->Previous();
1861 } while (newpar && newpar->GetDepth() > deth
1862 && newpar->footnoteflag == footnoteflag);
1865 if (Previous() || GetDepth())
1866 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1870 return newpar->FirstPhysicalPar();
1874 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1876 LyXParagraph const * newpar = this;
1881 newpar = newpar->FirstPhysicalPar()->Previous();
1882 } while (newpar && newpar->GetDepth() > deth
1883 && newpar->footnoteflag == footnoteflag);
1886 if (Previous() || GetDepth())
1887 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1891 return newpar->FirstPhysicalPar();
1895 int LyXParagraph::AutoDeleteInsets()
1898 InsetList::size_type index = 0;
1899 while (index < insetlist.size()) {
1900 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1901 Erase(insetlist[index].pos);
1902 // Erase() calls to insetlist.erase(&insetlist[index])
1903 // so index shouldn't be increased.
1912 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1914 InsetList::iterator it = lower_bound(insetlist.begin(),
1917 if (it != insetlist.end()) {
1925 // returns -1 if inset not found
1926 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1929 // We could use lower_bound here too, we just need to add
1930 // the approp. operator() to matchIT (and change the name
1931 // of that struct). Code would then be:
1932 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
1934 // inset, matchIT());
1935 // if ((*cit).inset == inset) {
1936 // return (*cit).pos;
1938 for (InsetList::const_iterator cit = insetlist.begin();
1939 cit != insetlist.end(); ++cit) {
1940 if ((*cit).inset == inset) {
1944 // Think about footnotes.
1945 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1946 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1948 NextAfterFootnote()->GetPositionOfInset(inset);
1950 return text.size() + 1 + further;
1956 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1958 TexRow & foot_texrow,
1961 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1962 LyXLayout const & style =
1963 textclasslist.Style(current_view->buffer()->params.textclass,
1966 bool further_blank_line = false;
1968 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1970 if (start_of_appendix) {
1971 os << "\\appendix\n";
1975 if (tex_code_break_column && style.isCommand()){
1980 if (pagebreak_top) {
1982 further_blank_line = true;
1984 if (added_space_top.kind() != VSpace::NONE) {
1985 os << added_space_top.asLatexCommand(current_view->buffer()->params);
1986 further_blank_line = true;
1990 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
1991 << "\\vspace{-1\\parskip}";
1992 further_blank_line = true;
1995 if (further_blank_line){
2000 Language const * language = getParLanguage();
2001 Language const * doc_language = current_view->buffer()->params.language_info;
2002 if (language != doc_language) {
2003 os << subst(lyxrc.language_command_begin, "$$lang",
2009 switch (style.latextype) {
2012 << style.latexname()
2013 << style.latexparam();
2015 case LATEX_ITEM_ENVIRONMENT:
2017 bibkey->Latex(os, false, false);
2021 case LATEX_LIST_ENVIRONMENT:
2028 bool need_par = SimpleTeXOnePar(os, texrow);
2030 // Spit out footnotes
2031 LyXParagraph * par = next;
2032 if (lyxrc.rtl_support) {
2033 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2034 && next->footnoteflag != footnoteflag) {
2035 LyXParagraph * p = 0;
2036 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2037 if ( (p = NextAfterFootnote()) != 0 &&
2038 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2039 is_rtl = GetFontSettings(0).isRightToLeft();
2041 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2042 par->footnoteflag != footnoteflag) {
2043 par = par->TeXFootnote(os, texrow, foot,
2044 foot_texrow, foot_count,
2046 par->SimpleTeXOnePar(os, texrow);
2047 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2049 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2050 (p = par->NextAfterFootnote()) != 0 &&
2051 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2052 is_rtl = GetFontSettings(0).isRightToLeft();
2057 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2058 && par->footnoteflag != footnoteflag) {
2059 par = par->TeXFootnote(os, texrow,
2060 foot, foot_texrow, foot_count,
2062 par->SimpleTeXOnePar(os, texrow);
2067 // Make sure that \\par is done with the font of the last
2068 // character if this has another size as the default.
2069 // This is necessary because LaTeX (and LyX on the screen)
2070 // calculates the space between the baselines according
2071 // to this font. (Matthias)
2072 LyXFont font = getFont(Last() - 1);
2074 if (style.resfont.size() != font.size()) {
2080 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2081 GetLayout()).isCommand()){
2082 if (style.resfont.size() != font.size()) {
2088 } else if (style.resfont.size() != font.size()){
2089 os << "{\\" << font.latexSize() << " \\par}";
2092 if (language != doc_language) {
2094 << subst(lyxrc.language_command_end, "$$lang",
2095 doc_language->lang);
2098 switch (style.latextype) {
2099 case LATEX_ITEM_ENVIRONMENT:
2100 case LATEX_LIST_ENVIRONMENT:
2101 if (par && (depth < par->depth)) {
2106 case LATEX_ENVIRONMENT:
2107 // if its the last paragraph of the current environment
2108 // skip it otherwise fall through
2110 && (par->layout != layout
2111 || par->depth != depth
2112 || par->pextra_type != pextra_type))
2115 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2116 && footnotekind != LyXParagraph::FOOTNOTE
2117 && footnotekind != LyXParagraph::MARGIN
2121 // don't insert this if we would be adding it
2122 // before or after a table in a float. This
2123 // little trick is needed in order to allow
2124 // use of tables in \subfigures or \subtables.
2130 further_blank_line = false;
2132 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2133 further_blank_line = true;
2136 if (added_space_bottom.kind() != VSpace::NONE) {
2137 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2138 further_blank_line = true;
2141 if (pagebreak_bottom) {
2143 further_blank_line = true;
2146 if (further_blank_line){
2151 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2152 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2157 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2162 // This one spits out the text of the paragraph
2163 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow)
2165 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2168 return SimpleTeXOneTablePar(os, texrow);
2170 bool return_value = false;
2172 LyXLayout const & style =
2173 textclasslist.Style(current_view->buffer()->params.textclass,
2175 LyXFont basefont, last_font;
2177 // Maybe we have to create a optional argument.
2178 size_type main_body;
2179 if (style.labeltype != LABEL_MANUAL)
2182 main_body = BeginningOfMainBody();
2184 if (main_body > 0) {
2186 basefont = getFont(-2); // Get label font
2188 basefont = getFont(-1); // Get layout font
2196 if (style.isCommand()) {
2199 } else if (align != LYX_ALIGN_LAYOUT) {
2202 return_value = true;
2206 // Which font is currently active?
2207 LyXFont running_font(basefont);
2208 // Do we have an open font change?
2209 bool open_font = false;
2211 texrow.start(this, 0);
2213 for (size_type i = 0; i < size(); ++i) {
2215 // First char in paragraph or after label?
2216 if (i == main_body && !IsDummy()) {
2217 if (main_body > 0) {
2219 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2222 basefont = getFont(-1); // Now use the layout font
2223 running_font = basefont;
2227 if (style.isCommand()) {
2230 } else if (align != LYX_ALIGN_LAYOUT) {
2233 return_value = true;
2237 os << "\\noindent ";
2241 case LYX_ALIGN_NONE:
2242 case LYX_ALIGN_BLOCK:
2243 case LYX_ALIGN_LAYOUT:
2244 case LYX_ALIGN_SPECIAL:
2246 case LYX_ALIGN_LEFT:
2247 if (getParLanguage()->lang != "hebrew") {
2248 os << "\\raggedright ";
2251 os << "\\raggedleft ";
2255 case LYX_ALIGN_RIGHT:
2256 if (getParLanguage()->lang != "hebrew") {
2257 os << "\\raggedleft ";
2260 os << "\\raggedright ";
2264 case LYX_ALIGN_CENTER:
2265 os << "\\centering ";
2273 // Fully instantiated font
2274 LyXFont font = getFont(i);
2275 LyXParagraph * p = 0;
2276 if (i == 0 && previous &&
2277 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2278 (p = PreviousBeforeFootnote()) != 0)
2279 last_font = p->getFont(p->size()-1);
2281 last_font = running_font;
2283 // Spaces at end of font change are simulated to be
2284 // outside font change, i.e. we write "\textXX{text} "
2285 // rather than "\textXX{text }". (Asger)
2286 if (open_font && c == ' ' && i <= size() - 2
2287 && !getFont(i+1).equalExceptLatex(running_font)
2288 && !getFont(i+1).equalExceptLatex(font)) {
2289 font = getFont(i + 1);
2291 // We end font definition before blanks
2292 if (!font.equalExceptLatex(running_font) && open_font) {
2293 column += running_font.latexWriteEndChanges(os,
2295 (i == main_body-1) ? basefont : font);
2296 running_font = basefont;
2300 // Blanks are printed before start of fontswitch
2302 // Do not print the separation of the optional argument
2303 if (i != main_body - 1) {
2304 SimpleTeXBlanks(os, texrow, i,
2305 column, font, style);
2309 // Do we need to change font?
2310 if (!font.equalExceptLatex(running_font)
2311 && i != main_body-1) {
2312 column += font.latexWriteStartChanges(os, basefont,
2314 running_font = font;
2318 if (c == LyXParagraph::META_NEWLINE) {
2319 // newlines are handled differently here than
2320 // the default in SimpleTeXSpecialChars().
2321 if (!style.newline_allowed
2322 || font.latex() == LyXFont::ON) {
2326 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2329 basefont = getFont(-1);
2330 running_font = basefont;
2331 if (font.family() ==
2332 LyXFont::TYPEWRITER_FAMILY) {
2338 texrow.start(this, i + 1);
2341 SimpleTeXSpecialChars(os, texrow,
2342 font, running_font, basefont,
2343 open_font, style, i, column, c);
2347 // If we have an open font definition, we have to close it
2349 LyXParagraph * p = 0;
2350 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2351 && (p = NextAfterFootnote()) != 0)
2352 running_font.latexWriteEndChanges(os, basefont,
2355 running_font.latexWriteEndChanges(os, basefont, basefont);
2358 // Needed if there is an optional argument but no contents.
2359 if (main_body > 0 && main_body == size()) {
2361 return_value = false;
2364 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2365 return return_value;
2369 // This one spits out the text of a table paragraph
2370 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2372 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2374 bool return_value = false;
2376 LyXLayout const & style =
2377 textclasslist.Style(current_view->buffer()->params.textclass,
2381 if (!IsDummy()) { // it is dummy if it is in a float!!!
2382 if (style.isCommand()) {
2385 } else if (align != LYX_ALIGN_LAYOUT) {
2388 return_value = true;
2391 os << "\\noindent ";
2395 case LYX_ALIGN_NONE:
2396 case LYX_ALIGN_BLOCK:
2397 case LYX_ALIGN_LAYOUT:
2398 case LYX_ALIGN_SPECIAL: break;
2399 case LYX_ALIGN_LEFT:
2400 os << "\\raggedright ";
2403 case LYX_ALIGN_RIGHT:
2404 os << "\\raggedleft ";
2407 case LYX_ALIGN_CENTER:
2408 os << "\\centering ";
2414 LyXFont basefont = getFont(-1); // Get layout font
2415 // Which font is currently active?
2416 LyXFont running_font = basefont;
2418 // Do we have an open font change?
2419 bool open_font = false;
2420 int current_cell_number = -1;
2421 int tmp = table->TexEndOfCell(os, current_cell_number);
2422 for (; tmp > 0 ; --tmp)
2425 texrow.start(this, 0);
2427 bool is_rtl = getParLanguage()->RightToLeft;
2428 bool first_in_cell = true;
2430 for (size_type i = 0; i < size(); ++i) {
2431 char c = GetChar(i);
2432 if (table->IsContRow(current_cell_number + 1)) {
2433 if (c == LyXParagraph::META_NEWLINE)
2434 ++current_cell_number;
2439 if (first_in_cell && is_rtl) {
2442 first_in_cell = false;
2445 // Fully instantiated font
2446 LyXFont font = getFont(i);
2447 last_font = running_font;
2449 // Spaces at end of font change are simulated to be
2450 // outside font change.
2451 // i.e. we write "\textXX{text} " rather than
2452 // "\textXX{text }". (Asger)
2453 if (open_font && c == ' ' && i <= size() - 2
2454 && getFont(i + 1) != running_font
2455 && getFont(i + 1) != font) {
2456 font = getFont(i + 1);
2459 // We end font definition before blanks
2460 if (font != running_font && open_font) {
2461 column += running_font.latexWriteEndChanges(os,
2464 running_font = basefont;
2467 // Blanks are printed before start of fontswitch
2469 SimpleTeXBlanks(os, texrow, i, column, font, style);
2471 // Do we need to change font?
2472 if (font != running_font) {
2473 column += font.latexWriteStartChanges(os, basefont,
2475 running_font = font;
2478 // Do we need to turn on LaTeX mode?
2479 if (font.latex() != running_font.latex()) {
2480 if (font.latex() == LyXFont::ON
2481 && style.needprotect) {
2486 if (c == LyXParagraph::META_NEWLINE) {
2487 // special case for inside a table
2488 // different from default case in
2489 // SimpleTeXSpecialChars()
2491 column += running_font
2492 .latexWriteEndChanges(os, basefont,
2496 basefont = getFont(-1);
2497 running_font = basefont;
2498 ++current_cell_number;
2499 if (table->CellHasContRow(current_cell_number) >= 0) {
2500 TeXContTableRows(os, i + 1,
2501 current_cell_number,
2504 if (is_rtl && !first_in_cell) {
2506 first_in_cell = true;
2509 // if this cell follow only ContRows till end don't
2510 // put the EndOfCell because it is put after the
2512 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2513 --current_cell_number;
2516 int tmp = table->TexEndOfCell(os,
2517 current_cell_number);
2520 } else if (tmp < 0) {
2526 texrow.start(this, i + 1);
2528 SimpleTeXSpecialChars(os, texrow,
2529 font, running_font, basefont,
2530 open_font, style, i, column, c);
2534 // If we have an open font definition, we have to close it
2536 running_font.latexWriteEndChanges(os, basefont, basefont);
2538 ++current_cell_number;
2539 if (is_rtl && !first_in_cell)
2541 tmp = table->TexEndOfCell(os, current_cell_number);
2542 for (; tmp > 0; --tmp)
2544 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2545 return return_value;
2549 // This one spits out the text off ContRows in tables
2550 bool LyXParagraph::TeXContTableRows(ostream & os,
2551 LyXParagraph::size_type i,
2552 int current_cell_number,
2553 int & column, TexRow & texrow)
2555 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2561 bool return_value = false;
2562 LyXLayout const & style =
2563 textclasslist.Style(current_view->buffer()->params.textclass,
2565 LyXFont basefont = getFont(-1); // Get layout font
2567 // Which font is currently active?
2568 LyXFont running_font = basefont;
2569 // Do we have an open font change?
2570 bool open_font = false;
2572 size_type lastpos = i;
2573 int cell = table->CellHasContRow(current_cell_number);
2574 ++current_cell_number;
2576 // first find the right position
2578 for (; (i < size()) && (current_cell_number<cell); ++i) {
2580 if (c == LyXParagraph::META_NEWLINE)
2581 ++current_cell_number;
2585 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2589 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2594 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2598 // Fully instantiated font
2599 LyXFont font = getFont(i);
2600 last_font = running_font;
2602 // Spaces at end of font change are simulated to
2603 // be outside font change. i.e. we write
2604 // "\textXX{text} " rather than "\textXX{text }".
2606 if (open_font && c == ' ' && i <= size() - 2
2607 && getFont(i + 1) != running_font
2608 && getFont(i + 1) != font) {
2609 font = getFont(i + 1);
2612 // We end font definition before blanks
2613 if (font != running_font && open_font) {
2614 column += running_font.latexWriteEndChanges(os, basefont, font);
2615 running_font = basefont;
2618 // Blanks are printed before start of fontswitch
2620 SimpleTeXBlanks(os, texrow, i,
2621 column, font, style);
2623 // Do we need to change font?
2624 if (font != running_font) {
2626 font.latexWriteStartChanges(os,
2629 running_font = font;
2632 // Do we need to turn on LaTeX mode?
2633 if (font.latex() != running_font.latex()) {
2634 if (font.latex() == LyXFont::ON
2635 && style.needprotect) {
2640 SimpleTeXSpecialChars(os, texrow, font,
2641 running_font, basefont,
2642 open_font, style, i, column, c);
2644 // If we have an open font definition, we have to close it
2646 running_font.latexWriteEndChanges(os, basefont,
2650 basefont = getFont(-1);
2651 running_font = basefont;
2652 cell = table->CellHasContRow(current_cell_number);
2654 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2655 return return_value;
2659 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2661 bool retval = false;
2663 case LyXParagraph::META_HFILL:
2664 sgml_string.clear();
2667 case LyXParagraph::META_PROTECTED_SEPARATOR:
2671 case LyXParagraph::META_NEWLINE:
2675 sgml_string = "&";
2678 sgml_string = "<";
2681 sgml_string = ">";
2684 sgml_string = "$";
2687 sgml_string = "#";
2690 sgml_string = "%";
2693 sgml_string = "[";
2696 sgml_string = "]";
2699 sgml_string = "{";
2702 sgml_string = "}";
2705 sgml_string = "˜";
2708 sgml_string = """;
2711 sgml_string = "\";
2717 case '\0': // Ignore :-)
2718 sgml_string.clear();
2728 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2729 int & desc_on, int depth)
2732 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2734 LyXFont font1, font2;
2737 size_type main_body;
2738 bool emph_flag = false;
2740 LyXLayout const & style =
2741 textclasslist.Style(current_view->buffer()->params.textclass,
2744 if (style.labeltype != LABEL_MANUAL)
2747 main_body = BeginningOfMainBody();
2749 // Gets paragraph main font.
2751 font1 = style.labelfont;
2755 int char_line_count = depth;
2756 os << newlineAndDepth(depth);
2757 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2758 os << "<INFORMALTABLE>"
2759 << newlineAndDepth(++depth);
2761 int current_cell_number = -1;
2762 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2764 // Parsing main loop.
2765 for (size_type i = 0; i < size(); ++i) {
2767 if (table->IsContRow(current_cell_number+1)) {
2768 if (c == LyXParagraph::META_NEWLINE)
2769 ++current_cell_number;
2774 // Fully instantiated font
2777 // Handle <emphasis> tag.
2778 if (font1.emph() != font2.emph() && i) {
2779 if (font2.emph() == LyXFont::ON) {
2782 } else if (emph_flag) {
2783 os << "</emphasis>";
2787 if (c == LyXParagraph::META_NEWLINE) {
2788 // We have only to control for emphasis open here!
2790 os << "</emphasis>";
2793 font1 = font2 = getFont(-1);
2794 ++current_cell_number;
2795 if (table->CellHasContRow(current_cell_number) >= 0) {
2796 DocBookContTableRows(os, extra, desc_on, i + 1,
2797 current_cell_number,
2800 // if this cell follow only ContRows till end don't
2801 // put the EndOfCell because it is put after the
2803 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2804 --current_cell_number;
2807 tmp = table->DocBookEndOfCell(os,
2808 current_cell_number,
2813 } else if (c == LyXParagraph::META_INSET) {
2814 inset = GetInset(i);
2816 std::ostringstream ost;
2817 inset->DocBook(ost);
2818 string tmp_out = ost.str().c_str();
2821 inset->DocBook(ost);
2823 char * ctmp = ost.str();
2824 string tmp_out(ctmp);
2828 // This code needs some explanation:
2829 // Two insets are treated specially
2830 // label if it is the first element in a
2831 // command paragraph
2833 // graphics inside tables or figure floats
2835 // title (the equivalente in latex for this
2837 // and title should come first
2840 if(desc_on != 3 || i != 0) {
2841 if(tmp_out[0] == '@') {
2843 extra += frontStrip(tmp_out,
2846 os << frontStrip(tmp_out,
2851 } else if (font2.latex() == LyXFont::ON) {
2852 // "TeX"-Mode on == > SGML-Mode on.
2858 if (linuxDocConvertChar(c, sgml_string)
2859 && !style.free_spacing) {
2860 // in freespacing mode, spaces are
2861 // non-breaking characters
2866 << "</term><listitem><para>";
2878 // Needed if there is an optional argument but no contents.
2879 if (main_body > 0 && main_body == size()) {
2884 os << "</emphasis>";
2887 ++current_cell_number;
2888 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2889 // Resets description flag correctly.
2892 // <term> not closed...
2896 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2897 os << "</INFORMALTABLE>";
2899 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2904 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2906 LyXParagraph::size_type i,
2907 int current_cell_number, int &column)
2912 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2917 //string emph = "emphasis";
2918 bool emph_flag = false;
2919 int char_line_count = 0;
2921 LyXLayout const & style =
2922 textclasslist.Style(current_view->buffer()->params.textclass,
2925 size_type main_body;
2926 if (style.labeltype != LABEL_MANUAL)
2929 main_body = BeginningOfMainBody();
2931 // Gets paragraph main font.
2934 font1 = style.labelfont;
2938 size_type lastpos = i;
2939 int cell = table->CellHasContRow(current_cell_number);
2940 ++current_cell_number;
2942 // first find the right position
2944 for (; i < size() && current_cell_number < cell; ++i) {
2946 if (c == LyXParagraph::META_NEWLINE)
2947 ++current_cell_number;
2951 // I don't know how to handle this so I comment it
2952 // for the moment (Jug)
2953 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2954 // file += " \\\\\n";
2957 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2962 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2966 // Fully instantiated font
2969 // Handle <emphasis> tag.
2970 if (font1.emph() != font2.emph() && i) {
2971 if (font2.emph() == LyXFont::ON) {
2974 } else if (emph_flag) {
2975 os << "</emphasis>";
2979 if (c == LyXParagraph::META_INSET) {
2980 inset = GetInset(i);
2982 std::ostringstream ost;
2983 inset->DocBook(ost);
2984 string tmp_out = ost.str().c_str();
2987 inset->DocBook(ost);
2989 char * ctmp = ost.str();
2990 string tmp_out(ctmp);
2994 // This code needs some explanation:
2995 // Two insets are treated specially
2996 // label if it is the first element in a
2997 // command paragraph
2999 // graphics inside tables or figure floats
3000 // can't go on title (the equivalente in
3001 // latex for this case is caption and title
3002 // should come first
3005 if(desc_on != 3 || i != 0) {
3006 if(tmp_out[0] == '@') {
3008 extra += frontStrip(tmp_out, '@');
3010 os << frontStrip(tmp_out, '@');
3014 } else if (font2.latex() == LyXFont::ON) {
3015 // "TeX"-Mode on == > SGML-Mode on.
3021 if (linuxDocConvertChar(c, sgml_string)
3022 && !style.free_spacing) {
3023 // in freespacing mode, spaces are
3024 // non-breaking characters
3029 << "</term><listitem><para>";
3039 // we have only to control for emphasis open here!
3041 os << "</emphasis>";
3044 font1 = font2 = getFont(-1);
3045 cell = table->CellHasContRow(current_cell_number);
3047 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3051 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3052 LyXParagraph::size_type const i,
3053 int & column, LyXFont const & font,
3054 LyXLayout const & style)
3056 if (column > tex_code_break_column
3058 && GetChar(i - 1) != ' '
3060 // In LaTeX mode, we don't want to
3061 // break lines since some commands
3063 && ! (font.latex() == LyXFont::ON)
3064 // same in FreeSpacing mode
3065 && !style.free_spacing
3066 // In typewriter mode, we want to avoid
3067 // ! . ? : at the end of a line
3068 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3069 && (GetChar(i-1) == '.'
3070 || GetChar(i-1) == '?'
3071 || GetChar(i-1) == ':'
3072 || GetChar(i-1) == '!'))) {
3073 if (tex_code_break_column == 0) {
3074 // in batchmode we need LaTeX to still
3075 // see it as a space not as an extra '\n'
3081 texrow.start(this, i + 1);
3083 } else if (font.latex() == LyXFont::OFF) {
3084 if (style.free_spacing) {
3093 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3095 LyXFont & running_font,
3098 LyXLayout const & style,
3099 LyXParagraph::size_type & i,
3100 int & column, char const c)
3102 // Two major modes: LaTeX or plain
3103 // Handle here those cases common to both modes
3104 // and then split to handle the two modes separately.
3106 case LyXParagraph::META_INSET: {
3107 Inset * inset = GetInset(i);
3110 int len = os.tellp();
3111 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3112 || inset->LyxCode() == Inset::MATH_CODE
3113 || inset->LyxCode() == Inset::URL_CODE)
3114 && running_font.isRightToLeft()) {
3117 } else if (inset->LyxCode() == Inset::NUMBER_CODE
3118 && running_font.isRightToLeft()) {
3123 int tmp = inset->Latex(os, style.isCommand(),
3124 style.free_spacing);
3127 if (inset->LyxCode() == Inset::NUMBER_CODE)
3135 column += os.tellp() - len;
3144 case LyXParagraph::META_NEWLINE:
3146 column += running_font.latexWriteEndChanges(os,
3151 basefont = getFont(-1);
3152 running_font = basefont;
3155 case LyXParagraph::META_HFILL:
3161 // And now for the special cases within each mode
3162 // Are we in LaTeX mode?
3163 if (font.latex() == LyXFont::ON) {
3164 // at present we only have one option
3165 // but I'll leave it as a switch statement
3166 // so its simpler to extend. (ARRae)
3169 case LyXParagraph::META_PROTECTED_SEPARATOR:
3174 // make sure that we will not print
3175 // error generating chars to the tex
3176 // file. This test would not be needed
3177 // if it were done in the buffer
3185 // Plain mode (i.e. not LaTeX)
3188 case LyXParagraph::META_PROTECTED_SEPARATOR:
3193 os << "\\textbackslash{}";
3197 case '°': case '±': case '²': case '³':
3198 case '×': case '÷': case '¹': case 'ª':
3199 case 'º': case '¬': case 'µ':
3200 if (current_view->buffer()->params.inputenc == "latin1") {
3201 os << "\\ensuremath{"
3210 case '|': case '<': case '>':
3211 // In T1 encoding, these characters exist
3212 if (lyxrc.fontenc == "T1") {
3214 //... but we should avoid ligatures
3215 if ((c == '>' || c == '<')
3217 && GetChar(i + 1) == c){
3218 os << "\\textcompwordmark{}";
3223 // Typewriter font also has them
3224 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3228 // Otherwise, we use what LaTeX
3232 os << "\\textless{}";
3236 os << "\\textgreater{}";
3240 os << "\\textbar{}";
3246 case '-': // "--" in Typewriter mode -> "-{}-"
3248 && GetChar(i + 1) == '-'
3249 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3258 os << "\\char`\\\"{}";
3263 if (current_view->buffer()->params.inputenc == "default") {
3272 case '%': case '#': case '{':
3279 os << "\\textasciitilde{}";
3284 os << "\\textasciicircum{}";
3288 case '*': case '[': case ']':
3289 // avoid being mistaken for optional arguments
3290 os << '{' << c << '}';
3295 // Blanks are printed before font switching.
3296 // Sure? I am not! (try nice-latex)
3297 // I am sure it's correct. LyX might be smarter
3298 // in the future, but for now, nothing wrong is
3303 /* idea for labels --- begin*/
3307 && font.family() != LyXFont::TYPEWRITER_FAMILY
3308 && GetChar(i + 1) == 'y'
3309 && GetChar(i + 2) == 'X') {
3317 && font.family() != LyXFont::TYPEWRITER_FAMILY
3318 && GetChar(i + 1) == 'e'
3319 && GetChar(i + 2) == 'X') {
3324 // Check for "LaTeX2e"
3327 && font.family() != LyXFont::TYPEWRITER_FAMILY
3328 && GetChar(i + 1) == 'a'
3329 && GetChar(i + 2) == 'T'
3330 && GetChar(i + 3) == 'e'
3331 && GetChar(i + 4) == 'X'
3332 && GetChar(i + 5) == '2'
3333 && GetChar(i + 6) == 'e') {
3338 // Check for "LaTeX"
3341 && font.family() != LyXFont::TYPEWRITER_FAMILY
3342 && GetChar(i + 1) == 'a'
3343 && GetChar(i + 2) == 'T'
3344 && GetChar(i + 3) == 'e'
3345 && GetChar(i + 4) == 'X') {
3349 /* idea for labels --- end*/
3350 } else if (c != '\0') {
3361 bool LyXParagraph::RoffContTableRows(ostream & os,
3362 LyXParagraph::size_type i,
3368 LyXFont font1(LyXFont::ALL_INHERIT);
3373 string fname2 = TmpFileName(string(), "RAT2");
3375 int cell = table->CellHasContRow(actcell);
3378 // first find the right position
3380 for (; i < size() && actcell < cell; ++i) {
3382 if (c == LyXParagraph::META_NEWLINE)
3387 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3390 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3392 font2 = GetFontSettings(i);
3393 if (font1.latex() != font2.latex()) {
3394 if (font2.latex() != LyXFont::OFF)
3399 case LyXParagraph::META_INSET:
3400 if ((inset = GetInset(i))) {
3403 stringstream ss(ios::in | ios::out);
3404 inset->Latex(ss, -1);
3416 inset->Latex(ss, -1);
3429 fstream fs(fname2.c_str(),
3432 WriteAlert(_("LYX_ERROR:"),
3433 _("Cannot open temporary file:"),
3437 inset->Latex(fs, -1);
3451 case LyXParagraph::META_NEWLINE:
3453 case LyXParagraph::META_HFILL:
3456 case LyXParagraph::META_PROTECTED_SEPARATOR:
3466 lyxerr.debug() << "RoffAsciiTable: "
3467 "NULL char in structure."
3472 cell = table->CellHasContRow(actcell);
3479 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3481 TexRow & foot_texrow,
3484 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3485 LyXParagraph * par = this;
3487 while (par && par->depth == depth) {
3489 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3490 if (textclasslist.Style(current_view->buffer()->params.textclass,
3491 par->layout).isEnvironment()
3492 || par->pextra_type != PEXTRA_NONE) {
3493 par = par->TeXEnvironment(os, texrow,
3497 par = par->TeXOnePar(os, texrow,
3502 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3508 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3510 TexRow & foot_texrow,
3513 bool eindent_open = false;
3514 bool foot_this_level = false;
3515 // flags when footnotetext should be appended to file.
3516 static bool minipage_open = false;
3517 static int minipage_open_depth = 0;
3518 char par_sep = current_view->buffer()->params.paragraph_separation;
3520 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3522 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3524 LyXLayout const & style =
3525 textclasslist.Style(current_view->buffer()->params.textclass,
3528 if (pextra_type == PEXTRA_INDENT) {
3529 if (!pextra_width.empty()) {
3530 os << "\\begin{LyXParagraphIndent}{"
3531 << pextra_width << "}\n";
3533 //float ib = atof(pextra_widthp.c_str())/100;
3534 // string can't handle floats at present (971109)
3535 // so I'll do a conversion by hand knowing that
3536 // the limits are 0.0 to 1.0. ARRae.
3537 os << "\\begin{LyXParagraphIndent}{";
3538 switch (pextra_widthp.length()) {
3550 os << "\\columnwidth}\n";
3553 eindent_open = true;
3555 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3556 if (pextra_hfill && Previous() &&
3557 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3558 os << "\\hfill{}\n";
3561 if (par_sep == BufferParams::PARSEP_INDENT) {
3562 os << "{\\setlength\\parindent{0pt}\n";
3565 os << "\\begin{minipage}";
3566 switch(pextra_alignment) {
3567 case MINIPAGE_ALIGN_TOP:
3570 case MINIPAGE_ALIGN_MIDDLE:
3573 case MINIPAGE_ALIGN_BOTTOM:
3577 if (!pextra_width.empty()) {
3578 os << '{' << pextra_width << "}\n";
3580 //float ib = atof(par->pextra_width.c_str())/100;
3581 // string can't handle floats at present
3582 // so I'll do a conversion by hand knowing that
3583 // the limits are 0.0 to 1.0. ARRae.
3585 switch (pextra_widthp.length()) {
3597 os << "\\columnwidth}\n";
3600 if (par_sep == BufferParams::PARSEP_INDENT) {
3601 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3604 minipage_open = true;
3605 minipage_open_depth = depth;
3608 #ifdef WITH_WARNINGS
3609 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3610 //I disabled it because it breaks when lists span on several
3613 if (style.isEnvironment()){
3614 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3615 #ifdef FANCY_FOOTNOTE_CODE
3616 if (foot_count < 0) {
3617 // flag that footnote[mark][text] should be
3618 // used for any footnotes from now on
3620 foot_this_level = true;
3623 os << "\\begin{" << style.latexname() << "}{"
3624 << labelwidthstring << "}\n";
3625 } else if (style.labeltype == LABEL_BIBLIO) {
3627 os << "\\begin{" << style.latexname() << "}{"
3628 << bibitemWidthest(current_view->painter())
3630 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3631 #ifdef FANCY_FOOTNOTE_CODE
3632 if (foot_count < 0) {
3633 // flag that footnote[mark][text] should be
3634 // used for any footnotes from now on
3636 foot_this_level = true;
3639 os << "\\begin{" << style.latexname() << '}'
3640 << style.latexparam() << '\n';
3642 os << "\\begin{" << style.latexname() << '}'
3643 << style.latexparam() << '\n';
3646 LyXParagraph * par = this;
3648 par = par->TeXOnePar(os, texrow,
3649 foot, foot_texrow, foot_count);
3651 if (minipage_open && par && !style.isEnvironment() &&
3652 (par->pextra_type == PEXTRA_MINIPAGE) &&
3653 par->pextra_start_minipage) {
3654 os << "\\end{minipage}\n";
3656 if (par_sep == BufferParams::PARSEP_INDENT) {
3660 minipage_open = false;
3662 if (par && par->depth > depth) {
3663 if (textclasslist.Style(current_view->buffer()->params.textclass,
3664 par->layout).isParagraph()
3667 // How to handle this? (Lgb)
3668 //&& !suffixIs(os, "\n\n")
3670 // There should be at least one '\n' already
3671 // but we need there to be two for Standard
3672 // paragraphs that are depth-increment'ed to be
3673 // output correctly. However, tables can
3674 // also be paragraphs so don't adjust them.
3677 // Will it ever harm to have one '\n' too
3678 // many? i.e. that we sometimes will have
3679 // three in a row. (Lgb)
3683 par = par->TeXDeeper(os, texrow,
3684 foot, foot_texrow, foot_count);
3686 if (par && par->layout == layout && par->depth == depth &&
3687 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3688 if (par->pextra_hfill && par->Previous() &&
3689 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3690 os << "\\hfill{}\n";
3693 if (par_sep == BufferParams::PARSEP_INDENT) {
3694 os << "{\\setlength\\parindent{0pt}\n";
3697 os << "\\begin{minipage}";
3698 switch(par->pextra_alignment) {
3699 case MINIPAGE_ALIGN_TOP:
3702 case MINIPAGE_ALIGN_MIDDLE:
3705 case MINIPAGE_ALIGN_BOTTOM:
3709 if (!par->pextra_width.empty()) {
3710 os << '{' << par->pextra_width << "}\n";
3712 //float ib = atof(par->pextra_widthp.c_str())/100;
3713 // string can't handle floats at present
3714 // so I'll do a conversion by hand knowing that
3715 // the limits are 0.0 to 1.0. ARRae.
3717 switch (par->pextra_widthp.length()) {
3722 os << "0." << par->pextra_widthp;
3725 os << "0.0" << par->pextra_widthp;
3727 os << "\\columnwidth}\n";
3730 if (par_sep == BufferParams::PARSEP_INDENT) {
3731 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3734 minipage_open = true;
3735 minipage_open_depth = par->depth;
3738 && par->layout == layout
3739 && par->depth == depth
3740 && par->pextra_type == pextra_type);
3742 if (style.isEnvironment()) {
3743 os << "\\end{" << style.latexname() << '}';
3744 // maybe this should go after the minipage closes?
3745 if (foot_this_level) {
3746 if (foot_count >= 1) {
3747 if (foot_count > 1) {
3748 os << "\\addtocounter{footnote}{-"
3753 texrow += foot_texrow;
3755 foot_texrow.reset();
3760 if (minipage_open && (minipage_open_depth == depth) &&
3761 (!par || par->pextra_start_minipage ||
3762 par->pextra_type != PEXTRA_MINIPAGE)) {
3763 os << "\\end{minipage}\n";
3765 if (par_sep == BufferParams::PARSEP_INDENT) {
3769 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3770 os << "\\medskip\n\n";
3774 minipage_open = false;
3777 os << "\\end{LyXParagraphIndent}\n";
3780 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3781 && par->pextra_hfill)) {
3785 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3786 return par; // ale970302
3790 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3791 ostream & foot, TexRow & foot_texrow,
3795 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3796 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3797 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3798 "No footnote!" << endl;
3800 LyXParagraph * par = this;
3801 LyXLayout const & style =
3802 textclasslist.Style(current_view->buffer()->params.textclass,
3803 previous->GetLayout());
3805 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3806 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3807 "Float other than footnote in command"
3808 " with moving argument is illegal" << endl;
3811 if (footnotekind != LyXParagraph::FOOTNOTE
3812 && footnotekind != LyXParagraph::MARGIN
3815 // How to solve this?
3816 //&& !suffixIs(file, '\n')
3818 // we need to ensure that real floats like tables and figures
3819 // have their \begin{} on a new line otherwise we can get
3820 // incorrect results when using the endfloat.sty package
3821 // especially if two floats follow one another. ARRae 981022
3822 // NOTE: if the file is length 0 it must have just been
3823 // written out so we assume it ended with a '\n'
3825 // As far as I can see there is never any harm in writing
3826 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3831 bool need_closing = false;
3832 bool is_rtl = isRightToLeftPar();
3833 if (is_rtl != parent_is_rtl) {
3838 need_closing = true;
3841 BufferParams * params = ¤t_view->buffer()->params;
3842 bool footer_in_body = true;
3843 switch (footnotekind) {
3844 case LyXParagraph::FOOTNOTE:
3845 if (style.intitle) {
3846 os << "\\thanks{\n";
3847 footer_in_body = false;
3849 if (foot_count == -1) {
3850 // we're at depth 0 so we can use:
3851 os << "\\footnote{%\n";
3852 footer_in_body = false;
3854 os << "\\footnotemark{}%\n";
3856 // we only need this when there are
3857 // multiple footnotes
3858 os << "\\stepcounter{footnote}";
3860 os << "\\footnotetext{%\n";
3861 foot_texrow.start(this, 0);
3862 foot_texrow.newline();
3867 case LyXParagraph::MARGIN:
3868 os << "\\marginpar{\n";
3870 case LyXParagraph::FIG:
3871 if (pextra_type == PEXTRA_FLOATFLT
3872 && (!pextra_width.empty()
3873 || !pextra_widthp.empty())) {
3874 if (!pextra_width.empty())
3875 os << "\\begin{floatingfigure}{"
3876 << pextra_width << "}\n";
3878 os << "\\begin{floatingfigure}{"
3879 << atoi(pextra_widthp.c_str())/100.0
3880 << "\\textwidth}\n";
3882 os << "\\begin{figure}";
3883 if (!params->float_placement.empty()) {
3884 os << '[' << params->float_placement << "]\n";
3890 case LyXParagraph::TAB:
3891 os << "\\begin{table}";
3892 if (!params->float_placement.empty()) {
3893 os << '[' << params->float_placement << "]\n";
3898 case LyXParagraph::WIDE_FIG:
3899 os << "\\begin{figure*}";
3900 if (!params->float_placement.empty()) {
3901 os << '[' << params->float_placement << "]\n";
3906 case LyXParagraph::WIDE_TAB:
3907 os << "\\begin{table*}";
3908 if (!params->float_placement.empty()) {
3909 os << '[' << params->float_placement << "]\n";
3914 case LyXParagraph::ALGORITHM:
3915 os << "\\begin{algorithm}\n";
3920 if (footnotekind != LyXParagraph::FOOTNOTE
3921 || !footer_in_body) {
3922 // Process text for all floats except footnotes in body
3924 LyXLayout const & style =
3926 .Style(current_view->buffer()->params
3930 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3932 if (style.isEnvironment()
3933 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3934 // Allows the use of minipages within float
3935 // environments. Shouldn't be circular because
3936 // we don't support footnotes inside
3937 // floats (yet). ARRae
3938 par = par->TeXEnvironment(os, texrow,
3942 par = par->TeXOnePar(os, texrow,
3947 if (par && !par->IsDummy() && par->depth > depth) {
3948 par = par->TeXDeeper(os, texrow,
3952 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3954 // process footnotes > depth 0 or in environments separately
3955 // NOTE: Currently don't support footnotes within footnotes
3956 // even though that is possible using the \footnotemark
3958 std::ostringstream dummy;
3962 TexRow dummy_texrow;
3963 int dummy_count = 0;
3965 LyXLayout const & style =
3967 .Style(current_view->buffer()->params
3971 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3973 if (style.isEnvironment()
3974 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3975 // Allows the use of minipages within float
3976 // environments. Shouldn't be circular because
3977 // we don't support footnotes inside
3978 // floats (yet). ARRae
3979 par = par->TeXEnvironment(foot, foot_texrow,
3980 dummy, dummy_texrow,
3983 par = par->TeXOnePar(foot, foot_texrow,
3984 dummy, dummy_texrow,
3988 if (par && !par->IsDummy() && par->depth > depth) {
3989 par = par->TeXDeeper(foot, foot_texrow,
3990 dummy, dummy_texrow,
3994 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3996 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3997 "Footnote in a Footnote -- not supported"
4000 #ifndef HAVE_OSTREAM
4001 delete [] dummy.str();
4005 switch (footnotekind) {
4006 case LyXParagraph::FOOTNOTE:
4007 if (footer_in_body) {
4008 // This helps tell which of the multiple
4009 // footnotetexts an error was in.
4011 foot_texrow.newline();
4016 case LyXParagraph::MARGIN:
4019 case LyXParagraph::FIG:
4020 if (pextra_type == PEXTRA_FLOATFLT
4021 && (!pextra_width.empty()
4022 || !pextra_widthp.empty()))
4023 os << "\\end{floatingfigure}";
4025 os << "\\end{figure}";
4027 case LyXParagraph::TAB:
4028 os << "\\end{table}";
4030 case LyXParagraph::WIDE_FIG:
4031 os << "\\end{figure*}";
4033 case LyXParagraph::WIDE_TAB:
4034 os << "\\end{table*}";
4036 case LyXParagraph::ALGORITHM:
4037 os << "\\end{algorithm}";
4044 if (footnotekind != LyXParagraph::FOOTNOTE
4045 && footnotekind != LyXParagraph::MARGIN) {
4046 // we need to ensure that real floats like tables and figures
4047 // have their \end{} on a line of their own otherwise we can
4048 // get incorrect results when using the endfloat.sty package.
4053 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4058 bool LyXParagraph::IsDummy() const
4060 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4061 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4065 void LyXParagraph::SetPExtraType(int type, char const * width,
4066 char const * widthp)
4069 pextra_width = width;
4070 pextra_widthp = widthp;
4072 if (textclasslist.Style(current_view->buffer()->params.textclass,
4073 layout).isEnvironment()) {
4078 while (par && (par->layout == layout)
4079 && (par->depth == depth)) {
4081 par = par->Previous();
4083 par = par->FirstPhysicalPar();
4084 while (par && par->depth > depth) {
4085 par = par->Previous();
4087 par = par->FirstPhysicalPar();
4091 while (par && (par->layout == layout)
4092 && (par->depth == depth)) {
4093 par->pextra_type = type;
4094 par->pextra_width = width;
4095 par->pextra_widthp = widthp;
4096 par = par->NextAfterFootnote();
4097 if (par && (par->depth > depth))
4098 par->SetPExtraType(type, width, widthp);
4099 while (par && ((par->depth > depth) || par->IsDummy()))
4100 par = par->NextAfterFootnote();
4106 void LyXParagraph::UnsetPExtraType()
4108 if (pextra_type == PEXTRA_NONE)
4111 pextra_type = PEXTRA_NONE;
4112 pextra_width.clear();
4113 pextra_widthp.clear();
4115 if (textclasslist.Style(current_view->buffer()->params.textclass,
4116 layout).isEnvironment()) {
4121 while (par && (par->layout == layout)
4122 && (par->depth == depth)) {
4124 par = par->Previous();
4126 par = par->FirstPhysicalPar();
4127 while (par && par->depth > depth) {
4128 par = par->Previous();
4130 par = par->FirstPhysicalPar();
4134 while (par && (par->layout == layout)
4135 && (par->depth == depth)) {
4136 par->pextra_type = PEXTRA_NONE;
4137 par->pextra_width.clear();
4138 par->pextra_widthp.clear();
4139 par = par->NextAfterFootnote();
4140 if (par && (par->depth > depth))
4141 par->UnsetPExtraType();
4142 while (par && ((par->depth > depth) || par->IsDummy()))
4143 par = par->NextAfterFootnote();
4149 bool LyXParagraph::IsHfill(size_type pos) const
4151 return IsHfillChar(GetChar(pos));
4155 bool LyXParagraph::IsInset(size_type pos) const
4157 return IsInsetChar(GetChar(pos));
4161 bool LyXParagraph::IsFloat(size_type pos) const
4163 return IsFloatChar(GetChar(pos));
4167 bool LyXParagraph::IsNewline(size_type pos) const
4169 return pos >= 0 && IsNewlineChar(GetChar(pos));
4173 bool LyXParagraph::IsSeparator(size_type pos) const
4175 return IsSeparatorChar(GetChar(pos));
4179 bool LyXParagraph::IsLineSeparator(size_type pos) const
4181 return IsLineSeparatorChar(GetChar(pos));
4185 bool LyXParagraph::IsKomma(size_type pos) const
4187 return IsKommaChar(GetChar(pos));
4191 /// Used by the spellchecker
4192 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4194 unsigned char c = GetChar(pos);
4195 if (IsLetterChar(c))
4197 // '\0' is not a letter, allthough every string contains "" (below)
4200 // We want to pass the ' and escape chars to ispell
4201 string extra = lyxrc.isp_esc_chars + '\'';
4205 return contains(extra, ch);
4209 bool LyXParagraph::IsWord(size_type pos ) const
4211 return IsWordChar(GetChar(pos)) ;
4215 Language const * LyXParagraph::getParLanguage() const
4219 return FirstPhysicalPar()->GetFirstFontSettings()
4222 for (size_type pos = 0; pos < size(); ++pos)
4224 return GetFontSettings(pos).language();
4225 return GetFirstFontSettings().language();
4228 return previous->getParLanguage();
4230 return current_view->buffer()->params.language_info;
4234 bool LyXParagraph::isRightToLeftPar() const
4236 return lyxrc.rtl_support && !table && getParLanguage()->RightToLeft;
4240 void LyXParagraph::ChangeLanguage(Language const * from, Language const * to)
4242 for(size_type i = 0; i < size(); ++i) {
4243 LyXFont font = GetFontSettings(i);
4244 if (font.language() == from) {
4245 font.setLanguage(to);
4252 bool LyXParagraph::isMultiLingual()
4254 Language const * doc_language =
4255 current_view->buffer()->params.language_info;
4256 for(size_type i = 0; i < size(); ++i) {
4257 LyXFont font = GetFontSettings(i);
4258 if (font.language() != doc_language)