Now that Text knows its owner, use the associated Buffer access.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30941 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2009-08-09 15:29:34 +00:00
parent e8674d6141
commit 5425c53fd1
13 changed files with 89 additions and 91 deletions

View File

@ -690,7 +690,7 @@ bool Buffer::readDocument(Lexer & lex)
} }
// read main text // read main text
bool const res = text().read(*this, lex, errorList, d->inset); bool const res = text().read(lex, errorList, d->inset);
updateMacros(); updateMacros();
updateMacroInstances(); updateMacroInstances();
@ -1028,7 +1028,7 @@ bool Buffer::write(ostream & ofs) const
// write the text // write the text
ofs << "\n\\begin_body\n"; ofs << "\n\\begin_body\n";
text().write(*this, ofs); text().write(ofs);
ofs << "\n\\end_body\n"; ofs << "\n\\end_body\n";
// Write marker that shows file is complete // Write marker that shows file is complete

View File

@ -79,11 +79,10 @@ namespace lyx {
using cap::cutSelection; using cap::cutSelection;
using cap::pasteParagraphList; using cap::pasteParagraphList;
namespace { void Text::readParToken(Paragraph & par, Lexer & lex,
void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
string const & token, Font & font, Change & change, ErrorList & errorList) string const & token, Font & font, Change & change, ErrorList & errorList)
{ {
Buffer const & buf = owner_->buffer();
BufferParams const & bp = buf.params(); BufferParams const & bp = buf.params();
if (token[0] != '\\') { if (token[0] != '\\') {
@ -102,7 +101,7 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
if (layoutname.empty()) if (layoutname.empty())
layoutname = tclass.defaultLayoutName(); layoutname = tclass.defaultLayoutName();
if (par.forcePlainLayout()) { if (owner_->forcePlainLayout()) {
// in this case only the empty layout is allowed // in this case only the empty layout is allowed
layoutname = tclass.plainLayoutName(); layoutname = tclass.plainLayoutName();
} else if (par.usePlainLayout()) { } else if (par.usePlainLayout()) {
@ -246,7 +245,7 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
} }
void readParagraph(Buffer const & buf, Paragraph & par, Lexer & lex, void Text::readParagraph(Paragraph & par, Lexer & lex,
ErrorList & errorList) ErrorList & errorList)
{ {
lex.nextToken(); lex.nextToken();
@ -255,7 +254,7 @@ void readParagraph(Buffer const & buf, Paragraph & par, Lexer & lex,
Change change(Change::UNCHANGED); Change change(Change::UNCHANGED);
while (lex.isOK()) { while (lex.isOK()) {
readParToken(buf, par, lex, token, font, change, errorList); readParToken(par, lex, token, font, change, errorList);
lex.nextToken(); lex.nextToken();
token = lex.getString(); token = lex.getString();
@ -287,8 +286,6 @@ void readParagraph(Buffer const & buf, Paragraph & par, Lexer & lex,
} }
} // namespace anon
class TextCompletionList : public CompletionList class TextCompletionList : public CompletionList
{ {
public: public:
@ -328,10 +325,10 @@ bool Text::empty() const
} }
double Text::spacing(Buffer const & buffer, Paragraph const & par) const double Text::spacing(Paragraph const & par) const
{ {
if (par.params().spacing().isDefault()) if (par.params().spacing().isDefault())
return buffer.params().spacing().getValue(); return owner_->buffer().params().spacing().getValue();
return par.params().spacing().getValue(); return par.params().spacing().getValue();
} }
@ -453,12 +450,12 @@ void Text::insertChar(Cursor & cur, char_type c)
|| par.isSeparator(cur.pos() - 2) || par.isSeparator(cur.pos() - 2)
|| par.isNewline(cur.pos() - 2)) || par.isNewline(cur.pos() - 2))
) { ) {
setCharFont(buffer, pit, cur.pos() - 1, cur.current_font, setCharFont(pit, cur.pos() - 1, cur.current_font,
tm.font_); tm.font_);
} else if (contains(number_seperators, c) } else if (contains(number_seperators, c)
&& cur.pos() >= 2 && cur.pos() >= 2
&& tm.displayFont(pit, cur.pos() - 2).fontInfo().number() == FONT_ON) { && tm.displayFont(pit, cur.pos() - 2).fontInfo().number() == FONT_ON) {
setCharFont(buffer, pit, cur.pos() - 1, cur.current_font, setCharFont(pit, cur.pos() - 1, cur.current_font,
tm.font_); tm.font_);
} }
} }
@ -1208,7 +1205,7 @@ bool Text::dissolveInset(Cursor & cur)
{ {
LASSERT(this == cur.text(), return false); LASSERT(this == cur.text(), return false);
if (isMainText(cur.bv().buffer()) || cur.inset().nargs() != 1) if (isMainText() || cur.inset().nargs() != 1)
return false; return false;
cur.recordUndoInset(); cur.recordUndoInset();
@ -1259,8 +1256,9 @@ void Text::getWord(CursorSlice & from, CursorSlice & to,
} }
void Text::write(Buffer const & buf, ostream & os) const void Text::write(ostream & os) const
{ {
Buffer const & buf = owner_->buffer();
ParagraphList::const_iterator pit = paragraphs().begin(); ParagraphList::const_iterator pit = paragraphs().begin();
ParagraphList::const_iterator end = paragraphs().end(); ParagraphList::const_iterator end = paragraphs().end();
depth_type dth = 0; depth_type dth = 0;
@ -1273,9 +1271,10 @@ void Text::write(Buffer const & buf, ostream & os) const
} }
bool Text::read(Buffer const & buf, Lexer & lex, bool Text::read(Lexer & lex,
ErrorList & errorList, InsetText * insetPtr) ErrorList & errorList, InsetText * insetPtr)
{ {
Buffer const & buf = owner_->buffer();
depth_type depth = 0; depth_type depth = 0;
bool res = true; bool res = true;
@ -1308,10 +1307,7 @@ bool Text::read(Buffer const & buf, Lexer & lex,
par.params().depth(depth); par.params().depth(depth);
par.setFont(0, Font(inherit_font, buf.params().language)); par.setFont(0, Font(inherit_font, buf.params().language));
pars_.push_back(par); pars_.push_back(par);
readParagraph(pars_.back(), lex, errorList);
// FIXME: goddamn InsetTabular makes us pass a Buffer
// not BufferParams
lyx::readParagraph(buf, pars_.back(), lex, errorList);
// register the words in the global word list // register the words in the global word list
CursorSlice sl = CursorSlice(*insetPtr); CursorSlice sl = CursorSlice(*insetPtr);

View File

@ -19,7 +19,6 @@
namespace lyx { namespace lyx {
class Buffer;
class BufferParams; class BufferParams;
class BufferView; class BufferView;
class CompletionList; class CompletionList;
@ -53,15 +52,14 @@ public:
InsetText const * inset() { return owner_; } InsetText const * inset() { return owner_; }
/// ///
FontInfo layoutFont(Buffer const & buffer, pit_type pit) const; FontInfo layoutFont(pit_type pit) const;
/// ///
FontInfo labelFont(Buffer const & buffer, FontInfo labelFont(Paragraph const & par) const;
Paragraph const & par) const;
/** Set font of character at position \p pos in paragraph \p pit. /** 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, * 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). * and the inset is not allowed inside a font change (see below).
*/ */
void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos, void setCharFont(pit_type pit, pos_type pos,
Font const & font, Font const & display_font); Font const & font, Font const & display_font);
/** Needed to propagate font changes to all text cells of insets /** Needed to propagate font changes to all text cells of insets
@ -78,7 +76,7 @@ public:
void breakParagraph(Cursor & cur, bool inverse_logic = false); void breakParagraph(Cursor & cur, bool inverse_logic = false);
/// set layout over selection /// set layout over selection
void setLayout(Buffer const & buffer, pit_type start, pit_type end, void setLayout(pit_type start, pit_type end,
docstring const & layout); docstring const & layout);
/// Set given layout to current cursor position. /// Set given layout to current cursor position.
/// FIXME: replace Cursor with DocIterator. /// FIXME: replace Cursor with DocIterator.
@ -265,15 +263,15 @@ public:
ParagraphList const & paragraphs() const { return pars_; } ParagraphList const & paragraphs() const { return pars_; }
ParagraphList & paragraphs() { return pars_; } ParagraphList & paragraphs() { return pars_; }
/// return true if this is the main text /// return true if this is the main text
bool isMainText(Buffer const &) const; bool isMainText() const;
/// ///
double spacing(Buffer const & buffer, Paragraph const & par) const; double spacing(Paragraph const & par) const;
/// make a suggestion for a label /// make a suggestion for a label
/// FIXME: replace Cursor with DocIterator. /// FIXME: replace Cursor with DocIterator.
docstring getPossibleLabel(Cursor const & cur) const; docstring getPossibleLabel(Cursor const & cur) const;
/// is this paragraph right-to-left? /// is this paragraph right-to-left?
bool isRTL(Buffer const &, Paragraph const & par) const; bool isRTL(Paragraph const & par) const;
/// ///
bool checkAndActivateInset(Cursor & cur, bool front); bool checkAndActivateInset(Cursor & cur, bool front);
@ -281,10 +279,10 @@ public:
bool checkAndActivateInsetVisual(Cursor & cur, bool movingForward, bool movingLeft); bool checkAndActivateInsetVisual(Cursor & cur, bool movingForward, bool movingLeft);
/// ///
void write(Buffer const & buf, std::ostream & os) const; void write(std::ostream & os) const;
/// returns true if \end_document has not been read /// returns true if \end_document has not been read
/// insetPtr is the containing Inset /// insetPtr is the containing Inset
bool read(Buffer const & buf, Lexer & lex, ErrorList & errorList, bool read(Lexer & lex, ErrorList & errorList,
InsetText * insetPtr); InsetText * insetPtr);
/// delete double spaces, leading spaces, and empty paragraphs around old cursor. /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
@ -347,6 +345,11 @@ private:
/// \param asParagraphs whether to paste as paragraphs or as lines /// \param asParagraphs whether to paste as paragraphs or as lines
void pasteString(Cursor & cur, docstring const & str, void pasteString(Cursor & cur, docstring const & str,
bool asParagraphs); bool asParagraphs);
///
void readParToken(Paragraph & par, Lexer & lex, std::string const & token,
Font & font, Change & change, ErrorList & errorList);
///
void readParagraph(Paragraph & par, Lexer & lex, ErrorList & errorList);
/// Owner Inset. /// Owner Inset.
InsetText * owner_; InsetText * owner_;

View File

@ -63,14 +63,14 @@ using namespace std;
namespace lyx { namespace lyx {
bool Text::isMainText(Buffer const & buffer) const bool Text::isMainText() const
{ {
return &buffer.text() == this; return &owner_->buffer().text() == this;
} }
// Note that this is supposed to return a fully realized font. // Note that this is supposed to return a fully realized font.
FontInfo Text::layoutFont(Buffer const & buffer, pit_type const pit) const FontInfo Text::layoutFont(pit_type const pit) const
{ {
Layout const & layout = pars_[pit].layout(); Layout const & layout = pars_[pit].layout();
@ -78,7 +78,7 @@ FontInfo Text::layoutFont(Buffer const & buffer, pit_type const pit) const
FontInfo lf = layout.resfont; FontInfo lf = layout.resfont;
// In case the default family has been customized // In case the default family has been customized
if (layout.font.family() == INHERIT_FAMILY) if (layout.font.family() == INHERIT_FAMILY)
lf.setFamily(buffer.params().getFont().fontInfo().family()); lf.setFamily(owner_->buffer().params().getFont().fontInfo().family());
// FIXME // FIXME
// It ought to be possible here just to use Inset::getLayout() and skip // It ought to be possible here just to use Inset::getLayout() and skip
// the asInsetCollapsable() bit. Unfortunatley, that doesn't work right // the asInsetCollapsable() bit. Unfortunatley, that doesn't work right
@ -96,15 +96,16 @@ FontInfo Text::layoutFont(Buffer const & buffer, pit_type const pit) const
FontInfo font = layout.font; FontInfo font = layout.font;
// Realize with the fonts of lesser depth. // Realize with the fonts of lesser depth.
//font.realize(outerFont(pit, paragraphs())); //font.realize(outerFont(pit, paragraphs()));
font.realize(buffer.params().getFont().fontInfo()); font.realize(owner_->buffer().params().getFont().fontInfo());
return font; return font;
} }
// Note that this is supposed to return a fully realized font. // Note that this is supposed to return a fully realized font.
FontInfo Text::labelFont(Buffer const & buffer, Paragraph const & par) const FontInfo Text::labelFont(Paragraph const & par) const
{ {
Buffer const & buffer = owner_->buffer();
Layout const & layout = par.layout(); Layout const & layout = par.layout();
if (!par.getDepth()) { if (!par.getDepth()) {
@ -123,9 +124,10 @@ FontInfo Text::labelFont(Buffer const & buffer, Paragraph const & par) const
} }
void Text::setCharFont(Buffer const & buffer, pit_type pit, void Text::setCharFont(pit_type pit,
pos_type pos, Font const & fnt, Font const & display_font) pos_type pos, Font const & fnt, Font const & display_font)
{ {
Buffer const & buffer = owner_->buffer();
Font font = fnt; Font font = fnt;
Layout const & layout = pars_[pit].layout(); Layout const & layout = pars_[pit].layout();
@ -151,7 +153,7 @@ void Text::setCharFont(Buffer const & buffer, pit_type pit,
// Inside inset, apply the inset's font attributes if any // Inside inset, apply the inset's font attributes if any
// (charstyle!) // (charstyle!)
if (!isMainText(buffer)) if (!isMainText())
layoutfont.realize(display_font.fontInfo()); layoutfont.realize(display_font.fontInfo());
layoutfont.realize(buffer.params().getFont().fontInfo()); layoutfont.realize(buffer.params().getFont().fontInfo());
@ -202,11 +204,12 @@ pit_type Text::undoSpan(pit_type pit)
} }
void Text::setLayout(Buffer const & buffer, pit_type start, pit_type end, void Text::setLayout(pit_type start, pit_type end,
docstring const & layout) docstring const & layout)
{ {
LASSERT(start != end, /**/); LASSERT(start != end, /**/);
Buffer const & buffer = owner_->buffer();
BufferParams const & bp = buffer.params(); BufferParams const & bp = buffer.params();
Layout const & lyxlayout = bp.documentClass()[layout]; Layout const & lyxlayout = bp.documentClass()[layout];
@ -228,7 +231,7 @@ void Text::setLayout(Cursor & cur, docstring const & layout)
pit_type end = cur.selEnd().pit() + 1; pit_type end = cur.selEnd().pit() + 1;
pit_type undopit = undoSpan(end - 1); pit_type undopit = undoSpan(end - 1);
recUndo(cur, start, undopit - 1); recUndo(cur, start, undopit - 1);
setLayout(*cur.buffer(), start, end, layout); setLayout(start, end, layout);
cur.buffer()->updateLabels(); cur.buffer()->updateLabels();
} }
@ -300,9 +303,9 @@ void Text::setFont(Cursor & cur, Font const & font, bool toggleall)
FontInfo layoutfont; FontInfo layoutfont;
pit_type pit = cur.pit(); pit_type pit = cur.pit();
if (cur.pos() < pars_[pit].beginOfBody()) if (cur.pos() < pars_[pit].beginOfBody())
layoutfont = labelFont(*cur.buffer(), pars_[pit]); layoutfont = labelFont(pars_[pit]);
else else
layoutfont = layoutFont(*cur.buffer(), pit); layoutfont = layoutFont(pit);
// Update current font // Update current font
cur.real_current_font.update(font, cur.real_current_font.update(font,
@ -354,7 +357,7 @@ void Text::setFont(BufferView const & bv, CursorSlice const & begin,
TextMetrics const & tm = bv.textMetrics(this); TextMetrics const & tm = bv.textMetrics(this);
Font f = tm.displayFont(pit, pos); Font f = tm.displayFont(pit, pos);
f.update(font, language, toggleall); f.update(font, language, toggleall);
setCharFont(buffer, pit, pos, f, tm.font_); setCharFont(pit, pos, f, tm.font_);
} }
} }

View File

@ -507,8 +507,9 @@ void Text::number(Cursor & cur)
} }
bool Text::isRTL(Buffer const & buffer, Paragraph const & par) const bool Text::isRTL(Paragraph const & par) const
{ {
Buffer const & buffer = owner_->buffer();
return par.isRTL(buffer.params()); return par.isRTL(buffer.params());
} }
@ -1287,7 +1288,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
if (layout.empty()) if (layout.empty())
layout = tclass.defaultLayoutName(); layout = tclass.defaultLayoutName();
if (para.forcePlainLayout()) if (owner_->forcePlainLayout())
// in this case only the empty layout is allowed // in this case only the empty layout is allowed
layout = tclass.plainLayoutName(); layout = tclass.plainLayoutName();
else if (para.usePlainLayout()) { else if (para.usePlainLayout()) {
@ -2543,7 +2544,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
enable = cur.inset().lyxCode() == FLEX_CODE enable = cur.inset().lyxCode() == FLEX_CODE
&& il.lyxtype() == type; && il.lyxtype() == type;
} else { } else {
enable = ((!isMainText(cur.bv().buffer()) enable = ((!isMainText()
&& cur.inset().nargs() == 1) && cur.inset().nargs() == 1)
|| (cur.nextInset() || (cur.nextInset()
&& cur.nextInset()->nargs() == 1)); && cur.nextInset()->nargs() == 1));
@ -2571,7 +2572,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_OUTLINE_OUT: case LFUN_OUTLINE_OUT:
case LFUN_OUTLINE_DRAGMOVE: case LFUN_OUTLINE_DRAGMOVE:
// FIXME: LyX is not ready for outlining within inset. // FIXME: LyX is not ready for outlining within inset.
enable = isMainText(cur.bv().buffer()) enable = isMainText()
&& cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC; && cur.paragraph().layout().toclevel != Layout::NOT_IN_TOC;
break; break;

View File

@ -263,7 +263,7 @@ Font TextMetrics::displayFont(pit_type pit, pos_type pos) const
// We specialize the 95% common case: // We specialize the 95% common case:
if (!par.getDepth()) { if (!par.getDepth()) {
Font f = par.getFontSettings(params, pos); Font f = par.getFontSettings(params, pos);
if (!text_->isMainText(buffer)) if (!text_->isMainText())
applyOuterFont(f); applyOuterFont(f);
bool lab = layout.labeltype == LABEL_MANUAL && pos < body_pos; bool lab = layout.labeltype == LABEL_MANUAL && pos < body_pos;
@ -284,7 +284,7 @@ Font TextMetrics::displayFont(pit_type pit, pos_type pos) const
Font font = par.getFontSettings(params, pos); Font font = par.getFontSettings(params, pos);
font.fontInfo().realize(layoutfont); font.fontInfo().realize(layoutfont);
if (!text_->isMainText(buffer)) if (!text_->isMainText())
applyOuterFont(font); applyOuterFont(font);
// Realize against environment font information // Realize against environment font information
@ -520,7 +520,6 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
row.label_hfill = 0; row.label_hfill = 0;
row.separator = 0; row.separator = 0;
Buffer & buffer = bv_->buffer();
Paragraph const & par = text_->getPar(pit); Paragraph const & par = text_->getPar(pit);
double w = width - row.width(); double w = width - row.width();
@ -531,7 +530,7 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
//lyxerr << "row.width() " << row.width() << endl; //lyxerr << "row.width() " << row.width() << endl;
//lyxerr << "w " << w << endl; //lyxerr << "w " << w << endl;
bool const is_rtl = text_->isRTL(buffer, par); bool const is_rtl = text_->isRTL(par);
if (is_rtl) if (is_rtl)
row.x = rightMargin(pit); row.x = rightMargin(pit);
else else
@ -648,7 +647,7 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
if (body_pos > 0 if (body_pos > 0
&& (body_pos > end || !par.isLineSeparator(body_pos - 1))) && (body_pos > end || !par.isLineSeparator(body_pos - 1)))
{ {
row.x += theFontMetrics(text_->labelFont(buffer, par)). row.x += theFontMetrics(text_->labelFont(par)).
width(layout.labelsep); width(layout.labelsep);
if (body_pos <= end) if (body_pos <= end)
row.x += row.label_hfill; row.x += row.label_hfill;
@ -684,7 +683,6 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
int TextMetrics::labelFill(pit_type const pit, Row const & row) const int TextMetrics::labelFill(pit_type const pit, Row const & row) const
{ {
Buffer & buffer = bv_->buffer();
Paragraph const & par = text_->getPar(pit); Paragraph const & par = text_->getPar(pit);
pos_type last = par.beginOfBody(); pos_type last = par.beginOfBody();
@ -706,7 +704,7 @@ int TextMetrics::labelFill(pit_type const pit, Row const & row) const
return 0; return 0;
FontMetrics const & fm FontMetrics const & fm
= theFontMetrics(text_->labelFont(buffer, par)); = theFontMetrics(text_->labelFont(par));
return max(0, fm.width(label) - w); return max(0, fm.width(label) - w);
} }
@ -795,7 +793,6 @@ private:
pit_type TextMetrics::rowBreakPoint(int width, pit_type const pit, pit_type TextMetrics::rowBreakPoint(int width, pit_type const pit,
pit_type pos) const pit_type pos) const
{ {
Buffer & buffer = bv_->buffer();
ParagraphMetrics const & pm = par_metrics_[pit]; ParagraphMetrics const & pm = par_metrics_[pit];
Paragraph const & par = text_->getPar(pit); Paragraph const & par = text_->getPar(pit);
pos_type const end = par.size(); pos_type const end = par.size();
@ -846,7 +843,7 @@ pit_type TextMetrics::rowBreakPoint(int width, pit_type const pit,
// add the auto-hfill from label end to the body // add the auto-hfill from label end to the body
if (body_pos && i == body_pos) { if (body_pos && i == body_pos) {
FontMetrics const & fm = theFontMetrics( FontMetrics const & fm = theFontMetrics(
text_->labelFont(buffer, par)); text_->labelFont(par));
int add = fm.width(layout.labelsep); int add = fm.width(layout.labelsep);
if (par.isLineSeparator(i - 1)) if (par.isLineSeparator(i - 1))
add -= singleWidth(pit, i - 1); add -= singleWidth(pit, i - 1);
@ -918,7 +915,6 @@ pit_type TextMetrics::rowBreakPoint(int width, pit_type const pit,
int TextMetrics::rowWidth(int right_margin, pit_type const pit, int TextMetrics::rowWidth(int right_margin, pit_type const pit,
pos_type const first, pos_type const end) const pos_type const first, pos_type const end) const
{ {
Buffer & buffer = bv_->buffer();
// get the pure distance // get the pure distance
ParagraphMetrics const & pm = par_metrics_[pit]; ParagraphMetrics const & pm = par_metrics_[pit];
Paragraph const & par = text_->getPar(pit); Paragraph const & par = text_->getPar(pit);
@ -943,7 +939,7 @@ int TextMetrics::rowWidth(int right_margin, pit_type const pit,
for ( ; i < end; ++i, ++fi) { for ( ; i < end; ++i, ++fi) {
if (body_pos > 0 && i == body_pos) { if (body_pos > 0 && i == body_pos) {
FontMetrics const & fm = theFontMetrics( FontMetrics const & fm = theFontMetrics(
text_->labelFont(buffer, par)); text_->labelFont(par));
w += fm.width(par.layout().labelsep); w += fm.width(par.layout().labelsep);
if (par.isLineSeparator(i - 1)) if (par.isLineSeparator(i - 1))
w -= singleWidth(pit, i - 1); w -= singleWidth(pit, i - 1);
@ -962,7 +958,7 @@ int TextMetrics::rowWidth(int right_margin, pit_type const pit,
if (body_pos > 0 && body_pos >= end) { if (body_pos > 0 && body_pos >= end) {
FontMetrics const & fm = theFontMetrics( FontMetrics const & fm = theFontMetrics(
text_->labelFont(buffer, par)); text_->labelFont(par));
w += fm.width(par.layout().labelsep); w += fm.width(par.layout().labelsep);
if (end > 0 && par.isLineSeparator(end - 1)) if (end > 0 && par.isLineSeparator(end - 1))
w -= singleWidth(pit, end - 1); w -= singleWidth(pit, end - 1);
@ -994,18 +990,18 @@ Dimension TextMetrics::rowHeight(pit_type const pit, pos_type const first,
Buffer const & buffer = bv_->buffer(); Buffer const & buffer = bv_->buffer();
Font font = displayFont(pit, first); Font font = displayFont(pit, first);
FontSize const tmpsize = font.fontInfo().size(); FontSize const tmpsize = font.fontInfo().size();
font.fontInfo() = text_->layoutFont(buffer, pit); font.fontInfo() = text_->layoutFont(pit);
FontSize const size = font.fontInfo().size(); FontSize const size = font.fontInfo().size();
font.fontInfo().setSize(tmpsize); font.fontInfo().setSize(tmpsize);
FontInfo labelfont = text_->labelFont(buffer, par); FontInfo labelfont = text_->labelFont(par);
FontMetrics const & labelfont_metrics = theFontMetrics(labelfont); FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
FontMetrics const & fontmetrics = theFontMetrics(font); FontMetrics const & fontmetrics = theFontMetrics(font);
// these are minimum values // these are minimum values
double const spacing_val = layout.spacing.getValue() double const spacing_val = layout.spacing.getValue()
* text_->spacing(buffer, par); * text_->spacing(par);
//lyxerr << "spacing_val = " << spacing_val << endl; //lyxerr << "spacing_val = " << spacing_val << endl;
int maxasc = int(fontmetrics.maxAscent() * spacing_val); int maxasc = int(fontmetrics.maxAscent() * spacing_val);
int maxdesc = int(fontmetrics.maxDescent() * spacing_val); int maxdesc = int(fontmetrics.maxDescent() * spacing_val);
@ -1070,7 +1066,7 @@ Dimension TextMetrics::rowHeight(pit_type const pit, pos_type const first,
&& !par.params().labelString().empty()) { && !par.params().labelString().empty()) {
labeladdon = int(labelfont_metrics.maxHeight() labeladdon = int(labelfont_metrics.maxHeight()
* layout.spacing.getValue() * layout.spacing.getValue()
* text_->spacing(buffer, par)); * text_->spacing(par));
} }
// special code for the top label // special code for the top label
@ -1083,7 +1079,7 @@ Dimension TextMetrics::rowHeight(pit_type const pit, pos_type const first,
labeladdon = int( labeladdon = int(
labelfont_metrics.maxHeight() labelfont_metrics.maxHeight()
* layout.spacing.getValue() * layout.spacing.getValue()
* text_->spacing(buffer, par) * text_->spacing(par)
+ (layout.topsep + layout.labelbottomsep) * dh); + (layout.topsep + layout.labelbottomsep) * dh);
} }
@ -1209,7 +1205,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
last_tmpx = tmpx; last_tmpx = tmpx;
if (body_pos > 0 && c == body_pos - 1) { if (body_pos > 0 && c == body_pos - 1) {
FontMetrics const & fm = theFontMetrics( FontMetrics const & fm = theFontMetrics(
text_->labelFont(buffer, par)); text_->labelFont(par));
tmpx += row.label_hfill + fm.width(layout.labelsep); tmpx += row.label_hfill + fm.width(layout.labelsep);
if (par.isLineSeparator(body_pos - 1)) if (par.isLineSeparator(body_pos - 1))
tmpx -= singleWidth(pit, body_pos - 1); tmpx -= singleWidth(pit, body_pos - 1);
@ -1235,7 +1231,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
// If lastrow is false, we don't need to compute // If lastrow is false, we don't need to compute
// the value of rtl. // the value of rtl.
bool const rtl = lastrow ? text_->isRTL(buffer, par) : false; bool const rtl = lastrow ? text_->isRTL(par) : false;
if (lastrow && if (lastrow &&
((rtl && left_side && vc == row.pos() && x < tmpx - 5) || ((rtl && left_side && vc == row.pos() && x < tmpx - 5) ||
(!rtl && !left_side && vc == end && x > tmpx + 5))) { (!rtl && !left_side && vc == end && x > tmpx + 5))) {
@ -1618,7 +1614,7 @@ int TextMetrics::cursorX(CursorSlice const & sl,
if (end <= row_pos) if (end <= row_pos)
cursor_vpos = row_pos; cursor_vpos = row_pos;
else if (ppos >= end) else if (ppos >= end)
cursor_vpos = text_->isRTL(buffer, par) ? row_pos : end; cursor_vpos = text_->isRTL(par) ? row_pos : end;
else if (ppos > row_pos && ppos >= end) else if (ppos > row_pos && ppos >= end)
// Place cursor after char at (logical) position pos - 1 // Place cursor after char at (logical) position pos - 1
cursor_vpos = (bidi.level(ppos - 1) % 2 == 0) cursor_vpos = (bidi.level(ppos - 1) % 2 == 0)
@ -1670,7 +1666,7 @@ int TextMetrics::cursorX(CursorSlice const & sl,
pos_type pos = bidi.vis2log(vpos); pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) { if (body_pos > 0 && pos == body_pos - 1) {
FontMetrics const & labelfm = theFontMetrics( FontMetrics const & labelfm = theFontMetrics(
text_->labelFont(buffer, par)); text_->labelFont(par));
x += row.label_hfill + labelfm.width(par.layout().labelsep); x += row.label_hfill + labelfm.width(par.layout().labelsep);
if (par.isLineSeparator(body_pos - 1)) if (par.isLineSeparator(body_pos - 1))
x -= singleWidth(pit, body_pos - 1); x -= singleWidth(pit, body_pos - 1);
@ -1839,7 +1835,7 @@ int TextMetrics::leftMargin(int max_width,
int l_margin = 0; int l_margin = 0;
if (text_->isMainText(buffer)) if (text_->isMainText())
l_margin += bv_->leftMargin(); l_margin += bv_->leftMargin();
l_margin += theFontMetrics(buffer.params().getFont()).signedWidth( l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(
@ -1869,7 +1865,7 @@ int TextMetrics::leftMargin(int max_width,
&& pit > 0 && pars[pit - 1].layout().nextnoindent) && pit > 0 && pars[pit - 1].layout().nextnoindent)
parindent.erase(); parindent.erase();
FontInfo const labelfont = text_->labelFont(buffer, par); FontInfo const labelfont = text_->labelFont(par);
FontMetrics const & labelfont_metrics = theFontMetrics(labelfont); FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
switch (layout.margintype) { switch (layout.margintype) {
@ -2115,7 +2111,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) co
// 12 lines lower): // 12 lines lower):
if (lyxerr.debugging(Debug::PAINTING) && inside if (lyxerr.debugging(Debug::PAINTING) && inside
&& (row.selection() || pi.full_repaint || row_has_changed)) { && (row.selection() || pi.full_repaint || row_has_changed)) {
string const foreword = text_->isMainText(bv_->buffer()) ? string const foreword = text_->isMainText() ?
"main text redraw " : "inset text redraw: "; "main text redraw " : "inset text redraw: ";
LYXERR(Debug::PAINTING, foreword << "pit=" << pit << " row=" << i LYXERR(Debug::PAINTING, foreword << "pit=" << pit << " row=" << i
<< " row_selection=" << row.selection() << " row_selection=" << row.selection()
@ -2160,7 +2156,6 @@ void TextMetrics::drawRowSelection(PainterInfo & pi, int x, Row const & row,
bool const begin_boundary = beg.pos() >= row.endpos(); bool const begin_boundary = beg.pos() >= row.endpos();
bool const end_boundary = row.sel_end == row.endpos(); bool const end_boundary = row.sel_end == row.endpos();
Buffer & buffer = bv_->buffer();
DocIterator cur = beg; DocIterator cur = beg;
cur.boundary(begin_boundary); cur.boundary(begin_boundary);
int x1 = cursorX(beg.top(), begin_boundary); int x1 = cursorX(beg.top(), begin_boundary);
@ -2168,12 +2163,12 @@ void TextMetrics::drawRowSelection(PainterInfo & pi, int x, Row const & row,
int const y1 = bv_->getPos(cur, cur.boundary()).y_ - row.ascent(); int const y1 = bv_->getPos(cur, cur.boundary()).y_ - row.ascent();
int const y2 = y1 + row.height(); int const y2 = y1 + row.height();
int const rm = text_->isMainText(buffer) ? bv_->rightMargin() : 0; int const rm = text_->isMainText() ? bv_->rightMargin() : 0;
int const lm = text_->isMainText(buffer) ? bv_->leftMargin() : 0; int const lm = text_->isMainText() ? bv_->leftMargin() : 0;
// draw the margins // draw the margins
if (row.begin_margin_sel) { if (row.begin_margin_sel) {
if (text_->isRTL(buffer, beg.paragraph())) { if (text_->isRTL(beg.paragraph())) {
pi.pain.fillRectangle(x + x1, y1, width() - rm - x1, y2 - y1, pi.pain.fillRectangle(x + x1, y1, width() - rm - x1, y2 - y1,
Color_selection); Color_selection);
} else { } else {
@ -2183,7 +2178,7 @@ void TextMetrics::drawRowSelection(PainterInfo & pi, int x, Row const & row,
} }
if (row.end_margin_sel) { if (row.end_margin_sel) {
if (text_->isRTL(buffer, beg.paragraph())) { if (text_->isRTL(beg.paragraph())) {
pi.pain.fillRectangle(x + lm, y1, x2 - lm, y2 - y1, pi.pain.fillRectangle(x + lm, y1, x2 - lm, y2 - y1,
Color_selection); Color_selection);
} else { } else {

View File

@ -60,7 +60,7 @@ InsetCaption::InsetCaption(Buffer const & buf)
void InsetCaption::write(ostream & os) const void InsetCaption::write(ostream & os) const
{ {
os << "Caption\n"; os << "Caption\n";
text().write(buffer(), os); text().write(os);
} }

View File

@ -148,7 +148,7 @@ void InsetCollapsable::write(ostream & os) const
break; break;
} }
os << "\n"; os << "\n";
text().write(buffer(), os); text().write(os);
} }

View File

@ -1030,7 +1030,7 @@ void toggleFixedWidth(Cursor & cur, InsetTableCell * inset, bool fixedWidth)
// reset layout // reset layout
cur.push(*inset); cur.push(*inset);
// undo information has already been recorded // undo information has already been recorded
inset->getText(0)->setLayout(cur.bv().buffer(), 0, cur.lastpit() + 1, inset->getText(0)->setLayout(0, cur.lastpit() + 1,
bp.documentClass().plainLayoutName()); bp.documentClass().plainLayoutName());
cur.pop(); cur.pop();
} }

View File

@ -153,7 +153,7 @@ Dimension const InsetText::dimension(BufferView const & bv) const
void InsetText::write(ostream & os) const void InsetText::write(ostream & os) const
{ {
os << "Text\n"; os << "Text\n";
text_.write(buffer(), os); text_.write(os);
} }
@ -166,7 +166,7 @@ void InsetText::read(Lexer & lex)
paragraphs().clear(); paragraphs().clear();
ErrorList errorList; ErrorList errorList;
lex.setContext("InsetText::read"); lex.setContext("InsetText::read");
bool res = text_.read(buffer(), lex, errorList, this); bool res = text_.read(lex, errorList, this);
if (!res) if (!res)
lex.printError("Missing \\end_inset at this point. "); lex.printError("Missing \\end_inset at this point. ");

View File

@ -81,7 +81,7 @@ void InsetMathMBox::write(WriteStream & ws) const
} else { } else {
ws << "\\mbox{\n"; ws << "\\mbox{\n";
ostringstream os; ostringstream os;
text_.text().write(buffer(), os); text_.text().write(os);
ws.os() << from_utf8(os.str()); ws.os() << from_utf8(os.str());
ws << "}"; ws << "}";
} }

View File

@ -333,7 +333,7 @@ ParagraphList::const_iterator TeXOnePar(Buffer const & buf,
runparams.moving_arg |= style.needprotect; runparams.moving_arg |= style.needprotect;
bool const maintext = text.isMainText(buf); bool const maintext = text.isMainText();
// we are at the beginning of an inset and CJK is already open; // we are at the beginning of an inset and CJK is already open;
// we count inheritation levels to get the inset nesting right. // we count inheritation levels to get the inset nesting right.
if (pit == paragraphs.begin() && !maintext if (pit == paragraphs.begin() && !maintext
@ -798,7 +798,7 @@ void latexParagraphs(Buffer const & buf,
const_cast<OutputParams&>(runparams).par_end = 0; const_cast<OutputParams&>(runparams).par_end = 0;
} }
bool const maintext = text.isMainText(buf); bool const maintext = text.isMainText();
bool const is_child = buf.masterBuffer() != &buf; bool const is_child = buf.masterBuffer() != &buf;
// Open a CJK environment at the beginning of the main buffer // Open a CJK environment at the beginning of the main buffer

View File

@ -76,7 +76,7 @@ RowPainter::RowPainter(PainterInfo & pi,
FontInfo RowPainter::labelFont() const FontInfo RowPainter::labelFont() const
{ {
return text_.labelFont(pi_.base.bv->buffer(), par_); return text_.labelFont(par_);
} }
@ -393,7 +393,7 @@ void RowPainter::paintChangeBar()
void RowPainter::paintAppendix() void RowPainter::paintAppendix()
{ {
// only draw the appendix frame once (for the main text) // only draw the appendix frame once (for the main text)
if (!par_.params().appendix() || !text_.isMainText(pi_.base.bv->buffer())) if (!par_.params().appendix() || !text_.isMainText())
return; return;
int y = yo_ - row_.ascent(); int y = yo_ - row_.ascent();
@ -433,7 +433,7 @@ void RowPainter::paintDepthBar()
int const w = nestMargin() / 5; int const w = nestMargin() / 5;
int x = int(xo_) + w * i; int x = int(xo_) + w * i;
// only consider the changebar space if we're drawing outermost text // only consider the changebar space if we're drawing outermost text
if (text_.isMainText(pi_.base.bv->buffer())) if (text_.isMainText())
x += changebarMargin(); x += changebarMargin();
int const starty = yo_ - row_.ascent(); int const starty = yo_ - row_.ascent();
@ -503,7 +503,7 @@ void RowPainter::paintFirst()
} }
} }
bool const is_rtl = text_.isRTL(buffer, par_); bool const is_rtl = text_.isRTL(par_);
bool const is_seq = isFirstInSequence(pit_, text_.paragraphs()); bool const is_seq = isFirstInSequence(pit_, text_.paragraphs());
//lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << endl; //lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << endl;
@ -596,7 +596,7 @@ void RowPainter::paintFirst()
void RowPainter::paintLast() void RowPainter::paintLast()
{ {
bool const is_rtl = text_.isRTL(pi_.base.bv->buffer(), par_); bool const is_rtl = text_.isRTL(par_);
int const endlabel = getEndLabel(pit_, text_.paragraphs()); int const endlabel = getEndLabel(pit_, text_.paragraphs());
// paint imaginary end-of-paragraph character // paint imaginary end-of-paragraph character