-MetricsBase::MetricsBase(BufferView * b, FontInfo const & f, int w)
- : bv(b), font(f), style(LM_ST_TEXT), fontname("mathnormal"),
- textwidth(w)
-{}
+Changer MetricsBase::changeFontSet(string const & name)
+{
+ RefChanger<MetricsBase> rc = make_save(*this);
+ ColorCode oldcolor = font.color();
+ string const oldname = fontname;
+ fontname = name;
+ if (isMathFont(name) || isMathFont(oldname))
+ font = sane_font;
+ augmentFont(font, name);
+ font.setSize(rc->old.font.size());
+ font.setStyle(rc->old.font.style());
+ if (name == "emph") {
+ font.setColor(oldcolor);
+ if (rc->old.font.shape() != UP_SHAPE)
+ font.setShape(UP_SHAPE);
+ else
+ font.setShape(ITALIC_SHAPE);
+ } else if (name != "lyxtex"
+ && ((isTextFont(oldname) && oldcolor != Color_foreground)
+ || (isMathFont(oldname) && oldcolor != Color_math)))
+ font.setColor(oldcolor);
+#if __cplusplus >= 201402L
+ return rc;
+#else
+ /** In theory, this is not needed with C++11, and modern compilers
+ * will complain in C++11 mode, but gcc 4.9 requires this. */
+ return std::move(rc);
+#endif
+}
+
+
+Changer MetricsBase::changeEnsureMath(Inset::mode_type mode)
+{
+ switch (mode) {
+ case Inset::UNDECIDED_MODE:
+ return noChange();
+ case Inset::TEXT_MODE:
+ return isMathFont(fontname) ? changeFontSet("textnormal") : noChange();
+ case Inset::MATH_MODE:
+ // FIXME:
+ // \textit{\ensuremath{\text{a}}}
+ // should appear in italics
+ return isTextFont(fontname) ? changeFontSet("mathnormal"): noChange();
+ }
+ return noChange();
+}