Fix bug 1749. CAUTION: lyx2lyx not fully working yet (see FIXMEs).

* development/FORMAT: 
	- document file format change

* src/Buffer.cpp: bump format to 275.

* lib/lyx2lyx/LyX.py:
* lib/lyx2lyx/lyx_1_5.py:
	- conversion and reversion of scaleBeforeRotation param (doesn't work yet!)

* src/insets/InsetGraphicsParams.{cpp,h}: 
	- new param scaleBeforeRotation
* src/insets/InsetGraphics.cpp:
	- swap order of scale and rotate (if scaleBeforeRotation is false)

* src/frontends/qt4/QGraphics.C:
* src/frontends/qt4/QGraphicsDialog.{cpp,h}:
* src/frontends/qt4/ui/GraphicsUi.ui:
	- add checkbox to toggle scaleBeforeRotation.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18885 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2007-06-25 13:49:51 +00:00
parent 54ed37eade
commit bcf64dd11c
11 changed files with 305 additions and 152 deletions

View File

@ -1,6 +1,11 @@
LyX file-format changes
-----------------------
2007-05-04 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* format incremented to 275: add graphics params scaleBeforeRotation
(fix bug 1749).
2007-06-13 Dov Feldstern <dov@lyx.org>
* format incremented to 274: applying the conversion done in format 259
to the \lang property, which was forgotten back then... This is

View File

@ -77,7 +77,7 @@ format_relation = [("0_06", [200], generate_minor_versions("0.6" , 4)),
("1_2", [220], generate_minor_versions("1.2" , 4)),
("1_3", [221], generate_minor_versions("1.3" , 7)),
("1_4", range(222,246), generate_minor_versions("1.4" , 4)),
("1_5", range(246,275), generate_minor_versions("1.5" , 0))]
("1_5", range(246,276), generate_minor_versions("1.5" , 0))]
def formats_list():

View File

