X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetCaption.cpp;h=e1ace0dc925b1c759b0b3eb410eac5c1e735133b;hb=8124e6c02ea1fd6779bb6c47ffe2bca2c8bd2d97;hp=3f1aebf99e103c923260159f5e32912ce8b70874;hpb=5e21a8fbf78babfb69d3e9f236cfe6aaffd1c465;p=lyx.git diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index 3f1aebf99e..e1ace0dc92 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -25,10 +25,11 @@ #include "FuncStatus.h" #include "InsetList.h" #include "Language.h" +#include "LyXRC.h" #include "MetricsInfo.h" +#include "xml.h" #include "output_latex.h" #include "output_xhtml.h" -#include "OutputParams.h" #include "Paragraph.h" #include "ParIterator.h" #include "TexRow.h" @@ -52,8 +53,7 @@ namespace lyx { InsetCaption::InsetCaption(Buffer * buf, string const & type) - : InsetText(buf, InsetText::PlainLayout), - labelwidth_(0), is_subfloat_(false), is_deleted_(false), type_(type) + : InsetText(buf, InsetText::PlainLayout), type_(type) { setDrawFrame(true); setFrameColor(Color_collapsibleframe); @@ -82,7 +82,8 @@ void InsetCaption::cursorPos(BufferView const & bv, CursorSlice const & sl, bool boundary, int & x, int & y) const { InsetText::cursorPos(bv, sl, boundary, x, y); - x += labelwidth_; + if (!rtl_) + x += labelwidth_; } @@ -110,8 +111,6 @@ void InsetCaption::addToToc(DocIterator const & cpit, bool output_active, void InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const { - FontInfo tmpfont = mi.base.font; - mi.base.font = mi.base.bv->buffer().params().getFont().fontInfo(); labelwidth_ = theFontMetrics(mi.base.font).width(full_label_); // add some space to separate the label from the inset text labelwidth_ += leftOffset(mi.base.bv) + rightOffset(mi.base.bv); @@ -120,7 +119,6 @@ void InsetCaption::metrics(MetricsInfo & mi, Dimension & dim) const // Correct for button and label width mi.base.textwidth -= dim.wid; InsetText::metrics(mi, textdim); - mi.base.font = tmpfont; mi.base.textwidth += dim.wid; dim.des = max(dim.des - textdim.asc + dim.asc, textdim.des); dim.asc = textdim.asc; @@ -133,6 +131,8 @@ void InsetCaption::drawBackground(PainterInfo & pi, int x, int y) const TextMetrics & tm = pi.base.bv->textMetrics(&text()); int const h = tm.height() + topOffset(pi.base.bv) + bottomOffset(pi.base.bv); int const yy = y - topOffset(pi.base.bv) - tm.ascent(); + if (rtl_) + x+= + dimension(*pi.base.bv).wid - labelwidth_; pi.pain.fillRectangle(x, yy, labelwidth_, h, pi.backgroundColor(this)); } @@ -147,16 +147,25 @@ void InsetCaption::draw(PainterInfo & pi, int x, int y) const // Answer: the text inset (in buffer_funcs.cpp: setCaption). + rtl_ = !pi.ltr_pos; FontInfo tmpfont = pi.base.font; - pi.base.font = pi.base.bv->buffer().params().getFont().fontInfo(); - pi.base.font.setColor(pi.textColor(pi.base.font.color()).baseColor); - if (is_deleted_) - pi.base.font.setStrikeout(FONT_ON); - else if (isChanged()) - pi.base.font.setUnderbar(FONT_ON); - int const xx = x + leftOffset(pi.base.bv); - pi.pain.text(xx, y, full_label_, pi.base.font); - InsetText::draw(pi, x + labelwidth_, y); + if (non_float_) + pi.base.font.setColor(Color_error); + else + pi.base.font.setPaintColor(pi.textColor(pi.base.font.color())); + int const lo = leftOffset(pi.base.bv); + if (rtl_) { + InsetText::draw(pi, x, y); + pi.pain.text(x + dimension(*pi.base.bv).wid - labelwidth_ + lo, + y, full_label_, pi.base.font); + } else { + pi.pain.text(x + lo, y, full_label_, pi.base.font); + InsetText::draw(pi, x + labelwidth_, y); + } + // Draw the change tracking cue on the label, unless RowPainter already + // takes care of it. + if (canPaintChange(*pi.base.bv)) + pi.change.paintCue(pi, x, y, x + labelwidth_, pi.base.font); pi.base.font = tmpfont; } @@ -231,7 +240,7 @@ bool InsetCaption::getStatus(Cursor & cur, FuncRequest const & cmd, if (cur.depth() > 1) { varia = cur[cur.depth() - 2].inset().allowsCaptionVariation(type); } - status.setEnabled(varia + status.setEnabled(!is_subfloat_ && varia && buffer().params().documentClass().hasInsetLayout( from_ascii("Caption:" + type))); return true; @@ -290,24 +299,19 @@ int InsetCaption::plaintext(odocstringstream & os, } -int InsetCaption::docbook(odocstream & os, - OutputParams const & runparams) const +void InsetCaption::docbook(XMLStream &, OutputParams const &) const { - int ret; - os << ""; - ret = InsetText::docbook(os, runparams); - os << "\n"; - return ret; + // This function should never be called (rather InsetFloat::docbook, the titles should be skipped in floats). } -docstring InsetCaption::xhtml(XHTMLStream & xs, OutputParams const & rp) const +docstring InsetCaption::xhtml(XMLStream & xs, OutputParams const & rp) const { if (rp.html_disable_captions) return docstring(); InsetLayout const & il = getLayout(); string const & tag = il.htmltag(); - string attr = il.htmlattr(); + string attr = il.htmlGetAttrString(); if (!type_.empty()) { string const our_class = "float-caption-" + type_; size_t const loc = attr.find("class='"); @@ -316,13 +320,22 @@ docstring InsetCaption::xhtml(XHTMLStream & xs, OutputParams const & rp) const else attr = attr + " class='" + our_class + "'"; } - xs << html::StartTag(tag, attr); + xs << xml::StartTag(tag, attr); docstring def = getCaptionAsHTML(xs, rp); - xs << html::EndTag(tag); + xs << xml::EndTag(tag); return def; } +docstring InsetCaption::toolTip(BufferView const & bv, int x, int y) const +{ + if (non_float_) + return _("Standard captions are not allowed outside floats. You will get a LaTeX error.\n" + "For captions outside floats, you can use the 'nonfloat' LaTeX package."); + return InsetText::toolTip(bv, x, y); +} + + void InsetCaption::getArgument(otexstream & os, OutputParams const & runparams) const { @@ -363,7 +376,19 @@ int InsetCaption::getCaptionAsPlaintext(odocstream & os, } -docstring InsetCaption::getCaptionAsHTML(XHTMLStream & xs, +void InsetCaption::getCaptionAsDocBook(XMLStream & xs, + OutputParams const & runparams) const +{ + if (runparams.docbook_in_float) + return; + + // Ignore full_label_, as the DocBook processor will deal with the numbering. + InsetText::XHTMLOptions opts = InsetText::WriteInnerTag; + InsetText::docbook(xs, runparams, opts); +} + + +docstring InsetCaption::getCaptionAsHTML(XMLStream & xs, OutputParams const & runparams) const { xs << full_label_ << ' '; @@ -387,9 +412,10 @@ void InsetCaption::updateBuffer(ParIterator const & it, UpdateType utype, bool c is_deleted_ = deleted; // Memorize type for addToToc(). floattype_ = type; - if (type.empty() || type == "senseless") - full_label_ = master.B_("Senseless!!! "); - else { + if (type.empty() || type == "senseless") { + full_label_ = master.B_("Orphaned caption:"); + non_float_ = true; + } else { // FIXME: life would be _much_ simpler if listings was // listed in Floating. docstring name; @@ -425,10 +451,10 @@ void InsetCaption::updateBuffer(ParIterator const & it, UpdateType utype, bool c sec += from_ascii(" "); sec += bformat(from_ascii("(%1$s)"), labelstring); } - if (!sec.empty()) - full_label_ = bformat(from_ascii("%1$s %2$s: "), name, sec); - else - full_label_ = bformat(from_ascii("%1$s #: "), name); + if (sec.empty()) + sec = from_ascii("#"); + full_label_ = bformat(master.B_("%1$s %2$s: [[Caption label (ex. Figure 1: )]]"), name, sec); + non_float_ = false; } // Do the real work now.