*** Support for generic sideways floats ***

* src/Buffer.cpp:
	- format is up to 312.
* src/LaTeXFeatures.cpp:
	- add rotfloat.
* src/Insets/InsetFloat.cpp:
	- handle starred and generic sideways floats.
* src/frontends/qt4/FloatPlacement.{cpp,h}:
	- adjust GUI to the new features.
* lib/chkconfig.ltx:
	- add rotfloat
* lib/lyx2lyx/LyX.py:
* lib/lyx2lyx/lyx_1_6.py:
	- add reversion methods for new floats
* lib/lyx2lyx/lyx_1_4.py:
	- add proper reversion method for sideways floats (this was missing).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22495 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2008-01-11 18:56:53 +00:00
parent 97c4feea71
commit 4b799833e7
10 changed files with 128 additions and 18 deletions

View File

@ -1,6 +1,10 @@
LyX file-format changes
-----------------------
2008-01-11 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* Format incremented to 312: support for sidewaysalgorithm (rotfloat)
and wide sideways{figure,table}.
2008-01-10 Richard Heck <rgheck@bobjweil.com>
* Format incremented to 311: dummy format to drive the AMS conversion

View File

@ -247,6 +247,7 @@
\TestPackage{prettyref}
\TestPackage{preview}
\TestPackage{rotating}
\TestPackage{rotfloat}
\TestPackage{setspace}
\TestPackage{soul}
\TestPackage{subfigure}

View File

@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)),
("1_3", [221], minor_versions("1.3" , 7)),
("1_4", range(222,246), minor_versions("1.4" , 5)),
("1_5", range(246,277), minor_versions("1.5" , 2)),
("1_6", range(277,312), minor_versions("1.6" , 0))] # Richard Heck: AMS conversion
("1_6", range(277,313), minor_versions("1.6" , 0))] # JSpitzm: rotfloat support
def formats_list():

View File

@ -1826,20 +1826,35 @@ def convert_float(document):
def revert_float(document):
" Revert sideway floats. "
" Revert sideways floats. "
i = 0
while 1:
i = find_token_exact(document.body, '\\begin_inset Float', i)
if i == -1:
return
floatline = document.body[i]
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed lyx document: Missing '\\end_inset'.")
i = i + 1
continue
if get_value(document.body, 'sideways', i, j) != "false":
document.warning("Conversion of 'sideways true' not yet implemented.")
# Don't remove 'sideways' so that people will get warnings by lyx
l = find_token(document.body, "\\begin_layout Standard", i + 1, j)
if l == -1:
document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Float inset.")
return
floattype = "table"
if floatline == "\\begin_inset Float figure":
floattype = "figure"
document.body[j] = '\\layout Standard\n\\begin_inset ERT\nstatus Collapsed\n\n' \
'\\layout Standard\n\n\n\\backslash\n' \
'end{sideways' + floattype + '}\n\n\\end_inset\n'
del document.body[i+1:l-1]
document.body[i] = '\\begin_inset ERT\nstatus Collapsed\n\n' \
'\\layout Standard\n\n\n\\backslash\n' \
'begin{sideways' + floattype + '}\n\n\\end_inset\n\n'
add_to_preamble(document,
['\\usepackage{rotfloat}\n'])
i = i + 1
continue
del_token(document.body, 'sideways', i, j)

View File