@ -1356,6 +1356,65 @@ def revert_cv_textclass(document):
document.textclass = "cv"
#
# add scaleBeforeRotation graphics param
def convert_graphics_rotation(document):
" add scaleBeforeRotation graphics parameter. "
i = 0
while 1:
i = find_token(document.body, "\\begin_inset Graphics", i)
if i == -1:
return
j = find_end_of_inset(document.body, i+1)
if j == -1:
# should not happen
document.warning("Malformed LyX document: Could not find end of graphics inset.")
# Seach for rotateAngle and width or height or scale
# If these params are not there, nothing needs to be done.
# FIXME: this also inserts scaleBeforeRotation if "rotateAngle" is not there!
for k in range(i+1, j):
if (document.body[k].find("rotateAngle") and \
(document.body[k].find("width") or \
document.body[k].find("height") or \
document.body[k].find("scale"))):
document.body.insert(j, 'scaleBeforeRotation')
i = i + 1
# FIXME: does not work at all
def revert_graphics_rotation(document):
" remove scaleBeforeRotation graphics parameter. "
i = 0
while 1:
i = find_token(document.body, "\\begin_inset Graphics", i)
if i == -1:
return
j = find_end_of_inset(document.body, i + 1)
if j == -1:
# should not happen
document.warning("Malformed LyX document: Could not find end of graphics inset.")
for k in range(i+1, j):
# If there's a scaleBeforeRotation param, just remove that
if document.body[k].find('scaleBeforeRotation'):
del document.body[k]
break
# if not, and if we have rotateAngle and width or height or scale,
# we have to put the rotateAngle value to special
rotateAngle = get_value(document.body, 'rotateAngle', i+1, j)
special = get_value(document.body, 'special', i+1, j)
if (document.body[k].find("width") or \
document.body[k].find("height") or \
document.body[k].find("scale") and \
document.body[k].find("rotateAngle")):
if special == "":
document.body.insert(j-1, '\tspecial angle=%s' % rotateAngle)
else:
l = find_token(document.body, "special", i+1, j)
document.body[l].replace(special, 'angle=%s,%s' % (rotateAngle, special))
i = i + 1
def convert_tableborder(document):
# The problematic is: LyX double the table cell border as it ignores the "|" character in
# the cell arguments. A fix takes care of this and therefore the "|" has to be removed
@ -1782,10 +1841,12 @@ convert = [[246, []],
[271, [convert_ext_font_sizes]],
[272, []],
[273, []],
[274, [normalize_font_whitespace_274]]
[274, [normalize_font_whitespace_274]],
[275, [convert_graphics_rotation]]
]
revert = [
[274, [revert_graphics_rotation]],
[273, []],
[272, [revert_separator_layout]],
[271, [revert_preamble_listings_params, revert_listings_inset, revert_include_listings]],

View File

@ -142,7 +142,7 @@ using std::string;
namespace {
int const LYX_FORMAT = 274;
int const LYX_FORMAT = 275;
} // namespace anon

View File

@ -89,6 +89,7 @@ void QGraphics::build_dialog()
bcview().addReadOnly(dialog_->rotationGB);
bcview().addReadOnly(dialog_->latexoptions);
bcview().addReadOnly(dialog_->getPB);
bcview().addReadOnly(dialog_->rotateOrderCB);
// initialize the length validator
addCheckedLineEdit(bcview(), dialog_->Scale, dialog_->scaleCB);
@ -264,6 +265,12 @@ void QGraphics::update_contents()
dialog_->setAutoText();
dialog_->angle->setText(toqstr(igp.rotateAngle));
dialog_->rotateOrderCB->setChecked(igp.scaleBeforeRotation);
dialog_->rotateOrderCB->setEnabled((widthChecked ||
heightChecked ||
scaleChecked) &&
(igp.rotateAngle != "0"));
dialog_->origin->clear();
@ -382,6 +389,8 @@ void QGraphics::apply()
igp.rotateOrigin =
QGraphics::origin_ltx[dialog_->origin->currentIndex()];
igp.scaleBeforeRotation = dialog_->rotateOrderCB->isChecked();
// more latex options
igp.special = fromqstr(dialog_->latexoptions->text());
}

View File

@ -77,6 +77,8 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form)
this, SLOT(change_adaptor()));
connect(Scale, SIGNAL(textChanged(const QString &)),
this, SLOT(change_adaptor()));
connect(rotateOrderCB, SIGNAL(clicked()),
this, SLOT(change_adaptor()));
filename->setValidator(new PathValidator(true, filename));
setFocusProxy(filename);
@ -201,7 +203,8 @@ void QGraphicsDialog::on_filename_textChanged(const QString & filename)
}
void QGraphicsDialog::setAutoText() {
void QGraphicsDialog::setAutoText()
{
if (scaleCB->isChecked()) return;
if (!Scale->isEnabled() && Scale->text() != "100")
Scale->setText(QString("auto"));
@ -236,6 +239,11 @@ void QGraphicsDialog::on_scaleCB_toggled(bool setScale)
aspectratio->setDisabled(true);
aspectratio->setChecked(true);
rotateOrderCB->setEnabled((WidthCB->isChecked() ||
HeightCB->isChecked() ||
scaleCB->isChecked()) &&
(angle->text() != "0"));
setAutoText();
}
@ -256,6 +264,9 @@ void QGraphicsDialog::on_WidthCB_toggled(bool setWidth)
//already will be unchecked, so don't need to do that
Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
&& scaleCB->isChecked()); //should be false, but let's check
rotateOrderCB->setEnabled((setWidth || setHeight ||
scaleCB->isChecked()) &&
(angle->text() != "0"));
setAutoText();
}
@ -277,11 +288,23 @@ void QGraphicsDialog::on_HeightCB_toggled(bool setHeight)
//already unchecked
Scale->setEnabled((!setWidth && !setHeight) //=scaleCB->isEnabled()
&& scaleCB->isChecked()); //should be false
rotateOrderCB->setEnabled((setWidth || setHeight ||
scaleCB->isChecked()) &&
(angle->text() != "0"));
setAutoText();
}
void QGraphicsDialog::on_angle_textChanged(const QString & filename)
{
rotateOrderCB->setEnabled((WidthCB->isChecked() ||
HeightCB->isChecked() ||
scaleCB->isChecked()) &&
(filename != "0"));
}
} // namespace frontend
} // namespace lyx

