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"
21 #include "support/gettext.h"
22 #include "support/lstrings.h"
26 using namespace lyx::support;
30 InsetMathFont::InsetMathFont(Buffer * buf, latexkeys const * key)
31 : InsetMathNest(buf, 1), key_(key)
35 Inset * InsetMathFont::clone() const
37 return new InsetMathFont(*this);
41 InsetMath::mode_type InsetMathFont::currentMode() const
43 if (key_->extra == "mathmode")
45 if (key_->extra == "textmode")
47 return UNDECIDED_MODE;
51 bool InsetMathFont::lockedMode() const
53 if (key_->extra == "forcetext")
59 void InsetMathFont::metrics(MetricsInfo & mi, Dimension & dim) const
61 FontSetChanger dummy(mi.base, key_->name);
62 cell(0).metrics(mi, dim);
67 void InsetMathFont::draw(PainterInfo & pi, int x, int y) const
69 FontSetChanger dummy(pi.base, key_->name);
70 cell(0).draw(pi, x + 1, y);
71 drawMarkers(pi, x, y);
72 setPosCache(pi, x, y);
76 void InsetMathFont::metricsT(TextMetricsInfo const & mi, Dimension &) const
80 cell(0).metricsT(mi, dim);
84 void InsetMathFont::drawT(TextPainter & pain, int x, int y) const
86 cell(0).drawT(pain, x, y);
90 docstring InsetMathFont::name() const
96 void InsetMathFont::validate(LaTeXFeatures & features) const
98 InsetMathNest::validate(features);
99 if (features.runparams().isLaTeX()) {
100 // Make sure amssymb is put in preamble if Blackboard Bold or
102 if (key_->name == "mathfrak" || key_->name == "mathbb")
103 features.require("amssymb");
104 if (key_->name == "text" || key_->name == "textnormal"
105 || (key_->name.length() == 6 && key_->name.substr(0, 4) == "text"))
106 features.require("amstext");
107 if (key_->name == "mathscr")
108 features.require("mathrsfs");
109 if (key_->name == "textipa")
110 features.require("tipa");
111 if (key_->name == "ce" || key_->name == "cf")
112 features.require("mhchem");
113 } else if (features.runparams().math_flavor == OutputParams::MathAsHTML) {
114 features.addCSSSnippet(
115 "span.normal{font: normal normal normal inherit serif;}\n"
116 "span.fraktur{font: normal normal normal inherit cursive;}\n"
117 "span.bold{font: normal normal bold inherit serif;}\n"
118 "span.script{font: normal normal normal inherit cursive;}\n"
119 "span.italic{font: italic normal normal inherit serif;}\n"
120 "span.sans{font: normal normal normal inherit sans-serif;}\n"
121 "span.monospace{font: normal normal normal inherit monospace;}\n"
122 "span.noun{font: normal small-caps normal inherit normal;}");
127 // The fonts we want to support are listed in lib/symbols
128 void InsetMathFont::htmlize(HtmlStream & os) const
130 // FIXME These are not quite right, because they do not nest
131 // correctly. A proper fix would presumably involve tracking
132 // the fonts already in effect.
134 docstring const & tag = key_->name;
135 if (tag == "mathnormal" || tag == "mathrm"
136 || tag == "text" || tag == "textnormal"
137 || tag == "textrm" || tag == "textup"
140 else if (tag == "frak" || tag == "mathfrak")
142 else if (tag == "mathbb" || tag == "mathbf"
145 else if (tag == "mathcal")
147 else if (tag == "mathit" || tag == "textsl"
148 || tag == "emph" || tag == "textit")
150 else if (tag == "mathsf" || tag == "textsf")
152 else if (tag == "mathtt" || tag == "texttt")
153 variant = "monospace";
154 else if (tag == "textipa" || tag == "textsc" || tag == "noun")
157 docstring const beg = (tag.size() < 4) ? from_ascii("") : tag.substr(0, 4);
158 if (!variant.empty()) {
159 os << MTag("span", "class='" + variant + "'")
167 // The fonts we want to support are listed in lib/symbols
168 void InsetMathFont::mathmlize(MathStream & os) const
170 // FIXME These are not quite right, because they do not nest
171 // correctly. A proper fix would presumably involve tracking
172 // the fonts already in effect.
174 docstring const & tag = key_->name;
175 if (tag == "mathnormal" || tag == "mathrm"
176 || tag == "text" || tag == "textnormal"
177 || tag == "textrm" || tag == "textup"
180 else if (tag == "frak" || tag == "mathfrak")
182 else if (tag == "mathbb" || tag == "mathbf"
185 else if (tag == "mathcal")
187 else if (tag == "mathit" || tag == "textsl"
188 || tag == "emph" || tag == "textit")
190 else if (tag == "mathsf" || tag == "textsf")
191 variant = "sans-serif";
192 else if (tag == "mathtt" || tag == "texttt")
193 variant = "monospace";
194 // no support at present for textipa, textsc, noun
196 if (!variant.empty()) {
197 os << MTag("mstyle", "mathvariant='" + variant + "'")
205 void InsetMathFont::infoize(odocstream & os) const
207 os << bformat(_("Font: %1$s"), key_->name);