FRect TextLayout::boundingBox(int pos, uint len) const { FRect result; LineSpec ls; for (uint i=0; i < lines(); ++i) { ls = line(i); if (ls.lastItem < pos) continue; if (ls.firstItem <= pos) { /* //if (ls.lastItem == pos && (item(pos)->effects() & ScLayout_SuppressSpace) ) { if (i+1 < lines()) { ls = line(i+1); result.setRect(ls.x, ls.y - ls.ascent, 1, ls.ascent + ls.descent); } else { ls = line(lines()-1); const ParagraphStyle& pstyle(paragraphStyle(pos)); result.setRect(ls.x, ls.y + pstyle.lineSpacing() - ls.ascent, 1, ls.ascent + ls.descent); } } else */ { qreal xpos = ls.x; for (int j = ls.firstItem; j < pos; ++j) { if (story()->hasObject(j)) xpos += (story()->object(j)->width() + story()->object(j)->lineWidth()) * story()->getGlyphs(j)->scaleH; else xpos += story()->getGlyphs(j)->wide(); } qreal finalw = 1; if (story()->hasObject(pos)) finalw = (story()->object(pos)->width() + story()->object(pos)->lineWidth()) * story()->getGlyphs(pos)->scaleH; else finalw = story()->getGlyphs(pos)->wide(); const CharStyle& cs(story()->charStyle(pos)); qreal desc = -cs.font().descent(cs.fontSize() / 10.0); qreal asce = cs.font().ascent(cs.fontSize() / 10.0); result.setRect(xpos, ls.y - asce, pos < story()->length()? finalw : 1, desc+asce); } return result; } } const ParagraphStyle& pstyle(story()->paragraphStyle(qMin(pos, story()->length()))); // rather the trailing style than a segfault. if (lines() > 0) { ls = line(lines()-1); result.setRect(ls.x, ls.y + pstyle.lineSpacing() - ls.ascent, 1, ls.ascent + ls.descent); } else { result.setRect(1, 1, 1, pstyle.lineSpacing()); } return result; }