3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "insetvspace.h"
21 #include "metricsinfo.h"
24 #include "frontends/Painter.h"
25 #include "frontends/font_metrics.h"
27 #include "support/std_sstream.h"
30 using std::istringstream;
32 using std::ostringstream;
38 InsetVSpace::InsetVSpace(VSpace const & space)
43 std::auto_ptr<InsetBase> InsetVSpace::clone() const
45 return std::auto_ptr<InsetBase>(new InsetVSpace(*this));
49 void InsetVSpace::read(Buffer const &, LyXLex & lex)
53 space_ = VSpace(lex.getString());
58 void InsetVSpace::write(Buffer const &, ostream & os) const
60 os << "VSpace " << space_.asLyXCommand();
64 void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const
67 if (space_.kind() != VSpace::NONE) {
68 int const arrow_size = 4;
69 int const space_size = space_.inPixels(*mi.base.bv);
73 int const min_size = max(3 * arrow_size, font_metrics::maxHeight(font));
75 if (space_.length().len().value() < 0.0)
78 size = max(min_size, space_size);
89 void InsetVSpace::draw(PainterInfo & pi, int x, int y) const
91 static std::string const label = _("Vertical Space");
96 //if (space_.kind() == VSpace::NONE)
99 int const arrow_size = 4;
100 int const start = y - dim_.asc;
101 int const end = y + dim_.des;
103 // the label to display (if any)
105 // y-values for top arrow
107 // y-values for bottom arrow
110 str = label + " (" + space_.asLyXCommand() + ")";
112 if (space_.kind() == VSpace::VFILL) {
116 // adding or removing space
117 bool const added = space_.kind() != VSpace::LENGTH ||
118 space_.length().len().value() > 0.0;
119 ty1 = added ? (start + arrow_size) : start;
120 ty2 = added ? start : (start + arrow_size);
121 by1 = added ? (end - arrow_size) : end;
122 by2 = added ? end : (end - arrow_size);
125 int const midx = xo_ + arrow_size;
126 int const rightx = midx + arrow_size;
134 font.setColor(LColor::added_space);
137 font_metrics::rectText(str, font, w, a, d);
139 pi.pain.rectText(x + 2 * arrow_size + 5, y + d,
140 str, font, LColor::none, LColor::none);
143 pi.pain.line(x, ty1, midx, ty2, LColor::added_space);
144 pi.pain.line(midx, ty2, rightx, ty1, LColor::added_space);
147 pi.pain.line(x, by1, midx, by2, LColor::added_space);
148 pi.pain.line(midx, by2, rightx, by1, LColor::added_space);
151 pi.pain.line(midx, ty2, midx, by2, LColor::added_space);
155 int InsetVSpace::latex(Buffer const & buf, ostream & os,
156 OutputParams const &) const
158 os << space_.asLatexCommand(buf.params()) << '\n';
163 int InsetVSpace::plaintext(Buffer const &, ostream & os,
164 OutputParams const &) const
171 int InsetVSpace::linuxdoc(Buffer const &, std::ostream & os,
172 OutputParams const &) const
179 int InsetVSpace::docbook(Buffer const &, std::ostream & os,
180 OutputParams const &) const
187 string const InsetVSpaceMailer::name_ = "vspace";
190 InsetVSpaceMailer::InsetVSpaceMailer(InsetVSpace & inset)
195 string const InsetVSpaceMailer::inset2string(Buffer const &) const
197 return params2string(inset_.space_);
201 void InsetVSpaceMailer::string2params(string const & in, VSpace & vspace)
203 //lyxerr << "\nInsetVSpaceMailer::string2params, got: '" << in << "'" << endl;
210 istringstream data(in);
216 string const name = lex.getString();
219 // This is part of the inset proper that is usually swallowed
220 // by Buffer::readInset
223 vspace = VSpace(lex.getString());
228 string const InsetVSpaceMailer::params2string(VSpace const & vspace)
231 data << name_ << ' ' << vspace.asLyXCommand();