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 = parMetrics(pit);
164 dim.asc = parMetrics(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 ParagraphMetrics pm(par);
189 Buffer & buffer = *bv_->buffer();
190 main_text_ = (text_ == &buffer.text());
191 bool changed = false;
193 // FIXME This check ought to be done somewhere else. It is the reason
194 // why text_ is not const. But then, where else to do it?
195 // Well, how can you end up with either (a) a biblio environment that
196 // has no InsetBibitem or (b) a biblio environment with more than one
197 // InsetBibitem? I think the answer is: when paragraphs are merged;
198 // when layout is set; when material is pasted.
199 int const moveCursor = par.checkBiblio(buffer.params().trackChanges);
201 const_cast<Cursor &>(bv_->cursor()).posRight();
202 else if (moveCursor < 0) {
203 Cursor & cursor = const_cast<Cursor &>(bv_->cursor());
204 if (cursor.pos() >= -moveCursor)
208 // Optimisation: this is used in the next two loops
209 // so better to calculate that once here.
210 int const right_margin = rightMargin(pm);
213 // FIXME: We should always use getFont(), see documentation of
214 // noFontChange() in Inset.h.
215 Font const bufferfont = buffer.params().getFont();
216 InsetList::const_iterator ii = par.insetlist.begin();
217 InsetList::const_iterator iend = par.insetlist.end();
218 for (; ii != iend; ++ii) {
220 int const w = max_width_ - text_->leftMargin(buffer, max_width_, pit, ii->pos)
222 Font const & font = ii->inset->noFontChange() ?
223 bufferfont : text_->getFont(buffer, par, ii->pos);
224 MetricsInfo mi(bv_, font, w);
225 changed |= ii->inset->metrics(mi, dim);
228 // rebreak the paragraph
231 par.setBeginOfBody();
233 // maximum pixel width of a row
234 int width = max_width_ - right_margin; // - leftMargin(buffer, max_width_, pit, row);
237 rowBreakPoint(width, pit, row);
238 setRowWidth(right_margin, pit, row);
239 setHeightOfRow(pit, row);
240 pm.rows().push_back(row);
241 pm.dim().wid = std::max(pm.dim().wid, row.width());
242 pm.dim().des += row.height();
244 } while (z < par.size());
246 // Make sure that if a par ends in newline, there is one more row
248 if (z > 0 && par.isNewline(z - 1)) {
251 setRowWidth(right_margin, pit, row);
252 setHeightOfRow(pit, row);
253 pm.rows().push_back(row);
254 pm.dim().des += row.height();
257 pm.dim().asc += pm.rows()[0].ascent();
258 pm.dim().des -= pm.rows()[0].ascent();
260 // IMPORTANT NOTE: We pass 'false' explicitely in order to not call
261 // redoParagraph() recursively inside parMetrics.
262 Dimension old_dim = parMetrics(pit, false).dim();
264 changed |= old_dim.height() != pm.dim().height();
266 par_metrics_[pit] = pm;
268 // Update the row change statuses. The painter will need that info
269 // in order to know which row has to be repainted.
270 par_metrics_[pit].updateRowChangeStatus();
275 RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
276 Row const & row) const
279 Buffer & buffer = *bv_->buffer();
280 Paragraph const & par = text_->getPar(pit);
282 double w = dim_.wid - row.width();
284 bool const is_rtl = text_->isRTL(buffer, par);
286 result.x = rightMargin(pit);
288 result.x = text_->leftMargin(buffer, max_width_, pit, row.pos());
290 // is there a manual margin with a manual label
291 Layout_ptr const & layout = par.layout();
293 if (layout->margintype == MARGIN_MANUAL
294 && layout->labeltype == LABEL_MANUAL) {
295 /// We might have real hfills in the label part
296 int nlh = numberOfLabelHfills(par, row);
298 // A manual label par (e.g. List) has an auto-hfill
299 // between the label text and the body of the
301 // But we don't want to do this auto hfill if the par
306 if (nlh && !par.getLabelWidthString().empty())
307 result.label_hfill = labelFill(par, row) / double(nlh);
310 // are there any hfills in the row?
311 int const nh = numberOfHfills(par, row);
315 result.hfill = w / nh;
316 // we don't have to look at the alignment if it is ALIGN_LEFT and
317 // if the row is already larger then the permitted width as then
318 // we force the LEFT_ALIGN'edness!
319 } else if (int(row.width()) < max_width_) {
320 // is it block, flushleft or flushright?
321 // set x how you need it
323 if (par.params().align() == LYX_ALIGN_LAYOUT)
324 align = layout->align;
326 align = par.params().align();
328 // Display-style insets should always be on a centred row
329 // The test on par.size() is to catch zero-size pars, which
330 // would trigger the assert in Paragraph::getInset().
331 //inset = par.size() ? par.getInset(row.pos()) : 0;
332 if (row.pos() < par.size()
333 && par.isInset(row.pos()))
335 switch(par.getInset(row.pos())->display()) {
336 case Inset::AlignLeft:
337 align = LYX_ALIGN_BLOCK;
339 case Inset::AlignCenter:
340 align = LYX_ALIGN_CENTER;
342 // other types unchanged (use align)
347 case LYX_ALIGN_BLOCK: {
348 int const ns = numberOfSeparators(par, row);
349 bool disp_inset = false;
350 if (row.endpos() < par.size()) {
351 Inset const * in = par.getInset(row.endpos());
353 disp_inset = in->display();
355 // If we have separators, this is not the last row of a
356 // par, does not end in newline, and is not row above a
357 // display inset... then stretch it
359 && row.endpos() < par.size()
360 && !par.isNewline(row.endpos() - 1)
363 result.separator = w / ns;
369 case LYX_ALIGN_RIGHT:
372 case LYX_ALIGN_CENTER:
378 text_->bidi.computeTables(par, buffer, row);
380 pos_type body_pos = par.beginOfBody();
381 pos_type end = row.endpos();
384 && (body_pos > end || !par.isLineSeparator(body_pos - 1)))
386 docstring const lsep = from_utf8(layout->labelsep);
387 result.x += theFontMetrics(text_->getLabelFont(buffer, par)).width(lsep);
389 result.x += result.label_hfill;
397 int TextMetrics::labelFill(Paragraph const & par, Row const & row) const
399 Buffer & buffer = *bv_->buffer();
401 pos_type last = par.beginOfBody();
402 BOOST_ASSERT(last > 0);
404 // -1 because a label ends with a space that is in the label
407 // a separator at this end does not count
408 if (par.isLineSeparator(last))
412 for (pos_type i = row.pos(); i <= last; ++i)
413 w += text_->singleWidth(buffer, par, i);
415 docstring const & label = par.params().labelWidthString();
419 FontMetrics const & fm
420 = theFontMetrics(text_->getLabelFont(buffer, par));
422 return max(0, fm.width(label) - w);
428 // this needs special handling - only newlines count as a break point
429 pos_type addressBreakPoint(pos_type i, Paragraph const & par)
431 pos_type const end = par.size();
434 if (par.isNewline(i))
443 int TextMetrics::labelEnd(pit_type const pit) const
445 // labelEnd is only needed if the layout fills a flushleft label.
446 if (text_->getPar(pit).layout()->margintype != MARGIN_MANUAL)
448 // return the beginning of the body
449 return text_->leftMargin(*bv_->buffer(), max_width_, pit);
453 void TextMetrics::rowBreakPoint(int width, pit_type const pit,
456 Buffer & buffer = *bv_->buffer();
457 Paragraph const & par = text_->getPar(pit);
458 pos_type const end = par.size();
459 pos_type const pos = row.pos();
470 Layout_ptr const & layout = par.layout();
472 if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
473 row.endpos(addressBreakPoint(pos, par));
477 pos_type const body_pos = par.beginOfBody();
480 // Now we iterate through until we reach the right margin
481 // or the end of the par, then choose the possible break
484 int label_end = labelEnd(pit);
485 int const left = text_->leftMargin(buffer, max_width_, pit, pos);
488 // pixel width since last breakpoint
491 FontIterator fi = FontIterator(buffer, *text_, par, pos);
492 pos_type point = end;
494 FontMetrics const & fm = theFontMetrics(text_->getLabelFont(buffer, par));
495 for ( ; i < end; ++i, ++fi) {
496 char_type const c = par.getChar(i);
497 int thiswidth = text_->singleWidth(par, i, c, *fi);
499 // add the auto-hfill from label end to the body
500 if (body_pos && i == body_pos) {
501 docstring lsep = from_utf8(layout->labelsep);
502 int add = fm.width(lsep);
503 if (par.isLineSeparator(i - 1))
504 add -= text_->singleWidth(buffer, par, i - 1);
506 add = std::max(add, label_end - x);
511 chunkwidth += thiswidth;
513 // break before a character that will fall off
514 // the right of the row
516 // if no break before, break here
517 if (point == end || chunkwidth >= width - left) {
524 // exit on last registered breakpoint:
528 if (par.isNewline(i)) {
534 if (par.isInset(i + 1) && par.getInset(i + 1)->display()) {
539 if (par.isInset(i) && par.getInset(i)->display()) {
545 if (!par.isInset(i) || par.getInset(i)->isChar()) {
546 // some insets are line separators too
547 if (par.isLineSeparator(i)) {
548 // register breakpoint:
555 // maybe found one, but the par is short enough.
556 if (i == end && x < width)
559 // manual labels cannot be broken in LaTeX. But we
560 // want to make our on-screen rendering of footnotes
562 if (body_pos && point < body_pos)
569 void TextMetrics::setRowWidth(int right_margin,
570 pit_type const pit, Row & row) const
572 Buffer & buffer = *bv_->buffer();
573 // get the pure distance
574 pos_type const end = row.endpos();
576 Paragraph const & par = text_->getPar(pit);
577 docstring const labelsep = from_utf8(par.layout()->labelsep);
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();
584 FontMetrics const & fm = theFontMetrics(text_->getLabelFont(buffer, par));
587 FontIterator fi = FontIterator(buffer, *text_, par, i);
588 for ( ; i < end; ++i, ++fi) {
589 if (body_pos > 0 && i == body_pos) {
590 w += fm.width(labelsep);
591 if (par.isLineSeparator(i - 1))
592 w -= text_->singleWidth(buffer, par, i - 1);
593 w = max(w, label_end);
595 char_type const c = par.getChar(i);
596 w += text_->singleWidth(par, i, c, *fi);
600 if (body_pos > 0 && body_pos >= end) {
601 w += fm.width(labelsep);
602 if (end > 0 && par.isLineSeparator(end - 1))
603 w -= text_->singleWidth(buffer, par, end - 1);
604 w = max(w, label_end);
607 row.width(w + right_margin);
611 void TextMetrics::setHeightOfRow(pit_type const pit,
614 Paragraph const & par = text_->getPar(pit);
615 // get the maximum ascent and the maximum descent
616 double layoutasc = 0;
617 double layoutdesc = 0;
618 double const dh = defaultRowHeight();
620 // ok, let us initialize the maxasc and maxdesc value.
621 // Only the fontsize count. The other properties
622 // are taken from the layoutfont. Nicer on the screen :)
623 Layout_ptr const & layout = par.layout();
625 // as max get the first character of this row then it can
626 // increase but not decrease the height. Just some point to
627 // start with so we don't have to do the assignment below too
629 Buffer const & buffer = *bv_->buffer();
630 Font font = text_->getFont(buffer, par, row.pos());
631 Font::FONT_SIZE const tmpsize = font.size();
632 font = text_->getLayoutFont(buffer, pit);
633 Font::FONT_SIZE const size = font.size();
634 font.setSize(tmpsize);
636 Font labelfont = text_->getLabelFont(buffer, par);
638 FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
639 FontMetrics const & fontmetrics = theFontMetrics(font);
641 // these are minimum values
642 double const spacing_val = layout->spacing.getValue()
643 * text_->spacing(buffer, par);
644 //lyxerr << "spacing_val = " << spacing_val << endl;
645 int maxasc = int(fontmetrics.maxAscent() * spacing_val);
646 int maxdesc = int(fontmetrics.maxDescent() * spacing_val);
648 // insets may be taller
649 InsetList::const_iterator ii = par.insetlist.begin();
650 InsetList::const_iterator iend = par.insetlist.end();
651 for ( ; ii != iend; ++ii) {
652 if (ii->pos >= row.pos() && ii->pos < row.endpos()) {
653 maxasc = max(maxasc, ii->inset->ascent());
654 maxdesc = max(maxdesc, ii->inset->descent());
658 // Check if any custom fonts are larger (Asger)
659 // This is not completely correct, but we can live with the small,
660 // cosmetic error for now.
662 pos_type const pos_end = row.endpos();
664 Font::FONT_SIZE maxsize =
665 par.highestFontInRange(row.pos(), pos_end, size);
666 if (maxsize > font.size()) {
667 font.setSize(maxsize);
668 maxasc = max(maxasc, fontmetrics.maxAscent());
669 maxdesc = max(maxdesc, fontmetrics.maxDescent());
672 // This is nicer with box insets:
677 ParagraphList const & pars = text_->paragraphs();
680 if (row.pos() == 0) {
681 BufferParams const & bufparams = buffer.params();
682 // some parskips VERY EASY IMPLEMENTATION
683 if (bufparams.paragraph_separation
684 == BufferParams::PARSEP_SKIP
685 && par.ownerCode() != Inset::ERT_CODE
686 && par.ownerCode() != Inset::LISTINGS_CODE
688 && ((layout->isParagraph() && par.getDepth() == 0)
689 || (pars[pit - 1].layout()->isParagraph()
690 && pars[pit - 1].getDepth() == 0)))
692 maxasc += bufparams.getDefSkip().inPixels(*bv_);
695 if (par.params().startOfAppendix())
696 maxasc += int(3 * dh);
698 // This is special code for the chapter, since the label of this
699 // layout is printed in an extra row
700 if (layout->counter == "chapter"
701 && !par.params().labelString().empty()) {
702 labeladdon = int(labelfont_metrics.maxHeight()
703 * layout->spacing.getValue()
704 * text_->spacing(buffer, par));
707 // special code for the top label
708 if ((layout->labeltype == LABEL_TOP_ENVIRONMENT
709 || layout->labeltype == LABEL_BIBLIO
710 || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)
711 && isFirstInSequence(pit, pars)
712 && !par.getLabelstring().empty())
715 labelfont_metrics.maxHeight()
716 * layout->spacing.getValue()
717 * text_->spacing(buffer, par)
718 + (layout->topsep + layout->labelbottomsep) * dh);
721 // Add the layout spaces, for example before and after
722 // a section, or between the items of a itemize or enumerate
725 pit_type prev = depthHook(pit, pars, par.getDepth());
726 Paragraph const & prevpar = pars[prev];
728 && prevpar.layout() == layout
729 && prevpar.getDepth() == par.getDepth()
730 && prevpar.getLabelWidthString()
731 == par.getLabelWidthString()) {
732 layoutasc = layout->itemsep * dh;
733 } else if (pit != 0 || row.pos() != 0) {
734 if (layout->topsep > 0)
735 layoutasc = layout->topsep * dh;
738 prev = outerHook(pit, pars);
739 if (prev != pit_type(pars.size())) {
740 maxasc += int(pars[prev].layout()->parsep * dh);
741 } else if (pit != 0) {
742 Paragraph const & prevpar = pars[pit - 1];
743 if (prevpar.getDepth() != 0 ||
744 prevpar.layout() == layout) {
745 maxasc += int(layout->parsep * dh);
750 // is it a bottom line?
751 if (row.endpos() >= par.size()) {
752 // add the layout spaces, for example before and after
753 // a section, or between the items of a itemize or enumerate
755 pit_type nextpit = pit + 1;
756 if (nextpit != pit_type(pars.size())) {
761 if (pars[cpit].getDepth() > pars[nextpit].getDepth()) {
762 usual = pars[cpit].layout()->bottomsep * dh;
763 cpit = depthHook(cpit, pars, pars[nextpit].getDepth());
764 if (pars[cpit].layout() != pars[nextpit].layout()
765 || pars[nextpit].getLabelWidthString() != pars[cpit].getLabelWidthString())
767 unusual = pars[cpit].layout()->bottomsep * dh;
769 layoutdesc = max(unusual, usual);
770 } else if (pars[cpit].getDepth() == pars[nextpit].getDepth()) {
771 if (pars[cpit].layout() != pars[nextpit].layout()
772 || pars[nextpit].getLabelWidthString() != pars[cpit].getLabelWidthString())
773 layoutdesc = int(pars[cpit].layout()->bottomsep * dh);
778 // incalculate the layout spaces
779 maxasc += int(layoutasc * 2 / (2 + pars[pit].getDepth()));
780 maxdesc += int(layoutdesc * 2 / (2 + pars[pit].getDepth()));
782 // FIXME: the correct way is to do the following is to move the
783 // following code in another method specially tailored for the
784 // main Text. The following test is thus bogus.
785 // Top and bottom margin of the document (only at top-level)
787 if (pit == 0 && row.pos() == 0)
789 if (pit + 1 == pit_type(pars.size()) &&
790 row.endpos() == par.size() &&
791 !(row.endpos() > 0 && par.isNewline(row.endpos() - 1)))
795 row.ascent(maxasc + labeladdon);
796 row.descent(maxdesc);
800 // x is an absolute screen coord
801 // returns the column near the specified x-coordinate of the row
802 // x is set to the real beginning of this column
803 pos_type TextMetrics::getColumnNearX(pit_type const pit,
804 Row const & row, int & x, bool & boundary) const
806 Buffer const & buffer = *bv_->buffer();
808 /// For the main Text, it is possible that this pit is not
809 /// yet in the CoordCache when moving cursor up.
810 /// x Paragraph coordinate is always 0 for main text anyway.
811 int const xo = main_text_? 0 : bv_->coordCache().get(text_, pit).x_;
813 RowMetrics const r = computeRowMetrics(pit, row);
814 Paragraph const & par = text_->getPar(pit);
816 pos_type vc = row.pos();
817 pos_type end = row.endpos();
819 Layout_ptr const & layout = par.layout();
821 bool left_side = false;
823 pos_type body_pos = par.beginOfBody();
826 double last_tmpx = tmpx;
829 (body_pos > end || !par.isLineSeparator(body_pos - 1)))
832 // check for empty row
838 frontend::FontMetrics const & fm
839 = theFontMetrics(text_->getLabelFont(buffer, par));
841 while (vc < end && tmpx <= x) {
842 c = text_->bidi.vis2log(vc);
844 if (body_pos > 0 && c == body_pos - 1) {
846 docstring const lsep = from_utf8(layout->labelsep);
847 tmpx += r.label_hfill + fm.width(lsep);
848 if (par.isLineSeparator(body_pos - 1))
849 tmpx -= text_->singleWidth(buffer, par, body_pos - 1);
852 if (par.hfillExpansion(row, c)) {
853 tmpx += text_->singleWidth(buffer, par, c);
857 tmpx += r.label_hfill;
858 } else if (par.isSeparator(c)) {
859 tmpx += text_->singleWidth(buffer, par, c);
863 tmpx += text_->singleWidth(buffer, par, c);
868 if ((tmpx + last_tmpx) / 2 > x) {
873 BOOST_ASSERT(vc <= end); // This shouldn't happen.
876 // This (rtl_support test) is not needed, but gives
877 // some speedup if rtl_support == false
878 bool const lastrow = lyxrc.rtl_support && row.endpos() == par.size();
880 // If lastrow is false, we don't need to compute
882 bool const rtl = lastrow ? text_->isRTL(buffer, par) : false;
884 ((rtl && left_side && vc == row.pos() && x < tmpx - 5) ||
885 (!rtl && !left_side && vc == end && x > tmpx + 5)))
887 else if (vc == row.pos()) {
888 c = text_->bidi.vis2log(vc);
889 if (text_->bidi.level(c) % 2 == 1)
892 c = text_->bidi.vis2log(vc - 1);
893 bool const rtl = (text_->bidi.level(c) % 2 == 1);
894 if (left_side == rtl) {
896 boundary = text_->bidi.isBoundary(buffer, par, c);
900 // I believe this code is not needed anymore (Jug 20050717)
902 // The following code is necessary because the cursor position past
903 // the last char in a row is logically equivalent to that before
904 // the first char in the next row. That's why insets causing row
905 // divisions -- Newline and display-style insets -- must be treated
906 // specially, so cursor up/down doesn't get stuck in an air gap -- MV
907 // Newline inset, air gap below:
908 if (row.pos() < end && c >= end && par.isNewline(end - 1)) {
909 if (text_->bidi.level(end -1) % 2 == 0)
910 tmpx -= text_->singleWidth(buffer, par, end - 1);
912 tmpx += text_->singleWidth(buffer, par, end - 1);
916 // Air gap above display inset:
917 if (row.pos() < end && c >= end && end < par.size()
918 && par.isInset(end) && par.getInset(end)->display()) {
921 // Air gap below display inset:
922 if (row.pos() < end && c >= end && par.isInset(end - 1)
923 && par.getInset(end - 1)->display()) {
929 pos_type const col = c - row.pos();
931 if (!c || end == par.size())
934 if (c==end && !par.isLineSeparator(c-1) && !par.isNewline(c-1)) {
939 return min(col, end - 1 - row.pos());
943 pos_type TextMetrics::x2pos(pit_type pit, int row, int x) const
945 ParagraphMetrics const & pm = parMetrics(pit);
946 BOOST_ASSERT(!pm.rows().empty());
947 BOOST_ASSERT(row < int(pm.rows().size()));
949 Row const & r = pm.rows()[row];
950 return r.pos() + getColumnNearX(pit, r, x, bound);
954 //int Text::pos2x(pit_type pit, pos_type pos) const
956 // ParagraphMetrics const & pm = parMetrics(pit);
957 // Row const & r = pm.rows()[row];
963 int defaultRowHeight()
965 return int(theFontMetrics(Font(Font::ALL_SANE)).maxHeight() * 1.2);