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 // Maybe the paragraph has special spacing
172 spacing.writeFile(os, true);
174 // The labelwidth string used in lists.
175 if (!labelwidthstring.empty())
176 os << "\\labelwidthstring "
177 << labelwidthstring << '\n';
179 // Lines above or below?
183 os << "\\line_bottom ";
185 // Pagebreaks above or below?
187 os << "\\pagebreak_top ";
188 if (pagebreak_bottom)
189 os << "\\pagebreak_bottom ";
191 // Start of appendix?
192 if (start_of_appendix)
193 os << "\\start_of_appendix ";
200 if (align != LYX_ALIGN_LAYOUT) {
202 case LYX_ALIGN_LEFT: h = 1; break;
203 case LYX_ALIGN_RIGHT: h = 2; break;
204 case LYX_ALIGN_CENTER: h = 3; break;
205 default: h = 0; break;
207 os << "\\align " << string_align[h] << " ";
209 if (pextra_type != PEXTRA_NONE) {
210 os << "\\pextra_type " << pextra_type;
211 if (pextra_type == PEXTRA_MINIPAGE) {
212 os << " \\pextra_alignment "
215 os << " \\pextra_hfill "
217 if (pextra_start_minipage)
218 os << " \\pextra_start_minipage "
219 << pextra_start_minipage;
221 if (!pextra_width.empty()) {
222 os << " \\pextra_width "
223 << VSpace(pextra_width).asLyXCommand();
224 } else if (!pextra_widthp.empty()) {
225 os << " \\pextra_widthp "
231 // Dummy layout. This means that a footnote ended.
232 os << "\n\\end_float ";
233 footflag = LyXParagraph::NO_FOOTNOTE;
236 // It might be a table.
238 os << "\\LyXTable\n";
246 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
249 for (size_type i = 0; i < size(); ++i) {
255 // Write font changes
256 font2 = GetFontSettings(i);
257 if (font2 != font1) {
258 font2.lyxWriteChanges(font1, os);
267 Inset const * inset = GetInset(i);
269 if (inset->DirectWrite()) {
270 // international char, let it write
271 // code directly so it's shorter in
275 os << "\n\\begin_inset ";
277 os << "\n\\end_inset \n\n";
283 os << "\n\\newline \n";
287 os << "\n\\hfill \n";
291 os << "\n\\backslash \n";
295 if (i + 1 < size() && GetChar(i + 1) == ' ') {
302 if ((column > 70 && c == ' ')
307 // this check is to amend a bug. LyX sometimes
308 // inserts '\0' this could cause problems.
312 lyxerr << "ERROR (LyXParagraph::writeFile):"
313 " NULL char in structure." << endl;
319 // now write the next paragraph
321 next->writeFile(os, params, footflag, dth);
325 void LyXParagraph::validate(LaTeXFeatures & features) const
327 BufferParams const & params = features.bufferParams();
329 // this will be useful later
330 LyXLayout const & layout =
331 textclasslist.Style(params.textclass,
335 if (line_top || line_bottom)
336 features.lyxline = true;
337 if (!spacing.isDefault())
338 features.setspace = true;
341 features.layout[GetLayout()] = true;
344 Language const * doc_language = params.language_info;
346 for (FontList::const_iterator cit = fontlist.begin();
347 cit != fontlist.end(); ++cit) {
348 if ((*cit).font.noun() == LyXFont::ON) {
349 lyxerr[Debug::LATEX] << "font.noun: "
350 << (*cit).font.noun()
352 features.noun = true;
353 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
354 << (*cit).font.stateText()
357 switch ((*cit).font.color()) {
359 case LColor::inherit:
363 features.color = true;
364 lyxerr[Debug::LATEX] << "Color enabled. Font: "
365 << (*cit).font.stateText()
368 Language const * language = (*cit).font.language();
369 if (language != doc_language && language != default_language) {
370 features.UsedLanguages.insert(language);
371 lyxerr[Debug::LATEX] << "Found language "
372 << language->lang << endl;
377 for (InsetList::const_iterator cit = insetlist.begin();
378 cit != insetlist.end(); ++cit) {
380 (*cit).inset->Validate(features);
383 if (table && table->IsLongTable())
384 features.longtable = true;
385 if (pextra_type == PEXTRA_INDENT)
386 features.LyXParagraphIndent = true;
387 if (pextra_type == PEXTRA_FLOATFLT)
388 features.floatflt = true;
389 if (layout.needprotect
390 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
391 features.NeedLyXFootnoteCode = true;
392 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
393 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
394 features.NeedLyXMinipageIndent = true;
395 if (table && table->NeedRotating())
396 features.rotating = true;
397 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
398 features.algorithm = true;
402 // First few functions needed for cut and paste and paragraph breaking.
403 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
405 minibuffer_char = GetChar(pos);
406 minibuffer_font = GetFontSettings(pos);
407 minibuffer_inset = 0;
408 if (minibuffer_char == LyXParagraph::META_INSET) {
410 minibuffer_inset = GetInset(pos)->Clone();
412 minibuffer_inset = 0;
413 minibuffer_char = ' ';
414 // This reflects what GetInset() does (ARRae)
420 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
422 minibuffer_char = GetChar(pos);
423 minibuffer_font = GetFontSettings(pos);
424 minibuffer_inset = 0;
425 if (minibuffer_char == LyXParagraph::META_INSET) {
427 minibuffer_inset = GetInset(pos);
428 // This is a little hack since I want exactly
429 // the inset, not just a clone. Otherwise
430 // the inset would be deleted when calling Erase(pos)
432 InsetList::iterator it = lower_bound(insetlist.begin(),
435 if (it != insetlist.end() && (*it).pos == pos)
438 minibuffer_inset = 0;
439 minibuffer_char = ' ';
440 // This reflects what GetInset() does (ARRae)
445 // Erase(pos); now the caller is responsible for that.
449 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
451 if ((minibuffer_char == LyXParagraph::META_INSET) &&
452 !InsertInsetAllowed(minibuffer_inset))
454 InsertChar(pos, minibuffer_char);
455 SetFont(pos, minibuffer_font);
456 if (minibuffer_char == LyXParagraph::META_INSET)
457 InsertInset(pos, minibuffer_inset);
465 void LyXParagraph::Clear()
470 pagebreak_top = false;
471 pagebreak_bottom = false;
473 added_space_top = VSpace(VSpace::NONE);
474 added_space_bottom = VSpace(VSpace::NONE);
475 spacing.set(Spacing::Default);
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));
648 inset->setOwner(inset_owner);
653 bool LyXParagraph::InsertInsetAllowed(Inset *inset)
656 printf("CODE:%d\n",inset->LyxCode());
657 return inset_owner->InsertInsetAllowed(inset);
662 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
666 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
667 return NextAfterFootnote()
668 ->GetInset(pos - text.size() - 1);
670 lyxerr << "ERROR (LyXParagraph::GetInset): "
671 "position does not exist: "
677 InsetList::iterator it = lower_bound(insetlist.begin(),
680 if (it != insetlist.end() && (*it).pos == pos)
683 lyxerr << "ERROR (LyXParagraph::GetInset): "
684 "Inset does not exist: " << pos << endl;
685 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
686 // Did this commenting out introduce a bug? So far I have not
687 // see any, please enlighten me. (Lgb)
688 // My guess is that since the inset does not exist, we might
689 // as well replace it with a space to prevent craches. (Asger)
694 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
698 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
699 return NextAfterFootnote()
700 ->GetInset(pos - text.size() - 1);
702 lyxerr << "ERROR (LyXParagraph::GetInset): "
703 "position does not exist: "
709 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
712 if (cit != insetlist.end() && (*cit).pos == pos)
715 lyxerr << "ERROR (LyXParagraph::GetInset): "
716 "Inset does not exist: " << pos << endl;
717 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
718 // Did this commenting out introduce a bug? So far I have not
719 // see any, please enlighten me. (Lgb)
720 // My guess is that since the inset does not exist, we might
721 // as well replace it with a space to prevent craches. (Asger)
726 // Gets uninstantiated font setting at position.
727 // Optimized after profiling. (Asger)
728 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
731 #ifdef SORTED_FONT_LIST
732 for (FontList::const_iterator cit = fontlist.begin();
733 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
734 if (pos >= (*cit).pos)
737 for (FontList::const_iterator cit = fontlist.begin();
738 cit != fontlist.end(); ++cit)
739 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
743 // > because last is the next unused position, and you can
744 // use it if you want
745 else if (pos > size()) {
747 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
748 return NextAfterFootnote()
749 ->GetFontSettings(pos - text.size() - 1);
751 // Why is it an error to ask for the font of a
752 // position that does not exist? Would it be
753 // enough for this to be enabled on debug?
754 // We want strict error checking, but it's ok to only
755 // have it when debugging. (Asger)
756 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
757 "position does not exist. "
758 << pos << " (" << static_cast<int>(pos)
761 } else if (pos > 0) {
762 return GetFontSettings(pos - 1);
763 } else // pos = size() = 0
764 return LyXFont(LyXFont::ALL_INHERIT,getParLanguage());
766 return LyXFont(LyXFont::ALL_INHERIT);
769 // Gets uninstantiated font setting at position 0
770 LyXFont LyXParagraph::GetFirstFontSettings() const
773 #ifdef SORTED_FONT_LIST
774 if (!fontlist.empty() && fontlist.front().pos == 0)
775 return fontlist.front().font;
777 for (FontList::const_iterator cit = fontlist.begin();
778 cit != fontlist.end(); ++cit)
779 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
782 } else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
783 return NextAfterFootnote()->GetFirstFontSettings();
784 return LyXFont(LyXFont::ALL_INHERIT);
787 // Gets the fully instantiated font at a given position in a paragraph
788 // This is basically the same function as LyXText::GetFont() in text2.C.
789 // The difference is that this one is used for generating the LaTeX file,
790 // and thus cosmetic "improvements" are disallowed: This has to deliver
791 // the true picture of the buffer. (Asger)
792 // If position is -1, we get the layout font of the paragraph.
793 // If position is -2, we get the font of the manual label of the paragraph.
794 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
797 LyXLayout const & layout =
798 textclasslist.Style(current_view->buffer()->params.textclass,
800 LyXParagraph::size_type main_body = 0;
801 if (layout.labeltype == LABEL_MANUAL)
802 main_body = BeginningOfMainBody();
807 layoutfont = layout.labelfont;
809 layoutfont = layout.font;
810 tmpfont = GetFontSettings(pos);
811 tmpfont.realize(layoutfont);
813 // process layoutfont for pos == -1 and labelfont for pos < -1
815 tmpfont = layout.font;
817 tmpfont = layout.labelfont;
818 tmpfont.setLanguage(getParLanguage());
821 // check for environment font information
822 char par_depth = GetDepth();
823 LyXParagraph const * par = this;
824 while (par && par_depth && !tmpfont.resolved()) {
825 par = par->DepthHook(par_depth - 1);
827 tmpfont.realize(textclasslist.
828 Style(current_view->buffer()->params.textclass,
829 par->GetLayout()).font);
830 par_depth = par->GetDepth();
834 tmpfont.realize(textclasslist
835 .TextClass(current_view->buffer()->params.textclass)
841 /// Returns the height of the highest font in range
843 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
844 LyXParagraph::size_type endpos) const
846 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
847 for (FontList::const_iterator cit = fontlist.begin();
848 cit != fontlist.end(); ++cit) {
849 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
850 LyXFont::FONT_SIZE size = (*cit).font.size();
851 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
859 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
866 // > because last is the next unused position, and you can
867 // use it if you want
868 else if (pos > size()) {
869 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
870 return NextAfterFootnote()
871 ->GetChar(pos - text.size() - 1);
873 lyxerr << "ERROR (LyXParagraph::GetChar): "
874 "position does not exist."
875 << pos << " (" << static_cast<int>(pos)
877 // Assert(false); // This triggers sometimes...
882 // We should have a footnote environment.
883 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
884 // Notice that LyX does request the
885 // last char from time to time. (Asger)
886 //lyxerr << "ERROR (LyXParagraph::GetChar): "
887 // "expected footnote." << endl;
890 switch (next->footnotekind) {
891 case LyXParagraph::FOOTNOTE:
892 return LyXParagraph::META_FOOTNOTE;
893 case LyXParagraph::MARGIN:
894 return LyXParagraph::META_MARGIN;
895 case LyXParagraph::FIG:
896 case LyXParagraph::WIDE_FIG:
897 return LyXParagraph::META_FIG;
898 case LyXParagraph::TAB:
899 case LyXParagraph::WIDE_TAB:
900 return LyXParagraph::META_TAB;
901 case LyXParagraph::ALGORITHM:
902 return LyXParagraph::META_ALGORITHM;
904 return '\0'; // to shut up gcc
909 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
916 // > because last is the next unused position, and you can
917 // use it if you want
918 else if (pos > size()) {
919 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
920 return NextAfterFootnote()
921 ->GetChar(pos - text.size() - 1);
923 lyxerr << "ERROR (LyXParagraph::GetChar const): "
924 "position does not exist."
925 << pos << " (" << static_cast<int>(pos)
931 // We should have a footnote environment.
932 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
933 // Notice that LyX does request the
934 // last char from time to time. (Asger)
935 //lyxerr << "ERROR (LyXParagraph::GetChar): "
936 // "expected footnote." << endl;
939 switch (next->footnotekind) {
940 case LyXParagraph::FOOTNOTE:
941 return LyXParagraph::META_FOOTNOTE;
942 case LyXParagraph::MARGIN:
943 return LyXParagraph::META_MARGIN;
944 case LyXParagraph::FIG:
945 case LyXParagraph::WIDE_FIG:
946 return LyXParagraph::META_FIG;
947 case LyXParagraph::TAB:
948 case LyXParagraph::WIDE_TAB:
949 return LyXParagraph::META_TAB;
950 case LyXParagraph::ALGORITHM:
951 return LyXParagraph::META_ALGORITHM;
953 return '\0'; // to shut up gcc
958 // return an string of the current word, and the end of the word in lastpos.
959 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
963 // the current word is defined as starting at the first character
964 // from the immediate left of lastpospos which meets the definition
965 // of IsLetter(), continuing to the last character to the right
966 // of this meeting IsLetter.
972 // move back until we have a letter
974 //there's no real reason to have firstpos & lastpos as
975 //separate variables as this is written, but maybe someon
976 // will want to return firstpos in the future.
978 //since someone might have typed a punctuation first
979 int firstpos = lastpos;
981 while ((firstpos >= 0) && !IsLetter(firstpos))
984 // now find the beginning by looking for a nonletter
986 while ((firstpos>= 0) && IsLetter(firstpos))
989 // the above is now pointing to the preceeding non-letter
993 // so copy characters into theword until we get a nonletter
994 // note that this can easily exceed lastpos, wich means
995 // that if used in the middle of a word, the whole word
998 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1005 LyXParagraph::size_type LyXParagraph::Last() const
1007 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1008 return text.size() + NextAfterFootnote()->Last() + 1;
1009 // the 1 is the symbol
1016 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1018 // > because last is the next unused position, and you can
1019 // use it if you want
1022 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1023 return NextAfterFootnote()
1024 ->ParFromPos(pos - text.size() - 1);
1026 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1027 "position does not exist." << endl;
1034 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1036 // > because last is the next unused position, and you can
1037 // use it if you want
1040 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1041 return NextAfterFootnote()
1042 ->PositionInParFromPos(pos - text.size() - 1);
1045 "ERROR (LyXParagraph::PositionInParFromPos): "
1046 "position does not exist." << endl;
1054 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1055 LyXFont const & font)
1057 // > because last is the next unused position, and you can
1058 // use it if you want
1061 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1062 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1065 lyxerr << "ERROR (LyXParagraph::SetFont): "
1066 "position does not exist." << endl;
1070 LyXFont patternfont(LyXFont::ALL_INHERIT);
1072 // First, reduce font against layout/label font
1073 // Update: The SetCharFont() routine in text2.C already
1074 // reduces font, so we don't need to do that here. (Asger)
1075 // No need to simplify this because it will disappear
1076 // in a new kernel. (Asger)
1077 // Next search font table
1078 FontList::iterator tmp = fontlist.begin();
1079 for (; tmp != fontlist.end(); ++tmp) {
1080 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1084 if (tmp == fontlist.end()) { // !found
1085 // if we did not find a font entry, but if the font at hand
1086 // is the same as default, we just forget it
1087 if (font == patternfont) return;
1089 // ok, we did not find a font entry. But maybe there is exactly
1090 // the needed font ientry one position left
1091 FontList::iterator tmp2 = fontlist.begin();
1092 for (; tmp2 != fontlist.end(); ++tmp2) {
1093 if (pos - 1 >= (*tmp2).pos
1094 && pos - 1 <= (*tmp2).pos_end)
1097 if (tmp2 != fontlist.end()) {
1098 // ok there is one, maybe it is exactly
1100 if ((*tmp2).font == font) {
1101 // put the position under the font
1106 // Add a new entry in the
1107 // fontlist for the position
1111 ft.font = font; // or patternfont
1112 // It seems that using font instead of patternfont here
1113 // fixes all the problems. This also surfaces a "bug" in
1115 fontlist.insert(fontlist.begin(), ft);
1116 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1118 // more than one character
1119 if (pos == (*tmp).pos) {
1120 // maybe we should enlarge the left fonttable
1121 FontList::iterator tmp2 = fontlist.begin();
1122 for (; tmp2 != fontlist.end(); ++tmp2) {
1123 if (pos - 1 >= (*tmp2).pos
1124 && pos - 1 <= (*tmp2).pos_end)
1127 // Is there is one, and is it exactly
1129 if (tmp2 != fontlist.end() &&
1130 (*tmp2).font == font) {
1131 // Put the position under the font
1137 // Add a new entry in the
1138 // fontlist for the position
1141 ft.pos_end = (*tmp).pos_end;
1142 ft.font = (*tmp).font;
1143 (*tmp).pos_end = pos;
1145 fontlist.insert(fontlist.begin(), ft);
1146 } else if (pos == (*tmp).pos_end) {
1147 // Add a new entry in the
1148 // fontlist for the position
1150 ft.pos = (*tmp).pos;
1151 ft.pos_end = (*tmp).pos_end - 1;
1152 ft.font = (*tmp).font;
1153 (*tmp).pos = (*tmp).pos_end;
1155 fontlist.insert(fontlist.begin(), ft);
1157 // Add a new entry in the
1158 // fontlist for the position
1160 ft.pos = (*tmp).pos;
1161 ft.pos_end = pos - 1;
1162 ft.font = (*tmp).font;
1166 ft2.pos_end = (*tmp).pos_end;
1167 ft2.font = (*tmp).font;
1170 (*tmp).pos_end = pos;
1173 fontlist.insert(fontlist.begin(), ft);
1174 fontlist.insert(fontlist.begin(), ft2);
1182 // This function is able to hide closed footnotes.
1183 LyXParagraph * LyXParagraph::Next()
1185 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1186 LyXParagraph * tmp = next;
1188 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1190 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1191 return tmp->Next(); /* there can be more than one
1192 footnote in a logical
1195 return next; // This should never happen!
1201 LyXParagraph * LyXParagraph::NextAfterFootnote()
1203 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1204 LyXParagraph * tmp = next;
1205 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1207 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1208 return tmp; /* there can be more than one footnote
1209 in a logical paragraph */
1211 return next; // This should never happen!
1217 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1219 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1220 LyXParagraph * tmp = next;
1221 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1223 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1224 return tmp; /* there can be more than one footnote
1225 in a logical paragraph */
1227 return next; // This should never happen!
1233 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1236 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1238 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1239 tmp = tmp->previous;
1240 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1241 return tmp; /* there can be more than one footnote
1242 in a logical paragraph */
1244 return previous; // This should never happen!
1250 LyXParagraph * LyXParagraph::LastPhysicalPar()
1252 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1255 LyXParagraph * tmp = this;
1257 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1258 tmp = tmp->NextAfterFootnote();
1263 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1265 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1268 LyXParagraph const * tmp = this;
1270 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1271 tmp = tmp->NextAfterFootnote();
1276 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1280 LyXParagraph * tmppar = this;
1284 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1285 tmppar = tmppar->previous;
1294 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1298 LyXParagraph const * tmppar = this;
1302 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1303 tmppar = tmppar->previous;
1312 // This function is able to hide closed footnotes.
1313 LyXParagraph * LyXParagraph::Previous()
1315 LyXParagraph * tmp = previous;
1320 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1321 tmp = tmp->previous;
1323 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1324 tmp = tmp->previous;
1325 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1326 return tmp->next->Previous();
1335 // This function is able to hide closed footnotes.
1336 LyXParagraph const * LyXParagraph::Previous() const
1338 LyXParagraph * tmp = previous;
1343 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1344 tmp = tmp->previous;
1346 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1347 tmp = tmp->previous;
1348 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1349 return tmp->next->Previous();
1358 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1361 size_type i, j, pos_end, pos_first;
1362 // create a new paragraph
1363 LyXParagraph * par = ParFromPos(pos);
1364 LyXParagraph * firstpar = FirstPhysicalPar();
1366 LyXParagraph * tmp = new LyXParagraph(par);
1368 tmp->footnoteflag = footnoteflag;
1369 tmp->footnotekind = footnotekind;
1371 // this is an idea for a more userfriendly layout handling, I will
1372 // see what the users say
1374 // layout stays the same with latex-environments
1376 tmp->SetOnlyLayout(firstpar->layout);
1377 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1380 if (Last() > pos || !Last() || flag == 2) {
1381 tmp->SetOnlyLayout(firstpar->layout);
1382 tmp->align = firstpar->align;
1383 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1385 tmp->line_bottom = firstpar->line_bottom;
1386 firstpar->line_bottom = false;
1387 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1388 firstpar->pagebreak_bottom = false;
1389 tmp->added_space_bottom = firstpar->added_space_bottom;
1390 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1392 tmp->depth = firstpar->depth;
1393 tmp->noindent = firstpar->noindent;
1395 // copy everything behind the break-position
1396 // to the new paragraph
1398 while (ParFromPos(pos_first) != par)
1401 pos_end = pos_first + par->text.size() - 1;
1403 for (i = j = pos; i <= pos_end; ++i) {
1404 par->CutIntoMinibuffer(i - pos_first);
1405 if (tmp->InsertFromMinibuffer(j - pos))
1408 tmp->text.resize(tmp->text.size());
1409 for (i = pos_end; i >= pos; --i)
1410 par->Erase(i - pos_first);
1412 par->text.resize(par->text.size());
1415 // just an idea of me
1417 tmp->line_top = firstpar->line_top;
1418 tmp->pagebreak_top = firstpar->pagebreak_top;
1419 tmp->added_space_top = firstpar->added_space_top;
1420 tmp->bibkey = firstpar->bibkey;
1422 // layout stays the same with latex-environments
1424 firstpar->SetOnlyLayout(tmp->layout);
1425 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1426 firstpar->depth = tmp->depth;
1432 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1434 par = par->FirstPhysicalPar();
1435 footnoteflag = par->footnoteflag;
1436 footnotekind = par->footnotekind;
1438 layout = par->layout;
1439 align = par-> align;
1440 SetLabelWidthString(par->labelwidthstring);
1442 line_bottom = par->line_bottom;
1443 pagebreak_bottom = par->pagebreak_bottom;
1444 added_space_bottom = par->added_space_bottom;
1446 line_top = par->line_top;
1447 pagebreak_top = par->pagebreak_top;
1448 added_space_top = par->added_space_top;
1450 spacing = par->spacing;
1452 pextra_type = par->pextra_type;
1453 pextra_width = par->pextra_width;
1454 pextra_widthp = par->pextra_widthp;
1455 pextra_alignment = par->pextra_alignment;
1456 pextra_hfill = par->pextra_hfill;
1457 pextra_start_minipage = par->pextra_start_minipage;
1459 noindent = par->noindent;
1464 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1466 LyXParagraph * tmppar = this;
1469 && tmppar->previous->footnoteflag ==
1470 LyXParagraph::CLOSED_FOOTNOTE)
1471 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1472 tmppar = tmppar->previous;
1475 return this; // This should never happen!
1481 LyXParagraph * LyXParagraph::Clone() const
1483 // create a new paragraph
1484 LyXParagraph * result = new LyXParagraph;
1486 result->MakeSameLayout(this);
1488 // this is because of the dummy layout of the paragraphs that
1490 result->layout = layout;
1492 /* table stuff -- begin*/
1494 result->table = table->Clone();
1497 /* table stuff -- end*/
1499 result->inset_owner = inset_owner;
1502 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1505 // copy everything behind the break-position to the new paragraph
1507 result->text = text;
1508 result->fontlist = fontlist;
1509 result->insetlist = insetlist;
1510 for (InsetList::iterator it = result->insetlist.begin();
1511 it != result->insetlist.end(); ++it)
1512 (*it).inset = (*it).inset->Clone();
1517 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1519 par = par->FirstPhysicalPar();
1522 par->footnoteflag == footnoteflag &&
1523 par->footnotekind == footnotekind &&
1525 par->layout == layout &&
1527 par->align == align &&
1529 par->line_bottom == line_bottom &&
1530 par->pagebreak_bottom == pagebreak_bottom &&
1531 par->added_space_bottom == added_space_bottom &&
1533 par->line_top == line_top &&
1534 par->pagebreak_top == pagebreak_top &&
1535 par->added_space_top == added_space_top &&
1537 par->spacing == spacing &&
1539 par->pextra_type == pextra_type &&
1540 par->pextra_width == pextra_width &&
1541 par->pextra_widthp == pextra_widthp &&
1542 par->pextra_alignment == pextra_alignment &&
1543 par->pextra_hfill == pextra_hfill &&
1544 par->pextra_start_minipage == pextra_start_minipage &&
1546 par->table == table && // what means: NO TABLE AT ALL
1548 par->noindent == noindent &&
1549 par->depth == depth);
1553 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1555 // create a new paragraph
1556 LyXParagraph * par = ParFromPos(pos);
1558 LyXParagraph * tmp = new LyXParagraph(par);
1560 tmp->MakeSameLayout(par);
1562 // When can pos < Last()?
1563 // I guess pos == Last() is possible.
1565 // copy everything behind the break-position to the new
1567 size_type pos_first = 0;
1568 while (ParFromPos(pos_first) != par)
1570 size_type pos_end = pos_first + par->text.size() - 1;
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;
1672 LyXTextClass::size_type LyXParagraph::GetLayout() const
1674 return FirstPhysicalPar()->layout;
1678 char LyXParagraph::GetDepth() const
1680 return FirstPhysicalPar()->depth;
1684 char LyXParagraph::GetAlign() const
1686 return FirstPhysicalPar()->align;
1690 string LyXParagraph::GetLabelstring() const
1692 return FirstPhysicalPar()->labelstring;
1696 int LyXParagraph::GetFirstCounter(int i) const
1698 return FirstPhysicalPar()->counter_[i];
1702 // the next two functions are for the manual labels
1703 string LyXParagraph::GetLabelWidthString() const
1705 if (!FirstPhysicalPar()->labelwidthstring.empty())
1706 return FirstPhysicalPar()->labelwidthstring;
1708 return _("Senseless with this layout!");
1712 void LyXParagraph::SetLabelWidthString(string const & s)
1714 LyXParagraph * par = FirstPhysicalPar();
1716 par->labelwidthstring = s;
1720 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1722 LyXParagraph * par = FirstPhysicalPar();
1723 LyXParagraph * ppar = 0;
1724 LyXParagraph * npar = 0;
1726 par->layout = new_layout;
1727 /* table stuff -- begin*/
1730 /* table stuff -- end*/
1731 if (par->pextra_type == PEXTRA_NONE) {
1732 if (par->Previous()) {
1733 ppar = par->Previous()->FirstPhysicalPar();
1736 && (ppar->depth > par->depth))
1737 ppar = ppar->Previous()->FirstPhysicalPar();
1740 npar = par->Next()->NextAfterFootnote();
1743 && (npar->depth > par->depth))
1744 npar = npar->Next()->NextAfterFootnote();
1746 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1748 p1 = ppar->pextra_width,
1749 p2 = ppar->pextra_widthp;
1750 ppar->SetPExtraType(ppar->pextra_type,
1751 p1.c_str(), p2.c_str());
1753 if ((par->pextra_type == PEXTRA_NONE) &&
1754 npar && (npar->pextra_type != PEXTRA_NONE)) {
1756 p1 = npar->pextra_width,
1757 p2 = npar->pextra_widthp;
1758 npar->SetPExtraType(npar->pextra_type,
1759 p1.c_str(), p2.c_str());
1765 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1768 * par = FirstPhysicalPar(),
1772 par->layout = new_layout;
1773 par->labelwidthstring.clear();
1774 par->align = LYX_ALIGN_LAYOUT;
1775 par->added_space_top = VSpace(VSpace::NONE);
1776 par->added_space_bottom = VSpace(VSpace::NONE);
1777 par->spacing.set(Spacing::Default);
1779 /* table stuff -- begin*/
1782 /* table stuff -- end*/
1783 if (par->pextra_type == PEXTRA_NONE) {
1784 if (par->Previous()) {
1785 ppar = par->Previous()->FirstPhysicalPar();
1788 && (ppar->depth > par->depth))
1789 ppar = ppar->Previous()->FirstPhysicalPar();
1792 npar = par->Next()->NextAfterFootnote();
1795 && (npar->depth > par->depth))
1796 npar = npar->Next()->NextAfterFootnote();
1798 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1800 p1 = ppar->pextra_width,
1801 p2 = ppar->pextra_widthp;
1802 ppar->SetPExtraType(ppar->pextra_type,
1803 p1.c_str(), p2.c_str());
1805 if ((par->pextra_type == PEXTRA_NONE) &&
1806 npar && (npar->pextra_type != PEXTRA_NONE)) {
1808 p1 = npar->pextra_width,
1809 p2 = npar->pextra_widthp;
1810 npar->SetPExtraType(npar->pextra_type,
1811 p1.c_str(), p2.c_str());
1817 // if the layout of a paragraph contains a manual label, the beginning of the
1818 // main body is the beginning of the second word. This is what the par-
1819 // function returns. If the layout does not contain a label, the main
1820 // body always starts with position 0. This differentiation is necessary,
1821 // because there cannot be a newline or a blank <= the beginning of the
1822 // main body in TeX.
1824 int LyXParagraph::BeginningOfMainBody() const
1826 if (FirstPhysicalPar() != this)
1829 // Unroll the first two cycles of the loop
1830 // and remember the previous character to
1831 // remove unnecessary GetChar() calls
1834 && GetChar(i) != LyXParagraph::META_NEWLINE
1837 char previous_char = 0, temp = 0;
1839 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1840 // Yes, this ^ is supposed to be "= " not "=="
1843 && previous_char != ' '
1844 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1846 previous_char = temp;
1851 if (i == 0 && i == size() &&
1852 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1853 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1854 ++i; /* the cursor should not jump
1855 * to the main body if there
1861 LyXParagraph * LyXParagraph::DepthHook(int deth)
1863 LyXParagraph * newpar = this;
1868 newpar = newpar->FirstPhysicalPar()->Previous();
1869 } while (newpar && newpar->GetDepth() > deth
1870 && newpar->footnoteflag == footnoteflag);
1873 if (Previous() || GetDepth())
1874 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1878 return newpar->FirstPhysicalPar();
1882 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1884 LyXParagraph const * newpar = this;
1889 newpar = newpar->FirstPhysicalPar()->Previous();
1890 } while (newpar && newpar->GetDepth() > deth
1891 && newpar->footnoteflag == footnoteflag);
1894 if (Previous() || GetDepth())
1895 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1899 return newpar->FirstPhysicalPar();
1903 int LyXParagraph::AutoDeleteInsets()
1906 InsetList::size_type index = 0;
1907 while (index < insetlist.size()) {
1908 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1909 Erase(insetlist[index].pos);
1910 // Erase() calls to insetlist.erase(&insetlist[index])
1911 // so index shouldn't be increased.
1920 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1922 InsetList::iterator it = lower_bound(insetlist.begin(),
1925 if (it != insetlist.end()) {
1933 // returns -1 if inset not found
1934 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1937 // We could use lower_bound here too, we just need to add
1938 // the approp. operator() to matchIT (and change the name
1939 // of that struct). Code would then be:
1940 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
1942 // inset, matchIT());
1943 // if ((*cit).inset == inset) {
1944 // return (*cit).pos;
1946 for (InsetList::const_iterator cit = insetlist.begin();
1947 cit != insetlist.end(); ++cit) {
1948 if ((*cit).inset == inset) {
1952 // Think about footnotes.
1953 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1954 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1956 NextAfterFootnote()->GetPositionOfInset(inset);
1958 return text.size() + 1 + further;
1964 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1966 TexRow & foot_texrow,
1969 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1970 LyXLayout const & style =
1971 textclasslist.Style(current_view->buffer()->params.textclass,
1974 bool further_blank_line = false;
1976 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1978 if (start_of_appendix) {
1979 os << "\\appendix\n";
1983 if (!spacing.isDefault()
1984 && (!Previous() || !Previous()->HasSameLayout(this))) {
1985 os << spacing.writeEnvirBegin() << "\n";
1989 if (tex_code_break_column && style.isCommand()){
1994 if (pagebreak_top) {
1996 further_blank_line = true;
1998 if (added_space_top.kind() != VSpace::NONE) {
1999 os << added_space_top.asLatexCommand(current_view->buffer()->params);
2000 further_blank_line = true;
2004 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
2005 << "\\vspace{-1\\parskip}";
2006 further_blank_line = true;
2009 if (further_blank_line){
2014 Language const * language = getParLanguage();
2015 Language const * doc_language = current_view->buffer()->params.language_info;
2016 if (language != doc_language) {
2017 os << subst(lyxrc.language_command_begin, "$$lang",
2023 switch (style.latextype) {
2026 << style.latexname()
2027 << style.latexparam();
2029 case LATEX_ITEM_ENVIRONMENT:
2031 bibkey->Latex(os, false, false);
2035 case LATEX_LIST_ENVIRONMENT:
2042 bool need_par = SimpleTeXOnePar(os, texrow);
2044 // Spit out footnotes
2045 LyXParagraph * par = next;
2046 if (lyxrc.rtl_support) {
2047 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2048 && next->footnoteflag != footnoteflag) {
2049 LyXParagraph * p = 0;
2050 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2051 if ( (p = NextAfterFootnote()) != 0 &&
2052 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2053 is_rtl = GetFontSettings(0).isRightToLeft();
2055 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2056 par->footnoteflag != footnoteflag) {
2057 par = par->TeXFootnote(os, texrow, foot,
2058 foot_texrow, foot_count,
2060 par->SimpleTeXOnePar(os, texrow);
2061 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2063 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2064 (p = par->NextAfterFootnote()) != 0 &&
2065 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2066 is_rtl = GetFontSettings(0).isRightToLeft();
2071 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2072 && par->footnoteflag != footnoteflag) {
2073 par = par->TeXFootnote(os, texrow,
2074 foot, foot_texrow, foot_count,
2076 par->SimpleTeXOnePar(os, texrow);
2081 // Make sure that \\par is done with the font of the last
2082 // character if this has another size as the default.
2083 // This is necessary because LaTeX (and LyX on the screen)
2084 // calculates the space between the baselines according
2085 // to this font. (Matthias)
2086 LyXFont font = getFont(Last() - 1);
2088 if (style.resfont.size() != font.size()) {
2094 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2095 GetLayout()).isCommand()){
2096 if (style.resfont.size() != font.size()) {
2102 } else if (style.resfont.size() != font.size()){
2103 os << "{\\" << font.latexSize() << " \\par}";
2106 if (language != doc_language) {
2108 << subst(lyxrc.language_command_end, "$$lang",
2109 doc_language->lang);
2112 switch (style.latextype) {
2113 case LATEX_ITEM_ENVIRONMENT:
2114 case LATEX_LIST_ENVIRONMENT:
2115 if (par && (depth < par->depth)) {
2120 case LATEX_ENVIRONMENT:
2121 // if its the last paragraph of the current environment
2122 // skip it otherwise fall through
2124 && (par->layout != layout
2125 || par->depth != depth
2126 || par->pextra_type != pextra_type))
2129 // we don't need it for the last paragraph!!!
2130 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2131 && footnotekind != LyXParagraph::FOOTNOTE
2132 && footnotekind != LyXParagraph::MARGIN
2136 // don't insert this if we would be adding it
2137 // before or after a table in a float. This
2138 // little trick is needed in order to allow
2139 // use of tables in \subfigures or \subtables.
2145 further_blank_line = false;
2147 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2148 further_blank_line = true;
2151 if (added_space_bottom.kind() != VSpace::NONE) {
2152 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2153 further_blank_line = true;
2156 if (pagebreak_bottom) {
2158 further_blank_line = true;
2161 if (further_blank_line){
2166 if (!spacing.isDefault()
2167 && (!par || !par->HasSameLayout(this))) {
2168 os << spacing.writeEnvirEnd() << "\n";
2172 // we don't need it for the last paragraph!!!
2173 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2174 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2179 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2184 // This one spits out the text of the paragraph
2185 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow)
2187 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2190 return SimpleTeXOneTablePar(os, texrow);
2192 bool return_value = false;
2194 LyXLayout const & style =
2195 textclasslist.Style(current_view->buffer()->params.textclass,
2197 LyXFont basefont, last_font;
2199 // Maybe we have to create a optional argument.
2200 size_type main_body;
2201 if (style.labeltype != LABEL_MANUAL)
2204 main_body = BeginningOfMainBody();
2206 if (main_body > 0) {
2208 basefont = getFont(-2); // Get label font
2210 basefont = getFont(-1); // Get layout font
2218 if (style.isCommand()) {
2221 } else if (align != LYX_ALIGN_LAYOUT) {
2224 return_value = true;
2228 // Which font is currently active?
2229 LyXFont running_font(basefont);
2230 // Do we have an open font change?
2231 bool open_font = false;
2233 texrow.start(this, 0);
2235 for (size_type i = 0; i < size(); ++i) {
2237 // First char in paragraph or after label?
2238 if (i == main_body && !IsDummy()) {
2239 if (main_body > 0) {
2241 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2244 basefont = getFont(-1); // Now use the layout font
2245 running_font = basefont;
2249 if (style.isCommand()) {
2252 } else if (align != LYX_ALIGN_LAYOUT) {
2255 return_value = true;
2259 os << "\\noindent ";
2263 case LYX_ALIGN_NONE:
2264 case LYX_ALIGN_BLOCK:
2265 case LYX_ALIGN_LAYOUT:
2266 case LYX_ALIGN_SPECIAL:
2268 case LYX_ALIGN_LEFT:
2269 if (getParLanguage()->lang != "hebrew") {
2270 os << "\\raggedright ";
2273 os << "\\raggedleft ";
2277 case LYX_ALIGN_RIGHT:
2278 if (getParLanguage()->lang != "hebrew") {
2279 os << "\\raggedleft ";
2282 os << "\\raggedright ";
2286 case LYX_ALIGN_CENTER:
2287 os << "\\centering ";
2295 // Fully instantiated font
2296 LyXFont font = getFont(i);
2297 LyXParagraph * p = 0;
2298 if (i == 0 && previous &&
2299 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2300 (p = PreviousBeforeFootnote()) != 0)
2301 last_font = p->getFont(p->size()-1);
2303 last_font = running_font;
2305 // Spaces at end of font change are simulated to be
2306 // outside font change, i.e. we write "\textXX{text} "
2307 // rather than "\textXX{text }". (Asger)
2308 if (open_font && c == ' ' && i <= size() - 2
2309 && !getFont(i+1).equalExceptLatex(running_font)
2310 && !getFont(i+1).equalExceptLatex(font)) {
2311 font = getFont(i + 1);
2313 // We end font definition before blanks
2314 if (!font.equalExceptLatex(running_font) && open_font) {
2315 column += running_font.latexWriteEndChanges(os,
2317 (i == main_body-1) ? basefont : font);
2318 running_font = basefont;
2322 // Blanks are printed before start of fontswitch
2324 // Do not print the separation of the optional argument
2325 if (i != main_body - 1) {
2326 SimpleTeXBlanks(os, texrow, i,
2327 column, font, style);
2331 // Do we need to change font?
2332 if (!font.equalExceptLatex(running_font)
2333 && i != main_body-1) {
2334 column += font.latexWriteStartChanges(os, basefont,
2336 running_font = font;
2340 if (c == LyXParagraph::META_NEWLINE) {
2341 // newlines are handled differently here than
2342 // the default in SimpleTeXSpecialChars().
2343 if (!style.newline_allowed
2344 || font.latex() == LyXFont::ON) {
2348 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2351 basefont = getFont(-1);
2352 running_font = basefont;
2353 if (font.family() ==
2354 LyXFont::TYPEWRITER_FAMILY) {
2360 texrow.start(this, i + 1);
2363 SimpleTeXSpecialChars(os, texrow,
2364 font, running_font, basefont,
2365 open_font, style, i, column, c);
2369 // If we have an open font definition, we have to close it
2371 LyXParagraph * p = 0;
2372 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2373 && (p = NextAfterFootnote()) != 0)
2374 running_font.latexWriteEndChanges(os, basefont,
2377 running_font.latexWriteEndChanges(os, basefont, basefont);
2380 // Needed if there is an optional argument but no contents.
2381 if (main_body > 0 && main_body == size()) {
2383 return_value = false;
2386 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2387 return return_value;
2391 // This one spits out the text of a table paragraph
2392 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2394 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2396 bool return_value = false;
2398 LyXLayout const & style =
2399 textclasslist.Style(current_view->buffer()->params.textclass,
2403 if (!IsDummy()) { // it is dummy if it is in a float!!!
2404 if (style.isCommand()) {
2407 } else if (align != LYX_ALIGN_LAYOUT) {
2410 return_value = true;
2413 os << "\\noindent ";
2417 case LYX_ALIGN_NONE:
2418 case LYX_ALIGN_BLOCK:
2419 case LYX_ALIGN_LAYOUT:
2420 case LYX_ALIGN_SPECIAL: break;
2421 case LYX_ALIGN_LEFT:
2422 os << "\\raggedright ";
2425 case LYX_ALIGN_RIGHT:
2426 os << "\\raggedleft ";
2429 case LYX_ALIGN_CENTER:
2430 os << "\\centering ";
2436 LyXFont basefont = getFont(-1); // Get layout font
2437 // Which font is currently active?
2438 LyXFont running_font = basefont;
2440 // Do we have an open font change?
2441 bool open_font = false;
2442 int current_cell_number = -1;
2443 int tmp = table->TexEndOfCell(os, current_cell_number);
2444 for (; tmp > 0 ; --tmp)
2447 texrow.start(this, 0);
2449 bool is_rtl = getParLanguage()->RightToLeft;
2450 bool first_in_cell = true;
2452 for (size_type i = 0; i < size(); ++i) {
2453 char c = GetChar(i);
2454 if (table->IsContRow(current_cell_number + 1)) {
2455 if (c == LyXParagraph::META_NEWLINE)
2456 ++current_cell_number;
2461 if (first_in_cell && is_rtl) {
2464 first_in_cell = false;
2467 // Fully instantiated font
2468 LyXFont font = getFont(i);
2469 last_font = running_font;
2471 // Spaces at end of font change are simulated to be
2472 // outside font change.
2473 // i.e. we write "\textXX{text} " rather than
2474 // "\textXX{text }". (Asger)
2475 if (open_font && c == ' ' && i <= size() - 2
2476 && getFont(i + 1) != running_font
2477 && getFont(i + 1) != font) {
2478 font = getFont(i + 1);
2481 // We end font definition before blanks
2482 if (font != running_font && open_font) {
2483 column += running_font.latexWriteEndChanges(os,
2486 running_font = basefont;
2489 // Blanks are printed before start of fontswitch
2491 SimpleTeXBlanks(os, texrow, i, column, font, style);
2493 // Do we need to change font?
2494 if (font != running_font) {
2495 column += font.latexWriteStartChanges(os, basefont,
2497 running_font = font;
2500 // Do we need to turn on LaTeX mode?
2501 if (font.latex() != running_font.latex()) {
2502 if (font.latex() == LyXFont::ON
2503 && style.needprotect) {
2508 if (c == LyXParagraph::META_NEWLINE) {
2509 // special case for inside a table
2510 // different from default case in
2511 // SimpleTeXSpecialChars()
2513 column += running_font
2514 .latexWriteEndChanges(os, basefont,
2518 basefont = getFont(-1);
2519 running_font = basefont;
2520 ++current_cell_number;
2521 if (table->CellHasContRow(current_cell_number) >= 0) {
2522 TeXContTableRows(os, i + 1,
2523 current_cell_number,
2526 if (is_rtl && !first_in_cell) {
2528 first_in_cell = true;
2531 // if this cell follow only ContRows till end don't
2532 // put the EndOfCell because it is put after the
2534 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2535 --current_cell_number;
2538 int tmp = table->TexEndOfCell(os,
2539 current_cell_number);
2542 } else if (tmp < 0) {
2548 texrow.start(this, i + 1);
2550 SimpleTeXSpecialChars(os, texrow,
2551 font, running_font, basefont,
2552 open_font, style, i, column, c);
2556 // If we have an open font definition, we have to close it
2558 running_font.latexWriteEndChanges(os, basefont, basefont);
2560 ++current_cell_number;
2561 if (is_rtl && !first_in_cell)
2563 tmp = table->TexEndOfCell(os, current_cell_number);
2564 for (; tmp > 0; --tmp)
2566 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2567 return return_value;
2571 // This one spits out the text off ContRows in tables
2572 bool LyXParagraph::TeXContTableRows(ostream & os,
2573 LyXParagraph::size_type i,
2574 int current_cell_number,
2575 int & column, TexRow & texrow)
2577 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2583 bool return_value = false;
2584 LyXLayout const & style =
2585 textclasslist.Style(current_view->buffer()->params.textclass,
2587 LyXFont basefont = getFont(-1); // Get layout font
2589 // Which font is currently active?
2590 LyXFont running_font = basefont;
2591 // Do we have an open font change?
2592 bool open_font = false;
2594 size_type lastpos = i;
2595 int cell = table->CellHasContRow(current_cell_number);
2596 ++current_cell_number;
2598 // first find the right position
2600 for (; (i < size()) && (current_cell_number<cell); ++i) {
2602 if (c == LyXParagraph::META_NEWLINE)
2603 ++current_cell_number;
2607 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2611 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2616 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2620 // Fully instantiated font
2621 LyXFont font = getFont(i);
2622 last_font = running_font;
2624 // Spaces at end of font change are simulated to
2625 // be outside font change. i.e. we write
2626 // "\textXX{text} " rather than "\textXX{text }".
2628 if (open_font && c == ' ' && i <= size() - 2
2629 && getFont(i + 1) != running_font
2630 && getFont(i + 1) != font) {
2631 font = getFont(i + 1);
2634 // We end font definition before blanks
2635 if (font != running_font && open_font) {
2636 column += running_font.latexWriteEndChanges(os, basefont, font);
2637 running_font = basefont;
2640 // Blanks are printed before start of fontswitch
2642 SimpleTeXBlanks(os, texrow, i,
2643 column, font, style);
2645 // Do we need to change font?
2646 if (font != running_font) {
2648 font.latexWriteStartChanges(os,
2651 running_font = font;
2654 // Do we need to turn on LaTeX mode?
2655 if (font.latex() != running_font.latex()) {
2656 if (font.latex() == LyXFont::ON
2657 && style.needprotect) {
2662 SimpleTeXSpecialChars(os, texrow, font,
2663 running_font, basefont,
2664 open_font, style, i, column, c);
2666 // If we have an open font definition, we have to close it
2668 running_font.latexWriteEndChanges(os, basefont,
2672 basefont = getFont(-1);
2673 running_font = basefont;
2674 cell = table->CellHasContRow(current_cell_number);
2676 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2677 return return_value;
2681 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2683 bool retval = false;
2685 case LyXParagraph::META_HFILL:
2686 sgml_string.clear();
2688 case LyXParagraph::META_NEWLINE:
2692 sgml_string = "&";
2695 sgml_string = "<";
2698 sgml_string = ">";
2701 sgml_string = "$";
2704 sgml_string = "#";
2707 sgml_string = "%";
2710 sgml_string = "[";
2713 sgml_string = "]";
2716 sgml_string = "{";
2719 sgml_string = "}";
2722 sgml_string = "˜";
2725 sgml_string = """;
2728 sgml_string = "\";
2734 case '\0': // Ignore :-)
2735 sgml_string.clear();
2745 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2746 int & desc_on, int depth)
2749 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2751 LyXFont font1, font2;
2754 size_type main_body;
2755 bool emph_flag = false;
2757 LyXLayout const & style =
2758 textclasslist.Style(current_view->buffer()->params.textclass,
2761 if (style.labeltype != LABEL_MANUAL)
2764 main_body = BeginningOfMainBody();
2766 // Gets paragraph main font.
2768 font1 = style.labelfont;
2772 int char_line_count = depth;
2773 os << newlineAndDepth(depth);
2774 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2775 os << "<INFORMALTABLE>"
2776 << newlineAndDepth(++depth);
2778 int current_cell_number = -1;
2779 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2781 // Parsing main loop.
2782 for (size_type i = 0; i < size(); ++i) {
2784 if (table->IsContRow(current_cell_number+1)) {
2785 if (c == LyXParagraph::META_NEWLINE)
2786 ++current_cell_number;
2791 // Fully instantiated font
2794 // Handle <emphasis> tag.
2795 if (font1.emph() != font2.emph() && i) {
2796 if (font2.emph() == LyXFont::ON) {
2799 } else if (emph_flag) {
2800 os << "</emphasis>";
2804 if (c == LyXParagraph::META_NEWLINE) {
2805 // We have only to control for emphasis open here!
2807 os << "</emphasis>";
2810 font1 = font2 = getFont(-1);
2811 ++current_cell_number;
2812 if (table->CellHasContRow(current_cell_number) >= 0) {
2813 DocBookContTableRows(os, extra, desc_on, i + 1,
2814 current_cell_number,
2817 // if this cell follow only ContRows till end don't
2818 // put the EndOfCell because it is put after the
2820 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2821 --current_cell_number;
2824 tmp = table->DocBookEndOfCell(os,
2825 current_cell_number,
2830 } else if (c == LyXParagraph::META_INSET) {
2831 inset = GetInset(i);
2833 std::ostringstream ost;
2834 inset->DocBook(ost);
2835 string tmp_out = ost.str().c_str();
2838 inset->DocBook(ost);
2840 char * ctmp = ost.str();
2841 string tmp_out(ctmp);
2845 // This code needs some explanation:
2846 // Two insets are treated specially
2847 // label if it is the first element in a
2848 // command paragraph
2850 // graphics inside tables or figure floats
2852 // title (the equivalente in latex for this
2854 // and title should come first
2857 if(desc_on != 3 || i != 0) {
2858 if(tmp_out[0] == '@') {
2860 extra += frontStrip(tmp_out,
2863 os << frontStrip(tmp_out,
2868 } else if (font2.latex() == LyXFont::ON) {
2869 // "TeX"-Mode on == > SGML-Mode on.
2875 if (linuxDocConvertChar(c, sgml_string)
2876 && !style.free_spacing) {
2877 // in freespacing mode, spaces are
2878 // non-breaking characters
2883 << "</term><listitem><para>";
2895 // Needed if there is an optional argument but no contents.
2896 if (main_body > 0 && main_body == size()) {
2901 os << "</emphasis>";
2904 ++current_cell_number;
2905 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2906 // Resets description flag correctly.
2909 // <term> not closed...
2913 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2914 os << "</INFORMALTABLE>";
2916 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2921 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2923 LyXParagraph::size_type i,
2924 int current_cell_number, int &column)
2929 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2934 //string emph = "emphasis";
2935 bool emph_flag = false;
2936 int char_line_count = 0;
2938 LyXLayout const & style =
2939 textclasslist.Style(current_view->buffer()->params.textclass,
2942 size_type main_body;
2943 if (style.labeltype != LABEL_MANUAL)
2946 main_body = BeginningOfMainBody();
2948 // Gets paragraph main font.
2951 font1 = style.labelfont;
2955 size_type lastpos = i;
2956 int cell = table->CellHasContRow(current_cell_number);
2957 ++current_cell_number;
2959 // first find the right position
2961 for (; i < size() && current_cell_number < cell; ++i) {
2963 if (c == LyXParagraph::META_NEWLINE)
2964 ++current_cell_number;
2968 // I don't know how to handle this so I comment it
2969 // for the moment (Jug)
2970 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2971 // file += " \\\\\n";
2974 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2979 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2983 // Fully instantiated font
2986 // Handle <emphasis> tag.
2987 if (font1.emph() != font2.emph() && i) {
2988 if (font2.emph() == LyXFont::ON) {
2991 } else if (emph_flag) {
2992 os << "</emphasis>";
2996 if (c == LyXParagraph::META_INSET) {
2997 inset = GetInset(i);
2999 std::ostringstream ost;
3000 inset->DocBook(ost);
3001 string tmp_out = ost.str().c_str();
3004 inset->DocBook(ost);
3006 char * ctmp = ost.str();
3007 string tmp_out(ctmp);
3011 // This code needs some explanation:
3012 // Two insets are treated specially
3013 // label if it is the first element in a
3014 // command paragraph
3016 // graphics inside tables or figure floats
3017 // can't go on title (the equivalente in
3018 // latex for this case is caption and title
3019 // should come first
3022 if(desc_on != 3 || i != 0) {
3023 if(tmp_out[0] == '@') {
3025 extra += frontStrip(tmp_out, '@');
3027 os << frontStrip(tmp_out, '@');
3031 } else if (font2.latex() == LyXFont::ON) {
3032 // "TeX"-Mode on == > SGML-Mode on.
3038 if (linuxDocConvertChar(c, sgml_string)
3039 && !style.free_spacing) {
3040 // in freespacing mode, spaces are
3041 // non-breaking characters
3046 << "</term><listitem><para>";
3056 // we have only to control for emphasis open here!
3058 os << "</emphasis>";
3061 font1 = font2 = getFont(-1);
3062 cell = table->CellHasContRow(current_cell_number);
3064 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3068 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3069 LyXParagraph::size_type const i,
3070 int & column, LyXFont const & font,
3071 LyXLayout const & style)
3073 if (column > tex_code_break_column
3075 && GetChar(i - 1) != ' '
3077 // In LaTeX mode, we don't want to
3078 // break lines since some commands
3080 && ! (font.latex() == LyXFont::ON)
3081 // same in FreeSpacing mode
3082 && !style.free_spacing
3083 // In typewriter mode, we want to avoid
3084 // ! . ? : at the end of a line
3085 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3086 && (GetChar(i-1) == '.'
3087 || GetChar(i-1) == '?'
3088 || GetChar(i-1) == ':'
3089 || GetChar(i-1) == '!'))) {
3090 if (tex_code_break_column == 0) {
3091 // in batchmode we need LaTeX to still
3092 // see it as a space not as an extra '\n'
3098 texrow.start(this, i + 1);
3100 } else if (font.latex() == LyXFont::OFF) {
3101 if (style.free_spacing) {
3110 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3112 LyXFont & running_font,
3115 LyXLayout const & style,
3116 LyXParagraph::size_type & i,
3117 int & column, char const c)
3119 // Two major modes: LaTeX or plain
3120 // Handle here those cases common to both modes
3121 // and then split to handle the two modes separately.
3123 case LyXParagraph::META_INSET: {
3124 Inset * inset = GetInset(i);
3127 int len = os.tellp();
3128 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3129 || inset->LyxCode() == Inset::MATH_CODE
3130 || inset->LyxCode() == Inset::URL_CODE)
3131 && running_font.isRightToLeft()) {
3136 int tmp = inset->Latex(os, style.isCommand(),
3137 style.free_spacing);
3145 column += os.tellp() - len;
3154 case LyXParagraph::META_NEWLINE:
3156 column += running_font.latexWriteEndChanges(os,
3161 basefont = getFont(-1);
3162 running_font = basefont;
3165 case LyXParagraph::META_HFILL:
3171 // And now for the special cases within each mode
3172 // Are we in LaTeX mode?
3173 if (font.latex() == LyXFont::ON) {
3174 // at present we only have one option
3175 // but I'll leave it as a switch statement
3176 // so its simpler to extend. (ARRae)
3179 // make sure that we will not print
3180 // error generating chars to the tex
3181 // file. This test would not be needed
3182 // if it were done in the buffer
3190 // Plain mode (i.e. not LaTeX)
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))) {
3402 stringstream ss(ios::in | ios::out);
3429 case LyXParagraph::META_NEWLINE:
3431 case LyXParagraph::META_HFILL:
3440 lyxerr.debug() << "RoffAsciiTable: "
3441 "NULL char in structure."
3446 cell = table->CellHasContRow(actcell);
3453 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3455 TexRow & foot_texrow,
3458 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3459 LyXParagraph * par = this;
3462 (par->depth == depth) &&
3463 (par->footnoteflag == footnoteflag)) {
3465 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3466 if (textclasslist.Style(current_view->buffer()->params.textclass,
3467 par->layout).isEnvironment()
3468 || par->pextra_type != PEXTRA_NONE) {
3469 par = par->TeXEnvironment(os, texrow,
3473 par = par->TeXOnePar(os, texrow,
3478 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3484 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3486 TexRow & foot_texrow,
3489 bool eindent_open = false;
3490 bool foot_this_level = false;
3491 // flags when footnotetext should be appended to file.
3492 static bool minipage_open = false;
3493 static int minipage_open_depth = 0;
3494 char par_sep = current_view->buffer()->params.paragraph_separation;
3496 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3498 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3500 LyXLayout const & style =
3501 textclasslist.Style(current_view->buffer()->params.textclass,
3504 if (pextra_type == PEXTRA_INDENT) {
3505 if (!pextra_width.empty()) {
3506 os << "\\begin{LyXParagraphIndent}{"
3507 << pextra_width << "}\n";
3509 //float ib = atof(pextra_widthp.c_str())/100;
3510 // string can't handle floats at present (971109)
3511 // so I'll do a conversion by hand knowing that
3512 // the limits are 0.0 to 1.0. ARRae.
3513 os << "\\begin{LyXParagraphIndent}{";
3514 switch (pextra_widthp.length()) {
3526 os << "\\columnwidth}\n";
3529 eindent_open = true;
3531 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3532 if (pextra_hfill && Previous() &&
3533 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3534 os << "\\hfill{}\n";
3537 if (par_sep == BufferParams::PARSEP_INDENT) {
3538 os << "{\\setlength\\parindent{0pt}\n";
3541 os << "\\begin{minipage}";
3542 switch(pextra_alignment) {
3543 case MINIPAGE_ALIGN_TOP:
3546 case MINIPAGE_ALIGN_MIDDLE:
3549 case MINIPAGE_ALIGN_BOTTOM:
3553 if (!pextra_width.empty()) {
3554 os << '{' << pextra_width << "}\n";
3556 //float ib = atof(par->pextra_width.c_str())/100;
3557 // string can't handle floats at present
3558 // so I'll do a conversion by hand knowing that
3559 // the limits are 0.0 to 1.0. ARRae.
3561 switch (pextra_widthp.length()) {
3573 os << "\\columnwidth}\n";
3576 if (par_sep == BufferParams::PARSEP_INDENT) {
3577 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3580 minipage_open = true;
3581 minipage_open_depth = depth;
3584 #ifdef WITH_WARNINGS
3585 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3586 //I disabled it because it breaks when lists span on several
3589 if (style.isEnvironment()){
3590 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3591 #ifdef FANCY_FOOTNOTE_CODE
3592 if (foot_count < 0) {
3593 // flag that footnote[mark][text] should be
3594 // used for any footnotes from now on
3596 foot_this_level = true;
3599 os << "\\begin{" << style.latexname() << "}{"
3600 << labelwidthstring << "}\n";
3601 } else if (style.labeltype == LABEL_BIBLIO) {
3603 os << "\\begin{" << style.latexname() << "}{"
3604 << bibitemWidthest(current_view->painter())
3606 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3607 #ifdef FANCY_FOOTNOTE_CODE
3608 if (foot_count < 0) {
3609 // flag that footnote[mark][text] should be
3610 // used for any footnotes from now on
3612 foot_this_level = true;
3615 os << "\\begin{" << style.latexname() << '}'
3616 << style.latexparam() << '\n';
3618 os << "\\begin{" << style.latexname() << '}'
3619 << style.latexparam() << '\n';
3622 LyXParagraph * par = this;
3624 par = par->TeXOnePar(os, texrow,
3625 foot, foot_texrow, foot_count);
3627 if (minipage_open && par && !style.isEnvironment() &&
3628 (par->pextra_type == PEXTRA_MINIPAGE) &&
3629 par->pextra_start_minipage) {
3630 os << "\\end{minipage}\n";
3632 if (par_sep == BufferParams::PARSEP_INDENT) {
3636 minipage_open = false;
3638 if (par && par->depth > depth) {
3639 if (textclasslist.Style(current_view->buffer()->params.textclass,
3640 par->layout).isParagraph()
3643 // How to handle this? (Lgb)
3644 //&& !suffixIs(os, "\n\n")
3646 // There should be at least one '\n' already
3647 // but we need there to be two for Standard
3648 // paragraphs that are depth-increment'ed to be
3649 // output correctly. However, tables can
3650 // also be paragraphs so don't adjust them.
3653 // Will it ever harm to have one '\n' too
3654 // many? i.e. that we sometimes will have
3655 // three in a row. (Lgb)
3659 par = par->TeXDeeper(os, texrow,
3660 foot, foot_texrow, foot_count);
3662 if (par && par->layout == layout && par->depth == depth &&
3663 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3664 if (par->pextra_hfill && par->Previous() &&
3665 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3666 os << "\\hfill{}\n";
3669 if (par_sep == BufferParams::PARSEP_INDENT) {
3670 os << "{\\setlength\\parindent{0pt}\n";
3673 os << "\\begin{minipage}";
3674 switch(par->pextra_alignment) {
3675 case MINIPAGE_ALIGN_TOP:
3678 case MINIPAGE_ALIGN_MIDDLE:
3681 case MINIPAGE_ALIGN_BOTTOM:
3685 if (!par->pextra_width.empty()) {
3686 os << '{' << par->pextra_width << "}\n";
3688 //float ib = atof(par->pextra_widthp.c_str())/100;
3689 // string can't handle floats at present
3690 // so I'll do a conversion by hand knowing that
3691 // the limits are 0.0 to 1.0. ARRae.
3693 switch (par->pextra_widthp.length()) {
3698 os << "0." << par->pextra_widthp;
3701 os << "0.0" << par->pextra_widthp;
3703 os << "\\columnwidth}\n";
3706 if (par_sep == BufferParams::PARSEP_INDENT) {
3707 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3710 minipage_open = true;
3711 minipage_open_depth = par->depth;
3714 && par->layout == layout
3715 && par->depth == depth
3716 && par->pextra_type == pextra_type
3717 && par->footnoteflag == footnoteflag);
3719 if (style.isEnvironment()) {
3720 os << "\\end{" << style.latexname() << '}';
3721 // maybe this should go after the minipage closes?
3722 if (foot_this_level) {
3723 if (foot_count >= 1) {
3724 if (foot_count > 1) {
3725 os << "\\addtocounter{footnote}{-"
3730 texrow += foot_texrow;
3732 foot_texrow.reset();
3737 if (minipage_open && (minipage_open_depth == depth) &&
3738 (!par || par->pextra_start_minipage ||
3739 par->pextra_type != PEXTRA_MINIPAGE)) {
3740 os << "\\end{minipage}\n";
3742 if (par_sep == BufferParams::PARSEP_INDENT) {
3746 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3747 os << "\\medskip\n\n";
3751 minipage_open = false;
3754 os << "\\end{LyXParagraphIndent}\n";
3757 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3758 && par->pextra_hfill)) {
3762 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3763 return par; // ale970302
3767 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3768 ostream & foot, TexRow & foot_texrow,
3772 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3773 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3774 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3775 "No footnote!" << endl;
3777 LyXParagraph * par = this;
3778 LyXLayout const & style =
3779 textclasslist.Style(current_view->buffer()->params.textclass,
3780 previous->GetLayout());
3782 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3783 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3784 "Float other than footnote in command"
3785 " with moving argument is illegal" << endl;
3788 if (footnotekind != LyXParagraph::FOOTNOTE
3789 && footnotekind != LyXParagraph::MARGIN
3792 // How to solve this?
3793 //&& !suffixIs(file, '\n')
3795 // we need to ensure that real floats like tables and figures
3796 // have their \begin{} on a new line otherwise we can get
3797 // incorrect results when using the endfloat.sty package
3798 // especially if two floats follow one another. ARRae 981022
3799 // NOTE: if the file is length 0 it must have just been
3800 // written out so we assume it ended with a '\n'
3802 // As far as I can see there is never any harm in writing
3803 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3808 bool need_closing = false;
3809 bool is_rtl = isRightToLeftPar();
3810 if (is_rtl != parent_is_rtl) {
3815 need_closing = true;
3818 BufferParams * params = ¤t_view->buffer()->params;
3819 bool footer_in_body = true;
3820 switch (footnotekind) {
3821 case LyXParagraph::FOOTNOTE:
3822 if (style.intitle) {
3823 os << "\\thanks{\n";
3824 footer_in_body = false;
3826 if (foot_count == -1) {
3827 // we're at depth 0 so we can use:
3828 os << "\\footnote{%\n";
3829 footer_in_body = false;
3831 os << "\\footnotemark{}%\n";
3833 // we only need this when there are
3834 // multiple footnotes
3835 os << "\\stepcounter{footnote}";
3837 os << "\\footnotetext{%\n";
3838 foot_texrow.start(this, 0);
3839 foot_texrow.newline();
3844 case LyXParagraph::MARGIN:
3845 os << "\\marginpar{\n";
3847 case LyXParagraph::FIG:
3848 if (pextra_type == PEXTRA_FLOATFLT
3849 && (!pextra_width.empty()
3850 || !pextra_widthp.empty())) {
3851 if (!pextra_width.empty())
3852 os << "\\begin{floatingfigure}{"
3853 << pextra_width << "}\n";
3855 os << "\\begin{floatingfigure}{"
3856 << atoi(pextra_widthp.c_str())/100.0
3857 << "\\textwidth}\n";
3859 os << "\\begin{figure}";
3860 if (!params->float_placement.empty()) {
3861 os << '[' << params->float_placement << "]\n";
3867 case LyXParagraph::TAB:
3868 os << "\\begin{table}";
3869 if (!params->float_placement.empty()) {
3870 os << '[' << params->float_placement << "]\n";
3875 case LyXParagraph::WIDE_FIG:
3876 os << "\\begin{figure*}";
3877 if (!params->float_placement.empty()) {
3878 os << '[' << params->float_placement << "]\n";
3883 case LyXParagraph::WIDE_TAB:
3884 os << "\\begin{table*}";
3885 if (!params->float_placement.empty()) {
3886 os << '[' << params->float_placement << "]\n";
3891 case LyXParagraph::ALGORITHM:
3892 os << "\\begin{algorithm}\n";
3897 if (footnotekind != LyXParagraph::FOOTNOTE
3898 || !footer_in_body) {
3899 // Process text for all floats except footnotes in body
3901 LyXLayout const & style =
3903 .Style(current_view->buffer()->params
3907 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3909 if (style.isEnvironment()
3910 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3911 // Allows the use of minipages within float
3912 // environments. Shouldn't be circular because
3913 // we don't support footnotes inside
3914 // floats (yet). ARRae
3915 par = par->TeXEnvironment(os, texrow,
3919 par = par->TeXOnePar(os, texrow,
3924 if (par && !par->IsDummy() && par->depth > depth) {
3925 par = par->TeXDeeper(os, texrow,
3929 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3931 // process footnotes > depth 0 or in environments separately
3932 // NOTE: Currently don't support footnotes within footnotes
3933 // even though that is possible using the \footnotemark
3935 std::ostringstream dummy;
3939 TexRow dummy_texrow;
3940 int dummy_count = 0;
3942 LyXLayout const & style =
3944 .Style(current_view->buffer()->params
3948 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3950 if (style.isEnvironment()
3951 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3952 // Allows the use of minipages within float
3953 // environments. Shouldn't be circular because
3954 // we don't support footnotes inside
3955 // floats (yet). ARRae
3956 par = par->TeXEnvironment(foot, foot_texrow,
3957 dummy, dummy_texrow,
3960 par = par->TeXOnePar(foot, foot_texrow,
3961 dummy, dummy_texrow,
3965 if (par && !par->IsDummy() && par->depth > depth) {
3966 par = par->TeXDeeper(foot, foot_texrow,
3967 dummy, dummy_texrow,
3971 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3973 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3974 "Footnote in a Footnote -- not supported"
3977 #ifndef HAVE_OSTREAM
3978 delete [] dummy.str();
3982 switch (footnotekind) {
3983 case LyXParagraph::FOOTNOTE:
3984 if (footer_in_body) {
3985 // This helps tell which of the multiple
3986 // footnotetexts an error was in.
3988 foot_texrow.newline();
3993 case LyXParagraph::MARGIN:
3996 case LyXParagraph::FIG:
3997 if (pextra_type == PEXTRA_FLOATFLT
3998 && (!pextra_width.empty()
3999 || !pextra_widthp.empty()))
4000 os << "\\end{floatingfigure}";
4002 os << "\\end{figure}";
4004 case LyXParagraph::TAB:
4005 os << "\\end{table}";
4007 case LyXParagraph::WIDE_FIG:
4008 os << "\\end{figure*}";
4010 case LyXParagraph::WIDE_TAB:
4011 os << "\\end{table*}";
4013 case LyXParagraph::ALGORITHM:
4014 os << "\\end{algorithm}";
4021 if (footnotekind != LyXParagraph::FOOTNOTE
4022 && footnotekind != LyXParagraph::MARGIN) {
4023 // we need to ensure that real floats like tables and figures
4024 // have their \end{} on a line of their own otherwise we can
4025 // get incorrect results when using the endfloat.sty package.
4030 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4035 bool LyXParagraph::IsDummy() const
4037 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4038 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4042 void LyXParagraph::SetPExtraType(int type, char const * width,
4043 char const * widthp)
4046 pextra_width = width;
4047 pextra_widthp = widthp;
4049 if (textclasslist.Style(current_view->buffer()->params.textclass,
4050 layout).isEnvironment()) {
4055 while (par && (par->layout == layout)
4056 && (par->depth == depth)) {
4058 par = par->Previous();
4060 par = par->FirstPhysicalPar();
4061 while (par && par->depth > depth) {
4062 par = par->Previous();
4064 par = par->FirstPhysicalPar();
4068 while (par && (par->layout == layout)
4069 && (par->depth == depth)) {
4070 par->pextra_type = type;
4071 par->pextra_width = width;
4072 par->pextra_widthp = widthp;
4073 par = par->NextAfterFootnote();
4074 if (par && (par->depth > depth))
4075 par->SetPExtraType(type, width, widthp);
4076 while (par && ((par->depth > depth) || par->IsDummy()))
4077 par = par->NextAfterFootnote();
4083 void LyXParagraph::UnsetPExtraType()
4085 if (pextra_type == PEXTRA_NONE)
4088 pextra_type = PEXTRA_NONE;
4089 pextra_width.clear();
4090 pextra_widthp.clear();
4092 if (textclasslist.Style(current_view->buffer()->params.textclass,
4093 layout).isEnvironment()) {
4098 while (par && (par->layout == layout)
4099 && (par->depth == depth)) {
4101 par = par->Previous();
4103 par = par->FirstPhysicalPar();
4104 while (par && par->depth > depth) {
4105 par = par->Previous();
4107 par = par->FirstPhysicalPar();
4111 while (par && (par->layout == layout)
4112 && (par->depth == depth)) {
4113 par->pextra_type = PEXTRA_NONE;
4114 par->pextra_width.clear();
4115 par->pextra_widthp.clear();
4116 par = par->NextAfterFootnote();
4117 if (par && (par->depth > depth))
4118 par->UnsetPExtraType();
4119 while (par && ((par->depth > depth) || par->IsDummy()))
4120 par = par->NextAfterFootnote();
4126 bool LyXParagraph::IsHfill(size_type pos) const
4128 return IsHfillChar(GetChar(pos));
4132 bool LyXParagraph::IsInset(size_type pos) const
4134 return IsInsetChar(GetChar(pos));
4138 bool LyXParagraph::IsFloat(size_type pos) const
4140 return IsFloatChar(GetChar(pos));
4144 bool LyXParagraph::IsNewline(size_type pos) const
4146 return pos >= 0 && IsNewlineChar(GetChar(pos));
4150 bool LyXParagraph::IsSeparator(size_type pos) const
4152 return IsSeparatorChar(GetChar(pos));
4156 bool LyXParagraph::IsLineSeparator(size_type pos) const
4158 return IsLineSeparatorChar(GetChar(pos));
4162 bool LyXParagraph::IsKomma(size_type pos) const
4164 return IsKommaChar(GetChar(pos));
4168 /// Used by the spellchecker
4169 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4171 unsigned char c = GetChar(pos);
4172 if (IsLetterChar(c))
4174 // '\0' is not a letter, allthough every string contains "" (below)
4177 // We want to pass the ' and escape chars to ispell
4178 string extra = lyxrc.isp_esc_chars + '\'';
4182 return contains(extra, ch);
4186 bool LyXParagraph::IsWord(size_type pos ) const
4188 return IsWordChar(GetChar(pos)) ;
4192 Language const * LyXParagraph::getParLanguage() const
4196 return FirstPhysicalPar()->GetFirstFontSettings()
4199 for (size_type pos = 0; pos < size(); ++pos)
4201 return GetFontSettings(pos).language();
4202 return GetFirstFontSettings().language();
4205 return previous->getParLanguage();
4207 return current_view->buffer()->params.language_info;
4211 bool LyXParagraph::isRightToLeftPar() const
4213 return lyxrc.rtl_support && !table && getParLanguage()->RightToLeft;
4217 void LyXParagraph::ChangeLanguage(Language const * from, Language const * to)
4219 for(size_type i = 0; i < size(); ++i) {
4220 LyXFont font = GetFontSettings(i);
4221 if (font.language() == from) {
4222 font.setLanguage(to);
4229 bool LyXParagraph::isMultiLingual()
4231 Language const * doc_language =
4232 current_view->buffer()->params.language_info;
4233 for(size_type i = 0; i < size(); ++i) {
4234 LyXFont font = GetFontSettings(i);
4235 if (font.language() != doc_language)