API cosmetics

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23295 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2008-02-27 23:03:26 +00:00
parent 3c5f43af7d
commit 1cca0a86bd
12 changed files with 66 additions and 67 deletions

View File

@ -768,7 +768,7 @@ void BufferView::showCursor(DocIterator const & dit)
else if (bot_pit == tm.last().first + 1)
tm.newParMetricsDown();
if (tm.has(bot_pit)) {
if (tm.contains(bot_pit)) {
ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
BOOST_ASSERT(!pm.rows().empty());
// FIXME: smooth scrolling doesn't work in mathed.
@ -1995,7 +1995,7 @@ Point BufferView::getPos(DocIterator const & dit, bool boundary) const
{
CursorSlice const & bot = dit.bottom();
TextMetrics const & tm = textMetrics(bot.text());
if (!tm.has(bot.pit()))
if (!tm.contains(bot.pit()))
return Point(-1, -1);
Point p = coordOffset(dit, boundary); // offset from outer paragraph

View File

@ -1825,7 +1825,7 @@ void Cursor::setCurrentFont()
// get font
BufferParams const & bufparams = buffer().params();
current_font = par.getFontSettings(bufparams, cpos);
real_current_font = tm.getDisplayFont(cpit, cpos);
real_current_font = tm.displayFont(cpit, cpos);
// special case for paragraph end
if (cs.pos() == lastpos()

View File

@ -23,7 +23,7 @@ namespace lyx {
FontIterator::FontIterator(TextMetrics const & tm,
Paragraph const & par, pit_type pit, pos_type pos)
: tm_(tm), par_(par), pit_(pit), pos_(pos),
font_(tm.getDisplayFont(pit, pos)),
font_(tm.displayFont(pit, pos)),
endspan_(par.fontSpan(pos).last),
bodypos_(par.beginOfBody())
{}
@ -45,7 +45,7 @@ FontIterator & FontIterator::operator++()
{
++pos_;
if (pos_ > endspan_ || pos_ == bodypos_) {
font_ = tm_.getDisplayFont(pit_, pos_);
font_ = tm_.displayFont(pit_, pos_);
endspan_ = par_.fontSpan(pos_).last;
}
return *this;

View File

@ -450,8 +450,8 @@ void Text::insertChar(Cursor & cur, char_type c)
!(contains(number_seperators, c) &&
cur.pos() != 0 &&
cur.pos() != cur.lastpos() &&
tm.getDisplayFont(pit, cur.pos()).fontInfo().number() == FONT_ON &&
tm.getDisplayFont(pit, cur.pos() - 1).fontInfo().number() == FONT_ON)
tm.displayFont(pit, cur.pos()).fontInfo().number() == FONT_ON &&
tm.displayFont(pit, cur.pos() - 1).fontInfo().number() == FONT_ON)
)
number(cur); // Set current_font.number to OFF
} else if (isDigit(c) &&
@ -469,7 +469,7 @@ void Text::insertChar(Cursor & cur, char_type c)
tm.font_);
} else if (contains(number_seperators, c)
&& cur.pos() >= 2
&& tm.getDisplayFont(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,
tm.font_);
}
@ -502,7 +502,7 @@ void Text::insertChar(Cursor & cur, char_type c)
if ((cur.pos() >= 2) && (par.isLineSeparator(cur.pos() - 1))) {
// get font in front and behind the space in question. But do NOT
// use getFont(cur.pos()) because the character c is not inserted yet
Font const pre_space_font = tm.getDisplayFont(cur.pit(), cur.pos() - 2);
Font const pre_space_font = tm.displayFont(cur.pit(), cur.pos() - 2);
Font const & post_space_font = cur.real_current_font;
bool pre_space_rtl = pre_space_font.isVisibleRightToLeft();
bool post_space_rtl = post_space_font.isVisibleRightToLeft();
@ -515,7 +515,7 @@ void Text::insertChar(Cursor & cur, char_type c)
(pre_space_rtl == par.isRTL(buffer.params())) ?
pre_space_font.language() : post_space_font.language();
Font space_font = tm.getDisplayFont(cur.pit(), cur.pos() - 1);
Font space_font = tm.displayFont(cur.pit(), cur.pos() - 1);
space_font.setLanguage(lang);
par.setFont(cur.pos() - 1, space_font);
}

View File

@ -48,9 +48,9 @@ public:
bool empty() const;
///
FontInfo getLayoutFont(Buffer const & buffer, pit_type pit) const;
FontInfo layoutFont(Buffer const & buffer, pit_type pit) const;
///
FontInfo getLabelFont(Buffer const & buffer,
FontInfo labelFont(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,
@ -319,4 +319,4 @@ private:
} // namespace lyx
#endif // LYXTEXT_H
#endif // TEXT_H

View File

@ -73,7 +73,7 @@ bool Text::isMainText(Buffer const & buffer) const
}
FontInfo Text::getLayoutFont(Buffer const & buffer, pit_type const pit) const
FontInfo Text::layoutFont(Buffer const & buffer, pit_type const pit) const
{
LayoutPtr const & layout = pars_[pit].layout();
@ -94,7 +94,7 @@ FontInfo Text::getLayoutFont(Buffer const & buffer, pit_type const pit) const
}
FontInfo Text::getLabelFont(Buffer const & buffer, Paragraph const & par) const
FontInfo Text::labelFont(Buffer const & buffer, Paragraph const & par) const
{
LayoutPtr const & layout = par.layout();
@ -308,9 +308,9 @@ void Text::setFont(Cursor & cur, Font const & font, bool toggleall)
FontInfo layoutfont;
pit_type pit = cur.pit();
if (cur.pos() < pars_[pit].beginOfBody())
layoutfont = getLabelFont(cur.buffer(), pars_[pit]);
layoutfont = labelFont(cur.buffer(), pars_[pit]);
else
layoutfont = getLayoutFont(cur.buffer(), pit);
layoutfont = layoutFont(cur.buffer(), pit);
// Update current font
cur.real_current_font.update(font,
@ -360,7 +360,7 @@ void Text::setFont(BufferView const & bv, CursorSlice const & begin,
setInsetFont(bv, pit, pos, font, toggleall);
}
TextMetrics const & tm = bv.textMetrics(this);
Font f = tm.getDisplayFont(pit, pos);
Font f = tm.displayFont(pit, pos);
f.update(font, language, toggleall);
setCharFont(buffer, pit, pos, f, tm.font_);
}
@ -526,7 +526,7 @@ bool Text::setCursor(Cursor & cur, pit_type par, pos_type pos,
bool setfont, bool boundary)
{
TextMetrics const & tm = cur.bv().textMetrics(this);
bool const update_needed = !tm.has(par);
bool const update_needed = !tm.contains(par);
Cursor old = cur;
setCursorIntern(cur, par, pos, setfont, boundary);
return cur.bv().checkDepm(cur, old) || update_needed;

View File

@ -387,7 +387,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
BufferView * bv = &cur.bv();
TextMetrics & tm = bv->textMetrics(this);
if (!tm.has(cur.pit()))
if (!tm.contains(cur.pit()))
lyx::dispatch(FuncRequest(LFUN_SCREEN_RECENTER));
// FIXME: We use the update flag to indicates wether a singlePar or a

View File

@ -128,7 +128,7 @@ TextMetrics::TextMetrics(BufferView * bv, Text * text)
}
bool TextMetrics::has(pit_type pit) const
bool TextMetrics::contains(pit_type pit) const
{
return par_metrics_.find(pit) != par_metrics_.end();
}
@ -241,7 +241,7 @@ void TextMetrics::applyOuterFont(Font & font) const
}
Font TextMetrics::getDisplayFont(pit_type pit, pos_type pos) const
Font TextMetrics::displayFont(pit_type pit, pos_type pos) const
{
BOOST_ASSERT(pos >= 0);
@ -302,7 +302,7 @@ bool TextMetrics::isRTL(CursorSlice const & sl, bool boundary) const
if (boundary && sl.pos() > 0)
correction = -1;
return getDisplayFont(sl.pit(), sl.pos() + correction).isVisibleRightToLeft();
return displayFont(sl.pit(), sl.pos() + correction).isVisibleRightToLeft();
}
@ -317,12 +317,12 @@ bool TextMetrics::isRTLBoundary(pit_type pit, pos_type pos) const
Paragraph const & par = text_->getPar(pit);
bool left = getDisplayFont(pit, pos - 1).isVisibleRightToLeft();
bool left = displayFont(pit, pos - 1).isVisibleRightToLeft();
bool right;
if (pos == par.size())
right = par.isRTL(bv_->buffer().params());
else
right = getDisplayFont(pit, pos).isVisibleRightToLeft();
right = displayFont(pit, pos).isVisibleRightToLeft();
return left != right;
}
@ -339,7 +339,7 @@ bool TextMetrics::isRTLBoundary(pit_type pit, pos_type pos,
if (pos == par.size())
right = par.isRTL(bv_->buffer().params());
else
right = getDisplayFont(pit, pos).isVisibleRightToLeft();
right = displayFont(pit, pos).isVisibleRightToLeft();
return left != right;
}
@ -414,7 +414,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
int const w = max_width_ - leftMargin(max_width_, pit, ii->pos)
- right_margin;
Font const & font = ii->inset->noFontChange() ?
bufferfont : getDisplayFont(pit, ii->pos);
bufferfont : displayFont(pit, ii->pos);
MacroContext mc(buffer, parPos);
MetricsInfo mi(bv_, font.fontInfo(), w, mc);
ii->inset->metrics(mi, dim);
@ -627,7 +627,7 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
if (body_pos > 0
&& (body_pos > end || !par.isLineSeparator(body_pos - 1)))
{
row.x += theFontMetrics(text_->getLabelFont(buffer, par)).
row.x += theFontMetrics(text_->labelFont(buffer, par)).
width(layout->labelsep);
if (body_pos <= end)
row.x += row.label_hfill;
@ -684,7 +684,7 @@ int TextMetrics::labelFill(pit_type const pit, Row const & row) const
return 0;
FontMetrics const & fm
= theFontMetrics(text_->getLabelFont(buffer, par));
= theFontMetrics(text_->labelFont(buffer, par));
return max(0, fm.width(label) - w);
}
@ -767,7 +767,7 @@ pit_type TextMetrics::rowBreakPoint(int width, pit_type const pit,
// add the auto-hfill from label end to the body
if (body_pos && i == body_pos) {
FontMetrics const & fm = theFontMetrics(
text_->getLabelFont(buffer, par));
text_->labelFont(buffer, par));
int add = fm.width(layout->labelsep);
if (par.isLineSeparator(i - 1))
add -= singleWidth(pit, i - 1);
@ -864,7 +864,7 @@ int TextMetrics::rowWidth(int right_margin, pit_type const pit,
for ( ; i < end; ++i, ++fi) {
if (body_pos > 0 && i == body_pos) {
FontMetrics const & fm = theFontMetrics(
text_->getLabelFont(buffer, par));
text_->labelFont(buffer, par));
w += fm.width(par.layout()->labelsep);
if (par.isLineSeparator(i - 1))
w -= singleWidth(pit, i - 1);
@ -883,7 +883,7 @@ int TextMetrics::rowWidth(int right_margin, pit_type const pit,
if (body_pos > 0 && body_pos >= end) {
FontMetrics const & fm = theFontMetrics(
text_->getLabelFont(buffer, par));
text_->labelFont(buffer, par));
w += fm.width(par.layout()->labelsep);
if (end > 0 && par.isLineSeparator(end - 1))
w -= singleWidth(pit, end - 1);
@ -913,13 +913,13 @@ Dimension TextMetrics::rowHeight(pit_type const pit, pos_type const first,
// start with so we don't have to do the assignment below too
// often.
Buffer const & buffer = bv_->buffer();
Font font = getDisplayFont(pit, first);
Font font = displayFont(pit, first);
FontSize const tmpsize = font.fontInfo().size();
font.fontInfo() = text_->getLayoutFont(buffer, pit);
font.fontInfo() = text_->layoutFont(buffer, pit);
FontSize const size = font.fontInfo().size();
font.fontInfo().setSize(tmpsize);
FontInfo labelfont = text_->getLabelFont(buffer, par);
FontInfo labelfont = text_->labelFont(buffer, par);
FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
FontMetrics const & fontmetrics = theFontMetrics(font);
@ -1129,7 +1129,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
last_tmpx = tmpx;
if (body_pos > 0 && c == body_pos - 1) {
FontMetrics const & fm = theFontMetrics(
text_->getLabelFont(buffer, par));
text_->labelFont(buffer, par));
tmpx += row.label_hfill + fm.width(layout->labelsep);
if (par.isLineSeparator(body_pos - 1))
tmpx -= singleWidth(pit, body_pos - 1);
@ -1550,7 +1550,7 @@ int TextMetrics::cursorX(CursorSlice const & sl,
// Inline completion RTL special case row_pos == cursor_pos:
// "__|b" => cursor_pos is right of __
if (row_pos == inlineCompletionVPos && row_pos == cursor_vpos) {
font = getDisplayFont(pit, row_pos + 1);
font = displayFont(pit, row_pos + 1);
docstring const & completion = bv_->inlineCompletion();
if (font.isRightToLeft() && completion.length() > 0)
x += theFontMetrics(font.fontInfo()).width(completion);
@ -1563,7 +1563,7 @@ int TextMetrics::cursorX(CursorSlice const & sl,
pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) {
FontMetrics const & labelfm = theFontMetrics(
text_->getLabelFont(buffer, par));
text_->labelFont(buffer, par));
x += row.label_hfill + labelfm.width(par.layout()->labelsep);
if (par.isLineSeparator(body_pos - 1))
x -= singleWidth(pit, body_pos - 1);
@ -1572,7 +1572,7 @@ int TextMetrics::cursorX(CursorSlice const & sl,
// Use font span to speed things up, see above
if (pos < font_span.first || pos > font_span.last) {
font_span = par.fontSpan(pos);
font = getDisplayFont(pit, pos);
font = displayFont(pit, pos);
}
x += pm.singleWidth(pos, font);
@ -1581,7 +1581,7 @@ int TextMetrics::cursorX(CursorSlice const & sl,
// "a__|b", __ of b => non-boundary a-pos is right of __
if (vpos + 1 == inlineCompletionVPos
&& (vpos + 1 < cursor_vpos || !boundary_correction)) {
font = getDisplayFont(pit, vpos + 1);
font = displayFont(pit, vpos + 1);
docstring const & completion = bv_->inlineCompletion();
if (font.isRightToLeft() && completion.length() > 0)
x += theFontMetrics(font.fontInfo()).width(completion);
@ -1591,7 +1591,7 @@ int TextMetrics::cursorX(CursorSlice const & sl,
// "b|__a", __ of b => non-boundary a-pos is in front of __
if (vpos == inlineCompletionVPos
&& (vpos + 1 < cursor_vpos || boundary_correction)) {
font = getDisplayFont(pit, vpos);
font = displayFont(pit, vpos);
docstring const & completion = bv_->inlineCompletion();
if (!font.isRightToLeft() && completion.length() > 0)
x += theFontMetrics(font.fontInfo()).width(completion);
@ -1801,7 +1801,7 @@ int TextMetrics::leftMargin(int max_width,
&& pit > 0 && pars[pit - 1].layout()->nextnoindent)
parindent.erase();
FontInfo const labelfont = text_->getLabelFont(buffer, par);
FontInfo const labelfont = text_->labelFont(buffer, par);
FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
switch (layout->margintype) {
@ -1922,7 +1922,7 @@ int TextMetrics::singleWidth(pit_type pit, pos_type pos) const
{
ParagraphMetrics const & pm = par_metrics_[pit];
return pm.singleWidth(pos, getDisplayFont(pit, pos));
return pm.singleWidth(pos, displayFont(pit, pos));
}

View File

@ -38,7 +38,7 @@ public:
TextMetrics(BufferView *, Text *);
///
bool has(pit_type pit) const;
bool contains(pit_type pit) const;
///
ParagraphMetrics const & parMetrics(pit_type) const;
///
@ -68,8 +68,7 @@ public:
/// The difference is that this one is used for displaying, and thus we
/// are allowed to make cosmetic improvements. For instance make footnotes
/// smaller. (Asger)
Font getDisplayFont(pit_type pit,
pos_type pos) const;
Font displayFont(pit_type pit, pos_type pos) const;
/// There are currently two font mechanisms in LyX:
/// 1. The font attributes in a lyxtext, and

View File

@ -345,7 +345,7 @@ bool getTokenValue(string const & str, char const * token, string & ret)
{
ret.erase();
size_t token_length = strlen(token);
string::size_type pos = str.find(token);
size_t pos = str.find(token);
if (pos == string::npos || pos + token_length + 1 >= str.length()
|| str[pos + token_length] != '=')
@ -4697,8 +4697,8 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
col_type cols = 1;
row_type rows = 1;
col_type maxCols = 1;
docstring::size_type const len = buf.length();
docstring::size_type p = 0;
size_t const len = buf.length();
size_t p = 0;
while (p < len &&
(p = buf.find_first_of(from_ascii("\t\n"), p)) != docstring::npos) {
@ -4732,7 +4732,7 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
row = tabular.cellRow(cell);
}
docstring::size_type op = 0;
size_t op = 0;
idx_type const cells = loctab->cellCount();
p = 0;
cols = ocol;
@ -4750,7 +4750,7 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
if (cols < columns) {
shared_ptr<InsetText> inset = loctab->getCellInset(cell);
Font const font = bv.textMetrics(&inset->text_).
getDisplayFont(0, 0);
displayFont(0, 0);
inset->setText(buf.substr(op, p - op), font,
buffer().params().trackChanges);
++cols;
@ -4762,7 +4762,7 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
if (cols < columns) {
shared_ptr<InsetText> inset = tabular.getCellInset(cell);
Font const font = bv.textMetrics(&inset->text_).
getDisplayFont(0, 0);
displayFont(0, 0);
inset->setText(buf.substr(op, p - op), font,
buffer().params().trackChanges);
}
@ -4778,7 +4778,7 @@ bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
// check for the last cell if there is no trailing '\n'
if (cell < cells && op < len) {
shared_ptr<InsetText> inset = loctab->getCellInset(cell);
Font const font = bv.textMetrics(&inset->text_).getDisplayFont(0, 0);
Font const font = bv.textMetrics(&inset->text_).displayFont(0, 0);
inset->setText(buf.substr(op, len - op), font,
buffer().params().trackChanges);
}

View File

@ -74,9 +74,9 @@ RowPainter::RowPainter(PainterInfo & pi,
}
FontInfo const RowPainter::getLabelFont() const
FontInfo RowPainter::labelFont() const
{
return text_.getLabelFont(pi_.base.bv->buffer(), par_);
return text_.labelFont(pi_.base.bv->buffer(), par_);
}
@ -93,7 +93,7 @@ int RowPainter::leftMargin() const
void RowPainter::paintInset(Inset const * inset, pos_type const pos)
{
Font const font = text_metrics_.getDisplayFont(pit_, pos);
Font const font = text_metrics_.displayFont(pit_, pos);
BOOST_ASSERT(inset);
// Backup full_repaint status because some insets (InsetTabular)
@ -174,7 +174,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos, FontInfo const & font)
if (!Encodings::isComposeChar_hebrew(c)) {
if (isPrintableNonspace(c)) {
int const width2 = pm_.singleWidth(i,
text_metrics_.getDisplayFont(pit_, i));
text_metrics_.displayFont(pit_, i));
dx = (c == 0x05e8 || // resh
c == 0x05d3) // dalet
? width2 - width
@ -208,7 +208,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos, FontInfo const & font)
if (!Encodings::isComposeChar_arabic(c)) {
if (isPrintableNonspace(c)) {
int const width2 = pm_.singleWidth(i,
text_metrics_.getDisplayFont(pit_, i));
text_metrics_.displayFont(pit_, i));
dx = (width2 - width) / 2;
}
break;
@ -329,7 +329,7 @@ void RowPainter::paintForeignMark(double orig_x, Language const * lang,
void RowPainter::paintFromPos(pos_type & vpos)
{
pos_type const pos = bidi_.vis2log(vpos);
Font const orig_font = text_metrics_.getDisplayFont(pit_, pos);
Font const orig_font = text_metrics_.displayFont(pit_, pos);
double const orig_x = x_;
// usual characters, no insets
@ -502,7 +502,7 @@ void RowPainter::paintFirst()
|| layout->latextype != LATEX_ENVIRONMENT
|| is_seq)) {
FontInfo const font = getLabelFont();
FontInfo const font = labelFont();
FontMetrics const & fm = theFontMetrics(font);
docstring const str = par_.labelString();
@ -550,7 +550,7 @@ void RowPainter::paintFirst()
(layout->labeltype == LABEL_TOP_ENVIRONMENT ||
layout->labeltype == LABEL_BIBLIO ||
layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
FontInfo const font = getLabelFont();
FontInfo const font = labelFont();
docstring const str = par_.labelString();
if (!str.empty()) {
double spacing_val = 1.0;
@ -606,7 +606,7 @@ void RowPainter::paintLast()
switch (endlabel) {
case END_LABEL_BOX:
case END_LABEL_FILLED_BOX: {
FontInfo const font = getLabelFont();
FontInfo const font = labelFont();
FontMetrics const & fm = theFontMetrics(font);
int const size = int(0.75 * fm.maxAscent());
int const y = yo_ - size;
@ -627,7 +627,7 @@ void RowPainter::paintLast()
}
case END_LABEL_STATIC: {
FontInfo const font = getLabelFont();
FontInfo const font = labelFont();
FontMetrics const & fm = theFontMetrics(font);
docstring const & str = par_.layout()->endlabelstring();
double const x = is_rtl ?
@ -721,7 +721,7 @@ void RowPainter::paintText()
// Use font span to speed things up, see above
if (vpos < font_span.first || vpos > font_span.last) {
font_span = par_.fontSpan(vpos);
font = text_metrics_.getDisplayFont(pit_, vpos);
font = text_metrics_.displayFont(pit_, vpos);
// split font span if inline completion is inside
if (font_span.first <= inlineCompletionVPos
@ -761,7 +761,7 @@ void RowPainter::paintText()
}
if (body_pos > 0 && pos == body_pos - 1) {
int const lwidth = theFontMetrics(getLabelFont())
int const lwidth = theFontMetrics(labelFont())
.width(layout->labelsep);
x_ += row_.label_hfill + lwidth - width_pos;
@ -772,7 +772,7 @@ void RowPainter::paintText()
paintInlineCompletion(font);
if (par_.isSeparator(pos)) {
Font const orig_font = text_metrics_.getDisplayFont(pit_, pos);
Font const orig_font = text_metrics_.displayFont(pit_, pos);
double const orig_x = x_;
x_ += width_pos;
if (pos >= body_pos)

View File

@ -69,7 +69,7 @@ private:
int leftMargin() const;
/// return the label font for this row
FontInfo const getLabelFont() const;
FontInfo labelFont() const;
/// contains painting related information.
PainterInfo & pi_;