InsetFloat: allow float placement for rotated floats

- fixes bug #10270
- fileformat change
- fixes also a bug that unwanted placement was output to LaTeX on certain cases
This commit is contained in:
Uwe Stöhr 2017-04-15 06:57:52 +02:00
parent 87c553af56
commit 58e6c6c876
6 changed files with 82 additions and 9 deletions

View File

@ -7,6 +7,10 @@ changes happened in particular if possible. A good example would be
-----------------------
2017-04-15 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 540: support for rotated float placements
- no new LFUN or buffer parameters
2017-04-08 Uwe Stöhr <uwestoehr@web.de>
* Format incremented to 539: support for \baselineskip.
- new length unit BLS

View File

@ -2077,6 +2077,51 @@ def revert_baselineskip(document):
i = i + 1
def revert_rotfloat(document):
" Revert placement options for rotated floats "
i = 0
j = 0
k = 0
while True:
i = find_token(document.body, "sideways true", i)
if i != -1:
regexp = re.compile(r'^.*placement.*$')
j = find_re(document.body, regexp, i-2)
if j == -1:
return
if j != i-2:
i = i + 1
continue
else:
return
# we found a sideways float with placement options
# at first store the placement
beg = document.body[i-2].rfind(" ");
placement = document.body[i-2][beg+1:]
# check if the option'H' is used
if placement.find("H") != -1:
add_to_preamble(document, ["\\usepackage{float}"])
# now check if it is a starred type
if document.body[i-1].find("wide true") != -1:
star = '*'
else:
star = ''
# store the float type
beg = document.body[i-3].rfind(" ");
fType = document.body[i-3][beg+1:]
# now output TeX code
endInset = find_end_of_inset(document.body, i-3)
if endInset == -1:
document.warning("Malformed LyX document: Missing '\\end_inset' of Float inset.")
return
else:
document.body[endInset-2: endInset+1] = put_cmd_in_ert("\\end{sideways" + fType + star + '}')
document.body[i-3: i+2] = put_cmd_in_ert("\\begin{sideways" + fType + star + "}[" + placement + ']')
add_to_preamble(document, ["\\usepackage{rotfloat}"])
i = i + 1
##
# Conversion hub
#
@ -2113,10 +2158,12 @@ convert = [
[536, []],
[537, []],
[538, [convert_mathindent]],
[539, []]
[539, []],
[540, []]
]
revert = [
[539, [revert_rotfloat]],
[538, [revert_baselineskip]],
[537, [revert_mathindent]],
[536, [revert_xout]],

View File

@ -244,21 +244,36 @@ void FloatPlacement::checkAllowed() const
if (spanCB->isVisible()) {
bool const span = spanCB->isChecked();
bool const sideways = sidewaysCB->isChecked();
defaultsCB->setEnabled(!sideways);
topCB->setEnabled(!sideways && !defaults && !heredefinitely
&& contains(allowed_placement_, 't'));
bottomCB->setEnabled(!sideways && !defaults && !span && !heredefinitely
&& contains(allowed_placement_, 'b'));
pageCB->setEnabled(!sideways && !defaults && !heredefinitely
&& contains(allowed_placement_, 'p'));
herepossiblyCB->setEnabled(!sideways && !defaults && !span && !heredefinitely
if (!pageCB->isChecked())
pageCB->setChecked(sideways && contains(allowed_placement_, 'p'));
herepossiblyCB->setEnabled(!defaults && !span && !heredefinitely
&& contains(allowed_placement_, 'h'));
heredefinitelyCB->setEnabled(!sideways && !defaults && !span
heredefinitelyCB->setEnabled(!defaults && !span
&& contains(allowed_placement_, 'H'));
ignoreCB->setEnabled(!sideways && !defaults && ignore && !heredefinitely
ignoreCB->setEnabled(!defaults && ignore && !heredefinitely
&& contains(allowed_placement_, '!'));
// handle special case with sideways
if ((!herepossiblyCB->isChecked() && sideways) || (span && sideways))
ignoreCB->setEnabled(false);
// when disabled the options must be unchecked to avoid strange LaTeX export
// don't do it for pageCB because this case is handled with sideways
if (ignoreCB->isChecked() && !ignoreCB->isEnabled())
ignoreCB->setChecked(false);
if (herepossiblyCB->isChecked() && !herepossiblyCB->isEnabled())
herepossiblyCB->setChecked(false);
if (topCB->isChecked() && !topCB->isEnabled())
topCB->setChecked(false);
if (bottomCB->isChecked() && !bottomCB->isEnabled())
bottomCB->setChecked(false);
spanCB->setEnabled(allows_wide_ && (!sideways || standardfloat_));
sidewaysCB->setEnabled(allows_sideways_);
defaultsCB->setEnabled(!(sideways && span));
} else {
topCB->setEnabled(!defaults && !heredefinitely);
bottomCB->setEnabled(!defaults && !heredefinitely);

View File

@ -389,8 +389,10 @@ void InsetFloat::latex(otexstream & os, OutputParams const & runparams_in) const
if (runparams.lastid != -1)
os.texrow().start(runparams.lastid, runparams.lastpos);
// We only output placement if different from the def_placement.
// sidewaysfloats always use their own page
if (!placement.empty() && !params_.sideways)
// sidewaysfloats always use their own page,
// therefore don't output the p option that is always set
if (!placement.empty()
&& (!params_.sideways || (params_.sideways && from_ascii(placement) != "p")))
os << '[' << from_ascii(placement) << ']';
os << '\n';

View File

@ -1468,6 +1468,7 @@ void parse_environment(Parser & p, ostream & os, bool outer,
else if (unstarred_name == "sidewaysfigure"
|| unstarred_name == "sidewaystable"
|| unstarred_name == "sidewaysalgorithm") {
string const opt = p.hasOpt() ? p.getArg('[', ']') : string();
eat_whitespace(p, os, parent_context, false);
parent_context.check_layout(os);
if (unstarred_name == "sidewaysfigure")
@ -1476,6 +1477,10 @@ void parse_environment(Parser & p, ostream & os, bool outer,
begin_inset(os, "Float table\n");
else if (unstarred_name == "sidewaysalgorithm")
begin_inset(os, "Float algorithm\n");
if (!opt.empty())
os << "placement " << opt << '\n';
if (contains(opt, "H"))
preamble.registerAutomaticallyLoadedPackage("float");
os << "wide " << convert<string>(is_starred)
<< "\nsideways true"
<< "\nstatus open\n\n";

View File

@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
#define LYX_FORMAT_LYX 539 // uwestoehr: support for \baselineskip
#define LYX_FORMAT_TEX2LYX 539
#define LYX_FORMAT_LYX 540 // uwestoehr: enable placement for rotated floats
#define LYX_FORMAT_TEX2LYX 540
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER