mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
allow to use glue lengths in the HSpace dialog; file format change
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30724 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
64c067f2d1
commit
0b33b9d090
@ -1,6 +1,10 @@
|
||||
LyX file-format changes
|
||||
-----------------------
|
||||
|
||||
2009-07-21 Jürgen Spitzmüller <spitz@lyx.org>, Uwe Stöhr <uwestoehr@web.de>
|
||||
* Format incremented to 368: allow to use glue lengths for
|
||||
horizontal spaces.
|
||||
|
||||
2009-07-20 Uwe Stöhr <uwestoehr@web.de>
|
||||
* Format incremented to 367: allow to use percent lengths for
|
||||
vertical and horizontal spaces.
|
||||
|
@ -182,42 +182,136 @@ def latex_length(string):
|
||||
i = string.find("text%")
|
||||
if i > -1:
|
||||
percent = True
|
||||
value = string[:i]
|
||||
value = str(float(value)/100)
|
||||
return "True," + value + "\\textwidth"
|
||||
minus = string.rfind("-", 0, i)
|
||||
plus = string.rfind("+", 0, i)
|
||||
if plus == -1 and minus == -1:
|
||||
value = string[:i]
|
||||
value = str(float(value)/100)
|
||||
end = string[i+5:]
|
||||
string = value + "\\textwidth" + end
|
||||
if plus > minus:
|
||||
value = string[plus+1:i]
|
||||
value = str(float(value)/100)
|
||||
begin = string[:plus+1]
|
||||
end = string[i+5:]
|
||||
string = begin + value + "\\textwidth" + end
|
||||
if plus < minus:
|
||||
value = string[minus+1:i]
|
||||
value = str(float(value)/100)
|
||||
begin = string[:minus+1]
|
||||
string = begin + value + "\\textwidth"
|
||||
i = string.find("col%")
|
||||
if i > -1:
|
||||
percent = True
|
||||
value = string[:i]
|
||||
value = str(float(value)/100)
|
||||
return "True," + value + "\\columnwidth"
|
||||
minus = string.rfind("-", 0, i)
|
||||
plus = string.rfind("+", 0, i)
|
||||
if plus == -1 and minus == -1:
|
||||
value = string[:i]
|
||||
value = str(float(value)/100)
|
||||
end = string[i+4:]
|
||||
string = value + "\\columnwidth" + end
|
||||
if plus > minus:
|
||||
value = string[plus+1:i]
|
||||
value = str(float(value)/100)
|
||||
begin = string[:plus+1]
|
||||
end = string[i+4:]
|
||||
string = begin + value + "\\columnwidth" + end
|
||||
if plus < minus:
|
||||
value = string[minus+1:i]
|
||||
value = str(float(value)/100)
|
||||
begin = string[:minus+1]
|
||||
string = begin + value + "\\columnwidth"
|
||||
i = string.find("page%")
|
||||
if i > -1:
|
||||
percent = True
|
||||
value = string[:i]
|
||||
value = str(float(value)/100)
|
||||
return "True," + value + "\\paperwidth"
|
||||
minus = string.rfind("-", 0, i)
|
||||
plus = string.rfind("+", 0, i)
|
||||
if plus == -1 and minus == -1:
|
||||
value = string[:i]
|
||||
value = str(float(value)/100)
|
||||
end = string[i+5:]
|
||||
string = value + "\\paperwidth" + end
|
||||
if plus > minus:
|
||||
value = string[plus+1:i]
|
||||
value = str(float(value)/100)
|
||||
begin = string[:plus+1]
|
||||
end = string[i+5:]
|
||||
string = begin + value + "\\paperwidth" + end
|
||||
if plus < minus:
|
||||
value = string[minus+1:i]
|
||||
value = str(float(value)/100)
|
||||
begin = string[:minus+1]
|
||||
string = begin + value + "\\paperwidth"
|
||||
i = string.find("line%")
|
||||
if i > -1:
|
||||
percent = True
|
||||
value = string[:i]
|
||||
value = str(float(value)/100)
|
||||
return "True," + value + "\\linewidth"
|
||||
minus = string.rfind("-", 0, i)
|
||||
plus = string.rfind("+", 0, i)
|
||||
if plus == -1 and minus == -1:
|
||||
value = string[:i]
|
||||
value = str(float(value)/100)
|
||||
end = string[i+5:]
|
||||
string = value + "\\linewidth" + end
|
||||
if plus > minus:
|
||||
value = string[plus+1:i]
|
||||
value = str(float(value)/100)
|
||||
begin = string[:plus+1]
|
||||
end = string[i+5:]
|
||||
string = begin + value + "\\linewidth" + end
|
||||
if plus < minus:
|
||||
value = string[minus+1:i]
|
||||
value = str(float(value)/100)
|
||||
begin = string[:minus+1]
|
||||
string = begin + value + "\\linewidth"
|
||||
i = string.find("theight%")
|
||||
if i > -1:
|
||||
percent = True
|
||||
value = string[:i]
|
||||
value = str(float(value)/100)
|
||||
return "True," + value + "\\textheight"
|
||||
minus = string.rfind("-", 0, i)
|
||||
plus = string.rfind("+", 0, i)
|
||||
if plus == -1 and minus == -1:
|
||||
value = string[:i]
|
||||
value = str(float(value)/100)
|
||||
end = string[i+8:]
|
||||
string = value + "\\textheight" + end
|
||||
if plus > minus:
|
||||
value = string[plus+1:i]
|
||||
value = str(float(value)/100)
|
||||
begin = string[:plus+1]
|
||||
end = string[i+8:]
|
||||
string = begin + value + "\\textheight" + end
|
||||
if plus < minus:
|
||||
value = string[minus+1:i]
|
||||
value = str(float(value)/100)
|
||||
begin = string[:minus+1]
|
||||
string = begin + value + "\\textheight"
|
||||
i = string.find("pheight%")
|
||||
if i > -1:
|
||||
percent = True
|
||||
value = string[:i]
|
||||
value = str(float(value)/100)
|
||||
return "True," + value + "\\paperheight"
|
||||
minus = string.rfind("-", 0, i)
|
||||
plus = string.rfind("+", 0, i)
|
||||
if plus == -1 and minus == -1:
|
||||
value = string[:i]
|
||||
value = str(float(value)/100)
|
||||
end = string[i+8:]
|
||||
string = value + "\\paperheight" + end
|
||||
if plus > minus:
|
||||
value = string[plus+1:i]
|
||||
value = str(float(value)/100)
|
||||
begin = string[:plus+1]
|
||||
end = string[i+8:]
|
||||
string = begin + value + "\\paperheight" + end
|
||||
if plus < minus:
|
||||
value = string[minus+1:i]
|
||||
value = str(float(value)/100)
|
||||
begin = string[:minus+1]
|
||||
string = begin + value + "\\paperheight"
|
||||
if percent == False:
|
||||
return "False," + string
|
||||
|
||||
return "False," + string
|
||||
else:
|
||||
string = string.replace("+", " plus ")
|
||||
string = string.replace("-", " minus ")
|
||||
return "True," + string
|
||||
|
||||
|
||||
####################################################################
|
||||
|
||||
@ -945,6 +1039,53 @@ def revert_percent_hspace_lengths(document):
|
||||
j = i
|
||||
|
||||
|
||||
def revert_hspace_glue_lengths(document):
|
||||
" Revert HSpace glue lengths to ERT "
|
||||
i = 0
|
||||
j = 0
|
||||
while True:
|
||||
i = find_token(document.body, "\\begin_inset space \hspace{}", i)
|
||||
if i == -1:
|
||||
j = find_token(document.body, "\\begin_inset space \hspace*{}", j)
|
||||
if j == -1:
|
||||
break
|
||||
else:
|
||||
star = True
|
||||
i = j
|
||||
else:
|
||||
star = False
|
||||
# only revert when a custom length was set and when
|
||||
# it used a percent length
|
||||
o = document.body[i+1].find("\\length")
|
||||
if o == -1:
|
||||
document.warning("Error: Cannot find lenght for \\hspace!")
|
||||
break
|
||||
# search for the beginning of the value via the space
|
||||
k = document.body[i+1].find(" ")
|
||||
length = document.body[i+1][k+1:]
|
||||
# check if the length contains a plus or minus
|
||||
l = length.find("+")
|
||||
if l == -1:
|
||||
l = length.find("-")
|
||||
if l == -1:
|
||||
break
|
||||
# handle percent lengths
|
||||
length = latex_length(length)
|
||||
# latex_length returns "bool,length"
|
||||
m = length.find(",")
|
||||
percent = length[:m]
|
||||
length = length[m+1:]
|
||||
# revert the HSpace inset to ERT
|
||||
if percent == "True":
|
||||
if star == True:
|
||||
subst = [put_cmd_in_ert("\\hspace*{" + length + "}")]
|
||||
else:
|
||||
subst = [put_cmd_in_ert("\\hspace{" + length + "}")]
|
||||
document.body[i:i+3] = subst
|
||||
i = i + 2
|
||||
j = i
|
||||
|
||||
|
||||
##
|
||||
# Conversion hub
|
||||
#
|
||||
@ -971,10 +1112,12 @@ convert = [[346, []],
|
||||
[364, []],
|
||||
[365, []],
|
||||
[366, []],
|
||||
[367, []]
|
||||
[367, []],
|
||||
[368, []]
|
||||
]
|
||||
|
||||
revert = [[366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
|
||||
revert = [[367, [revert_hspace_glue_lengths]],
|
||||
[366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]],
|
||||
[365, [revert_percent_skip_lengths]],
|
||||
[364, [revert_paragraph_indentation]],
|
||||
[363, [revert_branch_filename]],
|
||||
|
@ -127,7 +127,7 @@ namespace {
|
||||
|
||||
// Do not remove the comment below, so we get merge conflict in
|
||||
// independent branches. Instead add your own.
|
||||
int const LYX_FORMAT = 367; // uwestoehr: percent lengths for the VSpace dialog
|
||||
int const LYX_FORMAT = 368; // spitz, uwestoehr: glue lengths for the HSpace dialog
|
||||
|
||||
typedef map<string, bool> DepClean;
|
||||
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
|
||||
|
@ -387,22 +387,22 @@ Inset * createInsetHelper(Buffer & buf, FuncRequest const & cmd)
|
||||
else if (name == "hrulefill")
|
||||
isp.kind = InsetSpaceParams::HRULEFILL;
|
||||
else if (name == "hspace") {
|
||||
if (len.empty() || !isValidLength(len)) {
|
||||
if (len.empty() || !isValidGlueLength(len)) {
|
||||
lyxerr << "LyX function 'space-insert hspace' "
|
||||
<< "needs a valid length argument." << endl;
|
||||
break;
|
||||
}
|
||||
isp.kind = InsetSpaceParams::CUSTOM;
|
||||
isp.length = Length(len);
|
||||
isp.length = GlueLength(len);
|
||||
}
|
||||
else if (name == "hspace*") {
|
||||
if (len.empty() || !isValidLength(len)) {
|
||||
if (len.empty() || !isValidGlueLength(len)) {
|
||||
lyxerr << "LyX function 'space-insert hspace*' "
|
||||
<< "needs a valid length argument." << endl;
|
||||
break;
|
||||
}
|
||||
isp.kind = InsetSpaceParams::CUSTOM_PROTECTED;
|
||||
isp.length = Length(len);
|
||||
isp.length = GlueLength(len);
|
||||
}
|
||||
else {
|
||||
lyxerr << "Wrong argument for LyX function 'space-insert'." << endl;
|
||||
|
@ -57,7 +57,10 @@ GuiHSpace::GuiHSpace(GuiView & lv, bool math)
|
||||
connect(fillPatternCO, SIGNAL(activated(int)),
|
||||
this, SLOT(patternChanged()));
|
||||
|
||||
valueLE->setValidator(unsignedLengthValidator(valueLE));
|
||||
if (params_.math)
|
||||
valueLE->setValidator(unsignedLengthValidator(valueLE));
|
||||
else
|
||||
valueLE->setValidator(unsignedGlueLengthValidator(valueLE));
|
||||
|
||||
// Manage the ok, apply, restore and cancel/close buttons
|
||||
bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
|
||||
@ -245,9 +248,10 @@ static void setWidgetsFromHSpace(InsetSpaceParams const & params,
|
||||
keep->setChecked(protect);
|
||||
|
||||
Length::UNIT const default_unit = Length::defaultUnit();
|
||||
if (item == (params.math ? 9 : 7))
|
||||
lengthToWidgets(value, unit, params.length, default_unit);
|
||||
else
|
||||
if (item == (params.math ? 9 : 7)) {
|
||||
string length = params.length.asString();
|
||||
lengthToWidgets(value, unit, length, default_unit);
|
||||
} else
|
||||
lengthToWidgets(value, unit, "", default_unit);
|
||||
}
|
||||
|
||||
@ -269,7 +273,7 @@ static InsetSpaceParams setHSpaceFromWidgets(int spacing,
|
||||
case 8: params.kind = InsetSpaceParams::QQUAD; break;
|
||||
case 9:
|
||||
params.kind = InsetSpaceParams::CUSTOM;
|
||||
params.length = Length(widgetsToLength(value, unit));
|
||||
params.length = GlueLength(widgetsToLength(value, unit));
|
||||
break;
|
||||
}
|
||||
return params;
|
||||
@ -323,7 +327,7 @@ static InsetSpaceParams setHSpaceFromWidgets(int spacing,
|
||||
params.kind = InsetSpaceParams::CUSTOM_PROTECTED;
|
||||
else
|
||||
params.kind = InsetSpaceParams::CUSTOM;
|
||||
params.length = Length(widgetsToLength(value, unit));
|
||||
params.length = GlueLength(widgetsToLength(value, unit));
|
||||
break;
|
||||
}
|
||||
return params;
|
||||
|
@ -53,7 +53,7 @@ InsetSpaceParams::Kind InsetSpace::kind() const
|
||||
}
|
||||
|
||||
|
||||
Length InsetSpace::length() const
|
||||
GlueLength InsetSpace::length() const
|
||||
{
|
||||
return params_.length;
|
||||
}
|
||||
@ -130,12 +130,14 @@ docstring InsetSpace::toolTip(BufferView const &, int, int) const
|
||||
message = _("Horizontal Fill (Down Brace)");
|
||||
break;
|
||||
case InsetSpaceParams::CUSTOM:
|
||||
// FIXME unicode
|
||||
message = support::bformat(_("Horizontal Space (%1$s)"),
|
||||
params_.length.asDocstring());
|
||||
from_ascii(params_.length.asString()));
|
||||
break;
|
||||
case InsetSpaceParams::CUSTOM_PROTECTED:
|
||||
// FIXME unicode
|
||||
message = support::bformat(_("Protected Horizontal Space (%1$s)"),
|
||||
params_.length.asDocstring());
|
||||
from_ascii(params_.length.asString()));
|
||||
break;
|
||||
}
|
||||
return message;
|
||||
@ -238,7 +240,7 @@ void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||
case InsetSpaceParams::CUSTOM:
|
||||
case InsetSpaceParams::CUSTOM_PROTECTED: {
|
||||
int const w =
|
||||
params_.length.inPixels(mi.base.textwidth,
|
||||
params_.length.len().inPixels(mi.base.textwidth,
|
||||
fm.width(char_type('M')));
|
||||
int const minw = (w < 0) ? 3 * arrow_size : 4;
|
||||
dim.wid = max(minw, abs(w));
|
||||
@ -264,7 +266,7 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const
|
||||
{
|
||||
Dimension const dim = dimension(*pi.base.bv);
|
||||
|
||||
if (isStretchableSpace() || params_.length.value() < 0) {
|
||||
if (isStretchableSpace() || params_.length.len().value() < 0) {
|
||||
int const asc = theFontMetrics(pi.base.font).ascent('M');
|
||||
int const desc = theFontMetrics(pi.base.font).descent('M');
|
||||
// Pixel height divisible by 2 for prettier fill graphics:
|
||||
@ -450,7 +452,7 @@ void InsetSpaceParams::write(ostream & os) const
|
||||
break;
|
||||
}
|
||||
|
||||
if (!length.empty())
|
||||
if (!length.len().empty())
|
||||
os << "\n\\length " << length.asString();
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ public:
|
||||
///
|
||||
Kind kind;
|
||||
///
|
||||
Length length;
|
||||
GlueLength length;
|
||||
/**
|
||||
* Whether these params are to be used in mathed.
|
||||
* This determines the set of valid kinds.
|
||||
@ -110,7 +110,7 @@ public:
|
||||
///
|
||||
static std::string params2string(InsetSpaceParams const &);
|
||||
///
|
||||
Length length() const;
|
||||
GlueLength length() const;
|
||||
|
||||
///
|
||||
docstring toolTip(BufferView const & bv, int x, int y) const;
|
||||
|
@ -214,7 +214,7 @@ string const InsetMathSpace::createDialogStr() const
|
||||
LASSERT(space_info[space_].visible, /**/);
|
||||
InsetSpaceParams isp(true);
|
||||
isp.kind = space_info[space_].kind;
|
||||
isp.length = length_;
|
||||
isp.length = GlueLength(length_);
|
||||
return InsetSpace::params2string(isp);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user