* Layout.h

- leftMargin, rightMargin, labelsep, labelindent, parindent are now docstring.

* TextClass.h:
- leftMargin() and rightMargin(): now return a docstring.

All other files: adapt to change above.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19633 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2007-08-18 13:21:12 +00:00
parent 2f751fe117
commit 98008dc568
8 changed files with 59 additions and 84 deletions

View File

@ -375,22 +375,22 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
case LT_LEFTMARGIN: // left margin type case LT_LEFTMARGIN: // left margin type
if (lexrc.next()) if (lexrc.next())
leftmargin = lexrc.getString(); leftmargin = lexrc.getDocString();
break; break;
case LT_RIGHTMARGIN: // right margin type case LT_RIGHTMARGIN: // right margin type
if (lexrc.next()) if (lexrc.next())
rightmargin = lexrc.getString(); rightmargin = lexrc.getDocString();
break; break;
case LT_LABELINDENT: // label indenting flag case LT_LABELINDENT: // label indenting flag
if (lexrc.next()) if (lexrc.next())
labelindent = lexrc.getString(); labelindent = lexrc.getDocString();
break; break;
case LT_PARINDENT: // paragraph indent. flag case LT_PARINDENT: // paragraph indent. flag
if (lexrc.next()) if (lexrc.next())
parindent = lexrc.getString(); parindent = lexrc.getDocString();
break; break;
case LT_PARSKIP: // paragraph skip size case LT_PARSKIP: // paragraph skip size
@ -420,7 +420,7 @@ bool Layout::read(Lexer & lexrc, TextClass const & tclass)
case LT_LABELSEP: // label separator case LT_LABELSEP: // label separator
if (lexrc.next()) { if (lexrc.next()) {
labelsep = subst(lexrc.getString(), 'x', ' '); labelsep = from_utf8(subst(lexrc.getString(), 'x', ' '));
} }
break; break;

View File

@ -250,15 +250,15 @@ public:
Font reslabelfont; Font reslabelfont;
/// Text that dictates how wide the left margin is on the screen /// Text that dictates how wide the left margin is on the screen
std::string leftmargin; docstring leftmargin;
/// Text that dictates how wide the right margin is on the screen /// Text that dictates how wide the right margin is on the screen
std::string rightmargin; docstring rightmargin;
/// Text that dictates how much space to leave after a potential label /// Text that dictates how much space to leave after a potential label
std::string labelsep; docstring labelsep;
/// Text that dictates how much space to leave before a potential label /// Text that dictates how much space to leave before a potential label
std::string labelindent; docstring labelindent;
/// Text that dictates the width of the indentation of indented pars /// Text that dictates the width of the indentation of indented pars
std::string parindent; docstring parindent;
/// ///
double parskip; double parskip;
/// ///

View File

