///
Font getLabelFont(Buffer const & buffer,
Paragraph const & par) const;
- ///
+ /** Set font of character at position \p pos in paragraph \p pit.
+ * Must not be called if \p pos denotes an inset with text contents,
+ * and the inset is not allowed inside a font change (see below).
+ */
void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
Font const & font);
+ /** Needed to propagate font changes to all text cells of insets
+ * that are not allowed inside a font change (bug 1973).
+ * Must not be called if \p pos denotes an ordinary character or an
+ * inset that is alowed inside a font change.
+ * FIXME: This should be removed, see documentation of noFontChange
+ * in insetbase.h
+ */
+ void setInsetFont(Buffer const & buffer, pit_type pit, pos_type pos,
+ Font const & font, bool toggleall = false);
+
/// what you expect when pressing \<enter\> at cursor position
void breakParagraph(Cursor & cur, bool keep_layout = false);
/// Set font over selection paragraphs and rebreak.
/// FIXME: replace Cursor with DocIterator.
void setFont(Cursor & cur, Font const &, bool toggleall = false);
+ /// Set font from \p begin to \p end and rebreak.
+ void setFont(Buffer const & buffer, DocIterator const & begin,
+ DocIterator const & end, Font const &,
+ bool toggleall = false);
///
void toggleFree(Cursor & cur, Font const &, bool toggleall = false);
void Text::setCharFont(Buffer const & buffer, pit_type pit,
pos_type pos, Font const & fnt)
{
+ BOOST_ASSERT(!pars_[pit].isInset(pos) ||
+ !pars_[pit].getInset(pos)->noFontChange());
+
Font font = fnt;
Layout_ptr const & layout = pars_[pit].layout();
}
+void Text::setInsetFont(Buffer const & buffer, pit_type pit,
+ pos_type pos, Font const & font, bool toggleall)
+{
+ BOOST_ASSERT(pars_[pit].isInset(pos) &&
+ pars_[pit].getInset(pos)->noFontChange());
+
+ Inset * const inset = pars_[pit].getInset(pos);
+ DocIterator dit = doc_iterator_begin(*inset);
+ // start of the last cell
+ DocIterator end = dit;
+ end.idx() = end.lastidx();
+
+ while (true) {
+ Text * text = dit.text();
+ Inset * cell = dit.realInset();
+ if (text && cell) {
+ DocIterator cellbegin = doc_iterator_begin(*cell);
+ // last position of the cell
+ DocIterator cellend = cellbegin;
+ cellend.pit() = cellend.lastpit();
+ cellend.pos() = cellend.lastpos();
+ text->setFont(buffer, cellbegin, cellend, font, toggleall);
+ }
+ if (dit == end)
+ break;
+ dit.forwardIdx();
+ }
+}
+
+
// return past-the-last paragraph influenced by a layout change on pit
pit_type Text::undoSpan(pit_type pit)
{
}
-// set font over selection
void Text::setFont(Cursor & cur, Font const & font, bool toggleall)
{
BOOST_ASSERT(this == cur.text());
// Ok, we have a selection.
recordUndoSelection(cur);
- DocIterator dit = cur.selectionBegin();
- DocIterator ditend = cur.selectionEnd();
+ setFont(cur.buffer(), cur.selectionBegin(), cur.selectionEnd(), font,
+ toggleall);
+}
- BufferParams const & params = cur.buffer().params();
+void Text::setFont(Buffer const & buffer, DocIterator const & begin,
+ DocIterator const & end, Font const & font,
+ bool toggleall)
+{
// Don't use forwardChar here as ditend might have
// pos() == lastpos() and forwardChar would miss it.
// Can't use forwardPos either as this descends into
// nested insets.
- for (; dit != ditend; dit.forwardPosNoDescend()) {
+ Language const * language = buffer.params().language;
+ for (DocIterator dit = begin; dit != end; dit.forwardPosNoDescend()) {
if (dit.pos() != dit.lastpos()) {
- Font f = getFont(cur.buffer(), dit.paragraph(), dit.pos());
- f.update(font, params.language, toggleall);
- setCharFont(cur.buffer(), dit.pit(), dit.pos(), f);
+ pit_type const pit = dit.pit();
+ pos_type const pos = dit.pos();
+ if (pars_[pit].isInset(pos) &&
+ pars_[pit].getInset(pos)->noFontChange())
+ // We need to propagate the font change to all
+ // text cells of the inset (bug 1973).
+ // FIXME: This should change, see documentation
+ // of noFontChange in insetbase.h
+ setInsetFont(buffer, pit, pos, font, toggleall);
+ else {
+ Font f = getFont(buffer, dit.paragraph(), pos);
+ f.update(font, language, toggleall);
+ setCharFont(buffer, pit, pos, f);
+ }
}
}
}