More unicode conversion

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15355 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2006-10-17 14:46:45 +00:00
parent 5ac136d708
commit 52bd213992
25 changed files with 191 additions and 197 deletions

View File

@ -699,7 +699,8 @@ void LCursor::insert(InsetBase * inset)
void LCursor::niceInsert(string const & t)
{
MathArray ar;
asArray(t, ar);
// FIXME UNICODE
asArray(lyx::from_utf8(t), ar);
if (ar.size() == 1)
niceInsert(ar[0]);
else
@ -720,7 +721,8 @@ void LCursor::niceInsert(MathAtom const & t)
pushLeft(*nextInset());
// We may not use niceInsert here (recursion)
MathArray ar;
asArray(safe, ar);
// FIXME UNICODE
asArray(lyx::from_utf8(safe), ar);
insert(ar);
}
}
@ -879,7 +881,8 @@ void LCursor::handleNest(MathAtom const & a, int c)
{
//lyxerr << "LCursor::handleNest: " << c << endl;
MathAtom t = a;
asArray(lyx::cap::grabAndEraseSelection(*this), t.nucleus()->cell(c));
// FIXME UNICODE
asArray(lyx::from_utf8(lyx::cap::grabAndEraseSelection(*this)), t.nucleus()->cell(c));
insert(t);
posLeft();
pushLeft(*nextInset());

View File

@ -159,20 +159,22 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const
LyXFont msgFont(mi.base.font);
msgFont.setFamily(LyXFont::SANS_FAMILY);
string const justname = onlyFilename(params_.filename);
docstring djust(justname.begin(), justname.end());
// FIXME UNICODE
docstring const justname =
lyx::from_utf8(onlyFilename(params_.filename));
if (!justname.empty()) {
msgFont.setSize(LyXFont::SIZE_FOOTNOTE);
font_width = theFontMetrics(msgFont)
.width(djust);
.width(justname);
}
string const msg = statusMessage(params_, loader_.status());
// FIXME UNICODE
docstring const msg =
lyx::from_utf8(statusMessage(params_, loader_.status()));
if (!msg.empty()) {
docstring dmsg(msg.begin(), msg.end());
msgFont.setSize(LyXFont::SIZE_TINY);
font_width = std::max(font_width,
theFontMetrics(msgFont).width(dmsg));
theFontMetrics(msgFont).width(msg));
}
dim.wid = std::max(50, font_width + 15);

View File

@ -131,9 +131,9 @@ void RenderPreview::metrics(MetricsInfo & mi, Dimension & dim) const
LyXFont font(mi.base.font);
font.setFamily(LyXFont::SANS_FAMILY);
font.setSize(LyXFont::SIZE_FOOTNOTE);
string stat = statusMessage(mi.base.bv, snippet_);
docstring dstat(stat.begin(), stat.end());
dim.wid = 15 + theFontMetrics(font).width(dstat);
// FIXME UNICODE
docstring const stat = lyx::from_utf8(statusMessage(mi.base.bv, snippet_));
dim.wid = 15 + theFontMetrics(font).width(stat);
}
dim_ = dim;
@ -165,11 +165,11 @@ void RenderPreview::draw(PainterInfo & pi, int x, int y) const
font.setFamily(LyXFont::SANS_FAMILY);
font.setSize(LyXFont::SIZE_FOOTNOTE);
string stat = statusMessage(pi.base.bv, snippet_);
docstring dstat(stat.begin(), stat.end());
// FIXME UNICODE
docstring const stat = lyx::from_utf8(statusMessage(pi.base.bv, snippet_));
pi.pain.text(x + offset + 6,
y - theFontMetrics(font).maxAscent() - 4,
dstat, font);
stat, font);
}
}

View File

@ -28,7 +28,8 @@ InsetMathComment::InsetMathComment()
InsetMathComment::InsetMathComment(string const & str)
: InsetMathNest(1)
{
asArray(str, cell(0));
// FIXME UNICODE
asArray(lyx::from_utf8(str), cell(0));
}

View File

@ -41,13 +41,15 @@ auto_ptr<InsetBase> InsetMathExFunc::doClone() const
void InsetMathExFunc::metrics(MetricsInfo & mi, Dimension & /*dim*/) const
{
mathed_string_dim(mi.base.font, name_, dim_);
// FIXME UNICODE
mathed_string_dim(mi.base.font, lyx::from_utf8(name_), dim_);
}
void InsetMathExFunc::draw(PainterInfo & pi, int x, int y) const
{
drawStrBlack(pi, x, y, name_);
// FIXME UNICODE
drawStrBlack(pi, x, y, lyx::from_utf8(name_));
}

View File