@ -179,13 +179,11 @@ int ParagraphMetrics::rightMargin(Buffer const & buffer) const
{ {
BufferParams const & params = buffer.params(); BufferParams const & params = buffer.params();
TextClass const & tclass = params.getTextClass(); TextClass const & tclass = params.getTextClass();
docstring trmarg = from_utf8(tclass.rightmargin());
docstring lrmarg = from_utf8(par_->layout()->rightmargin);
frontend::FontMetrics const & fm = theFontMetrics(params.getFont()); frontend::FontMetrics const & fm = theFontMetrics(params.getFont());
int const r_margin = int const r_margin =
lyx::rightMargin() lyx::rightMargin()
+ fm.signedWidth(trmarg) + fm.signedWidth(tclass.rightmargin())
+ fm.signedWidth(lrmarg) + fm.signedWidth(par_->layout()->rightmargin)
* 4 / (par_->getDepth() + 4); * 4 / (par_->getDepth() + 4);
return r_margin; return r_margin;

View File

@ -416,16 +416,15 @@ int Text::leftMargin(Buffer const & buffer, int max_width,
TextClass const & tclass = buffer.params().getTextClass(); TextClass const & tclass = buffer.params().getTextClass();
Layout_ptr const & layout = par.layout(); Layout_ptr const & layout = par.layout();
string parindent = layout->parindent; docstring parindent = layout->parindent;
int l_margin = 0; int l_margin = 0;
if (isMainText(buffer)) if (isMainText(buffer))
l_margin += changebarMargin(); l_margin += changebarMargin();
// FIXME UNICODE l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(
docstring leftm = from_utf8(tclass.leftmargin()); tclass.leftmargin());
l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(leftm);
if (par.getDepth() != 0) { if (par.getDepth() != 0) {
// find the next level paragraph // find the next level paragraph
@ -456,55 +455,41 @@ int Text::leftMargin(Buffer const & buffer, int max_width,
switch (layout->margintype) { switch (layout->margintype) {
case MARGIN_DYNAMIC: case MARGIN_DYNAMIC:
if (!layout->leftmargin.empty()) { if (!layout->leftmargin.empty()) {
// FIXME UNICODE l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(
docstring leftm = from_utf8(layout->leftmargin); layout->leftmargin);
l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(leftm);
} }
if (!par.getLabelstring().empty()) { if (!par.getLabelstring().empty()) {
// FIXME UNICODE l_margin += labelfont_metrics.signedWidth(layout->labelindent);
docstring labin = from_utf8(layout->labelindent); l_margin += labelfont_metrics.width(par.getLabelstring());
l_margin += labelfont_metrics.signedWidth(labin); l_margin += labelfont_metrics.width(layout->labelsep);
docstring labstr = par.getLabelstring();
l_margin += labelfont_metrics.width(labstr);
docstring labsep = from_utf8(layout->labelsep);
l_margin += labelfont_metrics.width(labsep);
} }
break; break;
case MARGIN_MANUAL: { case MARGIN_MANUAL: {
// FIXME UNICODE l_margin += labelfont_metrics.signedWidth(layout->labelindent);
docstring labin = from_utf8(layout->labelindent);
l_margin += labelfont_metrics.signedWidth(labin);
// The width of an empty par, even with manual label, should be 0 // The width of an empty par, even with manual label, should be 0
if (!par.empty() && pos >= par.beginOfBody()) { if (!par.empty() && pos >= par.beginOfBody()) {
if (!par.getLabelWidthString().empty()) { if (!par.getLabelWidthString().empty()) {
docstring labstr = par.getLabelWidthString(); docstring labstr = par.getLabelWidthString();
l_margin += labelfont_metrics.width(labstr); l_margin += labelfont_metrics.width(labstr);
docstring labsep = from_utf8(layout->labelsep); l_margin += labelfont_metrics.width(layout->labelsep);
l_margin += labelfont_metrics.width(labsep);
} }
} }
break; break;
} }
case MARGIN_STATIC: { case MARGIN_STATIC: {
// FIXME UNICODE l_margin += theFontMetrics(buffer.params().getFont()).
docstring leftm = from_utf8(layout->leftmargin); signedWidth(layout->leftmargin) * 4 / (par.getDepth() + 4);
l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(leftm)
* 4 / (par.getDepth() + 4);
break; break;
} }
case MARGIN_FIRST_DYNAMIC: case MARGIN_FIRST_DYNAMIC:
if (layout->labeltype == LABEL_MANUAL) { if (layout->labeltype == LABEL_MANUAL) {
if (pos >= par.beginOfBody()) { if (pos >= par.beginOfBody()) {
// FIXME UNICODE l_margin += labelfont_metrics.signedWidth(layout->leftmargin);
l_margin += labelfont_metrics.signedWidth(
from_utf8(layout->leftmargin));
} else { } else {
// FIXME UNICODE l_margin += labelfont_metrics.signedWidth(layout->labelindent);
l_margin += labelfont_metrics.signedWidth(
from_utf8(layout->labelindent));
} }
} else if (pos != 0 } else if (pos != 0
// Special case to fix problems with // Special case to fix problems with
@ -512,14 +497,13 @@ int Text::leftMargin(Buffer const & buffer, int max_width,
|| (layout->labeltype == LABEL_STATIC || (layout->labeltype == LABEL_STATIC
&& layout->latextype == LATEX_ENVIRONMENT && layout->latextype == LATEX_ENVIRONMENT
&& !isFirstInSequence(pit, pars_))) { && !isFirstInSequence(pit, pars_))) {
// FIXME UNICODE l_margin += labelfont_metrics.signedWidth(layout->leftmargin);
l_margin += labelfont_metrics.signedWidth(from_utf8(layout->leftmargin));
} else if (layout->labeltype != LABEL_TOP_ENVIRONMENT } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
&& layout->labeltype != LABEL_BIBLIO && layout->labeltype != LABEL_BIBLIO
&& layout->labeltype != && layout->labeltype !=
LABEL_CENTERED_TOP_ENVIRONMENT) { LABEL_CENTERED_TOP_ENVIRONMENT) {
l_margin += labelfont_metrics.signedWidth(from_utf8(layout->labelindent)); l_margin += labelfont_metrics.signedWidth(layout->labelindent);
l_margin += labelfont_metrics.width(from_utf8(layout->labelsep)); l_margin += labelfont_metrics.width(layout->labelsep);
l_margin += labelfont_metrics.width(par.getLabelstring()); l_margin += labelfont_metrics.width(par.getLabelstring());
} }
break; break;
@ -574,8 +558,8 @@ int Text::leftMargin(Buffer const & buffer, int max_width,
|| buffer.params().paragraph_separation == || buffer.params().paragraph_separation ==
BufferParams::PARSEP_INDENT)) BufferParams::PARSEP_INDENT))
{ {
docstring din = from_utf8(parindent); l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(
l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(din); parindent);
} }
return l_margin; return l_margin;
@ -1749,8 +1733,6 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
// Use font span to speed things up, see below // Use font span to speed things up, see below
FontSpan font_span; FontSpan font_span;
Font font; Font font;
FontMetrics const & labelfm = theFontMetrics(
getLabelFont(buffer, par));
// If the last logical character is a separator, skip it, unless // If the last logical character is a separator, skip it, unless
// it's in the last row of a paragraph; see skipped_sep_vpos declaration // it's in the last row of a paragraph; see skipped_sep_vpos declaration
@ -1763,9 +1745,9 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
continue; continue;
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) {
// FIXME UNICODE FontMetrics const & labelfm = theFontMetrics(
docstring const lsep = from_utf8(par.layout()->labelsep); getLabelFont(buffer, par));
x += m.label_hfill + labelfm.width(lsep); x += m.label_hfill + labelfm.width(par.layout()->labelsep);
if (par.isLineSeparator(body_pos - 1)) if (par.isLineSeparator(body_pos - 1))
x -= singleWidth(buffer, par, body_pos - 1); x -= singleWidth(buffer, par, body_pos - 1);
} }

