From 52bd213992aeedde743ca8d794cddfe17a6893b9 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Tue, 17 Oct 2006 14:46:45 +0000 Subject: [PATCH] More unicode conversion git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15355 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/cursor.C | 9 ++- src/insets/render_graphic.C | 14 ++-- src/insets/render_preview.C | 12 ++-- src/mathed/InsetMathComment.C | 3 +- src/mathed/InsetMathExFunc.C | 6 +- src/mathed/InsetMathFrameBox.C | 8 +-- src/mathed/InsetMathHull.C | 17 ++--- src/mathed/InsetMathHull.h | 2 +- src/mathed/InsetMathMacro.C | 21 +++--- src/mathed/InsetMathMakebox.C | 8 +-- src/mathed/InsetMathNest.C | 4 +- src/mathed/InsetMathNumber.C | 7 +- src/mathed/InsetMathString.C | 6 +- src/mathed/InsetMathSymbol.C | 8 +-- src/mathed/InsetMathUnknown.C | 8 ++- src/mathed/InsetMathXYArrow.C | 2 +- src/mathed/MathMacroArgument.C | 5 +- src/mathed/MathMacroTable.C | 3 +- src/mathed/MathParser.C | 3 +- src/mathed/MathSupport.C | 35 ++++------ src/mathed/MathSupport.h | 16 ++--- src/rowpainter.C | 63 +++++++++-------- src/text.C | 119 ++++++++++++++------------------- src/text2.C | 6 +- src/undo.C | 3 +- 25 files changed, 191 insertions(+), 197 deletions(-) diff --git a/src/cursor.C b/src/cursor.C index cae408cdaf..69ba63b195 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -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()); diff --git a/src/insets/render_graphic.C b/src/insets/render_graphic.C index 73cdf27c5d..5315637fca 100644 --- a/src/insets/render_graphic.C +++ b/src/insets/render_graphic.C @@ -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); diff --git a/src/insets/render_preview.C b/src/insets/render_preview.C index d219e39c10..d88289181d 100644 --- a/src/insets/render_preview.C +++ b/src/insets/render_preview.C @@ -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); } } diff --git a/src/mathed/InsetMathComment.C b/src/mathed/InsetMathComment.C index b7fde26649..f2473d70fb 100644 --- a/src/mathed/InsetMathComment.C +++ b/src/mathed/InsetMathComment.C @@ -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)); } diff --git a/src/mathed/InsetMathExFunc.C b/src/mathed/InsetMathExFunc.C index 6ee9479e50..4fd615de23 100644 --- a/src/mathed/InsetMathExFunc.C +++ b/src/mathed/InsetMathExFunc.C @@ -41,13 +41,15 @@ auto_ptr 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_)); } diff --git a/src/mathed/InsetMathFrameBox.C b/src/mathed/InsetMathFrameBox.C index dac60baff9..9781963ab3 100644 --- a/src/mathed/InsetMathFrameBox.C +++ b/src/mathed/InsetMathFrameBox.C @@ -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); diff --git a/src/mathed/InsetMathHull.C b/src/mathed/InsetMathHull.C index ac27c50a48..095bf92dd6 100644 --- a/src/mathed/InsetMathHull.C +++ b/src/mathed/InsetMathHull.C @@ -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; diff --git a/src/mathed/InsetMathHull.h b/src/mathed/InsetMathHull.h index e2db6d5910..c67fe8aebf 100644 --- a/src/mathed/InsetMathHull.h +++ b/src/mathed/InsetMathHull.h @@ -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); /// diff --git a/src/mathed/InsetMathMacro.C b/src/mathed/InsetMathMacro.C index 7a0110eea1..efad92485d 100644 --- a/src/mathed/InsetMathMacro.C +++ b/src/mathed/InsetMathMacro.C @@ -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; diff --git a/src/mathed/InsetMathMakebox.C b/src/mathed/InsetMathMakebox.C index 4fca51552e..31bb3fd4ac 100644 --- a/src/mathed/InsetMathMakebox.C +++ b/src/mathed/InsetMathMakebox.C @@ -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); diff --git a/src/mathed/InsetMathNest.C b/src/mathed/InsetMathNest.C index 3ccd2e1a37..e0e3e419a2 100644 --- a/src/mathed/InsetMathNest.C +++ b/src/mathed/InsetMathNest.C @@ -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); diff --git a/src/mathed/InsetMathNumber.C b/src/mathed/InsetMathNumber.C index 8b8fb9b8b4..8988a571c8 100644 --- a/src/mathed/InsetMathNumber.C +++ b/src/mathed/InsetMathNumber.C @@ -34,14 +34,15 @@ auto_ptr 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_)); } diff --git a/src/mathed/InsetMathString.C b/src/mathed/InsetMathString.C index 9f5afa70b9..f23df13e56 100644 --- a/src/mathed/InsetMathString.C +++ b/src/mathed/InsetMathString.C @@ -34,14 +34,16 @@ auto_ptr 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); } diff --git a/src/mathed/InsetMathSymbol.C b/src/mathed/InsetMathSymbol.C index 1aa9ba0f85..70d747df1d 100644 --- a/src/mathed/InsetMathSymbol.C +++ b/src/mathed/InsetMathSymbol.C @@ -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(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)); } diff --git a/src/mathed/InsetMathUnknown.C b/src/mathed/InsetMathUnknown.C index 14cee3c3e9..fd52b0aed9 100644 --- a/src/mathed/InsetMathUnknown.C +++ b/src/mathed/InsetMathUnknown.C @@ -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); } diff --git a/src/mathed/InsetMathXYArrow.C b/src/mathed/InsetMathXYArrow.C index 205b9265ee..5cd4c86172 100644 --- a/src/mathed/InsetMathXYArrow.C +++ b/src/mathed/InsetMathXYArrow.C @@ -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; diff --git a/src/mathed/MathMacroArgument.C b/src/mathed/MathMacroArgument.C index 5f0cf20102..0ffaa799ec 100644 --- a/src/mathed/MathMacroArgument.C +++ b/src/mathed/MathMacroArgument.C @@ -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); } diff --git a/src/mathed/MathMacroTable.C b/src/mathed/MathMacroTable.C index c22ce605cb..daae5fc954 100644 --- a/src/mathed/MathMacroTable.C +++ b/src/mathed/MathMacroTable.C @@ -45,7 +45,8 @@ MacroData::MacroData(string const & def, int numargs, string const & disp) void MacroData::expand(vector 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()) { diff --git a/src/mathed/MathParser.C b/src/mathed/MathParser.C index b8268eb72a..34c8e8c8b1 100644 --- a/src/mathed/MathParser.C +++ b/src/mathed/MathParser.C @@ -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 { diff --git a/src/mathed/MathSupport.C b/src/mathed/MathSupport.C index 02c224ffff..983c3c7637 100644 --- a/src/mathed/MathSupport.C +++ b/src/mathed/MathSupport.C @@ -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)); } diff --git a/src/mathed/MathSupport.h b/src/mathed/MathSupport.h index 68fd49d6e1..8b026fe434 100644 --- a/src/mathed/MathSupport.h +++ b/src/mathed/MathSupport.h @@ -13,7 +13,7 @@ #ifndef MATH_SUPPORT_H #define MATH_SUPPORT_H -#include +#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 diff --git a/src/rowpainter.C b/src/rowpainter.C index 102c154a20..ac58297801 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -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; } diff --git a/src/text.C b/src/text.C index c8a9af6468..73171abbbc 100644 --- a/src/text.C +++ b/src/text.C @@ -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); } diff --git a/src/text2.C b/src/text2.C index c916e07a61..e50753430b 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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); } diff --git a/src/undo.C b/src/undo.C index 29b3c7b640..d40de5d33c 100644 --- a/src/undo.C +++ b/src/undo.C @@ -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 <