Herbert's big graphics patch.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3446 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2002-01-29 09:26:24 +00:00
parent 65b6ee4cd3
commit f09619a7e8
21 changed files with 2062 additions and 1080 deletions

View File

@ -1,3 +1,7 @@
2002-01-27 Herbert Voss <voss@lyx.org>
* help/Graphics.hlp: added, but not finished
2002-01-26 Dekel Tsur <dekelts@tau.ac.il> 2002-01-26 Dekel Tsur <dekelts@tau.ac.il>
* fonts-xlfd: * fonts-xlfd:

8
lib/help/Graphics.hlp Normal file
View File

@ -0,0 +1,8 @@
@bFilename:
You do not need the extension like *eps, when your
config file of graphicx is present and has such
entries.
@bBounding Box:
The image size in Pixeln. Given through lower left
corner (x0,y0) and upper right corner (y1,y2)

View File

@ -1,3 +1,7 @@
2002-01-27 Herbert Voss <voss@lyx.org>
* buffer.C: link old Figure to new graphic inset
2002-01-26 Dekel Tsur <dekelts@tau.ac.il> 2002-01-26 Dekel Tsur <dekelts@tau.ac.il>
* FontLoader.C (getFontinfo): Change the latex font names in order * FontLoader.C (getFontinfo): Change the latex font names in order

View File

@ -1513,8 +1513,8 @@ void Buffer::readInset(LyXLex & lex, Paragraph *& par,
} else if (tmptok == "Formula") { } else if (tmptok == "Formula") {
inset = new InsetFormula; inset = new InsetFormula;
} else if (tmptok == "Figure") { // Backward compatibility } else if (tmptok == "Figure") { // Backward compatibility
inset = new InsetFig(100, 100, *this); // inset = new InsetFig(100, 100, *this);
//inset = new InsetGraphics; inset = new InsetGraphics;
} else if (tmptok == "Graphics") { } else if (tmptok == "Graphics") {
inset = new InsetGraphics; inset = new InsetGraphics;
} else if (tmptok == "Info") {// backwards compatibility } else if (tmptok == "Info") {// backwards compatibility

View File

@ -1,3 +1,8 @@
2002-01-27 Herbert Voss <voss@lyx.org>
* ControlGraphic.[Ch]: added support for Bounding Box, other
small changes
2002-01-25 Angus Leeming <a.leeming@ic.ac.uk> 2002-01-25 Angus Leeming <a.leeming@ic.ac.uk>
* ControlAboutlyx.h: * ControlAboutlyx.h:

View File

@ -9,9 +9,11 @@
* *
* \file ControlGraphics.C * \file ControlGraphics.C
* \author Angus Leeming <a.leeming@ic.ac.uk> * \author Angus Leeming <a.leeming@ic.ac.uk>
* \author Herbert Voss <voss@perce.de>
*/ */
#include <config.h> #include <config.h>
#include <fstream>
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation #pragma implementation
@ -31,12 +33,15 @@
#include "support/FileInfo.h" // for FileInfo #include "support/FileInfo.h" // for FileInfo
#include "helper_funcs.h" // for browseFile #include "helper_funcs.h" // for browseFile
#include "support/lstrings.h"
#include "support/filetools.h" // for AddName #include "support/filetools.h" // for AddName
#include "BufferView.h" #include "BufferView.h"
using std::pair; using std::pair;
using std::make_pair; using std::make_pair;
using std::ifstream;
ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d) ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d)
: ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d) : ControlInset<InsetGraphics, InsetGraphicsParams>(lv, d)
{ {
@ -80,7 +85,7 @@ string const ControlGraphics::Browse(string const & in_name)
{ {
string const title = N_("Graphics"); string const title = N_("Graphics");
// FIXME: currently we need the second '|' to prevent mis-interpretation // FIXME: currently we need the second '|' to prevent mis-interpretation
string const pattern = "*.(ps|eps|png|jpeg|jpg|gif)|"; string const pattern = "*.(ps|eps|png|jpeg|jpg|gif|gz)|";
// Does user clipart directory exist? // Does user clipart directory exist?
string clipdir = AddName (user_lyxdir, "clipart"); string clipdir = AddName (user_lyxdir, "clipart");
@ -93,3 +98,33 @@ string const ControlGraphics::Browse(string const & in_name)
// Show the file browser dialog // Show the file browser dialog
return browseFile(&lv_, in_name, title, pattern, dir1); return browseFile(&lv_, in_name, title, pattern, dir1);
} }
string const ControlGraphics::readBB(string const & file)
{
// in a file it's an entry like %%BoundingBox:23 45 321 345
// the first number can following without a space, so we have
// to check a bit more.
// ControlGraphics::bbChanged = false;
std::ifstream is(file.c_str());
while (is) {
string s;
is >> s;
if (contains(s,"%%BoundingBox:")) {
string a, b, c, d;
is >> a >> b >> c >> d;
if (is) {
if (s != "%%BoundingBox:")
return (s.substr(14)+" "+a+" "+b+" "+c+" ");
else
return (a+" "+b+" "+c+" "+d+" ");
}
}
}
return string();
}
void ControlGraphics::help() const
{
lv_.getDialogs()->showFile(i18nLibFileSearch("help","Graphics.hlp"));
}

View File

@ -10,7 +10,8 @@
* *
* \file ControlGraphics.h * \file ControlGraphics.h
* \author Angus Leeming <a.leeming@ic.ac.uk> * \author Angus Leeming <a.leeming@ic.ac.uk>
*/ * \author Herbert Voss <voss@perce.de>
*/
#ifndef CONTROLGRAPHICS_H #ifndef CONTROLGRAPHICS_H
#define CONTROLGRAPHICS_H #define CONTROLGRAPHICS_H
@ -35,6 +36,12 @@ public:
/// Browse for a file /// Browse for a file
string const Browse(string const &); string const Browse(string const &);
/// Read the Bounding Box from a eps or ps-file
string const readBB(string const & file);
/// Control the bb
bool bbChanged;
/// Show Help file
void help() const;
private: private:
/// Dispatch the changed parameters to the kernel. /// Dispatch the changed parameters to the kernel.
@ -48,3 +55,4 @@ private:
}; };
#endif // CONTROLGRAPHICS_H #endif // CONTROLGRAPHICS_H

View File

@ -1,3 +1,13 @@
2002-01-27 Herbert Voss <voss@lyx.org>
* FormGraphic.[Ch]:
* form_graphic.[Ch]:
* forms/form_graphic.fd: rewritten to support graphicx with
all options and to be sure that the old figinsets are correct
converted.
* xforms-helpers.h: added two choice const for the LyXLength
one with all and one only with length which have a unit.
2002-01-28 Angus Leeming <a.leeming@ic.ac.uk> 2002-01-28 Angus Leeming <a.leeming@ic.ac.uk>
* FormAboutlyx.[Ch]: Removed redundant form() method and * FormAboutlyx.[Ch]: Removed redundant form() method and

View File