View File

@ -398,12 +398,12 @@ bool TextClass::read(FileName const & filename, bool merge)
case TC_LEFTMARGIN: // left margin type case TC_LEFTMARGIN: // left margin type
if (lexrc.next()) if (lexrc.next())
leftmargin_ = lexrc.getString(); leftmargin_ = lexrc.getDocString();
break; break;
case TC_RIGHTMARGIN: // right margin type case TC_RIGHTMARGIN: // right margin type
if (lexrc.next()) if (lexrc.next())
rightmargin_ = lexrc.getString(); rightmargin_ = lexrc.getDocString();
break; break;
case TC_INSETLAYOUT: case TC_INSETLAYOUT:
if (lexrc.next()) { if (lexrc.next()) {
@ -903,13 +903,13 @@ Font const & TextClass::defaultfont() const
} }
string const & TextClass::leftmargin() const docstring const & TextClass::leftmargin() const
{ {
return leftmargin_; return leftmargin_;
} }
string const & TextClass::rightmargin() const docstring const & TextClass::rightmargin() const
{ {
return rightmargin_; return rightmargin_;
} }

View File

@ -163,10 +163,10 @@ public:
Font const & defaultfont() const; Font const & defaultfont() const;
/// Text that dictates how wide the left margin is on the screen /// Text that dictates how wide the left margin is on the screen
std::string const & leftmargin() const; docstring const & leftmargin() const;
/// Text that dictates how wide the right margin is on the screen /// Text that dictates how wide the right margin is on the screen
std::string const & rightmargin() const; docstring const & rightmargin() const;
/// The type of command used to produce a title /// The type of command used to produce a title
LYX_TITLE_LATEX_TYPES titletype() const; LYX_TITLE_LATEX_TYPES titletype() const;
@ -225,10 +225,10 @@ private:
*/ */
Font defaultfont_; Font defaultfont_;
/// Text that dictates how wide the left margin is on the screen /// Text that dictates how wide the left margin is on the screen
std::string leftmargin_; docstring leftmargin_;
/// Text that dictates how wide the right margin is on the screen /// Text that dictates how wide the right margin is on the screen
std::string rightmargin_; docstring rightmargin_;
/// The type of command used to produce a title /// The type of command used to produce a title
LYX_TITLE_LATEX_TYPES titletype_; LYX_TITLE_LATEX_TYPES titletype_;

