diff --git a/development/FORMAT b/development/FORMAT index b64512115a..4eef5b799f 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,11 @@ LyX file-format changes ----------------------- +2007-05-04 Jürgen Spitzmüller + + * format incremented to 275: add graphics params scaleBeforeRotation + (fix bug 1749). + 2007-06-13 Dov Feldstern * format incremented to 274: applying the conversion done in format 259 to the \lang property, which was forgotten back then... This is diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index f7770890ac..9088a41e2e 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -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(): diff --git a/lib/lyx2lyx/lyx_1_5.py b/lib/lyx2lyx/lyx_1_5.py index 32f84cd54e..595fffe15f 100644 --- a/lib/lyx2lyx/lyx_1_5.py +++ b/lib/lyx2lyx/lyx_1_5.py @@ -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]], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 73aacb1d21..fbd56b8faa 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -142,7 +142,7 @@ using std::string; namespace { -int const LYX_FORMAT = 274; +int const LYX_FORMAT = 275; } // namespace anon diff --git a/src/frontends/qt4/QGraphics.cpp b/src/frontends/qt4/QGraphics.cpp index dcd340dc77..f88bd15080 100644 --- a/src/frontends/qt4/QGraphics.cpp +++ b/src/frontends/qt4/QGraphics.cpp @@ -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()); } diff --git a/src/frontends/qt4/QGraphicsDialog.cpp b/src/frontends/qt4/QGraphicsDialog.cpp index b0beb48359..ba801d4df8 100644 --- a/src/frontends/qt4/QGraphicsDialog.cpp +++ b/src/frontends/qt4/QGraphicsDialog.cpp @@ -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 diff --git a/src/frontends/qt4/QGraphicsDialog.h b/src/frontends/qt4/QGraphicsDialog.h index 29ba1b4ab5..0b2c2b733e 100644 --- a/src/frontends/qt4/QGraphicsDialog.h +++ b/src/frontends/qt4/QGraphicsDialog.h @@ -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: diff --git a/src/frontends/qt4/ui/GraphicsUi.ui b/src/frontends/qt4/ui/GraphicsUi.ui index 38beafd67b..40c8186a76 100644 --- a/src/frontends/qt4/ui/GraphicsUi.ui +++ b/src/frontends/qt4/ui/GraphicsUi.ui @@ -5,8 +5,8 @@ 0 0 - 432 - 328 + 450 + 379 @@ -92,79 +92,13 @@ - - - - Rotate Graphics - - - true - - - - 9 - - - 6 - - - - - Angle to rotate image by - - - A&ngle (Degrees): - - - angle - - - - - - - - 3 - 0 - 0 - 0 - - - - Angle to rotate image by - - - - - - - The origin of the rotation - - - Or&igin: - - - origin - - - - - - - The origin of the rotation - - - - - - Output Size - true + false @@ -280,6 +214,82 @@ + + + + Rotate Graphics + + + false + + + + 9 + + + 6 + + + + + Check to change the order of rotating and scaling + + + Ro&tate after scaling + + + + + + + The origin of the rotation + + + + + + + The origin of the rotation + + + Or&igin: + + + origin + + + + + + + + 3 + 0 + 0 + 0 + + + + Angle to rotate image by + + + + + + + Angle to rotate image by + + + A&ngle (Degrees): + + + angle + + + + + + @@ -333,7 +343,7 @@ QFrame::StyledPanel - QFrame::Raised + QFrame::Plain @@ -457,35 +467,33 @@ 6 - - - - Additional LaTeX options + + + + Qt::Vertical - - LaTeX &options: + + + 20 + 21 + - - latexoptions - - + - - - - - 3 - 0 - 0 - 0 - + + + + Qt::Vertical - - Additional LaTeX options + + + 20 + 41 + - + - + Don't uncompress image before exporting to LaTeX @@ -495,17 +503,7 @@ - - - - Draft mode - - - &Draft mode - - - - + Qt::StrongFocus @@ -514,7 +512,7 @@ S&ubfigure - true + false true @@ -560,7 +558,7 @@ - + Qt::StrongFocus @@ -569,32 +567,50 @@ Sho&w in LyX - true + false true - + 9 6 - - + + + + true + + + + 1 + 0 + 0 + 0 + + - Screen display - - - &Display: - - - showCB + Percentage to scale by in LyX - + + + + Percentage to scale by in LyX + + + Sca&le on Screen (%): + + + displayscale + + + + Screen display @@ -621,40 +637,60 @@ - - + + - Percentage to scale by in LyX + Screen display - Sca&le on Screen (%): + &Display: - displayscale - - - - - - - true - - - - 1 - 0 - 0 - 0 - - - - Percentage to scale by in LyX + showCB + + + + + 3 + 0 + 0 + 0 + + + + Additional LaTeX options + + + + + + + Additional LaTeX options + + + LaTeX &options: + + + latexoptions + + + + + + + Draft mode + + + &Draft mode + + + @@ -775,6 +811,7 @@ aspectratio angle origin + rotateOrderCB restorePB okPB applyPB @@ -802,6 +839,5 @@ qt_helpers.h - - + diff --git a/src/insets/InsetGraphics.cpp b/src/insets/InsetGraphics.cpp index 477f884e2e..f48f784e7f 100644 --- a/src/insets/InsetGraphics.cpp +++ b/src/insets/InsetGraphics.cpp @@ -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(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; } diff --git a/src/insets/InsetGraphicsParams.cpp b/src/insets/InsetGraphicsParams.cpp index 858ce5e8f0..b7d97400b8 100644 --- a/src/insets/InsetGraphicsParams.cpp +++ b/src/insets/InsetGraphicsParams.cpp @@ -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) { diff --git a/src/insets/InsetGraphicsParams.h b/src/insets/InsetGraphicsParams.h index 5294a42ba3..b6cea1fd9b 100644 --- a/src/insets/InsetGraphicsParams.h +++ b/src/insets/InsetGraphicsParams.h @@ -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;