3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Asger Alstrup
7 * \author Lars Gullik Bjønnes
8 * \author Jean-Marc Lasgouttes
10 * \author André Pönitz
12 * \author Jürgen Vigna
14 * Full author contact details are available in file CREDITS.
22 #include "bufferparams.h"
23 #include "BufferView.h"
25 #include "dispatchresult.h"
27 #include "funcrequest.h"
31 #include "lyxlength.h"
35 #include "lyxrow_funcs.h"
36 #include "metricsinfo.h"
37 #include "paragraph.h"
38 #include "paragraph_funcs.h"
39 #include "ParagraphParameters.h"
40 #include "rowpainter.h"
43 #include "WordLangTuple.h"
45 #include "frontends/font_metrics.h"
46 #include "frontends/LyXView.h"
48 #include "insets/insettext.h"
50 #include "support/lstrings.h"
51 #include "support/textutils.h"
54 using lyx::word_location;
56 using lyx::support::contains;
57 using lyx::support::lowercase;
58 using lyx::support::uppercase;
65 /// some space for drawing the 'nested' markers (in pixel)
66 extern int const NEST_MARGIN = 20;
67 /// margin for changebar
68 extern int const CHANGEBAR_MARGIN = 10;
70 extern int const RIGHT_MARGIN = 10;
75 unsigned int maxParagraphWidth(ParagraphList const & plist)
77 unsigned int width = 0;
78 ParagraphList::const_iterator pit = plist.begin();
79 ParagraphList::const_iterator end = plist.end();
80 for (; pit != end; ++pit)
81 width = std::max(width, pit->width);
88 BufferView * LyXText::bv()
90 BOOST_ASSERT(bv_owner != 0);
95 double LyXText::spacing(Paragraph const & par) const
97 if (par.params().spacing().isDefault())
98 return bv()->buffer()->params().spacing().getValue();
99 return par.params().spacing().getValue();
103 BufferView * LyXText::bv() const
105 BOOST_ASSERT(bv_owner != 0);
110 void LyXText::updateParPositions()
112 ParagraphList::iterator pit = paragraphs().begin();
113 ParagraphList::iterator end = paragraphs().end();
114 for (height = 0; pit != end; ++pit) {
116 height += pit->height;
121 int LyXText::textWidth() const
127 int LyXText::singleWidth(ParagraphList::iterator pit, pos_type pos) const
129 if (pos >= pit->size())
132 char const c = pit->getChar(pos);
133 return singleWidth(pit, pos, c, getFont(pit, pos));
137 int LyXText::singleWidth(ParagraphList::iterator pit,
138 pos_type pos, char c, LyXFont const & font) const
140 if (pos >= pit->size()) {
141 lyxerr << "in singleWidth(), pos: " << pos << endl;
146 // The most common case is handled first (Asger)
147 if (IsPrintable(c)) {
148 if (!font.language()->RightToLeft()) {
149 if ((lyxrc.font_norm_type == LyXRC::ISO_8859_6_8 ||
150 lyxrc.font_norm_type == LyXRC::ISO_10646_1)
151 && font.language()->lang() == "arabic") {
152 if (Encodings::IsComposeChar_arabic(c))
155 c = pit->transformChar(c, pos);
156 } else if (font.language()->lang() == "hebrew" &&
157 Encodings::IsComposeChar_hebrew(c))
160 return font_metrics::width(c, font);
163 if (c == Paragraph::META_INSET)
164 return pit->getInset(pos)->width();
166 if (IsSeparatorChar(c))
168 return font_metrics::width(c, font);
172 int LyXText::leftMargin(ParagraphList::iterator pit) const
174 return leftMargin(pit, pit->size());
178 int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const
180 LyXTextClass const & tclass =
181 bv()->buffer()->params().getLyXTextClass();
182 LyXLayout_ptr const & layout = pit->layout();
184 string parindent = layout->parindent;
186 int x = NEST_MARGIN + CHANGEBAR_MARGIN;
188 x += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
190 // This is the way LyX handles LaTeX-Environments.
191 // I have had this idea very late, so it seems to be a
192 // later added hack and this is true
193 if (pit->getDepth() == 0) {
194 if (pit->layout() == tclass.defaultLayout()) {
195 // find the previous same level paragraph
196 if (pit != paragraphs().begin()) {
197 ParagraphList::iterator newpit =
198 depthHook(pit, paragraphs(), pit->getDepth());
199 if (newpit == pit && newpit->layout()->nextnoindent)
204 // find the next level paragraph
205 ParagraphList::iterator newpar =
206 outerHook(pit, paragraphs());
208 // Make a corresponding row. Need to call leftMargin()
209 // to check whether it is a sufficent paragraph.
210 if (newpar != paragraphs().end()
211 && newpar->layout()->isEnvironment()) {
212 x = leftMargin(newpar);
215 if (newpar != paragraphs().end()
216 && pit->layout() == tclass.defaultLayout()) {
217 if (newpar->params().noindent())
220 parindent = newpar->layout()->parindent;
224 LyXFont const labelfont = getLabelFont(pit);
225 switch (layout->margintype) {
227 if (!layout->leftmargin.empty())
228 x += font_metrics::signedWidth(layout->leftmargin,
229 tclass.defaultfont());
230 if (!pit->getLabelstring().empty()) {
231 x += font_metrics::signedWidth(layout->labelindent,
233 x += font_metrics::width(pit->getLabelstring(),
235 x += font_metrics::width(layout->labelsep, labelfont);
240 x += font_metrics::signedWidth(layout->labelindent, labelfont);
241 // The width of an empty par, even with manual label, should be 0
242 if (!pit->empty() && pos >= pit->beginOfBody()) {
243 if (!pit->getLabelWidthString().empty()) {
244 x += font_metrics::width(pit->getLabelWidthString(),
246 x += font_metrics::width(layout->labelsep, labelfont);
252 x += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
253 / (pit->getDepth() + 4);
256 case MARGIN_FIRST_DYNAMIC:
257 if (layout->labeltype == LABEL_MANUAL) {
258 if (pos >= pit->beginOfBody()) {
259 x += font_metrics::signedWidth(layout->leftmargin,
262 x += font_metrics::signedWidth(layout->labelindent,
266 // Special case to fix problems with
268 || (layout->labeltype == LABEL_STATIC
269 && layout->latextype == LATEX_ENVIRONMENT
270 && !isFirstInSequence(pit, paragraphs()))) {
271 x += font_metrics::signedWidth(layout->leftmargin,
273 } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
274 && layout->labeltype != LABEL_BIBLIO
275 && layout->labeltype !=
276 LABEL_CENTERED_TOP_ENVIRONMENT) {
277 x += font_metrics::signedWidth(layout->labelindent,
279 x += font_metrics::width(layout->labelsep, labelfont);
280 x += font_metrics::width(pit->getLabelstring(),
285 case MARGIN_RIGHT_ADDRESS_BOX: {
287 // ok, a terrible hack. The left margin depends on the widest
288 // row in this paragraph.
289 RowList::iterator rit = pit->rows.begin();
290 RowList::iterator end = pit->rows.end();
291 #warning This is wrong.
292 int minfill = textwidth_;
293 for ( ; rit != end; ++rit)
294 if (rit->fill() < minfill)
295 minfill = rit->fill();
296 x += font_metrics::signedWidth(layout->leftmargin,
297 tclass.defaultfont());
300 // also wrong, but much shorter.
306 if (!pit->params().leftIndent().zero())
307 x += pit->params().leftIndent().inPixels(textWidth());
311 if (pit->params().align() == LYX_ALIGN_LAYOUT)
312 align = layout->align;
314 align = pit->params().align();
316 // set the correct parindent
318 && (layout->labeltype == LABEL_NO_LABEL
319 || layout->labeltype == LABEL_TOP_ENVIRONMENT
320 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT
321 || (layout->labeltype == LABEL_STATIC
322 && layout->latextype == LATEX_ENVIRONMENT
323 && !isFirstInSequence(pit, paragraphs())))
324 && align == LYX_ALIGN_BLOCK
325 && !pit->params().noindent()
326 // in tabulars and ert paragraphs are never indented!
328 || !pit->inInset()->owner()
329 || (pit->inInset()->owner()->lyxCode() != InsetOld::TABULAR_CODE
330 && pit->inInset()->owner()->lyxCode() != InsetOld::ERT_CODE))
331 && (pit->layout() != tclass.defaultLayout()
332 || bv()->buffer()->params().paragraph_separation ==
333 BufferParams::PARSEP_INDENT))
335 x += font_metrics::signedWidth(parindent, tclass.defaultfont());
342 int LyXText::rightMargin(Paragraph const & par) const
344 LyXTextClass const & tclass = bv()->buffer()->params().getLyXTextClass();
348 + font_metrics::signedWidth(tclass.rightmargin(),
349 tclass.defaultfont())
350 + font_metrics::signedWidth(par.layout()->rightmargin,
351 tclass.defaultfont())
352 * 4 / (par.getDepth() + 4);
356 int LyXText::labelEnd(ParagraphList::iterator pit) const
358 // labelEnd is only needed if the layout fills a flushleft label.
359 if (pit->layout()->margintype != MARGIN_MANUAL)
361 // return the beginning of the body
362 return leftMargin(pit);
368 // this needs special handling - only newlines count as a break point
369 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
371 pos_type const end = par.size();
374 if (par.isNewline(i))
383 void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
385 pos_type const end = pit->size();
386 pos_type const pos = row.pos();
392 // maximum pixel width of a row
393 int width = textWidth() - rightMargin(*pit); // - leftMargin(pit, row);
399 LyXLayout_ptr const & layout = pit->layout();
401 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
402 row.endpos(addressBreakPoint(pos, *pit));
406 pos_type const body_pos = pit->beginOfBody();
409 // Now we iterate through until we reach the right margin
410 // or the end of the par, then choose the possible break
413 int const left = leftMargin(pit, pos);
416 // pixel width since last breakpoint
420 // We re-use the font resolution for the entire font span when possible
421 LyXFont font = getFont(pit, pos);
422 lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(pos);
424 pos_type point = end;
426 for ( ; i < end; ++i) {
427 if (pit->isNewline(i)) {
433 if (pit->isInset(i + 1) && pit->getInset(i + 1)->display()) {
438 if (pit->isInset(i) && pit->getInset(i)->display()) {
444 char const c = pit->getChar(i);
446 if (i > endPosOfFontSpan) {
447 font = getFont(pit, i);
448 endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
452 int thiswidth = singleWidth(pit, i, c, font);
454 // add the auto-hfill from label end to the body
455 if (body_pos && i == body_pos) {
456 int add = font_metrics::width(layout->labelsep, getLabelFont(pit));
457 if (pit->isLineSeparator(i - 1))
458 add -= singleWidth(pit, i - 1);
460 add = std::max(add, labelEnd(pit) - x);
465 //lyxerr << "i: " << i << " x: "
466 //<< x << " width: " << width << endl;
467 chunkwidth += thiswidth;
470 // break before a character that will fall off
471 // the right of the row
473 // if no break before, break here
474 if (point == end || chunkwidth >= width - left) {
480 // exit on last registered breakpoint:
484 if (!pit->isInset(i) || pit->getInset(i)->isChar()) {
485 // some insets are line separators too
486 if (pit->isLineSeparator(i)) {
487 // register breakpoint:
494 if (i == end && x < width) {
495 // maybe found one, but the par is short enough.
499 // manual labels cannot be broken in LaTeX. But we
500 // want to make our on-screen rendering of footnotes
502 if (body_pos && point < body_pos)
509 // returns the minimum space a row needs on the screen in pixel
510 void LyXText::fill(ParagraphList::iterator pit, Row & row, int workwidth) const
512 // get the pure distance
513 pos_type const end = row.endpos();
515 string labelsep = pit->layout()->labelsep;
516 int w = leftMargin(pit, row.pos());
518 pos_type const body_pos = pit->beginOfBody();
519 pos_type i = row.pos();
522 // We re-use the font resolution for the entire span when possible
523 LyXFont font = getFont(pit, i);
524 lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
525 for ( ; i < end; ++i) {
526 if (body_pos > 0 && i == body_pos) {
527 w += font_metrics::width(labelsep, getLabelFont(pit));
528 if (pit->isLineSeparator(i - 1))
529 w -= singleWidth(pit, i - 1);
530 w = max(w, labelEnd(pit));
532 char const c = pit->getChar(i);
533 if (IsPrintable(c) && i > endPosOfFontSpan) {
534 // We need to get the next font
535 font = getFont(pit, i);
536 endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
538 w += singleWidth(pit, i, c, font);
542 if (body_pos > 0 && body_pos >= end) {
543 w += font_metrics::width(labelsep, getLabelFont(pit));
544 if (end > 0 && pit->isLineSeparator(end - 1))
545 w -= singleWidth(pit, end - 1);
546 w = max(w, labelEnd(pit));
549 int const fill = workwidth - w - rightMargin(*pit);
551 row.width(workwidth - fill);
555 // returns the minimum space a manual label needs on the screen in pixel
556 int LyXText::labelFill(ParagraphList::iterator pit, Row const & row) const
558 pos_type last = pit->beginOfBody();
560 BOOST_ASSERT(last > 0);
562 // -1 because a label ends with a space that is in the label
565 // a separator at this end does not count
566 if (pit->isLineSeparator(last))
570 for (pos_type i = row.pos(); i <= last; ++i)
571 w += singleWidth(pit, i);
573 string const & label = pit->params().labelWidthString();
577 return max(0, font_metrics::width(label, getLabelFont(pit)) - w);
581 LColor_color LyXText::backgroundColor() const
583 return LColor_color(LColor::color(background_color_));
587 void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row)
589 // get the maximum ascent and the maximum descent
590 double layoutasc = 0;
591 double layoutdesc = 0;
592 double const dh = defaultRowHeight();
594 // ok, let us initialize the maxasc and maxdesc value.
595 // Only the fontsize count. The other properties
596 // are taken from the layoutfont. Nicer on the screen :)
597 LyXLayout_ptr const & layout = pit->layout();
599 // as max get the first character of this row then it can increase but not
600 // decrease the height. Just some point to start with so we don't have to
601 // do the assignment below too often.
602 LyXFont font = getFont(pit, row.pos());
603 LyXFont::FONT_SIZE const tmpsize = font.size();
604 font = getLayoutFont(pit);
605 LyXFont::FONT_SIZE const size = font.size();
606 font.setSize(tmpsize);
608 LyXFont labelfont = getLabelFont(pit);
610 // these are minimum values
611 double const spacing_val = layout->spacing.getValue() * spacing(*pit);
612 //lyxerr << "spacing_val = " << spacing_val << endl;
613 int maxasc = int(font_metrics::maxAscent(font) * spacing_val);
614 int maxdesc = int(font_metrics::maxDescent(font) * spacing_val);
616 // insets may be taller
617 InsetList::iterator ii = pit->insetlist.begin();
618 InsetList::iterator iend = pit->insetlist.end();
619 for ( ; ii != iend; ++ii) {
620 if (ii->pos >= row.pos() && ii->pos < row.endpos()) {
621 maxasc = max(maxasc, ii->inset->ascent());
622 maxdesc = max(maxdesc, ii->inset->descent());
626 // Check if any custom fonts are larger (Asger)
627 // This is not completely correct, but we can live with the small,
628 // cosmetic error for now.
630 pos_type const pos_end = row.endpos();
632 LyXFont::FONT_SIZE maxsize =
633 pit->highestFontInRange(row.pos(), pos_end, size);
634 if (maxsize > font.size()) {
635 font.setSize(maxsize);
636 maxasc = max(maxasc, font_metrics::maxAscent(font));
637 maxdesc = max(maxdesc, font_metrics::maxDescent(font));
640 // This is nicer with box insets:
644 row.ascent_of_text(maxasc);
647 if (row.pos() == 0) {
648 BufferParams const & bufparams = bv()->buffer()->params();
649 // some parksips VERY EASY IMPLEMENTATION
650 if (bv()->buffer()->params().paragraph_separation
651 == BufferParams::PARSEP_SKIP
652 && pit != paragraphs().begin()
653 && ((layout->isParagraph() && pit->getDepth() == 0)
654 || (boost::prior(pit)->layout()->isParagraph()
655 && boost::prior(pit)->getDepth() == 0)))
657 maxasc += bufparams.getDefSkip().inPixels(*bv());
660 if (pit->params().startOfAppendix())
661 maxasc += int(3 * dh);
663 // This is special code for the chapter, since the label of this
664 // layout is printed in an extra row
665 if (layout->counter == "chapter" && bufparams.secnumdepth >= 0) {
666 labeladdon = int(font_metrics::maxHeight(labelfont)
667 * layout->spacing.getValue() * spacing(*pit));
670 // special code for the top label
671 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
672 || layout->labeltype == LABEL_BIBLIO
673 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
674 && isFirstInSequence(pit, paragraphs())
675 && !pit->getLabelstring().empty())
678 font_metrics::maxHeight(labelfont)
679 * layout->spacing.getValue()
681 + (layout->topsep + layout->labelbottomsep) * dh);
684 // Add the layout spaces, for example before and after
685 // a section, or between the items of a itemize or enumerate
688 ParagraphList::iterator prev =
689 depthHook(pit, paragraphs(), pit->getDepth());
691 && prev->layout() == layout
692 && prev->getDepth() == pit->getDepth()
693 && prev->getLabelWidthString() == pit->getLabelWidthString())
695 layoutasc = layout->itemsep * dh;
696 } else if (pit != paragraphs().begin() || row.pos() != 0) {
697 if (layout->topsep > 0)
698 layoutasc = layout->topsep * dh;
701 prev = outerHook(pit, paragraphs());
702 if (prev != paragraphs().end()) {
703 maxasc += int(prev->layout()->parsep * dh);
704 } else if (pit != paragraphs().begin()) {
705 ParagraphList::iterator prior_pit = boost::prior(pit);
706 if (prior_pit->getDepth() != 0 ||
707 prior_pit->layout() == layout) {
708 maxasc += int(layout->parsep * dh);
713 // is it a bottom line?
714 if (row.endpos() >= pit->size()) {
715 // add the layout spaces, for example before and after
716 // a section, or between the items of a itemize or enumerate
718 ParagraphList::iterator nextpit = boost::next(pit);
719 if (nextpit != paragraphs().end()) {
720 ParagraphList::iterator cpit = pit;
724 if (cpit->getDepth() > nextpit->getDepth()) {
725 usual = cpit->layout()->bottomsep * dh;
726 cpit = depthHook(cpit, paragraphs(), nextpit->getDepth());
727 if (cpit->layout() != nextpit->layout()
728 || nextpit->getLabelWidthString() != cpit->getLabelWidthString())
730 unusual = cpit->layout()->bottomsep * dh;
732 layoutdesc = max(unusual, usual);
733 } else if (cpit->getDepth() == nextpit->getDepth()) {
734 if (cpit->layout() != nextpit->layout()
735 || nextpit->getLabelWidthString() != cpit->getLabelWidthString())
736 layoutdesc = int(cpit->layout()->bottomsep * dh);
741 // incalculate the layout spaces
742 maxasc += int(layoutasc * 2 / (2 + pit->getDepth()));
743 maxdesc += int(layoutdesc * 2 / (2 + pit->getDepth()));
745 row.height(maxasc + maxdesc + labeladdon);
746 row.baseline(maxasc + labeladdon);
747 row.top_of_text(row.baseline() - font_metrics::maxAscent(font));
751 void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
753 // allow only if at start or end, or all previous is new text
754 ParagraphList::iterator cpit = cursorPar();
755 if (cursor.pos() && cursor.pos() != cpit->size()
756 && cpit->isChangeEdited(0, cursor.pos()))
759 LyXTextClass const & tclass =
760 bv()->buffer()->params().getLyXTextClass();
761 LyXLayout_ptr const & layout = cpit->layout();
763 // this is only allowed, if the current paragraph is not empty or caption
764 // and if it has not the keepempty flag active
765 if (cpit->empty() && !cpit->allowEmpty()
766 && layout->labeltype != LABEL_SENSITIVE)
769 recUndo(cursor.par());
771 // Always break behind a space
773 // It is better to erase the space (Dekel)
774 if (cursor.pos() < cpit->size() && cpit->isLineSeparator(cursor.pos()))
775 cpit->erase(cursor.pos());
777 // break the paragraph
781 keep_layout = layout->isEnvironment();
783 // we need to set this before we insert the paragraph. IMO the
784 // breakParagraph call should return a bool if it inserts the
785 // paragraph before or behind and we should react on that one
786 // but we can fix this in 1.3.0 (Jug 20020509)
787 bool const isempty = cpit->allowEmpty() && cpit->empty();
788 ::breakParagraph(bv()->buffer()->params(), paragraphs, cpit,
789 cursor.pos(), keep_layout);
792 ParagraphList::iterator next_par = boost::next(cpit);
794 // well this is the caption hack since one caption is really enough
795 if (layout->labeltype == LABEL_SENSITIVE) {
797 // set to standard-layout
798 cpit->applyLayout(tclass.defaultLayout());
800 // set to standard-layout
801 next_par->applyLayout(tclass.defaultLayout());
804 // if the cursor is at the beginning of a row without prior newline,
806 // This touches only the screen-update. Otherwise we would may have
807 // an empty row on the screen
808 RowList::iterator crit = cpit->getRow(cursor.pos());
809 if (cursor.pos() && crit->pos() == cursor.pos()
810 && !cpit->isNewline(cursor.pos() - 1))
815 while (!next_par->empty() && next_par->isNewline(0))
820 redoParagraph(next_par);
822 // This check is necessary. Otherwise the new empty paragraph will
823 // be deleted automatically. And it is more friendly for the user!
824 if (cursor.pos() || isempty)
825 setCursor(next_par, 0);
831 // convenience function
832 void LyXText::redoParagraph()
835 redoParagraph(cursorPar());
836 setCursorIntern(cursor.par(), cursor.pos());
840 // insert a character, moves all the following breaks in the
841 // same Paragraph one to the right and make a rebreak
842 void LyXText::insertChar(char c)
844 recordUndo(Undo::INSERT, this, cursor.par(), cursor.par());
846 // When the free-spacing option is set for the current layout,
847 // disable the double-space checking
849 bool const freeSpacing = cursorPar()->layout()->free_spacing ||
850 cursorPar()->isFreeSpacing();
852 if (lyxrc.auto_number) {
853 static string const number_operators = "+-/*";
854 static string const number_unary_operators = "+-";
855 static string const number_seperators = ".,:";
857 if (current_font.number() == LyXFont::ON) {
858 if (!IsDigit(c) && !contains(number_operators, c) &&
859 !(contains(number_seperators, c) &&
861 cursor.pos() < cursorPar()->size() &&
862 getFont(cursorPar(), cursor.pos()).number() == LyXFont::ON &&
863 getFont(cursorPar(), cursor.pos() - 1).number() == LyXFont::ON)
865 number(); // Set current_font.number to OFF
866 } else if (IsDigit(c) &&
867 real_current_font.isVisibleRightToLeft()) {
868 number(); // Set current_font.number to ON
870 if (cursor.pos() > 0) {
871 char const c = cursorPar()->getChar(cursor.pos() - 1);
872 if (contains(number_unary_operators, c) &&
873 (cursor.pos() == 1 ||
874 cursorPar()->isSeparator(cursor.pos() - 2) ||
875 cursorPar()->isNewline(cursor.pos() - 2))
881 } else if (contains(number_seperators, c) &&
885 cursor.pos() - 2).number() == LyXFont::ON) {
895 // First check, if there will be two blanks together or a blank at
896 // the beginning of a paragraph.
897 // I decided to handle blanks like normal characters, the main
898 // difference are the special checks when calculating the row.fill
899 // (blank does not count at the end of a row) and the check here
901 // The bug is triggered when we type in a description environment:
902 // The current_font is not changed when we go from label to main text
903 // and it should (along with realtmpfont) when we type the space.
904 // CHECK There is a bug here! (Asger)
906 // store the current font. This is because of the use of cursor
907 // movements. The moving cursor would refresh the current font
908 LyXFont realtmpfont = real_current_font;
909 LyXFont rawtmpfont = current_font;
911 if (!freeSpacing && IsLineSeparatorChar(c)) {
912 if ((cursor.pos() > 0
913 && cursorPar()->isLineSeparator(cursor.pos() - 1))
915 && cursorPar()->isNewline(cursor.pos() - 1))
916 || (cursor.pos() == 0)) {
917 static bool sent_space_message = false;
918 if (!sent_space_message) {
919 if (cursor.pos() == 0)
920 bv()->owner()->message(_("You cannot insert a space at the beginning of a paragraph. Please read the Tutorial."));
922 bv()->owner()->message(_("You cannot type two spaces this way. Please read the Tutorial."));
923 sent_space_message = true;
930 // Here case LyXText::InsertInset already inserted the character
931 if (c != Paragraph::META_INSET)
932 cursorPar()->insertChar(cursor.pos(), c);
934 setCharFont(cursorPar(), cursor.pos(), rawtmpfont);
936 current_font = rawtmpfont;
937 real_current_font = realtmpfont;
938 redoParagraph(cursorPar());
939 setCursor(cursor.par(), cursor.pos() + 1, false, cursor.boundary());
945 void LyXText::charInserted()
947 // Here we call finishUndo for every 20 characters inserted.
948 // This is from my experience how emacs does it. (Lgb)
949 static unsigned int counter;
959 void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
961 double w = row.fill();
962 double fill_hfill = 0;
963 double fill_label_hfill = 0;
964 double fill_separator = 0;
968 pit->isRightToLeftPar(bv()->buffer()->params());
970 x = rightMargin(*pit);
972 x = leftMargin(pit, row.pos());
974 // is there a manual margin with a manual label
975 LyXLayout_ptr const & layout = pit->layout();
977 if (layout->margintype == MARGIN_MANUAL
978 && layout->labeltype == LABEL_MANUAL) {
979 /// We might have real hfills in the label part
980 int nlh = numberOfLabelHfills(*pit, row);
982 // A manual label par (e.g. List) has an auto-hfill
983 // between the label text and the body of the
985 // But we don't want to do this auto hfill if the par
990 if (nlh && !pit->getLabelWidthString().empty())
991 fill_label_hfill = labelFill(pit, row) / double(nlh);
994 // are there any hfills in the row?
995 int const nh = numberOfHfills(*pit, row);
1000 // we don't have to look at the alignment if it is ALIGN_LEFT and
1001 // if the row is already larger then the permitted width as then
1002 // we force the LEFT_ALIGN'edness!
1003 } else if (int(row.width()) < textWidth()) {
1004 // is it block, flushleft or flushright?
1005 // set x how you need it
1007 if (pit->params().align() == LYX_ALIGN_LAYOUT)
1008 align = layout->align;
1010 align = pit->params().align();
1012 // Display-style insets should always be on a centred row
1013 // The test on pit->size() is to catch zero-size pars, which
1014 // would trigger the assert in Paragraph::getInset().
1015 //inset = pit->size() ? pit->getInset(row.pos()) : 0;
1017 && pit->isInset(row.pos())
1018 && pit->getInset(row.pos())->display())
1020 align = LYX_ALIGN_CENTER;
1024 case LYX_ALIGN_BLOCK: {
1025 int const ns = numberOfSeparators(*pit, row);
1026 bool disp_inset = false;
1027 if (row.endpos() < pit->size()) {
1028 InsetOld * in = pit->getInset(row.endpos());
1030 disp_inset = in->display();
1032 // If we have separators, this is not the last row of a
1033 // par, does not end in newline, and is not row above a
1034 // display inset... then stretch it
1036 && row.endpos() < pit->size()
1037 && !pit->isNewline(row.endpos() - 1)
1040 fill_separator = w / ns;
1041 } else if (is_rtl) {
1046 case LYX_ALIGN_RIGHT:
1049 case LYX_ALIGN_CENTER:
1055 bidi.computeTables(*pit, *bv()->buffer(), row);
1057 pos_type body_pos = pit->beginOfBody();
1058 pos_type end = row.endpos();
1061 && (body_pos > end || !pit->isLineSeparator(body_pos - 1)))
1063 x += font_metrics::width(layout->labelsep, getLabelFont(pit));
1064 if (body_pos <= end)
1065 x += fill_label_hfill;
1069 row.fill_hfill(fill_hfill);
1070 row.fill_label_hfill(fill_label_hfill);
1071 row.fill_separator(fill_separator);
1076 // the cursor set functions have a special mechanism. When they
1077 // realize, that you left an empty paragraph, they will delete it.
1079 void LyXText::cursorRightOneWord()
1081 cursorRightOneWord(cursor);
1082 setCursor(cursorPar(), cursor.pos());
1086 // Skip initial whitespace at end of word and move cursor to *start*
1087 // of prior word, not to end of next prior word.
1088 void LyXText::cursorLeftOneWord()
1090 LyXCursor tmpcursor = cursor;
1091 cursorLeftOneWord(tmpcursor);
1092 setCursor(getPar(tmpcursor), tmpcursor.pos());
1096 void LyXText::selectWord(word_location loc)
1098 LyXCursor from = cursor;
1099 LyXCursor to = cursor;
1100 getWord(from, to, loc);
1102 setCursor(from.par(), from.pos());
1105 selection.cursor = cursor;
1106 setCursor(to.par(), to.pos());
1111 // Select the word currently under the cursor when no
1112 // selection is currently set
1113 bool LyXText::selectWordWhenUnderCursor(word_location loc)
1115 if (!selection.set()) {
1117 return selection.set();
1123 void LyXText::acceptChange()
1125 if (!selection.set() && cursorPar()->size())
1128 if (selStart().par() == selEnd().par()) {
1129 LyXCursor const & startc = selStart();
1130 LyXCursor const & endc = selEnd();
1131 recordUndo(Undo::INSERT, this, startc.par());
1132 getPar(startc)->acceptChange(startc.pos(), endc.pos());
1135 redoParagraph(getPar(startc));
1136 setCursorIntern(startc.par(), 0);
1138 #warning handle multi par selection
1142 void LyXText::rejectChange()
1144 if (!selection.set() && cursorPar()->size())
1147 if (selStart().par() == selEnd().par()) {
1148 LyXCursor const & startc = selStart();
1149 LyXCursor const & endc = selEnd();
1150 recordUndo(Undo::INSERT, this, startc.par());
1151 getPar(startc)->rejectChange(startc.pos(), endc.pos());
1154 redoParagraph(getPar(startc));
1155 setCursorIntern(startc.par(), 0);
1157 #warning handle multi par selection
1161 // Delete from cursor up to the end of the current or next word.
1162 void LyXText::deleteWordForward()
1164 if (cursorPar()->empty())
1167 LyXCursor tmpcursor = cursor;
1168 selection.set(true); // to avoid deletion
1169 cursorRightOneWord();
1170 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
1171 selection.cursor = cursor;
1174 cutSelection(true, false);
1179 // Delete from cursor to start of current or prior word.
1180 void LyXText::deleteWordBackward()
1182 if (cursorPar()->empty())
1185 LyXCursor tmpcursor = cursor;
1186 selection.set(true); // to avoid deletion
1187 cursorLeftOneWord();
1188 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
1189 selection.cursor = cursor;
1192 cutSelection(true, false);
1197 // Kill to end of line.
1198 void LyXText::deleteLineForward()
1200 if (cursorPar()->empty()) {
1201 // Paragraph is empty, so we just go to the right
1204 LyXCursor tmpcursor = cursor;
1205 selection.set(true); // to avoid deletion
1207 setCursor(tmpcursor, tmpcursor.par(), tmpcursor.pos());
1208 selection.cursor = cursor;
1211 // What is this test for ??? (JMarc)
1212 if (!selection.set())
1213 deleteWordForward();
1215 cutSelection(true, false);
1220 void LyXText::changeCase(LyXText::TextCase action)
1225 if (selection.set()) {
1230 getWord(from, to, lyx::PARTIAL_WORD);
1231 setCursor(to.par(), to.pos() + 1);
1234 recordUndo(Undo::ATOMIC, this, from.par(), to.par());
1236 pos_type pos = from.pos();
1237 int par = from.par();
1239 while (par != int(paragraphs().size()) &&
1240 (pos != to.pos() || par != to.par())) {
1241 ParagraphList::iterator pit = getPar(par);
1242 if (pos == pit->size()) {
1247 unsigned char c = pit->getChar(pos);
1248 if (c != Paragraph::META_INSET) {
1250 case text_lowercase:
1253 case text_capitalization:
1255 action = text_lowercase;
1257 case text_uppercase:
1263 pit->setChar(pos, c);
1269 void LyXText::Delete()
1271 // this is a very easy implementation
1272 LyXCursor old_cursor = cursor;
1274 // just move to the right
1277 // if you had success make a backspace
1278 if (old_cursor.par() != cursor.par() || old_cursor.pos() != cursor.pos()) {
1279 recordUndo(Undo::DELETE, this, old_cursor.par());
1285 void LyXText::backspace()
1287 // Get the font that is used to calculate the baselineskip
1288 ParagraphList::iterator pit = cursorPar();
1289 pos_type lastpos = pit->size();
1291 if (cursor.pos() == 0) {
1292 // The cursor is at the beginning of a paragraph,
1293 // so the the backspace will collapse two paragraphs into one.
1295 // but it's not allowed unless it's new
1296 if (pit->isChangeEdited(0, pit->size()))
1299 // we may paste some paragraphs
1301 // is it an empty paragraph?
1303 if (lastpos == 0 || (lastpos == 1 && pit->isSeparator(0))) {
1304 // This is an empty paragraph and we delete it just
1305 // by moving the cursor one step
1306 // left and let the DeleteEmptyParagraphMechanism
1307 // handle the actual deletion of the paragraph.
1311 // the layout things can change the height of a row !
1317 if (cursor.par() != 0)
1318 recordUndo(Undo::DELETE, this, cursor.par() - 1, cursor.par());
1320 ParagraphList::iterator tmppit = cursorPar();
1321 // We used to do cursorLeftIntern() here, but it is
1322 // not a good idea since it triggers the auto-delete
1323 // mechanism. So we do a cursorLeftIntern()-lite,
1324 // without the dreaded mechanism. (JMarc)
1325 if (cursor.par() != 0) {
1326 // steps into the above paragraph.
1327 setCursorIntern(cursor.par() - 1,
1328 getPar(cursor.par() - 1)->size(),
1332 // Pasting is not allowed, if the paragraphs have different
1333 // layout. I think it is a real bug of all other
1334 // word processors to allow it. It confuses the user.
1335 // Correction: Pasting is always allowed with standard-layout
1336 Buffer & buf = *bv()->buffer();
1337 BufferParams const & bufparams = buf.params();
1338 LyXTextClass const & tclass = bufparams.getLyXTextClass();
1339 ParagraphList::iterator const cpit = cursorPar();
1342 && (cpit->layout() == tmppit->layout()
1343 || tmppit->layout() == tclass.defaultLayout())
1344 && cpit->getAlign() == tmppit->getAlign()) {
1345 mergeParagraph(bufparams, buf.paragraphs(), cpit);
1347 if (cursor.pos() && cpit->isSeparator(cursor.pos() - 1))
1348 cursor.pos(cursor.pos() - 1);
1350 // the counters may have changed
1352 setCursor(cursor.par(), cursor.pos(), false);
1355 // this is the code for a normal backspace, not pasting
1357 recordUndo(Undo::DELETE, this, cursor.par());
1358 // We used to do cursorLeftIntern() here, but it is
1359 // not a good idea since it triggers the auto-delete
1360 // mechanism. So we do a cursorLeftIntern()-lite,
1361 // without the dreaded mechanism. (JMarc)
1362 setCursorIntern(cursor.par(), cursor.pos() - 1,
1363 false, cursor.boundary());
1364 cursorPar()->erase(cursor.pos());
1367 lastpos = cursorPar()->size();
1368 if (cursor.pos() == lastpos)
1372 setCursor(cursor.par(), cursor.pos(), false, cursor.boundary());
1376 ParagraphList::iterator LyXText::cursorPar() const
1378 return getPar(cursor.par());
1382 RowList::iterator LyXText::cursorRow() const
1384 return cursorPar()->getRow(cursor.pos());
1388 ParagraphList::iterator LyXText::getPar(LyXCursor const & cur) const
1390 return getPar(cur.par());
1394 ParagraphList::iterator LyXText::getPar(int par) const
1396 BOOST_ASSERT(par >= 0);
1397 BOOST_ASSERT(par < int(paragraphs().size()));
1398 ParagraphList::iterator pit = paragraphs().begin();
1399 std::advance(pit, par);
1405 LyXText::getRowNearY(int y, ParagraphList::iterator & pit) const
1407 //lyxerr << "getRowNearY: y " << y << endl;
1409 ParagraphList::iterator const
1410 pend = boost::prior(paragraphs().end());
1411 pit = paragraphs().begin();
1412 while (int(pit->y + pit->height) < y && pit != pend)
1415 RowList::iterator rit = pit->rows.end();
1416 RowList::iterator const rbegin = pit->rows.begin();
1419 } while (rit != rbegin && int(pit->y + rit->y_offset()) > y);
1423 pit = boost::prior(paragraphs().end());
1425 RowList::iterator rit = lastRow();
1426 RowList::iterator rbegin = firstRow();
1428 while (rit != rbegin && int(pit->y + rit->y_offset()) > y)
1429 previousRow(pit, rit);
1436 int LyXText::getDepth() const
1438 return cursorPar()->getDepth();
1442 RowList::iterator LyXText::firstRow() const
1444 return paragraphs().front().rows.begin();
1448 ParagraphList::iterator LyXText::firstPar() const
1450 return paragraphs().begin();
1454 RowList::iterator LyXText::lastRow() const
1456 return boost::prior(endRow());
1460 ParagraphList::iterator LyXText::lastPar() const
1462 return boost::prior(endPar());
1466 RowList::iterator LyXText::endRow() const
1468 return paragraphs().back().rows.end();
1472 ParagraphList::iterator LyXText::endPar() const
1474 return paragraphs().end();
1478 void LyXText::nextRow(ParagraphList::iterator & pit,
1479 RowList::iterator & rit) const
1482 if (rit == pit->rows.end()) {
1484 if (pit == paragraphs().end())
1487 rit = pit->rows.begin();
1492 void LyXText::previousRow(ParagraphList::iterator & pit,
1493 RowList::iterator & rit) const
1495 if (rit != pit->rows.begin())
1498 BOOST_ASSERT(pit != paragraphs().begin());
1500 rit = boost::prior(pit->rows.end());
1505 string LyXText::selectionAsString(Buffer const & buffer, bool label) const
1507 if (!selection.set())
1510 // should be const ...
1511 ParagraphList::iterator startpit = getPar(selStart());
1512 ParagraphList::iterator endpit = getPar(selEnd());
1513 size_t const startpos = selStart().pos();
1514 size_t const endpos = selEnd().pos();
1516 if (startpit == endpit)
1517 return startpit->asString(buffer, startpos, endpos, label);
1519 // First paragraph in selection
1521 startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
1523 // The paragraphs in between (if any)
1524 ParagraphList::iterator pit = startpit;
1525 for (++pit; pit != endpit; ++pit)
1526 result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
1528 // Last paragraph in selection
1529 result += endpit->asString(buffer, 0, endpos, label);
1535 int LyXText::parOffset(ParagraphList::iterator pit) const
1537 return std::distance(paragraphs().begin(), pit);
1541 void LyXText::redoParagraphInternal(ParagraphList::iterator pit)
1543 // remove rows of paragraph, keep track of height changes
1544 height -= pit->height;
1552 InsetList::iterator ii = pit->insetlist.begin();
1553 InsetList::iterator iend = pit->insetlist.end();
1554 for (; ii != iend; ++ii) {
1556 int const w = textWidth() - leftMargin(pit) - rightMargin(*pit);
1557 MetricsInfo mi(bv(), getFont(pit, ii->pos), w);
1558 ii->inset->metrics(mi, dim);
1561 // rebreak the paragraph
1562 pit->setBeginOfBody();
1566 rowBreakPoint(pit, row);
1568 fill(pit, row, textwidth_);
1569 prepareToPrint(pit, row);
1570 setHeightOfRow(pit, row);
1571 row.y_offset(pit->height);
1572 pit->rows.push_back(row);
1573 pit->width = std::max(pit->width, row.width());
1574 pit->height += row.height();
1575 } while (z < pit->size());
1577 height += pit->height;
1578 //lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
1582 void LyXText::redoParagraphs(ParagraphList::iterator pit,
1583 ParagraphList::iterator end)
1585 for ( ; pit != end; ++pit)
1586 redoParagraphInternal(pit);
1587 updateParPositions();
1591 void LyXText::redoParagraph(ParagraphList::iterator pit)
1593 redoParagraphInternal(pit);
1594 updateParPositions();
1598 void LyXText::fullRebreak()
1600 redoParagraphs(paragraphs().begin(), paragraphs().end());
1601 selection.cursor = cursor;
1605 void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
1607 //BOOST_ASSERT(mi.base.textwidth);
1608 if (mi.base.textwidth)
1609 textwidth_ = mi.base.textwidth;
1610 //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
1611 // << " textWidth: " << textWidth() << "\nfont: " << mi.base.font << endl;
1613 // Rebuild row cache. This recomputes height as well.
1614 redoParagraphs(paragraphs().begin(), paragraphs().end());
1616 width = maxParagraphWidth(paragraphs());
1619 dim.asc = firstRow()->ascent_of_text();
1620 dim.des = height - dim.asc;
1625 // only used for inset right now. should also be used for main text
1626 void LyXText::draw(PainterInfo & pi, int x, int y) const
1630 paintTextInset(*this, pi, x, y);
1634 bool LyXText::isLastRow(ParagraphList::iterator pit, Row const & row) const
1636 return row.endpos() >= pit->size()
1637 && boost::next(pit) == paragraphs().end();
1641 bool LyXText::isFirstRow(ParagraphList::iterator pit, Row const & row) const
1643 return row.pos() == 0 && pit == paragraphs().begin();
1647 void LyXText::cursorLeftOneWord(LyXCursor & cursor)
1649 // treat HFills, floats and Insets as words
1651 ParagraphList::iterator pit = cursorPar();
1652 size_t pos = cursor.pos();
1655 (pit->isSeparator(pos - 1) ||
1656 pit->isKomma(pos - 1) ||
1657 pit->isNewline(pos - 1)) &&
1658 !(pit->isHfill(pos - 1) ||
1659 pit->isInset(pos - 1)))
1663 (pit->isInset(pos - 1) ||
1664 pit->isHfill(pos - 1))) {
1667 if (pit != paragraphs().begin()) {
1671 } else { // Here, cur != 0
1672 while (pos > 0 && pit->isWord(pos - 1))
1676 cursor.par(parOffset(pit));
1681 void LyXText::cursorRightOneWord(LyXCursor & cursor)
1683 // treat floats, HFills and Insets as words
1684 ParagraphList::iterator pit = cursorPar();
1685 pos_type pos = cursor.pos();
1687 if (pos == pit->size() &&
1688 boost::next(pit) != paragraphs().end()) {
1692 // Skip through initial nonword stuff.
1693 while (pos < pit->size() && !pit->isWord(pos)) {
1696 // Advance through word.
1697 while (pos < pit->size() && pit->isWord(pos)) {
1702 cursor.par(parOffset(pit));
1707 void LyXText::getWord(LyXCursor & from, LyXCursor & to, word_location const loc)
1709 ParagraphList::iterator from_par = getPar(from);
1710 ParagraphList::iterator to_par = getPar(to);
1712 case lyx::WHOLE_WORD_STRICT:
1713 if (from.pos() == 0 || from.pos() == from_par->size()
1714 || from_par->isSeparator(from.pos())
1715 || from_par->isKomma(from.pos())
1716 || from_par->isNewline(from.pos())
1717 || from_par->isSeparator(from.pos() - 1)
1718 || from_par->isKomma(from.pos() - 1)
1719 || from_par->isNewline(from.pos() - 1)) {
1723 // no break here, we go to the next
1725 case lyx::WHOLE_WORD:
1726 // Move cursor to the beginning, when not already there.
1727 if (from.pos() && !from_par->isSeparator(from.pos() - 1)
1728 && !(from_par->isKomma(from.pos() - 1)
1729 || from_par->isNewline(from.pos() - 1)))
1730 cursorLeftOneWord(from);
1732 case lyx::PREVIOUS_WORD:
1733 // always move the cursor to the beginning of previous word
1734 cursorLeftOneWord(from);
1736 case lyx::NEXT_WORD:
1737 lyxerr << "LyXText::getWord: NEXT_WORD not implemented yet"
1740 case lyx::PARTIAL_WORD:
1744 while (to.pos() < to_par->size()
1745 && !to_par->isSeparator(to.pos())
1746 && !to_par->isKomma(to.pos())
1747 && !to_par->isNewline(to.pos())
1748 && !to_par->isHfill(to.pos())
1749 && !to_par->isInset(to.pos()))
1751 to.pos(to.pos() + 1);
1756 void LyXText::write(Buffer const & buf, std::ostream & os) const
1758 ParagraphList::const_iterator pit = paragraphs().begin();
1759 ParagraphList::const_iterator end = paragraphs().end();
1760 Paragraph::depth_type dth = 0;
1761 for (; pit != end; ++pit)
1762 pit->write(buf, os, buf.params(), dth);
1766 bool LyXText::read(Buffer const & buf, LyXLex & lex)
1768 static Change current_change;
1770 bool the_end_read = false;
1771 ParagraphList::iterator pit = paragraphs().begin();
1772 Paragraph::depth_type depth = 0;
1774 while (lex.isOK()) {
1776 string token = lex.getString();
1783 if (token == "\\end_inset") {
1784 the_end_read = true;
1788 if (token == "\\end_document") {
1789 lex.printError("\\end_document read in inset! Error in document!");
1795 if (token == "\\end_document") {
1796 the_end_read = true;
1805 if (token == "\\begin_layout") {
1806 lex.pushToken(token);
1809 par.params().depth(depth);
1810 if (buf.params().tracking_changes)
1812 LyXFont f(LyXFont::ALL_INHERIT, buf.params().language);
1816 if (pit != paragraphs().end())
1819 pit = paragraphs().insert(pit, par);
1821 // FIXME: goddamn InsetTabular makes us pass a Buffer
1823 ::readParagraph(buf, *pit, lex);
1825 } else if (token == "\\begin_deeper") {
1827 } else if (token == "\\end_deeper") {
1829 lex.printError("\\end_deeper: " "depth is already null");
1838 return the_end_read;
1842 int LyXText::ascent() const
1844 return firstRow()->ascent_of_text();
1848 int LyXText::descent() const
1850 return height - firstRow()->ascent_of_text();
1854 int LyXText::cursorX() const
1856 return cursorX(cursor);
1860 int LyXText::cursorY() const
1862 return cursorY(cursor);
1866 int LyXText::cursorX(LyXCursor const & cur) const
1868 ParagraphList::iterator pit = getPar(cur);
1869 if (pit->rows.empty())
1871 Row const & row = *pit->getRow(cur.pos());
1872 pos_type pos = cur.pos();
1873 pos_type cursor_vpos = 0;
1875 double fill_separator = row.fill_separator();
1876 double fill_hfill = row.fill_hfill();
1877 double fill_label_hfill = row.fill_label_hfill();
1878 pos_type const row_pos = row.pos();
1879 pos_type const end = row.endpos();
1882 cursor_vpos = row_pos;
1883 else if (pos >= end)
1884 cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
1886 else if (pos > row_pos && pos >= end)
1887 // Place cursor after char at (logical) position pos - 1
1888 cursor_vpos = (bidi.level(pos - 1) % 2 == 0)
1889 ? bidi.log2vis(pos - 1) + 1 : bidi.log2vis(pos - 1);
1891 // Place cursor before char at (logical) position pos
1892 cursor_vpos = (bidi.level(pos) % 2 == 0)
1893 ? bidi.log2vis(pos) : bidi.log2vis(pos) + 1;
1895 pos_type body_pos = pit->beginOfBody();
1897 (body_pos > end || !pit->isLineSeparator(body_pos - 1)))
1900 for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
1901 pos_type pos = bidi.vis2log(vpos);
1902 if (body_pos > 0 && pos == body_pos - 1) {
1903 x += fill_label_hfill
1904 + font_metrics::width(pit->layout()->labelsep,
1906 if (pit->isLineSeparator(body_pos - 1))
1907 x -= singleWidth(pit, body_pos - 1);
1910 if (hfillExpansion(*pit, row, pos)) {
1911 x += singleWidth(pit, pos);
1912 if (pos >= body_pos)
1915 x += fill_label_hfill;
1916 } else if (pit->isSeparator(pos)) {
1917 x += singleWidth(pit, pos);
1918 if (pos >= body_pos)
1919 x += fill_separator;
1921 x += singleWidth(pit, pos);
1927 int LyXText::cursorY(LyXCursor const & cur) const
1929 Paragraph & par = *getPar(cur);
1930 Row & row = *par.getRow(cur.pos());
1931 return par.y + row.y_offset() + row.baseline();