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"
47 InsetCharStyle::InsetCharStyle(BufferParams const & bp, string const s)
48 : InsetCollapsable(bp, Collapsed)
54 InsetCharStyle::InsetCharStyle(BufferParams const & bp,
56 : InsetCollapsable(bp, Collapsed)
58 params_.name = il.name;
63 InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
64 : InsetCollapsable(in), params_(in.params_)
68 Inset * InsetCharStyle::clone() const
70 return new InsetCharStyle(*this);
74 bool InsetCharStyle::undefined() const
76 return layout_.labelstring == from_utf8("UNDEFINED");
80 void InsetCharStyle::setLayout(InsetLayout il)
86 docstring const InsetCharStyle::editMessage() const
88 return _("Opened CharStyle Inset");
92 void InsetCharStyle::write(Buffer const & buf, ostream & os) const
95 InsetCollapsable::write(buf, os);
99 void InsetCharStyle::read(Buffer const & buf, Lexer & lex)
102 InsetCollapsable::read(buf, lex);
106 bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
108 Font tmpfont = mi.base.font;
109 getDrawFont(mi.base.font);
110 mi.base.font.reduce(Font(Font::ALL_SANE));
111 mi.base.font.realize(tmpfont);
112 bool changed = InsetCollapsable::metrics(mi, dim);
113 mi.base.font = tmpfont;
118 void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
120 setPosCache(pi, x, y);
122 Font tmpfont = pi.base.font;
123 getDrawFont(pi.base.font);
124 // I don't understand why the above .reduce and .realize aren't
125 //needed, or even wanted, here. It just works. -- MV 10.04.2005
126 InsetCollapsable::draw(pi, x, y);
127 pi.base.font = tmpfont;
131 void InsetCharStyle::getDrawFont(Font & font) const
137 void InsetCharStyle::doDispatch(Cursor & cur, FuncRequest & cmd)
139 InsetCollapsable::doDispatch(cur, cmd);
143 bool InsetCharStyle::getStatus(Cursor & cur, FuncRequest const & cmd,
144 FuncStatus & status) const
146 switch (cmd.action) {
147 // paragraph breaks not allowed in charstyle insets
148 case LFUN_BREAK_PARAGRAPH:
149 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
150 case LFUN_BREAK_PARAGRAPH_SKIP:
151 status.enabled(false);
155 return InsetCollapsable::getStatus(cur, cmd, status);
160 int InsetCharStyle::plaintext(Buffer const & buf, odocstream & os,
161 OutputParams const & runparams) const
163 return InsetText::plaintext(buf, os, runparams);
167 int InsetCharStyle::docbook(Buffer const & buf, odocstream & os,
168 OutputParams const & runparams) const
170 ParagraphList::const_iterator beg = paragraphs().begin();
171 ParagraphList::const_iterator par = paragraphs().begin();
172 ParagraphList::const_iterator end = paragraphs().end();
176 sgml::openTag(os, layout_.latexname,
177 par->getID(buf, runparams) + layout_.latexparam);
179 for (; par != end; ++par) {
180 par->simpleDocBookOnePar(buf, os, runparams,
181 outerFont(std::distance(beg, par),
186 sgml::closeTag(os, layout_.latexname);
192 void InsetCharStyle::textString(Buffer const & buf, odocstream & os) const
194 os << paragraphs().begin()->asString(buf, true);
198 void InsetCharStyleParams::write(ostream & os) const
200 os << "CharStyle " << name << "\n";
204 void InsetCharStyleParams::read(Lexer & lex)
208 string token = lex.getString();
210 if (token == "CharStyle") {
212 name = lex.getString();
215 // This is handled in Collapsable
216 else if (token == "status") {
217 lex.pushToken(token);