Add visible space. After long discussion the solution is part of InsetSpace.

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

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39367 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Pavel Sanda 2011-07-23 18:40:21 +00:00
parent 950d926a9b
commit 5005facace
10 changed files with 69 additions and 11 deletions

View File

@ -11,6 +11,10 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
-----------------------
2011-07-02 Pavel Sanda <sanda@lyx.org>
* Format incremented to 414 (rXXXX)
New InsetSpace param \textvisiblespace
2011-02-15 Richard Heck <rgheck@comcast.net>
* Format incremented to 413 (r37682)
New buffer param \html_css_as_file to control whether

View File

@ -25,11 +25,15 @@ import sys, os
# Uncomment only what you need to import, please.
from parser_tools import find_token, find_end_of_inset
#from parser_tools import find_token, find_end_of, find_tokens, \
#find_token_exact, find_end_of_inset, find_end_of_layout, \
#find_token_backwards, is_in_inset, get_value, get_quoted_value, \
#del_token, check_token, get_option_value
from lyx2lyx_tools import put_cmd_in_ert
#from lyx2lyx_tools import add_to_preamble, insert_to_preamble, \
# put_cmd_in_ert, lyx2latex, latex_length, revert_flex_inset, \
# revert_font_attrs, hex2ratio, str2bool
@ -53,6 +57,16 @@ import sys, os
###
###############################################################################
def revert_visible_space(document):
"Revert InsetSpace visible into its ERT counterpart"
i = 0
while True:
i = find_token(document.body, "\\begin_inset space \\textvisiblespace{}", i)
if i == -1:
return
end = find_end_of_inset(document.body, i)
subst = put_cmd_in_ert("\\textvisiblespace{}")
document.body[i:end + 1] = subst
##
@ -60,10 +74,10 @@ import sys, os
#
supported_versions = ["2.1.0","2.1"]
convert = [#[414, []]
convert = [[414, []]
]
revert = [#[413, []]
revert = [[413, [revert_visible_space]]
]

View File

@ -199,6 +199,7 @@ Menuset
Menu "context-space"
Item "Interword Space|w" "inset-modify space \space{}"
Item "Protected Space|o" "inset-modify space ~"
Item "Visible Space|a" "inset-modify space \textvisiblespace{}"
Item "Thin Space|T" "inset-modify space \thinspace{}"
Item "Negative Thin Space|N" "inset-modify space \negthinspace{}"
Item "Half Quad Space (Enskip)|k" "inset-modify space \enskip{}"

View File

@ -392,6 +392,7 @@ Menuset
Separator
Item "Protected Space|P" "space-insert protected"
Item "Interword Space|w" "space-insert normal"
Item "Visible Space|i" "space-insert visible"
Item "Thin Space|T" "space-insert thin"
Item "Horizontal Space...|o" "dialog-show-new-inset space"
Item "Horizontal Line...|L" "dialog-show-new-inset line"

View File

@ -128,7 +128,7 @@ namespace {
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
int const LYX_FORMAT = 413; // rgh: html_css_as_file
int const LYX_FORMAT = 414; //ps : visible space
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -475,8 +475,8 @@ void LyXAction::init()
* \var lyx::FuncCode lyx::LFUN_SPACE_INSERT
* \li Action: Inserts one of horizontal space insets.
* \li Syntax: space-insert <NAME> [<LEN>]
* \li Params: <NAME>: normal, protected, thin, quad, qquad, enspace, enskip,
negthinspace, hfill, hfill*, dotfill, hrulefill, hspace,
* \li Params: <NAME>: normal, protected, visible, thin, quad, qquad, enspace,
enskip, negthinspace, hfill, hfill*, dotfill, hrulefill, hspace,
hspace* \n
<LEN>: length for custom spaces (hspace, hspace* for protected)
* \li Origin: JSpitzm, 20 May 2003, Mar 17 2008

View File

@ -382,6 +382,8 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
isp.kind = InsetSpaceParams::NORMAL;
else if (name == "protected")
isp.kind = InsetSpaceParams::PROTECTED;
else if (name == "visible")
isp.kind = InsetSpaceParams::VISIBLE;
else if (name == "thin")
isp.kind = InsetSpaceParams::THIN;
else if (isp.math && name == "med")

View File

@ -61,6 +61,7 @@ GuiHSpace::GuiHSpace(bool math_mode, QWidget * parent)
spacingCO->addItem(qt_("Double Quad (2 em)"));
spacingCO->addItem(qt_("Horizontal Fill"));
spacingCO->addItem(qt_("Custom"));
spacingCO->addItem(qt_("Visible Space"));
}
connect(spacingCO, SIGNAL(highlighted(QString)),
@ -96,7 +97,8 @@ void GuiHSpace::changedSlot()
void GuiHSpace::enableWidgets()
{
int const selection = spacingCO->currentIndex();
bool const custom = (selection == spacingCO->count() - 1);
bool const custom = (math_mode_ && selection == 9) ||
(!math_mode_ && selection == 7);
valueLE->setEnabled(custom);
unitCO->setEnabled(custom);
if (math_mode_) {
@ -130,6 +132,10 @@ void GuiHSpace::paramsToDialog(Inset const * inset)
item = 0;
protect = !params.math;
break;
case InsetSpaceParams::VISIBLE:
item = 8;
protect = true;
break;
case InsetSpaceParams::THIN:
item = params.math ? 0 : 1;
break;
@ -312,6 +318,9 @@ docstring GuiHSpace::dialogToParams() const
params.kind = InsetSpaceParams::CUSTOM;
params.length = GlueLength(widgetsToLength(valueLE, unitCO));
break;
case 8:
params.kind = InsetSpaceParams::VISIBLE;
break;
}
return from_ascii(InsetSpace::params2string(params));
}

View File

@ -70,6 +70,9 @@ docstring InsetSpace::toolTip(BufferView const &, int, int) const
case InsetSpaceParams::PROTECTED:
message = _("Protected Space");
break;
case InsetSpaceParams::VISIBLE:
message = _("Visible Space");
break;
case InsetSpaceParams::THIN:
message = _("Thin Space");
break;
@ -215,6 +218,7 @@ void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
dim.wid = fm.width(char_type('M')) / 2;
break;
case InsetSpaceParams::PROTECTED:
case InsetSpaceParams::VISIBLE:
case InsetSpaceParams::NORMAL:
dim.wid = fm.width(char_type(' '));
break;
@ -349,7 +353,8 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const
xp[0] = x;
yp[0] = y - max(h / 4, 1);
if (params_.kind == InsetSpaceParams::NORMAL ||
params_.kind == InsetSpaceParams::PROTECTED) {
params_.kind == InsetSpaceParams::PROTECTED ||
params_.kind == InsetSpaceParams::VISIBLE) {
xp[1] = x; yp[1] = y;
xp[2] = x + w; yp[2] = y;
} else {
@ -359,15 +364,18 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const
xp[3] = x + w;
yp[3] = y - max(h / 4, 1);
Color col = Color_special;
if (params_.kind == InsetSpaceParams::PROTECTED ||
params_.kind == InsetSpaceParams::ENSPACE ||
params_.kind == InsetSpaceParams::NEGTHIN ||
params_.kind == InsetSpaceParams::NEGMEDIUM ||
params_.kind == InsetSpaceParams::NEGTHICK ||
params_.kind == InsetSpaceParams::CUSTOM_PROTECTED)
pi.pain.lines(xp, yp, 4, Color_latex);
else
pi.pain.lines(xp, yp, 4, Color_special);
col = Color_latex;
else if (params_.kind == InsetSpaceParams::VISIBLE)
col = Color_foreground;
pi.pain.lines(xp, yp, 4, col);
}
@ -381,6 +389,9 @@ void InsetSpaceParams::write(ostream & os) const
case InsetSpaceParams::PROTECTED:
os << "~";
break;
case InsetSpaceParams::VISIBLE:
os << "\\textvisiblespace{}";
break;
case InsetSpaceParams::THIN:
os << "\\thinspace{}";
break;
@ -459,6 +470,8 @@ void InsetSpaceParams::read(Lexer & lex)
kind = InsetSpaceParams::NORMAL;
else if (command == "~")
kind = InsetSpaceParams::PROTECTED;
else if (command == "\\textvisiblespace{}")
kind = InsetSpaceParams::VISIBLE;
else if (command == "\\thinspace{}")
kind = InsetSpaceParams::THIN;
else if (math && command == "\\medspace{}")
@ -535,6 +548,9 @@ void InsetSpace::latex(otexstream & os, OutputParams const & runparams) const
else
os << (runparams.free_spacing ? ' ' : '~');
break;
case InsetSpaceParams::VISIBLE:
os << (runparams.free_spacing ? " " : "\\textvisiblespace{}");
break;
case InsetSpaceParams::THIN:
os << (runparams.free_spacing ? " " : "\\,");
break;
@ -646,8 +662,13 @@ int InsetSpace::docbook(odocstream & os, OutputParams const &) const
case InsetSpaceParams::ENSKIP:
os << " ";
break;
// FIXME For spaces and dashes look here:
// http://oreilly.com/catalog/docbook/book2/iso-pub.html
case InsetSpaceParams::PROTECTED:
// FIXME &blank; ?
case InsetSpaceParams::VISIBLE:
case InsetSpaceParams::ENSPACE:
// FIXME &thinsp; ?
case InsetSpaceParams::THIN:
case InsetSpaceParams::MEDIUM:
case InsetSpaceParams::THICK:
@ -705,6 +726,10 @@ docstring InsetSpace::xhtml(XHTMLStream & xs, OutputParams const &) const
case InsetSpaceParams::NEGTHICK:
output ="&nbsp;";
break;
// no XHTML entity, only unicode code for space character exists
case InsetSpaceParams::VISIBLE:
output ="&#x2423;";
break;
case InsetSpaceParams::HFILL:
case InsetSpaceParams::HFILL_PROTECTED:
case InsetSpaceParams::DOTFILL:

View File

@ -30,6 +30,8 @@ struct InsetSpaceParams {
NORMAL,
/// Protected (no break) space ('~')
PROTECTED,
/// Visible ("open box") space ('\textvisiblespace')
VISIBLE,
/// Thin space ('\,')
THIN,
/// Medium space ('\:')