]> git.lyx.org Git - lyx.git/commitdiff
Introduce strikeout text style (strike-through)
authorPavel Sanda <sanda@lyx.org>
Sun, 3 May 2009 22:45:14 +0000 (22:45 +0000)
committerPavel Sanda <sanda@lyx.org>
Sun, 3 May 2009 22:45:14 +0000 (22:45 +0000)
http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg150743.html

Somewhat related to http://www.lyx.org/trac/ticket/4248 .

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29523 a592a061-630c-0410-9148-cb99ea01b6c8

16 files changed:
lib/bind/cua.bind
lib/lyx2lyx/lyx_2_0.py
src/Buffer.cpp
src/Font.cpp
src/FontInfo.cpp
src/FontInfo.h
src/FuncCode.h
src/LyXAction.cpp
src/Text.cpp
src/Text3.cpp
src/frontends/qt4/GuiCharacter.cpp
src/frontends/qt4/GuiCharacter.h
src/frontends/qt4/GuiPainter.cpp
src/frontends/qt4/GuiPainter.h
src/insets/InsetCollapsable.cpp
src/insets/InsetTabular.cpp

index cd9be2e8bed4d645414a89d1e9499d7475910434..9e826cc2990683dcb59bc03f2095e6eda4f888eb 100644 (file)
@@ -62,6 +62,7 @@
 #\bind "C-k"                   "font-noun"             # 'k' for capitals
 \bind "C-u"                    "font-underline"
 \bind "C-S-P"                  "font-typewriter" # 'P' for Program
+\bind "C-S-O"                  "font-strikeout"
 
 \bind "C-m"                    "math-mode"
 \bind "C-S-M"                  "math-display"
index 63280f62a419e1a9c23c5ccfbe73f632214fa0a8..85b169cad6b250ad74f4b3cf99b8453a5454f9b7 100644 (file)
@@ -604,6 +604,14 @@ def revert_printindexall(document):
             document.body[i:k+1] = subst
         i = i + 1
 
+def revert_strikeout(document):
+    " Reverts \\strike character style "
+    while True:
+        i = find_token(document.body, '\\strikeout', 0)
+        if i == -1:
+            return
+        del document.body[i]
+
 
 ##
 # Conversion hub
@@ -618,10 +626,12 @@ convert = [[346, []],
            [351, []],
            [352, [convert_splitindex]],
            [353, []],
-           [354, []]
+           [354, []],
+           [355, []]
           ]
 
