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"
41 using std::lower_bound;
42 using std::upper_bound;
44 int tex_code_break_column = 72; // needs non-zero initialization. set later.
45 // this is a bad idea, but how can LyXParagraph find its buffer to get
46 // parameters? (JMarc)
47 extern BufferView * current_view;
51 extern string bibitemWidthest(Painter &);
53 // this is a minibuffer
54 static char minibuffer_char;
55 static LyXFont minibuffer_font;
56 static Inset * minibuffer_inset;
59 // Initialization of the counter for the paragraph id's,
60 // declared in lyxparagraph.h
61 unsigned int LyXParagraph::paragraph_id = 0;
64 LyXParagraph::LyXParagraph()
66 text.reserve(500); // is this number too big?
68 for (int i = 0; i < 10; ++i) setCounter(i , 0);
74 footnoteflag = LyXParagraph::NO_FOOTNOTE;
75 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
77 align = LYX_ALIGN_BLOCK;
79 /* table stuff -- begin*/
81 /* table stuff -- end*/
84 bibkey = 0; // ale970302
89 // This konstruktor inserts the new paragraph in a list.
90 LyXParagraph::LyXParagraph(LyXParagraph * par)
93 par->text.resize(par->text.size());
95 for (int i = 0; i < 10; ++i) setCounter(i, 0);
99 // double linked list begin
102 next->previous = this;
104 previous->next = this;
106 footnoteflag = LyXParagraph::NO_FOOTNOTE;
107 footnotekind = LyXParagraph::FOOTNOTE;
109 /* table stuff -- begin*/
111 /* table stuff -- end*/
113 id_ = paragraph_id++;
115 bibkey = 0; // ale970302
121 void LyXParagraph::writeFile(ostream & os, BufferParams const & params,
122 char footflag, char dth) const
124 LyXFont font1, font2;
129 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
131 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
133 // The beginning or the end of a footnote environment?
134 if (footflag != footnoteflag) {
135 footflag = footnoteflag;
137 os << "\n\\begin_float "
138 << string_footnotekinds[footnotekind]
141 os << "\n\\end_float ";
145 // The beginning or end of a deeper (i.e. nested) area?
148 while (depth > dth) {
149 os << "\n\\begin_deeper ";
153 while (depth < dth) {
154 os << "\n\\end_deeper ";
160 // First write the layout
162 << textclasslist.NameOfLayout(params.textclass, layout)
165 // Maybe some vertical spaces.
166 if (added_space_top.kind() != VSpace::NONE)
167 os << "\\added_space_top "
168 << added_space_top.asLyXCommand() << " ";
169 if (added_space_bottom.kind() != VSpace::NONE)
170 os << "\\added_space_bottom "
171 << added_space_bottom.asLyXCommand() << " ";
173 // Maybe the paragraph has special spacing
174 spacing.writeFile(os, true);
176 // The labelwidth string used in lists.
177 if (!labelwidthstring.empty())
178 os << "\\labelwidthstring "
179 << labelwidthstring << '\n';
181 // Lines above or below?
185 os << "\\line_bottom ";
187 // Pagebreaks above or below?
189 os << "\\pagebreak_top ";
190 if (pagebreak_bottom)
191 os << "\\pagebreak_bottom ";
193 // Start of appendix?
194 if (start_of_appendix)
195 os << "\\start_of_appendix ";
202 if (align != LYX_ALIGN_LAYOUT) {
204 case LYX_ALIGN_LEFT: h = 1; break;
205 case LYX_ALIGN_RIGHT: h = 2; break;
206 case LYX_ALIGN_CENTER: h = 3; break;
207 default: h = 0; break;
209 os << "\\align " << string_align[h] << " ";
211 if (pextra_type != PEXTRA_NONE) {
212 os << "\\pextra_type " << pextra_type;
213 if (pextra_type == PEXTRA_MINIPAGE) {
214 os << " \\pextra_alignment "
217 os << " \\pextra_hfill "
219 if (pextra_start_minipage)
220 os << " \\pextra_start_minipage "
221 << pextra_start_minipage;
223 if (!pextra_width.empty()) {
224 os << " \\pextra_width "
225 << VSpace(pextra_width).asLyXCommand();
226 } else if (!pextra_widthp.empty()) {
227 os << " \\pextra_widthp "
233 // Dummy layout. This means that a footnote ended.
234 os << "\n\\end_float ";
235 footflag = LyXParagraph::NO_FOOTNOTE;
238 // It might be a table.
240 os << "\\LyXTable\n";
248 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
251 for (size_type i = 0; i < size(); ++i) {
257 // Write font changes
258 font2 = GetFontSettings(i);
259 if (font2 != font1) {
260 font2.lyxWriteChanges(font1, os);
269 Inset const * inset = GetInset(i);
271 if (inset->DirectWrite()) {
272 // international char, let it write
273 // code directly so it's shorter in
277 os << "\n\\begin_inset ";
279 os << "\n\\end_inset \n\n";
285 os << "\n\\newline \n";
289 os << "\n\\hfill \n";
293 os << "\n\\backslash \n";
297 if (i + 1 < size() && GetChar(i + 1) == ' ') {
304 if ((column > 70 && c == ' ')
309 // this check is to amend a bug. LyX sometimes
310 // inserts '\0' this could cause problems.
314 lyxerr << "ERROR (LyXParagraph::writeFile):"
315 " NULL char in structure." << endl;
321 // now write the next paragraph
323 next->writeFile(os, params, footflag, dth);
327 void LyXParagraph::validate(LaTeXFeatures & features) const
329 BufferParams const & params = features.bufferParams();
331 // this will be useful later
332 LyXLayout const & layout =
333 textclasslist.Style(params.textclass,
337 if (line_top || line_bottom)
338 features.lyxline = true;
339 if (!spacing.isDefault())
340 features.setspace = true;
343 features.layout[GetLayout()] = true;
346 Language const * doc_language = params.language_info;
348 for (FontList::const_iterator cit = fontlist.begin();
349 cit != fontlist.end(); ++cit) {
350 if ((*cit).font.noun() == LyXFont::ON) {
351 lyxerr[Debug::LATEX] << "font.noun: "
352 << (*cit).font.noun()
354 features.noun = true;
355 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
356 << (*cit).font.stateText()
359 switch ((*cit).font.color()) {
361 case LColor::inherit:
365 features.color = true;
366 lyxerr[Debug::LATEX] << "Color enabled. Font: "
367 << (*cit).font.stateText()
370 Language const * language = (*cit).font.language();
371 if (language != doc_language && language != default_language) {
372 features.UsedLanguages.insert(language);
373 lyxerr[Debug::LATEX] << "Found language "
374 << language->lang << endl;
379 for (InsetList::const_iterator cit = insetlist.begin();
380 cit != insetlist.end(); ++cit) {
382 (*cit).inset->Validate(features);
385 if (table && table->IsLongTable())
386 features.longtable = true;
387 if (pextra_type == PEXTRA_INDENT)
388 features.LyXParagraphIndent = true;
389 if (pextra_type == PEXTRA_FLOATFLT)
390 features.floatflt = true;
391 if (layout.needprotect
392 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
393 features.NeedLyXFootnoteCode = true;
394 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
395 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
396 features.NeedLyXMinipageIndent = true;
397 if (table && table->NeedRotating())
398 features.rotating = true;
399 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
400 features.algorithm = true;
404 // First few functions needed for cut and paste and paragraph breaking.
405 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
407 minibuffer_char = GetChar(pos);
408 minibuffer_font = GetFontSettings(pos);
409 minibuffer_inset = 0;
410 if (minibuffer_char == LyXParagraph::META_INSET) {
412 minibuffer_inset = GetInset(pos)->Clone();
414 minibuffer_inset = 0;
415 minibuffer_char = ' ';
416 // This reflects what GetInset() does (ARRae)
422 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
424 minibuffer_char = GetChar(pos);
425 minibuffer_font = GetFontSettings(pos);
426 minibuffer_inset = 0;
427 if (minibuffer_char == LyXParagraph::META_INSET) {
429 minibuffer_inset = GetInset(pos);
430 // This is a little hack since I want exactly
431 // the inset, not just a clone. Otherwise
432 // the inset would be deleted when calling Erase(pos)
434 InsetList::iterator it = lower_bound(insetlist.begin(),
437 if (it != insetlist.end() && (*it).pos == pos)
440 minibuffer_inset = 0;
441 minibuffer_char = ' ';
442 // This reflects what GetInset() does (ARRae)
447 // Erase(pos); now the caller is responsible for that.
451 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
453 if ((minibuffer_char == LyXParagraph::META_INSET) &&
454 !InsertInsetAllowed(minibuffer_inset))
456 InsertChar(pos, minibuffer_char);
457 SetFont(pos, minibuffer_font);
458 if (minibuffer_char == LyXParagraph::META_INSET)
459 InsertInset(pos, minibuffer_inset);
467 void LyXParagraph::Clear()
472 pagebreak_top = false;
473 pagebreak_bottom = false;
475 added_space_top = VSpace(VSpace::NONE);
476 added_space_bottom = VSpace(VSpace::NONE);
477 spacing.set(Spacing::Default);
479 align = LYX_ALIGN_LAYOUT;
483 pextra_type = PEXTRA_NONE;
484 pextra_width.erase();
485 pextra_widthp.erase();
486 pextra_alignment = MINIPAGE_ALIGN_TOP;
487 pextra_hfill = false;
488 pextra_start_minipage = false;
491 labelwidthstring.erase();
495 start_of_appendix = false;
499 // the destructor removes the new paragraph from the list
500 LyXParagraph::~LyXParagraph()
503 previous->next = next;
505 next->previous = previous;
507 for (InsetList::iterator it = insetlist.begin();
508 it != insetlist.end(); ++it) {
512 /* table stuff -- begin*/
514 /* table stuff -- end*/
519 //lyxerr << "LyXParagraph::paragraph_id = "
520 // << LyXParagraph::paragraph_id << endl;
524 void LyXParagraph::Erase(LyXParagraph::size_type pos)
526 // > because last is the next unused position, and you can
527 // use it if you want
529 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
530 NextAfterFootnote()->Erase(pos - text.size() - 1);
532 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
533 "position does not exist." << endl;
536 if (pos < size()) { // last is free for insertation, but should be empty
537 // if it is an inset, delete the inset entry
538 if (text[pos] == LyXParagraph::META_INSET) {
540 InsetList::iterator it = lower_bound(insetlist.begin(),
543 if (it != insetlist.end() && (*it).pos == pos) {
548 text.erase(text.begin() + pos);
549 // Erase entries in the tables.
550 for (FontList::iterator it = fontlist.begin();
551 it != fontlist.end(); ++it) {
552 if (pos >= (*it).pos && pos <= (*it).pos_end) {
553 if ((*it).pos == (*it).pos_end) {
554 // If it is a multi-character font
555 // entry, we just make it smaller
556 // (see update below), otherwise we
563 // Update all other entries.
564 for (FontList::iterator it = fontlist.begin();
565 it != fontlist.end(); ++it) {
568 if ((*it).pos_end >= pos)
572 // Update the inset table.
573 for (InsetList::iterator it = upper_bound(insetlist.begin(),
576 it != insetlist.end(); ++it)
579 lyxerr << "ERROR (LyXParagraph::Erase): "
580 "can't erase non-existant char." << endl;
585 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
587 // > because last is the next unused position, and you can
588 // use it if you want
591 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
592 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
595 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
596 "position does not exist." << endl;
599 text.insert(text.begin() + pos, c);
600 // Update the font table.
601 for (FontList::iterator it = fontlist.begin();
602 it != fontlist.end(); ++it) {
603 if ((*it).pos >= pos)
605 if ((*it).pos_end >= pos)
609 // Update the inset table.
610 for (InsetList::iterator it = lower_bound(insetlist.begin(),
613 it != insetlist.end(); ++it)
618 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
621 // > because last is the next unused position, and you can
622 // use it if you want
625 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
627 ->InsertInset(pos - text.size() - 1, inset);
629 lyxerr << "ERROR (LyXParagraph::InsertInset): "
630 "position does not exist: " << pos << endl;
633 if (text[pos] != LyXParagraph::META_INSET) {
634 lyxerr << "ERROR (LyXParagraph::InsertInset): "
635 "there is no LyXParagraph::META_INSET" << endl;
640 // Add a new entry in the inset table.
641 InsetList::iterator it = lower_bound(insetlist.begin(),
644 if (it != insetlist.end() && (*it).pos == pos)
645 lyxerr << "ERROR (LyXParagraph::InsertInset): "
646 "there is an inset in position: " << pos << endl;
648 insetlist.insert(it, InsetTable(pos,inset));
650 inset->setOwner(inset_owner);
655 bool LyXParagraph::InsertInsetAllowed(Inset *inset)
658 printf("CODE:%d\n",inset->LyxCode());
659 return inset_owner->InsertInsetAllowed(inset);
664 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
668 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
669 return NextAfterFootnote()
670 ->GetInset(pos - text.size() - 1);
672 lyxerr << "ERROR (LyXParagraph::GetInset): "
673 "position does not exist: "
679 InsetList::iterator it = lower_bound(insetlist.begin(),
682 if (it != insetlist.end() && (*it).pos == pos)
685 lyxerr << "ERROR (LyXParagraph::GetInset): "
686 "Inset does not exist: " << pos << endl;
687 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
688 // Did this commenting out introduce a bug? So far I have not
689 // see any, please enlighten me. (Lgb)
690 // My guess is that since the inset does not exist, we might
691 // as well replace it with a space to prevent craches. (Asger)
696 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
700 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
701 return NextAfterFootnote()
702 ->GetInset(pos - text.size() - 1);
704 lyxerr << "ERROR (LyXParagraph::GetInset): "
705 "position does not exist: "
711 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
714 if (cit != insetlist.end() && (*cit).pos == pos)
717 lyxerr << "ERROR (LyXParagraph::GetInset): "
718 "Inset does not exist: " << pos << endl;
719 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
720 // Did this commenting out introduce a bug? So far I have not
721 // see any, please enlighten me. (Lgb)
722 // My guess is that since the inset does not exist, we might
723 // as well replace it with a space to prevent craches. (Asger)
728 // Gets uninstantiated font setting at position.
729 // Optimized after profiling. (Asger)
730 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
733 #ifdef SORTED_FONT_LIST
734 for (FontList::const_iterator cit = fontlist.begin();
735 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
736 if (pos >= (*cit).pos)
739 for (FontList::const_iterator cit = fontlist.begin();
740 cit != fontlist.end(); ++cit)
741 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
745 // > because last is the next unused position, and you can
746 // use it if you want
747 else if (pos > size()) {
749 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
750 return NextAfterFootnote()
751 ->GetFontSettings(pos - text.size() - 1);
753 // Why is it an error to ask for the font of a
754 // position that does not exist? Would it be
755 // enough for this to be enabled on debug?
756 // We want strict error checking, but it's ok to only
757 // have it when debugging. (Asger)
758 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
759 "position does not exist. "
760 << pos << " (" << static_cast<int>(pos)
763 } else if (pos > 0) {
764 return GetFontSettings(pos - 1);
765 } else // pos = size() = 0
766 return LyXFont(LyXFont::ALL_INHERIT,getParLanguage());
768 return LyXFont(LyXFont::ALL_INHERIT);
771 // Gets uninstantiated font setting at position 0
772 LyXFont LyXParagraph::GetFirstFontSettings() const
775 #ifdef SORTED_FONT_LIST
776 if (!fontlist.empty() && fontlist.front().pos == 0)
777 return fontlist.front().font;
779 for (FontList::const_iterator cit = fontlist.begin();
780 cit != fontlist.end(); ++cit)
781 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
784 } else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
785 return NextAfterFootnote()->GetFirstFontSettings();
786 return LyXFont(LyXFont::ALL_INHERIT);
789 // Gets the fully instantiated font at a given position in a paragraph
790 // This is basically the same function as LyXText::GetFont() in text2.C.
791 // The difference is that this one is used for generating the LaTeX file,
792 // and thus cosmetic "improvements" are disallowed: This has to deliver
793 // the true picture of the buffer. (Asger)
794 // If position is -1, we get the layout font of the paragraph.
795 // If position is -2, we get the font of the manual label of the paragraph.
796 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
799 LyXLayout const & layout =
800 textclasslist.Style(current_view->buffer()->params.textclass,
802 LyXParagraph::size_type main_body = 0;
803 if (layout.labeltype == LABEL_MANUAL)
804 main_body = BeginningOfMainBody();
809 layoutfont = layout.labelfont;
811 layoutfont = layout.font;
812 tmpfont = GetFontSettings(pos);
813 tmpfont.realize(layoutfont);
815 // process layoutfont for pos == -1 and labelfont for pos < -1
817 tmpfont = layout.font;
819 tmpfont = layout.labelfont;
820 tmpfont.setLanguage(getParLanguage());
823 // check for environment font information
824 char par_depth = GetDepth();
825 LyXParagraph const * par = this;
826 while (par && par_depth && !tmpfont.resolved()) {
827 par = par->DepthHook(par_depth - 1);
829 tmpfont.realize(textclasslist.
830 Style(current_view->buffer()->params.textclass,
831 par->GetLayout()).font);
832 par_depth = par->GetDepth();
836 tmpfont.realize(textclasslist
837 .TextClass(current_view->buffer()->params.textclass)
843 /// Returns the height of the highest font in range
845 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
846 LyXParagraph::size_type endpos) const
848 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
849 for (FontList::const_iterator cit = fontlist.begin();
850 cit != fontlist.end(); ++cit) {
851 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
852 LyXFont::FONT_SIZE size = (*cit).font.size();
853 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
861 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
868 // > because last is the next unused position, and you can
869 // use it if you want
870 else if (pos > size()) {
871 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
872 return NextAfterFootnote()
873 ->GetChar(pos - text.size() - 1);
875 lyxerr << "ERROR (LyXParagraph::GetChar): "
876 "position does not exist."
877 << pos << " (" << static_cast<int>(pos)
879 // Assert(false); // This triggers sometimes...
884 // We should have a footnote environment.
885 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
886 // Notice that LyX does request the
887 // last char from time to time. (Asger)
888 //lyxerr << "ERROR (LyXParagraph::GetChar): "
889 // "expected footnote." << endl;
892 switch (next->footnotekind) {
893 case LyXParagraph::FOOTNOTE:
894 return LyXParagraph::META_FOOTNOTE;
895 case LyXParagraph::MARGIN:
896 return LyXParagraph::META_MARGIN;
897 case LyXParagraph::FIG:
898 case LyXParagraph::WIDE_FIG:
899 return LyXParagraph::META_FIG;
900 case LyXParagraph::TAB:
901 case LyXParagraph::WIDE_TAB:
902 return LyXParagraph::META_TAB;
903 case LyXParagraph::ALGORITHM:
904 return LyXParagraph::META_ALGORITHM;
906 return '\0'; // to shut up gcc
911 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
918 // > because last is the next unused position, and you can
919 // use it if you want
920 else if (pos > size()) {
921 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
922 return NextAfterFootnote()
923 ->GetChar(pos - text.size() - 1);
925 lyxerr << "ERROR (LyXParagraph::GetChar const): "
926 "position does not exist."
927 << pos << " (" << static_cast<int>(pos)
933 // We should have a footnote environment.
934 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
935 // Notice that LyX does request the
936 // last char from time to time. (Asger)
937 //lyxerr << "ERROR (LyXParagraph::GetChar): "
938 // "expected footnote." << endl;
941 switch (next->footnotekind) {
942 case LyXParagraph::FOOTNOTE:
943 return LyXParagraph::META_FOOTNOTE;
944 case LyXParagraph::MARGIN:
945 return LyXParagraph::META_MARGIN;
946 case LyXParagraph::FIG:
947 case LyXParagraph::WIDE_FIG:
948 return LyXParagraph::META_FIG;
949 case LyXParagraph::TAB:
950 case LyXParagraph::WIDE_TAB:
951 return LyXParagraph::META_TAB;
952 case LyXParagraph::ALGORITHM:
953 return LyXParagraph::META_ALGORITHM;
955 return '\0'; // to shut up gcc
960 // return an string of the current word, and the end of the word in lastpos.
961 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
965 // the current word is defined as starting at the first character
966 // from the immediate left of lastpospos which meets the definition
967 // of IsLetter(), continuing to the last character to the right
968 // of this meeting IsLetter.
974 // move back until we have a letter
976 //there's no real reason to have firstpos & lastpos as
977 //separate variables as this is written, but maybe someon
978 // will want to return firstpos in the future.
980 //since someone might have typed a punctuation first
981 int firstpos = lastpos;
983 while ((firstpos >= 0) && !IsLetter(firstpos))
986 // now find the beginning by looking for a nonletter
988 while ((firstpos>= 0) && IsLetter(firstpos))
991 // the above is now pointing to the preceeding non-letter
995 // so copy characters into theword until we get a nonletter
996 // note that this can easily exceed lastpos, wich means
997 // that if used in the middle of a word, the whole word
1000 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1007 LyXParagraph::size_type LyXParagraph::Last() const
1009 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1010 return text.size() + NextAfterFootnote()->Last() + 1;
1011 // the 1 is the symbol
1018 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1020 // > because last is the next unused position, and you can
1021 // use it if you want
1024 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1025 return NextAfterFootnote()
1026 ->ParFromPos(pos - text.size() - 1);
1028 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1029 "position does not exist." << endl;
1036 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1038 // > because last is the next unused position, and you can
1039 // use it if you want
1042 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1043 return NextAfterFootnote()
1044 ->PositionInParFromPos(pos - text.size() - 1);
1047 "ERROR (LyXParagraph::PositionInParFromPos): "
1048 "position does not exist." << endl;
1056 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1057 LyXFont const & font)
1059 // > because last is the next unused position, and you can
1060 // use it if you want
1063 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1064 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1067 lyxerr << "ERROR (LyXParagraph::SetFont): "
1068 "position does not exist." << endl;
1072 LyXFont patternfont(LyXFont::ALL_INHERIT);
1074 // First, reduce font against layout/label font
1075 // Update: The SetCharFont() routine in text2.C already
1076 // reduces font, so we don't need to do that here. (Asger)
1077 // No need to simplify this because it will disappear
1078 // in a new kernel. (Asger)
1079 // Next search font table
1080 FontList::iterator tmp = fontlist.begin();
1081 for (; tmp != fontlist.end(); ++tmp) {
1082 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1086 if (tmp == fontlist.end()) { // !found
1087 // if we did not find a font entry, but if the font at hand
1088 // is the same as default, we just forget it
1089 if (font == patternfont) return;
1091 // ok, we did not find a font entry. But maybe there is exactly
1092 // the needed font ientry one position left
1093 FontList::iterator tmp2 = fontlist.begin();
1094 for (; tmp2 != fontlist.end(); ++tmp2) {
1095 if (pos - 1 >= (*tmp2).pos
1096 && pos - 1 <= (*tmp2).pos_end)
1099 if (tmp2 != fontlist.end()) {
1100 // ok there is one, maybe it is exactly
1102 if ((*tmp2).font == font) {
1103 // put the position under the font
1108 // Add a new entry in the
1109 // fontlist for the position
1113 ft.font = font; // or patternfont
1114 // It seems that using font instead of patternfont here
1115 // fixes all the problems. This also surfaces a "bug" in
1117 fontlist.insert(fontlist.begin(), ft);
1118 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1120 // more than one character
1121 if (pos == (*tmp).pos) {
1122 // maybe we should enlarge the left fonttable
1123 FontList::iterator tmp2 = fontlist.begin();
1124 for (; tmp2 != fontlist.end(); ++tmp2) {
1125 if (pos - 1 >= (*tmp2).pos
1126 && pos - 1 <= (*tmp2).pos_end)
1129 // Is there is one, and is it exactly
1131 if (tmp2 != fontlist.end() &&
1132 (*tmp2).font == font) {
1133 // Put the position under the font
1139 // Add a new entry in the
1140 // fontlist for the position
1143 ft.pos_end = (*tmp).pos_end;
1144 ft.font = (*tmp).font;
1145 (*tmp).pos_end = pos;
1147 fontlist.insert(fontlist.begin(), ft);
1148 } else if (pos == (*tmp).pos_end) {
1149 // Add a new entry in the
1150 // fontlist for the position
1152 ft.pos = (*tmp).pos;
1153 ft.pos_end = (*tmp).pos_end - 1;
1154 ft.font = (*tmp).font;
1155 (*tmp).pos = (*tmp).pos_end;
1157 fontlist.insert(fontlist.begin(), ft);
1159 // Add a new entry in the
1160 // fontlist for the position
1162 ft.pos = (*tmp).pos;
1163 ft.pos_end = pos - 1;
1164 ft.font = (*tmp).font;
1168 ft2.pos_end = (*tmp).pos_end;
1169 ft2.font = (*tmp).font;
1172 (*tmp).pos_end = pos;
1175 fontlist.insert(fontlist.begin(), ft);
1176 fontlist.insert(fontlist.begin(), ft2);
1184 // This function is able to hide closed footnotes.
1185 LyXParagraph * LyXParagraph::Next()
1187 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1188 LyXParagraph * tmp = next;
1190 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1192 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1193 return tmp->Next(); /* there can be more than one
1194 footnote in a logical
1197 return next; // This should never happen!
1203 LyXParagraph * LyXParagraph::NextAfterFootnote()
1205 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1206 LyXParagraph * tmp = next;
1207 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1209 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1210 return tmp; /* there can be more than one footnote
1211 in a logical paragraph */
1213 return next; // This should never happen!
1219 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1221 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1222 LyXParagraph * tmp = next;
1223 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1225 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1226 return tmp; /* there can be more than one footnote
1227 in a logical paragraph */
1229 return next; // This should never happen!
1235 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1238 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1240 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1241 tmp = tmp->previous;
1242 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1243 return tmp; /* there can be more than one footnote
1244 in a logical paragraph */
1246 return previous; // This should never happen!
1252 LyXParagraph * LyXParagraph::LastPhysicalPar()
1254 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1257 LyXParagraph * tmp = this;
1259 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1260 tmp = tmp->NextAfterFootnote();
1265 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1267 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1270 LyXParagraph const * tmp = this;
1272 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1273 tmp = tmp->NextAfterFootnote();
1278 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1282 LyXParagraph * tmppar = this;
1286 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1287 tmppar = tmppar->previous;
1296 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1300 LyXParagraph const * tmppar = this;
1304 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1305 tmppar = tmppar->previous;
1314 // This function is able to hide closed footnotes.
1315 LyXParagraph * LyXParagraph::Previous()
1317 LyXParagraph * tmp = previous;
1322 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1323 tmp = tmp->previous;
1325 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1326 tmp = tmp->previous;
1327 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1328 return tmp->next->Previous();
1337 // This function is able to hide closed footnotes.
1338 LyXParagraph const * LyXParagraph::Previous() const
1340 LyXParagraph * tmp = previous;
1345 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1346 tmp = tmp->previous;
1348 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1349 tmp = tmp->previous;
1350 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1351 return tmp->next->Previous();
1360 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1363 size_type i, j, pos_end, pos_first;
1364 // create a new paragraph
1365 LyXParagraph * par = ParFromPos(pos);
1366 LyXParagraph * firstpar = FirstPhysicalPar();
1368 LyXParagraph * tmp = new LyXParagraph(par);
1370 tmp->footnoteflag = footnoteflag;
1371 tmp->footnotekind = footnotekind;
1373 // this is an idea for a more userfriendly layout handling, I will
1374 // see what the users say
1376 // layout stays the same with latex-environments
1378 tmp->SetOnlyLayout(firstpar->layout);
1379 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1382 if (Last() > pos || !Last() || flag == 2) {
1383 tmp->SetOnlyLayout(firstpar->layout);
1384 tmp->align = firstpar->align;
1385 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1387 tmp->line_bottom = firstpar->line_bottom;
1388 firstpar->line_bottom = false;
1389 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1390 firstpar->pagebreak_bottom = false;
1391 tmp->added_space_bottom = firstpar->added_space_bottom;
1392 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1394 tmp->depth = firstpar->depth;
1395 tmp->noindent = firstpar->noindent;
1397 // copy everything behind the break-position
1398 // to the new paragraph
1400 while (ParFromPos(pos_first) != par)
1403 pos_end = pos_first + par->text.size() - 1;
1405 for (i = j = pos; i <= pos_end; ++i) {
1406 par->CutIntoMinibuffer(i - pos_first);
1407 if (tmp->InsertFromMinibuffer(j - pos))
1410 tmp->text.resize(tmp->text.size());
1411 for (i = pos_end; i >= pos; --i)
1412 par->Erase(i - pos_first);
1414 par->text.resize(par->text.size());
1417 // just an idea of me
1419 tmp->line_top = firstpar->line_top;
1420 tmp->pagebreak_top = firstpar->pagebreak_top;
1421 tmp->added_space_top = firstpar->added_space_top;
1422 tmp->bibkey = firstpar->bibkey;
1424 // layout stays the same with latex-environments
1426 firstpar->SetOnlyLayout(tmp->layout);
1427 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1428 firstpar->depth = tmp->depth;
1434 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1436 par = par->FirstPhysicalPar();
1437 footnoteflag = par->footnoteflag;
1438 footnotekind = par->footnotekind;
1440 layout = par->layout;
1441 align = par-> align;
1442 SetLabelWidthString(par->labelwidthstring);
1444 line_bottom = par->line_bottom;
1445 pagebreak_bottom = par->pagebreak_bottom;
1446 added_space_bottom = par->added_space_bottom;
1448 line_top = par->line_top;
1449 pagebreak_top = par->pagebreak_top;
1450 added_space_top = par->added_space_top;
1452 spacing = par->spacing;
1454 pextra_type = par->pextra_type;
1455 pextra_width = par->pextra_width;
1456 pextra_widthp = par->pextra_widthp;
1457 pextra_alignment = par->pextra_alignment;
1458 pextra_hfill = par->pextra_hfill;
1459 pextra_start_minipage = par->pextra_start_minipage;
1461 noindent = par->noindent;
1466 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1468 LyXParagraph * tmppar = this;
1471 && tmppar->previous->footnoteflag ==
1472 LyXParagraph::CLOSED_FOOTNOTE)
1473 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1474 tmppar = tmppar->previous;
1477 return this; // This should never happen!
1483 LyXParagraph * LyXParagraph::Clone() const
1485 // create a new paragraph
1486 LyXParagraph * result = new LyXParagraph;
1488 result->MakeSameLayout(this);
1490 // this is because of the dummy layout of the paragraphs that
1492 result->layout = layout;
1494 /* table stuff -- begin*/
1496 result->table = table->Clone();
1499 /* table stuff -- end*/
1501 result->inset_owner = inset_owner;
1504 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1507 // copy everything behind the break-position to the new paragraph
1509 result->text = text;
1510 result->fontlist = fontlist;
1511 result->insetlist = insetlist;
1512 for (InsetList::iterator it = result->insetlist.begin();
1513 it != result->insetlist.end(); ++it)
1514 (*it).inset = (*it).inset->Clone();
1519 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1521 par = par->FirstPhysicalPar();
1524 par->footnoteflag == footnoteflag &&
1525 par->footnotekind == footnotekind &&
1527 par->layout == layout &&
1529 par->align == align &&
1531 par->line_bottom == line_bottom &&
1532 par->pagebreak_bottom == pagebreak_bottom &&
1533 par->added_space_bottom == added_space_bottom &&
1535 par->line_top == line_top &&
1536 par->pagebreak_top == pagebreak_top &&
1537 par->added_space_top == added_space_top &&
1539 par->spacing == spacing &&
1541 par->pextra_type == pextra_type &&
1542 par->pextra_width == pextra_width &&
1543 par->pextra_widthp == pextra_widthp &&
1544 par->pextra_alignment == pextra_alignment &&
1545 par->pextra_hfill == pextra_hfill &&
1546 par->pextra_start_minipage == pextra_start_minipage &&
1548 par->table == table && // what means: NO TABLE AT ALL
1550 par->noindent == noindent &&
1551 par->depth == depth);
1555 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1557 // create a new paragraph
1558 LyXParagraph * par = ParFromPos(pos);
1560 LyXParagraph * tmp = new LyXParagraph(par);
1562 tmp->MakeSameLayout(par);
1564 // When can pos < Last()?
1565 // I guess pos == Last() is possible.
1567 // copy everything behind the break-position to the new
1569 size_type pos_first = 0;
1570 while (ParFromPos(pos_first) != par)
1572 size_type pos_end = pos_first + par->text.size() - 1;
1575 for (i = j = pos; i <= pos_end; ++i) {
1576 par->CutIntoMinibuffer(i - pos_first);
1577 if (tmp->InsertFromMinibuffer(j - pos))
1580 tmp->text.resize(tmp->text.size());
1581 for (size_type i = pos_end; i >= pos; --i)
1582 par->Erase(i - pos_first);
1584 par->text.resize(par->text.size());
1589 // Be carefull, this does not make any check at all.
1590 void LyXParagraph::PasteParagraph()
1592 // copy the next paragraph to this one
1593 LyXParagraph * the_next = Next();
1595 LyXParagraph * firstpar = FirstPhysicalPar();
1597 // first the DTP-stuff
1598 firstpar->line_bottom = the_next->line_bottom;
1599 firstpar->added_space_bottom = the_next->added_space_bottom;
1600 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1602 size_type pos_end = the_next->text.size() - 1;
1603 size_type pos_insert = Last();
1605 // ok, now copy the paragraph
1607 for (i = j = 0; i <= pos_end; ++i) {
1608 the_next->CutIntoMinibuffer(i);
1609 if (InsertFromMinibuffer(pos_insert + j))
1613 // delete the next paragraph
1618 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1620 LyXParagraph * par = ParFromPos(pos);
1622 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1623 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1629 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1631 LyXParagraph * par = ParFromPos(pos);
1633 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1634 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1639 int LyXParagraph::GetEndLabel() const
1641 LyXParagraph const * par = this;
1642 int par_depth = GetDepth();
1644 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1646 textclasslist.Style(current_view->buffer()->params.textclass,
1647 layout).endlabeltype;
1648 if (endlabeltype != END_LABEL_NO_LABEL) {
1649 LyXParagraph const * last = this;
1650 if( footnoteflag == NO_FOOTNOTE)
1651 last = LastPhysicalPar();
1652 else if (next->footnoteflag == NO_FOOTNOTE)
1653 return endlabeltype;
1655 if (!last || !last->next)
1656 return endlabeltype;
1658 int next_depth = last->next->GetDepth();
1659 if (par_depth > next_depth ||
1660 (par_depth == next_depth && layout != last->next->GetLayout() ))
1661 return endlabeltype;
1666 par = par->DepthHook(par_depth - 1);
1668 par_depth = par->GetDepth();
1670 return END_LABEL_NO_LABEL;
1674 LyXTextClass::size_type LyXParagraph::GetLayout() const
1676 return FirstPhysicalPar()->layout;
1680 char LyXParagraph::GetDepth() const
1682 return FirstPhysicalPar()->depth;
1686 char LyXParagraph::GetAlign() const
1688 return FirstPhysicalPar()->align;
1692 string LyXParagraph::GetLabelstring() const
1694 return FirstPhysicalPar()->labelstring;
1698 int LyXParagraph::GetFirstCounter(int i) const
1700 return FirstPhysicalPar()->counter_[i];
1704 // the next two functions are for the manual labels
1705 string LyXParagraph::GetLabelWidthString() const
1707 if (!FirstPhysicalPar()->labelwidthstring.empty())
1708 return FirstPhysicalPar()->labelwidthstring;
1710 return _("Senseless with this layout!");
1714 void LyXParagraph::SetLabelWidthString(string const & s)
1716 LyXParagraph * par = FirstPhysicalPar();
1718 par->labelwidthstring = s;
1722 void LyXParagraph::SetOnlyLayout(LyXTextClass::size_type new_layout)
1724 LyXParagraph * par = FirstPhysicalPar();
1725 LyXParagraph * ppar = 0;
1726 LyXParagraph * npar = 0;
1728 par->layout = new_layout;
1729 /* table stuff -- begin*/
1732 /* table stuff -- end*/
1733 if (par->pextra_type == PEXTRA_NONE) {
1734 if (par->Previous()) {
1735 ppar = par->Previous()->FirstPhysicalPar();
1738 && (ppar->depth > par->depth))
1739 ppar = ppar->Previous()->FirstPhysicalPar();
1742 npar = par->Next()->NextAfterFootnote();
1745 && (npar->depth > par->depth))
1746 npar = npar->Next()->NextAfterFootnote();
1748 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1750 p1 = ppar->pextra_width,
1751 p2 = ppar->pextra_widthp;
1752 ppar->SetPExtraType(ppar->pextra_type,
1753 p1.c_str(), p2.c_str());
1755 if ((par->pextra_type == PEXTRA_NONE) &&
1756 npar && (npar->pextra_type != PEXTRA_NONE)) {
1758 p1 = npar->pextra_width,
1759 p2 = npar->pextra_widthp;
1760 npar->SetPExtraType(npar->pextra_type,
1761 p1.c_str(), p2.c_str());
1767 void LyXParagraph::SetLayout(LyXTextClass::size_type new_layout)
1770 * par = FirstPhysicalPar(),
1774 par->layout = new_layout;
1775 par->labelwidthstring.erase();
1776 par->align = LYX_ALIGN_LAYOUT;
1777 par->added_space_top = VSpace(VSpace::NONE);
1778 par->added_space_bottom = VSpace(VSpace::NONE);
1779 par->spacing.set(Spacing::Default);
1781 /* table stuff -- begin*/
1784 /* table stuff -- end*/
1785 if (par->pextra_type == PEXTRA_NONE) {
1786 if (par->Previous()) {
1787 ppar = par->Previous()->FirstPhysicalPar();
1790 && (ppar->depth > par->depth))
1791 ppar = ppar->Previous()->FirstPhysicalPar();
1794 npar = par->Next()->NextAfterFootnote();
1797 && (npar->depth > par->depth))
1798 npar = npar->Next()->NextAfterFootnote();
1800 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1802 p1 = ppar->pextra_width,
1803 p2 = ppar->pextra_widthp;
1804 ppar->SetPExtraType(ppar->pextra_type,
1805 p1.c_str(), p2.c_str());
1807 if ((par->pextra_type == PEXTRA_NONE) &&
1808 npar && (npar->pextra_type != PEXTRA_NONE)) {
1810 p1 = npar->pextra_width,
1811 p2 = npar->pextra_widthp;
1812 npar->SetPExtraType(npar->pextra_type,
1813 p1.c_str(), p2.c_str());
1819 // if the layout of a paragraph contains a manual label, the beginning of the
1820 // main body is the beginning of the second word. This is what the par-
1821 // function returns. If the layout does not contain a label, the main
1822 // body always starts with position 0. This differentiation is necessary,
1823 // because there cannot be a newline or a blank <= the beginning of the
1824 // main body in TeX.
1826 int LyXParagraph::BeginningOfMainBody() const
1828 if (FirstPhysicalPar() != this)
1831 // Unroll the first two cycles of the loop
1832 // and remember the previous character to
1833 // remove unnecessary GetChar() calls
1836 && GetChar(i) != LyXParagraph::META_NEWLINE
1839 char previous_char = 0, temp = 0;
1841 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1842 // Yes, this ^ is supposed to be "= " not "=="
1845 && previous_char != ' '
1846 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1848 previous_char = temp;
1853 if (i == 0 && i == size() &&
1854 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1855 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1856 ++i; /* the cursor should not jump
1857 * to the main body if there
1863 LyXParagraph * LyXParagraph::DepthHook(int deth)
1865 LyXParagraph * newpar = this;
1870 newpar = newpar->FirstPhysicalPar()->Previous();
1871 } while (newpar && newpar->GetDepth() > deth
1872 && newpar->footnoteflag == footnoteflag);
1875 if (Previous() || GetDepth())
1876 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1880 return newpar->FirstPhysicalPar();
1884 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1886 LyXParagraph const * newpar = this;
1891 newpar = newpar->FirstPhysicalPar()->Previous();
1892 } while (newpar && newpar->GetDepth() > deth
1893 && newpar->footnoteflag == footnoteflag);
1896 if (Previous() || GetDepth())
1897 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1901 return newpar->FirstPhysicalPar();
1905 int LyXParagraph::AutoDeleteInsets()
1908 InsetList::size_type index = 0;
1909 while (index < insetlist.size()) {
1910 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1911 Erase(insetlist[index].pos);
1912 // Erase() calls to insetlist.erase(&insetlist[index])
1913 // so index shouldn't be increased.
1922 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1924 InsetList::iterator it = lower_bound(insetlist.begin(),
1927 if (it != insetlist.end()) {
1935 // returns -1 if inset not found
1936 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1939 // We could use lower_bound here too, we just need to add
1940 // the approp. operator() to matchIT (and change the name
1941 // of that struct). Code would then be:
1942 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
1944 // inset, matchIT());
1945 // if ((*cit).inset == inset) {
1946 // return (*cit).pos;
1948 for (InsetList::const_iterator cit = insetlist.begin();
1949 cit != insetlist.end(); ++cit) {
1950 if ((*cit).inset == inset) {
1954 // Think about footnotes.
1955 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1956 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1958 NextAfterFootnote()->GetPositionOfInset(inset);
1960 return text.size() + 1 + further;
1966 LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow,
1968 TexRow & foot_texrow,
1971 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1972 LyXLayout const & style =
1973 textclasslist.Style(current_view->buffer()->params.textclass,
1976 bool further_blank_line = false;
1978 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1980 if (start_of_appendix) {
1981 os << "\\appendix\n";
1985 if (!spacing.isDefault()
1986 && (!Previous() || !Previous()->HasSameLayout(this))) {
1987 os << spacing.writeEnvirBegin() << "\n";
1991 if (tex_code_break_column && style.isCommand()){
1996 if (pagebreak_top) {
1998 further_blank_line = true;
2000 if (added_space_top.kind() != VSpace::NONE) {
2001 os << added_space_top.asLatexCommand(current_view->buffer()->params);
2002 further_blank_line = true;
2006 os << "\\lyxline{\\" << getFont(0).latexSize() << '}'
2007 << "\\vspace{-1\\parskip}";
2008 further_blank_line = true;
2011 if (further_blank_line){
2016 Language const * language = getParLanguage();
2017 Language const * doc_language = current_view->buffer()->params.language_info;
2018 if (language != doc_language) {
2019 os << subst(lyxrc.language_command_begin, "$$lang",
2025 switch (style.latextype) {
2028 << style.latexname()
2029 << style.latexparam();
2031 case LATEX_ITEM_ENVIRONMENT:
2033 bibkey->Latex(os, false, false);
2037 case LATEX_LIST_ENVIRONMENT:
2044 bool need_par = SimpleTeXOnePar(os, texrow);
2046 // Spit out footnotes
2047 LyXParagraph * par = next;
2048 if (lyxrc.rtl_support) {
2049 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2050 && next->footnoteflag != footnoteflag) {
2051 LyXParagraph * p = 0;
2052 bool is_rtl = GetFontSettings(size()-1).isRightToLeft();
2053 if ( (p = NextAfterFootnote()) != 0 &&
2054 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2055 is_rtl = GetFontSettings(0).isRightToLeft();
2057 par->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2058 par->footnoteflag != footnoteflag) {
2059 par = par->TeXFootnote(os, texrow, foot,
2060 foot_texrow, foot_count,
2062 par->SimpleTeXOnePar(os, texrow);
2063 is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft();
2065 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2066 (p = par->NextAfterFootnote()) != 0 &&
2067 p->GetFontSettings(0).isRightToLeft() != is_rtl)
2068 is_rtl = GetFontSettings(0).isRightToLeft();
2073 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2074 && par->footnoteflag != footnoteflag) {
2075 par = par->TeXFootnote(os, texrow,
2076 foot, foot_texrow, foot_count,
2078 par->SimpleTeXOnePar(os, texrow);
2083 // Make sure that \\par is done with the font of the last
2084 // character if this has another size as the default.
2085 // This is necessary because LaTeX (and LyX on the screen)
2086 // calculates the space between the baselines according
2087 // to this font. (Matthias)
2088 LyXFont font = getFont(Last() - 1);
2090 if (style.resfont.size() != font.size()) {
2096 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
2097 GetLayout()).isCommand()){
2098 if (style.resfont.size() != font.size()) {
2104 } else if (style.resfont.size() != font.size()){
2105 os << "{\\" << font.latexSize() << " \\par}";
2108 if (language != doc_language) {
2110 << subst(lyxrc.language_command_end, "$$lang",
2111 doc_language->lang);
2114 switch (style.latextype) {
2115 case LATEX_ITEM_ENVIRONMENT:
2116 case LATEX_LIST_ENVIRONMENT:
2117 if (par && (depth < par->depth)) {
2122 case LATEX_ENVIRONMENT:
2123 // if its the last paragraph of the current environment
2124 // skip it otherwise fall through
2126 && (par->layout != layout
2127 || par->depth != depth
2128 || par->pextra_type != pextra_type))
2131 // we don't need it for the last paragraph!!!
2132 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2133 && footnotekind != LyXParagraph::FOOTNOTE
2134 && footnotekind != LyXParagraph::MARGIN
2138 // don't insert this if we would be adding it
2139 // before or after a table in a float. This
2140 // little trick is needed in order to allow
2141 // use of tables in \subfigures or \subtables.
2147 further_blank_line = false;
2149 os << "\\lyxline{\\" << getFont(Last() - 1).latexSize() << '}';
2150 further_blank_line = true;
2153 if (added_space_bottom.kind() != VSpace::NONE) {
2154 os << added_space_bottom.asLatexCommand(current_view->buffer()->params);
2155 further_blank_line = true;
2158 if (pagebreak_bottom) {
2160 further_blank_line = true;
2163 if (further_blank_line){
2168 if (!spacing.isDefault()
2169 && (!par || !par->HasSameLayout(this))) {
2170 os << spacing.writeEnvirEnd() << "\n";
2174 // we don't need it for the last paragraph!!!
2175 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2176 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2181 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2186 // This one spits out the text of the paragraph
2187 bool LyXParagraph::SimpleTeXOnePar(ostream & os, TexRow & texrow)
2189 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2192 return SimpleTeXOneTablePar(os, texrow);
2194 bool return_value = false;
2196 LyXLayout const & style =
2197 textclasslist.Style(current_view->buffer()->params.textclass,
2199 LyXFont basefont, last_font;
2201 // Maybe we have to create a optional argument.
2202 size_type main_body;
2203 if (style.labeltype != LABEL_MANUAL)
2206 main_body = BeginningOfMainBody();
2208 if (main_body > 0) {
2210 basefont = getFont(-2); // Get label font
2212 basefont = getFont(-1); // Get layout font
2220 if (style.isCommand()) {
2223 } else if (align != LYX_ALIGN_LAYOUT) {
2226 return_value = true;
2230 // Which font is currently active?
2231 LyXFont running_font(basefont);
2232 // Do we have an open font change?
2233 bool open_font = false;
2235 texrow.start(this, 0);
2237 for (size_type i = 0; i < size(); ++i) {
2239 // First char in paragraph or after label?
2240 if (i == main_body && !IsDummy()) {
2241 if (main_body > 0) {
2243 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2246 basefont = getFont(-1); // Now use the layout font
2247 running_font = basefont;
2251 if (style.isCommand()) {
2254 } else if (align != LYX_ALIGN_LAYOUT) {
2257 return_value = true;
2261 os << "\\noindent ";
2265 case LYX_ALIGN_NONE:
2266 case LYX_ALIGN_BLOCK:
2267 case LYX_ALIGN_LAYOUT:
2268 case LYX_ALIGN_SPECIAL:
2270 case LYX_ALIGN_LEFT:
2271 if (getParLanguage()->lang != "hebrew") {
2272 os << "\\raggedright ";
2275 os << "\\raggedleft ";
2279 case LYX_ALIGN_RIGHT:
2280 if (getParLanguage()->lang != "hebrew") {
2281 os << "\\raggedleft ";
2284 os << "\\raggedright ";
2288 case LYX_ALIGN_CENTER:
2289 os << "\\centering ";
2297 // Fully instantiated font
2298 LyXFont font = getFont(i);
2299 LyXParagraph * p = 0;
2300 if (i == 0 && previous &&
2301 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2302 (p = PreviousBeforeFootnote()) != 0)
2303 last_font = p->getFont(p->size()-1);
2305 last_font = running_font;
2307 // Spaces at end of font change are simulated to be
2308 // outside font change, i.e. we write "\textXX{text} "
2309 // rather than "\textXX{text }". (Asger)
2310 if (open_font && c == ' ' && i <= size() - 2
2311 && !getFont(i+1).equalExceptLatex(running_font)
2312 && !getFont(i+1).equalExceptLatex(font)) {
2313 font = getFont(i + 1);
2315 // We end font definition before blanks
2316 if (!font.equalExceptLatex(running_font) && open_font) {
2317 column += running_font.latexWriteEndChanges(os,
2319 (i == main_body-1) ? basefont : font);
2320 running_font = basefont;
2324 // Blanks are printed before start of fontswitch
2326 // Do not print the separation of the optional argument
2327 if (i != main_body - 1) {
2328 SimpleTeXBlanks(os, texrow, i,
2329 column, font, style);
2333 // Do we need to change font?
2334 if (!font.equalExceptLatex(running_font)
2335 && i != main_body-1) {
2336 column += font.latexWriteStartChanges(os, basefont,
2338 running_font = font;
2342 if (c == LyXParagraph::META_NEWLINE) {
2343 // newlines are handled differently here than
2344 // the default in SimpleTeXSpecialChars().
2345 if (!style.newline_allowed
2346 || font.latex() == LyXFont::ON) {
2350 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2353 basefont = getFont(-1);
2354 running_font = basefont;
2355 if (font.family() ==
2356 LyXFont::TYPEWRITER_FAMILY) {
2362 texrow.start(this, i + 1);
2365 SimpleTeXSpecialChars(os, texrow,
2366 font, running_font, basefont,
2367 open_font, style, i, column, c);
2371 // If we have an open font definition, we have to close it
2373 LyXParagraph * p = 0;
2374 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2375 && (p = NextAfterFootnote()) != 0)
2376 running_font.latexWriteEndChanges(os, basefont,
2379 running_font.latexWriteEndChanges(os, basefont, basefont);
2382 // Needed if there is an optional argument but no contents.
2383 if (main_body > 0 && main_body == size()) {
2385 return_value = false;
2388 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2389 return return_value;
2393 // This one spits out the text of a table paragraph
2394 bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow)
2396 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2398 bool return_value = false;
2400 LyXLayout const & style =
2401 textclasslist.Style(current_view->buffer()->params.textclass,
2405 if (!IsDummy()) { // it is dummy if it is in a float!!!
2406 if (style.isCommand()) {
2409 } else if (align != LYX_ALIGN_LAYOUT) {
2412 return_value = true;
2415 os << "\\noindent ";
2419 case LYX_ALIGN_NONE:
2420 case LYX_ALIGN_BLOCK:
2421 case LYX_ALIGN_LAYOUT:
2422 case LYX_ALIGN_SPECIAL: break;
2423 case LYX_ALIGN_LEFT:
2424 os << "\\raggedright ";
2427 case LYX_ALIGN_RIGHT:
2428 os << "\\raggedleft ";
2431 case LYX_ALIGN_CENTER:
2432 os << "\\centering ";
2438 LyXFont basefont = getFont(-1); // Get layout font
2439 // Which font is currently active?
2440 LyXFont running_font = basefont;
2442 // Do we have an open font change?
2443 bool open_font = false;
2444 int current_cell_number = -1;
2445 int tmp = table->TexEndOfCell(os, current_cell_number);
2446 for (; tmp > 0 ; --tmp)
2449 texrow.start(this, 0);
2451 bool is_rtl = getParLanguage()->RightToLeft;
2452 bool first_in_cell = true;
2454 for (size_type i = 0; i < size(); ++i) {
2455 char c = GetChar(i);
2456 if (table->IsContRow(current_cell_number + 1)) {
2457 if (c == LyXParagraph::META_NEWLINE)
2458 ++current_cell_number;
2463 if (first_in_cell && is_rtl) {
2466 first_in_cell = false;
2469 // Fully instantiated font
2470 LyXFont font = getFont(i);
2471 last_font = running_font;
2473 // Spaces at end of font change are simulated to be
2474 // outside font change.
2475 // i.e. we write "\textXX{text} " rather than
2476 // "\textXX{text }". (Asger)
2477 if (open_font && c == ' ' && i <= size() - 2
2478 && getFont(i + 1) != running_font
2479 && getFont(i + 1) != font) {
2480 font = getFont(i + 1);
2483 // We end font definition before blanks
2484 if (font != running_font && open_font) {
2485 column += running_font.latexWriteEndChanges(os,
2488 running_font = basefont;
2491 // Blanks are printed before start of fontswitch
2493 SimpleTeXBlanks(os, texrow, i, column, font, style);
2495 // Do we need to change font?
2496 if (font != running_font) {
2497 column += font.latexWriteStartChanges(os, basefont,
2499 running_font = font;
2502 // Do we need to turn on LaTeX mode?
2503 if (font.latex() != running_font.latex()) {
2504 if (font.latex() == LyXFont::ON
2505 && style.needprotect) {
2510 if (c == LyXParagraph::META_NEWLINE) {
2511 // special case for inside a table
2512 // different from default case in
2513 // SimpleTeXSpecialChars()
2515 column += running_font
2516 .latexWriteEndChanges(os, basefont,
2520 basefont = getFont(-1);
2521 running_font = basefont;
2522 ++current_cell_number;
2523 if (table->CellHasContRow(current_cell_number) >= 0) {
2524 TeXContTableRows(os, i + 1,
2525 current_cell_number,
2528 if (is_rtl && !first_in_cell) {
2530 first_in_cell = true;
2533 // if this cell follow only ContRows till end don't
2534 // put the EndOfCell because it is put after the
2536 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2537 --current_cell_number;
2540 int tmp = table->TexEndOfCell(os,
2541 current_cell_number);
2544 } else if (tmp < 0) {
2550 texrow.start(this, i + 1);
2552 SimpleTeXSpecialChars(os, texrow,
2553 font, running_font, basefont,
2554 open_font, style, i, column, c);
2558 // If we have an open font definition, we have to close it
2560 running_font.latexWriteEndChanges(os, basefont, basefont);
2562 ++current_cell_number;
2563 if (is_rtl && !first_in_cell)
2565 tmp = table->TexEndOfCell(os, current_cell_number);
2566 for (; tmp > 0; --tmp)
2568 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2569 return return_value;
2573 // This one spits out the text off ContRows in tables
2574 bool LyXParagraph::TeXContTableRows(ostream & os,
2575 LyXParagraph::size_type i,
2576 int current_cell_number,
2577 int & column, TexRow & texrow)
2579 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2585 bool return_value = false;
2586 LyXLayout const & style =
2587 textclasslist.Style(current_view->buffer()->params.textclass,
2589 LyXFont basefont = getFont(-1); // Get layout font
2591 // Which font is currently active?
2592 LyXFont running_font = basefont;
2593 // Do we have an open font change?
2594 bool open_font = false;
2596 size_type lastpos = i;
2597 int cell = table->CellHasContRow(current_cell_number);
2598 ++current_cell_number;
2600 // first find the right position
2602 for (; (i < size()) && (current_cell_number<cell); ++i) {
2604 if (c == LyXParagraph::META_NEWLINE)
2605 ++current_cell_number;
2609 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2613 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2618 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2622 // Fully instantiated font
2623 LyXFont font = getFont(i);
2624 last_font = running_font;
2626 // Spaces at end of font change are simulated to
2627 // be outside font change. i.e. we write
2628 // "\textXX{text} " rather than "\textXX{text }".
2630 if (open_font && c == ' ' && i <= size() - 2
2631 && getFont(i + 1) != running_font
2632 && getFont(i + 1) != font) {
2633 font = getFont(i + 1);
2636 // We end font definition before blanks
2637 if (font != running_font && open_font) {
2638 column += running_font.latexWriteEndChanges(os, basefont, font);
2639 running_font = basefont;
2642 // Blanks are printed before start of fontswitch
2644 SimpleTeXBlanks(os, texrow, i,
2645 column, font, style);
2647 // Do we need to change font?
2648 if (font != running_font) {
2650 font.latexWriteStartChanges(os,
2653 running_font = font;
2656 // Do we need to turn on LaTeX mode?
2657 if (font.latex() != running_font.latex()) {
2658 if (font.latex() == LyXFont::ON
2659 && style.needprotect) {
2664 SimpleTeXSpecialChars(os, texrow, font,
2665 running_font, basefont,
2666 open_font, style, i, column, c);
2668 // If we have an open font definition, we have to close it
2670 running_font.latexWriteEndChanges(os, basefont,
2674 basefont = getFont(-1);
2675 running_font = basefont;
2676 cell = table->CellHasContRow(current_cell_number);
2678 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2679 return return_value;
2683 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2685 bool retval = false;
2687 case LyXParagraph::META_HFILL:
2688 sgml_string.erase();
2690 case LyXParagraph::META_NEWLINE:
2694 sgml_string = "&";
2697 sgml_string = "<";
2700 sgml_string = ">";
2703 sgml_string = "$";
2706 sgml_string = "#";
2709 sgml_string = "%";
2712 sgml_string = "[";
2715 sgml_string = "]";
2718 sgml_string = "{";
2721 sgml_string = "}";
2724 sgml_string = "˜";
2727 sgml_string = """;
2730 sgml_string = "\";
2736 case '\0': // Ignore :-)
2737 sgml_string.erase();
2747 void LyXParagraph::SimpleDocBookOneTablePar(ostream & os, string & extra,
2748 int & desc_on, int depth)
2751 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2753 LyXFont font1, font2;
2756 size_type main_body;
2757 bool emph_flag = false;
2759 LyXLayout const & style =
2760 textclasslist.Style(current_view->buffer()->params.textclass,
2763 if (style.labeltype != LABEL_MANUAL)
2766 main_body = BeginningOfMainBody();
2768 // Gets paragraph main font.
2770 font1 = style.labelfont;
2774 int char_line_count = depth;
2775 os << newlineAndDepth(depth);
2776 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2777 os << "<INFORMALTABLE>"
2778 << newlineAndDepth(++depth);
2780 int current_cell_number = -1;
2781 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2783 // Parsing main loop.
2784 for (size_type i = 0; i < size(); ++i) {
2786 if (table->IsContRow(current_cell_number+1)) {
2787 if (c == LyXParagraph::META_NEWLINE)
2788 ++current_cell_number;
2793 // Fully instantiated font
2796 // Handle <emphasis> tag.
2797 if (font1.emph() != font2.emph() && i) {
2798 if (font2.emph() == LyXFont::ON) {
2801 } else if (emph_flag) {
2802 os << "</emphasis>";
2806 if (c == LyXParagraph::META_NEWLINE) {
2807 // We have only to control for emphasis open here!
2809 os << "</emphasis>";
2812 font1 = font2 = getFont(-1);
2813 ++current_cell_number;
2814 if (table->CellHasContRow(current_cell_number) >= 0) {
2815 DocBookContTableRows(os, extra, desc_on, i + 1,
2816 current_cell_number,
2819 // if this cell follow only ContRows till end don't
2820 // put the EndOfCell because it is put after the
2822 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2823 --current_cell_number;
2826 tmp = table->DocBookEndOfCell(os,
2827 current_cell_number,
2832 } else if (c == LyXParagraph::META_INSET) {
2833 inset = GetInset(i);
2835 std::ostringstream ost;
2836 inset->DocBook(ost);
2837 string tmp_out = ost.str().c_str();
2840 inset->DocBook(ost);
2842 char * ctmp = ost.str();
2843 string tmp_out(ctmp);
2847 // This code needs some explanation:
2848 // Two insets are treated specially
2849 // label if it is the first element in a
2850 // command paragraph
2852 // graphics inside tables or figure floats
2854 // title (the equivalente in latex for this
2856 // and title should come first
2859 if(desc_on != 3 || i != 0) {
2860 if(tmp_out[0] == '@') {
2862 extra += frontStrip(tmp_out,
2865 os << frontStrip(tmp_out,
2870 } else if (font2.latex() == LyXFont::ON) {
2871 // "TeX"-Mode on == > SGML-Mode on.
2877 if (linuxDocConvertChar(c, sgml_string)
2878 && !style.free_spacing) {
2879 // in freespacing mode, spaces are
2880 // non-breaking characters
2885 << "</term><listitem><para>";
2897 // Needed if there is an optional argument but no contents.
2898 if (main_body > 0 && main_body == size()) {
2903 os << "</emphasis>";
2906 ++current_cell_number;
2907 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2908 // Resets description flag correctly.
2911 // <term> not closed...
2915 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2916 os << "</INFORMALTABLE>";
2918 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2923 void LyXParagraph::DocBookContTableRows(ostream & os, string & extra,
2925 LyXParagraph::size_type i,
2926 int current_cell_number, int &column)
2931 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2936 //string emph = "emphasis";
2937 bool emph_flag = false;
2938 int char_line_count = 0;
2940 LyXLayout const & style =
2941 textclasslist.Style(current_view->buffer()->params.textclass,
2944 size_type main_body;
2945 if (style.labeltype != LABEL_MANUAL)
2948 main_body = BeginningOfMainBody();
2950 // Gets paragraph main font.
2953 font1 = style.labelfont;
2957 size_type lastpos = i;
2958 int cell = table->CellHasContRow(current_cell_number);
2959 ++current_cell_number;
2961 // first find the right position
2963 for (; i < size() && current_cell_number < cell; ++i) {
2965 if (c == LyXParagraph::META_NEWLINE)
2966 ++current_cell_number;
2970 // I don't know how to handle this so I comment it
2971 // for the moment (Jug)
2972 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2973 // file += " \\\\\n";
2976 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2981 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2985 // Fully instantiated font
2988 // Handle <emphasis> tag.
2989 if (font1.emph() != font2.emph() && i) {
2990 if (font2.emph() == LyXFont::ON) {
2993 } else if (emph_flag) {
2994 os << "</emphasis>";
2998 if (c == LyXParagraph::META_INSET) {
2999 inset = GetInset(i);
3001 std::ostringstream ost;
3002 inset->DocBook(ost);
3003 string tmp_out = ost.str().c_str();
3006 inset->DocBook(ost);
3008 char * ctmp = ost.str();
3009 string tmp_out(ctmp);
3013 // This code needs some explanation:
3014 // Two insets are treated specially
3015 // label if it is the first element in a
3016 // command paragraph
3018 // graphics inside tables or figure floats
3019 // can't go on title (the equivalente in
3020 // latex for this case is caption and title
3021 // should come first
3024 if(desc_on != 3 || i != 0) {
3025 if(tmp_out[0] == '@') {
3027 extra += frontStrip(tmp_out, '@');
3029 os << frontStrip(tmp_out, '@');
3033 } else if (font2.latex() == LyXFont::ON) {
3034 // "TeX"-Mode on == > SGML-Mode on.
3040 if (linuxDocConvertChar(c, sgml_string)
3041 && !style.free_spacing) {
3042 // in freespacing mode, spaces are
3043 // non-breaking characters
3048 << "</term><listitem><para>";
3058 // we have only to control for emphasis open here!
3060 os << "</emphasis>";
3063 font1 = font2 = getFont(-1);
3064 cell = table->CellHasContRow(current_cell_number);
3066 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3070 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3071 LyXParagraph::size_type const i,
3072 int & column, LyXFont const & font,
3073 LyXLayout const & style)
3075 if (column > tex_code_break_column
3077 && GetChar(i - 1) != ' '
3079 // In LaTeX mode, we don't want to
3080 // break lines since some commands
3082 && ! (font.latex() == LyXFont::ON)
3083 // same in FreeSpacing mode
3084 && !style.free_spacing
3085 // In typewriter mode, we want to avoid
3086 // ! . ? : at the end of a line
3087 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3088 && (GetChar(i-1) == '.'
3089 || GetChar(i-1) == '?'
3090 || GetChar(i-1) == ':'
3091 || GetChar(i-1) == '!'))) {
3092 if (tex_code_break_column == 0) {
3093 // in batchmode we need LaTeX to still
3094 // see it as a space not as an extra '\n'
3100 texrow.start(this, i + 1);
3102 } else if (font.latex() == LyXFont::OFF) {
3103 if (style.free_spacing) {
3112 void LyXParagraph::SimpleTeXSpecialChars(ostream & os, TexRow & texrow,
3114 LyXFont & running_font,
3117 LyXLayout const & style,
3118 LyXParagraph::size_type & i,
3119 int & column, char const c)
3121 // Two major modes: LaTeX or plain
3122 // Handle here those cases common to both modes
3123 // and then split to handle the two modes separately.
3125 case LyXParagraph::META_INSET: {
3126 Inset * inset = GetInset(i);
3129 int len = os.tellp();
3130 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3131 || inset->LyxCode() == Inset::MATH_CODE
3132 || inset->LyxCode() == Inset::URL_CODE)
3133 && running_font.isRightToLeft()) {
3138 int tmp = inset->Latex(os, style.isCommand(),
3139 style.free_spacing);
3147 column += os.tellp() - len;
3156 case LyXParagraph::META_NEWLINE:
3158 column += running_font.latexWriteEndChanges(os,
3163 basefont = getFont(-1);
3164 running_font = basefont;
3167 case LyXParagraph::META_HFILL:
3173 // And now for the special cases within each mode
3174 // Are we in LaTeX mode?
3175 if (font.latex() == LyXFont::ON) {
3176 // at present we only have one option
3177 // but I'll leave it as a switch statement
3178 // so its simpler to extend. (ARRae)
3181 // make sure that we will not print
3182 // error generating chars to the tex
3183 // file. This test would not be needed
3184 // if it were done in the buffer
3192 // Plain mode (i.e. not LaTeX)
3195 os << "\\textbackslash{}";
3199 case '°': case '±': case '²': case '³':
3200 case '×': case '÷': case '¹': case 'ª':
3201 case 'º': case '¬': case 'µ':
3202 if (current_view->buffer()->params.inputenc == "latin1") {
3203 os << "\\ensuremath{"
3212 case '|': case '<': case '>':
3213 // In T1 encoding, these characters exist
3214 if (lyxrc.fontenc == "T1") {
3216 //... but we should avoid ligatures
3217 if ((c == '>' || c == '<')
3219 && GetChar(i + 1) == c){
3220 os << "\\textcompwordmark{}";
3225 // Typewriter font also has them
3226 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3230 // Otherwise, we use what LaTeX
3234 os << "\\textless{}";
3238 os << "\\textgreater{}";
3242 os << "\\textbar{}";
3248 case '-': // "--" in Typewriter mode -> "-{}-"
3250 && GetChar(i + 1) == '-'
3251 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3260 os << "\\char`\\\"{}";
3265 if (current_view->buffer()->params.inputenc == "default") {
3274 case '%': case '#': case '{':
3281 os << "\\textasciitilde{}";
3286 os << "\\textasciicircum{}";
3290 case '*': case '[': case ']':
3291 // avoid being mistaken for optional arguments
3292 os << '{' << c << '}';
3297 // Blanks are printed before font switching.
3298 // Sure? I am not! (try nice-latex)
3299 // I am sure it's correct. LyX might be smarter
3300 // in the future, but for now, nothing wrong is
3305 /* idea for labels --- begin*/
3309 && font.family() != LyXFont::TYPEWRITER_FAMILY
3310 && GetChar(i + 1) == 'y'
3311 && GetChar(i + 2) == 'X') {
3319 && font.family() != LyXFont::TYPEWRITER_FAMILY
3320 && GetChar(i + 1) == 'e'
3321 && GetChar(i + 2) == 'X') {
3326 // Check for "LaTeX2e"
3329 && font.family() != LyXFont::TYPEWRITER_FAMILY
3330 && GetChar(i + 1) == 'a'
3331 && GetChar(i + 2) == 'T'
3332 && GetChar(i + 3) == 'e'
3333 && GetChar(i + 4) == 'X'
3334 && GetChar(i + 5) == '2'
3335 && GetChar(i + 6) == 'e') {
3340 // Check for "LaTeX"
3343 && font.family() != LyXFont::TYPEWRITER_FAMILY
3344 && GetChar(i + 1) == 'a'
3345 && GetChar(i + 2) == 'T'
3346 && GetChar(i + 3) == 'e'
3347 && GetChar(i + 4) == 'X') {
3351 /* idea for labels --- end*/
3352 } else if (c != '\0') {
3363 bool LyXParagraph::RoffContTableRows(ostream & os,
3364 LyXParagraph::size_type i,
3370 LyXFont font1(LyXFont::ALL_INHERIT);
3375 string fname2 = TmpFileName(string(), "RAT2");
3377 int cell = table->CellHasContRow(actcell);
3380 // first find the right position
3382 for (; i < size() && actcell < cell; ++i) {
3384 if (c == LyXParagraph::META_NEWLINE)
3389 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3392 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3394 font2 = GetFontSettings(i);
3395 if (font1.latex() != font2.latex()) {
3396 if (font2.latex() != LyXFont::OFF)
3401 case LyXParagraph::META_INSET:
3402 if ((inset = GetInset(i))) {
3404 stringstream ss(ios::in | ios::out);
3431 case LyXParagraph::META_NEWLINE:
3433 case LyXParagraph::META_HFILL:
3442 lyxerr.debug() << "RoffAsciiTable: "
3443 "NULL char in structure."
3448 cell = table->CellHasContRow(actcell);
3455 LyXParagraph * LyXParagraph::TeXDeeper(ostream & os, TexRow & texrow,
3457 TexRow & foot_texrow,
3460 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3461 LyXParagraph * par = this;
3464 (par->depth == depth) &&
3465 (par->footnoteflag == footnoteflag)) {
3467 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3468 if (textclasslist.Style(current_view->buffer()->params.textclass,
3469 par->layout).isEnvironment()
3470 || par->pextra_type != PEXTRA_NONE) {
3471 par = par->TeXEnvironment(os, texrow,
3475 par = par->TeXOnePar(os, texrow,
3480 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3486 LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow,
3488 TexRow & foot_texrow,
3491 bool eindent_open = false;
3492 bool foot_this_level = false;
3493 // flags when footnotetext should be appended to file.
3494 static bool minipage_open = false;
3495 static int minipage_open_depth = 0;
3496 char par_sep = current_view->buffer()->params.paragraph_separation;
3498 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3500 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3502 LyXLayout const & style =
3503 textclasslist.Style(current_view->buffer()->params.textclass,
3506 if (pextra_type == PEXTRA_INDENT) {
3507 if (!pextra_width.empty()) {
3508 os << "\\begin{LyXParagraphIndent}{"
3509 << pextra_width << "}\n";
3511 //float ib = atof(pextra_widthp.c_str())/100;
3512 // string can't handle floats at present (971109)
3513 // so I'll do a conversion by hand knowing that
3514 // the limits are 0.0 to 1.0. ARRae.
3515 os << "\\begin{LyXParagraphIndent}{";
3516 switch (pextra_widthp.length()) {
3528 os << "\\columnwidth}\n";
3531 eindent_open = true;
3533 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3534 if (pextra_hfill && Previous() &&
3535 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3536 os << "\\hfill{}\n";
3539 if (par_sep == BufferParams::PARSEP_INDENT) {
3540 os << "{\\setlength\\parindent{0pt}\n";
3543 os << "\\begin{minipage}";
3544 switch(pextra_alignment) {
3545 case MINIPAGE_ALIGN_TOP:
3548 case MINIPAGE_ALIGN_MIDDLE:
3551 case MINIPAGE_ALIGN_BOTTOM:
3555 if (!pextra_width.empty()) {
3556 os << '{' << pextra_width << "}\n";
3558 //float ib = atof(par->pextra_width.c_str())/100;
3559 // string can't handle floats at present
3560 // so I'll do a conversion by hand knowing that
3561 // the limits are 0.0 to 1.0. ARRae.
3563 switch (pextra_widthp.length()) {
3575 os << "\\columnwidth}\n";
3578 if (par_sep == BufferParams::PARSEP_INDENT) {
3579 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3582 minipage_open = true;
3583 minipage_open_depth = depth;
3586 #ifdef WITH_WARNINGS
3587 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3588 //I disabled it because it breaks when lists span on several
3591 if (style.isEnvironment()){
3592 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3593 #ifdef FANCY_FOOTNOTE_CODE
3594 if (foot_count < 0) {
3595 // flag that footnote[mark][text] should be
3596 // used for any footnotes from now on
3598 foot_this_level = true;
3601 os << "\\begin{" << style.latexname() << "}{"
3602 << labelwidthstring << "}\n";
3603 } else if (style.labeltype == LABEL_BIBLIO) {
3605 os << "\\begin{" << style.latexname() << "}{"
3606 << bibitemWidthest(current_view->painter())
3608 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3609 #ifdef FANCY_FOOTNOTE_CODE
3610 if (foot_count < 0) {
3611 // flag that footnote[mark][text] should be
3612 // used for any footnotes from now on
3614 foot_this_level = true;
3617 os << "\\begin{" << style.latexname() << '}'
3618 << style.latexparam() << '\n';
3620 os << "\\begin{" << style.latexname() << '}'
3621 << style.latexparam() << '\n';
3624 LyXParagraph * par = this;
3626 par = par->TeXOnePar(os, texrow,
3627 foot, foot_texrow, foot_count);
3629 if (minipage_open && par && !style.isEnvironment() &&
3630 (par->pextra_type == PEXTRA_MINIPAGE) &&
3631 par->pextra_start_minipage) {
3632 os << "\\end{minipage}\n";
3634 if (par_sep == BufferParams::PARSEP_INDENT) {
3638 minipage_open = false;
3640 if (par && par->depth > depth) {
3641 if (textclasslist.Style(current_view->buffer()->params.textclass,
3642 par->layout).isParagraph()
3645 // How to handle this? (Lgb)
3646 //&& !suffixIs(os, "\n\n")
3648 // There should be at least one '\n' already
3649 // but we need there to be two for Standard
3650 // paragraphs that are depth-increment'ed to be
3651 // output correctly. However, tables can
3652 // also be paragraphs so don't adjust them.
3655 // Will it ever harm to have one '\n' too
3656 // many? i.e. that we sometimes will have
3657 // three in a row. (Lgb)
3661 par = par->TeXDeeper(os, texrow,
3662 foot, foot_texrow, foot_count);
3664 if (par && par->layout == layout && par->depth == depth &&
3665 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3666 if (par->pextra_hfill && par->Previous() &&
3667 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3668 os << "\\hfill{}\n";
3671 if (par_sep == BufferParams::PARSEP_INDENT) {
3672 os << "{\\setlength\\parindent{0pt}\n";
3675 os << "\\begin{minipage}";
3676 switch(par->pextra_alignment) {
3677 case MINIPAGE_ALIGN_TOP:
3680 case MINIPAGE_ALIGN_MIDDLE:
3683 case MINIPAGE_ALIGN_BOTTOM:
3687 if (!par->pextra_width.empty()) {
3688 os << '{' << par->pextra_width << "}\n";
3690 //float ib = atof(par->pextra_widthp.c_str())/100;
3691 // string can't handle floats at present
3692 // so I'll do a conversion by hand knowing that
3693 // the limits are 0.0 to 1.0. ARRae.
3695 switch (par->pextra_widthp.length()) {
3700 os << "0." << par->pextra_widthp;
3703 os << "0.0" << par->pextra_widthp;
3705 os << "\\columnwidth}\n";
3708 if (par_sep == BufferParams::PARSEP_INDENT) {
3709 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3712 minipage_open = true;
3713 minipage_open_depth = par->depth;
3716 && par->layout == layout
3717 && par->depth == depth
3718 && par->pextra_type == pextra_type
3719 && par->footnoteflag == footnoteflag);
3721 if (style.isEnvironment()) {
3722 os << "\\end{" << style.latexname() << '}';
3723 // maybe this should go after the minipage closes?
3724 if (foot_this_level) {
3725 if (foot_count >= 1) {
3726 if (foot_count > 1) {
3727 os << "\\addtocounter{footnote}{-"
3732 texrow += foot_texrow;
3734 foot_texrow.reset();
3739 if (minipage_open && (minipage_open_depth == depth) &&
3740 (!par || par->pextra_start_minipage ||
3741 par->pextra_type != PEXTRA_MINIPAGE)) {
3742 os << "\\end{minipage}\n";
3744 if (par_sep == BufferParams::PARSEP_INDENT) {
3748 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3749 os << "\\medskip\n\n";
3753 minipage_open = false;
3756 os << "\\end{LyXParagraphIndent}\n";
3759 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3760 && par->pextra_hfill)) {
3764 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3765 return par; // ale970302
3769 LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow,
3770 ostream & foot, TexRow & foot_texrow,
3774 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3775 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3776 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3777 "No footnote!" << endl;
3779 LyXParagraph * par = this;
3780 LyXLayout const & style =
3781 textclasslist.Style(current_view->buffer()->params.textclass,
3782 previous->GetLayout());
3784 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3785 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3786 "Float other than footnote in command"
3787 " with moving argument is illegal" << endl;
3790 if (footnotekind != LyXParagraph::FOOTNOTE
3791 && footnotekind != LyXParagraph::MARGIN
3794 // How to solve this?
3795 //&& !suffixIs(file, '\n')
3797 // we need to ensure that real floats like tables and figures
3798 // have their \begin{} on a new line otherwise we can get
3799 // incorrect results when using the endfloat.sty package
3800 // especially if two floats follow one another. ARRae 981022
3801 // NOTE: if the file is length 0 it must have just been
3802 // written out so we assume it ended with a '\n'
3804 // As far as I can see there is never any harm in writing
3805 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3810 bool need_closing = false;
3811 bool is_rtl = isRightToLeftPar();
3812 if (is_rtl != parent_is_rtl) {
3817 need_closing = true;
3820 BufferParams * params = ¤t_view->buffer()->params;
3821 bool footer_in_body = true;
3822 switch (footnotekind) {
3823 case LyXParagraph::FOOTNOTE:
3824 if (style.intitle) {
3825 os << "\\thanks{\n";
3826 footer_in_body = false;
3828 if (foot_count == -1) {
3829 // we're at depth 0 so we can use:
3830 os << "\\footnote{%\n";
3831 footer_in_body = false;
3833 os << "\\footnotemark{}%\n";
3835 // we only need this when there are
3836 // multiple footnotes
3837 os << "\\stepcounter{footnote}";
3839 os << "\\footnotetext{%\n";
3840 foot_texrow.start(this, 0);
3841 foot_texrow.newline();
3846 case LyXParagraph::MARGIN:
3847 os << "\\marginpar{\n";
3849 case LyXParagraph::FIG:
3850 if (pextra_type == PEXTRA_FLOATFLT
3851 && (!pextra_width.empty()
3852 || !pextra_widthp.empty())) {
3853 if (!pextra_width.empty())
3854 os << "\\begin{floatingfigure}{"
3855 << pextra_width << "}\n";
3857 os << "\\begin{floatingfigure}{"
3858 << atoi(pextra_widthp.c_str())/100.0
3859 << "\\textwidth}\n";
3861 os << "\\begin{figure}";
3862 if (!params->float_placement.empty()) {
3863 os << '[' << params->float_placement << "]\n";
3869 case LyXParagraph::TAB:
3870 os << "\\begin{table}";
3871 if (!params->float_placement.empty()) {
3872 os << '[' << params->float_placement << "]\n";
3877 case LyXParagraph::WIDE_FIG:
3878 os << "\\begin{figure*}";
3879 if (!params->float_placement.empty()) {
3880 os << '[' << params->float_placement << "]\n";
3885 case LyXParagraph::WIDE_TAB:
3886 os << "\\begin{table*}";
3887 if (!params->float_placement.empty()) {
3888 os << '[' << params->float_placement << "]\n";
3893 case LyXParagraph::ALGORITHM:
3894 os << "\\begin{algorithm}\n";
3899 if (footnotekind != LyXParagraph::FOOTNOTE
3900 || !footer_in_body) {
3901 // Process text for all floats except footnotes in body
3903 LyXLayout const & style =
3905 .Style(current_view->buffer()->params
3909 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3911 if (style.isEnvironment()
3912 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3913 // Allows the use of minipages within float
3914 // environments. Shouldn't be circular because
3915 // we don't support footnotes inside
3916 // floats (yet). ARRae
3917 par = par->TeXEnvironment(os, texrow,
3921 par = par->TeXOnePar(os, texrow,
3926 if (par && !par->IsDummy() && par->depth > depth) {
3927 par = par->TeXDeeper(os, texrow,
3931 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3933 // process footnotes > depth 0 or in environments separately
3934 // NOTE: Currently don't support footnotes within footnotes
3935 // even though that is possible using the \footnotemark
3937 std::ostringstream dummy;
3941 TexRow dummy_texrow;
3942 int dummy_count = 0;
3944 LyXLayout const & style =
3946 .Style(current_view->buffer()->params
3950 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3952 if (style.isEnvironment()
3953 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3954 // Allows the use of minipages within float
3955 // environments. Shouldn't be circular because
3956 // we don't support footnotes inside
3957 // floats (yet). ARRae
3958 par = par->TeXEnvironment(foot, foot_texrow,
3959 dummy, dummy_texrow,
3962 par = par->TeXOnePar(foot, foot_texrow,
3963 dummy, dummy_texrow,
3967 if (par && !par->IsDummy() && par->depth > depth) {
3968 par = par->TeXDeeper(foot, foot_texrow,
3969 dummy, dummy_texrow,
3973 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3975 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3976 "Footnote in a Footnote -- not supported"
3979 #ifndef HAVE_OSTREAM
3980 delete [] dummy.str();
3984 switch (footnotekind) {
3985 case LyXParagraph::FOOTNOTE:
3986 if (footer_in_body) {
3987 // This helps tell which of the multiple
3988 // footnotetexts an error was in.
3990 foot_texrow.newline();
3995 case LyXParagraph::MARGIN:
3998 case LyXParagraph::FIG:
3999 if (pextra_type == PEXTRA_FLOATFLT
4000 && (!pextra_width.empty()
4001 || !pextra_widthp.empty()))
4002 os << "\\end{floatingfigure}";
4004 os << "\\end{figure}";
4006 case LyXParagraph::TAB:
4007 os << "\\end{table}";
4009 case LyXParagraph::WIDE_FIG:
4010 os << "\\end{figure*}";
4012 case LyXParagraph::WIDE_TAB:
4013 os << "\\end{table*}";
4015 case LyXParagraph::ALGORITHM:
4016 os << "\\end{algorithm}";
4023 if (footnotekind != LyXParagraph::FOOTNOTE
4024 && footnotekind != LyXParagraph::MARGIN) {
4025 // we need to ensure that real floats like tables and figures
4026 // have their \end{} on a line of their own otherwise we can
4027 // get incorrect results when using the endfloat.sty package.
4032 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4037 bool LyXParagraph::IsDummy() const
4039 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4040 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4044 void LyXParagraph::SetPExtraType(int type, char const * width,
4045 char const * widthp)
4048 pextra_width = width;
4049 pextra_widthp = widthp;
4051 if (textclasslist.Style(current_view->buffer()->params.textclass,
4052 layout).isEnvironment()) {
4057 while (par && (par->layout == layout)
4058 && (par->depth == depth)) {
4060 par = par->Previous();
4062 par = par->FirstPhysicalPar();
4063 while (par && par->depth > depth) {
4064 par = par->Previous();
4066 par = par->FirstPhysicalPar();
4070 while (par && (par->layout == layout)
4071 && (par->depth == depth)) {
4072 par->pextra_type = type;
4073 par->pextra_width = width;
4074 par->pextra_widthp = widthp;
4075 par = par->NextAfterFootnote();
4076 if (par && (par->depth > depth))
4077 par->SetPExtraType(type, width, widthp);
4078 while (par && ((par->depth > depth) || par->IsDummy()))
4079 par = par->NextAfterFootnote();
4085 void LyXParagraph::UnsetPExtraType()
4087 if (pextra_type == PEXTRA_NONE)
4090 pextra_type = PEXTRA_NONE;
4091 pextra_width.erase();
4092 pextra_widthp.erase();
4094 if (textclasslist.Style(current_view->buffer()->params.textclass,
4095 layout).isEnvironment()) {
4100 while (par && (par->layout == layout)
4101 && (par->depth == depth)) {
4103 par = par->Previous();
4105 par = par->FirstPhysicalPar();
4106 while (par && par->depth > depth) {
4107 par = par->Previous();
4109 par = par->FirstPhysicalPar();
4113 while (par && (par->layout == layout)
4114 && (par->depth == depth)) {
4115 par->pextra_type = PEXTRA_NONE;
4116 par->pextra_width.erase();
4117 par->pextra_widthp.erase();
4118 par = par->NextAfterFootnote();
4119 if (par && (par->depth > depth))
4120 par->UnsetPExtraType();
4121 while (par && ((par->depth > depth) || par->IsDummy()))
4122 par = par->NextAfterFootnote();
4128 bool LyXParagraph::IsHfill(size_type pos) const
4130 return IsHfillChar(GetChar(pos));
4134 bool LyXParagraph::IsInset(size_type pos) const
4136 return IsInsetChar(GetChar(pos));
4140 bool LyXParagraph::IsFloat(size_type pos) const
4142 return IsFloatChar(GetChar(pos));
4146 bool LyXParagraph::IsNewline(size_type pos) const
4148 return pos >= 0 && IsNewlineChar(GetChar(pos));
4152 bool LyXParagraph::IsSeparator(size_type pos) const
4154 return IsSeparatorChar(GetChar(pos));
4158 bool LyXParagraph::IsLineSeparator(size_type pos) const
4160 return IsLineSeparatorChar(GetChar(pos));
4164 bool LyXParagraph::IsKomma(size_type pos) const
4166 return IsKommaChar(GetChar(pos));
4170 /// Used by the spellchecker
4171 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4173 unsigned char c = GetChar(pos);
4174 if (IsLetterChar(c))
4176 // '\0' is not a letter, allthough every string contains "" (below)
4179 // We want to pass the ' and escape chars to ispell
4180 string extra = lyxrc.isp_esc_chars + '\'';
4184 return contains(extra, ch);
4188 bool LyXParagraph::IsWord(size_type pos ) const
4190 return IsWordChar(GetChar(pos)) ;
4194 Language const * LyXParagraph::getParLanguage() const
4198 return FirstPhysicalPar()->GetFirstFontSettings()
4201 for (size_type pos = 0; pos < size(); ++pos)
4203 return GetFontSettings(pos).language();
4204 return GetFirstFontSettings().language();
4207 return previous->getParLanguage();
4209 return current_view->buffer()->params.language_info;
4213 bool LyXParagraph::isRightToLeftPar() const
4215 return lyxrc.rtl_support && !table && getParLanguage()->RightToLeft;
4219 void LyXParagraph::ChangeLanguage(Language const * from, Language const * to)
4221 for(size_type i = 0; i < size(); ++i) {
4222 LyXFont font = GetFontSettings(i);
4223 if (font.language() == from) {
4224 font.setLanguage(to);
4231 bool LyXParagraph::isMultiLingual()
4233 Language const * doc_language =
4234 current_view->buffer()->params.language_info;
4235 for(size_type i = 0; i < size(); ++i) {
4236 LyXFont font = GetFontSettings(i);
4237 if (font.language() != doc_language)