@ -51,18 +51,18 @@ void InsetMathFrameBox::draw(PainterInfo & pi, int x, int y) const
dim_.width() - 2, dim_.height() - 2, LColor::foreground);
x += 5;
drawStrBlack(pi, x, y, "[");
drawStrBlack(pi, x, y, lyx::from_ascii("["));
x += w_;
cell(0).draw(pi, x, y);
x += cell(0).width();
drawStrBlack(pi, x, y, "]");
drawStrBlack(pi, x, y, lyx::from_ascii("]"));
x += w_ + 4;
drawStrBlack(pi, x, y, "[");
drawStrBlack(pi, x, y, lyx::from_ascii("["));
x += w_;
cell(1).draw(pi, x, y);
x += cell(1).width();
drawStrBlack(pi, x, y, "]");
drawStrBlack(pi, x, y, lyx::from_ascii("]"));
x += w_ + 4;
cell(2).draw(pi, x, y);

View File

@ -347,9 +347,8 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
for (row_type row = 0; row < nrows(); ++row) {
int const yy = y + rowinfo_[row].offset_;
FontSetChanger dummy(pi.base, "mathrm");
string const nl = nicelabel(row);
docstring const dnl(nl.begin(), nl.end());
pi.draw(xx, yy, dnl);
docstring const nl = nicelabel(row);
pi.draw(xx, yy, nl);
}
}
setPosCache(pi, x, y);
@ -663,13 +662,14 @@ void InsetMathHull::delCol(col_type col)
}
string InsetMathHull::nicelabel(row_type row) const
docstring InsetMathHull::nicelabel(row_type row) const
{
if (nonum_[row])
return string();
return docstring();
if (label_[row].empty())
return string("(#)");
return '(' + label_[row] + ')';
return lyx::from_ascii("(#)");
// FIXME UNICODE
return lyx::from_utf8('(' + label_[row] + ')');
}
@ -980,7 +980,8 @@ void InsetMathHull::doExtern(LCursor & cur, FuncRequest & func)
size_type pos = cur.cell().find_last(eq);
MathArray ar;
if (cur.inMathed() && cur.selection()) {
asArray(grabAndEraseSelection(cur), ar);
// FIXME UNICODE
asArray(lyx::from_utf8(grabAndEraseSelection(cur)), ar);
} else if (pos == cur.cell().size()) {
ar = cur.cell();
lyxerr << "use whole cell: " << ar << endl;

View File

@ -141,7 +141,7 @@ private:
///
void footer_write(WriteStream &) const;
///
std::string nicelabel(row_type row) const;
lyx::docstring nicelabel(row_type row) const;
///
void doExtern(LCursor & cur, FuncRequest & func);
///

View File

@ -60,14 +60,17 @@ void MathMacro::cursorPos(CursorSlice const & sl, bool boundary, int & x,
void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
{
if (!MacroTable::globalMacros().has(name())) {
mathed_string_dim(mi.base.font, "Unknown: " + name(), dim);
mathed_string_dim(mi.base.font, lyx::from_utf8("Unknown: " + name()), dim);
} else if (editing(mi.base.bv)) {
asArray(MacroTable::globalMacros().get(name()).def(), tmpl_);
// FIXME UNICODE
asArray(lyx::from_utf8(MacroTable::globalMacros().get(name()).def()), tmpl_);
LyXFont font = mi.base.font;
augmentFont(font, "lyxtex");
tmpl_.metrics(mi, dim);
dim.wid += mathed_string_width(font, name()) + 10;
int ww = mathed_string_width(font, "#1: ");
// FIXME UNICODE
dim.wid += mathed_string_width(font, lyx::from_utf8(name())) + 10;
// FIXME UNICODE
int ww = mathed_string_width(font, lyx::from_ascii("#1: "));
for (idx_type i = 0; i < nargs(); ++i) {
MathArray const & c = cell(i);
c.metrics(mi);
@ -86,18 +89,20 @@ void MathMacro::metrics(MetricsInfo & mi, Dimension & dim) const
void MathMacro::draw(PainterInfo & pi, int x, int y) const
{
if (!MacroTable::globalMacros().has(name())) {
drawStrRed(pi, x, y, "Unknown: " + name());
// FIXME UNICODE
drawStrRed(pi, x, y, lyx::from_utf8("Unknown: " + name()));
} else if (editing(pi.base.bv)) {
LyXFont font = pi.base.font;
augmentFont(font, "lyxtex");
int h = y - dim_.ascent() + 2 + tmpl_.ascent();
docstring dn(name().begin(), name().end());
// FIXME UNICODE
docstring dn = lyx::from_utf8(name());
pi.pain.text(x + 3, h, dn, font);
int const w = mathed_string_width(font, name());
int const w = mathed_string_width(font, dn);
tmpl_.draw(pi, x + w + 12, h);
h += tmpl_.descent();
Dimension ldim;
mathed_string_dim(font, "#1: ", ldim);
mathed_string_dim(font, lyx::from_ascii("#1: "), ldim);
for (idx_type i = 0; i < nargs(); ++i) {
MathArray const & c = cell(i);
h += max(c.ascent(), ldim.asc) + 5;

View File

@ -50,18 +50,18 @@ void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
FontSetChanger dummy(pi.base, "textnormal");
drawMarkers(pi, x, y);
drawStrBlack(pi, x, y, "[");
drawStrBlack(pi, x, y, lyx::from_ascii("["));
x += w_;
cell(0).draw(pi, x, y);
x += cell(0).width();
drawStrBlack(pi, x, y, "]");
drawStrBlack(pi, x, y, lyx::from_ascii("]"));
x += w_ + 2;
drawStrBlack(pi, x, y, "[");
drawStrBlack(pi, x, y, lyx::from_ascii("["));
x += w_;
cell(1).draw(pi, x, y);
x += cell(1).width();
drawStrBlack(pi, x, y, "]");
drawStrBlack(pi, x, y, lyx::from_ascii("]"));
x += w_ + 2;
cell(2).draw(pi, x, y);

View File

@ -1114,9 +1114,9 @@ void InsetMathNest::lfunMousePress(LCursor & cur, FuncRequest & cmd)
} else if (cmd.button() == mouse_button::button2) {
MathArray ar;
if (cur.selection())
asArray(lyx::to_utf8(bv.cursor().selectionAsString(false)), ar);
asArray(bv.cursor().selectionAsString(false), ar);
else
asArray(lyx::to_utf8(theSelection().get()), ar);
asArray(theSelection().get(), ar);
cur.insert(ar);
bv.mouseSetCursor(cur);

View File

@ -34,14 +34,15 @@ auto_ptr<InsetBase> InsetMathNumber::doClone() const
void InsetMathNumber::metrics(MetricsInfo & mi, Dimension & dim) const
{
mathed_string_dim(mi.base.font, str_, dim);
// FIXME UNICODE
mathed_string_dim(mi.base.font, lyx::from_utf8(str_), dim);
}
void InsetMathNumber::draw(PainterInfo & pi, int x, int y) const
{
docstring const dstr(str_.begin(), str_.end());
pi.draw(x, y, dstr);
// FIXME UNICODE
pi.draw(x, y, lyx::from_utf8(str_));
}

View File

@ -34,14 +34,16 @@ auto_ptr<InsetBase> InsetMathString::doClone() const
void InsetMathString::metrics(MetricsInfo & mi, Dimension & dim) const
{
mathed_string_dim(mi.base.font, str_, dim);
// FIXME UNICODE
mathed_string_dim(mi.base.font, lyx::from_utf8(str_), dim);
}
void InsetMathString::draw(PainterInfo & pi, int x, int y) const
{
//lyxerr << "drawing '" << str_ << "' code: " << code_ << endl;
docstring dstr(str_.begin(), str_.end());
// FIXME UNICODE
docstring dstr = lyx::from_utf8(str_);
pi.draw(x, y, dstr);
}

View File

@ -62,7 +62,8 @@ void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
int const em = mathed_char_width(mi.base.font, 'M');
FontSetChanger dummy(mi.base, sym_->inset.c_str());
mathed_string_dim(mi.base.font, sym_->draw, dim);
// FIXME UNICODE
mathed_string_dim(mi.base.font, lyx::from_utf8(sym_->draw), dim);
// correct height for broken cmex and wasy font
#if defined(__APPLE__) && defined(__GNUC__)
if (sym_->inset == "cmex") {
@ -110,9 +111,8 @@ void InsetMathSymbol::draw(PainterInfo & pi, int x, int y) const
x += static_cast<int>(0.0833*em+0.5);
FontSetChanger dummy(pi.base, sym_->inset.c_str());
string const sym = sym_->draw;
docstring const dsym(sym.begin(), sym.end());
pi.draw(x, y - h_, dsym);
// FIXME UNICODE
pi.draw(x, y - h_, lyx::from_utf8(sym_->draw));
}

View File

@ -51,17 +51,19 @@ void InsetMathUnknown::normalize(NormalStream & os) const
void InsetMathUnknown::metrics(MetricsInfo & mi, Dimension & dim) const
{
mathed_string_dim(mi.base.font, name_, dim);
// FIXME UNICODE
mathed_string_dim(mi.base.font, lyx::from_utf8(name_), dim);
dim_ = dim;
}
void InsetMathUnknown::draw(PainterInfo & pi, int x, int y) const
{
// FIXME UNICODE
if (black_)
drawStrBlack(pi, x, y, name_);
drawStrBlack(pi, x, y, lyx::from_utf8(name_));
else
drawStrRed(pi, x, y, name_);
drawStrRed(pi, x, y, lyx::from_utf8(name_));
setPosCache(pi, x, y);
}

View File

@ -88,7 +88,7 @@ void InsetMathXYArrow::metrics(MetricsInfo & mi) const
target_ = mi.inset ? mi.inset->asXYMatrixInset() : 0;
if (editing()) {
int w = mathed_string_width(mi.base.font, "target: ");
int w = mathed_string_width(mi.base.font, lyx::from_ascii("target: "));
width_ = w + max(cell(0).width(), cell(1).width());
ascent_ = cell(0).ascent();
descent_ = cell(0).descent() + cell(1).height() + 10;

View File

@ -49,14 +49,15 @@ void MathMacroArgument::write(WriteStream & os) const
void MathMacroArgument::metrics(MetricsInfo & mi, Dimension & dim) const
{
mathed_string_dim(mi.base.font, str_, dim_);
mathed_string_dim(mi.base.font, lyx::from_utf8(str_), dim_);
dim = dim_;
}
void MathMacroArgument::draw(PainterInfo & pi, int x, int y) const
{
drawStrRed(pi, x, y, str_);
// FIXME UNICODE
drawStrRed(pi, x, y, lyx::from_utf8(str_));
setPosCache(pi, x, y);
}

View File

@ -45,7 +45,8 @@ MacroData::MacroData(string const & def, int numargs, string const & disp)
void MacroData::expand(vector<MathArray> const & args, MathArray & to) const
{
InsetMathSqrt inset; // Hack. Any inset with a cell would do.
asArray(disp_.empty() ? def_ : disp_, inset.cell(0));
// FIXME UNICODE
asArray(lyx::from_utf8(disp_.empty() ? def_ : disp_), inset.cell(0));
//lyxerr << "MathData::expand: args: " << args << endl;
//lyxerr << "MathData::expand: ar: " << inset.cell(0) << endl;
for (DocIterator it = doc_iterator_begin(inset); it; it.forwardChar()) {

View File

@ -1220,7 +1220,8 @@ void Parser::parse1(InsetMathGrid & grid, unsigned flags,
// FIXME: This is swallowed in inline formulas
string label = parse_verbatim_item();
MathArray ar;
asArray(label, ar);
// FIXME UNICODE
asArray(lyx::from_utf8(label), ar);
if (grid.asHullInset()) {
grid.asHullInset()->label(cellrow, label);
} else {

View File

@ -365,7 +365,7 @@ deco_struct const * search_deco(string const & name)
} // namespace anon
void mathed_char_dim(LyXFont const & font, unsigned char c, Dimension & dim)
void mathed_char_dim(LyXFont const & font, lyx::char_type c, Dimension & dim)
{
lyx::frontend::FontMetrics const & fm = theFontMetrics(font);
dim.des = fm.descent(c);
@ -374,35 +374,28 @@ void mathed_char_dim(LyXFont const & font, unsigned char c, Dimension & dim)
}
int mathed_char_width(LyXFont const & font, unsigned char c)
int mathed_char_width(LyXFont const & font, lyx::char_type c)
{
return theFontMetrics(font).width(c);
}
void mathed_string_dim(LyXFont const & font, string const & s, Dimension & dim)
void mathed_string_dim(LyXFont const & font, docstring const & s, Dimension & dim)
{
lyx::frontend::FontMetrics const & fm = theFontMetrics(font);
#if 1
dim.asc = 0;
dim.des = 0;
for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
for (docstring::const_iterator it = s.begin(); it != s.end(); ++it) {
dim.asc = max(dim.asc, fm.ascent(*it));
dim.des = max(dim.des, fm.descent(*it));
}
#else
dim.asc = fm.maxAscent();
dim.des = fm.maxDescent();
#endif
docstring ds(s.begin(), s.end());
dim.wid = fm.width(ds);
dim.wid = fm.width(s);
}
int mathed_string_width(LyXFont const & font, string const & s)
int mathed_string_width(LyXFont const & font, docstring const & s)
{
docstring ds(s.begin(), s.end());
return theFontMetrics(font).width(ds);
return theFontMetrics(font).width(s);
}
@ -476,21 +469,19 @@ void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
}
void drawStrRed(PainterInfo & pi, int x, int y, string const & str)
void drawStrRed(PainterInfo & pi, int x, int y, docstring const & str)
{
LyXFont f = pi.base.font;
f.setColor(LColor::latex);
docstring dstr(str.begin(), str.end());
pi.pain.text(x, y, dstr, f);
pi.pain.text(x, y, str, f);
}
void drawStrBlack(PainterInfo & pi, int x, int y, string const & str)
void drawStrBlack(PainterInfo & pi, int x, int y, docstring const & str)
{
LyXFont f = pi.base.font;
f.setColor(LColor::foreground);
docstring dstr(str.begin(), str.end());
pi.pain.text(x, y, dstr, f);
pi.pain.text(x, y, str, f);
}
@ -687,9 +678,9 @@ string asString(MathArray const & ar)
}
void asArray(string const & str, MathArray & ar)
void asArray(docstring const & str, MathArray & ar)
{
mathed_parse_cell(ar, str);
mathed_parse_cell(ar, lyx::to_utf8(str));
}

View File

@ -13,7 +13,7 @@
#ifndef MATH_SUPPORT_H
#define MATH_SUPPORT_H
#include <string>
#include "support/docstring.h"
class PainterInfo;
class LyXFont;
@ -23,17 +23,17 @@ class MathAtom;
class InsetMath;
void mathed_char_dim(LyXFont const &, unsigned char c, Dimension & dim);
int mathed_char_width(LyXFont const &, unsigned char c);
void mathed_char_dim(LyXFont const &, lyx::char_type c, Dimension & dim);
int mathed_char_width(LyXFont const &, lyx::char_type c);
void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
std::string const & name);
void mathed_string_dim(LyXFont const & font, std::string const & s, Dimension & dim);
int mathed_string_width(LyXFont const &, std::string const & s);
void mathed_string_dim(LyXFont const & font, lyx::docstring const & s, Dimension & dim);
int mathed_string_width(LyXFont const &, lyx::docstring const & s);
void drawStrRed(PainterInfo & pi, int x, int y, std::string const & s);
void drawStrBlack(PainterInfo & pi, int x, int y, std::string const & s);
void drawStrRed(PainterInfo & pi, int x, int y, lyx::docstring const & s);
void drawStrBlack(PainterInfo & pi, int x, int y, lyx::docstring const & s);
void math_font_max_dim(LyXFont const &, int & asc, int & desc);
@ -47,6 +47,6 @@ std::string asString(MathArray const & ar);
std::string asString(InsetMath const &);
std::string asString(MathAtom const &);
// converts string to single cell
void asArray(std::string const & str, MathArray & ar);
void asArray(lyx::docstring const & str, MathArray & ar);
#endif

View File

@ -194,7 +194,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos, LyXFont const & font)
{
pos_type pos = text_.bidi.vis2log(vpos);
string str;
docstring str;
// first char
char_type c = par_.getChar(pos);
@ -220,15 +220,15 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos, LyXFont const & font)
}
// Draw nikud
docstring dstr(str.begin(), str.end());
pain_.text(int(x_) + dx, yo_, dstr, font);
// FIXME UNICODE
pain_.text(int(x_) + dx, yo_, str, font);
}
void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font)
{
pos_type pos = text_.bidi.vis2log(vpos);
string str;
docstring str;
// first char
char_type c = par_.getChar(pos);
@ -251,8 +251,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos, LyXFont const & font)
}
}
// Draw nikud
docstring dstr(str.begin(), str.end());
pain_.text(int(x_) + dx, yo_, dstr, font);
pain_.text(int(x_) + dx, yo_, str, font);
}
@ -458,17 +457,17 @@ int RowPainter::paintAppendixStart(int y)
pb_font.setColor(LColor::appendix);
pb_font.decSize();
string const label = lyx::to_utf8(_("Appendix"));
int w = 0;
int a = 0;
int d = 0;
docstring dlab(label.begin(), label.end());
theFontMetrics(pb_font).rectText(dlab, w, a, d);
docstring const label = _("Appendix");
theFontMetrics(pb_font).rectText(label, w, a, d);
int const text_start = int(xo_ + (width_ - w) / 2);
int const text_end = text_start + w;
pain_.rectText(text_start, y + d, dlab, pb_font, LColor::none, LColor::none);
pain_.rectText(text_start, y + d, label, pb_font, LColor::none, LColor::none);
pain_.line(int(xo_ + 1), y, text_start, y, LColor::appendix);
pain_.line(text_end, y, int(xo_ + width_ - 2), y, LColor::appendix);
@ -520,10 +519,10 @@ void RowPainter::paintFirst()
LyXFont const font = getLabelFont();
FontMetrics const & fm = theFontMetrics(font);
string const str = par_.getLabelstring();
// FIXME UNICODE
docstring const str = lyx::from_utf8(par_.getLabelstring());
if (!str.empty()) {
double x = x_;
docstring dstr(str.begin(), str.end());
// this is special code for the chapter layout. This is
// printed in an extra row and has a pagebreak at
@ -543,22 +542,22 @@ void RowPainter::paintFirst()
if (is_rtl) {
x = width_ - leftMargin() -
fm.width(dstr);
fm.width(str);
}
pain_.text(int(x), yo_ - maxdesc - labeladdon, dstr, font);
pain_.text(int(x), yo_ - maxdesc - labeladdon, str, font);
} else {
string lab = layout->labelsep;
docstring dlab(lab.begin(), lab.end());
// FIXME UNICODE
docstring lab = lyx::from_utf8(layout->labelsep);
if (is_rtl) {
x = width_ - leftMargin()
+ fm.width(dlab);
+ fm.width(lab);
} else {
x = x_ - fm.width(dlab)
- fm.width(dstr);
x = x_ - fm.width(lab)
- fm.width(str);
}
pain_.text(int(x), yo_, dstr, font);
pain_.text(int(x), yo_, str, font);
}
}
@ -570,8 +569,7 @@ void RowPainter::paintFirst()
layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
LyXFont font = getLabelFont();
if (!par_.getLabelstring().empty()) {
string const str = par_.getLabelstring();
docstring dstr(str.begin(), str.end());
docstring const str = lyx::from_utf8(par_.getLabelstring());
double spacing_val = 1.0;
if (!parparams.spacing().isDefault())
spacing_val = parparams.spacing().getValue();
@ -592,11 +590,11 @@ void RowPainter::paintFirst()
if (is_rtl)
x = leftMargin();
x += (width_ - text_.rightMargin(par_) - leftMargin()) / 2;
x -= fm.width(dstr) / 2;
x -= fm.width(str) / 2;
} else if (is_rtl) {
x = width_ - leftMargin() - fm.width(dstr);
x = width_ - leftMargin() - fm.width(str);
}
pain_.text(int(x), yo_ - maxdesc - labeladdon, dstr, font);
pain_.text(int(x), yo_ - maxdesc - labeladdon, str, font);
}
}
}
@ -630,12 +628,12 @@ void RowPainter::paintLast()
case END_LABEL_STATIC: {
LyXFont font = getLabelFont();
FontMetrics const & fm = theFontMetrics(font);
string const & str = par_.layout()->endlabelstring();
docstring dstr(str.begin(), str.end());
// FIXME UNICODE
docstring const & str = lyx::from_utf8(par_.layout()->endlabelstring());
double const x = is_rtl ?
x_ - fm.width(dstr)
x_ - fm.width(str)
: - text_.rightMargin(par_) - row_.width();
pain_.text(int(x), yo_, dstr, font);
pain_.text(int(x), yo_, str, font);
break;
}
@ -713,10 +711,9 @@ void RowPainter::paintText()
}
if (body_pos > 0 && pos == body_pos - 1) {
string lab = layout->labelsep;
docstring dlab(lab.begin(), lab.end());
int const lwidth
= theFontMetrics(getLabelFont()).width(dlab);
// FIXME UNICODE
int const lwidth = theFontMetrics(getLabelFont())
.width(lyx::from_utf8(layout->labelsep));
x_ += label_hfill_ + lwidth - width_pos;
}

