From f6730f66b0d146cd7ec062cb371014ba0211010b Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sat, 11 Nov 2006 20:55:40 +0000 Subject: [PATCH] Unicode: remove more utf8 roundtrips and faulty conversions to docstring without from_utf8 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15864 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/buffer.C | 1 - src/frontends/controllers/ControlGraphics.C | 1 - src/insets/insetcaption.C | 12 +++--------- src/insets/insetcaption.h | 2 +- src/insets/insetcharstyle.C | 20 +++++++++----------- src/insets/insetcollapsable.C | 6 ++---- src/insets/insetinclude.C | 1 - src/insets/insetvspace.C | 17 +++++++---------- src/insets/insetvspace.h | 2 +- src/insets/render_graphic.C | 17 ++++++----------- src/insets/render_preview.C | 11 ++++------- 11 files changed, 33 insertions(+), 57 deletions(-) diff --git a/src/buffer.C b/src/buffer.C index ffd9fa74c0..cf93290a14 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1639,7 +1639,6 @@ void Buffer::changeRefsIfUnique(docstring const & from, docstring const & to, } else getLabelList(labels); - // FIXME UNICODE if (lyx::count(labels.begin(), labels.end(), from) > 1) return; diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index 15255c96ba..c1ce0a7893 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -83,7 +83,6 @@ void ControlGraphics::dispatchParams() docstring const ControlGraphics::browse(docstring const & in_name) const { - // FIXME UNICODE docstring const title = _("Select graphics file"); // Does user clipart directory exist? diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index 87f327c804..482642f94a 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -114,8 +114,7 @@ void InsetCaption::setLabel(LCursor & cur) const num = convert(counter_); // Generate the label - label = to_utf8( - bformat(from_ascii("%1$s %2$s:"), _(s), num)); + label = bformat(from_ascii("%1$s %2$s:"), _(s), num); } } @@ -125,8 +124,7 @@ void InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET; LCursor cur = mi.base.bv->cursor(); setLabel(cur); - docstring dlab(label.begin(), label.end()); - labelwidth_ = theFontMetrics(mi.base.font).width(dlab); + labelwidth_ = theFontMetrics(mi.base.font).width(label); dim.wid = labelwidth_; Dimension textdim; InsetText::metrics(mi, textdim); @@ -153,11 +151,7 @@ void InsetCaption::draw(PainterInfo & pi, int x, int y) const // belongs to. LCursor cur = pi.base.bv->cursor(); setLabel(cur); - docstring dlab(label.begin(), label.end()); - // FXIME: instead of using the fontLoader metrics, we should make - // painter::text() returns the drawn text witdh. - labelwidth_ = theFontMetrics(pi.base.font).width(dlab); - pi.pain.text(x, y, dlab, pi.base.font); + labelwidth_ = pi.pain.text(x, y, label, pi.base.font); InsetText::draw(pi, x + labelwidth_, y); setPosCache(pi, x, y); } diff --git a/src/insets/insetcaption.h b/src/insets/insetcaption.h index 723b9cf6b0..d60718c128 100644 --- a/src/insets/insetcaption.h +++ b/src/insets/insetcaption.h @@ -67,7 +67,7 @@ private: /// virtual std::auto_ptr doClone() const; /// - mutable std::string label; + mutable docstring label; /// mutable int labelwidth_; /// diff --git a/src/insets/insetcharstyle.C b/src/insets/insetcharstyle.C index aa8d3ea292..6d953726c8 100644 --- a/src/insets/insetcharstyle.C +++ b/src/insets/insetcharstyle.C @@ -157,12 +157,11 @@ void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const int w = 0; int a = 0; int d = 0; - string s(params_.type); + // FIXME UNICODE + docstring s(from_utf8(params_.type)); if (undefined()) - // FIXME UNICODE - s = to_utf8(_("Undef: ")) + s; - docstring ds(s.begin(), s.end()); - theFontMetrics(font).rectText(ds, w, a, d); + s = _("Undef: ") + s; + theFontMetrics(font).rectText(s, w, a, d); dim.wid = max(dim.wid, w); } dim.asc += TEXT_TO_INSET_OFFSET; @@ -205,14 +204,13 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const int w = 0; int a = 0; int d = 0; - string s(params_.type); + // FIXME UNICODE + docstring s(from_utf8(params_.type)); if (undefined()) - // FIXME UNICODE - s = to_utf8(_("Undef: ")) + s; - docstring ds(s.begin(), s.end()); - theFontMetrics(font).rectText(ds, w, a, d); + s = _("Undef: ") + s; + theFontMetrics(font).rectText(s, w, a, d); pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a, - ds, font, LColor::none, LColor::none); + s, font, LColor::none, LColor::none); } // a visual clue when the cursor is inside the inset diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 7d95df18c7..6c1f127dfc 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -126,9 +126,8 @@ void InsetCollapsable::read(Buffer const & buf, LyXLex & lex) Dimension InsetCollapsable::dimensionCollapsed() const { Dimension dim; - docstring dlab(label.begin(), label.end()); theFontMetrics(labelfont_).buttonText( - dlab, dim.wid, dim.asc, dim.des); + label, dim.wid, dim.asc, dim.des); return dim; } @@ -180,8 +179,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const button_dim.y1 = top; button_dim.y2 = top + dimc.height(); - docstring dlab(label.begin(), label.end()); - pi.pain.buttonText(xx, top + dimc.asc, dlab, labelfont_); + pi.pain.buttonText(xx, top + dimc.asc, label, labelfont_); if (status() == Open) { int textx, texty; diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 3a4965eaa1..af81cea209 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -545,7 +545,6 @@ int InsetInclude::docbook(Buffer const & buffer, odocstream & os, runparams.exportdata->addExternalFile("docbook-xml", writefile, exportfile); - // FIXME UNICODE if (isVerbatim(params_)) { os << " doClone() const; /// - std::string const label() const; + docstring const label() const; /// VSpace space_; diff --git a/src/insets/render_graphic.C b/src/insets/render_graphic.C index 46fc091f52..d940d782da 100644 --- a/src/insets/render_graphic.C +++ b/src/insets/render_graphic.C @@ -83,7 +83,7 @@ bool displayGraphic(graphics::Params const & params) } -string const statusMessage(graphics::Params const & params, +docstring const statusMessage(graphics::Params const & params, graphics::ImageStatus status) { docstring ret; @@ -128,8 +128,7 @@ string const statusMessage(graphics::Params const & params, } } - // FIXME UNICODE - return to_utf8(ret); + return ret; } @@ -168,9 +167,7 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const .width(justname); } - // FIXME UNICODE - docstring const msg = - from_utf8(statusMessage(params_, loader_.status())); + docstring const msg = statusMessage(params_, loader_.status()); if (!msg.empty()) { msgFont.setSize(LyXFont::SIZE_TINY); font_width = std::max(font_width, @@ -216,20 +213,18 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const string const justname = onlyFilename(params_.filename); if (!justname.empty()) { - docstring djust(justname.begin(), justname.end()); msgFont.setSize(LyXFont::SIZE_FOOTNOTE); pi.pain.text(x + InsetOld::TEXT_TO_INSET_OFFSET + 6, y - theFontMetrics(msgFont).maxAscent() - 4, - djust, msgFont); + from_utf8(justname), msgFont); } // Print the message. - string const msg = statusMessage(params_, loader_.status()); + docstring const msg = statusMessage(params_, loader_.status()); if (!msg.empty()) { - docstring dmsg(msg.begin(), msg.end()); msgFont.setSize(LyXFont::SIZE_TINY); pi.pain.text(x + InsetOld::TEXT_TO_INSET_OFFSET + 6, - y - 4, dmsg, msgFont); + y - 4, msg, msgFont); } } } diff --git a/src/insets/render_preview.C b/src/insets/render_preview.C index e0745fc8cd..21ce5c58b6 100644 --- a/src/insets/render_preview.C +++ b/src/insets/render_preview.C @@ -74,7 +74,7 @@ graphics::PreviewLoader & getPreviewLoader(Buffer const & buffer) } -string const statusMessage(BufferView const * bv, string const & snippet) +docstring const statusMessage(BufferView const * bv, string const & snippet) { BOOST_ASSERT(bv && bv->buffer()); @@ -96,8 +96,7 @@ string const statusMessage(BufferView const * bv, string const & snippet) break; } - // FIXME UNICODE - return to_utf8(message); + return message; } } // namespace anon @@ -129,8 +128,7 @@ void RenderPreview::metrics(MetricsInfo & mi, Dimension & dim) const LyXFont font(mi.base.font); font.setFamily(LyXFont::SANS_FAMILY); font.setSize(LyXFont::SIZE_FOOTNOTE); - // FIXME UNICODE - docstring const stat = from_utf8(statusMessage(mi.base.bv, snippet_)); + docstring const stat = statusMessage(mi.base.bv, snippet_); dim.wid = 15 + theFontMetrics(font).width(stat); } @@ -163,8 +161,7 @@ void RenderPreview::draw(PainterInfo & pi, int x, int y) const font.setFamily(LyXFont::SANS_FAMILY); font.setSize(LyXFont::SIZE_FOOTNOTE); - // FIXME UNICODE - docstring const stat = from_utf8(statusMessage(pi.base.bv, snippet_)); + docstring const stat = statusMessage(pi.base.bv, snippet_); pi.pain.text(x + offset + 6, y - theFontMetrics(font).maxAscent() - 4, stat, font); -- 2.39.2