+ docstring im;
+ InsetMathFont const * f = asFontInset();
+
+ switch(font.fontInfo().family()) {
+ case ROMAN_FAMILY:
+ if (!f || (f->name() != "textrm" && f->name() != "mathrm"))
+ im = currentMode() != MATH_MODE ? from_ascii("textrm")
+ : from_ascii("mathrm");
+ break;
+ case SANS_FAMILY:
+ if (!f || (f->name() != "textsf" && f->name() != "mathsf"))
+ im = currentMode() != MATH_MODE ? from_ascii("textsf")
+ : from_ascii("mathsf");
+ break;
+ case TYPEWRITER_FAMILY:
+ if (!f || (f->name() != "texttt" && f->name() != "mathtt"))
+ im = currentMode() != MATH_MODE ? from_ascii("texttt")
+ : from_ascii("mathtt");
+ break;
+ case SYMBOL_FAMILY:
+ case CMR_FAMILY:
+ case CMSY_FAMILY:
+ case CMM_FAMILY:
+ case CMEX_FAMILY:
+ case MSA_FAMILY:
+ case MSB_FAMILY:
+ case DS_FAMILY:
+ case EUFRAK_FAMILY:
+ case RSFS_FAMILY:
+ case STMARY_FAMILY:
+ case WASY_FAMILY:
+ case ESINT_FAMILY:
+ case INHERIT_FAMILY:
+ case IGNORE_FAMILY:
+ break;
+ }
+ if (!im.empty()) {
+ handleNest(cur, createInsetMath(im, cur.buffer()));
+ im.clear();
+ include_previous_change = true;
+ }
+
+ switch(font.fontInfo().series()) {
+ case MEDIUM_SERIES:
+ if (!f || (f->name() != "textmd" && f->name() != "mathrm"))
+ im = currentMode() != MATH_MODE ? from_ascii("textmd")
+ : from_ascii("mathrm");
+ break;
+ case BOLD_SERIES:
+ if (!f || (f->name() != "textbf" && f->name() != "mathbf"))
+ im = currentMode() != MATH_MODE ? from_ascii("textbf")
+ : from_ascii("boldsymbol");
+ break;
+ case INHERIT_SERIES:
+ case IGNORE_SERIES:
+ break;
+ }
+ if (!im.empty()) {
+ if (multiple_cells) {
+ cur.setCursor(sel_begin);
+ cur.idx() = 0;
+ cur.pos() = 0;
+ cur.resetAnchor();
+ cur.setCursor(sel_end);
+ cur.pos() = cur.lastpos();
+ cur.setSelection();
+ } else if (include_previous_change && selection) {
+ cur.setSelection();
+ }
+ handleNest(cur, createInsetMath(im, cur.buffer()));
+ im.clear();
+ include_previous_change = true;
+ }
+
+ switch(font.fontInfo().shape()) {
+ case UP_SHAPE:
+ if (!f || (f->name() != "textup" && f->name() != "mathrm"))
+ im = currentMode() != MATH_MODE ? from_ascii("textup")
+ : from_ascii("mathrm");
+ break;
+ case ITALIC_SHAPE:
+ if (!f || (f->name() != "textit" && f->name() != "mathit"))
+ im = currentMode() != MATH_MODE ? from_ascii("textit")
+ : from_ascii("mathit");
+ break;
+ case SLANTED_SHAPE:
+ if (!f || f->name() != "textsl")
+ im = currentMode() != MATH_MODE ? from_ascii("textsl")
+ : docstring();
+ break;
+ case SMALLCAPS_SHAPE:
+ if (!f || f->name() != "textsc")
+ im = currentMode() != MATH_MODE ? from_ascii("textsc")
+ : docstring();
+ break;
+ case INHERIT_SHAPE:
+ case IGNORE_SHAPE:
+ break;
+ }
+ if (!im.empty()) {
+ if (multiple_cells) {
+ cur.setCursor(sel_begin);
+ cur.idx() = 0;
+ cur.pos() = 0;
+ cur.resetAnchor();
+ cur.setCursor(sel_end);
+ cur.pos() = cur.lastpos();
+ cur.setSelection();
+ } else if (include_previous_change && selection) {
+ cur.setSelection();
+ }
+ handleNest(cur, createInsetMath(im, cur.buffer()));
+ im.clear();
+ include_previous_change = true;
+ }
+
+ switch(font.fontInfo().size()) {
+ case TINY_SIZE:
+ im = from_ascii("tiny");
+ break;
+ case SCRIPT_SIZE:
+ im = from_ascii("scriptsize");
+ break;
+ case FOOTNOTE_SIZE:
+ im = from_ascii("footnotesize");
+ break;
+ case SMALL_SIZE:
+ im = from_ascii("small");
+ break;
+ case NORMAL_SIZE:
+ im = from_ascii("normalsize");
+ break;
+ case LARGE_SIZE:
+ im = from_ascii("large");
+ break;
+ case LARGER_SIZE:
+ im = from_ascii("Large");
+ break;
+ case LARGEST_SIZE:
+ im = from_ascii("LARGE");
+ break;
+ case HUGE_SIZE:
+ im = from_ascii("huge");
+ break;
+ case HUGER_SIZE:
+ im = from_ascii("Huge");
+ break;
+ case INCREASE_SIZE:
+ case DECREASE_SIZE:
+ case INHERIT_SIZE:
+ case IGNORE_SIZE:
+ break;
+ }
+ if (!im.empty()) {
+ if (multiple_cells) {
+ cur.setCursor(sel_begin);
+ cur.idx() = 0;
+ cur.pos() = 0;
+ cur.resetAnchor();
+ cur.setCursor(sel_end);
+ cur.pos() = cur.lastpos();
+ cur.setSelection();
+ } else if (include_previous_change && selection) {
+ cur.setSelection();
+ }
+ handleNest(cur, createInsetMath(im, cur.buffer()));
+ im.clear();
+ include_previous_change = true;
+ }
+
+ InsetMathDecoration const * d = multiple_cells
+ ? nullptr : asDecorationInset();
+ docstring const name = d ? d->name() : docstring();
+
+ if ((font.fontInfo().underbar() == FONT_OFF && name == "uline") ||
+ (font.fontInfo().uuline() == FONT_OFF && name == "uuline") ||
+ (font.fontInfo().uwave() == FONT_OFF && name == "uwave")) {
+ if (include_previous_change) {
+ if (!selection)
+ cur.popForward();
+ cur.setSelection();
+ }
+ docstring const beg = '\\' + name + '{';
+ docstring const end = from_ascii("}");
+ docstring const sel2 = cur.selectionAsString(false);
+ cutSelection(cur, false);
+ cur.pos() = 0;
+ cur.setSelection();
+ docstring const sel1 = cur.selectionAsString(false);
+ cur.pos() = cur.lastpos();
+ cur.setSelection();
+ docstring const sel3 = cur.selectionAsString(false);
+ cur.mathForward(false);
+ cur.setSelection();
+ cutSelection(cur, false);
+ MathData ar;
+ if (!sel1.empty()) {
+ mathed_parse_cell(ar, beg + sel1 + end);
+ cur.insert(ar);
+ }
+ cur.resetAnchor();
+ if (!sel2.empty()) {
+ mathed_parse_cell(ar, sel2);
+ cur.insert(ar);
+ }
+ if (!sel3.empty()) {
+ pos_type pos = cur.pos();
+ mathed_parse_cell(ar, beg + sel3 + end);
+ cur.insert(ar);
+ cur.pos() = pos;
+ }
+ cur.setSelection();
+ sel_begin = cur.selectionBegin();
+ sel_end = cur.selectionEnd();
+ include_previous_change = false;
+ }
+
+ if (font.fontInfo().underbar() == FONT_ON) {
+ if (!d || name != "uline")
+ im = from_ascii("uline");
+ } else if (font.fontInfo().uuline() == FONT_ON) {
+ if (!d || name != "uuline")
+ im = from_ascii("uuline");
+ } else if (font.fontInfo().uwave() == FONT_ON) {
+ if (!d || name != "uwave")
+ im = from_ascii("uwave");
+ }
+
+ if (!im.empty()) {
+ if (multiple_cells) {
+ cur.setCursor(sel_begin);
+ cur.idx() = 0;
+ cur.pos() = 0;
+ cur.resetAnchor();
+ cur.setCursor(sel_end);
+ cur.pos() = cur.lastpos();
+ cur.setSelection();
+ } else if (include_previous_change && selection) {
+ cur.setSelection();
+ }
+ handleNest(cur, createInsetMath(im, cur.buffer()));
+ im.clear();
+ include_previous_change = true;
+ }
+