Few improvements

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4853 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Dekel Tsur 2002-08-03 14:29:12 +00:00
parent 33e6f2089a
commit ac51eb8283
2 changed files with 49 additions and 16 deletions

View File

@ -46,6 +46,13 @@ floats = {
"collapsed false"]
}
font_tokens = ["\\family", "\\series", "\\shape", "\\size", "\\emph",
"\\bar", "\\noun", "\\color", "\\lang"]
#
# Change \begin_float .. \end_float into \begin_inset Float .. \end_inset
#
def remove_oldfloat(lines, language):
i = 0
while 1:
@ -66,22 +73,24 @@ def remove_oldfloat(lines, language):
j2 = find_token(lines, "\\layout", j+1)
lines[j2:j2] = ["\\end_deeper "]*(i2-(i+1))
start = floats[floattype]+[""]
mid = lines[i2:j]
end = ["\\end_inset ",
"\\family default ",
"\\series default ",
"\\shape default ",
"\\size default ",
"\\emph default ",
# "\\numeric default ",
"\\bar default ",
"\\noun default ",
"\\color default "
"\\lang %s " % language]
# It isn't nice to always put all the '\xxx default' statements,
# but it doesn't hurt
lines[i:j+1]= start+mid+end
new = floats[floattype]+[""]
new = new+lines[i2:j]
new.append("\\end_inset ")
# After a float, all font attribute are reseted.
# We need to output '\foo default' for every attribute foo
# whose value is not default before the float.
# The check here is not accurate, but it doesn't matter
# as extra '\foo default' commands are ignored.
# In fact, it might be safer to output '\foo default' for all
# font attributes.
k = get_paragraph(lines, i)
for token in font_tokens:
if find_token(lines, token, k, i) != -1:
if token == "\\lang":
new.append(token+" "+language+" ")
else:
new.append(token+" default ")
lines[i:j+1]= new
i = i+1

View File

@ -59,12 +59,36 @@ def find_token_backwards(lines, token, start):
return i
return -1
def find_tokens_backwards(lines, tokens, start):
for i in xrange(start, -1, -1):
line = lines[i]
for token in tokens:
if line[:len(token)] == token:
return i
return -1
def get_value(lines, token, start, end = 0):
i = find_token(lines, token, start, end)
if i == -1:
return ""
return string.split(lines[i])[1]
# Finds the paragraph that contains line i.
def get_paragraph(lines, i):
while 1:
i = find_tokens_backwards(lines, ["\\end_inset", "\\layout"], i)
if check_token(lines[i], "\\layout"):
return i
count = 1
while count > 0:
i = find_tokens_backwards(lines, ["\\end_inset", "\\begin_inset"], i)
if check_token(lines[i], "\\end_inset"):
count = count+1
else:
count = count-1
i = i-1
def is_nonempty_line(line):
line = line[:-1]
return line != " "*len(line)