From 742ffb30325d81fe4517ef86aa3f0073a7f68270 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Matox?= Date: Fri, 3 Dec 2004 18:33:19 +0000 Subject: [PATCH] Move convertion code from the C++ source (where is never called) to lyx2lyx. (longtables). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9336 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/lyx2lyx/ChangeLog | 4 + lib/lyx2lyx/lyx_1_2.py | 184 ++++++++++++++++++++++++++++++++++++++++- src/ChangeLog | 4 + src/tabular.C | 121 +++------------------------ src/tabular.h | 3 - 5 files changed, 201 insertions(+), 115 deletions(-) diff --git a/lib/lyx2lyx/ChangeLog b/lib/lyx2lyx/ChangeLog index 24906339f1..2242723567 100644 --- a/lib/lyx2lyx/ChangeLog +++ b/lib/lyx2lyx/ChangeLog @@ -1,3 +1,7 @@ +2004-12-03 José Matos + + * lyx_1_2.py (update_longtable): Update longtables to table format 3. + 2004-12-02 José Matos * lyx_0_12.py (update_latexaccents): convert old style latexaccents. diff --git a/lib/lyx2lyx/lyx_1_2.py b/lib/lyx2lyx/lyx_1_2.py index f0fa00857c..13a270d44c 100644 --- a/lib/lyx2lyx/lyx_1_2.py +++ b/lib/lyx2lyx/lyx_1_2.py @@ -292,7 +292,7 @@ def remove_oldert(lines): k = k+1 new.append("") elif hfill: - new = new+["\hfill", ""] + new = new + ["\\hfill", ""] k = k2 elif specialchar: if new == []: @@ -456,10 +456,13 @@ def remove_figinset(lines): write_attribute(new, "lyxsize_type", "1") write_attribute(new, "lyxwidth", lyxwidth) write_attribute(new, "lyxheight", lyxheight) - new = new + ["\end_inset"] + new = new + ["\\end_inset"] lines[i:j+1] = new +## +# Convert tabular format 2 to 3 +# attr_re = re.compile(r' \w*="(false|0|)"') line_re = re.compile(r'<(features|column|row|cell)') @@ -482,6 +485,182 @@ def update_tabular(lines): i = i+1 +## +# Convert tabular format 2 to 3 +# +# compatibility read for old longtable options. Now we can make any +# row part of the header/footer type we want before it was strict +# sequential from the first row down (as LaTeX does it!). So now when +# we find a header/footer line we have to go up the rows and set it +# on all preceding rows till the first or one with already a h/f option +# set. If we find a firstheader on the same line as a header or a +# lastfooter on the same line as a footer then this should be set empty. +# (Jug 20011220) + +# just for compatibility with old python versions +# python >= 2.3 has real booleans (False and True) +false = 0 +true = 1 + +# simple data structure to deal with long table info +class row: + def __init__(self): + self.endhead = false # header row + self.endfirsthead = false # first header row + self.endfoot = false # footer row + self.endlastfoot = false # last footer row + + +def haveLTFoot(row_info): + for row_ in row_info: + if row_.endfoot: + return true + return false + + +def setHeaderFooterRows(hr, fhr, fr, lfr, rows_, row_info): + endfirsthead_empty = false + endlastfoot_empty = false + # set header info + while (hr > 0): + hr = hr - 1 + row_info[hr].endhead = true + + # set firstheader info + if fhr and fhr < rows_: + if row_info[fhr].endhead: + while fhr > 0: + fhr = fhr - 1 + row_info[fhr].endfirsthead = true + row_info[fhr].endhead = false + elif row_info[fhr - 1].endhead: + endfirsthead_empty = true + else: + while fhr > 0 and not row_info[fhr - 1].endhead: + fhr = fhr - 1 + row_info[fhr].endfirsthead = true + + # set footer info + if fr and fr < rows_: + if row_info[fr].endhead and row_info[fr - 1].endhead: + while fr > 0 and not row_info[fr - 1].endhead: + fr = fr - 1 + row_info[fr].endfoot = true + row_info[fr].endhead = false + elif row_info[fr].endfirsthead and row_info[fr - 1].endfirsthead: + while fr > 0 and not row_info[fr - 1].endfirsthead: + fr = fr - 1 + row_info[fr].endfoot = true + row_info[fr].endfirsthead = false + elif not row_info[fr - 1].endhead and not row_info[fr - 1].endfirsthead: + while fr > 0 and not row_info[fr - 1].endhead and not row_info[fr - 1].endfirsthead: + fr = fr - 1 + row_info[fr].endfoot = true + + # set lastfooter info + if lfr and lfr < rows_: + if row_info[lfr].endhead and row_info[lfr - 1].endhead: + while lfr > 0 and not row_info[lfr - 1].endhead: + lfr = lfr - 1 + row_info[lfr].endlastfoot = true + row_info[lfr].endhead = false + elif row_info[lfr].endfirsthead and row_info[lfr - 1].endfirsthead: + while lfr > 0 and not row_info[lfr - 1].endfirsthead: + lfr = lfr - 1 + row_info[lfr].endlastfoot = true + row_info[lfr].endfirsthead = false + elif row_info[lfr].endfoot and row_info[lfr - 1].endfoot: + while lfr > 0 and not row_info[lfr - 1].endfoot: + lfr = lfr - 1 + row_info[lfr].endlastfoot = true + row_info[lfr].endfoot = false + elif not row_info[fr - 1].endhead and not row_info[fr - 1].endfirsthead and not row_info[fr - 1].endfoot: + while lfr > 0 and not row_info[lfr - 1].endhead and not row_info[lfr - 1].endfirsthead and not row_info[lfr - 1].endfoot: + lfr = lfr - 1 + row_info[lfr].endlastfoot = true + elif haveLTFoot(row_info): + endlastfoot_empty = true + + return endfirsthead_empty, endlastfoot_empty + + +def insert_attribute(lines, i, attribute): + last = string.find(lines[i],'>') + lines[i] = lines[i][:last] + ' ' + attribute + lines[i][last:] + + +rows_re = re.compile(r'rows="(\d*)"') +longtable_re = re.compile(r'islongtable="(\w)"') +ltvalues_re = re.compile(r'endhead="(-?\d*)" endfirsthead="(-?\d*)" endfoot="(-?\d*)" endlastfoot="(-?\d*)"') +lt_features_re = re.compile(r'(endhead="-?\d*" endfirsthead="-?\d*" endfoot="-?\d*" endlastfoot="-?\d*")') +def update_longtables(file): + body = file.body + i = 0 + while 1: + i = find_token(body, '\\begin_inset Tabular', i) + if i == -1: + break + i = i + 1 + i = find_token(body, "