View File

@ -41,6 +41,7 @@ protected Q_SLOTS:
virtual void on_scaleCB_toggled(bool);
virtual void on_WidthCB_toggled(bool);
virtual void on_HeightCB_toggled(bool);
virtual void on_angle_textChanged(const QString &);
protected:
virtual void closeEvent(QCloseEvent * e);
private:

View File

@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>432</width>
<height>328</height>
<width>450</width>
<height>379</height>
</rect>
</property>
<property name="sizePolicy" >
@ -92,79 +92,13 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="4" >
<widget class="QGroupBox" name="rotationGB" >
<property name="title" >
<string>Rotate Graphics</string>
</property>
<property name="flat" >
<bool>true</bool>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QLabel" name="angleL" >
<property name="toolTip" >
<string>Angle to rotate image by</string>
</property>
<property name="text" >
<string>A&amp;ngle (Degrees):</string>
</property>
<property name="buddy" >
<cstring>angle</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="angle" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Angle to rotate image by</string>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QLabel" name="originL" >
<property name="toolTip" >
<string>The origin of the rotation</string>
</property>
<property name="text" >
<string>Or&amp;igin:</string>
</property>
<property name="buddy" >
<cstring>origin</cstring>
</property>
</widget>
</item>
<item row="0" column="3" >
<widget class="QComboBox" name="origin" >
<property name="toolTip" >
<string>The origin of the rotation</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="4" >
<widget class="QGroupBox" name="sizeGB" >
<property name="title" >
<string>Output Size</string>
</property>
<property name="flat" >
<bool>true</bool>
<bool>false</bool>
</property>
<layout class="QGridLayout" >
<property name="margin" >
@ -280,6 +214,82 @@
</layout>
</widget>
</item>
<item row="2" column="0" colspan="4" >
<widget class="QGroupBox" name="rotationGB" >
<property name="title" >
<string>Rotate Graphics</string>
</property>
<property name="flat" >
<bool>false</bool>
</property>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="1" column="0" colspan="2" >
<widget class="QCheckBox" name="rotateOrderCB" >
<property name="toolTip" >
<string>Check to change the order of rotating and scaling</string>
</property>
<property name="text" >
<string>Ro&amp;tate after scaling</string>
</property>
</widget>
</item>
<item row="0" column="3" >
<widget class="QComboBox" name="origin" >
<property name="toolTip" >
<string>The origin of the rotation</string>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QLabel" name="originL" >
<property name="toolTip" >
<string>The origin of the rotation</string>
</property>
<property name="text" >
<string>Or&amp;igin:</string>
</property>
<property name="buddy" >
<cstring>origin</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="angle" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Angle to rotate image by</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="angleL" >
<property name="toolTip" >
<string>Angle to rotate image by</string>
</property>
<property name="text" >
<string>A&amp;ngle (Degrees):</string>
</property>
<property name="buddy" >
<cstring>angle</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="Clipping" >
@ -333,7 +343,7 @@
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow" >
<enum>QFrame::Raised</enum>
<enum>QFrame::Plain</enum>
</property>
<layout class="QGridLayout" >
<property name="margin" >
@ -457,35 +467,33 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<widget class="QLabel" name="latexoptionsLA" >
<property name="toolTip" >
<string>Additional LaTeX options</string>
<item row="3" column="1" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="text" >
<string>LaTeX &amp;options:</string>
<property name="sizeHint" >
<size>
<width>20</width>
<height>21</height>
</size>
</property>
<property name="buddy" >
<cstring>latexoptions</cstring>
</property>
</widget>
</spacer>
</item>
<item row="0" column="1" >
<widget class="QLineEdit" name="latexoptions" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<item row="6" column="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="toolTip" >
<string>Additional LaTeX options</string>
<property name="sizeHint" >
<size>
<width>20</width>
<height>41</height>
</size>
</property>
</widget>
</spacer>
</item>
<item row="2" column="0" colspan="2" >
<item row="2" column="0" colspan="3" >
<widget class="QCheckBox" name="unzipCB" >
<property name="toolTip" >
<string>Don't uncompress image before exporting to LaTeX</string>
@ -495,17 +503,7 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="2" >
<widget class="QCheckBox" name="draftCB" >
<property name="toolTip" >
<string>Draft mode</string>
</property>
<property name="text" >
<string>&amp;Draft mode</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2" >
<item row="4" column="0" colspan="3" >
<widget class="QGroupBox" name="subfigure" >
<property name="focusPolicy" >
<enum>Qt::StrongFocus</enum>
@ -514,7 +512,7 @@
<string>S&amp;ubfigure</string>
</property>
<property name="flat" >
<bool>true</bool>
<bool>false</bool>
</property>
<property name="checkable" >
<bool>true</bool>
@ -560,7 +558,7 @@
</layout>
</widget>
</item>
<item row="4" column="0" colspan="2" >
<item row="5" column="0" colspan="3" >
<widget class="QGroupBox" name="displayGB" >
<property name="focusPolicy" >
<enum>Qt::StrongFocus</enum>
@ -569,32 +567,50 @@
<string>Sho&amp;w in LyX</string>
</property>
<property name="flat" >
<bool>true</bool>
<bool>false</bool>
</property>
<property name="checkable" >
<bool>true</bool>
</property>
<layout class="QHBoxLayout" >
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item>
<widget class="QLabel" name="showL" >
<item row="0" column="3" >
<widget class="QLineEdit" name="displayscale" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Screen display</string>
</property>
<property name="text" >
<string>&amp;Display:</string>
</property>
<property name="buddy" >
<cstring>showCB</cstring>
<string>Percentage to scale by in LyX</string>
</property>
</widget>
</item>
<item>
<item row="0" column="2" >
<widget class="QLabel" name="scaleLA" >
<property name="toolTip" >
<string>Percentage to scale by in LyX</string>
</property>
<property name="text" >
<string>Sca&amp;le on Screen (%):</string>
</property>
<property name="buddy" >
<cstring>displayscale</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QComboBox" name="showCB" >
<property name="toolTip" >
<string>Screen display</string>
@ -621,40 +637,60 @@
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="scaleLA" >
<item row="0" column="0" >
<widget class="QLabel" name="showL" >
<property name="toolTip" >
<string>Percentage to scale by in LyX</string>
<string>Screen display</string>
</property>
<property name="text" >
<string>Sca&amp;le on Screen (%):</string>
<string>&amp;Display:</string>
</property>
<property name="buddy" >
<cstring>displayscale</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="displayscale" >
<property name="enabled" >
<bool>true</bool>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Percentage to scale by in LyX</string>
<cstring>showCB</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1" colspan="2" >
<widget class="QLineEdit" name="latexoptions" >
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip" >
<string>Additional LaTeX options</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="latexoptionsLA" >
<property name="toolTip" >
<string>Additional LaTeX options</string>
</property>
<property name="text" >
<string>LaTeX &amp;options:</string>
</property>
<property name="buddy" >
<cstring>latexoptions</cstring>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3" >
<widget class="QCheckBox" name="draftCB" >
<property name="toolTip" >
<string>Draft mode</string>
</property>
<property name="text" >
<string>&amp;Draft mode</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
@ -775,6 +811,7 @@
<tabstop>aspectratio</tabstop>
<tabstop>angle</tabstop>
<tabstop>origin</tabstop>
<tabstop>rotateOrderCB</tabstop>
<tabstop>restorePB</tabstop>
<tabstop>okPB</tabstop>
<tabstop>applyPB</tabstop>
@ -802,6 +839,5 @@
<include location="local" >qt_helpers.h</include>
</includes>
<resources/>
<connections>
</connections>
<connections/>
</ui>

