2 * \file insetcharstyle.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
7 * \author Martin Vermeer
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
15 #include "insetcharstyle.h"
17 #include "BufferView.h"
18 #include "dispatchresult.h"
19 #include "funcrequest.h"
21 #include "LaTeXFeatures.h"
25 #include "metricsinfo.h"
26 #include "paragraph.h"
28 #include "support/std_sstream.h"
33 using std::istringstream;
35 using std::ostringstream;
38 void InsetCharStyle::init()
40 setInsetName("CharStyle");
45 InsetCharStyle::InsetCharStyle(BufferParams const & bp,
46 CharStyles::iterator cs)
47 : InsetCollapsable(bp)
49 params_.type = cs->name;
50 params_.latextype = cs->latextype;
51 params_.latexname = cs->latexname;
52 params_.font = cs->font;
53 params_.labelfont = cs->labelfont;
58 InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
59 : InsetCollapsable(in), params_(in.params_)
65 auto_ptr<InsetBase> InsetCharStyle::clone() const
67 return auto_ptr<InsetBase>(new InsetCharStyle(*this));
71 string const InsetCharStyle::editMessage() const
73 return _("Opened CharStyle Inset");
77 void InsetCharStyle::write(Buffer const & buf, ostream & os) const
80 InsetCollapsable::write(buf, os);
84 void InsetCharStyle::read(Buffer const & buf, LyXLex & lex)
86 InsetCollapsable::read(buf, lex);
91 void InsetCharStyle::setButtonLabel()
93 LyXFont font(params_.labelfont);
94 font.realize(LyXFont(LyXFont::ALL_SANE));
96 setLabel("Style: " + params_.type);
101 void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
103 InsetCollapsable::metrics(mi, dim);
108 void InsetCharStyle::getDrawFont(LyXFont & font) const
115 InsetCharStyle::priv_dispatch(FuncRequest const & cmd,
116 idx_type & idx, pos_type & pos)
118 DispatchResult dr = InsetCollapsable::priv_dispatch(cmd, idx, pos);
126 int outputVerbatim(std::ostream & os, InsetText inset)
129 ParagraphList::iterator par = inset.paragraphs().begin();
130 ParagraphList::iterator end = inset.paragraphs().end();
132 lyx::pos_type siz = par->size();
133 for (lyx::pos_type i = 0; i < siz; ++i) {
134 if (par->isNewline(i)) {
138 os << par->getChar(i);
153 int InsetCharStyle::latex(Buffer const &, ostream & os,
154 OutputParams const &) const
156 os << "%\n\\" << params_.latexname << "{";
157 int i = outputVerbatim(os, inset);
164 int InsetCharStyle::linuxdoc(Buffer const &, std::ostream & os,
165 OutputParams const &) const
167 os << "<" << params_.latexname << ">";
168 int const i = outputVerbatim(os, inset);
169 os << "</" << params_.latexname << ">";
174 int InsetCharStyle::docbook(Buffer const &, std::ostream & os,
175 OutputParams const &) const
177 os << "<" << params_.latexname << ">";
178 int const i = outputVerbatim(os, inset);
179 os << "</" << params_.latexname << ">";
184 int InsetCharStyle::plaintext(Buffer const &, std::ostream & os,
185 OutputParams const & runparams) const
187 return outputVerbatim(os, inset);
191 void InsetCharStyle::validate(LaTeXFeatures & features) const
193 features.require(params_.type);
197 void InsetCharStyleParams::write(ostream & os) const
199 os << "CharStyle " << type << "\n";
203 void InsetCharStyleParams::read(LyXLex & lex)
207 string token = lex.getString();
212 type = lex.getString();