@ -26,7 +26,8 @@
#include "input_validators.h" #include "input_validators.h"
#include "debug.h" // for lyxerr #include "debug.h" // for lyxerr
#include "support/lstrings.h" // for strToDbl & tostr #include "support/lstrings.h" // for strToDbl & tostr
#include "support/FileInfo.h" // for FileInfo #include "support/FileInfo.h"
#include "support/filetools.h" // for MakeAbsPath etc
#include "insets/insetgraphicsParams.h" #include "insets/insetgraphicsParams.h"
#include "lyxrc.h" // for lyxrc.display_graphics #include "lyxrc.h" // for lyxrc.display_graphics
@ -34,22 +35,11 @@ using std::endl;
namespace { namespace {
// Zero test for double precision numbers // Bound the number of input characters
double const tol = 1.0e-08;
// The maximum digits for the image scale
int const SCALE_MAXDIGITS = 3; int const SCALE_MAXDIGITS = 3;
// The maximum digits for the image width
int const WIDTH_MAXDIGITS = 3; int const WIDTH_MAXDIGITS = 3;
// The maximum digits for the image height
int const HEIGHT_MAXDIGITS = 3; int const HEIGHT_MAXDIGITS = 3;
// The max characters in the rotation angle (minus sign and 3 digits)
int const ROTATE_MAXCHARS = 4; int const ROTATE_MAXCHARS = 4;
// The maximum characters in a filename.
int const FILENAME_MAXCHARS = 1024; int const FILENAME_MAXCHARS = 1024;
} // namespace anon } // namespace anon
@ -62,63 +52,105 @@ FormGraphics::FormGraphics(ControlGraphics & c)
{} {}
void FormGraphics::redraw()
{
if(form() && form()->visible)
fl_redraw_form(form());
else
return;
FL_FORM * outer_form = fl_get_active_folder(dialog_->tabFolder);
if (outer_form && outer_form->visible)
fl_redraw_form(outer_form);
}
void FormGraphics::build() void FormGraphics::build()
{ {
dialog_.reset(build_graphics()); dialog_.reset(build_graphics());
// This is the place to add settings of the dialog that did not go
// to the .fd file.
// Set the input widgets to issue a callback to input() whenever
// they change, so we can verify their content.
fl_set_input_return (dialog_->input_filename, FL_RETURN_CHANGED);
fl_set_input_return (dialog_->input_scale, FL_RETURN_CHANGED);
fl_set_input_return (dialog_->input_width, FL_RETURN_CHANGED);
fl_set_input_return (dialog_->input_height, FL_RETURN_CHANGED);
fl_set_input_return (dialog_->input_rotate_angle, FL_RETURN_CHANGED);
fl_set_input_return (dialog_->input_subcaption, FL_RETURN_CHANGED);
// Set the maximum characters that can be written in the input texts.
fl_set_input_maxchars(dialog_->input_scale, SCALE_MAXDIGITS);
fl_set_input_maxchars(dialog_->input_width, WIDTH_MAXDIGITS);
fl_set_input_maxchars(dialog_->input_height, HEIGHT_MAXDIGITS);
fl_set_input_maxchars(dialog_->input_filename, FILENAME_MAXCHARS);
fl_set_input_maxchars(dialog_->input_rotate_angle, ROTATE_MAXCHARS);
// Set input filter on width and height to make them accept only
// unsigned numbers.
fl_set_input_filter(dialog_->input_scale, fl_unsigned_float_filter);
fl_set_input_filter(dialog_->input_width, fl_unsigned_float_filter);
fl_set_input_filter(dialog_->input_height, fl_unsigned_float_filter);
// Set input filter on rotate_angle to make it accept only
// floating point numbers.
fl_set_input_filter(dialog_->input_rotate_angle, fl_float_filter);
// Create the contents of the choices
string const width = " cm | inch | page %% | column %% ";
fl_addto_choice(dialog_->choice_width_units, width.c_str());
string const height = " cm | inch | page %% ";
fl_addto_choice(dialog_->choice_height_units, height.c_str());
// Manage the ok, apply, restore and cancel/close buttons // Manage the ok, apply, restore and cancel/close buttons
bc().setOK(dialog_->button_ok); bc().setOK(dialog_->button_ok);
bc().setApply(dialog_->button_apply); // bc().setApply(dialog_->button_apply);
bc().setCancel(dialog_->button_cancel); bc().setCancel(dialog_->button_cancel);
bc().setRestore(dialog_->button_restore); bc().setRestore(dialog_->button_restore);
bc().addReadOnly(dialog_->input_filename); // the file section
bc().addReadOnly(dialog_->button_browse); file_.reset(build_file());
bc().addReadOnly(dialog_->check_display);
bc().addReadOnly(dialog_->input_scale); fl_set_input_return (file_->input_filename, FL_RETURN_CHANGED);
bc().addReadOnly(dialog_->input_width); fl_set_input_return (file_->input_subcaption, FL_RETURN_CHANGED);
bc().addReadOnly(dialog_->choice_width_units); fl_set_input_return (file_->input_bbx0, FL_RETURN_CHANGED);
bc().addReadOnly(dialog_->input_height); fl_set_input_return (file_->input_bby0, FL_RETURN_CHANGED);
bc().addReadOnly(dialog_->choice_height_units); fl_set_input_return (file_->input_bbx1, FL_RETURN_CHANGED);
bc().addReadOnly(dialog_->input_rotate_angle); fl_set_input_return (file_->input_bby1, FL_RETURN_CHANGED);
bc().addReadOnly(dialog_->input_subcaption); fl_set_input_maxchars(file_->input_filename, FILENAME_MAXCHARS);
bc().addReadOnly(dialog_->check_subcaption);
string const bb_units = "pt|cm|in";
fl_addto_choice(file_->choice_bb_x0, bb_units.c_str());
fl_addto_choice(file_->choice_bb_y0, bb_units.c_str());
fl_addto_choice(file_->choice_bb_x1, bb_units.c_str());
fl_addto_choice(file_->choice_bb_y1, bb_units.c_str());
bc().addReadOnly(file_->button_browse);
bc().addReadOnly(file_->check_subcaption);
bc().addReadOnly(file_->button_getBB);
bc().addReadOnly(file_->button_clip);
bc().addReadOnly(file_->button_draft);
// the size section
size_.reset(build_size());
fl_set_input_return (size_->input_scale, FL_RETURN_CHANGED);
fl_set_input_return (size_->input_width, FL_RETURN_CHANGED);
fl_set_input_return (size_->input_height, FL_RETURN_CHANGED);
fl_set_input_return (size_->input_lyxwidth, FL_RETURN_CHANGED);
fl_set_input_return (size_->input_lyxheight, FL_RETURN_CHANGED);
fl_set_input_maxchars(size_->input_scale, SCALE_MAXDIGITS);
fl_set_input_maxchars(size_->input_width, WIDTH_MAXDIGITS);
fl_set_input_maxchars(size_->input_height, HEIGHT_MAXDIGITS);
fl_set_input_filter(size_->input_scale, fl_unsigned_float_filter);
fl_set_input_filter(size_->input_width, fl_unsigned_float_filter);
fl_set_input_filter(size_->input_height, fl_unsigned_float_filter);
fl_addto_choice(size_->choice_width_units, choice_Length_All.c_str());
fl_addto_choice(size_->choice_height_units, choice_Length_All.c_str());
fl_addto_choice(size_->choice_width_lyxwidth, choice_Length_All.c_str());
fl_addto_choice(size_->choice_width_lyxheight, choice_Length_All.c_str());
bc().addReadOnly(size_->button_default);
bc().addReadOnly(size_->button_wh);
bc().addReadOnly(size_->button_scale);
bc().addReadOnly(size_->check_aspectratio);
bc().addReadOnly(size_->radio_check_display);
bc().addReadOnly(size_->radio_display_mono);
bc().addReadOnly(size_->radio_display_gray);
bc().addReadOnly(size_->radio_display_color);
// the rotate section
special_.reset(build_special());
fl_set_input_return (special_->input_rotate_angle, FL_RETURN_CHANGED);
string const choice_origin =
"default|" // not important
"leftTop|leftBottom|leftBaseline|" // lt lb lB
"center|" // c
"centerTop|centerBottom|centerBaseline|" // ct cb cB
"rightTop|rightBottom|rightBaseline|" // rt rb rB
"referencePoint"; // special
fl_addto_choice(special_->choice_origin, choice_origin.c_str());
fl_set_input_return (special_->input_special, FL_RETURN_CHANGED);
fl_set_input_maxchars(special_->input_rotate_angle, ROTATE_MAXCHARS);
fl_set_input_filter(special_->input_rotate_angle, fl_float_filter);
// add the different tabfolders
fl_addto_tabfolder(dialog_->tabFolder, _("Filename"), file_->form);
fl_addto_tabfolder(dialog_->tabFolder, _("Image size"), size_->form);
fl_addto_tabfolder(dialog_->tabFolder, _("Special"), special_->form);
} }
@ -126,87 +158,57 @@ void FormGraphics::apply()
{ {
// Create the parameters structure and fill the data from the dialog. // Create the parameters structure and fill the data from the dialog.
InsetGraphicsParams & igp = controller().params(); InsetGraphicsParams & igp = controller().params();
igp.filename = getStringFromInput(file_->input_filename);
igp.filename = fl_get_input(dialog_->input_filename); if (!controller().bbChanged) // different to the original one?
igp.bb = string(); // don't write anything
if (lyxrc.display_graphics == "no") { else {
string bb;
if (getStringFromInput(file_->input_bbx0).empty())
bb = "0 ";
else
bb = getLengthFromWidgets(file_->input_bbx0,file_->choice_bb_x0)+" ";
if (getStringFromInput(file_->input_bby0).empty())
bb += "0 ";
else
bb += (getLengthFromWidgets(file_->input_bby0,file_->choice_bb_y0)+" ");
if (getStringFromInput(file_->input_bbx1).empty())
bb += "0 ";
else
bb += (getLengthFromWidgets(file_->input_bbx1,file_->choice_bb_x1)+" ");
if (getStringFromInput(file_->input_bby1).empty())
bb += "0 ";
else
bb += (getLengthFromWidgets(file_->input_bby1,file_->choice_bb_y1)+" ");
igp.bb = bb;
}
igp.draft = fl_get_button(file_->button_draft);
igp.clip = fl_get_button(file_->button_clip);
igp.subcaption = fl_get_button(file_->check_subcaption);
igp.subcaptionText = getStringFromInput(file_->input_subcaption);
if (fl_get_button(size_->radio_check_display)) {
igp.display = InsetGraphicsParams::NONE; igp.display = InsetGraphicsParams::NONE;
} else if (fl_get_button(size_->radio_display_mono)) {
} else { igp.display = InsetGraphicsParams::MONOCHROME;
if (fl_get_button(dialog_->check_display)) { } else if (fl_get_button(size_->radio_display_gray)) {
if (lyxrc.display_graphics == "mono") { igp.display = InsetGraphicsParams::GRAYSCALE;
igp.display = InsetGraphicsParams::MONOCHROME; } else if (fl_get_button(size_->radio_display_color)) {
} else if (lyxrc.display_graphics == "gray") { igp.display = InsetGraphicsParams::COLOR;
igp.display = InsetGraphicsParams::GRAYSCALE;
} else if (lyxrc.display_graphics == "color") {
igp.display = InsetGraphicsParams::COLOR;
}
} else {
igp.display = InsetGraphicsParams::NONE;
}
} }
if (fl_get_button(size_->button_default))
igp.size_type = InsetGraphicsParams::DEFAULT_SIZE;
else if (fl_get_button(size_->button_wh))
igp.size_type = InsetGraphicsParams::WH;
else
igp.size_type = InsetGraphicsParams::SCALE;
igp.width = LyXLength(getLengthFromWidgets(size_->input_width,size_->choice_width_units));
igp.height = LyXLength(getLengthFromWidgets(size_->input_height,size_->choice_height_units));
igp.scale = strToInt(getStringFromInput(size_->input_scale));
igp.keepAspectRatio = fl_get_button(size_->check_aspectratio);
igp.lyxwidth = LyXLength(getLengthFromWidgets(size_->input_lyxwidth,size_->choice_width_lyxwidth));
igp.lyxheight = LyXLength(getLengthFromWidgets(size_->input_lyxheight,size_->choice_width_lyxheight));
double const scale =
strToDbl(strip(fl_get_input(dialog_->input_scale)));
if (scale < tol) {
double const width =
strToDbl(strip(fl_get_input(dialog_->input_width)));
if (width < tol) {
igp.widthResize = InsetGraphicsParams::DEFAULT_SIZE;
igp.widthSize = 0.0;
} else {
switch (fl_get_choice(dialog_->choice_width_units)) {
case 2:
igp.widthResize = InsetGraphicsParams::INCH;
break;
case 3:
igp.widthResize =
InsetGraphicsParams::PERCENT_PAGE;
break;
case 4:
igp.widthResize =
InsetGraphicsParams::PERCENT_COLUMN;
break;
default:
igp.widthResize = InsetGraphicsParams::CM;
break;
}
igp.widthSize = width;
}
double const height =
strToDbl(strip(fl_get_input(dialog_->input_height)));
if (height < tol) {
igp.heightResize = InsetGraphicsParams::DEFAULT_SIZE;
igp.heightSize = 0.0;
} else {
switch (fl_get_choice(dialog_->choice_height_units)) {
case 2:
igp.heightResize = InsetGraphicsParams::INCH;
break;
case 3:
igp.heightResize =
InsetGraphicsParams::PERCENT_PAGE;
break;
default:
igp.heightResize = InsetGraphicsParams::CM;
break;
}
igp.heightSize = height;
}
} else {
igp.widthResize = InsetGraphicsParams::DEFAULT_SIZE;
igp.widthSize = 0.0;
igp.heightResize = InsetGraphicsParams::SCALE;
igp.heightSize = scale;
}
igp.rotateAngle = igp.rotateAngle =
strToDbl(strip(fl_get_input(dialog_->input_rotate_angle))); strToDbl(getStringFromInput(special_->input_rotate_angle));
while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) { while (igp.rotateAngle < 0.0 || igp.rotateAngle > 360.0) {
if (igp.rotateAngle < 0.0) { if (igp.rotateAngle < 0.0) {
igp.rotateAngle += 360.0; igp.rotateAngle += 360.0;
@ -214,155 +216,177 @@ void FormGraphics::apply()
igp.rotateAngle -= 360.0; igp.rotateAngle -= 360.0;
} }
} }
if (fl_get_choice(special_->choice_origin) > 0)
igp.subcaption = fl_get_button(dialog_->check_subcaption); igp.rotateOrigin = fl_get_choice_text(special_->choice_origin);
igp.subcaptionText = fl_get_input(dialog_->input_subcaption); else
igp.rotateOrigin = string();
igp.special = getStringFromInput(special_->input_special);
igp.testInvariant(); igp.testInvariant();
} }
void FormGraphics::update() void FormGraphics::update()
{ { string unit = "cm";
if (lyxrc.default_papersize < 3)
unit = "in";
string const defaultUnit = string(unit);
// Update dialog with details from inset // Update dialog with details from inset
InsetGraphicsParams & igp = controller().params(); InsetGraphicsParams & igp = controller().params();
fl_set_input(file_->input_filename, igp.filename.c_str());
// Update the filename input field // set the bounding box values, if exists. First we need the whole
fl_set_input(dialog_->input_filename, // path, because the controller knows nothing about the doc-dir
igp.filename.c_str()); lyxerr << "GraphicsUpdate::BoundingBox = " << igp.bb << "\n";
controller().bbChanged = false;
// To display or not to display if (igp.bb.empty()) {
if (lyxrc.display_graphics == "no") { string const fileWithAbsPath = MakeAbsPath(igp.filename, OnlyPath(igp.filename));
fl_set_button(dialog_->check_display, 0); string bb = controller().readBB(fileWithAbsPath);
} else { lyxerr << "file::BoundingBox = " << bb << "\n";
if (igp.display == InsetGraphicsParams::NONE) { if (!bb.empty()) {
fl_set_button(dialog_->check_display, 0); // get the values from the file
} else { // in this case we always have the point-unit
fl_set_button(dialog_->check_display, 1); fl_set_input(file_->input_bbx0, token(bb,' ',0).c_str());
} fl_set_input(file_->input_bby0, token(bb,' ',1).c_str());
fl_set_input(file_->input_bbx1, token(bb,' ',2).c_str());
fl_set_input(file_->input_bby1, token(bb,' ',3).c_str());
}
} else { // get the values from the inset
controller().bbChanged = true;
LyXLength anyLength;
anyLength = LyXLength(token(igp.bb,' ',0));
updateWidgetsFromLength(file_->input_bbx0,file_->choice_bb_x0,anyLength,"pt");
anyLength = LyXLength(token(igp.bb,' ',1));
updateWidgetsFromLength(file_->input_bby0,file_->choice_bb_y0,anyLength,"pt");
anyLength = LyXLength(token(igp.bb,' ',2));
updateWidgetsFromLength(file_->input_bbx1,file_->choice_bb_x1,anyLength,"pt");
anyLength = LyXLength(token(igp.bb,' ',3));
updateWidgetsFromLength(file_->input_bby1,file_->choice_bb_y1,anyLength,"pt");
} }
// Update the draft and clip mode
setEnabled(dialog_->check_display, (lyxrc.display_graphics != "no")); fl_set_button(file_->button_draft, igp.draft);
fl_set_button(file_->button_clip, igp.clip);
if (igp.heightResize == InsetGraphicsParams::SCALE) {
string number = tostr(igp.heightSize);
fl_set_input(dialog_->input_scale, number.c_str());
fl_set_input(dialog_->input_width, "");
fl_set_choice(dialog_->choice_width_units, 1);
fl_set_input(dialog_->input_height, "");
fl_set_choice(dialog_->choice_height_units, 1);
} else {
fl_set_input(dialog_->input_scale, "");
string number;
if (igp.widthResize != InsetGraphicsParams::DEFAULT_SIZE) {
number = tostr(igp.widthSize);
}
fl_set_input(dialog_->input_width, number.c_str());
int pos = 1;
//use inch as default with US papersizes in lyxrc
if (lyxrc.default_papersize < 3)
pos = 2;
switch (igp.widthResize) {
case InsetGraphicsParams::CM:
pos = 1; break;
case InsetGraphicsParams::INCH:
pos = 2; break;
case InsetGraphicsParams::PERCENT_PAGE:
pos = 3; break;
case InsetGraphicsParams::PERCENT_COLUMN:
pos = 4; break;
default:
break;
}
fl_set_choice(dialog_->choice_width_units, pos);
number.erase();
if (igp.heightResize != InsetGraphicsParams::DEFAULT_SIZE) {
number = tostr(igp.heightSize);
}
fl_set_input(dialog_->input_height, number.c_str());
pos = 1;
//use inch as default with US papersizes in lyxrc
if (lyxrc.default_papersize < 3)
pos = 2;
switch (igp.heightResize) {
case InsetGraphicsParams::CM:
pos = 1; break;
case InsetGraphicsParams::INCH:
pos = 2; break;
case InsetGraphicsParams::PERCENT_PAGE:
pos = 3; break;
default:
break;
}
fl_set_choice(dialog_->choice_height_units, pos);
}
// Update the rotate angle
fl_set_input(dialog_->input_rotate_angle,
tostr(igp.rotateAngle).c_str());
// Update the subcaption check button and input field // Update the subcaption check button and input field
fl_set_button(dialog_->check_subcaption, fl_set_button(file_->check_subcaption, igp.subcaption);
igp.subcaption); fl_set_input(file_->input_subcaption, igp.subcaptionText.c_str());
fl_set_input(dialog_->input_subcaption, setEnabled(file_->input_subcaption,
igp.subcaptionText.c_str()); fl_get_button(file_->check_subcaption));
switch (igp.display) {
setEnabled(dialog_->input_subcaption, case InsetGraphicsParams::NONE: { // dont't display
fl_get_button(dialog_->check_subcaption)); fl_set_button(size_->radio_check_display, 1);
break;
}
case InsetGraphicsParams::MONOCHROME: {
fl_set_button(size_->radio_display_mono, 1);
break;
}
case InsetGraphicsParams::GRAYSCALE: {
fl_set_button(size_->radio_display_gray, 1);
break;
}
case InsetGraphicsParams::COLOR: {
fl_set_button(size_->radio_display_color, 1);
break;
}
}
updateWidgetsFromLength(size_->input_width,size_->choice_width_units,igp.width,defaultUnit);
updateWidgetsFromLength(size_->input_height,size_->choice_height_units,igp.height,defaultUnit);
fl_set_input(size_->input_scale, tostr(igp.scale).c_str());
switch (igp.size_type) {
case InsetGraphicsParams::DEFAULT_SIZE: {
fl_set_button(size_->button_default,1);
setEnabled(size_->input_width, 0);
setEnabled(size_->choice_width_units, 0);
setEnabled(size_->input_height, 0);
setEnabled(size_->choice_height_units, 0);
setEnabled(size_->input_scale, 0);
break;
}
case InsetGraphicsParams::WH: {
fl_set_button(size_->button_wh, 1);
setEnabled(size_->input_width, 1);
setEnabled(size_->choice_width_units, 1);
setEnabled(size_->input_height, 1);
setEnabled(size_->choice_height_units, 1);
setEnabled(size_->input_scale, 0);
break;
}
case InsetGraphicsParams::SCALE: {
fl_set_button(size_->button_scale, 1);
setEnabled(size_->input_width, 0);
setEnabled(size_->choice_width_units, 0);
setEnabled(size_->input_height, 0);
setEnabled(size_->choice_height_units, 0);
setEnabled(size_->input_scale, 1);
break;
}
}
fl_set_button(size_->check_aspectratio,igp.keepAspectRatio);
// now the lyx-internally viewsize
updateWidgetsFromLength(size_->input_lyxwidth,size_->choice_width_lyxwidth,igp.lyxwidth,defaultUnit);
updateWidgetsFromLength(size_->input_lyxheight,size_->choice_width_lyxheight,igp.lyxheight,defaultUnit);
// Update the rotate angle and special commands
fl_set_input(special_->input_rotate_angle,
tostr(igp.rotateAngle).c_str());
if (igp.rotateOrigin.empty())
fl_set_choice(special_->choice_origin,0);
else
fl_set_choice_text(special_->choice_origin,igp.rotateOrigin.c_str());
fl_set_input(special_->input_special, igp.special.c_str());
} }
ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long) ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
{ {
if (ob == dialog_->button_browse) { if (ob == file_->button_browse) {
// Get the filename from the dialog // Get the filename from the dialog
string const in_name = fl_get_input(dialog_->input_filename); string const in_name = getStringFromInput(file_->input_filename);
string const out_name = controller().Browse(in_name); string const out_name = controller().Browse(in_name);
if (out_name != in_name && !out_name.empty()) { if (out_name != in_name && !out_name.empty()) {
fl_set_input(dialog_->input_filename, out_name.c_str()); fl_set_input(file_->input_filename, out_name.c_str());
} }
} } else if (!controller().bbChanged &&
((ob == file_->input_bbx0) || (ob == file_->input_bby0) ||
if (ob == dialog_->input_scale) { (ob == file_->input_bbx1) || (ob == file_->input_bby1) ||
double const scale = (ob == file_->choice_bb_x0) || (ob == file_->choice_bb_y0) ||
strToDbl(strip(fl_get_input(dialog_->input_scale))); (ob == file_->choice_bb_x1) || (ob == file_->choice_bb_y1))) {
if (scale > tol) { controller().bbChanged = true;
fl_set_input(dialog_->input_width, ""); } else if (ob == size_->button_default) {
fl_set_choice(dialog_->choice_width_units, 1); setEnabled(size_->input_width, 0);
fl_set_input(dialog_->input_height, ""); setEnabled(size_->choice_width_units, 0);
fl_set_choice(dialog_->choice_height_units, 1); setEnabled(size_->input_height, 0);
setEnabled(size_->choice_height_units, 0);
setEnabled(size_->input_scale, 0);
} else if (ob == size_->button_wh) {
setEnabled(size_->input_width, 1);
setEnabled(size_->choice_width_units, 1);
setEnabled(size_->input_height, 1);
setEnabled(size_->choice_height_units, 1);
setEnabled(size_->input_scale, 0);
} else if (ob == size_->button_scale) {
setEnabled(size_->input_width, 0);
setEnabled(size_->choice_width_units, 0);
setEnabled(size_->input_height, 0);
setEnabled(size_->choice_height_units, 0);
setEnabled(size_->input_scale, 1);
} else if (ob == file_->check_subcaption) {
setEnabled(file_->input_subcaption,
fl_get_button(file_->check_subcaption));
} else if (ob == file_->button_getBB) {
string const filename = getStringFromInput(file_->input_filename);
if (!filename.empty()) {
string const fileWithAbsPath = MakeAbsPath(filename, OnlyPath(filename));
string bb = controller().readBB(fileWithAbsPath);
lyxerr << "getBB::BoundingBox = " << bb << "\n";
if (!bb.empty()) {
fl_set_input(file_->input_bbx0, token(bb,' ',0).c_str());
fl_set_input(file_->input_bby0, token(bb,' ',1).c_str());
fl_set_input(file_->input_bbx1, token(bb,' ',2).c_str());
fl_set_input(file_->input_bby1, token(bb,' ',3).c_str());
} }
controller().bbChanged = false;
}
} else if (ob == dialog_->button_help) {
controller().help();
} }
if (ob == dialog_->input_width || ob == dialog_->input_height) {
double const width =
strToDbl(strip(fl_get_input(dialog_->input_width)));
double const height =
strToDbl(strip(fl_get_input(dialog_->input_height)));
if (width > tol || height > tol) {
fl_set_input(dialog_->input_scale, "");
}
}
if (ob == dialog_->check_subcaption) {
setEnabled(dialog_->input_subcaption,
fl_get_button(dialog_->check_subcaption));
}
return checkInput(); return checkInput();
} }
@ -372,20 +396,16 @@ ButtonPolicy::SMInput FormGraphics::checkInput()
// Put verifications that the dialog shows some sane values, // Put verifications that the dialog shows some sane values,
// if not disallow clicking on ok/apply. // if not disallow clicking on ok/apply.
// Possibly use a label in the bottom of the dialog to give the reason. // Possibly use a label in the bottom of the dialog to give the reason.
ButtonPolicy::SMInput activate = ButtonPolicy::SMI_VALID; ButtonPolicy::SMInput activate = ButtonPolicy::SMI_VALID;
// We verify now that there is a filename, it exists, it's a file // We verify now that there is a filename, it exists, it's a file
// and it's readable. // and it's readable.
string filename = fl_get_input(dialog_->input_filename); string filename = getStringFromInput(file_->input_filename);
FileInfo file(filename); FileInfo file(filename);
if (filename.empty() if (filename.empty() || !file.isOK() || !file.exist()
|| !file.isOK() || !file.isRegular() || !file.readable()
|| !file.exist()
|| !file.isRegular()
|| !file.readable()
) )
activate = ButtonPolicy::SMI_INVALID; activate = ButtonPolicy::SMI_INVALID;
return activate; return activate;
} }

