mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
* Text:
- singleWidth(Buffer...): transfered to TextMetrics. - singleWidth(Paragraph...): transfered to ParagraphMetrics. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19639 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
861e1e4dc5
commit
f91f682ef9
@ -189,4 +189,32 @@ int ParagraphMetrics::rightMargin(Buffer const & buffer) const
|
|||||||
return r_margin;
|
return r_margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ParagraphMetrics::singleWidth(pos_type pos, Font const & font) const
|
||||||
|
{
|
||||||
|
char_type c = par_->getChar(pos);
|
||||||
|
|
||||||
|
// The most special cases are handled first.
|
||||||
|
if (c == Paragraph::META_INSET)
|
||||||
|
return par_->getInset(pos)->width();
|
||||||
|
|
||||||
|
if (!isPrintable(c))
|
||||||
|
return theFontMetrics(font).width(c);
|
||||||
|
|
||||||
|
Language const * language = font.language();
|
||||||
|
if (language->rightToLeft()) {
|
||||||
|
if (language->lang() == "arabic_arabtex" ||
|
||||||
|
language->lang() == "arabic_arabi" ||
|
||||||
|
language->lang() == "farsi") {
|
||||||
|
if (Encodings::isComposeChar_arabic(c))
|
||||||
|
return 0;
|
||||||
|
c = par_->transformChar(c, pos);
|
||||||
|
} else if (language->lang() == "hebrew" &&
|
||||||
|
Encodings::isComposeChar_hebrew(c))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return theFontMetrics(font).width(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
@ -74,6 +74,8 @@ public:
|
|||||||
void updateRowChangeStatus();
|
void updateRowChangeStatus();
|
||||||
///
|
///
|
||||||
int rightMargin(Buffer const & buffer) const;
|
int rightMargin(Buffer const & buffer) const;
|
||||||
|
///
|
||||||
|
int singleWidth(pos_type pos, Font const & Font) const;
|
||||||
|
|
||||||
/// dump some information to lyxerr
|
/// dump some information to lyxerr
|
||||||
void dump() const;
|
void dump() const;
|
||||||
|
43
src/Text.cpp
43
src/Text.cpp
@ -361,41 +361,6 @@ double Text::spacing(Buffer const & buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Text::singleWidth(Buffer const & buffer, Paragraph const & par,
|
|
||||||
pos_type pos) const
|
|
||||||
{
|
|
||||||
return singleWidth(par, pos, par.getChar(pos),
|
|
||||||
getFont(buffer, par, pos));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Text::singleWidth(Paragraph const & par,
|
|
||||||
pos_type pos, char_type c, Font const & font) const
|
|
||||||
{
|
|
||||||
// The most common case is handled first (Asger)
|
|
||||||
if (isPrintable(c)) {
|
|
||||||
Language const * language = font.language();
|
|
||||||
if (language->rightToLeft()) {
|
|
||||||
if (language->lang() == "arabic_arabtex" ||
|
|
||||||
language->lang() == "arabic_arabi" ||
|
|
||||||
language->lang() == "farsi") {
|
|
||||||
if (Encodings::isComposeChar_arabic(c))
|
|
||||||
return 0;
|
|
||||||
c = par.transformChar(c, pos);
|
|
||||||
} else if (language->lang() == "hebrew" &&
|
|
||||||
Encodings::isComposeChar_hebrew(c))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return theFontMetrics(font).width(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c == Paragraph::META_INSET)
|
|
||||||
return par.getInset(pos)->width();
|
|
||||||
|
|
||||||
return theFontMetrics(font).width(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int Text::leftMargin(Buffer const & buffer, int max_width, pit_type pit) const
|
int Text::leftMargin(Buffer const & buffer, int max_width, pit_type pit) const
|
||||||
{
|
{
|
||||||
BOOST_ASSERT(pit >= 0);
|
BOOST_ASSERT(pit >= 0);
|
||||||
@ -1749,7 +1714,7 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
|
|||||||
getLabelFont(buffer, par));
|
getLabelFont(buffer, par));
|
||||||
x += m.label_hfill + labelfm.width(par.layout()->labelsep);
|
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 -= tm.singleWidth(pit, body_pos - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use font span to speed things up, see above
|
// Use font span to speed things up, see above
|
||||||
@ -1758,7 +1723,7 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
|
|||||||
font = getFont(buffer, par, pos);
|
font = getFont(buffer, par, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
x += singleWidth(par, pos, par.getChar(pos), font);
|
x += pm.singleWidth(pos, font);
|
||||||
|
|
||||||
if (par.hfillExpansion(row, pos))
|
if (par.hfillExpansion(row, pos))
|
||||||
x += (pos >= body_pos) ? m.hfill : m.label_hfill;
|
x += (pos >= body_pos) ? m.hfill : m.label_hfill;
|
||||||
@ -1769,9 +1734,9 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
|
|||||||
// see correction above
|
// see correction above
|
||||||
if (boundary_correction) {
|
if (boundary_correction) {
|
||||||
if (isRTL(buffer, sl, boundary))
|
if (isRTL(buffer, sl, boundary))
|
||||||
x -= singleWidth(buffer, par, ppos);
|
x -= tm.singleWidth(pit, ppos);
|
||||||
else
|
else
|
||||||
x += singleWidth(buffer, par, ppos);
|
x += tm.singleWidth(pit, ppos);
|
||||||
}
|
}
|
||||||
|
|
||||||
return int(x);
|
return int(x);
|
||||||
|
@ -295,15 +295,6 @@ public:
|
|||||||
/// \sa BufferView::getCoveringInset() to get the innermost inset.
|
/// \sa BufferView::getCoveringInset() to get the innermost inset.
|
||||||
Inset * checkInsetHit(BufferView &, int x, int y);
|
Inset * checkInsetHit(BufferView &, int x, int y);
|
||||||
|
|
||||||
///
|
|
||||||
/// FIXME: move to TextMetrics.
|
|
||||||
int singleWidth(Buffer const &, Paragraph const & par,
|
|
||||||
pos_type pos) const;
|
|
||||||
///
|
|
||||||
/// FIXME: move to TextMetrics.
|
|
||||||
int singleWidth(Paragraph const & par, pos_type pos, char_type c,
|
|
||||||
Font const & Font) const;
|
|
||||||
|
|
||||||
/// return the color of the canvas
|
/// return the color of the canvas
|
||||||
Color_color backgroundColor() const;
|
Color_color backgroundColor() const;
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
|
|||||||
++nlh;
|
++nlh;
|
||||||
|
|
||||||
if (nlh && !par.getLabelWidthString().empty())
|
if (nlh && !par.getLabelWidthString().empty())
|
||||||
result.label_hfill = labelFill(par, row) / double(nlh);
|
result.label_hfill = labelFill(pit, row) / double(nlh);
|
||||||
}
|
}
|
||||||
|
|
||||||
// are there any hfills in the row?
|
// are there any hfills in the row?
|
||||||
@ -395,9 +395,10 @@ RowMetrics TextMetrics::computeRowMetrics(pit_type const pit,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int TextMetrics::labelFill(Paragraph const & par, Row const & row) const
|
int TextMetrics::labelFill(pit_type const pit, Row const & row) const
|
||||||
{
|
{
|
||||||
Buffer & buffer = *bv_->buffer();
|
Buffer & buffer = *bv_->buffer();
|
||||||
|
Paragraph const & par = text_->getPar(pit);
|
||||||
|
|
||||||
pos_type last = par.beginOfBody();
|
pos_type last = par.beginOfBody();
|
||||||
BOOST_ASSERT(last > 0);
|
BOOST_ASSERT(last > 0);
|
||||||
@ -411,7 +412,7 @@ int TextMetrics::labelFill(Paragraph const & par, Row const & row) const
|
|||||||
|
|
||||||
int w = 0;
|
int w = 0;
|
||||||
for (pos_type i = row.pos(); i <= last; ++i)
|
for (pos_type i = row.pos(); i <= last; ++i)
|
||||||
w += text_->singleWidth(buffer, par, i);
|
w += singleWidth(pit, i);
|
||||||
|
|
||||||
docstring const & label = par.params().labelWidthString();
|
docstring const & label = par.params().labelWidthString();
|
||||||
if (label.empty())
|
if (label.empty())
|
||||||
@ -455,6 +456,7 @@ void TextMetrics::rowBreakPoint(int width, pit_type const pit,
|
|||||||
Row & row) const
|
Row & row) const
|
||||||
{
|
{
|
||||||
Buffer & buffer = *bv_->buffer();
|
Buffer & buffer = *bv_->buffer();
|
||||||
|
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();
|
||||||
pos_type const pos = row.pos();
|
pos_type const pos = row.pos();
|
||||||
@ -493,8 +495,7 @@ void TextMetrics::rowBreakPoint(int width, pit_type const pit,
|
|||||||
pos_type point = end;
|
pos_type point = end;
|
||||||
pos_type i = pos;
|
pos_type i = pos;
|
||||||
for ( ; i < end; ++i, ++fi) {
|
for ( ; i < end; ++i, ++fi) {
|
||||||
char_type const c = par.getChar(i);
|
int thiswidth = pm.singleWidth(i, *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) {
|
||||||
@ -502,7 +503,7 @@ void TextMetrics::rowBreakPoint(int width, pit_type const pit,
|
|||||||
text_->getLabelFont(buffer, par));
|
text_->getLabelFont(buffer, par));
|
||||||
int add = fm.width(layout->labelsep);
|
int add = fm.width(layout->labelsep);
|
||||||
if (par.isLineSeparator(i - 1))
|
if (par.isLineSeparator(i - 1))
|
||||||
add -= text_->singleWidth(buffer, par, i - 1);
|
add -= singleWidth(pit, i - 1);
|
||||||
|
|
||||||
add = std::max(add, label_end - x);
|
add = std::max(add, label_end - x);
|
||||||
thiswidth += add;
|
thiswidth += add;
|
||||||
@ -573,7 +574,7 @@ void TextMetrics::setRowWidth(int right_margin,
|
|||||||
Buffer & buffer = *bv_->buffer();
|
Buffer & buffer = *bv_->buffer();
|
||||||
// get the pure distance
|
// get the pure distance
|
||||||
pos_type const end = row.endpos();
|
pos_type const end = row.endpos();
|
||||||
|
ParagraphMetrics const & pm = par_metrics_[pit];
|
||||||
Paragraph const & par = text_->getPar(pit);
|
Paragraph const & par = text_->getPar(pit);
|
||||||
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);
|
||||||
@ -589,11 +590,10 @@ void TextMetrics::setRowWidth(int right_margin,
|
|||||||
text_->getLabelFont(buffer, par));
|
text_->getLabelFont(buffer, par));
|
||||||
w += fm.width(par.layout()->labelsep);
|
w += fm.width(par.layout()->labelsep);
|
||||||
if (par.isLineSeparator(i - 1))
|
if (par.isLineSeparator(i - 1))
|
||||||
w -= text_->singleWidth(buffer, par, i - 1);
|
w -= singleWidth(pit, i - 1);
|
||||||
w = max(w, label_end);
|
w = max(w, label_end);
|
||||||
}
|
}
|
||||||
char_type const c = par.getChar(i);
|
w += pm.singleWidth(i, *fi);
|
||||||
w += text_->singleWidth(par, i, c, *fi);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -602,7 +602,7 @@ void TextMetrics::setRowWidth(int right_margin,
|
|||||||
text_->getLabelFont(buffer, par));
|
text_->getLabelFont(buffer, 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 -= text_->singleWidth(buffer, par, end - 1);
|
w -= singleWidth(pit, end - 1);
|
||||||
w = max(w, label_end);
|
w = max(w, label_end);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -850,21 +850,21 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
|
|||||||
text_->getLabelFont(buffer, par));
|
text_->getLabelFont(buffer, par));
|
||||||
tmpx += r.label_hfill + fm.width(layout->labelsep);
|
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 -= singleWidth(pit, body_pos - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (par.hfillExpansion(row, c)) {
|
if (par.hfillExpansion(row, c)) {
|
||||||
tmpx += text_->singleWidth(buffer, par, c);
|
tmpx += singleWidth(pit, c);
|
||||||
if (c >= body_pos)
|
if (c >= body_pos)
|
||||||
tmpx += r.hfill;
|
tmpx += r.hfill;
|
||||||
else
|
else
|
||||||
tmpx += r.label_hfill;
|
tmpx += r.label_hfill;
|
||||||
} else if (par.isSeparator(c)) {
|
} else if (par.isSeparator(c)) {
|
||||||
tmpx += text_->singleWidth(buffer, par, c);
|
tmpx += singleWidth(pit, c);
|
||||||
if (c >= body_pos)
|
if (c >= body_pos)
|
||||||
tmpx += r.separator;
|
tmpx += r.separator;
|
||||||
} else {
|
} else {
|
||||||
tmpx += text_->singleWidth(buffer, par, c);
|
tmpx += singleWidth(pit, c);
|
||||||
}
|
}
|
||||||
++vc;
|
++vc;
|
||||||
}
|
}
|
||||||
@ -911,9 +911,9 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
|
|||||||
// Newline inset, air gap below:
|
// Newline inset, air gap below:
|
||||||
if (row.pos() < end && c >= end && par.isNewline(end - 1)) {
|
if (row.pos() < end && c >= end && par.isNewline(end - 1)) {
|
||||||
if (bidi.level(end -1) % 2 == 0)
|
if (bidi.level(end -1) % 2 == 0)
|
||||||
tmpx -= text_->singleWidth(buffer, par, end - 1);
|
tmpx -= singleWidth(pit, end - 1);
|
||||||
else
|
else
|
||||||
tmpx += text_->singleWidth(buffer, par, end - 1);
|
tmpx += singleWidth(pit, end - 1);
|
||||||
c = end - 1;
|
c = end - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -955,6 +955,15 @@ pos_type TextMetrics::x2pos(pit_type pit, int row, int x) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int TextMetrics::singleWidth(pit_type pit, pos_type pos) const
|
||||||
|
{
|
||||||
|
Buffer const & buffer = *bv_->buffer();
|
||||||
|
ParagraphMetrics const & pm = par_metrics_[pit];
|
||||||
|
|
||||||
|
return pm.singleWidth(pos, text_->getFont(buffer, text_->getPar(pit), pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//int Text::pos2x(pit_type pit, pos_type pos) const
|
//int Text::pos2x(pit_type pit, pos_type pos) const
|
||||||
//{
|
//{
|
||||||
// ParagraphMetrics const & pm = par_metrics_[pit];
|
// ParagraphMetrics const & pm = par_metrics_[pit];
|
||||||
|
@ -62,6 +62,8 @@ public:
|
|||||||
|
|
||||||
///
|
///
|
||||||
int maxWidth() const { return max_width_; }
|
int maxWidth() const { return max_width_; }
|
||||||
|
///
|
||||||
|
int singleWidth(pit_type const pit, pos_type pos) const;
|
||||||
|
|
||||||
///
|
///
|
||||||
int rightMargin(ParagraphMetrics const & pm) const;
|
int rightMargin(ParagraphMetrics const & pm) const;
|
||||||
@ -77,7 +79,7 @@ private:
|
|||||||
ParagraphMetrics & parMetrics(pit_type, bool redo_paragraph);
|
ParagraphMetrics & parMetrics(pit_type, bool redo_paragraph);
|
||||||
|
|
||||||
/// the minimum space a manual label needs on the screen in pixels
|
/// the minimum space a manual label needs on the screen in pixels
|
||||||
int labelFill(Paragraph const & par, Row const & row) const;
|
int labelFill(pit_type const pit, Row const & row) const;
|
||||||
|
|
||||||
/// FIXME??
|
/// FIXME??
|
||||||
int labelEnd(pit_type const pit) const;
|
int labelEnd(pit_type const pit) const;
|
||||||
|
@ -256,7 +256,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos, Font const & font)
|
|||||||
c = par_.getChar(i);
|
c = par_.getChar(i);
|
||||||
if (!Encodings::isComposeChar_hebrew(c)) {
|
if (!Encodings::isComposeChar_hebrew(c)) {
|
||||||
if (isPrintableNonspace(c)) {
|
if (isPrintableNonspace(c)) {
|
||||||
int const width2 = text_.singleWidth(par_, i, c,
|
int const width2 = pm_.singleWidth(i,
|
||||||
text_.getFont(*bv_.buffer(), par_, i));
|
text_.getFont(*bv_.buffer(), par_, i));
|
||||||
dx = (c == 0x05e8 || // resh
|
dx = (c == 0x05e8 || // resh
|
||||||
c == 0x05d3) // dalet
|
c == 0x05d3) // dalet
|
||||||
@ -290,7 +290,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos, Font const & font)
|
|||||||
c = par_.getChar(i);
|
c = par_.getChar(i);
|
||||||
if (!Encodings::isComposeChar_arabic(c)) {
|
if (!Encodings::isComposeChar_arabic(c)) {
|
||||||
if (isPrintableNonspace(c)) {
|
if (isPrintableNonspace(c)) {
|
||||||
int const width2 = text_.singleWidth(par_, i, c,
|
int const width2 = pm_.singleWidth(i,
|
||||||
text_.getFont(*bv_.buffer(), par_, i));
|
text_.getFont(*bv_.buffer(), par_, i));
|
||||||
dx = (width2 - width) / 2;
|
dx = (width2 - width) / 2;
|
||||||
}
|
}
|
||||||
@ -784,8 +784,7 @@ void RowPainter::paintText()
|
|||||||
font = text_.getFont(buffer, par_, vpos);
|
font = text_.getFont(buffer, par_, vpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
const int width_pos =
|
const int width_pos = pm_.singleWidth(pos, font);
|
||||||
text_.singleWidth(par_, pos, par_.getChar(pos), font);
|
|
||||||
|
|
||||||
if (x_ + width_pos < 0) {
|
if (x_ + width_pos < 0) {
|
||||||
x_ += width_pos;
|
x_ += width_pos;
|
||||||
|
Loading…
Reference in New Issue
Block a user