// << " xlow: " << xlow << " xhigh: " << xhigh
// << " ylow: " << ylow << " yhigh: " << yhigh
// << endl;
- Inset & inset = bv.buffer()->inset();
+ Inset & inset = bv.buffer().inset();
DocIterator it = doc_iterator_begin(inset);
it.pit() = from;
DocIterator et = doc_iterator_end(inset);
// bv functions are not yet available!
Cursor::Cursor(BufferView & bv)
: DocIterator(), bv_(&bv), anchor_(), x_target_(-1), textTargetOffset_(0),
- selection_(false), mark_(false), logicalpos_(false)
+ selection_(false), mark_(false), logicalpos_(false), current_font(Font::ALL_INHERIT)
{}
Buffer & Cursor::buffer() const
{
BOOST_ASSERT(bv_);
- BOOST_ASSERT(bv_->buffer());
- return *bv_->buffer();
+ return bv_->buffer();
}
xo = targetX();
// first get the current line
- TextMetrics const & tm = bv_->textMetrics(text());
+ TextMetrics & tm = bv_->textMetrics(text());
ParagraphMetrics const & pm = tm.parMetrics(pit());
int row;
if (pos() && boundary())
Cursor old = *this;
// To next/previous row
if (up)
- text()->editXY(*this, xo, yo - textRow().ascent() - 1);
+ tm.editXY(*this, xo, yo - textRow().ascent() - 1);
else
- text()->editXY(*this, xo, yo + textRow().descent() + 1);
+ tm.editXY(*this, xo, yo + textRow().descent() + 1);
clearSelection();
// This happens when you move out of an inset.
return docstring();
if (inTexted()) {
- Buffer const & buffer = *bv().buffer();
+ Buffer const & buffer = bv().buffer();
ParagraphList const & pars = text()->paragraphs();
// should be const ...
{
if (empty())
return 0;
- if (!bv().buffer())
- return 0;
int s = 0;
// go up until first non-0 text is hit
// (innermost text is 0 in mathed)
CursorSlice const & sl = operator[](s);
Text const & text = *sl.text();
Font font = text.getPar(sl.pit()).getFont(
- bv().buffer()->params(), sl.pos(), outerFont(sl.pit(), text.paragraphs()));
+ bv().buffer().params(), sl.pos(), outerFont(sl.pit(), text.paragraphs()));
return font.language()->encoding();
}
Font Cursor::getFont() const
{
- // The logic here should more or less match to the Text::setCurrentFont
+ // The logic here should more or less match to the Cursor::setCurrentFont
// logic, i.e. the cursor height should give a hint what will happen
// if a character is entered.
}
// get font at the position
- Font font = par.getFont(bv().buffer()->params(), pos,
+ Font font = par.getFont(bv().buffer().params(), pos,
outerFont(sl.pit(), text.paragraphs()));
return font;
}
-void Cursor::fixIfBroken()
+bool Cursor::fixIfBroken()
{
if (DocIterator::fixIfBroken()) {
clearSelection();
resetAnchor();
+ return true;
}
+ return false;
}
}
+void Cursor::setCurrentFont()
+{
+ pos_type cpos = pos();
+ Paragraph & par = paragraph();
+ Text const & ctext = *text();
+
+ // are we behind previous char in fact? -> go to that char
+ if (cpos > 0 && boundary())
+ --cpos;
+
+ // find position to take the font from
+ if (cpos != 0) {
+ // paragraph end? -> font of last char
+ if (cpos == lastpos())
+ --cpos;
+ // on space? -> look at the words in front of space
+ else if (cpos > 0 && par.isSeparator(cpos)) {
+ // abc| def -> font of c
+ // abc |[WERBEH], i.e. boundary==true -> font of c
+ // abc [WERBEH]| def, font of the space
+ if (!ctext.isRTLBoundary(buffer(), par, cpos))
+ --cpos;
+ }
+ }
+
+ // get font
+ BufferParams const & bufparams = buffer().params();
+ current_font = par.getFontSettings(bufparams, cpos);
+ real_current_font = ctext.getFont(buffer(), par, cpos);
+
+ // special case for paragraph end
+ if (pos() == lastpos()
+ && ctext.isRTLBoundary(buffer(), par, pos())
+ && !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);
+ }
+}
+
} // namespace lyx