Introduce double underline and wavy underline styles from ulem

http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg150803.html


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29542 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Pavel Sanda 2009-05-05 09:26:28 +00:00
parent c4af79abf3
commit 6fde8f8067
16 changed files with 212 additions and 8 deletions

View File

@ -1,6 +1,10 @@
LyX file-format changes
-----------------------
2009-05-05 Pavel Sanda <sanda@lyx.org>
* Format incremented to 356: support for double and wave underline character
styles via ulem's \uuline and \uwave
2009-05-03 Pavel Sanda <sanda@lyx.org>
* Format incremented to 355: support for strikeout character
style via ulem's \sout

View File

@ -613,6 +613,20 @@ def revert_strikeout(document):
del document.body[i]
def revert_uulinewave(document):
" Reverts \\uuline and \\uwave character style "
while True:
i = find_token(document.body, '\\uuline', 0)
if i == -1:
break
del document.body[i]
while True:
i = find_token(document.body, '\\uwave', 0)
if i == -1:
return
del document.body[i]
##
# Conversion hub
#
@ -627,10 +641,12 @@ convert = [[346, []],
[352, [convert_splitindex]],
[353, []],
[354, []],
[355, []]
[355, []],
[356, []]
]
revert = [[354, [revert_strikeout]],
revert = [[355, [revert_uulinewave]],
[354, [revert_strikeout]],
[353, [revert_printindexall]],
[352, [revert_subindex]],
[351, [revert_splitindex]],

View 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 = 355; // sanda: support for \\sout
int const LYX_FORMAT = 356; // sanda: support for \\uuline
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -177,6 +177,12 @@ docstring const stateText(FontInfo const & f)
_(GUIMiscNames[f.underbar()]));
if (f.strikeout() != FONT_INHERIT)
os << bformat(_("Strikeout %1$s, "),
_(GUIMiscNames[f.uuline()]));
if (f.uuline() != FONT_INHERIT)
os << bformat(_("Double underline %1$s, "),
_(GUIMiscNames[f.uwave()]));
if (f.uwave() != FONT_INHERIT)
os << bformat(_("Wavy underline %1$s, "),
_(GUIMiscNames[f.strikeout()]));
if (f.noun() != FONT_INHERIT)
os << bformat(_("Noun %1$s, "),
@ -334,6 +340,10 @@ FontInfo lyxRead(Lexer & lex, FontInfo const & fi)
f.setUnderbar(FONT_OFF);
} else if (ttok == "no_strikeout") {
f.setStrikeout(FONT_OFF);
} else if (ttok == "no_uuline") {
f.setUuline(FONT_OFF);
} else if (ttok == "no_uwave") {
f.setUwave(FONT_OFF);
} else if (ttok == "no_emph") {
f.setEmph(FONT_OFF);
} else if (ttok == "no_noun") {
@ -344,6 +354,10 @@ FontInfo lyxRead(Lexer & lex, FontInfo const & fi)
f.setUnderbar(FONT_ON);
} else if (ttok == "strikeout") {
f.setStrikeout(FONT_ON);
} else if (ttok == "uuline") {
f.setUuline(FONT_ON);
} else if (ttok == "uwave") {
f.setUwave(FONT_ON);
} else if (ttok == "noun") {
f.setNoun(FONT_ON);
} else {
@ -398,6 +412,12 @@ void Font::lyxWriteChanges(Font const & orgfont,
if (orgfont.fontInfo().strikeout() != bits_.strikeout()) {
os << "\\strikeout " << LyXMiscNames[bits_.strikeout()] << "\n";
}
if (orgfont.fontInfo().uuline() != bits_.uuline()) {
os << "\\uuline " << LyXMiscNames[bits_.uuline()] << "\n";
}
if (orgfont.fontInfo().uwave() != bits_.uwave()) {
os << "\\uwave " << LyXMiscNames[bits_.uwave()] << "\n";
}
if (orgfont.fontInfo().noun() != bits_.noun()) {
os << "\\noun " << LyXMiscNames[bits_.noun()] << "\n";
}
@ -541,6 +561,16 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
count += 6;
env = true; //We have opened a new environment
}
if (f.uuline() == FONT_ON) {
os << "\\uuline{";
count += 8;
env = true; //We have opened a new environment
}
if (f.uwave() == FONT_ON) {
os << "\\uwave{";
count += 7;
env = true; //We have opened a new environment
}
// \noun{} is a LyX special macro
if (f.noun() == FONT_ON) {
os << "\\noun{";
@ -615,6 +645,16 @@ int Font::latexWriteEndChanges(odocstream & os, BufferParams const & bparams,
++count;
env = true; // Size change need not bother about closing env.
}
if (f.uuline() == FONT_ON) {
os << '}';
++count;
env = true; // Size change need not bother about closing env.
}
if (f.uwave() == FONT_ON) {
os << '}';
++count;
env = true; // Size change need not bother about closing env.
}
if (f.noun() == FONT_ON) {
os << '}';
++count;
@ -675,6 +715,8 @@ string Font::toString(bool const toggle) const
<< "emph " << bits_.emph() << '\n'
<< "underbar " << bits_.underbar() << '\n'
<< "strikeout " << bits_.strikeout() << '\n'
<< "uuline " << bits_.uuline() << '\n'
<< "uwave " << bits_.uwave() << '\n'
<< "noun " << bits_.noun() << '\n'
<< "number " << bits_.number() << '\n'
<< "color " << bits_.color() << '\n'
@ -717,6 +759,7 @@ bool Font::fromString(string const & data, bool & toggle)
} else if (token == "emph" || token == "underbar" ||
token == "noun" || token == "number" ||
token == "uuline" || token == "uwave" ||
token == "strikeout") {
int const next = lex.getInteger();
@ -728,6 +771,10 @@ bool Font::fromString(string const & data, bool & toggle)
bits_.setUnderbar(misc);
else if (token == "strikeout")
bits_.setStrikeout(misc);
else if (token == "uuline")
bits_.setUuline(misc);
else if (token == "uwave")
bits_.setUwave(misc);
else if (token == "noun")
bits_.setNoun(misc);
else if (token == "number")
@ -776,6 +823,16 @@ void Font::validate(LaTeXFeatures & features) const
features.require("ulem");
LYXERR(Debug::LATEX, "Strikeout enabled. Font: " << to_utf8(stateText(0)));
}
if (bits_.uuline() == FONT_ON) {
LYXERR(Debug::LATEX, "font.uuline: " << bits_.uuline());
features.require("ulem");
LYXERR(Debug::LATEX, "Double underline enabled. Font: " << to_utf8(stateText(0)));
}
if (bits_.uwave() == FONT_ON) {
LYXERR(Debug::LATEX, "font.uwave: " << bits_.uwave());
features.require("ulem");
LYXERR(Debug::LATEX, "Wavy underline enabled. Font: " << to_utf8(stateText(0)));
}
switch (bits_.color()) {
case Color_none:
case Color_inherit:
@ -821,6 +878,8 @@ ostream & operator<<(ostream & os, FontInfo const & f)
<< " emph " << f.emph()
<< " underbar " << f.underbar()
<< " strikeout " << f.strikeout()
<< " uuline " << f.uuline()
<< " uwave " << f.uwave()
<< " noun " << f.noun()
<< " number " << f.number();
}

View File

@ -33,6 +33,8 @@ FontInfo const sane_font(
FONT_OFF,
FONT_OFF,
FONT_OFF,
FONT_OFF,
FONT_OFF,
FONT_OFF);
FontInfo const inherit_font(
@ -46,6 +48,8 @@ FontInfo const inherit_font(
FONT_INHERIT,
FONT_INHERIT,
FONT_INHERIT,
FONT_INHERIT,
FONT_INHERIT,
FONT_OFF);
FontInfo const ignore_font(
@ -59,6 +63,8 @@ FontInfo const ignore_font(
FONT_IGNORE,
FONT_IGNORE,
FONT_IGNORE,
FONT_IGNORE,
FONT_IGNORE,
FONT_IGNORE);
@ -146,6 +152,10 @@ void FontInfo::reduce(FontInfo const & tmplt)
underbar_ = FONT_INHERIT;
if (strikeout_ == tmplt.strikeout_)
strikeout_ = FONT_INHERIT;
if (uuline_ == tmplt.uuline_)
uuline_ = FONT_INHERIT;
if (uwave_ == tmplt.uwave_)
uwave_ = FONT_INHERIT;
if (noun_ == tmplt.noun_)
noun_ = FONT_INHERIT;
if (color_ == tmplt.color_)
@ -184,6 +194,12 @@ FontInfo & FontInfo::realize(FontInfo const & tmplt)
if (strikeout_ == FONT_INHERIT)
strikeout_ = tmplt.strikeout_;
if (uuline_ == FONT_INHERIT)
uuline_ = tmplt.uuline_;
if (uwave_ == FONT_INHERIT)
uwave_ = tmplt.uwave_;
if (noun_ == FONT_INHERIT)
noun_ = tmplt.noun_;
@ -261,6 +277,8 @@ void FontInfo::update(FontInfo const & newfont, bool toggleall)
setEmph(setMisc(newfont.emph_, emph_));
setUnderbar(setMisc(newfont.underbar_, underbar_));
setStrikeout(setMisc(newfont.strikeout_, strikeout_));
setUuline(setMisc(newfont.uuline_, uuline_));
setUwave(setMisc(newfont.uwave_, uwave_));
setNoun(setMisc(newfont.noun_, noun_));
setNumber(setMisc(newfont.number_, number_));
@ -281,6 +299,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
&& uuline_ != FONT_INHERIT && uwave_ != FONT_INHERIT
&& strikeout_ != FONT_INHERIT && noun_ != FONT_INHERIT
&& color_ != Color_inherit
&& background_ != Color_inherit);

View File

@ -42,11 +42,14 @@ public:
FontState emph,
FontState underbar,
FontState strikeout,
FontState uuline,
FontState uwave,
FontState noun,
FontState number)
: family_(family), series_(series), shape_(shape), size_(size),
color_(color), background_(background), paint_color_(), emph_(emph),
underbar_(underbar), strikeout_(strikeout), noun_(noun), number_(number)
underbar_(underbar), strikeout_(strikeout), uuline_(uuline),
uwave_(uwave), noun_(noun), number_(number)
{}
/// Decreases font size by one
@ -70,6 +73,10 @@ public:
void setUnderbar(FontState u) { underbar_ = u; }
FontState strikeout() const { return strikeout_; }
void setStrikeout(FontState s) { strikeout_ = s; }
FontState uuline() const { return uuline_; }
void setUuline(FontState s) { uuline_ = s; }
FontState uwave() const { return uwave_; }
void setUwave(FontState s) { uwave_ = s; }
FontState noun() const { return noun_; }
void setNoun(FontState n) { noun_ = n; }
FontState number() const { return number_; }
@ -150,6 +157,10 @@ private:
///
FontState strikeout_;
///
FontState uuline_;
///
FontState uwave_;
///
FontState noun_;
///
FontState number_;
@ -167,6 +178,8 @@ inline bool operator==(FontInfo const & lhs, FontInfo const & rhs)
&& lhs.emph_ == rhs.emph_
&& lhs.underbar_ == rhs.underbar_
&& lhs.strikeout_ == rhs.strikeout_
&& lhs.uuline_ == rhs.uuline_
&& lhs.uwave_ == rhs.uwave_
&& lhs.noun_ == rhs.noun_
&& lhs.number_ == rhs.number_;
}

View File

@ -180,10 +180,10 @@ enum FuncCode
LFUN_FONT_SANS,
LFUN_FONT_DEFAULT,
// 125
LFUN_FONT_UNDERLINE,
LFUN_FONT_STRIKEOUT,
LFUN_FONT_SIZE,
LFUN_FONT_STATE,
LFUN_MATH_FONT_STYLE,
LFUN_LABEL_INSERT,
LFUN_WORD_UPCASE,
// 130
LFUN_WORD_LOWCASE,
@ -427,9 +427,12 @@ enum FuncCode
LFUN_BUFFER_ZOOM_OUT, // vfr, 20090330
// 330
LFUN_MATH_BIGDELIM,
LFUN_MATH_FONT_STYLE,
LFUN_SECTION_SELECT, // vfr, 20090503
LFUN_LABEL_INSERT,
LFUN_FONT_UNDERLINE,
LFUN_FONT_STRIKEOUT,
LFUN_FONT_UULINE,
// 335
LFUN_FONT_UWAVE,
LFUN_LASTACTION // end of the table
};

View File

@ -1227,6 +1227,22 @@ void LyXAction::init()
* \endvar
*/
{ LFUN_FONT_UNDERLINE, "font-underline", Noop, Layout },
/*!
* \var lyx::FuncCode lyx::LFUN_FONT_UULINE
* \li Action: Toggles double underline in the font (selection-wise).
* \li Syntax: font-underunderline
* \li Origin: sanda, 5 May 2009
* \endvar
*/
{ LFUN_FONT_UULINE, "font-underunderline", Noop, Layout },
/*!
* \var lyx::FuncCode lyx::LFUN_FONT_UWAVE
* \li Action: Toggles wavy underline in the font (selection-wise).
* \li Syntax: font-underwave
* \li Origin: sanda, 5 May 2009
* \endvar
*/
{ LFUN_FONT_UWAVE, "font-underwave", Noop, Layout },
/*!
* \var lyx::FuncCode lyx::LFUN_FONT_STRIKEOUT
* \li Action: Toggles strikeout (strike-through) in the font (selection-wise).

View File

@ -191,6 +191,12 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
} else if (token == "\\strikeout") {
lex.next();
font.fontInfo().setStrikeout(font.setLyXMisc(lex.getString()));
} else if (token == "\\uuline") {
lex.next();
font.fontInfo().setUuline(font.setLyXMisc(lex.getString()));
} else if (token == "\\uwave") {
lex.next();
font.fontInfo().setUwave(font.setLyXMisc(lex.getString()));
} else if (token == "\\noun") {
lex.next();
font.fontInfo().setNoun(font.setLyXMisc(lex.getString()));

View File

@ -1728,6 +1728,21 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
toggleAndShow(cur, this, font);
break;
}
case LFUN_FONT_UULINE: {
Font font(ignore_font, ignore_language);
font.fontInfo().setUuline(FONT_TOGGLE);
toggleAndShow(cur, this, font);
break;
}
case LFUN_FONT_UWAVE: {
Font font(ignore_font, ignore_language);
font.fontInfo().setUwave(FONT_TOGGLE);
toggleAndShow(cur, this, font);
break;
}
case LFUN_FONT_UNDERLINE: {
Font font(ignore_font, ignore_language);
font.fontInfo().setUnderbar(FONT_TOGGLE);
@ -2430,6 +2445,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_FONT_DEFAULT:
case LFUN_FONT_UNDERLINE:
case LFUN_FONT_STRIKEOUT:
case LFUN_FONT_UULINE:
case LFUN_FONT_UWAVE:
case LFUN_FONT_SIZE:
case LFUN_LANGUAGE:
case LFUN_TEXTSTYLE_APPLY:

View File

@ -76,6 +76,8 @@ 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_("Double underbar"), UULINE_TOGGLE);
bars << BarPair(qt_("Wavy underbar"), UWAVE_TOGGLE);
bars << BarPair(qt_("Strikeout"), STRIKEOUT_TOGGLE);
bars << BarPair(qt_("Noun"), NOUN_TOGGLE);
bars << BarPair(qt_("Reset"), INHERIT);
@ -280,6 +282,12 @@ static FontState getBar(FontInfo const & fi)
if (fi.strikeout() == FONT_TOGGLE)
return STRIKEOUT_TOGGLE;
if (fi.uuline() == FONT_TOGGLE)
return UULINE_TOGGLE;
if (fi.uwave() == FONT_TOGGLE)
return UWAVE_TOGGLE;
if (fi.noun() == FONT_TOGGLE)
return NOUN_TOGGLE;
@ -314,6 +322,14 @@ static void setBar(FontInfo & fi, FontState val)
fi.setStrikeout(FONT_TOGGLE);
break;
case UULINE_TOGGLE:
fi.setUuline(FONT_TOGGLE);
break;
case UWAVE_TOGGLE:
fi.setUwave(FONT_TOGGLE);
break;
case NOUN_TOGGLE:
fi.setNoun(FONT_TOGGLE);
break;
@ -322,6 +338,8 @@ static void setBar(FontInfo & fi, FontState val)
fi.setEmph(FONT_INHERIT);
fi.setUnderbar(FONT_INHERIT);
fi.setStrikeout(FONT_INHERIT);
fi.setUuline(FONT_INHERIT);
fi.setUwave(FONT_INHERIT);
fi.setNoun(FONT_INHERIT);
break;
}

View File

@ -39,6 +39,10 @@ enum FontState {
///
STRIKEOUT_TOGGLE,
///
UULINE_TOGGLE,
///
UWAVE_TOGGLE,
///
INHERIT
};

View File

@ -338,6 +338,10 @@ int GuiPainter::text(int x, int y, docstring const & s,
underline(f, x, y, textwidth);
if (f.strikeout() == FONT_ON)
strikeoutLine(f, x, y, textwidth);
if (f.uuline() == FONT_ON)
doubleUnderline(f, x, y, textwidth);
if (f.uwave() == FONT_ON)
wavyHorizontalLine(x, y, textwidth, f.realColor().baseColor);
return textwidth;
}
@ -349,6 +353,11 @@ int GuiPainter::text(int x, int y, docstring const & s,
underline(f, x, y, textwidth);
if (f.strikeout() == FONT_ON)
strikeoutLine(f, x, y, textwidth);
if (f.uuline() == FONT_ON)
doubleUnderline(f, x, y, textwidth);
if (f.uwave() == FONT_ON)
// f.color() doesn't work on some circumstances
wavyHorizontalLine(x, y, textwidth, f.realColor().baseColor);
if (!isDrawingEnabled())
return textwidth;
@ -524,6 +533,17 @@ int GuiPainter::preeditText(int x, int y, char_type c,
}
void GuiPainter::doubleUnderline(FontInfo const & f, int x, int y, int width)
{
FontMetrics const & fm = theFontMetrics(f);
int const below = max(fm.maxDescent() / 2, 2);
line(x, y + below, x + width, y + below, f.realColor());
line(x, y + below - 2, x + width, y + below - 2, f.realColor());
}
void GuiPainter::underline(FontInfo const & f, int x, int y, int width)
{
FontMetrics const & fm = theFontMetrics(f);

View File

@ -129,10 +129,15 @@ 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);
/// check the font, and if set, draw double underline
void doubleUnderline(FontInfo const & f,
int x, int y, int width);
/// draw a bevelled button border
void buttonFrame(int x, int y, int w, int h);

View File

@ -689,6 +689,8 @@ bool InsetCollapsable::getStatus(Cursor & cur, FuncRequest const & cmd,
case LFUN_FONT_STATE:
case LFUN_FONT_UNDERLINE:
case LFUN_FONT_STRIKEOUT:
case LFUN_FONT_UULINE:
case LFUN_FONT_UWAVE:
case LFUN_FOOTNOTE_INSERT:
case LFUN_HYPERLINK_INSERT:
case LFUN_INDEX_INSERT:

View File

@ -3713,6 +3713,8 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_FONT_SIZE:
case LFUN_FONT_UNDERLINE:
case LFUN_FONT_STRIKEOUT:
case LFUN_FONT_UULINE:
case LFUN_FONT_UWAVE:
case LFUN_LANGUAGE:
case LFUN_WORD_CAPITALIZE:
case LFUN_WORD_UPCASE: