]> git.lyx.org Git - features.git/commitdiff
* John's maths patch,
authorAngus Leeming <leeming@lyx.org>
Mon, 30 Jul 2001 13:35:08 +0000 (13:35 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 30 Jul 2001 13:35:08 +0000 (13:35 +0000)
* 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

15 files changed:
src/frontends/controllers/ChangeLog
src/frontends/controllers/ControlFloat.h
src/frontends/controllers/ControlMinipage.C
src/frontends/controllers/ControlMinipage.h
src/frontends/xforms/ChangeLog
src/frontends/xforms/FormGraphics.C
src/frontends/xforms/FormMathsBitmap.C
src/frontends/xforms/form_graphics.C
src/frontends/xforms/form_graphics.h
src/frontends/xforms/forms/form_graphics.fd
src/insets/ChangeLog
src/insets/insetgraphics.C
src/insets/insetgraphicsParams.C
src/insets/insetgraphicsParams.h
src/insets/insetparent.C

index 308f7dbbcea6abe660089f2b091bb967325beb00..97f2b422c36c09d346d9f35f4522c70a5574d38e 100644 (file)
@@ -1,3 +1,11 @@
+2001-07-30  Angus Leeming  <a.leeming@ic.ac.uk>
+
+       * 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  <larsbj@birdstep.com>
 
        * Makefile.am (libcontrollers_la_SOURCES): add ControlFloat.h and
index 1794b06926fcc16f8efdbd27c43b443af76484f8..e1dfd8def0e285d72f4e0cb5b1ba058f7389eeb6 100644 (file)
@@ -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<InsetFloat, FloatParams>  {
index 414a16775227ea7c6098cf896a5ca02440dfb475..7c7f2ee9406f749dbcfec73ecf2155cbcd443bea 100644 (file)
@@ -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 {
 
index 0d0dc976567544ca9d1abb8a94e451280d6cc6ca..04fe73176672244a3f20a0079d0308daba07f2c6 100644 (file)
@@ -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.
index 2bb7612baefcf39383f7308b170800e1482794c3..cebb0314df36f20e519d632376a066454ce36005 100644 (file)
@@ -1,3 +1,12 @@
+2001-07-29  John Levon  <moz@compsoc.man.ac.uk>
+
+       * FormMathsBitmap.C: initialise form_
+
+2001-07-29  Baruch Even  <baruch@lyx.org>
+
+       * src/forms/form_graphics.fd:
+       * src/FormGraphics.C: Added support for the new horizontal scale factor.
+
 2001-07-30  Lars Gullik Bjønnes  <larsbj@birdstep.com>
 
        * forms/makefile (SRCS): add form_float.fd
 2001-07-26  John Levon  <moz@compsoc.man.ac.uk>
 
        * 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  <baruch@lyx.org>
 
        * FormGraphics.h:
index e76973ff006fa39812c0c120f8cac5565c4d4e04..a19b8309aa7eb618fde3262521ce4d63b4fbce1a 100644 (file)
@@ -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();
index c08da574b288c7fc25b355ef7bcceaee39f4003b..86461fcc4d1762c5e66d6ebee83f63e1902cc97a 100644 (file)
@@ -40,7 +40,7 @@ FormMathsBitmap::FormMathsBitmap(LyXView * lv, Dialogs * d,
                                 FormMathsPanel const & p,
                                 vector<string> 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_;
index ec76c10092d774b852da30182cc36560be821a4f..765b5513ef1ef1769c4f68485190bd730b2f918e 100644 (file)
@@ -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;
index 224f3d176553bdd8307041c77d2f2802b43591aa..2e000643543088c3f671671dec7e970ff0cd0a86 100644 (file)
@@ -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_ */
index 0a6543a784162c47fb458d83f1bdb25aed5ee0ff..49720b2a1a79b4e8fa0aeedd00410c8554cde987 100644 (file)
@@ -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
index 3e8b1617ab51b8dfdad7f3876ca962d25056844e..dd01e0bd6de030c207489e4109e367863193be5f 100644 (file)
@@ -8,14 +8,25 @@
 
        * insetfoot.h: remove InsetFoot:: qualifier.
 
-2001-07-30  Baruch Even  <baruch@lyx.org>
+2001-07-29  Baruch Even  <baruch@lyx.org>
+
+       * 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  <baruch@lyx.org>
 
        * 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  <baruch@lyx.org>
+2001-07-29  Baruch Even  <baruch@lyx.org>
 
        * insetgraphics.C: Added EPSI to be an alias of EPS.
 
index 5dff21009079afcfc000e8af664ba4d5dd4f7627..7630dc4a139e9146949fdc287837bf301d0b5ff7 100644 (file)
@@ -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 <algorithm> // 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;
index ed5980e72a83d0e15f937800b05a84ed93c70015..f817136eebd226b7d7b7c5ee0a31557a7db30195 100644 (file)
@@ -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
index 5eb3415ffce0e11f14249a7e21a16789bb113c3a..601df89b0a740839133208d0701a4e5ace6725d0 100644 (file)
@@ -75,7 +75,8 @@ struct InsetGraphicsParams
            CM,
            INCH,
            PERCENT_PAGE,
-           PERCENT_COLUMN
+           PERCENT_COLUMN,
+               SCALE
        };
 
 
index cf495ec7ec44ed4a0055b7ca8892705e9037c0dd..56dcb26b51013c0f9c301f66a7d83e301c3616f3 100644 (file)
@@ -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"