View File

@ -104,6 +104,7 @@ using support::onlyFilename;
using support::removeExtension;
using support::rtrim;
using support::subst;
using support::suffixIs;
using support::Systemcall;
using support::unzipFile;
using support::unzippedFileName;
@ -313,18 +314,21 @@ string const InsetGraphics::createLatexOptions() const
options << "draft,";
if (params().clip)
options << "clip,";
ostringstream size;
double const scl = convert<double>(params().scale);
if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
if (!float_equal(scl, 100.0, 0.05))
options << "scale=" << scl / 100.0 << ',';
size << "scale=" << scl / 100.0 << ',';
} else {
if (!params().width.zero())
options << "width=" << params().width.asLatexString() << ',';
size << "width=" << params().width.asLatexString() << ',';
if (!params().height.zero())
options << "height=" << params().height.asLatexString() << ',';
size << "height=" << params().height.asLatexString() << ',';
if (params().keepAspectRatio)
options << "keepaspectratio,";
size << "keepaspectratio,";
}
if (params().scaleBeforeRotation && !size.str().empty())
options << size.str();
// Make sure rotation angle is not very close to zero;
// a float can be effectively zero but not exactly zero.
@ -342,13 +346,18 @@ string const InsetGraphics::createLatexOptions() const
options << ',';
}
}
if (!params().scaleBeforeRotation && !size.str().empty())
options << size.str();
if (!params().special.empty())
options << params().special << ',';
string opts = options.str();
// delete last ','
return opts.substr(0, opts.size() - 1);
if (suffixIs(opts, ','))
opts = opts.substr(0, opts.size() - 1);
return opts;
}

