+ Font newfont = font;
+
+ if (toggleall) {
+ // Toggling behaves as follows: We check the first character of the
+ // selection. If it's (say) got EMPH on, then we set to off; if off,
+ // then to on. With families and the like, we set it to INHERIT, if
+ // we already have it.
+ CursorSlice const & sl = cur.selBegin();
+ Text const & text = *sl.text();
+ Paragraph const & par = text.getPar(sl.pit());
+
+ // get font at the position
+ Font oldfont = par.getFont(cur.bv().buffer().params(), sl.pos(),
+ text.outerFont(sl.pit()));
+ FontInfo const & oldfi = oldfont.fontInfo();
+
+ FontInfo & newfi = newfont.fontInfo();
+
+ FontFamily newfam = newfi.family();
+ if (newfam != INHERIT_FAMILY && newfam != IGNORE_FAMILY &&
+ newfam == oldfi.family())
+ newfi.setFamily(INHERIT_FAMILY);
+
+ FontSeries newser = newfi.series();
+ if (newser == BOLD_SERIES && oldfi.series() == BOLD_SERIES)
+ newfi.setSeries(INHERIT_SERIES);
+
+ FontShape newshp = newfi.shape();
+ if (newshp != INHERIT_SHAPE && newshp != IGNORE_SHAPE &&
+ newshp == oldfi.shape())
+ newfi.setShape(INHERIT_SHAPE);
+
+ ColorCode newcol = newfi.color();
+ if (newcol != Color_none && newcol != Color_inherit
+ && newcol != Color_ignore && newcol == oldfi.color())
+ newfi.setColor(Color_none);
+
+ // ON/OFF ones
+ if (newfi.emph() == FONT_TOGGLE)
+ newfi.setEmph(oldfi.emph() == FONT_OFF ? FONT_ON : FONT_OFF);
+ if (newfi.underbar() == FONT_TOGGLE)
+ newfi.setUnderbar(oldfi.underbar() == FONT_OFF ? FONT_ON : FONT_OFF);
+ if (newfi.strikeout() == FONT_TOGGLE)
+ newfi.setStrikeout(oldfi.strikeout() == FONT_OFF ? FONT_ON : FONT_OFF);
+ if (newfi.uuline() == FONT_TOGGLE)
+ newfi.setUuline(oldfi.uuline() == FONT_OFF ? FONT_ON : FONT_OFF);
+ if (newfi.uwave() == FONT_TOGGLE)
+ newfi.setUwave(oldfi.uwave() == FONT_OFF ? FONT_ON : FONT_OFF);
+ if (newfi.noun() == FONT_TOGGLE)
+ newfi.setNoun(oldfi.noun() == FONT_OFF ? FONT_ON : FONT_OFF);
+ if (newfi.number() == FONT_TOGGLE)
+ newfi.setNumber(oldfi.number() == FONT_OFF ? FONT_ON : FONT_OFF);
+ }