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

View File

@ -59,12 +59,36 @@ def find_token_backwards(lines, token, start):
return i return i
return -1 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): def get_value(lines, token, start, end = 0):
i = find_token(lines, token, start, end) i = find_token(lines, token, start, end)
if i == -1: if i == -1:
return "" return ""
return string.split(lines[i])[1] 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): def is_nonempty_line(line):
line = line[:-1] line = line[:-1]
return line != " "*len(line) return line != " "*len(line)