-revert =  [[353, [revert_printindexall]],
+revert =  [[354, [revert_strikeout]],
+           [353, [revert_printindexall]],
            [352, [revert_subindex]],
            [351, [revert_splitindex]],
            [350, [revert_backgroundcolor]],
index bc3585ebe9bb57856bf8fdb496aaf303d98b5157..077a5e2ff8e80f034a0cd5253e2ac1cc02ec3720 100644 (file)
@@ -125,7 +125,7 @@ namespace {
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 354;  // jspitzm: support for \print[sub]index*
+int const LYX_FORMAT = 355;  // sanda: support for \\sout
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
index 234314e05b7a00297b05a8116231d899fe08caf2..814a9a0680e68bc93feb2320bd97ccd4dedf9789 100644 (file)
@@ -175,6 +175,9 @@ docstring const stateText(FontInfo const & f)
        if (f.underbar() != FONT_INHERIT)
                os << bformat(_("Underline %1$s, "),
                              _(GUIMiscNames[f.underbar()]));
+       if (f.strikeout() != FONT_INHERIT)
+               os << bformat(_("Strikeout %1$s, "),
+                             _(GUIMiscNames[f.strikeout()]));
        if (f.noun() != FONT_INHERIT)
                os << bformat(_("Noun %1$s, "),
                              _(GUIMiscNames[f.noun()]));
@@ -329,6 +332,8 @@ FontInfo lyxRead(Lexer & lex, FontInfo const & fi)
 
                        if (ttok == "no_bar") {
                                f.setUnderbar(FONT_OFF);
+                       } else if (ttok == "no_strikeout") {
+                               f.setStrikeout(FONT_OFF);
                        } else if (ttok == "no_emph") {
                                f.setEmph(FONT_OFF);
                        } else if (ttok == "no_noun") {
@@ -337,6 +342,8 @@ FontInfo lyxRead(Lexer & lex, FontInfo const & fi)
                                f.setEmph(FONT_ON);
                        } else if (ttok == "underbar") {
                                f.setUnderbar(FONT_ON);
+                       } else if (ttok == "strikeout") {
+                               f.setStrikeout(FONT_ON);
                        } else if (ttok == "noun") {
                                f.setNoun(FONT_ON);
                        } else {
@@ -388,6 +395,9 @@ void Font::lyxWriteChanges(Font const & orgfont,
                break;
                }
        }
+       if (orgfont.fontInfo().strikeout() != bits_.strikeout()) {
+               os << "\\strikeout " << LyXMiscNames[bits_.strikeout()] << "\n";
+       }
        if (orgfont.fontInfo().noun() != bits_.noun()) {
                os << "\\noun " << LyXMiscNames[bits_.noun()] << "\n";
        }
@@ -526,6 +536,11 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
                count += 10;
                env = true; //We have opened a new environment
        }
+       if (f.strikeout() == FONT_ON) {
+               os << "\\sout{";
+               count += 6;
+               env = true; //We have opened a new environment
+       }
        // \noun{} is a LyX special macro
        if (f.noun() == FONT_ON) {
                os << "\\noun{";
@@ -595,6 +610,11 @@ int Font::latexWriteEndChanges(odocstream & os, BufferParams const & bparams,
                ++count;
                env = true; // Size change need not bother about closing env.
        }
+       if (f.strikeout() == FONT_ON) {
+               os << '}';
+               ++count;
+               env = true; // Size change need not bother about closing env.
+       }
        if (f.noun() == FONT_ON) {
                os << '}';
                ++count;
@@ -654,6 +674,7 @@ string Font::toString(bool const toggle) const
           << "size " << bits_.size() << '\n'
           << "emph " << bits_.emph() << '\n'
           << "underbar " << bits_.underbar() << '\n'
+          << "strikeout " << bits_.strikeout() << '\n'
           << "noun " << bits_.noun() << '\n'
           << "number " << bits_.number() << '\n'
           << "color " << bits_.color() << '\n'
@@ -695,7 +716,8 @@ bool Font::fromString(string const & data, bool & toggle)
                        bits_.setSize(FontSize(next));
 
                } else if (token == "emph" || token == "underbar" ||
-                          token == "noun" || token == "number") {
+                          token == "noun" || token == "number" ||
+                          token == "strikeout") {
 
                        int const next = lex.getInteger();
                        FontState const misc = FontState(next);
@@ -704,6 +726,8 @@ bool Font::fromString(string const & data, bool & toggle)
                                bits_.setEmph(misc);
                        else if (token == "underbar")
                                bits_.setUnderbar(misc);
+                       else if (token == "strikeout")
+                               bits_.setStrikeout(misc);
                        else if (token == "noun")
                                bits_.setNoun(misc);
                        else if (token == "number")
@@ -747,6 +771,11 @@ void Font::validate(LaTeXFeatures & features) const
                features.require("noun");
                LYXERR(Debug::LATEX, "Noun enabled. Font: " << to_utf8(stateText(0)));
        }
+       if (bits_.strikeout() == FONT_ON) {
+               LYXERR(Debug::LATEX, "font.strikeout: " << bits_.strikeout());
+               features.require("ulem");
+               LYXERR(Debug::LATEX, "Strikeout enabled. Font: " << to_utf8(stateText(0)));
+       }
        switch (bits_.color()) {
                case Color_none:
                case Color_inherit:
@@ -791,6 +820,7 @@ ostream & operator<<(ostream & os, FontInfo const & f)
                //<< " background " << f.background()
                << " emph " << f.emph()
                << " underbar " << f.underbar()
+               << " strikeout " << f.strikeout()
                << " noun " << f.noun()
                << " number " << f.number();
 }
index 00a9da165dfe538b817d5a2aaf979326f1c071ac..a1f30c5e057675613ce39a0d379ef0f70e08b54d 100644 (file)
@@ -32,6 +32,7 @@ FontInfo const sane_font(
        FONT_OFF,
        FONT_OFF,
        FONT_OFF,
+       FONT_OFF,
        FONT_OFF);
 
 FontInfo const inherit_font(
@@ -44,6 +45,7 @@ FontInfo const inherit_font(
        FONT_INHERIT,
        FONT_INHERIT,
        FONT_INHERIT,
+       FONT_INHERIT,
        FONT_OFF);
 
 FontInfo const ignore_font(
@@ -56,6 +58,7 @@ FontInfo const ignore_font(
        FONT_IGNORE,
        FONT_IGNORE,
        FONT_IGNORE,
+       FONT_IGNORE,
        FONT_IGNORE);
 
 
@@ -141,6 +144,8 @@ void FontInfo::reduce(FontInfo const & tmplt)
                emph_ = FONT_INHERIT;
        if (underbar_ == tmplt.underbar_)
                underbar_ = FONT_INHERIT;
+       if (strikeout_ == tmplt.strikeout_)
+               strikeout_ = FONT_INHERIT;
        if (noun_ == tmplt.noun_)
                noun_ = FONT_INHERIT;
        if (color_ == tmplt.color_)
@@ -176,6 +181,9 @@ FontInfo & FontInfo::realize(FontInfo const & tmplt)
        if (underbar_ == FONT_INHERIT)
                underbar_ = tmplt.underbar_;
 
+       if (strikeout_ == FONT_INHERIT)
+               strikeout_ = tmplt.strikeout_;
+
        if (noun_ == FONT_INHERIT)
                noun_ = tmplt.noun_;
 
@@ -252,6 +260,7 @@ void FontInfo::update(FontInfo const & newfont, bool toggleall)
 
        setEmph(setMisc(newfont.emph_, emph_));
        setUnderbar(setMisc(newfont.underbar_, underbar_));
+       setStrikeout(setMisc(newfont.strikeout_, strikeout_));
        setNoun(setMisc(newfont.noun_, noun_));
        setNumber(setMisc(newfont.number_, number_));
 
@@ -272,7 +281,7 @@ bool FontInfo::resolved() const
        return (family_ != INHERIT_FAMILY && series_ != INHERIT_SERIES
                && shape_ != INHERIT_SHAPE && size_ != FONT_SIZE_INHERIT
                && emph_ != FONT_INHERIT && underbar_ != FONT_INHERIT
-               && noun_ != FONT_INHERIT
+               && strikeout_ != FONT_INHERIT && noun_ != FONT_INHERIT
                && color_ != Color_inherit
                && background_ != Color_inherit);
 }
index 8db78d5ce1a492fe52e7ada0ecbf491cc1df9ba2..10d72354efeae4717d1a723c7922957895500a7a 100644 (file)
@@ -41,11 +41,12 @@ public:
                ColorCode background,
                FontState emph,
                FontState underbar,
+               FontState strikeout,
                FontState noun,
                FontState number)
                : family_(family), series_(series), shape_(shape), size_(size), 
                color_(color), background_(background), paint_color_(), emph_(emph),
-               underbar_(underbar), noun_(noun), number_(number)
+               underbar_(underbar), strikeout_(strikeout), noun_(noun), number_(number)
        {}
 
        /// Decreases font size by one
@@ -67,6 +68,8 @@ public:
        void setEmph(FontState e) { emph_ = e; }
        FontState underbar() const { return underbar_; }
        void setUnderbar(FontState u) { underbar_ = u; }
+       FontState strikeout() const { return strikeout_; }
+       void setStrikeout(FontState s) { strikeout_ = s; }
        FontState noun() const { return noun_; }
        void setNoun(FontState n) { noun_ = n; }
        FontState number() const { return number_; }
@@ -145,6 +148,8 @@ private:
        ///
        FontState underbar_;
        ///
+       FontState strikeout_;
+       ///
        FontState noun_;
        ///
        FontState number_;
@@ -161,6 +166,7 @@ inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
                && lhs.background_ == rhs.background_
                && lhs.emph_ == rhs.emph_
                && lhs.underbar_ == rhs.underbar_
+               && lhs.strikeout_ == rhs.strikeout_
                && lhs.noun_ == rhs.noun_
                && lhs.number_ == rhs.number_;
 }
index d2257a4e3718d535a35ca7b65e13a7fc62a46110..ee72e93910041923d937c5ff4c61ab285d56e41d 100644 (file)
@@ -181,13 +181,13 @@ enum FuncCode
        LFUN_FONT_DEFAULT,
        // 125
        LFUN_FONT_UNDERLINE,
+       LFUN_FONT_STRIKEOUT,
        LFUN_FONT_SIZE,
        LFUN_FONT_STATE,
        LFUN_WORD_UPCASE,
-       LFUN_WORD_LOWCASE,
        // 130
+       LFUN_WORD_LOWCASE,
        LFUN_WORD_CAPITALIZE,
-       LFUN_LABEL_INSERT,
        LFUN_DEPTH_DECREMENT,
        LFUN_DEPTH_INCREMENT,
        LFUN_MENU_OPEN,                 // used in bindings as of 20060905
@@ -429,7 +429,7 @@ enum FuncCode
        LFUN_MATH_BIGDELIM,
        LFUN_MATH_FONT_STYLE,
        LFUN_SECTION_SELECT,            // vfr, 20090503
-
+       LFUN_LABEL_INSERT,
 
        LFUN_LASTACTION                 // end of the table
 };
index d6d540d723089021ce7d7f129afe7a19d8353454..9deb2f9cfb82477cf10a5d8f95b42a3bb6606b61 100644 (file)
@@ -1227,6 +1227,14 @@ void LyXAction::init()
  * \endvar
  */
                { LFUN_FONT_UNDERLINE, "font-underline", Noop, Layout },
+/*!
+ * \var lyx::FuncCode lyx::LFUN_FONT_STRIKEOUT
+ * \li Action: Toggles strikeout (strike-through) in the font (selection-wise).
+ * \li Syntax: font-strikeout
+ * \li Origin: sanda, 3 May 2009
+ * \endvar
+ */
+               { LFUN_FONT_STRIKEOUT, "font-strikeout", Noop, Layout },
 /*!
  * \var lyx::FuncCode lyx::LFUN_FONT_EMPH
  * \li Action: Toggles the emphasis font style (selection-wise).
index 7f1861efb2e35649797c38ae95c6f568a4a4f116..c31739f82fd225893618b7956f29d4bfd4729899 100644 (file)
@@ -188,6 +188,9 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                else
                        lex.printError("Unknown bar font flag "
                                       "`$$Token'");
+       } else if (token == "\\strikeout") {
+               lex.next();
+               font.fontInfo().setStrikeout(font.setLyXMisc(lex.getString()));
        } else if (token == "\\noun") {
                lex.next();
                font.fontInfo().setNoun(font.setLyXMisc(lex.getString()));
index 1a8eee0f090b04ca4dfee1b57dce8a2ce4a29d1d..3481d5f300864435fb05f91e29c72bc361b1e3f5 100644 (file)
@@ -1722,6 +1722,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                break;
        }
 
+       case LFUN_FONT_STRIKEOUT: {
+               Font font(ignore_font, ignore_language);
+               font.fontInfo().setStrikeout(FONT_TOGGLE);
+               toggleAndShow(cur, this, font);
+               break;
+       }
        case LFUN_FONT_UNDERLINE: {
                Font font(ignore_font, ignore_language);
                font.fontInfo().setUnderbar(FONT_TOGGLE);
@@ -2423,6 +2429,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_MATH_SUPERSCRIPT:
        case LFUN_FONT_DEFAULT:
        case LFUN_FONT_UNDERLINE:
+       case LFUN_FONT_STRIKEOUT:
        case LFUN_FONT_SIZE:
        case LFUN_LANGUAGE:
        case LFUN_TEXTSTYLE_APPLY:
index 28dfdb560ccffaf12ac54852440491ad6b8fc327..8aad329218e80a3759bb5edb25974c973b6164f9 100644 (file)
@@ -76,6 +76,7 @@ static QList<BarPair> barData()
        bars << BarPair(qt_("No change"), IGNORE);
        bars << BarPair(qt_("Emph"),      EMPH_TOGGLE);
        bars << BarPair(qt_("Underbar"),  UNDERBAR_TOGGLE);
+       bars << BarPair(qt_("Strikeout"),  STRIKEOUT_TOGGLE);
        bars << BarPair(qt_("Noun"),      NOUN_TOGGLE);
        bars << BarPair(qt_("Reset"),     INHERIT);
        return bars;
@@ -276,6 +277,9 @@ static FontState getBar(FontInfo const & fi)
        if (fi.underbar() == FONT_TOGGLE)
                return UNDERBAR_TOGGLE;
 
+       if (fi.strikeout() == FONT_TOGGLE)
+               return STRIKEOUT_TOGGLE;
+
        if (fi.noun() == FONT_TOGGLE)
                return NOUN_TOGGLE;
 
@@ -294,6 +298,7 @@ static void setBar(FontInfo & fi, FontState val)
        case IGNORE:
                fi.setEmph(FONT_IGNORE);
                fi.setUnderbar(FONT_IGNORE);
+               fi.setStrikeout(FONT_IGNORE);
                fi.setNoun(FONT_IGNORE);
                break;
 
@@ -305,6 +310,10 @@ static void setBar(FontInfo & fi, FontState val)
                fi.setUnderbar(FONT_TOGGLE);
                break;
 
+       case STRIKEOUT_TOGGLE:
+               fi.setStrikeout(FONT_TOGGLE);
+               break;
+
        case NOUN_TOGGLE:
                fi.setNoun(FONT_TOGGLE);
                break;
@@ -312,6 +321,7 @@ static void setBar(FontInfo & fi, FontState val)
        case INHERIT:
                fi.setEmph(FONT_INHERIT);
                fi.setUnderbar(FONT_INHERIT);
+               fi.setStrikeout(FONT_INHERIT);
                fi.setNoun(FONT_INHERIT);
                break;
        }
index 16cdc239473ae031b61051aa2fa6999f20d31b72..02cd2feca4280932a818d6bf2e4335161b839a11 100644 (file)
@@ -37,6 +37,8 @@ enum FontState {
        ///
        NOUN_TOGGLE,
        ///
+       STRIKEOUT_TOGGLE,
+       ///
        INHERIT
 };
 
index fd2f96b39db0ebd17389dde96d03e0d3234ffd16..470b928e38e3c3155c8360db99593007509daf95 100644 (file)
@@ -336,6 +336,8 @@ int GuiPainter::text(int x, int y, docstring const & s,
                textwidth = smallCapsText(x, y, str, f);
                if (f.underbar() == FONT_ON)
                        underline(f, x, y, textwidth);
+               if (f.strikeout() == FONT_ON)
+                       strikeoutLine(f, x, y, textwidth);
                return textwidth;
        }
 
@@ -345,6 +347,8 @@ int GuiPainter::text(int x, int y, docstring const & s,
        textwidth = fm.width(s);
        if (f.underbar() == FONT_ON)
                underline(f, x, y, textwidth);
+       if (f.strikeout() == FONT_ON)
+               strikeoutLine(f, x, y, textwidth);
 
        if (!isDrawingEnabled())
                return textwidth;
@@ -534,6 +538,20 @@ void GuiPainter::underline(FontInfo const & f, int x, int y, int width)
 }
 
 
+void GuiPainter::strikeoutLine(FontInfo const & f, int x, int y, int width)
+{
+       FontMetrics const & fm = theFontMetrics(f);
+
+       int const middle = max((fm.maxHeight() / 4), 1);
+       int const height =  middle/3;
+
+       if (height < 2)
+               line(x, y - middle, x + width, y - middle, f.realColor());
+       else
+               fillRectangle(x, y - middle, width, height, f.realColor());
+}
+
+
 void GuiPainter::dashedUnderline(FontInfo const & f, int x, int y, int width)
 {
        FontMetrics const & fm = theFontMetrics(f);
index 232798e11ea594972a81373236d4c1242b7705ec..8e75438884689f17deed634d330ccfb688ea11cd 100644 (file)
@@ -129,6 +129,9 @@ private:
        /// check the font, and if set, draw an dashed underline
        void dashedUnderline(FontInfo const & f,
                int x, int y, int width);
+       /// check the font, and if set, draw an strike-through line
+       void strikeoutLine(FontInfo const & f,
+               int x, int y, int width);
 
        /// draw a bevelled button border
        void buttonFrame(int x, int y, int w, int h);
index 8606de4e3188ec0407a8e9dab994fb9235feb114..32f7633f2081139d5d7656432912e2b89389160e 100644 (file)
@@ -688,6 +688,7 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_FONT_SIZE:
        case LFUN_FONT_STATE:
        case LFUN_FONT_UNDERLINE:
+       case LFUN_FONT_STRIKEOUT:
        case LFUN_FOOTNOTE_INSERT:
        case LFUN_HYPERLINK_INSERT:
        case LFUN_INDEX_INSERT:
index 1ad481ec41e2bf5fb6d898003dde4429b9eb66c0..014ca949118a83bdebc693a2e905686e1cba462a 100644 (file)
@@ -3712,6 +3712,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_TEXTSTYLE_UPDATE:
        case LFUN_FONT_SIZE:
        case LFUN_FONT_UNDERLINE:
+       case LFUN_FONT_STRIKEOUT:
        case LFUN_LANGUAGE:
        case LFUN_WORD_CAPITALIZE:
        case LFUN_WORD_UPCASE: