+2003-03-08 John Levon <levon@movementarian.org>
+
+ * lyxrow.C:
+ * paragraph.C:
+ * paragraph.h:
+ * rowpainter.C:
+ * text.C:
+ * text2.C: Remove the "main" bit from the "main body"
+ notion.
+
2003-03-08 John Levon <levon@movementarian.org>
* text.C (leftMargin): The left margin of an empty
int Row::numberOfSeparators() const
{
pos_type const last = lastPrintablePos();
- pos_type p = max(pos(), par()->beginningOfMainBody());
+ pos_type p = max(pos(), par()->beginningOfBody());
int n = 0;
for (; p <= last; ++p) {
}
}
- first = max(first, par()->beginningOfMainBody());
+ first = max(first, par()->beginningOfBody());
int n = 0;
++first;
}
- last = min(last, par()->beginningOfMainBody());
+ last = min(last, par()->beginningOfBody());
int n = 0;
// last, because the end is ignored!
// in some labels it does not count
if (par()->layout()->margintype != MARGIN_MANUAL
- && pos < par()->beginningOfMainBody())
+ && pos < par()->beginningOfBody())
return false;
// if there is anything between the first char of the row and
LyXLayout_ptr const & lout = layout();
- pos_type const main_body = beginningOfMainBody();
+ pos_type const body_pos = beginningOfBody();
LyXFont layoutfont;
- if (pos < main_body)
+ if (pos < body_pos)
layoutfont = lout->labelfont;
else
layoutfont = lout->font;
}
-// if the layout of a paragraph contains a manual label, the beginning of the
-// main body is the beginning of the second word. This is what the par-
-// function returns. If the layout does not contain a label, the main
-// body always starts with position 0. This differentiation is necessary,
-// because there cannot be a newline or a blank <= the beginning of the
-// main body in TeX.
-
-int Paragraph::beginningOfMainBody() const
+int Paragraph::beginningOfBody() const
{
if (layout()->labeltype != LABEL_MANUAL)
return 0;
LyXFont basefont;
// Maybe we have to create a optional argument.
- pos_type main_body;
+ pos_type body_pos;
// FIXME: can we actually skip this check and just call
- // beginningOfMainBody() ??
+ // beginningOfBody() ??
if (style->labeltype != LABEL_MANUAL) {
- main_body = 0;
+ body_pos = 0;
} else {
- main_body = beginningOfMainBody();
+ body_pos = beginningOfBody();
}
unsigned int column = 0;
- if (main_body > 0) {
+ if (body_pos > 0) {
os << '[';
++column;
basefont = getLabelFont(bparams);
for (pos_type i = 0; i < size(); ++i) {
++column;
// First char in paragraph or after label?
- if (i == main_body) {
- if (main_body > 0) {
+ if (i == body_pos) {
+ if (body_pos > 0) {
if (open_font) {
column += running_font.latexWriteEndChanges(os, basefont, basefont);
open_font = false;
{
column += running_font.latexWriteEndChanges(os,
basefont,
- (i == main_body-1) ? basefont : font);
+ (i == body_pos-1) ? basefont : font);
running_font = basefont;
open_font = false;
}
// Blanks are printed before start of fontswitch
if (c == ' ') {
// Do not print the separation of the optional argument
- if (i != main_body - 1) {
+ if (i != body_pos - 1) {
pimpl_->simpleTeXBlanks(os, texrow, i,
column, font, *style);
}
// Do we need to change font?
if ((font != running_font ||
font.language() != running_font.language()) &&
- i != main_body - 1)
+ i != body_pos - 1)
{
column += font.latexWriteStartChanges(os, basefont,
last_font);
}
// Needed if there is an optional argument but no contents.
- if (main_body > 0 && main_body == size()) {
+ if (body_pos > 0 && body_pos == size()) {
os << "]~";
return_value = false;
}
Paragraph * outerHook();
///
Paragraph const * outerHook() const;
- ///
- int beginningOfMainBody() const;
+
+ /// Paragraphs can contain "manual labels", for example, Description environment.
+ /// The text for this user-editable label is stored in the paragraph alongside
+ /// the text of the rest of the paragraph (the body). This function returns
+ /// the starting position of the body of the text in the paragraph.
+ int beginningOfBody() const;
+
///
string const & getLabelstring() const;
if ((startrow != row && !is_rtl) || (endrow != row && is_rtl))
pain_.fillRectangle(xo_, yo_, int(x_), row_.height(), LColor::selection);
- pos_type const main_body = par_.beginningOfMainBody();
+ pos_type const body_pos = par_.beginningOfBody();
pos_type const last = row_.lastPrintablePos();
float tmpx = x_;
for (pos_type vpos = row_.pos(); vpos <= last; ++vpos) {
pos_type pos = text_.vis2log(vpos);
float const old_tmpx = tmpx;
- if (main_body > 0 && pos == main_body - 1) {
+ if (body_pos > 0 && pos == body_pos - 1) {
LyXLayout_ptr const & layout = par_.layout();
LyXFont const lfont = getLabelFont();
tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
- if (par_.isLineSeparator(main_body - 1))
- tmpx -= singleWidth(main_body - 1);
+ if (par_.isLineSeparator(body_pos - 1))
+ tmpx -= singleWidth(body_pos - 1);
}
if (row_.hfillExpansion(pos)) {
tmpx += singleWidth(pos);
- if (pos >= main_body)
+ if (pos >= body_pos)
tmpx += hfill_;
else
tmpx += label_hfill_;
else if (par_.isSeparator(pos)) {
tmpx += singleWidth(pos);
- if (pos >= main_body)
+ if (pos >= body_pos)
tmpx += separator_;
} else {
tmpx += singleWidth(pos);
bool RowPainter::paintText()
{
pos_type const last = row_.lastPrintablePos();
- pos_type main_body = par_.beginningOfMainBody();
- if (main_body > 0 &&
- (main_body - 1 > last ||
- !par_.isLineSeparator(main_body - 1))) {
- main_body = 0;
+ pos_type body_pos = par_.beginningOfBody();
+ if (body_pos > 0 &&
+ (body_pos - 1 > last ||
+ !par_.isLineSeparator(body_pos - 1))) {
+ body_pos = 0;
}
LyXLayout_ptr const & layout = par_.layout();
running_strikeout = false;
}
- if (main_body > 0 && pos == main_body - 1) {
+ if (body_pos > 0 && pos == body_pos - 1) {
int const lwidth = font_metrics::width(layout->labelsep,
getLabelFont());
x_ += label_hfill_ + lwidth
- - singleWidth(main_body - 1);
+ - singleWidth(body_pos - 1);
}
if (par_.isHfill(pos)) {
if (row_.hfillExpansion(pos)) {
int const y2 = (y0 + y1) / 2;
- if (pos >= main_body) {
+ if (pos >= body_pos) {
pain_.line(int(x_), y2,
int(x_ + hfill_), y2,
LColor::added_space,
++vpos;
} else if (par_.isSeparator(pos)) {
x_ += singleWidth(pos);
- if (pos >= main_body)
+ if (pos >= body_pos)
x_ += separator_;
++vpos;
} else {
int level = 0;
bool rtl = false;
bool rtl0 = false;
- pos_type const main_body = row->par()->beginningOfMainBody();
+ pos_type const body_pos = row->par()->beginningOfBody();
for (pos_type lpos = bidi_start; lpos <= bidi_end; ++lpos) {
bool is_space = row->par()->isLineSeparator(lpos);
bool new_rtl0 = font.isRightToLeft();
int new_level;
- if (lpos == main_body - 1
- && row->pos() < main_body - 1
+ if (lpos == body_pos - 1
+ && row->pos() < body_pos - 1
&& is_space) {
new_level = (rtl_par) ? 1 : 0;
new_rtl = new_rtl0 = rtl_par;
case MARGIN_MANUAL:
x += font_metrics::signedWidth(layout->labelindent, labelfont);
// The width of an empty par, even with manual label, should be 0
- if (!row->par()->empty() && row->pos() >= row->par()->beginningOfMainBody()) {
+ if (!row->par()->empty() && row->pos() >= row->par()->beginningOfBody()) {
if (!row->par()->getLabelWidthString().empty()) {
x += font_metrics::width(row->par()->getLabelWidthString(),
labelfont);
break;
case MARGIN_FIRST_DYNAMIC:
if (layout->labeltype == LABEL_MANUAL) {
- if (row->pos() >= row->par()->beginningOfMainBody()) {
+ if (row->pos() >= row->par()->beginningOfBody()) {
x += font_metrics::signedWidth(layout->leftmargin,
labelfont);
} else {
if (row.par()->layout()->margintype == MARGIN_MANUAL) {
Row tmprow = row;
tmprow.pos(row.par()->size());
- // just the beginning of the main body
+ // return the beginning of the body
return leftMargin(&bview, &tmprow);
}
pos_type last_separator = -1;
width -= rightMargin(*bview->buffer(), *row);
- pos_type const main_body = par->beginningOfMainBody();
+ pos_type const body_pos = par->beginningOfBody();
LyXLayout_ptr const & layout = par->layout();
pos_type i = pos;
if (in->display() &&
(layout->isCommand() ||
(layout->labeltype == LABEL_MANUAL
- && i < par->beginningOfMainBody())))
+ && i < par->beginningOfBody())))
{
// display istn't allowd
in->display(false);
x += singleWidth(bview, par, i, c);
}
++i;
- if (i == main_body) {
+ if (i == body_pos) {
x += font_metrics::width(layout->labelsep,
getLabelFont(bview->buffer(), par));
if (par->isLineSeparator(i - 1))
}
// manual labels cannot be broken in LaTeX, do not care
- if (main_body && last_separator < main_body)
- last_separator = main_body - 1;
+ if (body_pos && last_separator < body_pos)
+ last_separator = body_pos - 1;
return last_separator;
}
Paragraph * par = row.par();
LyXLayout_ptr const & layout = par->layout();
- pos_type const main_body = par->beginningOfMainBody();
+ pos_type const body_pos = par->beginningOfBody();
pos_type i = row.pos();
while (i <= last) {
- if (main_body > 0 && i == main_body) {
+ if (body_pos > 0 && i == body_pos) {
w += font_metrics::width(layout->labelsep, getLabelFont(bview.buffer(), par));
if (par->isLineSeparator(i - 1))
w -= singleWidth(&bview, par, i - 1);
w += singleWidth(&bview, par, i);
++i;
}
- if (main_body > 0 && main_body > last) {
+ if (body_pos > 0 && body_pos > last) {
w += font_metrics::width(layout->labelsep, getLabelFont(bview.buffer(), par));
if (last >= 0 && par->isLineSeparator(last))
w -= singleWidth(&bview, par, last);
// returns the minimum space a manual label needs on the screen in pixel
int LyXText::labelFill(BufferView & bview, Row const & row) const
{
- pos_type last = row.par()->beginningOfMainBody();
+ pos_type last = row.par()->beginningOfBody();
lyx::Assert(last > 0);
return;
}
} else if (IsNewlineChar(c)) {
- if (cursor.pos() <= cursor.par()->beginningOfMainBody()) {
+ if (cursor.pos() <= cursor.par()->beginningOfBody()) {
charInserted();
return;
}
nlh = row->numberOfLabelHfills();
// A manual label par (e.g. List) has an auto-hfill
- // between the label text and the "main body" of the
+ // between the label text and the body of the
// paragraph too.
// But we don't want to do this auto hfill if the par
// is empty.
- if (row->par()->size())
+ if (!row->par()->empty())
++nlh;
if (nlh && !row->par()->getLabelWidthString().empty()) {
computeBidiTables(bview->buffer(), row);
if (is_rtl) {
- pos_type main_body = row->par()->beginningOfMainBody();
+ pos_type body_pos = row->par()->beginningOfBody();
pos_type last = row->lastPos();
- if (main_body > 0 &&
- (main_body - 1 > last ||
- !row->par()->isLineSeparator(main_body - 1))) {
+ if (body_pos > 0 &&
+ (body_pos - 1 > last ||
+ !row->par()->isLineSeparator(body_pos - 1))) {
x += font_metrics::width(layout->labelsep,
getLabelFont(bview->buffer(), row->par()));
- if (main_body - 1 <= last)
+ if (body_pos - 1 <= last)
x += fill_label_hfill;
}
}
// delete newlines at the beginning of paragraphs
while (!cursor.par()->empty() &&
cursor.par()->isNewline(cursor.pos()) &&
- cursor.pos() == cursor.par()->beginningOfMainBody()) {
+ cursor.pos() == cursor.par()->beginningOfBody()) {
cursor.par()->erase(cursor.pos());
// refresh the positions
tmprow = row;
bool left_side = false;
- pos_type main_body = row->par()->beginningOfMainBody();
+ pos_type body_pos = row->par()->beginningOfBody();
float last_tmpx = tmpx;
- if (main_body > 0 &&
- (main_body - 1 > last ||
- !row->par()->isLineSeparator(main_body - 1)))
- main_body = 0;
+ if (body_pos > 0 &&
+ (body_pos - 1 > last ||
+ !row->par()->isLineSeparator(body_pos - 1)))
+ body_pos = 0;
// check for empty row
if (!row->par()->size()) {
while (vc <= last && tmpx <= x) {
c = vis2log(vc);
last_tmpx = tmpx;
- if (main_body > 0 && c == main_body-1) {
+ if (body_pos > 0 && c == body_pos-1) {
tmpx += fill_label_hfill +
font_metrics::width(layout->labelsep,
getLabelFont(bview->buffer(), row->par()));
- if (row->par()->isLineSeparator(main_body - 1))
- tmpx -= singleWidth(bview, row->par(), main_body-1);
+ if (row->par()->isLineSeparator(body_pos - 1))
+ tmpx -= singleWidth(bview, row->par(), body_pos-1);
}
if (row->hfillExpansion(c)) {
tmpx += singleWidth(bview, row->par(), c);
- if (c >= main_body)
+ if (c >= body_pos)
tmpx += fill_hfill;
else
tmpx += fill_label_hfill;
} else if (row->par()->isSeparator(c)) {
tmpx += singleWidth(bview, row->par(), c);
- if (c >= main_body)
+ if (c >= body_pos)
tmpx+= fill_separator;
} else {
tmpx += singleWidth(bview, row->par(), c);
// We specialize the 95% common case:
if (!par->getDepth()) {
if (layout->labeltype == LABEL_MANUAL
- && pos < par->beginningOfMainBody()) {
+ && pos < par->beginningOfBody()) {
// 1% goes here
LyXFont f = par->getFontSettings(buf->params, pos);
if (par->inInset())
LyXFont layoutfont;
- if (pos < par->beginningOfMainBody()) {
+ if (pos < par->beginningOfBody()) {
// 1% goes here
layoutfont = layout->labelfont;
} else {
// Get concrete layout font to reduce against
LyXFont layoutfont;
- if (pos < par->beginningOfMainBody())
+ if (pos < par->beginningOfBody())
layoutfont = layout->labelfont;
else
layoutfont = layout->font;
LyXFont layoutfont;
for (pos_type pos = 0; pos < par.size(); ++pos) {
- if (pos < par.beginningOfMainBody())
+ if (pos < par.beginningOfBody())
layoutfont = layout->labelfont;
else
layoutfont = layout->font;
if (!selection.set()) {
// Determine basis font
LyXFont layoutfont;
- if (cursor.pos() < cursor.par()->beginningOfMainBody()) {
+ if (cursor.pos() < cursor.par()->beginningOfBody()) {
layoutfont = getLabelFont(bview->buffer(),
cursor.par());
} else {
cursor_vpos = (bidi_level(pos) % 2 == 0)
? log2vis(pos) : log2vis(pos) + 1;
- pos_type main_body = row->par()->beginningOfMainBody();
- if ((main_body > 0) &&
- ((main_body-1 > last) ||
- !row->par()->isLineSeparator(main_body-1)))
- main_body = 0;
+ pos_type body_pos = row->par()->beginningOfBody();
+ if ((body_pos > 0) &&
+ ((body_pos-1 > last) ||
+ !row->par()->isLineSeparator(body_pos-1)))
+ body_pos = 0;
for (pos_type vpos = row->pos(); vpos < cursor_vpos; ++vpos) {
pos_type pos = vis2log(vpos);
- if (main_body > 0 && pos == main_body - 1) {
+ if (body_pos > 0 && pos == body_pos - 1) {
x += fill_label_hfill +
font_metrics::width(
row->par()->layout()->labelsep,
getLabelFont(bview->buffer(),
row->par()));
- if (row->par()->isLineSeparator(main_body - 1))
+ if (row->par()->isLineSeparator(body_pos - 1))
x -= singleWidth(bview,
- row->par(), main_body - 1);
+ row->par(), body_pos - 1);
}
if (row->hfillExpansion(pos)) {
x += singleWidth(bview, row->par(), pos);
- if (pos >= main_body)
+ if (pos >= body_pos)
x += fill_hfill;
else
x += fill_label_hfill;
} else if (row->par()->isSeparator(pos)) {
x += singleWidth(bview, row->par(), pos);
- if (pos >= main_body)
+ if (pos >= body_pos)
x += fill_separator;
} else
x += singleWidth(bview, row->par(), pos);