View File

@ -501,9 +501,9 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
if (isMainText())
l_margin += changebarMargin();
string leftm = tclass.leftmargin();
docstring dleft(leftm.begin(), leftm.end());
l_margin += theFontMetrics(params.getFont()).signedWidth(dleft);
// FIXME UNICODE
docstring leftm = lyx::from_utf8(tclass.leftmargin());
l_margin += theFontMetrics(params.getFont()).signedWidth(leftm);
if (par.getDepth() != 0) {
// find the next level paragraph
@ -534,45 +534,41 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
switch (layout->margintype) {
case MARGIN_DYNAMIC:
if (!layout->leftmargin.empty()) {
string leftm = layout->leftmargin;
docstring dleft(leftm.begin(), leftm.end());
l_margin += theFontMetrics(params.getFont()).signedWidth(dleft);
// FIXME UNICODE
docstring leftm = lyx::from_utf8(layout->leftmargin);
l_margin += theFontMetrics(params.getFont()).signedWidth(leftm);
}
if (!par.getLabelstring().empty()) {
string labin = layout->labelindent;
docstring dlabin(labin.begin(), labin.end());
l_margin += labelfont_metrics.signedWidth(dlabin);
string labstr = par.getLabelstring();
docstring dlabstr(labstr.begin(), labstr.end());
l_margin += labelfont_metrics.width(dlabstr);
string labsep = layout->labelsep;
docstring dlabsep(labsep.begin(), labsep.end());
l_margin += labelfont_metrics.width(dlabsep);
// FIXME UNICODE
docstring labin = lyx::from_utf8(layout->labelindent);
l_margin += labelfont_metrics.signedWidth(labin);
docstring labstr = lyx::from_utf8(par.getLabelstring());
l_margin += labelfont_metrics.width(labstr);
docstring labsep = lyx::from_utf8(layout->labelsep);
l_margin += labelfont_metrics.width(labsep);
}
break;
case MARGIN_MANUAL: {
string labin = layout->labelindent;
docstring dlabin(labin.begin(), labin.end());
l_margin += labelfont_metrics.signedWidth(dlabin);
// FIXME UNICODE
docstring labin = lyx::from_utf8(layout->labelindent);
l_margin += labelfont_metrics.signedWidth(labin);
// The width of an empty par, even with manual label, should be 0
if (!par.empty() && pos >= par.beginOfBody()) {
if (!par.getLabelWidthString().empty()) {
string labstr = par.getLabelWidthString();
docstring dlabstr(labstr.begin(), labstr.end());
l_margin += labelfont_metrics.width(dlabstr);
string labsep = layout->labelsep;
docstring dlabsep(labsep.begin(), labsep.end());
l_margin += labelfont_metrics.width(dlabsep);
docstring labstr = lyx::from_utf8(par.getLabelWidthString());
l_margin += labelfont_metrics.width(labstr);
docstring labsep = lyx::from_utf8(layout->labelsep);
l_margin += labelfont_metrics.width(labsep);
}
}
break;
}
case MARGIN_STATIC: {
string leftm = layout->leftmargin;
docstring dleft(leftm.begin(), leftm.end());
l_margin += theFontMetrics(params.getFont()).signedWidth(dleft)
// FIXME UNICODE
docstring leftm = lyx::from_utf8(layout->leftmargin);
l_margin += theFontMetrics(params.getFont()).signedWidth(leftm)
* 4 / (par.getDepth() + 4);
break;
}
@ -580,13 +576,13 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
case MARGIN_FIRST_DYNAMIC:
if (layout->labeltype == LABEL_MANUAL) {
if (pos >= par.beginOfBody()) {
string leftm = layout->leftmargin;
docstring dleft(leftm.begin(), leftm.end());
l_margin += labelfont_metrics.signedWidth(dleft);
// FIXME UNICODE
l_margin += labelfont_metrics.signedWidth(
lyx::from_utf8(layout->leftmargin));
} else {
string labin = layout->labelindent;
docstring dlabin(labin.begin(), labin.end());
l_margin += labelfont_metrics.signedWidth(dlabin);
// FIXME UNICODE
l_margin += labelfont_metrics.signedWidth(
lyx::from_utf8(layout->labelindent));
}
} else if (pos != 0
// Special case to fix problems with
@ -594,22 +590,15 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
|| (layout->labeltype == LABEL_STATIC
&& layout->latextype == LATEX_ENVIRONMENT
&& !isFirstInSequence(pit, pars_))) {
string leftm = layout->leftmargin;
docstring dleft(leftm.begin(), leftm.end());
l_margin += labelfont_metrics.signedWidth(dleft);
// FIXME UNICODE
l_margin += labelfont_metrics.signedWidth(lyx::from_utf8(layout->leftmargin));
} else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
&& layout->labeltype != LABEL_BIBLIO
&& layout->labeltype !=
LABEL_CENTERED_TOP_ENVIRONMENT) {
string labin = layout->labelindent;
docstring dlabin(labin.begin(), labin.end());
l_margin += labelfont_metrics.signedWidth(dlabin);
string labsep = layout->labelsep;
docstring dlabsep(labsep.begin(), labsep.end());
l_margin += labelfont_metrics.width(dlabsep);
string labstr = par.getLabelstring();
docstring dlabstr(labstr.begin(), labstr.end());
l_margin += labelfont_metrics.width(dlabstr);
l_margin += labelfont_metrics.signedWidth(lyx::from_utf8(layout->labelindent));
l_margin += labelfont_metrics.width(lyx::from_utf8(layout->labelsep));
l_margin += labelfont_metrics.width(lyx::from_utf8(par.getLabelstring()));
}
break;
@ -665,7 +654,7 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
|| bv()->buffer()->params().paragraph_separation ==
BufferParams::PARSEP_INDENT))
{
docstring din(parindent.begin(), parindent.end());
docstring din = lyx::from_utf8(parindent);
l_margin += theFontMetrics(params.getFont()).signedWidth(din);
}
@ -684,15 +673,13 @@ int LyXText::rightMargin(Paragraph const & par) const
BufferParams const & params = bv()->buffer()->params();
LyXTextClass const & tclass = params.getLyXTextClass();
string trmarg = tclass.rightmargin();
docstring dtrmarg(trmarg.begin(), trmarg.end());
string lrmarg = par.layout()->rightmargin;
docstring dlrmarg(lrmarg.begin(), lrmarg.end());
docstring trmarg = lyx::from_utf8(tclass.rightmargin());
docstring lrmarg = lyx::from_utf8(par.layout()->rightmargin);
FontMetrics const & fm = theFontMetrics(params.getFont());
int const r_margin =
::rightMargin()
+ fm.signedWidth(dtrmarg)
+ fm.signedWidth(dlrmarg)
+ fm.signedWidth(trmarg)
+ fm.signedWidth(lrmarg)
* 4 / (par.getDepth() + 4);
return r_margin;
@ -773,9 +760,8 @@ void LyXText::rowBreakPoint(pit_type const pit, Row & row) const
// add the auto-hfill from label end to the body
if (body_pos && i == body_pos) {
string lsep = layout->labelsep;
docstring dlsep(lsep.begin(), lsep.end());
int add = fm.width(dlsep);
docstring lsep = lyx::from_utf8(layout->labelsep);
int add = fm.width(lsep);
if (par.isLineSeparator(i - 1))
add -= singleWidth(par, i - 1);
@ -848,8 +834,7 @@ void LyXText::setRowWidth(pit_type const pit, Row & row) const
pos_type const end = row.endpos();
Paragraph const & par = pars_[pit];
string const & labelsep = par.layout()->labelsep;
docstring dlsep(labelsep.begin(), labelsep.end());
docstring const labelsep = lyx::from_utf8(par.layout()->labelsep);
int w = leftMargin(pit, row.pos());
pos_type const body_pos = par.beginOfBody();
@ -861,7 +846,7 @@ void LyXText::setRowWidth(pit_type const pit, Row & row) const
FontIterator fi = FontIterator(*this, par, i);
for ( ; i < end; ++i, ++fi) {
if (body_pos > 0 && i == body_pos) {
w += fm.width(dlsep);
w += fm.width(labelsep);
if (par.isLineSeparator(i - 1))
w -= singleWidth(par, i - 1);
w = max(w, labelEnd(pit));
@ -872,7 +857,7 @@ void LyXText::setRowWidth(pit_type const pit, Row & row) const
}
if (body_pos > 0 && body_pos >= end) {
w += fm.width(dlsep);
w += fm.width(labelsep);
if (end > 0 && par.isLineSeparator(end - 1))
w -= singleWidth(par, end - 1);
w = max(w, labelEnd(pit));
@ -904,11 +889,10 @@ int LyXText::labelFill(Paragraph const & par, Row const & row) const
if (label.empty())
return 0;
docstring dlab(label.begin(), label.end());
FontMetrics const & fm = theFontMetrics(getLabelFont(par));
return max(0, fm.width(dlab) - w);
// FIXME UNICODE
return max(0, fm.width(lyx::from_utf8(label)) - w);
}
@ -1393,9 +1377,8 @@ LyXText::computeRowMetrics(pit_type const pit, Row const & row) const
if (body_pos > 0
&& (body_pos > end || !par.isLineSeparator(body_pos - 1)))
{
string lsep = layout->labelsep;
docstring dlsep(lsep.begin(), lsep.end());
result.x += theFontMetrics(getLabelFont(par)).width(dlsep);
docstring const lsep = lyx::from_utf8(layout->labelsep);
result.x += theFontMetrics(getLabelFont(par)).width(lsep);
if (body_pos <= end)
result.x += result.label_hfill;
}
@ -2313,9 +2296,9 @@ int LyXText::cursorX(CursorSlice const & sl, bool boundary) const
for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) {
string lsep = par.layout()->labelsep;
docstring dlsep(lsep.begin(), lsep.end());
x += m.label_hfill + labelfm.width(dlsep);
// FIXME UNICODE
docstring const lsep = lyx::from_utf8(par.layout()->labelsep);
x += m.label_hfill + labelfm.width(lsep);
if (par.isLineSeparator(body_pos - 1))
x -= singleWidth(par, body_pos - 1);
}

View File

@ -812,9 +812,9 @@ pos_type LyXText::getColumnNearX(pit_type const pit,
c = bidi.vis2log(vc);
last_tmpx = tmpx;
if (body_pos > 0 && c == body_pos - 1) {
string lsep = layout->labelsep;
docstring dlsep(lsep.begin(), lsep.end());
tmpx += r.label_hfill + fm.width(dlsep);
// FIXME UNICODE
docstring const lsep = lyx::from_utf8(layout->labelsep);
tmpx += r.label_hfill + fm.width(lsep);
if (par.isLineSeparator(body_pos - 1))
tmpx -= singleWidth(par, body_pos - 1);
}

View File

@ -169,7 +169,8 @@ bool textUndoOrRedo(BufferView & bv,
// gained by storing just 'a few' paragraphs (most if not
// all math inset cells have just one paragraph!)
//lyxerr << "undo.array=" << undo.array <<endl;
asArray(undo.array, dit.cell());
// FIXME UNICODE
asArray(lyx::from_utf8(undo.array), dit.cell());
} else {
// Some finer machinery is needed here.
LyXText * text = dit.text();