- // > because last is the next unused position, and you can
- // use it if you want
- if (pos > size()) {
- if (next &&
- next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
- NextAfterFootnote()->SetFont(pos - text.size() - 1,
- font);
- } else {
- lyxerr << "ERROR (LyXParagraph::SetFont): "
- "position does not exist." << endl;
- }
- return;
- }
- LyXFont patternfont(LyXFont::ALL_INHERIT);
-
- // First, reduce font against layout/label font
- // Update: The SetCharFont() routine in text2.C already
- // reduces font, so we don't need to do that here. (Asger)
- // No need to simplify this because it will disappear
- // in a new kernel. (Asger)
- // Next search font table
- FontList::iterator tmp = fontlist.begin();
- for (; tmp != fontlist.end(); ++tmp) {
- if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
- break;
- }
- }
- if (tmp == fontlist.end()) { // !found
- // if we did not find a font entry, but if the font at hand
- // is the same as default, we just forget it
- if (font == patternfont) return;
-
- // ok, we did not find a font entry. But maybe there is exactly
- // the needed font ientry one position left
- FontList::iterator tmp2 = fontlist.begin();
- for (; tmp2 != fontlist.end(); ++tmp2) {
- if (pos - 1 >= (*tmp2).pos
- && pos - 1 <= (*tmp2).pos_end)
- break;
- }
- if (tmp2 != fontlist.end()) {
- // ok there is one, maybe it is exactly
- // the needed font
- if ((*tmp2).font == font) {
- // put the position under the font
- (*tmp2).pos_end++;
- return;
- }
- }
- // Add a new entry in the
- // fontlist for the position
- FontTable ft;
- ft.pos = pos;
- ft.pos_end = pos;
- ft.font = font; // or patternfont
- // It seems that using font instead of patternfont here
- // fixes all the problems. This also surfaces a "bug" in
- // the old code.
- fontlist.insert(fontlist.begin(), ft);
- } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
-
-// more than one character
- if (pos == (*tmp).pos) {
- // maybe we should enlarge the left fonttable
- FontList::iterator tmp2 = fontlist.begin();
- for (; tmp2 != fontlist.end(); ++tmp2) {
- if (pos - 1 >= (*tmp2).pos
- && pos - 1 <= (*tmp2).pos_end)
- break;
- }
- // Is there is one, and is it exactly
- // the needed font?
- if (tmp2 != fontlist.end() &&
- (*tmp2).font == font) {
- // Put the position under the font
- (*tmp2).pos_end++;
- (*tmp).pos++;
- return;
- }
-
- // Add a new entry in the
- // fontlist for the position
- FontTable ft;
- ft.pos = pos + 1;
- ft.pos_end = (*tmp).pos_end;
- ft.font = (*tmp).font;
- (*tmp).pos_end = pos;
- (*tmp).font = font;
- fontlist.insert(fontlist.begin(), ft);
- } else if (pos == (*tmp).pos_end) {
- // Add a new entry in the
- // fontlist for the position
- FontTable ft;
- ft.pos = (*tmp).pos;
- ft.pos_end = (*tmp).pos_end - 1;
- ft.font = (*tmp).font;
- (*tmp).pos = (*tmp).pos_end;
- (*tmp).font = font;
- fontlist.insert(fontlist.begin(), ft);
- } else {
- // Add a new entry in the
- // fontlist for the position
- FontTable ft;
- ft.pos = (*tmp).pos;
- ft.pos_end = pos - 1;
- ft.font = (*tmp).font;
-
- FontTable ft2;
- ft2.pos = pos + 1;
- ft2.pos_end = (*tmp).pos_end;
- ft2.font = (*tmp).font;
-
- (*tmp).pos = pos;
- (*tmp).pos_end = pos;
- (*tmp).font = font;
-
- fontlist.insert(fontlist.begin(), ft);
- fontlist.insert(fontlist.begin(), ft2);
- }
- } else {
- (*tmp).font = font;
- }
-}
-
-
-// This function is able to hide closed footnotes.
-LyXParagraph * LyXParagraph::Next()
-{
- if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
- LyXParagraph * tmp = next;
- while (tmp
- && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
- tmp = tmp->next;
- if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
- return tmp->Next(); /* there can be more than one
- footnote in a logical
- paragraph */
- else
- return next; // This should never happen!
- } else
- return next;
-}
-
-
-LyXParagraph * LyXParagraph::NextAfterFootnote()
-{
- if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
- LyXParagraph * tmp = next;
- while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
- tmp = tmp->next;
- if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
- return tmp; /* there can be more than one footnote
- in a logical paragraph */
- else
- return next; // This should never happen!
- } else
- return next;
-}
-
-
-LyXParagraph const * LyXParagraph::NextAfterFootnote() const
-{
- if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
- LyXParagraph * tmp = next;
- while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
- tmp = tmp->next;
- if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
- return tmp; /* there can be more than one footnote
- in a logical paragraph */
- else
- return next; // This should never happen!
- } else
- return next;
-}
-
-
-LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
-{
- LyXParagraph * tmp;
- if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
- tmp = previous;
- while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
- tmp = tmp->previous;
- if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
- return tmp; /* there can be more than one footnote
- in a logical paragraph */
- else
- return previous; // This should never happen!
- } else
- return previous;
-}
-
-
-LyXParagraph * LyXParagraph::LastPhysicalPar()
-{
- if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
- return this;
-
- LyXParagraph * tmp = this;
- while (tmp->next
- && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
- tmp = tmp->NextAfterFootnote();
-
- return tmp;
-}
-
-LyXParagraph const * LyXParagraph::LastPhysicalPar() const
-{
- if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
- return this;
-
- LyXParagraph const * tmp = this;
- while (tmp->next
- && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
- tmp = tmp->NextAfterFootnote();
-
- return tmp;
-}
-
-LyXParagraph * LyXParagraph::FirstPhysicalPar()
-{
- if (!IsDummy())
- return this;
- LyXParagraph * tmppar = this;
-
- while (tmppar &&
- (tmppar->IsDummy()
- || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
- tmppar = tmppar->previous;
-
- if (!tmppar) {
- return this;
- } else
- return tmppar;
-}
-
-
-LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
-{
- if (!IsDummy())
- return this;
- LyXParagraph const * tmppar = this;
-
- while (tmppar &&
- (tmppar->IsDummy()
- || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
- tmppar = tmppar->previous;
-
- if (!tmppar) {
- return this;
- } else
- return tmppar;
-}
-
-
-// This function is able to hide closed footnotes.
-LyXParagraph * LyXParagraph::Previous()
-{
- LyXParagraph * tmp = previous;
- if (!tmp)
- return tmp;
-
- if (tmp->previous
- && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
- tmp = tmp->previous;
- while (tmp
- && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
- tmp = tmp->previous;
- if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
- return tmp->next->Previous();
-
- else
- return previous;
- } else
- return previous;
-}
-
-
-// This function is able to hide closed footnotes.
-LyXParagraph const * LyXParagraph::Previous() const
-{
- LyXParagraph * tmp = previous;
- if (!tmp)
- return tmp;
-
- if (tmp->previous
- && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
- tmp = tmp->previous;
- while (tmp
- && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
- tmp = tmp->previous;
- if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
- return tmp->next->Previous();
-
- else
- return previous;
- } else
- return previous;