- setCurrentFont(cur);
-}
-
-
-void Text::setCurrentFont(Cursor & cur)
-{
- BOOST_ASSERT(this == cur.text());
- pos_type pos = cur.pos();
- Paragraph & par = cur.paragraph();
-
- if (cur.boundary() && pos > 0)
- --pos;
-
- if (pos > 0) {
- if (pos == cur.lastpos())
- --pos;
- else // potentional bug... BUG (Lgb)
- if (par.isSeparator(pos)) {
- if (pos > cur.textRow().pos() &&
- bidi.level(pos) % 2 ==
- bidi.level(pos - 1) % 2)
- --pos;
- else if (pos + 1 < cur.lastpos())
- ++pos;
- }
- }
-
- BufferParams const & bufparams = cur.buffer().params();
- current_font = par.getFontSettings(bufparams, pos);
- real_current_font = getFont(cur.buffer(), par, pos);
-
- if (cur.pos() == cur.lastpos()
- && bidi.isBoundary(cur.buffer(), par, cur.pos())
- && !cur.boundary()) {
- Language const * lang = par.getParLanguage(bufparams);
- current_font.setLanguage(lang);
- current_font.setNumber(Font::OFF);
- real_current_font.setLanguage(lang);
- real_current_font.setNumber(Font::OFF);
- }
-}
-
-// y is screen coordinate
-pit_type Text::getPitNearY(BufferView & bv, int y) const
-{
- BOOST_ASSERT(!paragraphs().empty());
- BOOST_ASSERT(bv.coordCache().getParPos().find(this) != bv.coordCache().getParPos().end());
- CoordCache::InnerParPosCache const & cc = bv.coordCache().getParPos().find(this)->second;
- LYXERR(Debug::DEBUG)
- << BOOST_CURRENT_FUNCTION
- << ": y: " << y << " cache size: " << cc.size()
- << endl;
-
- // look for highest numbered paragraph with y coordinate less than given y
- pit_type pit = 0;
- int yy = -1;
- CoordCache::InnerParPosCache::const_iterator it = cc.begin();
- CoordCache::InnerParPosCache::const_iterator et = cc.end();
- CoordCache::InnerParPosCache::const_iterator last = et; last--;
-
- TextMetrics & tm = bv.textMetrics(this);
- ParagraphMetrics const & pm = tm.parMetrics(it->first);
-
- // If we are off-screen (before the visible part)
- if (y < 0
- // and even before the first paragraph in the cache.
- && y < it->second.y_ - int(pm.ascent())) {
- // and we are not at the first paragraph in the inset.
- if (it->first == 0)
- return 0;
- // then this is the paragraph we are looking for.
- pit = it->first - 1;
- // rebreak it and update the CoordCache.
- tm.redoParagraph(pit);
- bv.coordCache().parPos()[this][pit] =
- Point(0, it->second.y_ - pm.descent());
- return pit;
- }
-
- ParagraphMetrics const & pm_last = bv.parMetrics(this, last->first);
-
- // If we are off-screen (after the visible part)
- if (y > bv.workHeight()
- // and even after the first paragraph in the cache.
- && y >= last->second.y_ + int(pm_last.descent())) {
- pit = last->first + 1;
- // and we are not at the last paragraph in the inset.
- if (pit == int(pars_.size()))
- return last->first;
- // then this is the paragraph we are looking for.
- // rebreak it and update the CoordCache.
- tm.redoParagraph(pit);
- bv.coordCache().parPos()[this][pit] =
- Point(0, last->second.y_ + pm_last.ascent());
- return pit;
- }
-
- for (; it != et; ++it) {
- LYXERR(Debug::DEBUG)
- << BOOST_CURRENT_FUNCTION
- << " examining: pit: " << it->first
- << " y: " << it->second.y_
- << endl;
-
- ParagraphMetrics const & pm = bv.parMetrics(this, it->first);
-
- if (it->first >= pit && int(it->second.y_) - int(pm.ascent()) <= y) {
- pit = it->first;
- yy = it->second.y_;
- }
- }
-
- LYXERR(Debug::DEBUG)
- << BOOST_CURRENT_FUNCTION
- << ": found best y: " << yy << " for pit: " << pit
- << endl;
-
- return pit;