View File

@ -10,11 +10,14 @@
* *
* \file FormGraphics.h * \file FormGraphics.h
* \author Baruch Even, baruch.even@writeme.com * \author Baruch Even, baruch.even@writeme.com
* \author Herbert Voss, voss@lyx.org
*/ */
#ifndef FORMGRAPHICS_H #ifndef FORMGRAPHICS_H
#define FORMGRAPHICS_H #define FORMGRAPHICS_H
#include <boost/smart_ptr.hpp>
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface #pragma interface
#endif #endif
@ -24,6 +27,9 @@
class ControlGraphics; class ControlGraphics;
struct FD_form_graphics; struct FD_form_graphics;
struct FD_form_file;
struct FD_form_size;
struct FD_form_special;
/** This class provides an XForms implementation of the Graphics Dialog. /** This class provides an XForms implementation of the Graphics Dialog.
*/ */
@ -33,6 +39,10 @@ public:
FormGraphics(ControlGraphics &); FormGraphics(ControlGraphics &);
private: private:
/** Redraw the form (on receipt of a Signal indicating, for example,
that the xforms colours have been re-mapped). */
virtual void redraw();
/// Set the Params variable for the Controller. /// Set the Params variable for the Controller.
virtual void apply(); virtual void apply();
/// Build the dialog. /// Build the dialog.
@ -41,13 +51,27 @@ private:
virtual void update(); virtual void update();
/// Filter the inputs on callback from xforms /// Filter the inputs on callback from xforms
virtual ButtonPolicy::SMInput input(FL_OBJECT *, long); virtual ButtonPolicy::SMInput input(FL_OBJECT *, long);
///
void help();
/// Verify that the input is correct. If not disable ok/apply buttons. /// Verify that the input is correct. If not disable ok/apply buttons.
ButtonPolicy::SMInput checkInput(); ButtonPolicy::SMInput checkInput();
/// Fdesign generated method /// Fdesign generated method
FD_form_graphics * build_graphics(); FD_form_graphics * build_graphics();
///
FD_form_file * build_file();
///
FD_form_size * build_size();
///
FD_form_special * build_special();
/// Real GUI implementation.
boost::scoped_ptr<FD_form_file> file_;
///
boost::scoped_ptr<FD_form_size> size_;
///
boost::scoped_ptr<FD_form_special> special_;
}; };
#endif // FORMGRAPHICS_H #endif // FORMGRAPHICS_H