View File

@ -385,8 +385,8 @@ RowMetrics 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)))
{ {
docstring const lsep = from_utf8(layout->labelsep); result.x += theFontMetrics(text_->getLabelFont(buffer, par)).
result.x += theFontMetrics(text_->getLabelFont(buffer, par)).width(lsep); width(layout->labelsep);
if (body_pos <= end) if (body_pos <= end)
result.x += result.label_hfill; result.x += result.label_hfill;
} }
@ -493,15 +493,15 @@ void TextMetrics::rowBreakPoint(int width, pit_type const pit,
FontIterator fi = FontIterator(buffer, *text_, par, pos); FontIterator fi = FontIterator(buffer, *text_, par, pos);
pos_type point = end; pos_type point = end;
pos_type i = pos; pos_type i = pos;
FontMetrics const & fm = theFontMetrics(text_->getLabelFont(buffer, par));
for ( ; i < end; ++i, ++fi) { for ( ; i < end; ++i, ++fi) {
char_type const c = par.getChar(i); char_type const c = par.getChar(i);
int thiswidth = text_->singleWidth(par, i, c, *fi); int thiswidth = text_->singleWidth(par, i, c, *fi);
// 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) {
docstring lsep = from_utf8(layout->labelsep); FontMetrics const & fm = theFontMetrics(
int add = fm.width(lsep); text_->getLabelFont(buffer, par));
int add = fm.width(layout->labelsep);
if (par.isLineSeparator(i - 1)) if (par.isLineSeparator(i - 1))
add -= text_->singleWidth(buffer, par, i - 1); add -= text_->singleWidth(buffer, par, i - 1);
@ -576,20 +576,19 @@ void TextMetrics::setRowWidth(int right_margin,
pos_type const end = row.endpos(); pos_type const end = row.endpos();
Paragraph const & par = text_->getPar(pit); Paragraph const & par = text_->getPar(pit);
docstring const labelsep = from_utf8(par.layout()->labelsep);
int w = text_->leftMargin(buffer, max_width_, pit, row.pos()); int w = text_->leftMargin(buffer, max_width_, pit, row.pos());
int label_end = labelEnd(pit); int label_end = labelEnd(pit);
pos_type const body_pos = par.beginOfBody(); pos_type const body_pos = par.beginOfBody();
pos_type i = row.pos(); pos_type i = row.pos();
FontMetrics const & fm = theFontMetrics(text_->getLabelFont(buffer, par));
if (i < end) { if (i < end) {
FontIterator fi = FontIterator(buffer, *text_, par, i); FontIterator fi = FontIterator(buffer, *text_, par, i);
for ( ; i < end; ++i, ++fi) { for ( ; i < end; ++i, ++fi) {
if (body_pos > 0 && i == body_pos) { if (body_pos > 0 && i == body_pos) {
w += fm.width(labelsep); FontMetrics const & fm = theFontMetrics(
text_->getLabelFont(buffer, par));
w += fm.width(par.layout()->labelsep);
if (par.isLineSeparator(i - 1)) if (par.isLineSeparator(i - 1))
w -= text_->singleWidth(buffer, par, i - 1); w -= text_->singleWidth(buffer, par, i - 1);
w = max(w, label_end); w = max(w, label_end);
@ -600,7 +599,9 @@ void TextMetrics::setRowWidth(int right_margin,
} }
if (body_pos > 0 && body_pos >= end) { if (body_pos > 0 && body_pos >= end) {
w += fm.width(labelsep); FontMetrics const & fm = theFontMetrics(
text_->getLabelFont(buffer, par));
w += fm.width(par.layout()->labelsep);
if (end > 0 && par.isLineSeparator(end - 1)) if (end > 0 && par.isLineSeparator(end - 1))
w -= text_->singleWidth(buffer, par, end - 1); w -= text_->singleWidth(buffer, par, end - 1);
w = max(w, label_end); w = max(w, label_end);
@ -842,16 +843,13 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
return 0; return 0;
} }
frontend::FontMetrics const & fm
= theFontMetrics(text_->getLabelFont(buffer, par));
while (vc < end && tmpx <= x) { while (vc < end && tmpx <= x) {
c = bidi.vis2log(vc); c = bidi.vis2log(vc);
last_tmpx = tmpx; last_tmpx = tmpx;
if (body_pos > 0 && c == body_pos - 1) { if (body_pos > 0 && c == body_pos - 1) {
// FIXME UNICODE FontMetrics const & fm = theFontMetrics(
docstring const lsep = from_utf8(layout->labelsep); text_->getLabelFont(buffer, par));
tmpx += r.label_hfill + fm.width(lsep); tmpx += r.label_hfill + fm.width(layout->labelsep);
if (par.isLineSeparator(body_pos - 1)) if (par.isLineSeparator(body_pos - 1))
tmpx -= text_->singleWidth(buffer, par, body_pos - 1); tmpx -= text_->singleWidth(buffer, par, body_pos - 1);
} }

View File

@ -623,13 +623,11 @@ void RowPainter::paintFirst()
pain_.text(int(x), yo_ - maxdesc - labeladdon, str, font); pain_.text(int(x), yo_ - maxdesc - labeladdon, str, font);
} else { } else {
// FIXME UNICODE
docstring lab = from_utf8(layout->labelsep);
if (is_rtl) { if (is_rtl) {
x = width_ - leftMargin() x = width_ - leftMargin()
+ fm.width(lab); + fm.width(layout->labelsep);
} else { } else {
x = x_ - fm.width(lab) x = x_ - fm.width(layout->labelsep)
- fm.width(str); - fm.width(str);
} }
@ -818,9 +816,8 @@ void RowPainter::paintText()
} }
if (body_pos > 0 && pos == body_pos - 1) { if (body_pos > 0 && pos == body_pos - 1) {
// FIXME UNICODE
int const lwidth = theFontMetrics(getLabelFont()) int const lwidth = theFontMetrics(getLabelFont())
.width(from_utf8(layout->labelsep)); .width(layout->labelsep);
x_ += label_hfill_ + lwidth - width_pos; x_ += label_hfill_ + lwidth - width_pos;
} }