View File

@ -74,6 +74,7 @@ void InsetGraphicsParams::init()
keepAspectRatio = false; // for LaTeX output
draft = false; // draft mode
noUnzip = false; // unzip files
scaleBeforeRotation = false; // scale image before rotating
bb = string(); // bounding box
clip = false; // clip image
@ -97,6 +98,7 @@ void InsetGraphicsParams::copy(InsetGraphicsParams const & igp)
keepAspectRatio = igp.keepAspectRatio;
draft = igp.draft;
noUnzip = igp.noUnzip;
scaleBeforeRotation = igp.scaleBeforeRotation;
bb = igp.bb;
clip = igp.clip;
@ -121,6 +123,7 @@ bool operator==(InsetGraphicsParams const & left,
left.keepAspectRatio == right.keepAspectRatio &&
left.draft == right.draft &&
left.noUnzip == right.noUnzip &&
left.scaleBeforeRotation == right.scaleBeforeRotation &&
left.bb == right.bb &&
@ -172,6 +175,8 @@ void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
os << "\tdraft\n";
if (noUnzip)
os << "\tnoUnzip\n";
if (scaleBeforeRotation)
os << "\tscaleBeforeRotation\n";
if (!bb.empty()) // bounding box
os << "\tBoundingBox " << bb << '\n';
@ -221,6 +226,8 @@ bool InsetGraphicsParams::Read(Lexer & lex, string const & token, string const &
draft = true;
} else if (token == "noUnzip") {
noUnzip = true;
} else if (token == "scaleBeforeRotation") {
scaleBeforeRotation = true;
} else if (token == "BoundingBox") {
bb.erase();
for (int i = 0; i < 4; ++i) {

View File

@ -47,6 +47,8 @@ public:
bool draft;
/// what to do with zipped files
bool noUnzip;
/// scale image before rotating
bool scaleBeforeRotation;
/// The bounding box with "xLB yLB yRT yRT ", divided by a space!
std::string bb;