From: Angus Leeming Date: Mon, 30 Jul 2001 13:35:08 +0000 (+0000) Subject: * John's maths patch, X-Git-Tag: 1.6.10~20956 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=2e5de574e172417d1a530414d5bb438ea6aa98ed;p=features.git * John's maths patch, * Baruch's second graphics patch, * A few things to get stuff to compile on my machine --- Lars see the ChangeLog in controllers; how do you get things to compile without a != operator? Surely compilation dies in ControlInset, included in ControlFloat, ControlMinipage. Angus git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2389 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 308f7dbbce..97f2b422c3 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,11 @@ +2001-07-30 Angus Leeming + + * ControlFloat.h: add a != operator for FloatParams. + Lars, how did you get this to compile!!! + + * ControlMinipage.[Ch]: uncommented someone's commenting out of + operator != for MinipageParams. Who's changing stuff and not compiling? + 2001-07-30 Lars Gullik Bjønnes * Makefile.am (libcontrollers_la_SOURCES): add ControlFloat.h and diff --git a/src/frontends/controllers/ControlFloat.h b/src/frontends/controllers/ControlFloat.h index 1794b06926..e1dfd8def0 100644 --- a/src/frontends/controllers/ControlFloat.h +++ b/src/frontends/controllers/ControlFloat.h @@ -42,6 +42,13 @@ bool operator==(FloatParams const & p1, FloatParams const & p2) } +inline +bool operator!=(FloatParams const & p1, FloatParams const & p2) +{ + return !(p1 == p2); +} + + /** A controller for Minipage dialogs. */ class ControlFloat : public ControlInset { diff --git a/src/frontends/controllers/ControlMinipage.C b/src/frontends/controllers/ControlMinipage.C index 414a167752..7c7f2ee940 100644 --- a/src/frontends/controllers/ControlMinipage.C +++ b/src/frontends/controllers/ControlMinipage.C @@ -78,10 +78,10 @@ bool operator==(MinipageParams const & p1, MinipageParams const & p2) } -//bool operator!=(MinipageParams const & p1, MinipageParams const & p2) -//{ -// return !(p1 == p2); -//} +bool operator!=(MinipageParams const & p1, MinipageParams const & p2) +{ + return !(p1 == p2); +} namespace minipage { diff --git a/src/frontends/controllers/ControlMinipage.h b/src/frontends/controllers/ControlMinipage.h index 0d0dc97656..04fe731766 100644 --- a/src/frontends/controllers/ControlMinipage.h +++ b/src/frontends/controllers/ControlMinipage.h @@ -43,7 +43,7 @@ struct MinipageParams { /// bool operator==(MinipageParams const &, MinipageParams const &); /// -//bool operator!=(MinipageParams const &, MinipageParams const &); +bool operator!=(MinipageParams const &, MinipageParams const &); /** A controller for Minipage dialogs. diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 2bb7612bae..cebb0314df 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,12 @@ +2001-07-29 John Levon + + * FormMathsBitmap.C: initialise form_ + +2001-07-29 Baruch Even + + * src/forms/form_graphics.fd: + * src/FormGraphics.C: Added support for the new horizontal scale factor. + 2001-07-30 Lars Gullik Bjønnes * forms/makefile (SRCS): add form_float.fd @@ -33,14 +42,14 @@ 2001-07-26 John Levon * Dialogs.C: - * Makefile.am: + * Makefile.am: * FormThesaurus.h: * FormThesaurus.C: * form_thesaurus.h: * form_thesaurus.C: * forms/makefile: * forms/form_thesaurus.fd: add thesaurus - + 2001-07-26 Baruch Even * FormGraphics.h: diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index e76973ff00..a19b8309aa 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -99,6 +99,8 @@ void FormGraphics::build() InsetGraphicsParams::INCH); heightButtons.registerRadioButton(dialog_->radio_height_percent_page, InsetGraphicsParams::PERCENT_PAGE); + heightButtons.registerRadioButton(dialog_->radio_height_scale, + InsetGraphicsParams::SCALE); // Add the widgets of the display radio buttons to their group displayButtons.reset(); diff --git a/src/frontends/xforms/FormMathsBitmap.C b/src/frontends/xforms/FormMathsBitmap.C index c08da574b2..86461fcc4d 100644 --- a/src/frontends/xforms/FormMathsBitmap.C +++ b/src/frontends/xforms/FormMathsBitmap.C @@ -40,7 +40,7 @@ FormMathsBitmap::FormMathsBitmap(LyXView * lv, Dialogs * d, FormMathsPanel const & p, vector const & l) : FormMathsSub(lv, d, p, _("Maths Bitmaps")), - latex_(l), ww_(0), x_(0), y_(0), w_(0), h_(0) + latex_(l), form_(0), ww_(0), x_(0), y_(0), w_(0), h_(0) { ww_ = 2 * FL_abs(FL_BOUND_WIDTH); x_ = y_ = ww_; diff --git a/src/frontends/xforms/form_graphics.C b/src/frontends/xforms/form_graphics.C index ec76c10092..765b5513ef 100644 --- a/src/frontends/xforms/form_graphics.C +++ b/src/frontends/xforms/form_graphics.C @@ -145,6 +145,8 @@ FD_form_graphics * FormGraphics::build_graphics() fl_set_button_shortcut(obj, scex(_(dummy)), 1); } fl_set_object_callback(obj, C_FormBaseCancelCB, 0); + fdui->radio_height_scale = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 140, 160, 96, 30, _("Scale")); + fl_set_object_callback(obj, C_FormBaseInputCB, CHECKINPUT); fl_end_form(); fdui->form->fdui = fdui; diff --git a/src/frontends/xforms/form_graphics.h b/src/frontends/xforms/form_graphics.h index 224f3d1765..2e00064354 100644 --- a/src/frontends/xforms/form_graphics.h +++ b/src/frontends/xforms/form_graphics.h @@ -44,6 +44,7 @@ struct FD_form_graphics { FL_OBJECT *button_ok; FL_OBJECT *button_apply; FL_OBJECT *button_cancel; + FL_OBJECT *radio_height_scale; }; #endif /* FD_form_graphics_h_ */ diff --git a/src/frontends/xforms/forms/form_graphics.fd b/src/frontends/xforms/forms/form_graphics.fd index 0a6543a784..49720b2a1a 100644 --- a/src/frontends/xforms/forms/form_graphics.fd +++ b/src/frontends/xforms/forms/form_graphics.fd @@ -10,7 +10,7 @@ Unit of measure: FL_COORD_PIXEL Name: form_graphics Width: 490 Height: 390 -Number of Objects: 36 +Number of Objects: 37 -------------------- class: FL_BOX @@ -663,5 +663,23 @@ name: button_cancel callback: C_FormBaseCancelCB argument: 0 +-------------------- +class: FL_CHECKBUTTON +type: RADIO_BUTTON +box: 140 160 96 30 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: Scale +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: radio_height_scale +callback: C_FormBaseInputCB +argument: CHECKINPUT + ============================== create_the_forms diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 3e8b1617ab..dd01e0bd6d 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -8,14 +8,25 @@ * insetfoot.h: remove InsetFoot:: qualifier. -2001-07-30 Baruch Even +2001-07-29 Baruch Even + + * ChangeLog: Hiding time travel evidence. + + * insetgraphicsParams.h: + * insetgraphicsParams.C: + * insetgraphics.C: Added horizontal scale option, it actually scales both + directions since it keeps image proportions. + + * insetgraphics.C: Fixed EPS detection to be non-hacky. + +2001-07-29 Baruch Even * insetgraphics.C (decideOutputImageFormat): when doing postscript output convert PNG/GIF/JPG to EPS, assume the rest are EPS already. HACKY! Will need to add an EPS detection routine like old InsetFig does! -2001-07-30 Baruch Even +2001-07-29 Baruch Even * insetgraphics.C: Added EPSI to be an alias of EPS. diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 5dff210090..7630dc4a13 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -41,6 +41,14 @@ Known BUGS: * We do not dither or resize the image in a WYSIWYM way, we load it at its original size and color, resizing is done in the final output, but not in the LyX window. + + * The scale option is only handled for the horizontal part, the vertical + part will not work. For now it is also shown only for horizontal + resizing on the form. + + * EPS figures are not fully detected, they may have a lot of possible + suffixes so we need to read the file and detect if it's EPS or not. + [Implemented, need testing] TODO Before initial production release: * Replace insetfig everywhere @@ -146,6 +154,7 @@ TODO Extended features: #include "lyxtext.h" #include "lyxrc.h" #include "font.h" // For the lyxfont class. +#include "fstream" // for ifstream in isEPS #include // For the std::max #include "support/lyxmanip.h" #include "debug.h" @@ -153,6 +162,7 @@ TODO Extended features: extern string system_tempdir; +using std::ifstream; using std::ostream; using std::endl; @@ -480,6 +490,8 @@ void formatResize(ostream & os, string const & key, os << key << '=' << size / 100 << "\\column" << key << ','; break; + case InsetGraphicsParams::SCALE: + os << "scale" << '=' << size << ','; } } @@ -511,28 +523,85 @@ InsetGraphics::createLatexOptions() const } namespace { - -string decideOutputImageFormat(string const & in_fmt) + +enum FileType { + EPS, + PNG, + JPEG, + GIF, + PDF, + UNKNOWN +}; + +bool isEPS(string const & filename) +{ + if (filename.empty() || !IsFileReadable(filename)) return false; + + ifstream ifs(filename.c_str()); + + if (!ifs) return false; // Couldn't open file... + + bool is_eps = false; // Have we recognized the file as EPS? + string to_find = "%!PS-Adobe-"; // The string we use to recognize + int const max_attempts = 500; // Maximum strings to read to attempt recognition + int count = 0; // Counter of attempts. + string str; + for (; count < max_attempts; ++count) { + if (ifs.eof()) { + lyxerr[Debug::INFO] << "InsetGraphics (isEPS)" + " End of file reached and it wasn't found to be EPS!" << endl; + break; + } + + ifs >> str; + if (str.find(to_find)) { + is_eps = true; + break; + } + } + + return is_eps; +} + +enum FileType classifyFileType(string const & filename, string const & suffix) +{ + if (suffix == "png") + return PNG; + else if (suffix == "jpg" || suffix == "jpeg") + return JPEG; + else if (suffix == "gif") + return GIF; + else if (suffix == "pdf") + return PDF; + else if (isEPS(filename)) + return EPS; + + return UNKNOWN; +} + +string decideOutputImageFormat(string const & suffix, enum FileType type) { // lyxrc.pdf_mode means: // Are we creating a PDF or a PS file? // (Should actually mean, are we using latex or pdflatex). if (lyxrc.pdf_mode) { - if (in_fmt == "eps" || in_fmt == "epsi" || in_fmt == "pdf") + if (type == EPS || type == EPS || type == PDF) return "pdf"; - else if (in_fmt == "jpg" || in_fmt == "jpeg") - return in_fmt; + else if (type == JPEG) + return suffix; else return "png"; } // If it's postscript, we always do eps. - // Garst has many eps files with various extensions, we just assume - // whatever goes in (except those we know to be otherwise) is eps - if (in_fmt == "gif" || in_fmt == "png" || in_fmt == "jpg") - return "eps"; - return in_fmt; + // There are many suffixes that are actually EPS (ask Garst for example) + // so we detect if it's an EPS by looking in the file, if it is, we return + // the same suffix of the file so it won't be converted. + if (type == EPS) + return suffix; + + return "eps"; } } // Anon. namespace @@ -559,10 +628,11 @@ InsetGraphics::prepareFile(Buffer const *buf) const // Get the extension (format) of the original file. string const extension = GetExtension(params.filename); + FileType type = classifyFileType(params.filename, extension); // Are we creating a PDF or a PS file? // (Should actually mean, are we usind latex or pdflatex). - string const image_target = decideOutputImageFormat(extension); + string const image_target = decideOutputImageFormat(extension, type); if (extension == image_target) return params.filename; diff --git a/src/insets/insetgraphicsParams.C b/src/insets/insetgraphicsParams.C index ed5980e72a..f817136eeb 100644 --- a/src/insets/insetgraphicsParams.C +++ b/src/insets/insetgraphicsParams.C @@ -61,6 +61,7 @@ InsetGraphicsParams::InsetGraphicsParams() resizeTranslator.addPair(INCH, "inch"); resizeTranslator.addPair(PERCENT_PAGE, "percentOfPage"); resizeTranslator.addPair(PERCENT_COLUMN, "percentOfColumn"); + resizeTranslator.addPair(SCALE, "scale"); // Fill the origin translator originTranslator.addPair(DEFAULT, "default"); @@ -155,17 +156,20 @@ void InsetGraphicsParams::testInvariant() const widthResize == CM || widthResize == INCH || widthResize == PERCENT_PAGE || - widthResize == PERCENT_COLUMN + widthResize == PERCENT_COLUMN || + widthResize == SCALE ); lyx::Assert(heightResize == DEFAULT_SIZE || heightResize == CM || heightResize == INCH || - heightResize == PERCENT_PAGE + heightResize == PERCENT_PAGE || + heightResize == SCALE ); - lyx::Assert(widthSize >= 0.0); - lyx::Assert(heightSize >= 0.0); + // For SCALE these can be negative. + //lyx::Assert(widthSize >= 0.0); + //lyx::Assert(heightSize >= 0.0); // Angle is in degrees and ranges -360 < angle < 360 // The reason for this is that in latex there is a meaning for the diff --git a/src/insets/insetgraphicsParams.h b/src/insets/insetgraphicsParams.h index 5eb3415ffc..601df89b0a 100644 --- a/src/insets/insetgraphicsParams.h +++ b/src/insets/insetgraphicsParams.h @@ -75,7 +75,8 @@ struct InsetGraphicsParams CM, INCH, PERCENT_PAGE, - PERCENT_COLUMN + PERCENT_COLUMN, + SCALE }; diff --git a/src/insets/insetparent.C b/src/insets/insetparent.C index cf495ec7ec..56dcb26b51 100644 --- a/src/insets/insetparent.C +++ b/src/insets/insetparent.C @@ -21,6 +21,7 @@ #include "support/filetools.h" #include "BufferView.h" #include "LyXView.h" +#include "support/LOstream.h" #include "commandtags.h" #include "buffer.h" #include "gettext.h"