2 * \file InsetMathFont.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathFont.h"
15 #include "LaTeXFeatures.h"
17 #include "MathStream.h"
18 #include "MathParser.h"
19 #include "MetricsInfo.h"
26 InsetMathFont::InsetMathFont(Buffer * buf, latexkeys const * key)
27 : InsetMathNest(buf, 1), key_(key)
31 Inset * InsetMathFont::clone() const
33 return new InsetMathFont(*this);
37 InsetMath::mode_type InsetMathFont::currentMode() const
39 if (key_->extra == "mathmode")
41 if (key_->extra == "textmode")
43 return UNDECIDED_MODE;
47 bool InsetMathFont::lockedMode() const
49 if (key_->extra == "forcetext")
55 void InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const
57 FontSetChanger dummy(mi.base, key_->name);
58 cell(0).metrics(mi, dim);
63 void InsetMathFont::draw(PainterInfo & pi, int x, int y) const
65 FontSetChanger dummy(pi.base, key_->name.c_str());
66 cell(0).draw(pi, x + 1, y);
67 drawMarkers(pi, x, y);
68 setPosCache(pi, x, y);
72 void InsetMathFont::metricsT(TextMetricsInfo const & mi, Dimension &) const
76 cell(0).metricsT(mi, dim);
80 void InsetMathFont::drawT(TextPainter & pain, int x, int y) const
82 cell(0).drawT(pain, x, y);
86 docstring InsetMathFont::name() const
92 void InsetMathFont::validate(LaTeXFeatures & features) const
94 InsetMathNest::validate(features);
95 if (features.runparams().isLaTeX()) {
96 // Make sure amssymb is put in preamble if Blackboard Bold or
98 if (key_->name == "mathfrak" || key_->name == "mathbb")
99 features.require("amssymb");
100 if (key_->name == "text" || key_->name == "textnormal"
101 || (key_->name.length() == 6 && key_->name.substr(0, 4) == "text"))
102 features.require("amstext");
103 if (key_->name == "mathscr")
104 features.require("mathrsfs");
105 if (key_->name == "textipa")
106 features.require("tipa");
107 if (key_->name == "ce" || key_->name == "cf")
108 features.require("mhchem");
109 } else if (features.runparams().math_flavor == OutputParams::MathAsHTML) {
110 features.addCSSSnippet(
111 "span.normal{font: normal normal normal inherit serif;}\n"
112 "span.fraktur{font: normal normal normal inherit cursive;}\n"
113 "span.bold{font: normal normal bold inherit serif;}\n"
114 "span.script{font: normal normal normal inherit cursive;}\n"
115 "span.italic{font: italic normal normal inherit serif;}\n"
116 "span.sans{font: normal normal normal inherit sans-serif;}\n"
117 "span.monospace{font: normal normal normal inherit monospace;}\n"
118 "span.noun{font: normal small-caps normal inherit normal;}");
123 // The fonts we want to support are listed in lib/symbols
124 void InsetMathFont::htmlize(HtmlStream & os) const
126 // FIXME These are not quite right, because they do not nest
127 // correctly. A proper fix would presumably involve tracking
128 // the fonts already in effect.
130 docstring const & tag = key_->name;
131 if (tag == "mathnormal" || tag == "mathrm"
132 || tag == "text" || tag == "textnormal"
133 || tag == "textrm" || tag == "textup"
136 else if (tag == "frak" || tag == "mathfrak")
138 else if (tag == "mathbb" || tag == "mathbf"
141 else if (tag == "mathcal")
143 else if (tag == "mathit" || tag == "textsl"
144 || tag == "emph" || tag == "textit")
146 else if (tag == "mathsf" || tag == "textsf")
148 else if (tag == "mathtt" || tag == "texttt")
149 variant = "monospace";
150 else if (tag == "textipa" || tag == "textsc" || tag == "noun")
153 docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4);
154 if (!variant.empty()) {
155 os << MTag("span", "class='" + variant + "'")
163 // The fonts we want to support are listed in lib/symbols
164 void InsetMathFont::mathmlize(MathStream & os) const
166 // FIXME These are not quite right, because they do not nest
167 // correctly. A proper fix would presumably involve tracking
168 // the fonts already in effect.
170 docstring const & tag = key_->name;
171 if (tag == "mathnormal" || tag == "mathrm"
172 || tag == "text" || tag == "textnormal"
173 || tag == "textrm" || tag == "textup"
176 else if (tag == "frak" || tag == "mathfrak")
178 else if (tag == "mathbb" || tag == "mathbf"
181 else if (tag == "mathcal")
183 else if (tag == "mathit" || tag == "textsl"
184 || tag == "emph" || tag == "textit")
186 else if (tag == "mathsf" || tag == "textsf")
187 variant = "sans-serif";
188 else if (tag == "mathtt" || tag == "texttt")
189 variant = "monospace";
190 // no support at present for textipa, textsc, noun
192 if (!variant.empty()) {
193 os << MTag("mstyle", "mathvariant='" + variant + "'")
201 void InsetMathFont::infoize(odocstream & os) const
203 os << "Font: " << key_->name;