* lyx_2_0.py (revert_percent_hspace_lengths, revert_hspace_glue_lengths):

- further simplifications of the code.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30738 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2009-07-21 17:41:00 +00:00
parent 21c5e4633d
commit 9a594992d2

View File

@ -1022,7 +1022,7 @@ def revert_percent_hspace_lengths(document):
if i == -1: if i == -1:
break break
star = (document.body[i].find("\\hspace*{}") != -1) star = (document.body[i].find("\\hspace*{}") != -1)
# only revert when a custom length was set and when # only revert if a custom length was set and when
# it used a percent length # it used a percent length
length = get_value(document.body, '\\length', i+1) length = get_value(document.body, '\\length', i+1)
if length == '': if length == '':
@ -1031,9 +1031,8 @@ def revert_percent_hspace_lengths(document):
# handle percent lengths # handle percent lengths
length = latex_length(length) length = latex_length(length)
# latex_length returns "bool,length" # latex_length returns "bool,length"
m = length.find(",") percent = length.split(",")[0]
percent = length[:m] length = length.split(",")[1]
length = length[m+1:]
# revert the HSpace inset to ERT # revert the HSpace inset to ERT
if percent == "True": if percent == "True":
if star == True: if star == True:
@ -1056,26 +1055,20 @@ def revert_hspace_glue_lengths(document):
if length == '': if length == '':
document.warning("Malformed lyx document: Missing '\\length' in Space inset.") document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
return return
# only revert when the length contains a plus or minus # only revert if the length contains a plus or minus at pos != 0
l = length.find("+") glue = re.compile(r'.+[\+-]')
if l == -1: if glue.search(length) == None:
l = length.find("-") break
if l == -1:
break
# handle percent lengths # handle percent lengths
length = latex_length(length) length = latex_length(length)
# latex_length returns "bool,length" # latex_length returns "bool,length"
m = length.find(",") length = length.split(",")[1]
length = length[m+1:]
# revert the HSpace inset to ERT # revert the HSpace inset to ERT
# allow leading - if star == True:
n = length.find("-") subst = [put_cmd_in_ert("\\hspace*{" + length + "}")]
if n != 0 or (n == 0 and (length.rfind("plus") > -1 or length.rfind("minus") > -1)): else:
if star == True: subst = [put_cmd_in_ert("\\hspace{" + length + "}")]
subst = [put_cmd_in_ert("\\hspace*{" + length + "}")] document.body[i:i+3] = subst
else:
subst = [put_cmd_in_ert("\\hspace{" + length + "}")]
document.body[i:i+3] = subst
i = i + 2 i = i + 2