2 * \file src/TextMetrics.cpp
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
13 * \author Abdelrazak Younes
15 * Full author contact details are available in file CREDITS.
20 #include "TextMetrics.h"
23 #include "BufferParams.h"
24 #include "BufferView.h"
25 #include "paragraph_funcs.h"
26 #include "ParIterator.h"
27 #include "CoordCache.h"
29 #include "FuncRequest.h"
30 #include "FontIterator.h"
35 #include "MetricsInfo.h"
36 #include "ParagraphParameters.h"
39 #include "frontends/FontMetrics.h"
40 #include "frontends/Painter.h"
48 using frontend::FontMetrics;
52 int numberOfSeparators(Paragraph const & par, Row const & row)
54 pos_type const first = max(row.pos(), par.beginOfBody());
55 pos_type const last = row.endpos() - 1;
57 for (pos_type p = first; p < last; ++p) {
58 if (par.isSeparator(p))
65 int numberOfLabelHfills(Paragraph const & par, Row const & row)
67 pos_type last = row.endpos() - 1;
68 pos_type first = row.pos();
70 // hfill *DO* count at the beginning of paragraphs!
72 while (first < last && par.isHfill(first))
76 last = min(last, par.beginOfBody());
78 for (pos_type p = first; p < last; ++p) {
86 int numberOfHfills(Paragraph const & par, Row const & row)
88 pos_type const last = row.endpos();
89 pos_type first = row.pos();
91 // hfill *DO* count at the beginning of paragraphs!
93 while (first < last && par.isHfill(first))
97 first = max(first, par.beginOfBody());
100 for (pos_type p = first; p < last; ++p) {
109 TextMetrics::TextMetrics(BufferView * bv, Text * text)
110 : bv_(bv), text_(text)
113 max_width_ = bv_->workWidth();
114 dim_.wid = max_width_;
118 //text_->updateLabels(bv->buffer());
122 ParagraphMetrics const & TextMetrics::parMetrics(pit_type pit) const
124 return const_cast<TextMetrics *>(this)->parMetrics(pit, true);
128 ParagraphMetrics & TextMetrics::parMetrics(pit_type pit,
131 ParMetricsCache::iterator pmc_it = par_metrics_.find(pit);
132 if (pmc_it == par_metrics_.end()) {
133 pmc_it = par_metrics_.insert(
134 std::make_pair(pit, ParagraphMetrics(text_->getPar(pit)))).first;
136 if (pmc_it->second.rows().empty() && redo) {
139 return pmc_it->second;
143 bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim)
145 BOOST_ASSERT(mi.base.textwidth);
146 max_width_ = mi.base.textwidth;
148 //lyxerr << "Text::metrics: width: " << mi.base.textwidth
149 // << " maxWidth: " << max_width_ << "\nfont: " << mi.base.font << endl;
151 bool changed = false;
155 for (pit_type pit = 0, n = text_->paragraphs().size(); pit != n; ++pit) {
156 changed |= redoParagraph(pit);
157 ParagraphMetrics const & pm = par_metrics_[pit];
164 dim.asc = par_metrics_[0].ascent();
165 dim.des = h - dim.asc;
167 changed |= dim_ != dim;
173 int TextMetrics::rightMargin(ParagraphMetrics const & pm) const
175 return main_text_? pm.rightMargin(bv_->buffer()) : 0;
179 int TextMetrics::rightMargin(pit_type const pit) const
181 return main_text_? par_metrics_[pit].rightMargin(bv_->buffer()) : 0;
185 bool TextMetrics::redoParagraph(pit_type const pit)
187 Paragraph & par = text_->getPar(pit);
188 // IMPORTANT NOTE: We pass 'false' explicitely in order to not call
189 // redoParagraph() recursively inside parMetrics.
190 Dimension old_dim = parMetrics(pit, false).dim();
191 ParagraphMetrics & pm = par_metrics_[pit];
194 Buffer & buffer = bv_->buffer();
195 main_text_ = (text_ == &buffer.text());
196 bool changed = false;
198 // FIXME This check ought to be done somewhere else. It is the reason
199 // why text_ is not const. But then, where else to do it?
200 // Well, how can you end up with either (a) a biblio environment that
201 // has no InsetBibitem or (b) a biblio environment with more than one
202 // InsetBibitem? I think the answer is: when paragraphs are merged;
203 // when layout is set; when material is pasted.
204 int const moveCursor = par.checkBiblio(buffer.params().trackChanges);
206 const_cast<Cursor &>(bv_->cursor()).posRight();
207 else if (moveCursor < 0) {
208 Cursor & cursor = const_cast<Cursor &>(bv_->cursor());
209 if (cursor.pos() >= -moveCursor)
213 // Optimisation: this is used in the next two loops
214 // so better to calculate that once here.
215 int const right_margin = rightMargin(pm);
218 // FIXME: We should always use getFont(), see documentation of
219 // noFontChange() in Inset.h.
220 Font const bufferfont = buffer.params().getFont();
221 InsetList::const_iterator ii = par.insetlist.begin();
222 InsetList::const_iterator iend = par.insetlist.end();
223 for (; ii != iend; ++ii) {
224 Dimension old_dim = ii->inset->dimension();
226 int const w = max_width_ - text_->leftMargin(buffer, max_width_, pit, ii->pos)
228 Font const & font = ii->inset->noFontChange() ?
229 bufferfont : text_->getFont(buffer, par, ii->pos);
230 MetricsInfo mi(bv_, font, w);
231 ii->inset->metrics(mi, dim);
232 changed |= (old_dim != dim);
235 par.setBeginOfBody();
237 // maximum pixel width of a row
238 int width = max_width_ - right_margin; // - leftMargin(buffer, max_width_, pit, row);
241 rowBreakPoint(width, pit, row);
242 setRowWidth(right_margin, pit, row);
243 setHeightOfRow(pit, row);
244 pm.rows().push_back(row);
245 pm.dim().wid = std::max(pm.dim().wid, row.width());
246 pm.dim().des += row.height();
248 } while (z < par.size());
250 // Make sure that if a par ends in newline, there is one more row
252 if (z > 0 && par.isNewline(z - 1)) {
255 setRowWidth(right_margin, pit, row);
256 setHeightOfRow(pit, row);
257 pm.rows().push_back(row);
258 pm.dim().des += row.height();
261 pm.dim().asc += pm.rows()[0].ascent();
262 pm.dim().des -= pm.rows()[0].ascent();
264 changed |= old_dim.height() != pm.dim().height();
266 // Update the row change statuses. The painter will need that info
267 // in order to know which row has to be repainted.
268 pm.updateRowChangeStatus();
273 RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
274 Row const & row) const
277 Buffer & buffer = bv_->buffer();
278 Paragraph const & par = text_->getPar(pit);
280 double w = dim_.wid - row.width();
282 bool const is_rtl = text_->isRTL(buffer, par);
284 result.x = rightMargin(pit);
286 result.x = text_->leftMargin(buffer, max_width_, pit, row.pos());
288 // is there a manual margin with a manual label
289 LayoutPtr const & layout = par.layout();
291 if (layout->margintype == MARGIN_MANUAL
292 && layout->labeltype == LABEL_MANUAL) {
293 /// We might have real hfills in the label part
294 int nlh = numberOfLabelHfills(par, row);
296 // A manual label par (e.g. List) has an auto-hfill
297 // between the label text and the body of the
299 // But we don't want to do this auto hfill if the par
304 if (nlh && !par.getLabelWidthString().empty())
305 result.label_hfill = labelFill(pit, row) / double(nlh);
308 // are there any hfills in the row?
309 int const nh = numberOfHfills(par, row);
313 result.hfill = w / nh;
314 // we don't have to look at the alignment if it is ALIGN_LEFT and
315 // if the row is already larger then the permitted width as then
316 // we force the LEFT_ALIGN'edness!
317 } else if (int(row.width()) < max_width_) {
318 // is it block, flushleft or flushright?
319 // set x how you need it
321 if (par.params().align() == LYX_ALIGN_LAYOUT)
322 align = layout->align;
324 align = par.params().align();
326 // Display-style insets should always be on a centred row
327 // The test on par.size() is to catch zero-size pars, which
328 // would trigger the assert in Paragraph::getInset().
329 //inset = par.size() ? par.getInset(row.pos()) : 0;
330 if (row.pos() < par.size()
331 && par.isInset(row.pos()))
333 switch(par.getInset(row.pos())->display()) {
334 case Inset::AlignLeft:
335 align = LYX_ALIGN_BLOCK;
337 case Inset::AlignCenter:
338 align = LYX_ALIGN_CENTER;
341 case Inset::AlignRight:
342 // unchanged (use align)
348 case LYX_ALIGN_BLOCK: {
349 int const ns = numberOfSeparators(par, row);
350 bool disp_inset = false;
351 if (row.endpos() < par.size()) {
352 Inset const * in = par.getInset(row.endpos());
354 disp_inset = in->display();
356 // If we have separators, this is not the last row of a
357 // par, does not end in newline, and is not row above a
358 // display inset... then stretch it
360 && row.endpos() < par.size()
361 && !par.isNewline(row.endpos() - 1)
364 result.separator = w / ns;
370 case LYX_ALIGN_RIGHT:
373 case LYX_ALIGN_CENTER:
380 pos_type body_pos = par.beginOfBody();
381 pos_type end = row.endpos();
384 && (body_pos > end || !par.isLineSeparator(body_pos - 1)))
386 result.x += theFontMetrics(text_->getLabelFont(buffer, par)).
387 width(layout->labelsep);
389 result.x += result.label_hfill;
397 int TextMetrics::labelFill(pit_type const pit, Row const & row) const
399 Buffer & buffer = bv_->buffer();
400 Paragraph const & par = text_->getPar(pit);
402 pos_type last = par.beginOfBody();
403 BOOST_ASSERT(last > 0);
405 // -1 because a label ends with a space that is in the label
408 // a separator at this end does not count
409 if (par.isLineSeparator(last))
413 for (pos_type i = row.pos(); i <= last; ++i)
414 w += singleWidth(pit, i);
416 docstring const & label = par.params().labelWidthString();
420 FontMetrics const & fm
421 = theFontMetrics(text_->getLabelFont(buffer, par));
423 return max(0, fm.width(label) - w);
429 // this needs special handling - only newlines count as a break point
430 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
432 pos_type const end = par.size();
435 if (par.isNewline(i))
444 int TextMetrics::labelEnd(pit_type const pit) const
446 // labelEnd is only needed if the layout fills a flushleft label.
447 if (text_->getPar(pit).layout()->margintype != MARGIN_MANUAL)
449 // return the beginning of the body
450 return text_->leftMargin(bv_->buffer(), max_width_, pit);
454 void TextMetrics::rowBreakPoint(int width, pit_type const pit,
457 Buffer & buffer = bv_->buffer();
458 ParagraphMetrics const & pm = par_metrics_[pit];
459 Paragraph const & par = text_->getPar(pit);
460 pos_type const end = par.size();
461 pos_type const pos = row.pos();
472 LayoutPtr const & layout = par.layout();
474 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
475 row.endpos(addressBreakPoint(pos, par));
479 pos_type const body_pos = par.beginOfBody();
482 // Now we iterate through until we reach the right margin
483 // or the end of the par, then choose the possible break
486 int label_end = labelEnd(pit);
487 int const left = text_->leftMargin(buffer, max_width_, pit, pos);
490 // pixel width since last breakpoint
493 FontIterator fi = FontIterator(buffer, *text_, par, pos);
494 pos_type point = end;
496 for ( ; i < end; ++i, ++fi) {
497 int thiswidth = pm.singleWidth(i, *fi);
499 // add the auto-hfill from label end to the body
500 if (body_pos && i == body_pos) {
501 FontMetrics const & fm = theFontMetrics(
502 text_->getLabelFont(buffer, par));
503 int add = fm.width(layout->labelsep);
504 if (par.isLineSeparator(i - 1))
505 add -= singleWidth(pit, i - 1);
507 add = std::max(add, label_end - x);
512 chunkwidth += thiswidth;
514 // break before a character that will fall off
515 // the right of the row
517 // if no break before, break here
518 if (point == end || chunkwidth >= width - left) {
525 // exit on last registered breakpoint:
529 if (par.isNewline(i)) {
535 if (par.isInset(i + 1) && par.getInset(i + 1)->display()) {
540 if (par.isInset(i) && par.getInset(i)->display()) {
546 if (!par.isInset(i) || par.getInset(i)->isChar()) {
547 // some insets are line separators too
548 if (par.isLineSeparator(i)) {
549 // register breakpoint:
556 // maybe found one, but the par is short enough.
557 if (i == end && x < width)
560 // manual labels cannot be broken in LaTeX. But we
561 // want to make our on-screen rendering of footnotes
563 if (body_pos && point < body_pos)
570 void TextMetrics::setRowWidth(int right_margin,
571 pit_type const pit, Row & row) const
573 Buffer & buffer = bv_->buffer();
574 // get the pure distance
575 pos_type const end = row.endpos();
576 ParagraphMetrics const & pm = par_metrics_[pit];
577 Paragraph const & par = text_->getPar(pit);
578 int w = text_->leftMargin(buffer, max_width_, pit, row.pos());
579 int label_end = labelEnd(pit);
581 pos_type const body_pos = par.beginOfBody();
582 pos_type i = row.pos();
585 FontIterator fi = FontIterator(buffer, *text_, par, i);
586 for ( ; i < end; ++i, ++fi) {
587 if (body_pos > 0 && i == body_pos) {
588 FontMetrics const & fm = theFontMetrics(
589 text_->getLabelFont(buffer, par));
590 w += fm.width(par.layout()->labelsep);
591 if (par.isLineSeparator(i - 1))
592 w -= singleWidth(pit, i - 1);
593 w = max(w, label_end);
595 w += pm.singleWidth(i, *fi);
599 if (body_pos > 0 && body_pos >= end) {
600 FontMetrics const & fm = theFontMetrics(
601 text_->getLabelFont(buffer, par));
602 w += fm.width(par.layout()->labelsep);
603 if (end > 0 && par.isLineSeparator(end - 1))
604 w -= singleWidth(pit, end - 1);
605 w = max(w, label_end);
608 row.width(w + right_margin);
612 void TextMetrics::setHeightOfRow(pit_type const pit,
615 Paragraph const & par = text_->getPar(pit);
616 // get the maximum ascent and the maximum descent
617 double layoutasc = 0;
618 double layoutdesc = 0;
619 double const dh = defaultRowHeight();
621 // ok, let us initialize the maxasc and maxdesc value.
622 // Only the fontsize count. The other properties
623 // are taken from the layoutfont. Nicer on the screen :)
624 LayoutPtr const & layout = par.layout();
626 // as max get the first character of this row then it can
627 // increase but not decrease the height. Just some point to
628 // start with so we don't have to do the assignment below too
630 Buffer const & buffer = bv_->buffer();
631 Font font = text_->getFont(buffer, par, row.pos());
632 Font::FONT_SIZE const tmpsize = font.size();
633 font = text_->getLayoutFont(buffer, pit);
634 Font::FONT_SIZE const size = font.size();
635 font.setSize(tmpsize);
637 Font labelfont = text_->getLabelFont(buffer, par);
639 FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
640 FontMetrics const & fontmetrics = theFontMetrics(font);
642 // these are minimum values
643 double const spacing_val = layout->spacing.getValue()
644 * text_->spacing(buffer, par);
645 //lyxerr << "spacing_val = " << spacing_val << endl;
646 int maxasc = int(fontmetrics.maxAscent() * spacing_val);
647 int maxdesc = int(fontmetrics.maxDescent() * spacing_val);
649 // insets may be taller
650 InsetList::const_iterator ii = par.insetlist.begin();
651 InsetList::const_iterator iend = par.insetlist.end();
652 for ( ; ii != iend; ++ii) {
653 if (ii->pos >= row.pos() && ii->pos < row.endpos()) {
654 maxasc = max(maxasc, ii->inset->ascent());
655 maxdesc = max(maxdesc, ii->inset->descent());
659 // Check if any custom fonts are larger (Asger)
660 // This is not completely correct, but we can live with the small,
661 // cosmetic error for now.
663 pos_type const pos_end = row.endpos();
665 Font::FONT_SIZE maxsize =
666 par.highestFontInRange(row.pos(), pos_end, size);
667 if (maxsize > font.size()) {
668 // use standard paragraph font with the maximal size
670 maxfont.setSize(maxsize);
671 FontMetrics const & maxfontmetrics = theFontMetrics(maxfont);
672 maxasc = max(maxasc, maxfontmetrics.maxAscent());
673 maxdesc = max(maxdesc, maxfontmetrics.maxDescent());
676 // This is nicer with box insets:
681 ParagraphList const & pars = text_->paragraphs();
684 if (row.pos() == 0) {
685 BufferParams const & bufparams = buffer.params();
686 // some parskips VERY EASY IMPLEMENTATION
687 if (bufparams.paragraph_separation
688 == BufferParams::PARSEP_SKIP
689 && par.ownerCode() != Inset::ERT_CODE
690 && par.ownerCode() != Inset::LISTINGS_CODE
692 && ((layout->isParagraph() && par.getDepth() == 0)
693 || (pars[pit - 1].layout()->isParagraph()
694 && pars[pit - 1].getDepth() == 0)))
696 maxasc += bufparams.getDefSkip().inPixels(*bv_);
699 if (par.params().startOfAppendix())
700 maxasc += int(3 * dh);
702 // This is special code for the chapter, since the label of this
703 // layout is printed in an extra row
704 if (layout->counter == "chapter"
705 && !par.params().labelString().empty()) {
706 labeladdon = int(labelfont_metrics.maxHeight()
707 * layout->spacing.getValue()
708 * text_->spacing(buffer, par));
711 // special code for the top label
712 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
713 || layout->labeltype == LABEL_BIBLIO
714 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
715 && isFirstInSequence(pit, pars)
716 && !par.getLabelstring().empty())
719 labelfont_metrics.maxHeight()
720 * layout->spacing.getValue()
721 * text_->spacing(buffer, par)
722 + (layout->topsep + layout->labelbottomsep) * dh);
725 // Add the layout spaces, for example before and after
726 // a section, or between the items of a itemize or enumerate
729 pit_type prev = depthHook(pit, pars, par.getDepth());
730 Paragraph const & prevpar = pars[prev];
732 && prevpar.layout() == layout
733 && prevpar.getDepth() == par.getDepth()
734 && prevpar.getLabelWidthString()
735 == par.getLabelWidthString()) {
736 layoutasc = layout->itemsep * dh;
737 } else if (pit != 0 || row.pos() != 0) {
738 if (layout->topsep > 0)
739 layoutasc = layout->topsep * dh;
742 prev = outerHook(pit, pars);
743 if (prev != pit_type(pars.size())) {
744 maxasc += int(pars[prev].layout()->parsep * dh);
745 } else if (pit != 0) {
746 Paragraph const & prevpar = pars[pit - 1];
747 if (prevpar.getDepth() != 0 ||
748 prevpar.layout() == layout) {
749 maxasc += int(layout->parsep * dh);
754 // is it a bottom line?
755 if (row.endpos() >= par.size()) {
756 // add the layout spaces, for example before and after
757 // a section, or between the items of a itemize or enumerate
759 pit_type nextpit = pit + 1;
760 if (nextpit != pit_type(pars.size())) {
765 if (pars[cpit].getDepth() > pars[nextpit].getDepth()) {
766 usual = pars[cpit].layout()->bottomsep * dh;
767 cpit = depthHook(cpit, pars, pars[nextpit].getDepth());
768 if (pars[cpit].layout() != pars[nextpit].layout()
769 || pars[nextpit].getLabelWidthString() != pars[cpit].getLabelWidthString())
771 unusual = pars[cpit].layout()->bottomsep * dh;
773 layoutdesc = max(unusual, usual);
774 } else if (pars[cpit].getDepth() == pars[nextpit].getDepth()) {
775 if (pars[cpit].layout() != pars[nextpit].layout()
776 || pars[nextpit].getLabelWidthString() != pars[cpit].getLabelWidthString())
777 layoutdesc = int(pars[cpit].layout()->bottomsep * dh);
782 // incalculate the layout spaces
783 maxasc += int(layoutasc * 2 / (2 + pars[pit].getDepth()));
784 maxdesc += int(layoutdesc * 2 / (2 + pars[pit].getDepth()));
786 // FIXME: the correct way is to do the following is to move the
787 // following code in another method specially tailored for the
788 // main Text. The following test is thus bogus.
789 // Top and bottom margin of the document (only at top-level)
791 if (pit == 0 && row.pos() == 0)
793 if (pit + 1 == pit_type(pars.size()) &&
794 row.endpos() == par.size() &&
795 !(row.endpos() > 0 && par.isNewline(row.endpos() - 1)))
799 row.ascent(maxasc + labeladdon);
800 row.descent(maxdesc);
804 // x is an absolute screen coord
805 // returns the column near the specified x-coordinate of the row
806 // x is set to the real beginning of this column
807 pos_type TextMetrics::getColumnNearX(pit_type const pit,
808 Row const & row, int & x, bool & boundary) const
810 Buffer const & buffer = bv_->buffer();
812 /// For the main Text, it is possible that this pit is not
813 /// yet in the CoordCache when moving cursor up.
814 /// x Paragraph coordinate is always 0 for main text anyway.
815 int const xo = main_text_? 0 : bv_->coordCache().get(text_, pit).x_;
817 RowMetrics const r = computeRowMetrics(pit, row);
818 Paragraph const & par = text_->getPar(pit);
820 bidi.computeTables(par, buffer, row);
822 pos_type vc = row.pos();
823 pos_type end = row.endpos();
825 LayoutPtr const & layout = par.layout();
827 bool left_side = false;
829 pos_type body_pos = par.beginOfBody();
832 double last_tmpx = tmpx;
835 (body_pos > end || !par.isLineSeparator(body_pos - 1)))
838 // check for empty row
844 while (vc < end && tmpx <= x) {
845 c = bidi.vis2log(vc);
847 if (body_pos > 0 && c == body_pos - 1) {
848 FontMetrics const & fm = theFontMetrics(
849 text_->getLabelFont(buffer, par));
850 tmpx += r.label_hfill + fm.width(layout->labelsep);
851 if (par.isLineSeparator(body_pos - 1))
852 tmpx -= singleWidth(pit, body_pos - 1);
855 if (par.hfillExpansion(row, c)) {
856 tmpx += singleWidth(pit, c);
860 tmpx += r.label_hfill;
861 } else if (par.isSeparator(c)) {
862 tmpx += singleWidth(pit, c);
866 tmpx += singleWidth(pit, c);
871 if ((tmpx + last_tmpx) / 2 > x) {
876 BOOST_ASSERT(vc <= end); // This shouldn't happen.
879 // This (rtl_support test) is not needed, but gives
880 // some speedup if rtl_support == false
881 bool const lastrow = lyxrc.rtl_support && row.endpos() == par.size();
883 // If lastrow is false, we don't need to compute
885 bool const rtl = lastrow ? text_->isRTL(buffer, par) : false;
887 ((rtl && left_side && vc == row.pos() && x < tmpx - 5) ||
888 (!rtl && !left_side && vc == end && x > tmpx + 5)))
890 else if (vc == row.pos()) {
891 c = bidi.vis2log(vc);
892 if (bidi.level(c) % 2 == 1)
895 c = bidi.vis2log(vc - 1);
896 bool const rtl = (bidi.level(c) % 2 == 1);
897 if (left_side == rtl) {
899 boundary = text_->isRTLBoundary(buffer, par, c);
903 // I believe this code is not needed anymore (Jug 20050717)
905 // The following code is necessary because the cursor position past
906 // the last char in a row is logically equivalent to that before
907 // the first char in the next row. That's why insets causing row
908 // divisions -- Newline and display-style insets -- must be treated
909 // specially, so cursor up/down doesn't get stuck in an air gap -- MV
910 // Newline inset, air gap below:
911 if (row.pos() < end && c >= end && par.isNewline(end - 1)) {
912 if (bidi.level(end -1) % 2 == 0)
913 tmpx -= singleWidth(pit, end - 1);
915 tmpx += singleWidth(pit, end - 1);
919 // Air gap above display inset:
920 if (row.pos() < end && c >= end && end < par.size()
921 && par.isInset(end) && par.getInset(end)->display()) {
924 // Air gap below display inset:
925 if (row.pos() < end && c >= end && par.isInset(end - 1)
926 && par.getInset(end - 1)->display()) {
932 pos_type const col = c - row.pos();
934 if (!c || end == par.size())
937 if (c==end && !par.isLineSeparator(c-1) && !par.isNewline(c-1)) {
942 return min(col, end - 1 - row.pos());
946 pos_type TextMetrics::x2pos(pit_type pit, int row, int x) const
948 ParagraphMetrics const & pm = par_metrics_[pit];
949 BOOST_ASSERT(!pm.rows().empty());
950 BOOST_ASSERT(row < int(pm.rows().size()));
952 Row const & r = pm.rows()[row];
953 return r.pos() + getColumnNearX(pit, r, x, bound);
957 int TextMetrics::singleWidth(pit_type pit, pos_type pos) const
959 Buffer const & buffer = bv_->buffer();
960 ParagraphMetrics const & pm = par_metrics_[pit];
962 return pm.singleWidth(pos, text_->getFont(buffer, text_->getPar(pit), pos));
966 //int Text::pos2x(pit_type pit, pos_type pos) const
968 // ParagraphMetrics const & pm = par_metrics_[pit];
969 // Row const & r = pm.rows()[row];
975 int defaultRowHeight()
977 return int(theFontMetrics(Font(Font::ALL_SANE)).maxHeight() * 1.2);