View File

@ -22,103 +22,30 @@ FD_form_graphics * FormGraphics::build_graphics()
FL_OBJECT *obj; FL_OBJECT *obj;
FD_form_graphics *fdui = new FD_form_graphics; FD_form_graphics *fdui = new FD_form_graphics;
fdui->form = fl_bgn_form(FL_NO_BOX, 490, 390); fdui->form = fl_bgn_form(FL_NO_BOX, 510, 320);
fdui->form->u_vdata = this; fdui->form->u_vdata = this;
obj = fl_add_box(FL_UP_BOX, 0, 0, 490, 390, ""); obj = fl_add_box(FL_FLAT_BOX, 0, 0, 510, 320, "");
fl_set_object_lsize(obj, FL_NORMAL_SIZE); fdui->tabFolder = obj = fl_add_tabfolder(FL_TOP_TABFOLDER, 10, 5, 490, 270, _("Tabbed folder"));
fl_set_object_gravity(obj, FL_NorthWest, FL_SouthEast); fl_set_object_resize(obj, FL_RESIZE_ALL);
{ {
char const * const dummy = N_("File|#F"); char const * const dummy = N_("Help|#H");
fdui->input_filename = obj = fl_add_input(FL_NORMAL_INPUT, 90, 20, 270, 30, idex(_(dummy))); fdui->button_help = obj = fl_add_button(FL_NORMAL_BUTTON, 440, 280, 60, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Browse...|#B");
fdui->button_browse = obj = fl_add_button(FL_NORMAL_BUTTON, 370, 20, 100, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 20, 70, 240, 140, _("Size"));
{
char const * const dummy = N_("Width|#W");
fdui->input_width = obj = fl_add_input(FL_NORMAL_INPUT, 90, 80, 85, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1); fl_set_button_shortcut(obj, scex(_(dummy)), 1);
} }
fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseInputCB, 0); fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fdui->choice_width_units = obj = fl_add_choice(FL_NORMAL_CHOICE, 180, 80, 65, 30, "");
fl_set_object_boxtype(obj, FL_FRAME_BOX);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Height|#H");
fdui->input_height = obj = fl_add_input(FL_NORMAL_INPUT, 90, 120, 85, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fdui->choice_height_units = obj = fl_add_choice(FL_NORMAL_CHOICE, 180, 120, 65, 30, "");
fl_set_object_boxtype(obj, FL_FRAME_BOX);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Scale|#S");
fdui->input_scale = obj = fl_add_input(FL_NORMAL_INPUT, 90, 170, 85, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
// xgettext:no-c-format
obj = fl_add_text(FL_NORMAL_TEXT, 180, 170, 60, 30, _("%"));
fl_set_object_lalign(obj, FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 270, 70, 200, 70, _("Rotation"));
{
char const * const dummy = N_("Angle|#n");
fdui->input_rotate_angle = obj = fl_add_input(FL_INT_INPUT, 340, 90, 70, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
obj = fl_add_text(FL_NORMAL_TEXT, 410, 90, 50, 30, _("degs"));
fl_set_object_lalign(obj, FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 270, 160, 200, 50, _("Display Options"));
{
char const * const dummy = N_("Display in LyX|#D");
fdui->check_display = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 400, 170, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_LEFT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 20, 230, 450, 90, _("Subcaption"));
{
char const * const dummy = N_("Subcaption|#u");
fdui->check_subcaption = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 110, 240, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_LEFT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Title|#T");
fdui->input_subcaption = obj = fl_add_input(FL_NORMAL_INPUT, 110, 280, 350, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{ {
char const * const dummy = N_("Restore|#R"); char const * const dummy = N_("Restore|#R");
fdui->button_restore = obj = fl_add_button(FL_NORMAL_BUTTON, 20, 350, 100, 30, idex(_(dummy))); fdui->button_restore = obj = fl_add_button(FL_NORMAL_BUTTON, 135, 280, 75, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1); fl_set_button_shortcut(obj, scex(_(dummy)), 1);
} }
fl_set_object_gravity(obj, FL_SouthWest, FL_SouthWest); fl_set_object_gravity(obj, FL_SouthWest, FL_SouthWest);
fl_set_object_callback(obj, C_FormBaseRestoreCB, 0); fl_set_object_callback(obj, C_FormBaseRestoreCB, 0);
fdui->button_ok = obj = fl_add_button(FL_RETURN_BUTTON, 180, 350, 90, 30, _("Ok")); fdui->button_ok = obj = fl_add_button(FL_RETURN_BUTTON, 10, 280, 75, 30, _("Ok"));
fl_set_object_callback(obj, C_FormBaseOKCB, 0); fl_set_object_callback(obj, C_FormBaseOKCB, 0);
{
char const * const dummy = N_("Apply|#A");
fdui->button_apply = obj = fl_add_button(FL_NORMAL_BUTTON, 280, 350, 90, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_callback(obj, C_FormBaseApplyCB, 0);
{ {
char const * const dummy = N_("Cancel|^["); char const * const dummy = N_("Cancel|^[");
fdui->button_cancel = obj = fl_add_button(FL_NORMAL_BUTTON, 380, 350, 90, 30, idex(_(dummy))); fdui->button_cancel = obj = fl_add_button(FL_NORMAL_BUTTON, 260, 280, 75, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1); fl_set_button_shortcut(obj, scex(_(dummy)), 1);
} }
fl_set_object_callback(obj, C_FormBaseCancelCB, 0); fl_set_object_callback(obj, C_FormBaseCancelCB, 0);
@ -130,3 +57,309 @@ FD_form_graphics * FormGraphics::build_graphics()
} }
/*---------------------------------------*/ /*---------------------------------------*/
FD_form_file::~FD_form_file()
{
if ( form->visible ) fl_hide_form( form );
fl_free_form( form );
}
FD_form_file * FormGraphics::build_file()
{
FL_OBJECT *obj;
FD_form_file *fdui = new FD_form_file;
fdui->form = fl_bgn_form(FL_NO_BOX, 505, 235);
fdui->form->u_vdata = this;
obj = fl_add_box(FL_FLAT_BOX, 0, 0, 505, 235, "");
{
char const * const dummy = N_("File|#F");
fdui->input_filename = obj = fl_add_input(FL_NORMAL_INPUT, 85, 10, 270, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lstyle(obj, FL_BOLD_STYLE);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Browse...|#B");
fdui->button_browse = obj = fl_add_button(FL_NORMAL_BUTTON, 365, 10, 100, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 15, 50, 260, 115, _("Bounding Box"));
fl_set_object_lstyle(obj, FL_BOLD_STYLE);
{
char const * const dummy = N_("xLeftBottom|#x");
fdui->input_bbx0 = obj = fl_add_input(FL_NORMAL_INPUT, 25, 75, 50, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_TOP_LEFT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("yLeftBottom|#y");
fdui->input_bby0 = obj = fl_add_input(FL_NORMAL_INPUT, 160, 75, 50, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_TOP_LEFT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("xRightTop|#R");
fdui->input_bbx1 = obj = fl_add_input(FL_NORMAL_INPUT, 25, 125, 50, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_TOP);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("yRightTop|#T");
fdui->input_bby1 = obj = fl_add_input(FL_NORMAL_INPUT, 160, 125, 50, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_TOP_LEFT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("clip to bounding box|#c");
fdui->button_clip = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 290, 100, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_RIGHT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 15, 165, 465, 60, _("Subfigure"));
fl_set_object_lstyle(obj, FL_BOLD_STYLE);
{
char const * const dummy = N_("On/Off|#O");
fdui->check_subcaption = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 15, 180, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_RIGHT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Title|#T");
fdui->input_subcaption = obj = fl_add_input(FL_NORMAL_INPUT, 110, 185, 330, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_TOP);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 285, 50, 195, 115, _("Options"));
{
char const * const dummy = N_("draft mode|#D");
fdui->button_draft = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 290, 125, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_RIGHT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fdui->choice_bb_x0 = obj = fl_add_choice(FL_NORMAL_CHOICE, 80, 75, 50, 30, "");
fl_set_object_boxtype(obj, FL_FRAME_BOX);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fdui->choice_bb_y0 = obj = fl_add_choice(FL_NORMAL_CHOICE, 220, 75, 45, 30, "");
fl_set_object_boxtype(obj, FL_FRAME_BOX);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fdui->choice_bb_x1 = obj = fl_add_choice(FL_NORMAL_CHOICE, 80, 125, 50, 30, "");
fl_set_object_boxtype(obj, FL_FRAME_BOX);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fdui->choice_bb_y1 = obj = fl_add_choice(FL_NORMAL_CHOICE, 220, 125, 45, 30, "");
fl_set_object_boxtype(obj, FL_FRAME_BOX);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Get BB from file|#G");
fdui->button_getBB = obj = fl_add_button(FL_NORMAL_BUTTON, 295, 65, 170, 25, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fl_end_form();
fdui->form->fdui = fdui;
return fdui;
}
/*---------------------------------------*/
FD_form_size::~FD_form_size()
{
if ( form->visible ) fl_hide_form( form );
fl_free_form( form );
}
FD_form_size * FormGraphics::build_size()
{
FL_OBJECT *obj;
FD_form_size *fdui = new FD_form_size;
fdui->form = fl_bgn_form(FL_NO_BOX, 505, 235);
fdui->form->u_vdata = this;
obj = fl_add_box(FL_FLAT_BOX, 0, 0, 505, 235, "");
obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 15, 10, 225, 30, _("LaTeX"));
fl_set_object_lstyle(obj, FL_BOLD_STYLE);
{
char const * const dummy = N_("Width|#W");
fdui->input_width = obj = fl_add_input(FL_NORMAL_INPUT, 80, 80, 85, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fdui->choice_width_units = obj = fl_add_choice(FL_NORMAL_CHOICE, 170, 80, 60, 30, "");
fl_set_object_boxtype(obj, FL_FRAME_BOX);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Height|#H");
fdui->input_height = obj = fl_add_input(FL_NORMAL_INPUT, 80, 120, 85, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fdui->choice_height_units = obj = fl_add_choice(FL_NORMAL_CHOICE, 170, 120, 60, 30, "");
fl_set_object_boxtype(obj, FL_FRAME_BOX);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Scale|#S");
fdui->input_scale = obj = fl_add_input(FL_NORMAL_INPUT, 80, 185, 85, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
// xgettext:no-c-format
obj = fl_add_text(FL_NORMAL_TEXT, 170, 185, 25, 30, _("%"));
fl_set_object_lalign(obj, FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 255, 10, 230, 215, _("LyX Screen"));
fl_set_object_lstyle(obj, FL_BOLD_STYLE);
{
char const * const dummy = N_("Width|#w");
fdui->input_lyxwidth = obj = fl_add_input(FL_NORMAL_INPUT, 315, 145, 85, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fdui->choice_width_lyxwidth = obj = fl_add_choice(FL_NORMAL_CHOICE, 405, 145, 60, 30, "");
fl_set_object_boxtype(obj, FL_FRAME_BOX);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Height|#h");
fdui->input_lyxheight = obj = fl_add_input(FL_NORMAL_INPUT, 315, 185, 85, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fdui->choice_width_lyxheight = obj = fl_add_choice(FL_NORMAL_CHOICE, 405, 185, 60, 30, "");
fl_set_object_boxtype(obj, FL_FRAME_BOX);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
obj = fl_add_frame(FL_ENGRAVED_FRAME, 15, 40, 225, 120, "");
obj = fl_add_frame(FL_ENGRAVED_FRAME, 15, 160, 225, 65, "");
fdui->radio_display = fl_bgn_group();
{
char const * const dummy = N_("Don't display|#D");
fdui->radio_check_display = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 260, 20, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fl_set_button(obj, 1);
{
char const * const dummy = N_("in Grayscale|#G");
fdui->radio_display_gray = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 260, 75, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("in Color|#C");
fdui->radio_display_color = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 260, 105, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("in Monochrome|#M");
fdui->radio_display_mono = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 260, 45, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fl_end_group();
fdui->radio_size = fl_bgn_group();
{
char const * const dummy = N_("Default|#D");
fdui->button_default = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 15, 10, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_RIGHT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("On/Off|#O");
fdui->button_wh = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 15, 40, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_RIGHT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("On/Off|#n");
fdui->button_scale = obj = fl_add_checkbutton(FL_RADIO_BUTTON, 15, 155, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_RIGHT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fl_end_group();
{
char const * const dummy = N_("keep aspectratio|#k");
fdui->check_aspectratio = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 100, 40, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_RIGHT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fl_end_form();
fdui->form->fdui = fdui;
return fdui;
}
/*---------------------------------------*/
FD_form_special::~FD_form_special()
{
if ( form->visible ) fl_hide_form( form );
fl_free_form( form );
}
FD_form_special * FormGraphics::build_special()
{
FL_OBJECT *obj;
FD_form_special *fdui = new FD_form_special;
fdui->form = fl_bgn_form(FL_NO_BOX, 505, 235);
fdui->form->u_vdata = this;
obj = fl_add_box(FL_FLAT_BOX, 0, 0, 505, 235, "");
obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 15, 15, 255, 65, _("Rotation"));
fl_set_object_lstyle(obj, FL_BOLD_STYLE);
{
char const * const dummy = N_("Angle|#n");
fdui->input_rotate_angle = obj = fl_add_input(FL_INT_INPUT, 25, 40, 70, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_TOP_LEFT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
obj = fl_add_text(FL_NORMAL_TEXT, 100, 45, 45, 25, _("degrees"));
fl_set_object_lalign(obj, FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 275, 15, 205, 65, _("Special Options"));
fl_set_object_lstyle(obj, FL_BOLD_STYLE);
{
char const * const dummy = N_("Userdefined LaTeX-Options|#U");
fdui->input_special = obj = fl_add_input(FL_NORMAL_INPUT, 285, 42, 180, 27, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lalign(obj, FL_ALIGN_TOP_LEFT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Origin|#O");
fdui->choice_origin = obj = fl_add_choice(FL_NORMAL_CHOICE2, 150, 40, 115, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_boxtype(obj, FL_FRAME_BOX);
fl_set_object_lalign(obj, FL_ALIGN_TOP_LEFT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fl_end_form();
fdui->form->fdui = fdui;
return fdui;
}
/*---------------------------------------*/

View File

@ -8,30 +8,77 @@
extern "C" void C_FormBaseInputCB(FL_OBJECT *, long); extern "C" void C_FormBaseInputCB(FL_OBJECT *, long);
extern "C" void C_FormBaseRestoreCB(FL_OBJECT *, long); extern "C" void C_FormBaseRestoreCB(FL_OBJECT *, long);
extern "C" void C_FormBaseOKCB(FL_OBJECT *, long); extern "C" void C_FormBaseOKCB(FL_OBJECT *, long);
extern "C" void C_FormBaseApplyCB(FL_OBJECT *, long);
extern "C" void C_FormBaseCancelCB(FL_OBJECT *, long); extern "C" void C_FormBaseCancelCB(FL_OBJECT *, long);
extern "C" void C_FormBaseInputCB(FL_OBJECT *, long);
extern "C" void C_FormBaseInputCB(FL_OBJECT *, long);
extern "C" void C_FormBaseInputCB(FL_OBJECT *, long);
/**** Forms and Objects ****/ /**** Forms and Objects ****/
struct FD_form_graphics { struct FD_form_graphics {
~FD_form_graphics(); ~FD_form_graphics();
FL_FORM *form;
FL_OBJECT *tabFolder;
FL_OBJECT *button_help;
FL_OBJECT *button_restore;
FL_OBJECT *button_ok;
FL_OBJECT *button_cancel;
};
struct FD_form_file {
~FD_form_file();
FL_FORM *form; FL_FORM *form;
FL_OBJECT *input_filename; FL_OBJECT *input_filename;
FL_OBJECT *button_browse; FL_OBJECT *button_browse;
FL_OBJECT *input_bbx0;
FL_OBJECT *input_bby0;
FL_OBJECT *input_bbx1;
FL_OBJECT *input_bby1;
FL_OBJECT *button_clip;
FL_OBJECT *check_subcaption;
FL_OBJECT *input_subcaption;
FL_OBJECT *button_draft;
FL_OBJECT *choice_bb_x0;
FL_OBJECT *choice_bb_y0;
FL_OBJECT *choice_bb_x1;
FL_OBJECT *choice_bb_y1;
FL_OBJECT *button_getBB;
};
struct FD_form_size {
~FD_form_size();
FL_FORM *form;
FL_OBJECT *input_width; FL_OBJECT *input_width;
FL_OBJECT *choice_width_units; FL_OBJECT *choice_width_units;
FL_OBJECT *input_height; FL_OBJECT *input_height;
FL_OBJECT *choice_height_units; FL_OBJECT *choice_height_units;
FL_OBJECT *input_scale; FL_OBJECT *input_scale;
FL_OBJECT *input_lyxwidth;
FL_OBJECT *choice_width_lyxwidth;
FL_OBJECT *input_lyxheight;
FL_OBJECT *choice_width_lyxheight;
FL_OBJECT *radio_display;
FL_OBJECT *radio_check_display;
FL_OBJECT *radio_display_gray;
FL_OBJECT *radio_display_color;
FL_OBJECT *radio_display_mono;
FL_OBJECT *radio_size;
FL_OBJECT *button_default;
FL_OBJECT *button_wh;
FL_OBJECT *button_scale;
FL_OBJECT *check_aspectratio;
};
struct FD_form_special {
~FD_form_special();
FL_FORM *form;
FL_OBJECT *input_rotate_angle; FL_OBJECT *input_rotate_angle;
FL_OBJECT *check_display; FL_OBJECT *input_special;
FL_OBJECT *check_subcaption; FL_OBJECT *choice_origin;
FL_OBJECT *input_subcaption;
FL_OBJECT *button_restore;
FL_OBJECT *button_ok;
FL_OBJECT *button_apply;
FL_OBJECT *button_cancel;
}; };
#endif /* FD_form_graphics_h_ */ #endif /* FD_form_graphics_h_ */

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,12 @@
class LyXLength; class LyXLength;
// what we always need for lengths
string const choice_Length_All =
"cm|mm|in|%%|c%%|p%%|l%%|ex|em|pt|sp|bp|dd|pc|cc|mu";
string const choice_Length_WithUnit =
"cm|mm|in|ex|em|pt|sp|bp|dd|pc|cc|mu"; // all with a Unit
/// Extract shortcut from <ident>|<shortcut> string /// Extract shortcut from <ident>|<shortcut> string
char const * flyx_shortcut_extract(char const * sc); char const * flyx_shortcut_extract(char const * sc);
/// Shortcut for flyx_shortcut_extract /// Shortcut for flyx_shortcut_extract

View File

@ -1,3 +1,7 @@
2002-01-27 Herbert Voss <voss@lyx.org>
* GraphicsCacheItem.h: added Converting to the ImageStatus enum.
2002-01-17 John Levon <moz@compsoc.man.ac.uk> 2002-01-17 John Levon <moz@compsoc.man.ac.uk>
* ImageLoaderXPM.C: don't set XpmColorKey flag if we don't use it * ImageLoaderXPM.C: don't set XpmColorKey flag if we don't use it

View File

@ -41,6 +41,8 @@ public:
/// ///
Loading = 1, Loading = 1,
/// ///
Converting,
///
ErrorConverting, ErrorConverting,
/// ///
ErrorReading, ErrorReading,

View File

@ -1,3 +1,13 @@
2002-01-27 Herbert Voss <voss@lyx.org>
* insetgraphic.[Ch]: mostly newritten to support graphicx with
all options and to be sure that the old figinsets are correct
converted.
* insetgraphicParams.[Ch]: a lot of chamges to have a clean data-
structure and to support all lengths as LyXLength. The Parameter
structure changed again, but reading of "old" 1.2 graphic insets
is no problem.
2002-01-20 Dekel Tsur <dekelts@tau.ac.il> 2002-01-20 Dekel Tsur <dekelts@tau.ac.il>
* insetert.h (forceDefaultParagraphs): Added * insetert.h (forceDefaultParagraphs): Added

View File

@ -3,22 +3,12 @@
* *
* LyX, The Document Processor * LyX, The Document Processor
* *
* Copyright 1995-2001 the LyX Team. * Copyright 1995-2002 the LyX Team.
* *
* This file Copyright 2000 Baruch Even. * \author Baruch Even
* \author Herbert Voss <voss@lyx.org>
* ====================================================== */ * ====================================================== */
/*
Major tasks:
* Switch to convert the images in the background, this requires work on
the converter, the systemcontroller and the graphics cache.
Minor tasks:
* Pop up a dialog if the widget version is higher than what we accept.
* Provide sed/awk/C code to downgrade from InsetGraphics to FigInset(?)
*/
/* /*
Known BUGS: Known BUGS:
@ -47,10 +37,6 @@ Known BUGS:
its original size and color, resizing is done in the final output, its original size and color, resizing is done in the final output,
but not in the LyX window. 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 * 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. suffixes so we need to read the file and detect if it's EPS or not.
[Implemented, need testing] [Implemented, need testing]
@ -62,13 +48,6 @@ TODO Before initial production release:
And act upon them. Make sure not to remove InsetFig code for the And act upon them. Make sure not to remove InsetFig code for the
1.2.0 release, only afterwards, after deployment shows InsetGraphics 1.2.0 release, only afterwards, after deployment shows InsetGraphics
to be ok. to be ok.
TODO Extended features:
* Advanced Latex tab folder.
* Add support for more features so that it will be better than insetfig.
* Keep aspect ratio radio button
* Support for complete control over the latex parameters for TeXperts
* What advanced features the users want to do? * What advanced features the users want to do?
Implement them in a non latex dependent way, but a logical way. Implement them in a non latex dependent way, but a logical way.
LyX should translate it to latex or any other fitting format. LyX should translate it to latex or any other fitting format.
@ -83,43 +62,16 @@ TODO Extended features:
* Add support for the 'picinpar' package. * Add support for the 'picinpar' package.
* Improve support for 'subfigure' - Allow to set the various options * Improve support for 'subfigure' - Allow to set the various options
that are possible. that are possible.
* Add resizing by percentage of image size (50%, 150%) -
usefull for two images of different size to be resized where
they both should have the same scale compared to each other.
*/ */
/* NOTES: /* NOTES:
*
* Intentions:
* This is currently a moving target, I'm trying stuff and learning what
* is needed and how to accomplish it, since there is no predefined goal or
* way to go I invent it as I go.
*
* My current intention is for seperation from LaTeX, the basic needs are
* resizing and rotating, displaying on screen in various depths and printing
* conversion of depths (independent of the display depth). For this I'll
* provide a simple interface.
*
* The medium level includes clipping of the image, but in a limited way.
*
* For the LaTeX gurus I'll provide a complete control over the output, but
* this is latex dependent and guru dependent so I'd rather avoid doing this
* for the normal user. This stuff includes clipping, special image size
* specifications (\textwidth\minus 2in) which I see no way to generalize
* to non-latex specific way.
*
* Used packages:
* 'graphicx' for the graphics inclusion.
* 'subfigure' for the subfigures.
*
* Fileformat: * Fileformat:
*
* Current version is 1 (inset file format version), when changing it * Current version is 1 (inset file format version), when changing it
* it should be changed in the Write() function when writing in one place * it should be changed in the Write() function when writing in one place
* and when reading one should change the version check and the error message. * and when reading one should change the version check and the error message.
*
* The filename is kept in the lyx file in a relative way, so as to allow * The filename is kept in the lyx file in a relative way, so as to allow
* moving the document file and its images with no problem. * moving the document file and its images with no problem.
*
* *
* Conversions: * Conversions:
* Postscript output means EPS figures. * Postscript output means EPS figures.
@ -155,6 +107,7 @@ TODO Extended features:
#include "lyx_gui_misc.h" #include "lyx_gui_misc.h"
#include "support/FileInfo.h" #include "support/FileInfo.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "frontends/controllers/helper_funcs.h"
#include "support/lyxlib.h" #include "support/lyxlib.h"
#include "lyxtext.h" #include "lyxtext.h"
#include "lyxrc.h" #include "lyxrc.h"
@ -171,6 +124,9 @@ using std::ifstream;
using std::ostream; using std::ostream;
using std::endl; using std::endl;
///////////////////////////////////////////////////////////////////////////
int VersionNumber = 1;
///////////////////////////////////////////////////////////////////////////
// This function is a utility function // This function is a utility function
// ... that should be with ChangeExtension ... // ... that should be with ChangeExtension ...
@ -209,31 +165,28 @@ string const
InsetGraphics::statusMessage() const InsetGraphics::statusMessage() const
{ {
string msg; string msg;
if (cacheHandle.get()) { if (cacheHandle.get()) {
switch (cacheHandle->getImageStatus()) { switch (cacheHandle->getImageStatus()) {
case GraphicsCacheItem::UnknownError: case GraphicsCacheItem::UnknownError:
msg = _("Unknown Error"); msg = _("Unknown Error");
break; break;
case GraphicsCacheItem::Loading: case GraphicsCacheItem::Loading:
msg = _("Loading..."); msg = _("Loading...");
break; break;
case GraphicsCacheItem::ErrorReading: case GraphicsCacheItem::ErrorReading:
msg = _("Error reading"); msg = _("Error reading");
break; break;
case GraphicsCacheItem::Converting:
msg = _("Converting Image");
break;
case GraphicsCacheItem::ErrorConverting: case GraphicsCacheItem::ErrorConverting:
msg = _("Error converting"); msg = _("Error converting");
break; break;
case GraphicsCacheItem::Loaded: case GraphicsCacheItem::Loaded:
// No message to write. // No message to write.
break; break;
} }
} }
return msg; return msg;
} }
@ -369,8 +322,7 @@ Inset::EDITABLE InsetGraphics::editable() const
void InsetGraphics::write(Buffer const * buf, ostream & os) const void InsetGraphics::write(Buffer const * buf, ostream & os) const
{ {
os << "Graphics FormatVersion 1\n"; os << "Graphics FormatVersion " << VersionNumber << '\n';
params.Write(buf, os); params.Write(buf, os);
} }
@ -407,7 +359,7 @@ void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex)
} else if (token == "FormatVersion") { } else if (token == "FormatVersion") {
lex.next(); lex.next();
int version = lex.getInteger(); int version = lex.getInteger();
if (version > 1) if (version > VersionNumber)
lyxerr lyxerr
<< "This document was created with a newer Graphics widget" << "This document was created with a newer Graphics widget"
", You should use a newer version of LyX to read this" ", You should use a newer version of LyX to read this"
@ -426,6 +378,8 @@ void InsetGraphics::readInsetGraphics(Buffer const * buf, LyXLex & lex)
void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex) void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex)
{ {
std::vector<string> const oldUnits =
getVectorFromString("pt,cm,in,p%,c%");
bool finished = false; bool finished = false;
while (lex.isOK() && !finished) { while (lex.isOK() && !finished) {
@ -450,6 +404,7 @@ void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex)
} else if (token == "subcaption") { } else if (token == "subcaption") {
if (lex.eatLine()) if (lex.eatLine())
params.subcaptionText = lex.getString(); params.subcaptionText = lex.getString();
params.subcaption = true;
} else if (token == "label") { } else if (token == "label") {
if (lex.next()); if (lex.next());
// kept for backwards compability. Delete in 0.13.x // kept for backwards compability. Delete in 0.13.x
@ -457,14 +412,10 @@ void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex)
if (lex.next()) if (lex.next())
params.rotateAngle = lex.getFloat(); params.rotateAngle = lex.getFloat();
} else if (token == "size") { } else if (token == "size") {
// Size of image on screen is ignored in InsetGraphics, just eat if (lex.next())
// the input. params.lyxwidth = LyXLength(lex.getString()+"pt");
if (lex.next()) { if (lex.next())
lex.getInteger(); params.lyxheight = LyXLength(lex.getString()+"pt");
}
if (lex.next()) {
lex.getInteger();
}
} else if (token == "flags") { } else if (token == "flags") {
InsetGraphicsParams::DisplayType tmp = InsetGraphicsParams::COLOR; InsetGraphicsParams::DisplayType tmp = InsetGraphicsParams::COLOR;
if (lex.next()) if (lex.next())
@ -476,78 +427,73 @@ void InsetGraphics::readFigInset(Buffer const * buf, LyXLex & lex)
} else if (token == "subfigure") { } else if (token == "subfigure") {
params.subcaption = true; params.subcaption = true;
} else if (token == "width") { } else if (token == "width") {
if (lex.next()) {
int i = lex.getInteger();
if (lex.next()) { if (lex.next()) {
params.widthResize = static_cast<InsetGraphicsParams::Resize>(lex.getInteger()); if (i == 5) {
} params.scale = lex.getInteger();
if (lex.next()) { params.size_type = InsetGraphicsParams::SCALE;
params.widthSize = lex.getFloat(); } else {
params.width = LyXLength(lex.getString()+oldUnits[i]);
params.size_type = InsetGraphicsParams::WH;
}
} }
}
} else if (token == "height") { } else if (token == "height") {
if (lex.next()) {
int i = lex.getInteger();
if (lex.next()) { if (lex.next()) {
params.heightResize = static_cast<InsetGraphicsParams::Resize>(lex.getInteger()); params.height = LyXLength(lex.getString()+oldUnits[i]);
} params.size_type = InsetGraphicsParams::WH;
if (lex.next()) {
params.heightSize = lex.getFloat();
} }
}
} }
} }
} }
string const InsetGraphics::createLatexOptions() const
namespace {
void formatResize(ostream & os, string const & key,
InsetGraphicsParams::Resize resizeType, double size)
{
switch (resizeType) {
case InsetGraphicsParams::DEFAULT_SIZE:
break;
case InsetGraphicsParams::CM:
os << key << '=' << size << "cm,";
break;
case InsetGraphicsParams::INCH:
os << key << '=' << size << "in,";
break;
case InsetGraphicsParams::PERCENT_PAGE:
os << key << '=' << size / 100 << "\\text" << key << ',';
break;
case InsetGraphicsParams::PERCENT_COLUMN:
os << key << '=' << size / 100 << "\\column" << key << ',';
break;
case InsetGraphicsParams::SCALE:
os << "scale" << '=' << size/100 << ',';
}
}
} // namespace anon
string const
InsetGraphics::createLatexOptions() const
{ {
// Calculate the options part of the command, we must do it to a string // Calculate the options part of the command, we must do it to a string
// stream since we might have a trailing comma that we would like to remove // stream since we might have a trailing comma that we would like to remove
// before writing it to the output stream. // before writing it to the output stream.
ostringstream options; ostringstream options;
if (!params.bb.empty())
formatResize(options, "width", params.widthResize, params.widthSize); options << "bb=" << strip(params.bb) << ',';
formatResize(options, "height", params.heightResize, params.heightSize); if (params.draft)
options << "%\n draft,";
if (params.clip)
options << "%\n clip,";
if (params.size_type == InsetGraphicsParams::WH) {
if (!params.width.zero())
options << "%\n width=" << params.width.asLatexString() << ',';
if (!params.height.zero())
options << "%\n height=" << params.height.asLatexString() << ',';
} else if (params.size_type == InsetGraphicsParams::SCALE) {
if (params.scale > 0)
options << "%\n scale=" << double(params.scale)/100.0 << ',';
}
if (params.keepAspectRatio)
options << "%\n keepaspectratio,";
// Make sure it's not very close to zero, a float can be effectively // Make sure it's not very close to zero, a float can be effectively
// zero but not exactly zero. // zero but not exactly zero.
if (!lyx::float_equal(params.rotateAngle, 0, 0.001)) { if (!lyx::float_equal(params.rotateAngle, 0, 0.001)) {
options << "angle=" options << "%\n angle=" << params.rotateAngle << ',';
<< params.rotateAngle << ','; if (!params.rotateOrigin.empty()) {
options << "%\n origin=";
options << params.rotateOrigin[0];
if (contains(params.rotateOrigin,"Top"))
options << 't';
else if (contains(params.rotateOrigin,"Bottom"))
options << 'b';
else if (contains(params.rotateOrigin,"Baseline"))
options << 'B';
options << ',';
}
} }
if (!params.special.empty())
options << params.special << ',';
string opts = options.str().c_str(); string opts = options.str().c_str();
opts = strip(opts, ','); opts = strip(opts, ',');
return opts; return opts;
} }
@ -612,8 +558,7 @@ string decideOutputImageFormat(string const & suffix, enum FileType type)
{ {
// lyxrc.pdf_mode means: // lyxrc.pdf_mode means:
// Are we creating a PDF or a PS file? // Are we creating a PDF or a PS file?
// (Should actually mean, are we using latex or pdflatex). // (Should actually mean, are we using latex or pdflatex).
if (lyxrc.pdf_mode) { if (lyxrc.pdf_mode) {
if (type == EPS || type == EPS || type == PDF) if (type == EPS || type == EPS || type == PDF)
return "pdf"; return "pdf";
@ -635,15 +580,12 @@ string decideOutputImageFormat(string const & suffix, enum FileType type)
} // Anon. namespace } // Anon. namespace
string const string const InsetGraphics::prepareFile(Buffer const *buf) const
InsetGraphics::prepareFile(Buffer const *buf) const
{ {
// do_convert = Do we need to convert the file? // do_convert = Do we need to convert the file?
// nice = Do we create a nice version? // nice = Do we create a nice version?
// This is used when exporting the latex file only. // This is used when exporting the latex file only.
// //
//
// if (!do_convert) // if (!do_convert)
// return original filename // return original filename
// //
@ -680,9 +622,7 @@ InsetGraphics::prepareFile(Buffer const *buf) const
string const relname = MakeRelPath(params.filename, path); string const relname = MakeRelPath(params.filename, path);
outfile = RemoveExtension(relname); outfile = RemoveExtension(relname);
} }
converters.convert(buf, params.filename, outfile, extension, image_target); converters.convert(buf, params.filename, outfile, extension, image_target);
return outfile; return outfile;
} }
@ -690,58 +630,36 @@ InsetGraphics::prepareFile(Buffer const *buf) const
int InsetGraphics::latex(Buffer const *buf, ostream & os, int InsetGraphics::latex(Buffer const *buf, ostream & os,
bool /*fragile*/, bool/*fs*/) const bool /*fragile*/, bool/*fs*/) const
{ {
// MISSING: We have to decide how to do the order of the options
// that is dependent of order, like width, height, angle. Should
// we rotate before scale? Should we let the user decide?
// bool rot_before_scale; ?
// (BE) As a first step we should do a scale before rotate since this is
// more like the natural thought of how to do it.
// (BE) I believe that a priority list presented to the user with
// a default order would be the best, though it would be better to
// hide such a thing in an "Advanced options" dialog.
// (BE) This should go an advanced LaTeX options dialog.
// If there is no file specified, just output a message about it in // If there is no file specified, just output a message about it in
// the latex output. // the latex output.
if (params.filename.empty()) { if (params.filename.empty()) {
os << "\\fbox{\\rule[-0.5in]{0pt}{1in}" os << "\\fbox{\\rule[-0.5in]{0pt}{1in}"
<< _("empty figure path") << _("empty figure path") << "}\n";
<< "}\n";
return 1; // One end of line marker added to the stream. return 1; // One end of line marker added to the stream.
} }
// Keep count of newlines that we issued. // Keep count of newlines that we issued.
int newlines = 0; int newlines = 0;
// This variables collect all the latex code that should be before and // This variables collect all the latex code that should be before and
// after the actual includegraphics command. // after the actual includegraphics command.
string before; string before;
string after; string after;
// Do we want subcaptions? // Do we want subcaptions?
if (params.subcaption) { if (params.subcaption) {
before += "\\subfigure[" + params.subcaptionText + "]{"; before += "\\subfigure[" + params.subcaptionText + "]{";
after = '}' + after; after = '}' + after;
} }
// We never use the starred form, we use the "clip" option instead. // We never use the starred form, we use the "clip" option instead.
os << before << "\\includegraphics"; os << before << "\\includegraphics";
// Write the options if there are any. // Write the options if there are any.
string const opts = createLatexOptions(); string const opts = createLatexOptions();
if (!opts.empty()) { if (!opts.empty()) {
os << '[' << opts << ']'; os << "[%\n " << opts << ']';
} }
// Make the filename relative to the lyx file // Make the filename relative to the lyx file
// and remove the extension so the LaTeX will use whatever is // and remove the extension so the LaTeX will use whatever is
// appropriate (when there are several versions in different formats) // appropriate (when there are several versions in different formats)
string const filename = prepareFile(buf); string const filename = prepareFile(buf);
os << '{' << filename << '}' << after; os << '{' << filename << '}' << after;
// Return how many newlines we issued. // Return how many newlines we issued.
return newlines; return newlines;
} }
@ -849,3 +767,4 @@ Inset * InsetGraphics::clone(Buffer const &, bool same_id) const
{ {
return new InsetGraphics(*this, same_id); return new InsetGraphics(*this, same_id);
} }

View File

@ -7,6 +7,8 @@
* Copyright 1995 Matthias Ettrich * Copyright 1995 Matthias Ettrich
* Copyright 1995-2001 the LyX Team. * Copyright 1995-2001 the LyX Team.
* *
* \author Baruch Even
* \author Herbert Voss <voss@lyx.org>
* ====================================================== */ * ====================================================== */
#ifndef INSET_GRAPHICS_H #ifndef INSET_GRAPHICS_H

View File

@ -5,7 +5,9 @@
* Copyright 1995 Matthias Ettrich. * Copyright 1995 Matthias Ettrich.
* Copyright 1995-2001 The LyX Team. * Copyright 1995-2001 The LyX Team.
* *
* This file Copyright 2000 Baruch Even * \author Baruch Even
* \author Herbert Voss <voss@lyx.org>
*
* ================================================= */ * ================================================= */
#include <config.h> #include <config.h>
@ -29,63 +31,46 @@ namespace {
/// translations. /// translations.
bool translatorsSet = false; bool translatorsSet = false;
/// This is the translator between the Resize enum and corresponding lyx
/// file strings.
Translator< InsetGraphicsParams::Resize, string >
resizeTranslator(InsetGraphicsParams::DEFAULT_SIZE, "default");
/// This is the translator between the Origin enum and corresponding lyx
/// file strings.
Translator< InsetGraphicsParams::Origin, string >
originTranslator(InsetGraphicsParams::DEFAULT, "default");
/// This is the translator between the Display enum and corresponding lyx /// This is the translator between the Display enum and corresponding lyx
/// file strings. /// file strings.
Translator< InsetGraphicsParams::DisplayType, string > Translator< InsetGraphicsParams::DisplayType, string >
displayTranslator(InsetGraphicsParams::MONOCHROME, "monochrome"); displayTranslator(InsetGraphicsParams::MONOCHROME, "monochrome");
// this is only compatibility stuff for the first 1.2 version
// it is obselete until 1.3
LyXLength convertResizeValue(string const token, LyXLex & lex) {
lex.next();
string value = lex.getString(); // "width" or "height"
lex.next(); // anyway not interesting
value = lex.getString();
if (token == "default")
return (LyXLength(value+"pt"));
else if (token == "cm")
return (LyXLength(value+"cm"));
else if (token == "inch")
return (LyXLength(value+"in"));
else if (token == "percentOfColumn")
return (LyXLength(value+"c%"));
else if (token == "percentOfPage")
return (LyXLength(value+"p%"));
else return LyXLength("0pt"); // nothing with figinset
}
} // namespace anon } // namespace anon
InsetGraphicsParams::InsetGraphicsParams() InsetGraphicsParams::InsetGraphicsParams()
{ {
init(); init();
// Set translators // Set translators
if (! translatorsSet) { if (! translatorsSet) {
translatorsSet = true; translatorsSet = true;
// Fill the resize translator
resizeTranslator.addPair(DEFAULT_SIZE, "default");
resizeTranslator.addPair(CM, "cm");
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");
originTranslator.addPair(LEFTTOP, "leftTop");
originTranslator.addPair(LEFTCENTER, "leftCenter");
originTranslator.addPair(LEFTBASELINE, "leftBaseLine");
originTranslator.addPair(LEFTBOTTOM, "leftBottom");
originTranslator.addPair(CENTERTOP, "centerTop");
originTranslator.addPair(CENTER, "center");
originTranslator.addPair(CENTERBASELINE, "centerBaseLine");
originTranslator.addPair(CENTERBOTTOM, "centerBottom");
originTranslator.addPair(RIGHTTOP, "rightTop");
originTranslator.addPair(RIGHTCENTER, "rightCenter");
originTranslator.addPair(RIGHTBASELINE, "rightBaseLine");
originTranslator.addPair(RIGHTBOTTOM, "rightBottom");
originTranslator.addPair(REFERENCE_POINT, "referencePoint");
// Fill the display translator // Fill the display translator
displayTranslator.addPair(MONOCHROME, "monochrome"); displayTranslator.addPair(MONOCHROME, "monochrome");
displayTranslator.addPair(GRAYSCALE, "grayscale"); displayTranslator.addPair(GRAYSCALE, "grayscale");
displayTranslator.addPair(COLOR, "color"); displayTranslator.addPair(COLOR, "color");
displayTranslator.addPair(NONE, "none"); displayTranslator.addPair(NONE, "none");
} }
} }
@ -103,7 +88,6 @@ InsetGraphicsParams::operator=(InsetGraphicsParams const & params)
// Are we assigning the object into itself? // Are we assigning the object into itself?
if (this == &params) if (this == &params)
return * this; return * this;
copy(params); copy(params);
return *this; return *this;
} }
@ -111,15 +95,21 @@ InsetGraphicsParams::operator=(InsetGraphicsParams const & params)
void InsetGraphicsParams::init() void InsetGraphicsParams::init()
{ {
subcaptionText = filename = string(); subcaptionText = filename = string();
display = MONOCHROME; bb = string(); // bounding box
subcaption = false; draft = false; // draft mode
keepAspectRatio = true; clip = false; // clip image
widthResize = DEFAULT_SIZE; display = MONOCHROME; // LyX-View
widthSize = 0.0; subcaption = false; // subfigure
heightResize = DEFAULT_SIZE; width = LyXLength(); // set to 0pt
heightSize = 0.0; height = LyXLength();
rotateOrigin = DEFAULT; lyxwidth = LyXLength(); // for the view in lyx
rotateAngle = 0.0; lyxheight = LyXLength();
scale = 0;
size_type = DEFAULT_SIZE;
keepAspectRatio = false;
rotateOrigin = string(); //
rotateAngle = 0.0; // in degrees
special = string(); // userdefined stuff
testInvariant(); testInvariant();
} }
@ -127,16 +117,22 @@ void InsetGraphicsParams::init()
void InsetGraphicsParams::copy(InsetGraphicsParams const & igp) void InsetGraphicsParams::copy(InsetGraphicsParams const & igp)
{ {
filename = igp.filename; filename = igp.filename;
bb = igp.bb;
draft = igp.draft;
clip = igp.clip;
display = igp.display; display = igp.display;
subcaption = igp.subcaption; subcaption = igp.subcaption;
subcaptionText = igp.subcaptionText; subcaptionText = igp.subcaptionText;
keepAspectRatio = igp.keepAspectRatio; keepAspectRatio = igp.keepAspectRatio;
widthResize = igp.widthResize; width = igp.width;
widthSize = igp.widthSize; height = igp.height;
heightResize = igp.heightResize; scale = igp.scale;
heightSize = igp.heightSize; size_type = igp.size_type;
lyxwidth = igp.lyxwidth;
lyxheight = igp.lyxheight;
rotateOrigin = igp.rotateOrigin; rotateOrigin = igp.rotateOrigin;
rotateAngle = igp.rotateAngle; rotateAngle = igp.rotateAngle;
special = igp.special;
testInvariant(); testInvariant();
} }
@ -145,32 +141,11 @@ void InsetGraphicsParams::testInvariant() const
{ {
// Filename might be empty (when the dialog is first created). // Filename might be empty (when the dialog is first created).
// Assert(!filename.empty()); // Assert(!filename.empty());
lyx::Assert(display == COLOR || lyx::Assert(display == COLOR ||
display == MONOCHROME || display == MONOCHROME ||
display == GRAYSCALE || display == GRAYSCALE ||
display == NONE display == NONE
); );
lyx::Assert(widthResize == DEFAULT_SIZE ||
widthResize == CM ||
widthResize == INCH ||
widthResize == PERCENT_PAGE ||
widthResize == PERCENT_COLUMN ||
widthResize == SCALE
);
lyx::Assert(heightResize == DEFAULT_SIZE ||
heightResize == CM ||
heightResize == INCH ||
heightResize == PERCENT_PAGE ||
heightResize == SCALE
);
// 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 // Angle is in degrees and ranges -360 < angle < 360
// The reason for this is that in latex there is a meaning for the // The reason for this is that in latex there is a meaning for the
// different angles and they are not necessarliy interchangeable, // different angles and they are not necessarliy interchangeable,
@ -184,16 +159,22 @@ bool operator==(InsetGraphicsParams const & left,
InsetGraphicsParams const & right) InsetGraphicsParams const & right)
{ {
if (left.filename == right.filename && if (left.filename == right.filename &&
left.bb == right.bb &&
left.draft == right.draft &&
left.clip == right.clip &&
left.display == right.display && left.display == right.display &&
left.subcaption == right.subcaption && left.subcaption == right.subcaption &&
left.subcaptionText == right.subcaptionText && left.subcaptionText == right.subcaptionText &&
left.keepAspectRatio == right.keepAspectRatio && left.keepAspectRatio == right.keepAspectRatio &&
left.widthResize == right.widthResize && left.width == right.width &&
left.widthSize == right.widthSize && left.height == right.height &&
left.heightResize == right.heightResize && left.scale == right.scale &&
left.heightSize == right.heightSize && left.size_type == right.size_type &&
left.lyxwidth == right.lyxwidth &&
left.lyxheight == right.lyxheight &&
left.rotateOrigin == right.rotateOrigin && left.rotateOrigin == right.rotateOrigin &&
lyx::float_equal(left.rotateAngle, right.rotateAngle, 0.001) lyx::float_equal(left.rotateAngle, right.rotateAngle, 0.001 &&
left.special == right.special)
) )
return true; return true;
@ -207,96 +188,75 @@ bool operator!=(InsetGraphicsParams const & left,
} }
namespace {
void writeResize(ostream & os, string const & key,
InsetGraphicsParams::Resize resize, double size)
{
os << ' ' << key << "Resize ";
os << resizeTranslator.find(resize);
os << ' ' << key << ' ' << size << '\n';
}
void writeOrigin(ostream & os,
InsetGraphicsParams::Origin origin)
{
os << " rotateOrigin " << originTranslator.find(origin);
os << '\n';
}
} // namespace anon
void InsetGraphicsParams::Write(Buffer const * buf, ostream & os) const void InsetGraphicsParams::Write(Buffer const * buf, ostream & os) const
{ {
// If there is no filename, write nothing for it. // If there is no filename, write nothing for it.
if (! filename.empty()) { if (! filename.empty()) {
os << "filename " os << "\tfilename "
<< MakeRelPath(filename, buf->filePath()) << MakeRelPath(filename, buf->filePath())
<< '\n'; << '\n';
} }
if (!bb.empty()) // bounding box
os << "\tBoundingBox " << bb << '\n';
if (clip) // clip image
os << "\tclip\n";
if (draft) // draft mode
os << "\tdraft\n";
// Save the display type // Save the display type
os << " display " << displayTranslator.find(display) << '\n'; os << "\tdisplay " << displayTranslator.find(display) << '\n';
// Save the subcaption status // Save the subcaption status
if (subcaption) if (subcaption)
os << " subcaption"; os << "\tsubcaption\n";
if (!subcaptionText.empty())
if (! subcaptionText.empty()) os << "\tsubcaptionText \"" << subcaptionText << '\"' << '\n';
os << " subcaptionText \"" << subcaptionText << '\"' << '\n'; // we always need the size type
// 0: no special
writeResize(os, "width", widthResize, widthSize); // 1: width/height combination
writeResize(os, "height", heightResize, heightSize); // 2: scale
os << "\tsize_type " << size_type << '\n';
writeOrigin(os, rotateOrigin); if (!width.zero())
if (!lyx::float_equal(rotateAngle, 0.0, 0.001)) { os << "\twidth " << width.asString() << '\n';
os << " rotateAngle " << rotateAngle << '\n'; if (!height.zero())
} os << "\theight " << height.asString() << '\n';
if (scale != 0)
os << "\tscale " << scale << '\n';
if (keepAspectRatio)
os << "\tkeepAspectRatio\n";
if (!lyx::float_equal(rotateAngle, 0.0, 0.001))
os << "\trotateAngle " << rotateAngle << '\n';
if (!rotateOrigin.empty())
os << "\trotateOrigin " << rotateOrigin << '\n';
if (!special.empty())
os << "\tspecial " << special << '\n';
if (!lyxwidth.zero()) // the lyx-viewsize
os << "\tlyxwidth " << lyxwidth.asString() << '\n';
if (!lyxheight.zero())
os << "\tlyxheight " << lyxheight.asString();
} }
namespace {
void readResize(InsetGraphicsParams * igp, bool height,
string const & token)
{
InsetGraphicsParams::Resize resize = InsetGraphicsParams::DEFAULT_SIZE;
resize = resizeTranslator.find(token);
if (height)
igp->heightResize = resize;
else
igp->widthResize = resize;
}
void readOrigin(InsetGraphicsParams * igp, string const & token)
{
// TODO: complete this function.
igp->rotateOrigin = originTranslator.find(token);
}
} // namespace anon
bool InsetGraphicsParams::Read(Buffer const * buf, LyXLex & lex, bool InsetGraphicsParams::Read(Buffer const * buf, LyXLex & lex,
string const& token) string const& token)
{ {
if (token == "filename") { if (token == "filename") {
lex.next(); lex.next();
filename = lex.getString(); filename = lex.getString();
if (!filename.empty()) { if (!filename.empty()) {
// Make the filename with absolute directory. // Make the filename with absolute directory.
filename = MakeAbsPath(filename, buf->filePath()); filename = MakeAbsPath(filename, buf->filePath());
} }
} else if (token == "BoundingBox") {
for (int i=0; i<4 ;i++) {
lex.next();
bb += (lex.getString()+" ");
}
} else if (token == "clip") {
clip = true;
} else if (token == "draft") {
draft = true;
} else if (token == "display") { } else if (token == "display") {
lex.next(); lex.next();
string const type = lex.getString(); string const type = lex.getString();
display = displayTranslator.find(type); display = displayTranslator.find(type);
} else if (token == "subcaption") { } else if (token == "subcaption") {
subcaption = true; subcaption = true;
@ -304,33 +264,55 @@ bool InsetGraphicsParams::Read(Buffer const * buf, LyXLex & lex,
lex.next(); lex.next();
subcaptionText = lex.getString(); subcaptionText = lex.getString();
} else if (token == "widthResize") { } else if (token == "widthResize") {
if (lex.next()) {
string const token = lex.getString();
if (token == "scale") {
lex.next();
scale = lex.getInteger();
size_type = SCALE;
}
else {
width = convertResizeValue(token, lex);
size_type = WH;
}
}
} else if (token == "size_type") {
lex.next(); lex.next();
string const token = lex.getString(); switch (lex.getInteger()) {
case 0 : size_type = DEFAULT_SIZE;
readResize(this, false, token); break;
case 1 : size_type = WH;
break;
case 2 : size_type = SCALE;
}
} else if (token == "width") { } else if (token == "width") {
lex.next(); lex.next();
widthSize = lex.getFloat(); width = LyXLength(lex.getString());
size_type = WH;
} else if (token == "heightResize") { } else if (token == "heightResize") {
lex.next(); if (lex.next())
string const token = lex.getString(); height = convertResizeValue(lex.getString(), lex);
readResize(this, true, token);
} else if (token == "height") { } else if (token == "height") {
lex.next(); lex.next();
heightSize = lex.getFloat(); height = LyXLength(lex.getString());
} else if (token == "rotateOrigin") { size_type = WH;
lex.next(); } else if (token == "keepAspectRatio") {
string const token = lex.getString(); keepAspectRatio = true;
readOrigin(this, token);
} else if (token == "rotateAngle") { } else if (token == "rotateAngle") {
lex.next(); lex.next();
rotateAngle = lex.getFloat(); rotateAngle = lex.getFloat();
} else if (token == "rotateOrigin") {
lex.next();
rotateOrigin=lex.getString();
} else if (token == "lyxwidth") {
lex.next();
lyxwidth = LyXLength(lex.getString());
} else if (token == "lyxheight") {
lex.next();
lyxheight = LyXLength(lex.getString());
} else { } else {
// If it's none of the above, its not ours. // If it's none of the above, its not ours.
return false; return false;
} }
return true; return true;
} }

View File

@ -4,9 +4,10 @@
* *
* LyX, The Document Processor * LyX, The Document Processor
* Copyright 1995 Matthias Ettrich. * Copyright 1995 Matthias Ettrich.
* Copyright 1995-2001 The LyX Team. * Copyright 1995-2002 The LyX Team.
* *
* This file Copyright 2000 Baruch Even * \author Baruch Even
* \author Herbert Voss <voss@lyx.org>
* ================================================= */ * ================================================= */
#ifndef INSETGRAPHICSPARAMS_H #ifndef INSETGRAPHICSPARAMS_H
@ -26,74 +27,50 @@ using std::ostream;
/// This struct holds all the parameters needed by insetGraphics. /// This struct holds all the parameters needed by insetGraphics.
struct InsetGraphicsParams struct InsetGraphicsParams
{ {
/// Image filename.
string filename;
/// How do we display the image? /// How do we display the image?
enum DisplayType { enum DisplayType {
/// In full color range (if it's not in color we show it as it is) COLOR, // full color range
COLOR, GRAYSCALE, // 256 shades of gray
/// In Grayscale (256 shades of gray). MONOCHROME, // In black and white.
GRAYSCALE, NONE // only keep a frame in place.
/// In black and white.
MONOCHROME,
/// Don't display it on screen, only keep a frame in place.
NONE
}; };
enum sizeType {
/// How to display the image DEFAULT_SIZE, // like none
DisplayType display; WH, // width/height values
SCALE // percentage value
};
/// Image filename.
string filename;
/// Do we have a subcaption? /// Do we have a subcaption?
bool subcaption; bool subcaption;
/// The text of the subcaption. /// The text of the subcaption.
string subcaptionText; string subcaptionText;
/// The bounding box with "xLB yLB yRT yRT ", divided by a space!
/// This is the different origins that the graphicx package support. string bb;
enum Origin { /// clip image
DEFAULT, bool clip;
LEFTTOP, /// draft mode
LEFTCENTER, bool draft;
LEFTBASELINE, /// How to display the image
LEFTBOTTOM, DisplayType display;
CENTERTOP, /// any userdefined special command
CENTER, string special;
CENTERBASELINE, /// three possible values for rescaling
CENTERBOTTOM, LyXLength width;
RIGHTTOP, ///
RIGHTCENTER, LyXLength height;
RIGHTBASELINE, ///
RIGHTBOTTOM, int scale;
REFERENCE_POINT = LEFTBASELINE /// Type of rescaling
}; sizeType size_type;
/** The resize of the image, is it the default size, in cm, inch or
percentage of the page/column width/height */
enum Resize {
DEFAULT_SIZE,
CM,
INCH,
PERCENT_PAGE,
PERCENT_COLUMN,
SCALE
};
/// Keep the ratio between height and width when resizing. /// Keep the ratio between height and width when resizing.
bool keepAspectRatio; bool keepAspectRatio;
/// the size for the view inside lyx
/// What width resize to do? LyXLength lyxwidth;
Resize widthResize; ///
/// Value of width resize LyXLength lyxheight;
float widthSize;
/// What height resize to do?
Resize heightResize;
/// Value of height resize
float heightSize;
/// Origin point of rotation /// Origin point of rotation
Origin rotateOrigin; string rotateOrigin;
/// Rotation angle. /// Rotation angle.
float rotateAngle; float rotateAngle;
/// ///
@ -102,20 +79,16 @@ struct InsetGraphicsParams
InsetGraphicsParams(InsetGraphicsParams const &); InsetGraphicsParams(InsetGraphicsParams const &);
/// ///
InsetGraphicsParams & operator=(InsetGraphicsParams const &); InsetGraphicsParams & operator=(InsetGraphicsParams const &);
/// Save the parameters in the LyX format stream. /// Save the parameters in the LyX format stream.
void Write(Buffer const * buf, ostream & os) const; void Write(Buffer const * buf, ostream & os) const;
/// If the token belongs to our parameters, read it. /// If the token belongs to our parameters, read it.
bool Read(Buffer const * buf, LyXLex & lex, string const & token); bool Read(Buffer const * buf, LyXLex & lex, string const & token);
/// Test the struct to make sure that all the options have legal values. /// Test the struct to make sure that all the options have legal values.
void testInvariant() const; void testInvariant() const;
private: private:
/// Initialize the object to a default status. /// Initialize the object to a default status.
void init(); void init();
/// Copy the other objects content to us, used in copy c-tor and assignment /// Copy the other objects content to us, used in copy c-tor and assignment
void copy(InsetGraphicsParams const & params); void copy(InsetGraphicsParams const & params);
}; };