Hi All,
Here is another patch for review...
It adds the vertical alignment of the tabular as a whole as a property
to InsetTabular. It can be set with:
tabular-feature tabular-valign-[top|middle|bottom]
Any objections, things I forgot or comments ?
Vincent
>In comparison to the previous patch I added
> - three menu items to Edit->Table
> - a lyx2lyx revert routine
> - increased fileformat number
>
>Would somebody like to have a look at this. Especially the lyx2lyx part
>might need some attention. I tried to put the inset tabulars in a
>minipage with the correct alignment.
>
>Greetz,
>
>Vincent
I know it's a busy time, but I just want to SHOUT again and ask whether
someone would like to have a look at my first Python-experiment for lyx2lyx:
It adds a "\\begin_inset Box ... \\begin_layout Plain Layout ...
\\end_layout, \\end_inset" around an Tabular inset when the Tabular
inset has the alignment top or bottom specified.
+
+def revert_tabularvalign(document):
+ "Revert the tabular valign option"
+ i = 0
+ while True:
+ i = find_token(document.body, "\\begin_inset Tabular", i)
+ if i == -1:
+ return
+ i = i + 1
+ j = find_end_of_inset(document.body, i + 1)
+ if j == -1:
+ document.warning("Malformed LyX document: Could not find
end of tabular.")
+
+ k = i
+ k = find_token(document.body, "<features tabularvalignment=", k)
+ if k == -1:
+ continue
+
+ # which valignment is specified?
+ tabularvalignment_re = re.compile(r'<features
tabularvalignment="(top|bottom)">')
+ m = tabularvalignment_re.match(document.body[k])
+ if not m:
+ continue
+
+ tabularvalignment = m.group(1)
+
+ subst = [document.body[i-2],
+ '\\begin_inset Box Frameless',
+ 'position "' + tabularvalignment[0] +'"',
+ 'hor_pos "c"',
+ 'has_inner_box 1',
+ 'inner_pos "c"',
+ 'use_parbox 0',
+ 'width "0col%"',
+ 'special "none"',
+ 'height "1in"',
+ 'height_special "totalheight"',
+ 'status open',
+ '',
+ '\\begin_layout Plain Layout']
+
+ document.body[i-2:i-1] = subst
+ i = i + 13
+ j = j + 13
+
+ subst = [document.body[j],
+ '\end_inset',
+ '\end_layout']
+ document.body[j:j+1] = subst
Vincent
Index: src/LyXAction.cpp
===================================================================
--- src/LyXAction.cpp (revision 27972)
+++ src/LyXAction.cpp (working copy)
@@ -1894,7 +1894,8 @@
unset-lthead|set-ltfirsthead|unset-ltfirsthead|set-ltfoot|unset-ltfoot|
set-ltlastfoot|unset-ltlastfoot|set-ltnewpage|toggle-ltcaption|
set-special-column|set-special-multi|set-booktabs|unset-booktabs|
-
set-top-space|set-bottom-space|set-interline-space|set-border-lines \n
+
set-top-space|set-bottom-space|set-interline-space|set-border-lines|
+
tabular-valign-top|tabular-valign-middle|tabular-valign-bottom \n
<ARG>: additional argument for some commands, use debug mode to
explore its values.
* \li Origin: Jug, 28 Jul 2000
* \endvar
Index: src/insets/InsetTabular.h
===================================================================
--- src/insets/InsetTabular.h (revision 27972)
+++ src/insets/InsetTabular.h (working copy)
@@ -178,6 +178,12 @@
///
SET_BORDER_LINES,
///
+ TABULAR_VALIGN_TOP,
+ ///
+ TABULAR_VALIGN_MIDDLE,
+ ///
+ TABULAR_VALIGN_BOTTOM,
+ ///
LAST_ACTION
};
///
@@ -557,6 +563,8 @@
bool use_booktabs;
///
bool rotate;
+ ///
+ VAlignment tabular_valignment;
//
// for long tabulars
//
Index: src/insets/InsetTabular.cpp
===================================================================
--- src/insets/InsetTabular.cpp (revision 27972)
+++ src/insets/InsetTabular.cpp (working copy)
@@ -160,6 +160,9 @@
{ Tabular::SET_BOTTOM_SPACE, "set-bottom-space" },
{ Tabular::SET_INTERLINE_SPACE, "set-interline-space" },
{ Tabular::SET_BORDER_LINES, "set-border-lines" },
+ { Tabular::TABULAR_VALIGN_TOP, "tabular-valign-top"},
+ { Tabular::TABULAR_VALIGN_MIDDLE, "tabular-valign-middle"},
+ { Tabular::TABULAR_VALIGN_BOTTOM, "tabular-valign-bottom"},
{ Tabular::LAST_ACTION, "" }
};
@@ -595,6 +598,7 @@
cell_info.reserve(100);
updateIndexes();
is_long_tabular = false;
+ tabular_valignment = LYX_VALIGN_MIDDLE;
rotate = false;
use_booktabs = false;
size_t row_count = row_info.size();
@@ -1286,6 +1290,7 @@
<< write_attribute("rotate", rotate)
<< write_attribute("booktabs", use_booktabs)
<< write_attribute("islongtable", is_long_tabular)
+ << write_attribute("tabularvalignment", tabular_valignment)
<< write_attribute("firstHeadTopDL", endfirsthead.topDL)
<< write_attribute("firstHeadBottomDL", endfirsthead.bottomDL)
<< write_attribute("firstHeadEmpty", endfirsthead.empty)
@@ -1384,6 +1389,7 @@
getTokenValue(line, "rotate", rotate);
getTokenValue(line, "booktabs", use_booktabs);
getTokenValue(line, "islongtable", is_long_tabular);
+ getTokenValue(line, "tabularvalignment", tabular_valignment);
getTokenValue(line, "firstHeadTopDL", endfirsthead.topDL);
getTokenValue(line, "firstHeadBottomDL", endfirsthead.bottomDL);
getTokenValue(line, "firstHeadEmpty", endfirsthead.empty);
@@ -2286,10 +2292,23 @@
++ret;
}
if (is_long_tabular)
- os << "\\begin{longtable}{";
+ os << "\\begin{longtable}";
else
- os << "\\begin{tabular}{";
+ os << "\\begin{tabular}";
+ switch (tabular_valignment) {
+ case LYX_VALIGN_TOP:
+ os << "[t]";
+ break;
+ case LYX_VALIGN_BOTTOM:
+ os << "[b]";
+ break;
+ case LYX_VALIGN_MIDDLE:
+ break;
+ }
+
+ os << "{";
+
for (col_type i = 0; i < column_info.size(); ++i) {
if (columnLeftLine(i))
os << '|';
@@ -3813,6 +3832,19 @@
status.setOnOff(tabular.rotate);
break;
+ case Tabular::TABULAR_VALIGN_TOP:
+ status.setOnOff(tabular.tabular_valignment
+ == Tabular::LYX_VALIGN_TOP);
+ break;
+ case Tabular::TABULAR_VALIGN_MIDDLE:
+ status.setOnOff(tabular.tabular_valignment
+ == Tabular::LYX_VALIGN_MIDDLE);
+ break;
+ case Tabular::TABULAR_VALIGN_BOTTOM:
+ status.setOnOff(tabular.tabular_valignment
+ == Tabular::LYX_VALIGN_BOTTOM);
+ break;
+
case Tabular::UNSET_ROTATE_TABULAR:
status.setOnOff(!tabular.rotate);
break;
@@ -4560,6 +4592,18 @@
tabular.rotate = !tabular.rotate;
break;
+ case Tabular::TABULAR_VALIGN_TOP:
+ tabular.tabular_valignment = Tabular::LYX_VALIGN_TOP;
+ break;
+
+ case Tabular::TABULAR_VALIGN_MIDDLE:
+ tabular.tabular_valignment = Tabular::LYX_VALIGN_MIDDLE;
+ break;
+
+ case Tabular::TABULAR_VALIGN_BOTTOM:
+ tabular.tabular_valignment = Tabular::LYX_VALIGN_BOTTOM;
+ break;
+
case Tabular::SET_ROTATE_CELL:
for (row_type i = sel_row_start; i <= sel_row_end; ++i)
for (col_type j = sel_col_start; j <= sel_col_end; ++j)
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp (revision 27972)
+++ src/Buffer.cpp (working copy)
@@ -118,7 +118,7 @@
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
-int const LYX_FORMAT = 346; // jspitzm: Swiss German
+int const LYX_FORMAT = 347; // vfr: add tabular valign opion
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
Index: lib/lyx2lyx/lyx_2_0.py
===================================================================
--- lib/lyx2lyx/lyx_2_0.py (revision 27972)
+++ lib/lyx2lyx/lyx_2_0.py (working copy)
@@ -18,6 +18,8 @@
""" Convert files to the file format generated by lyx 2.0"""
+import re
+
from parser_tools import find_token, find_end_of, find_tokens, get_value,
get_value_string
####################################################################
@@ -46,15 +48,68 @@
document.body[j] = document.body[j].replace("\\lang german-ch",
"\\lang ngerman")
j = j + 1
+
+def revert_tabularvalign(document):
+ "Revert the tabular valign option"
+ i = 0
+ while True:
+ i = find_token(document.body, "\\begin_inset Tabular", i)
+ if i == -1:
+ return
+ i = i + 1
+ j = find_end_of_inset(document.body, i + 1)
+ if j == -1:
+ document.warning("Malformed LyX document: Could not find end of
tabular.")
+
+ k = i
+ k = find_token(document.body, "<features tabularvalignment=", k)
+ if k == -1:
+ continue
+
+ # which valignment is specified?
+ tabularvalignment_re = re.compile(r'<features
tabularvalignment="(top|bottom)">')
+ m = tabularvalignment_re.match(document.body[k])
+ if not m:
+ continue
+
+ tabularvalignment = m.group(1)
+
+ subst = [document.body[i-2],
+ '\\begin_inset Box Frameless',
+ 'position "' + tabularvalignment[0] +'"',
+ 'hor_pos "c"',
+ 'has_inner_box 1',
+ 'inner_pos "c"',
+ 'use_parbox 0',
+ 'width "0col%"',
+ 'special "none"',
+ 'height "1in"',
+ 'height_special "totalheight"',
+ 'status open',
+ '',
+ '\\begin_layout Plain Layout']
+
+ document.body[i-2:i-1] = subst
+ i = i + 13
+ j = j + 13
+
+ subst = [document.body[j],
+ '\end_inset',
+ '\end_layout']
+ document.body[j:j+1] = subst
+
+
##
# Conversion hub
#
-supported_versions = ["2.2.0","2.0"]
-convert = [[346, []]
+supported_versions = ["2.0.0","2.0"]
+convert = [[346, []],
+ [347, []]
]
-revert = [[345, [revert_swiss]]
+revert = [[346, [revert_tabularvalign]],
+ [345, [revert_swiss]]
]
Index: lib/ui/stdmenus.inc
===================================================================
--- lib/ui/stdmenus.inc (revision 27972)
+++ lib/ui/stdmenus.inc (working copy)
@@ -166,6 +166,9 @@
Item "Left Line|L" "tabular-feature toggle-line-left"
Item "Right Line|R" "tabular-feature toggle-line-right"
Separator
+ Item "Top|p" "tabular-feature tabular-valign-top"
+ Item "Middle|M" "tabular-feature tabular-valign-middle"
+ Item "Bottom|o" "tabular-feature tabular-valign-bottom"
End
Menu "edit_tabular_features"