@ -36,6 +36,15 @@ def wrap_into_ert(string, src, dst):
return string.replace(src, '\n\\begin_inset ERT\nstatus collapsed\n\\begin_layout Standard\n'
+ dst + '\n\\end_layout\n\\end_inset\n')
def add_to_preamble(document, text):
""" Add text to the preamble if it is not already there.
Only the first line is checked!"""
if find_token(document.preamble, text[0], 0) != -1:
return
document.preamble.extend(text)
####################################################################
def fix_wrong_tables(document):
@ -1092,6 +1101,77 @@ def revert_serbianlatin(document):
j = j + 1
def revert_rotfloat(document):
" Revert sidewaysalgorithm. "
i = 0
while 1:
i = find_token(document.body, '\\begin_inset Float algorithm', i)
if i == -1:
return
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed lyx document: Missing '\\end_inset'.")
i = i + 1
continue
if get_value(document.body, 'sideways', i, j) != "false":
l = find_token(document.body, "\\begin_layout Standard", i + 1, j)
if l == -1:
document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Float inset.")
return
document.body[j] = '\\begin_layout Standard\n\\begin_inset ERT\nstatus collapsed\n\n' \
'\\begin_layout Standard\n\n\n\\backslash\n' \
'end{sidewaysalgorithm}\n\\end_layout\n\n\\end_inset\n'
del document.body[i+1:l-1]
document.body[i] = '\\begin_inset ERT\nstatus collapsed\n\n' \
'\\begin_layout Standard\n\n\n\\backslash\n' \
'begin{sidewaysalgorithm}\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n\n'
add_to_preamble(document,
['% Commands inserted by lyx2lyx for sideways algorithm float',
'\\usepackage{rotfloat}\n'
'\\floatstyle{ruled}\n'
'\\newfloat{algorithm}{tbp}{loa}\n'
'\\floatname{algorithm}{Algorithm}\n'])
i = i + 1
continue
i = i + 1
def revert_widesideways(document):
" Revert wide sideways floats. "
i = 0
while 1:
i = find_token(document.body, '\\begin_inset Float', i)
if i == -1:
return
floatline = document.body[i]
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Malformed lyx document: Missing '\\end_inset'.")
i = i + 1
continue
if get_value(document.body, 'sideways', i, j) != "false":
if get_value(document.body, 'wide', i, j) != "false":
l = find_token(document.body, "\\begin_layout Standard", i + 1, j)
if l == -1:
document.warning("Malformed LyX document: Missing `\\begin_layout Standard' in Float inset.")
return
floattype = "table"
if floatline == "\\begin_inset Float figure":
floattype = "figure"
document.body[j] = '\\begin_layout Standard\n\\begin_inset ERT\nstatus collapsed\n\n' \
'\\begin_layout Standard\n\n\n\\backslash\n' \
'end{sideways' + floattype + '*}\n\\end_layout\n\n\\end_inset\n'
del document.body[i+1:l-1]
document.body[i] = '\\begin_inset ERT\nstatus collapsed\n\n' \
'\\begin_layout Standard\n\n\n\\backslash\n' \
'begin{sideways' + floattype + '*}\n\\end_layout\n\n\\end_inset\n\n\\end_layout\n\n'
add_to_preamble(document,
['\\usepackage{rotfloat}\n'])
i = i + 1
continue
i = i + 1
##
# Conversion hub
#
@ -1131,10 +1211,12 @@ convert = [[277, [fix_wrong_tables]],
[308, []],
[309, []],
[310, []],
[311, [convert_ams_classes]]
[311, [convert_ams_classes]],
[312, []],
]
revert = [[310, []],
revert = [[311, [revert_rotfloat, revert_widesideways]],
[310, []],
[309, [revert_btprintall]],
[308, [revert_nocite]],
[307, [revert_serbianlatin]],

View File

@ -118,7 +118,7 @@ namespace os = support::os;
namespace {
int const LYX_FORMAT = 311; // Richard Heck: a dummy format to drive the AMS conversion
int const LYX_FORMAT = 312; // JSpitzm: rotfloat support
} // namespace anon

View File

@ -510,6 +510,7 @@ char const * simplefeatures[] = {
the `float' package. See the caption package documentation
for explanation.*/
"float",
"rotfloat",
"wrapfig",
"booktabs",
"dvipost",

View File

@ -112,6 +112,9 @@ void FloatPlacement::set(lyx::InsetFloatParams const & params)
{
set(params.placement);
standardfloat_ = (params.type == "figure"
|| params.type == "table");
if (params.wide) {
herepossiblyCB->setChecked(false);
heredefinitelyCB->setChecked(false);
@ -120,8 +123,8 @@ void FloatPlacement::set(lyx::InsetFloatParams const & params)
spanCB->setChecked(params.wide);
sidewaysCB->setChecked(params.sideways);
sidewaysCB->setEnabled(params.type == "figure"
|| params.type == "table");
// the package rotfloat only has *-versions for figure and table
spanCB->setEnabled(!params.sideways || standardfloat_);
checkAllowed();
}
@ -225,7 +228,7 @@ void FloatPlacement::checkAllowed()
ignoreCB->setEnabled(!sideways && !defaults && ignore);
herepossiblyCB->setEnabled(!sideways && !defaults && !span);
heredefinitelyCB->setEnabled(!sideways && !defaults && !span);
spanCB->setEnabled(!sideways);
spanCB->setEnabled(!sideways || standardfloat_);
} else {
topCB->setEnabled(!defaults);
bottomCB->setEnabled(!defaults);

View File

@ -46,6 +46,10 @@ public Q_SLOTS:
Q_SIGNALS:
void changed();
private:
/// one of figure or table?
bool standardfloat_;
};

View File

@ -261,7 +261,7 @@ void InsetFloat::validate(LaTeXFeatures & features) const
}
if (params_.sideways)
features.require("rotating");
features.require("rotfloat");
features.useFloat(params_.type);
InsetCollapsable::validate(features);
@ -284,13 +284,13 @@ int InsetFloat::latex(Buffer const & buf, odocstream & os,
OutputParams const & runparams) const
{
FloatList const & floats = buf.params().getTextClass().floats();
string tmptype = (params_.wide ? params_.type + "*" : params_.type);
if (params_.sideways) {
if (params_.type == "table")
tmptype = "sidewaystable";
else if (params_.type == "figure")
tmptype = "sidewaysfigure";
}
string tmptype = params_.type;
if (params_.sideways)
tmptype = "sideways" + params_.type;
if (params_.wide && (!params_.sideways ||
params_.type == "figure" ||
params_.type == "table"))
tmptype += "*";
// Figure out the float placement to use.
// From lowest to highest:
// - float default placement