2 * \file InsetCharStyle.cpp
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"
18 #include "BufferParams.h"
19 #include "BufferView.h"
20 #include "DispatchResult.h"
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
28 #include "MetricsInfo.h"
29 #include "Paragraph.h"
30 #include "paragraph_funcs.h"
33 #include "frontends/FontMetrics.h"
34 #include "frontends/Painter.h"
36 #include "support/convert.h"
45 using std::istringstream;
48 using std::ostringstream;
52 InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
53 : InsetCollapsable(bp, Collapsed)
59 InsetCharStyle::InsetCharStyle(BufferParams const & bp,
61 : InsetCollapsable(bp, Collapsed)
63 params_.name = il.name;
68 InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
69 : InsetCollapsable(in), params_(in.params_)
73 auto_ptr<Inset> InsetCharStyle::doClone() const
75 return auto_ptr<Inset>(new InsetCharStyle(*this));
79 bool InsetCharStyle::undefined() const
81 return layout_.labelstring == from_utf8("UNDEFINED");
85 void InsetCharStyle::setLayout(InsetLayout il)
91 docstring const InsetCharStyle::editMessage() const
93 return _("Opened CharStyle Inset");
97 void InsetCharStyle::write(Buffer const & buf, ostream & os) const
100 InsetCollapsable::write(buf, os);
104 void InsetCharStyle::read(Buffer const & buf, Lexer & lex)
107 InsetCollapsable::read(buf, lex);
111 bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
113 Font tmpfont = mi.base.font;
114 getDrawFont(mi.base.font);
115 mi.base.font.reduce(Font(Font::ALL_SANE));
116 mi.base.font.realize(tmpfont);
117 bool changed = InsetCollapsable::metrics(mi, dim);
118 mi.base.font = tmpfont;
123 void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
125 setPosCache(pi, x, y);
127 Font tmpfont = pi.base.font;
128 getDrawFont(pi.base.font);
129 // I don't understand why the above .reduce and .realize aren't
130 //needed, or even wanted, here. It just works. -- MV 10.04.2005
131 InsetCollapsable::draw(pi, x, y);
132 pi.base.font = tmpfont;
136 void InsetCharStyle::getDrawFont(Font & font) const
142 void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd)
144 InsetCollapsable::doDispatch(cur, cmd);
148 bool InsetCharStyle::getStatus(Cursor & cur, FuncRequest const & cmd,
149 FuncStatus & status) const
151 switch (cmd.action) {
152 // paragraph breaks not allowed in charstyle insets
153 case LFUN_BREAK_PARAGRAPH:
154 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
155 case LFUN_BREAK_PARAGRAPH_SKIP:
156 status.enabled(false);
160 return InsetCollapsable::getStatus(cur, cmd, status);
165 int InsetCharStyle::plaintext(Buffer const & buf, odocstream & os,
166 OutputParams const & runparams) const
168 return InsetText::plaintext(buf, os, runparams);
172 int InsetCharStyle::docbook(Buffer const & buf, odocstream & os,
173 OutputParams const & runparams) const
175 ParagraphList::const_iterator beg = paragraphs().begin();
176 ParagraphList::const_iterator par = paragraphs().begin();
177 ParagraphList::const_iterator end = paragraphs().end();
181 sgml::openTag(os, layout_.latexname,
182 par->getID(buf, runparams) + layout_.latexparam);
184 for (; par != end; ++par) {
185 par->simpleDocBookOnePar(buf, os, runparams,
186 outerFont(std::distance(beg, par),
191 sgml::closeTag(os, layout_.latexname);
197 void InsetCharStyle::textString(Buffer const & buf, odocstream & os) const
199 os << paragraphs().begin()->asString(buf, true);
203 void InsetCharStyleParams::write(ostream & os) const
205 os << "CharStyle " << name << "\n";
209 void InsetCharStyleParams::read(Lexer & lex)
213 string token = lex.getString();
215 if (token == "CharStyle") {
217 name = lex.getString();
220 // This is handled in Collapsable
221 else if (token == "status") {
222 lex.pushToken(token);