mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Add transformations to InsetExternal.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7877 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
453fe5d990
commit
8c96de553b
@ -1,5 +1,29 @@
|
||||
LyX file-format changes
|
||||
-----------------------
|
||||
2003-10-07 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* Add transformations to InsetExternal
|
||||
|
||||
boundingBox 0 0 20 20 the dimensions of the B.B..
|
||||
Output if the B.B. is not empty.
|
||||
clip clip the image to the B.B.
|
||||
Output if true.
|
||||
extra LaTeX "draft" 'extra' data passed to the primary
|
||||
command for this output format.
|
||||
(Possible formats LaTeX, PDFLaTeX,
|
||||
LinuxDoc, DocBook, Ascii.)
|
||||
The string can contain spaces and so
|
||||
is wrapped in "...".
|
||||
rotateAngle 30 Rotation of the data.
|
||||
Output for non-zero rotation only.
|
||||
rotateOrigin bottomleft Rotation origin.
|
||||
Output for non-zero rotation and
|
||||
non-default origin (center) only.
|
||||
scale 50
|
||||
width 2cm Output only if the image is resized.
|
||||
height 2cm
|
||||
keepAspectRatio
|
||||
|
||||
2003-10-07 Martin Vermeer <martin.vermeer@hut.fi>
|
||||
|
||||
* Added box inset. File format:
|
||||
|
@ -1,3 +1,8 @@
|
||||
2003-10-07 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* external_templates: add transformers to the RasterImage and XFig
|
||||
templates.
|
||||
|
||||
2003-10-07 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* images/buffer-close.xpm:
|
||||
|
@ -52,14 +52,28 @@ Template RasterImage
|
||||
FileFilter "*.(gif|png|jpg|bmp|pbm|ppm|tga|tif|xpm|xbm)"
|
||||
EditCommand "gimp $$FName"
|
||||
AutomaticProduction true
|
||||
Transform Rotate
|
||||
Transform Resize
|
||||
Transform Clip
|
||||
Transform Extra
|
||||
Format LaTeX
|
||||
Product "\\includegraphics{$$Basename}"
|
||||
TransformOption Rotate RotationLatexOption
|
||||
TransformOption Resize ResizeLatexOption
|
||||
TransformOption Clip ClipLatexOption
|
||||
TransformOption Extra ExtraOption
|
||||
Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
|
||||
Product "\\includegraphics$$Arg{$$Basename}"
|
||||
UpdateFormat eps
|
||||
UpdateResult "$$Basename.eps"
|
||||
Requirement "graphicx"
|
||||
FormatEnd
|
||||
Format PDFLaTeX
|
||||
Product "\\includegraphics{$$Basename}"
|
||||
TransformOption Rotate RotationLatexOption
|
||||
TransformOption Resize ResizeLatexOption
|
||||
TransformOption Clip ClipLatexOption
|
||||
TransformOption Extra ExtraOption
|
||||
Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
|
||||
Product "\\includegraphics$$Arg{$$Basename}"
|
||||
UpdateFormat png
|
||||
UpdateResult "$$Basename.png"
|
||||
Requirement "graphicx"
|
||||
@ -90,8 +104,12 @@ Template XFig
|
||||
FileFilter "*.fig"
|
||||
EditCommand "xfig $$FName"
|
||||
AutomaticProduction true
|
||||
Transform Rotate
|
||||
Transform Resize
|
||||
Format LaTeX
|
||||
Product "\\inputOrWarn{$$Basename.pstex_t}"
|
||||
TransformCommand Rotate RotationLatexCommand
|
||||
TransformCommand Resize ResizeLatexCommand
|
||||
Product "$$RotateFront$$ResizeFront\\input{$$Basename.pstex_t}$$ResizeBack$$RotateBack"
|
||||
UpdateFormat pstex
|
||||
UpdateResult "$$Basename.pstex_t"
|
||||
Requirement "graphicx"
|
||||
@ -99,7 +117,9 @@ Template XFig
|
||||
Preamble InputOrWarn
|
||||
FormatEnd
|
||||
Format PDFLaTeX
|
||||
Product "\\inputOrWarn{$$Basename.pdftex_t}"
|
||||
TransformCommand Rotate RotationLatexCommand
|
||||
TransformCommand Resize ResizeLatexCommand
|
||||
Product "$$RotateFront$$ResizeFront\\input{$$Basename.pdftex_t}$$ResizeBack$$RotateBack"
|
||||
UpdateFormat pdftex
|
||||
UpdateResult "$$Basename.pdftex_t"
|
||||
Requirement "graphicx"
|
||||
|
@ -1,3 +1,10 @@
|
||||
2003-10-07 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* ui/QExternalDialogBase.ui:
|
||||
* QExternal.[Ch]:
|
||||
* QExternalDialog.[Ch]: allow the user to alter the extradata
|
||||
field of InsetExternal::Params.
|
||||
|
||||
2003-10-07 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* QExternal.C: InsetExternal::Params -> InsetExternalParams.
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "Qt2BC.h"
|
||||
|
||||
using lyx::support::strToInt;
|
||||
using lyx::support::trim;
|
||||
|
||||
using std::string;
|
||||
|
||||
@ -53,6 +54,7 @@ void QExternal::build_dialog()
|
||||
bcview().addReadOnly(dialog_->externalCO);
|
||||
bcview().addReadOnly(dialog_->fileED);
|
||||
bcview().addReadOnly(dialog_->browsePB);
|
||||
bcview().addReadOnly(dialog_->extraED);
|
||||
|
||||
std::vector<string> templates(controller().getTemplates());
|
||||
|
||||
@ -73,7 +75,7 @@ void QExternal::update_contents()
|
||||
|
||||
dialog_->externalCO->setCurrentItem(controller()
|
||||
.getTemplateNumber(params.templatename()));
|
||||
dialog_->externalTV->setText(toqstr(helpText()));
|
||||
updateTemplate();
|
||||
|
||||
int item = 0;
|
||||
switch (params.display) {
|
||||
@ -95,6 +97,47 @@ void QExternal::update_contents()
|
||||
}
|
||||
|
||||
|
||||
void QExternal::updateTemplate()
|
||||
{
|
||||
namespace external = lyx::external;
|
||||
|
||||
dialog_->externalTV->setText(toqstr(helpText()));
|
||||
|
||||
// Ascertain whether the template has any formats supporting
|
||||
// the 'Extra' option
|
||||
QLineEdit * const input = dialog_->extraED;
|
||||
QComboBox * const combo = dialog_->extraFormatCB;
|
||||
|
||||
extra_.clear();
|
||||
input->clear();
|
||||
combo->clear();
|
||||
|
||||
external::Template templ =
|
||||
controller().getTemplate(dialog_->externalCO->currentItem());
|
||||
external::Template::Formats::const_iterator it = templ.formats.begin();
|
||||
external::Template::Formats::const_iterator end = templ.formats.end();
|
||||
for (; it != end; ++it) {
|
||||
if (it->second.option_transformers.find(external::Extra) ==
|
||||
it->second.option_transformers.end())
|
||||
continue;
|
||||
string const format = it->first;
|
||||
string const opt = controller().params().extradata.get(format);
|
||||
combo->insertItem(toqstr(format));
|
||||
extra_[format] = toqstr(opt);
|
||||
}
|
||||
|
||||
bool const enabled = combo->count() > 0;
|
||||
|
||||
input->setEnabled(enabled && !kernel().isBufferReadonly());
|
||||
combo->setEnabled(enabled);
|
||||
|
||||
if (enabled) {
|
||||
combo->setCurrentItem(0);
|
||||
input->setText(extra_[fromqstr(combo->currentText())]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string const QExternal::helpText() const
|
||||
{
|
||||
lyx::external::Template templ =
|
||||
@ -126,5 +169,10 @@ void QExternal::apply()
|
||||
|
||||
params.lyxscale = strToInt(fromqstr(dialog_->displayscale->text()));
|
||||
|
||||
std::map<string, QString>::const_iterator it = extra_.begin();
|
||||
std::map<string, QString>::const_iterator end = extra_.end();
|
||||
for (; it != end; ++it)
|
||||
params.extradata.set(it->first, trim(fromqstr(it->second)));
|
||||
|
||||
controller().setParams(params);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
|
||||
#include "QDialogView.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
class ControlExternal;
|
||||
@ -38,6 +39,11 @@ private:
|
||||
|
||||
/// get the right helptext
|
||||
std::string const helpText() const;
|
||||
|
||||
/// Helper function called when the template is changed.
|
||||
void updateTemplate();
|
||||
|
||||
std::map<std::string, QString> extra_;
|
||||
};
|
||||
|
||||
#endif // QEXTERNAL_H
|
||||
|
@ -10,10 +10,10 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
|
||||
#include "qt_helpers.h"
|
||||
#include "ControlExternal.h"
|
||||
|
||||
#include <qcombobox.h>
|
||||
#include <qpushbutton.h>
|
||||
#include <qfiledialog.h>
|
||||
#include <qtextview.h>
|
||||
@ -83,6 +83,21 @@ void QExternalDialog::browseClicked()
|
||||
|
||||
void QExternalDialog::templateChanged()
|
||||
{
|
||||
externalTV->setText(toqstr(form_->helpText()));
|
||||
form_->updateTemplate();
|
||||
form_->changed();
|
||||
}
|
||||
|
||||
|
||||
void QExternalDialog::formatChanged(const QString& format)
|
||||
{
|
||||
extraED->setText(form_->extra_[fromqstr(format)]);
|
||||
}
|
||||
|
||||
|
||||
void QExternalDialog::extraChanged(const QString& text)
|
||||
{
|
||||
std::string const format = fromqstr(extraFormatCB->currentText());
|
||||
form_->extra_[format] = text;
|
||||
form_->changed();
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,8 @@ protected slots:
|
||||
virtual void editClicked();
|
||||
virtual void browseClicked();
|
||||
virtual void templateChanged();
|
||||
virtual void formatChanged(const QString&);
|
||||
virtual void extraChanged(const QString&);
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent * e);
|
||||
private:
|
||||
|
@ -13,8 +13,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>280</width>
|
||||
<height>472</height>
|
||||
<width>279</width>
|
||||
<height>580</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
@ -34,77 +34,6 @@
|
||||
<name>spacing</name>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<widget row="0" column="0" rowspan="1" colspan="2" >
|
||||
<class>QGroupBox</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>GroupBox3</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>title</name>
|
||||
<string>Template</string>
|
||||
</property>
|
||||
<grid>
|
||||
<property stdset="1">
|
||||
<name>margin</name>
|
||||
<number>11</number>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>spacing</name>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<widget row="0" column="0" >
|
||||
<class>QComboBox</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>externalCO</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>sizePolicy</name>
|
||||
<sizepolicy>
|
||||
<hsizetype>3</hsizetype>
|
||||
<vsizetype>0</vsizetype>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property>
|
||||
<name>toolTip</name>
|
||||
<string>Available templates</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget row="1" column="0" rowspan="1" colspan="2" >
|
||||
<class>QTextView</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>externalTV</cstring>
|
||||
</property>
|
||||
<property>
|
||||
<name>toolTip</name>
|
||||
<string>LaTeX error messages</string>
|
||||
</property>
|
||||
</widget>
|
||||
<spacer row="0" column="1" >
|
||||
<property>
|
||||
<name>name</name>
|
||||
<cstring>Spacer3_2</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>orientation</name>
|
||||
<enum>Horizontal</enum>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>sizeType</name>
|
||||
<enum>Preferred</enum>
|
||||
</property>
|
||||
<property>
|
||||
<name>sizeHint</name>
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</grid>
|
||||
</widget>
|
||||
<widget row="2" column="0" >
|
||||
<class>QPushButton</class>
|
||||
<property stdset="1">
|
||||
@ -195,93 +124,6 @@
|
||||
</widget>
|
||||
</hbox>
|
||||
</widget>
|
||||
<widget row="4" column="0" rowspan="1" colspan="2" >
|
||||
<class>QLayoutWidget</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>Layout2</cstring>
|
||||
</property>
|
||||
<hbox>
|
||||
<property stdset="1">
|
||||
<name>margin</name>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>spacing</name>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<spacer>
|
||||
<property>
|
||||
<name>name</name>
|
||||
<cstring>Spacer3</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>orientation</name>
|
||||
<enum>Horizontal</enum>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>sizeType</name>
|
||||
<enum>Expanding</enum>
|
||||
</property>
|
||||
<property>
|
||||
<name>sizeHint</name>
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<widget>
|
||||
<class>QPushButton</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>okPB</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>text</name>
|
||||
<string>&OK</string>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>default</name>
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget>
|
||||
<class>QPushButton</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>applyPB</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>text</name>
|
||||
<string>&Apply</string>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>default</name>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget>
|
||||
<class>QPushButton</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>closePB</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>text</name>
|
||||
<string>&Close</string>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>autoDefault</name>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>default</name>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</hbox>
|
||||
</widget>
|
||||
<spacer row="2" column="1" >
|
||||
<property>
|
||||
<name>name</name>
|
||||
@ -504,6 +346,267 @@
|
||||
</widget>
|
||||
</grid>
|
||||
</widget>
|
||||
<widget row="0" column="0" rowspan="1" colspan="2" >
|
||||
<class>QGroupBox</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>GroupBox3</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>title</name>
|
||||
<string>Template</string>
|
||||
</property>
|
||||
<grid>
|
||||
<property stdset="1">
|
||||
<name>margin</name>
|
||||
<number>11</number>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>spacing</name>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<widget row="0" column="0" >
|
||||
<class>QComboBox</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>externalCO</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>sizePolicy</name>
|
||||
<sizepolicy>
|
||||
<hsizetype>3</hsizetype>
|
||||
<vsizetype>0</vsizetype>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property>
|
||||
<name>toolTip</name>
|
||||
<string>Available templates</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget row="1" column="0" rowspan="1" colspan="2" >
|
||||
<class>QTextView</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>externalTV</cstring>
|
||||
</property>
|
||||
<property>
|
||||
<name>toolTip</name>
|
||||
<string>LaTeX error messages</string>
|
||||
</property>
|
||||
</widget>
|
||||
<spacer row="0" column="1" >
|
||||
<property>
|
||||
<name>name</name>
|
||||
<cstring>Spacer3_2</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>orientation</name>
|
||||
<enum>Horizontal</enum>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>sizeType</name>
|
||||
<enum>Preferred</enum>
|
||||
</property>
|
||||
<property>
|
||||
<name>sizeHint</name>
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</grid>
|
||||
</widget>
|
||||
<widget row="5" column="0" rowspan="1" colspan="2" >
|
||||
<class>QLayoutWidget</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>Layout2</cstring>
|
||||
</property>
|
||||
<hbox>
|
||||
<property stdset="1">
|
||||
<name>margin</name>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>spacing</name>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<spacer>
|
||||
<property>
|
||||
<name>name</name>
|
||||
<cstring>Spacer3</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>orientation</name>
|
||||
<enum>Horizontal</enum>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>sizeType</name>
|
||||
<enum>Expanding</enum>
|
||||
</property>
|
||||
<property>
|
||||
<name>sizeHint</name>
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<widget>
|
||||
<class>QPushButton</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>okPB</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>text</name>
|
||||
<string>&OK</string>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>default</name>
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget>
|
||||
<class>QPushButton</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>applyPB</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>text</name>
|
||||
<string>&Apply</string>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>default</name>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget>
|
||||
<class>QPushButton</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>closePB</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>text</name>
|
||||
<string>&Close</string>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>autoDefault</name>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>default</name>
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</hbox>
|
||||
</widget>
|
||||
<widget row="4" column="0" rowspan="1" colspan="2" >
|
||||
<class>QGroupBox</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>GroupBox5</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>title</name>
|
||||
<string>Output Options</string>
|
||||
</property>
|
||||
<grid>
|
||||
<property stdset="1">
|
||||
<name>margin</name>
|
||||
<number>11</number>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>spacing</name>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<widget row="0" column="0" >
|
||||
<class>QLayoutWidget</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>Layout13</cstring>
|
||||
</property>
|
||||
<vbox>
|
||||
<property stdset="1">
|
||||
<name>margin</name>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>spacing</name>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<widget>
|
||||
<class>QLabel</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>formatLA</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>text</name>
|
||||
<string>Forma&t:</string>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>textFormat</name>
|
||||
<enum>AutoText</enum>
|
||||
</property>
|
||||
<property>
|
||||
<name>buddy</name>
|
||||
<cstring>extraFormatCB</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
<widget>
|
||||
<class>QComboBox</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>extraFormatCB</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</vbox>
|
||||
</widget>
|
||||
<widget row="0" column="1" >
|
||||
<class>QLayoutWidget</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>Layout14</cstring>
|
||||
</property>
|
||||
<vbox>
|
||||
<property stdset="1">
|
||||
<name>margin</name>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>spacing</name>
|
||||
<number>6</number>
|
||||
</property>
|
||||
<widget>
|
||||
<class>QLabel</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>optionLA</cstring>
|
||||
</property>
|
||||
<property stdset="1">
|
||||
<name>text</name>
|
||||
<string>O&ption:</string>
|
||||
</property>
|
||||
<property>
|
||||
<name>buddy</name>
|
||||
<cstring>extraED</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
<widget>
|
||||
<class>QLineEdit</class>
|
||||
<property stdset="1">
|
||||
<name>name</name>
|
||||
<cstring>extraED</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</vbox>
|
||||
</widget>
|
||||
</grid>
|
||||
</widget>
|
||||
</grid>
|
||||
</widget>
|
||||
<connections>
|
||||
@ -555,15 +658,29 @@
|
||||
<receiver>QExternalDialogBase</receiver>
|
||||
<slot>change_adaptor()</slot>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>extraFormatCB</sender>
|
||||
<signal>activated(const QString&)</signal>
|
||||
<receiver>QExternalDialogBase</receiver>
|
||||
<slot>formatChanged(const QString&)</slot>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>displayscale</sender>
|
||||
<signal>textChanged(const QString&)</signal>
|
||||
<receiver>QExternalDialogBase</receiver>
|
||||
<slot>change_adaptor()</slot>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>extraED</sender>
|
||||
<signal>textChanged(const QString&)</signal>
|
||||
<receiver>QExternalDialogBase</receiver>
|
||||
<slot>extraChanged(const QString&)</slot>
|
||||
</connection>
|
||||
<slot access="public">browseClicked()</slot>
|
||||
<slot access="public">change_adaptor()</slot>
|
||||
<slot access="public">editClicked()</slot>
|
||||
<slot access="public">formatChanged(const QString&)</slot>
|
||||
<slot access="public">extraChanged(const QString&)</slot>
|
||||
<slot access="public">templateChanged()</slot>
|
||||
<slot access="public">updateClicked()</slot>
|
||||
<slot access="public">viewClicked()</slot>
|
||||
|
@ -1,3 +1,13 @@
|
||||
2003-10-07 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* FormExternal.[Ch]:
|
||||
* forms/form_external.fd: allow the user to alter the extradata
|
||||
field of InsetExternal::Params.
|
||||
|
||||
2003-10-07 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* FormExternal.C: InsetExternal::Params -> InsetExternalParams.
|
||||
|
||||
2003-10-07 Martin Vermeer <martin.vermeer@hut.fi>
|
||||
|
||||
* Dialogs.C:
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
using lyx::support::getStringFromVector;
|
||||
using lyx::support::strToInt;
|
||||
using lyx::support::trim;
|
||||
|
||||
using std::string;
|
||||
|
||||
@ -73,6 +74,11 @@ void FormExternal::apply()
|
||||
params.display = lyx::graphics::DefaultDisplay;
|
||||
}
|
||||
|
||||
std::map<string, string>::const_iterator it = extra_.begin();
|
||||
std::map<string, string>::const_iterator end = extra_.end();
|
||||
for (; it != end; ++it)
|
||||
params.extradata.set(it->first, trim(it->second));
|
||||
|
||||
controller().setParams(params);
|
||||
}
|
||||
|
||||
@ -90,6 +96,7 @@ void FormExternal::build()
|
||||
// Disable for read-only documents.
|
||||
bcview().addReadOnly(dialog_->input_filename);
|
||||
bcview().addReadOnly(dialog_->button_browse);
|
||||
bcview().addReadOnly(dialog_->input_extra);
|
||||
|
||||
// Trigger an input event for cut&paste with middle mouse button.
|
||||
setPrehandler(dialog_->input_filename);
|
||||
@ -97,6 +104,8 @@ void FormExternal::build()
|
||||
// Activate ok/apply immediately upon input.
|
||||
fl_set_input_return(dialog_->input_filename, FL_RETURN_CHANGED);
|
||||
fl_set_input_return(dialog_->input_lyxscale, FL_RETURN_CHANGED);
|
||||
fl_set_input_return(dialog_->input_extra, FL_RETURN_CHANGED);
|
||||
fl_set_input_return(dialog_->input_lyxscale, FL_RETURN_CHANGED);
|
||||
|
||||
fl_set_input_filter(dialog_->input_lyxscale, fl_unsigned_int_filter);
|
||||
|
||||
@ -174,6 +183,17 @@ ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
|
||||
} else if (ob == dialog_->button_edit) {
|
||||
controller().editExternal();
|
||||
result = ButtonPolicy::SMI_NOOP;
|
||||
|
||||
} else if (ob == dialog_->input_extra) {
|
||||
string const format =
|
||||
fl_get_choice_text(dialog_->choice_extra_format);
|
||||
extra_[format] = getString(dialog_->input_extra);
|
||||
|
||||
} else if (ob == dialog_->choice_extra_format) {
|
||||
string const format =
|
||||
fl_get_choice_text(dialog_->choice_extra_format);
|
||||
fl_set_input(dialog_->input_extra, extra_[format].c_str());
|
||||
result = ButtonPolicy::SMI_NOOP;
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -182,8 +202,10 @@ ButtonPolicy::SMInput FormExternal::input(FL_OBJECT * ob, long)
|
||||
|
||||
void FormExternal::updateComboChange()
|
||||
{
|
||||
namespace external = lyx::external;
|
||||
|
||||
int const choice = fl_get_choice(dialog_->choice_template) - 1;
|
||||
lyx::external::Template templ = controller().getTemplate(choice);
|
||||
external::Template templ = controller().getTemplate(choice);
|
||||
|
||||
// Update the help text
|
||||
string const txt = formatted(templ.helpText,
|
||||
@ -191,4 +213,35 @@ void FormExternal::updateComboChange()
|
||||
fl_clear_browser(dialog_->browser_helptext);
|
||||
fl_addto_browser(dialog_->browser_helptext, txt.c_str());
|
||||
fl_set_browser_topline(dialog_->browser_helptext, 0);
|
||||
|
||||
// Ascertain whether the template has any formats supporting
|
||||
// the 'Extra' option
|
||||
FL_OBJECT * const ob_input = dialog_->input_extra;
|
||||
FL_OBJECT * const ob_choice = dialog_->choice_extra_format;
|
||||
extra_.clear();
|
||||
fl_set_input(ob_input, "");
|
||||
fl_clear_choice(ob_choice);
|
||||
|
||||
external::Template::Formats::const_iterator it = templ.formats.begin();
|
||||
external::Template::Formats::const_iterator end = templ.formats.end();
|
||||
for (; it != end; ++it) {
|
||||
if (it->second.option_transformers.find(external::Extra) ==
|
||||
it->second.option_transformers.end())
|
||||
continue;
|
||||
string const format = it->first;
|
||||
string const opt = controller().params().extradata.get(format);
|
||||
fl_addto_choice(ob_choice, format.c_str());
|
||||
extra_[format] = opt;
|
||||
}
|
||||
|
||||
bool const enabled = fl_get_choice_maxitems(ob_choice) > 0;
|
||||
|
||||
setEnabled(ob_input, enabled && !kernel().isBufferReadonly());
|
||||
setEnabled(ob_choice, enabled);
|
||||
|
||||
if (enabled) {
|
||||
fl_set_choice(ob_choice, 1);
|
||||
string const format = fl_get_choice_text(ob_choice);
|
||||
fl_set_input(ob_input, extra_[format].c_str());
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
|
||||
#include "FormDialogView.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
class ControlExternal;
|
||||
@ -42,6 +43,8 @@ private:
|
||||
|
||||
///
|
||||
void updateComboChange();
|
||||
|
||||
std::map<std::string, std::string> extra_;
|
||||
};
|
||||
|
||||
#endif // FORMEXTERNAL_H
|
||||
|
@ -10,13 +10,13 @@ SnapGrid: 5
|
||||
=============== FORM ===============
|
||||
Name: form_external
|
||||
Width: 395
|
||||
Height: 375
|
||||
Number of Objects: 13
|
||||
Height: 445
|
||||
Number of Objects: 16
|
||||
|
||||
--------------------
|
||||
class: FL_BOX
|
||||
type: FLAT_BOX
|
||||
box: 0 0 395 375
|
||||
box: 0 0 395 445
|
||||
boxtype: FL_FLAT_BOX
|
||||
colors: FL_COL1 FL_COL1
|
||||
alignment: FL_ALIGN_CENTER
|
||||
@ -31,6 +31,42 @@ name:
|
||||
callback:
|
||||
argument:
|
||||
|
||||
--------------------
|
||||
class: FL_CHOICE
|
||||
type: NORMAL_CHOICE
|
||||
box: 140 5 160 25
|
||||
boxtype: FL_FRAME_BOX
|
||||
colors: FL_COL1 FL_RIGHT_BCOL
|
||||
alignment: FL_ALIGN_LEFT
|
||||
style: FL_NORMAL_STYLE
|
||||
size: FL_NORMAL_SIZE
|
||||
lcol: FL_BLACK
|
||||
label: Template:|#T
|
||||
shortcut:
|
||||
resize: FL_RESIZE_ALL
|
||||
gravity: FL_NorthWest FL_NorthEast
|
||||
name: choice_template
|
||||
callback: C_FormDialogView_InputCB
|
||||
argument: 0
|
||||
|
||||
--------------------
|
||||
class: FL_BROWSER
|
||||
type: NORMAL_BROWSER
|
||||
box: 10 35 380 140
|
||||
boxtype: FL_DOWN_BOX
|
||||
colors: FL_COL1 FL_YELLOW
|
||||
alignment: FL_ALIGN_TOP
|
||||
style: FL_NORMAL_STYLE
|
||||
size: FL_DEFAULT_SIZE
|
||||
lcol: FL_BLACK
|
||||
label:
|
||||
shortcut:
|
||||
resize: FL_RESIZE_ALL
|
||||
gravity: FL_NorthWest FL_SouthEast
|
||||
name: browser_helptext
|
||||
callback:
|
||||
argument:
|
||||
|
||||
--------------------
|
||||
class: FL_INPUT
|
||||
type: NORMAL_INPUT
|
||||
@ -158,45 +194,63 @@ callback: C_FormDialogView_InputCB
|
||||
argument: 0
|
||||
|
||||
--------------------
|
||||
class: FL_CHOICE
|
||||
type: NORMAL_CHOICE
|
||||
box: 140 5 160 25
|
||||
boxtype: FL_FRAME_BOX
|
||||
colors: FL_COL1 FL_RIGHT_BCOL
|
||||
alignment: FL_ALIGN_LEFT
|
||||
class: FL_LABELFRAME
|
||||
type: ENGRAVED_FRAME
|
||||
box: 5 340 385 55
|
||||
boxtype: FL_NO_BOX
|
||||
colors: FL_BLACK FL_COL1
|
||||
alignment: FL_ALIGN_TOP_LEFT
|
||||
style: FL_NORMAL_STYLE
|
||||
size: FL_NORMAL_SIZE
|
||||
lcol: FL_BLACK
|
||||
label: Template:|#T
|
||||
label: Output options
|
||||
shortcut:
|
||||
resize: FL_RESIZE_ALL
|
||||
gravity: FL_NorthWest FL_NorthEast
|
||||
name: choice_template
|
||||
callback: C_FormDialogView_InputCB
|
||||
argument: 0
|
||||
|
||||
--------------------
|
||||
class: FL_BROWSER
|
||||
type: NORMAL_BROWSER
|
||||
box: 10 35 380 140
|
||||
boxtype: FL_DOWN_BOX
|
||||
colors: FL_COL1 FL_YELLOW
|
||||
alignment: FL_ALIGN_TOP
|
||||
style: FL_NORMAL_STYLE
|
||||
size: FL_DEFAULT_SIZE
|
||||
lcol: FL_BLACK
|
||||
label:
|
||||
shortcut:
|
||||
resize: FL_RESIZE_ALL
|
||||
gravity: FL_NorthWest FL_SouthEast
|
||||
name: browser_helptext
|
||||
gravity: FL_NoGravity FL_NoGravity
|
||||
name:
|
||||
callback:
|
||||
argument:
|
||||
|
||||
--------------------
|
||||
class: FL_INPUT
|
||||
type: NORMAL_INPUT
|
||||
box: 85 355 125 25
|
||||
boxtype: FL_DOWN_BOX
|
||||
colors: FL_COL1 FL_MCOL
|
||||
alignment: FL_ALIGN_LEFT
|
||||
style: FL_NORMAL_STYLE
|
||||
size: FL_NORMAL_SIZE
|
||||
lcol: FL_BLACK
|
||||
label: Option|#O
|
||||
shortcut:
|
||||
resize: FL_RESIZE_X
|
||||
gravity: FL_West FL_East
|
||||
name: input_extra
|
||||
callback: C_FormDialogView_InputCB
|
||||
argument: 0
|
||||
|
||||
--------------------
|
||||
class: FL_CHOICE
|
||||
type: NORMAL_CHOICE
|
||||
box: 265 355 115 25
|
||||
boxtype: FL_FRAME_BOX
|
||||
colors: FL_COL1 FL_BLACK
|
||||
alignment: FL_ALIGN_LEFT
|
||||
style: FL_NORMAL_STYLE
|
||||
size: FL_NORMAL_SIZE
|
||||
lcol: FL_BLACK
|
||||
label: Format|#t
|
||||
shortcut:
|
||||
resize: FL_RESIZE_NONE
|
||||
gravity: FL_East FL_East
|
||||
name: choice_extra_format
|
||||
callback: C_FormDialogView_InputCB
|
||||
argument: 0
|
||||
|
||||
--------------------
|
||||
class: FL_BUTTON
|
||||
type: RETURN_BUTTON
|
||||
box: 110 340 90 25
|
||||
box: 110 410 90 25
|
||||
boxtype: FL_UP_BOX
|
||||
colors: FL_COL1 FL_COL1
|
||||
alignment: FL_ALIGN_CENTER
|
||||
@ -214,7 +268,7 @@ argument: 0
|
||||
--------------------
|
||||
class: FL_BUTTON
|
||||
type: NORMAL_BUTTON
|
||||
box: 205 340 90 25
|
||||
box: 205 410 90 25
|
||||
boxtype: FL_UP_BOX
|
||||
colors: FL_COL1 FL_COL1
|
||||
alignment: FL_ALIGN_CENTER
|
||||
@ -232,7 +286,7 @@ argument: 0
|
||||
--------------------
|
||||
class: FL_BUTTON
|
||||
type: NORMAL_BUTTON
|
||||
box: 300 340 90 25
|
||||
box: 300 410 90 25
|
||||
boxtype: FL_UP_BOX
|
||||
colors: FL_COL1 FL_COL1
|
||||
alignment: FL_ALIGN_CENTER
|
||||
|
@ -1,3 +1,19 @@
|
||||
2003-10-07 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* ExternalTransforms.[Ch]: new files, detailing transforms that can
|
||||
be applied to InsetExternal.
|
||||
|
||||
* Makefile.am: add these new files.
|
||||
|
||||
* ExternalTemplate.[Ch]: add a list of available transforms to
|
||||
class Template and a list of factory functions for transformer classes
|
||||
that can act on this data to class Format.
|
||||
|
||||
* insetexternal.[Ch]: add transform data to InsetExternal::Params.
|
||||
|
||||
* ExternalSupport.C: Add code to replace transform placeholders
|
||||
with appropriate output.
|
||||
|
||||
2003-10-07 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* ExternalSupport.[Ch]: new files, moving the private member functions
|
||||
|
@ -12,12 +12,13 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "ExternalSupport.h"
|
||||
#include "ExternalTemplate.h"
|
||||
#include "ExternalTransforms.h"
|
||||
#include "insetexternal.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "converter.h"
|
||||
#include "debug.h"
|
||||
#include "ExternalTemplate.h"
|
||||
|
||||
#include "support/filetools.h"
|
||||
#include "support/forkedcall.h"
|
||||
@ -35,6 +36,7 @@ using std::endl;
|
||||
|
||||
using std::ostream;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
|
||||
namespace lyx {
|
||||
@ -197,6 +199,13 @@ void updateExternal(InsetExternalParams const & params,
|
||||
// return success
|
||||
}
|
||||
|
||||
|
||||
string const substituteCommands(InsetExternalParams const & params,
|
||||
string const & input, string const & format);
|
||||
|
||||
string const substituteOptions(InsetExternalParams const & params,
|
||||
string const & input, string const & format);
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
@ -229,8 +238,10 @@ int writeExternal(InsetExternalParams const & params,
|
||||
buffer.temppath());
|
||||
}
|
||||
|
||||
string const str = doSubstitution(params, buffer, cit->second.product,
|
||||
from_file);
|
||||
string str = doSubstitution(params, buffer, cit->second.product,
|
||||
from_file);
|
||||
str = substituteCommands(params, str, format);
|
||||
str = substituteOptions(params, str, format);
|
||||
os << str;
|
||||
return int(lyx::count(str.begin(), str.end(),'\n') + 1);
|
||||
}
|
||||
@ -245,5 +256,158 @@ string const doSubstitution(InsetExternalParams const & params,
|
||||
return doSubstitution(params, buffer, s, filename);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Empty template, specialised below.
|
||||
template <typename TransformType>
|
||||
string const substituteIt(string const &,
|
||||
TransformID,
|
||||
string const &,
|
||||
Template::Format const &,
|
||||
InsetExternalParams const &);
|
||||
|
||||
|
||||
template <>
|
||||
string const substituteIt<TransformCommand>(string const & input,
|
||||
TransformID id,
|
||||
string const & /* formatname */,
|
||||
Template::Format const & format,
|
||||
InsetExternalParams const & params)
|
||||
{
|
||||
typedef std::map<TransformID, TransformStore> Transformers;
|
||||
Transformers::const_iterator it = format.command_transformers.find(id);
|
||||
if (it == format.command_transformers.end())
|
||||
return input;
|
||||
|
||||
TransformStore const & store = it->second;
|
||||
|
||||
TransformCommand::ptr_type ptr;
|
||||
if (id == Rotate)
|
||||
ptr = store.getCommandTransformer(params.rotationdata);
|
||||
else if (id == Resize)
|
||||
ptr = store.getCommandTransformer(params.resizedata);
|
||||
|
||||
if (!ptr.get())
|
||||
return input;
|
||||
|
||||
string result =
|
||||
support::subst(input, ptr->front_placeholder(), ptr->front());
|
||||
return support::subst(result, ptr->back_placeholder(), ptr->back());
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
string const substituteIt<TransformOption>(string const & input,
|
||||
TransformID id,
|
||||
string const & fname,
|
||||
Template::Format const & format,
|
||||
InsetExternalParams const & params)
|
||||
{
|
||||
typedef std::map<TransformID, TransformStore> Transformers;
|
||||
Transformers::const_iterator it = format.option_transformers.find(id);
|
||||
if (it == format.option_transformers.end())
|
||||
return input;
|
||||
|
||||
TransformStore const & store = it->second;
|
||||
|
||||
TransformOption::ptr_type ptr;
|
||||
switch (id) {
|
||||
case Clip:
|
||||
ptr = store.getOptionTransformer(params.clipdata);
|
||||
break;
|
||||
case Extra:
|
||||
ptr = store.getOptionTransformer(params.extradata.get(fname));
|
||||
break;
|
||||
case Rotate:
|
||||
ptr = store.getOptionTransformer(params.rotationdata);
|
||||
break;
|
||||
case Resize:
|
||||
ptr = store.getOptionTransformer(params.resizedata);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ptr.get())
|
||||
return input;
|
||||
|
||||
return support::subst(input, ptr->placeholder(), ptr->option());
|
||||
}
|
||||
|
||||
|
||||
template <typename TransformerType>
|
||||
string const transformIt(InsetExternalParams const & params,
|
||||
string const & s, string const & formatname)
|
||||
{
|
||||
Template const * const et = getTemplatePtr(params);
|
||||
if (!et || et->transformIds.empty())
|
||||
return s;
|
||||
|
||||
Template::Formats::const_iterator fit = et->formats.find(formatname);
|
||||
if (fit == et->formats.end())
|
||||
return s;
|
||||
|
||||
string result = s;
|
||||
Template::Format const & format = fit->second;
|
||||
|
||||
typedef vector<TransformID> TransformsIDs;
|
||||
TransformsIDs::const_iterator it = et->transformIds.begin();
|
||||
TransformsIDs::const_iterator end = et->transformIds.end();
|
||||
for (; it != end; ++it) {
|
||||
result = substituteIt<TransformerType>(result, *it, formatname,
|
||||
format, params);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
string const substituteCommands(InsetExternalParams const & params,
|
||||
string const & input, string const & format)
|
||||
{
|
||||
return transformIt<TransformCommand>(params, input, format);
|
||||
}
|
||||
|
||||
|
||||
string const substituteOption(InsetExternalParams const & params,
|
||||
string const & input, string const & format)
|
||||
{
|
||||
string opt = transformIt<TransformOption>(params, input, format);
|
||||
|
||||
if (format == "LaTeX" || format == "PDFLaTeX")
|
||||
return sanitizeLatexOption(opt);
|
||||
if (format == "DocBook")
|
||||
return sanitizeDocBookOption(opt);
|
||||
if (format == "LinuxDoc")
|
||||
return sanitizeLinuxDocOption(opt);
|
||||
return opt;
|
||||
}
|
||||
|
||||
|
||||
string const substituteOptions(InsetExternalParams const & params,
|
||||
string const & input, string const & format)
|
||||
{
|
||||
string output = input;
|
||||
|
||||
Template const * const et = getTemplatePtr(params);
|
||||
if (!et || et->transformIds.empty())
|
||||
return output;
|
||||
|
||||
Template::Formats::const_iterator fit = et->formats.find(format);
|
||||
if (fit == et->formats.end() || fit->second.options.empty())
|
||||
return output;
|
||||
|
||||
typedef vector<Template::Option> Options;
|
||||
Options const & options = fit->second.options;
|
||||
Options::const_iterator it = options.begin();
|
||||
Options::const_iterator end = options.end();
|
||||
for (; it != end; ++it) {
|
||||
string const opt = substituteOption(params, it->option, format);
|
||||
string const placeholder = "$$" + it->name;
|
||||
output = support::subst(output, placeholder, opt);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
} // namespace external
|
||||
} // namespace lyx
|
||||
|
@ -4,6 +4,7 @@
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Asger Alstrup Nielsen
|
||||
* \author Angus Leeming
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -19,6 +20,7 @@
|
||||
#include "support/lstrings.h"
|
||||
#include "support/path.h"
|
||||
#include "support/path_defines.h"
|
||||
#include "support/translator.h"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
@ -37,6 +39,14 @@ using std::vector;
|
||||
namespace lyx {
|
||||
namespace external {
|
||||
|
||||
namespace {
|
||||
|
||||
typedef Translator<TransformID, string> TransformIDTranslator;
|
||||
TransformIDTranslator const & transformIDTranslator();
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
// We have to have dummy default commands for security reasons!
|
||||
Template::Template()
|
||||
: inputFormat("*")
|
||||
@ -93,6 +103,15 @@ public:
|
||||
<< "\tFileFilter " << et.fileRegExp << '\n'
|
||||
<< "\tEditCommand " << et.editCommand << '\n'
|
||||
<< "\tAutomaticProduction " << et.automaticProduction << '\n';
|
||||
|
||||
typedef vector<TransformID> IDs;
|
||||
IDs::const_iterator it = et.transformIds.begin();
|
||||
IDs::const_iterator end = et.transformIds.end();
|
||||
for (; it != end; ++it) {
|
||||
ost << "\tTransform "
|
||||
<< transformIDTranslator().find(*it) << '\n';
|
||||
}
|
||||
|
||||
et.dumpFormats(ost);
|
||||
ost << "TemplateEnd" << endl;
|
||||
|
||||
@ -108,7 +127,7 @@ public:
|
||||
|
||||
dumpFormat(ostream & o) : ost(o) {}
|
||||
|
||||
void operator()(value_type const & vt) const{
|
||||
void operator()(value_type const & vt) const {
|
||||
Template::Format const & ft = vt.second;
|
||||
ost << "\tFormat " << vt.first << '\n'
|
||||
<< "\t\tProduct " << ft.product << '\n'
|
||||
@ -116,10 +135,21 @@ public:
|
||||
<< "\t\tUpdateResult " << ft.updateResult << '\n'
|
||||
<< "\t\tRequirement " << ft.requirement << '\n';
|
||||
|
||||
vector<string>::const_iterator it = ft.preambleNames.begin();
|
||||
vector<string>::const_iterator end = ft.preambleNames.end();
|
||||
for (; it != end; ++it) {
|
||||
ost << "\t\tPreamble " << *it << '\n';
|
||||
typedef vector<Template::Option> Options;
|
||||
Options::const_iterator oit = ft.options.begin();
|
||||
Options::const_iterator oend = ft.options.end();
|
||||
for (; oit != oend; ++oit) {
|
||||
ost << "\t\tOption "
|
||||
<< oit->name
|
||||
<< ": "
|
||||
<< oit->option
|
||||
<< '\n';
|
||||
}
|
||||
|
||||
vector<string>::const_iterator pit = ft.preambleNames.begin();
|
||||
vector<string>::const_iterator pend = ft.preambleNames.end();
|
||||
for (; pit != pend; ++pit) {
|
||||
ost << "\t\tPreamble " << *pit << '\n';
|
||||
}
|
||||
|
||||
ost << "\tFormatEnd\n";
|
||||
@ -244,6 +274,23 @@ void TemplateManager::readTemplates(string const & path)
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void add(vector<TransformID> & ids, string const & name)
|
||||
{
|
||||
TransformID id = transformIDTranslator().find(name);
|
||||
if (int(id) == -1) {
|
||||
lyxerr << "external::Template::readTemplate\n"
|
||||
<< "Transform " << name << " is not recognized"
|
||||
<< std::endl;
|
||||
} else {
|
||||
ids.push_back(id);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
void Template::readTemplate(LyXLex & lex)
|
||||
{
|
||||
enum TemplateOptionTags {
|
||||
@ -253,6 +300,7 @@ void Template::readTemplate(LyXLex & lex)
|
||||
TO_FILTER,
|
||||
TO_EDITCMD,
|
||||
TO_AUTOMATIC,
|
||||
TO_TRANSFORM,
|
||||
TO_FORMAT,
|
||||
TO_END
|
||||
};
|
||||
@ -265,7 +313,8 @@ void Template::readTemplate(LyXLex & lex)
|
||||
{ "guiname", TO_GUINAME },
|
||||
{ "helptext", TO_HELPTEXT },
|
||||
{ "inputformat", TO_INPUTFORMAT },
|
||||
{ "templateend", TO_END }
|
||||
{ "templateend", TO_END },
|
||||
{ "transform", TO_TRANSFORM }
|
||||
};
|
||||
|
||||
pushpophelper pph(lex, templateoptiontags, TO_END);
|
||||
@ -301,6 +350,11 @@ void Template::readTemplate(LyXLex & lex)
|
||||
automaticProduction = lex.getBool();
|
||||
break;
|
||||
|
||||
case TO_TRANSFORM:
|
||||
lex.next(true);
|
||||
add(transformIds, lex.getString());
|
||||
break;
|
||||
|
||||
case TO_FORMAT:
|
||||
lex.next(true);
|
||||
formats[lex.getString()].readFormat(lex);
|
||||
@ -319,6 +373,87 @@ void Template::readTemplate(LyXLex & lex)
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
void transform_not_found(std::ostream & os, string const & transform)
|
||||
{
|
||||
os << "external::Format::readFormat. Transformation \""
|
||||
<< transform << "\" is unrecognized." << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void transform_class_not_found(std::ostream & os, string const & tclass)
|
||||
{
|
||||
os << "external::Format::readFormat. Transformation class \""
|
||||
<< tclass << "\" is unrecognized." << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void setCommandFactory(Template::Format & format, string const & transform,
|
||||
string const & transformer_class)
|
||||
{
|
||||
bool class_found = false;
|
||||
if (transform == "Resize" && transformer_class == "ResizeLatexCommand") {
|
||||
class_found = true;
|
||||
ResizeCommandFactory factory = ResizeLatexCommand::factory;
|
||||
format.command_transformers[Resize] =
|
||||
TransformStore(Resize, factory);
|
||||
|
||||
} else if (transform == "Rotate" &&
|
||||
transformer_class == "RotationLatexCommand") {
|
||||
class_found = true;
|
||||
RotationCommandFactory factory = RotationLatexCommand::factory;
|
||||
format.command_transformers[Rotate] =
|
||||
TransformStore(Rotate, factory);
|
||||
|
||||
} else
|
||||
transform_not_found(lyxerr, transform);
|
||||
|
||||
if (!class_found)
|
||||
transform_class_not_found(lyxerr, transformer_class);
|
||||
}
|
||||
|
||||
|
||||
void setOptionFactory(Template::Format & format, string const & transform,
|
||||
string const & transformer_class)
|
||||
{
|
||||
bool class_found = false;
|
||||
if (transform == "Clip" && transformer_class == "ClipLatexOption") {
|
||||
class_found = true;
|
||||
ClipOptionFactory factory = ClipLatexOption::factory;
|
||||
format.option_transformers[Clip] =
|
||||
TransformStore(Clip, factory);
|
||||
|
||||
} else if (transform == "Extra" && transformer_class == "ExtraOption") {
|
||||
class_found = true;
|
||||
ExtraOptionFactory factory = ExtraOption::factory;
|
||||
format.option_transformers[Extra] =
|
||||
TransformStore(Extra, factory);
|
||||
|
||||
} else if (transform == "Resize" &&
|
||||
transformer_class == "ResizeLatexOption") {
|
||||
class_found = true;
|
||||
ResizeOptionFactory factory = ResizeLatexOption::factory;
|
||||
format.option_transformers[Resize] =
|
||||
TransformStore(Resize, factory);
|
||||
|
||||
} else if (transform == "Rotate" &&
|
||||
transformer_class == "RotationLatexOption") {
|
||||
class_found = true;
|
||||
RotationOptionFactory factory = RotationLatexOption::factory;
|
||||
format.option_transformers[Rotate] =
|
||||
TransformStore(Rotate, factory);
|
||||
|
||||
} else
|
||||
transform_not_found(lyxerr, transform);
|
||||
|
||||
if (!class_found)
|
||||
transform_class_not_found(lyxerr, transformer_class);
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
void Template::Format::readFormat(LyXLex & lex)
|
||||
{
|
||||
enum FormatTags {
|
||||
@ -326,15 +461,21 @@ void Template::Format::readFormat(LyXLex & lex)
|
||||
FO_UPDATEFORMAT,
|
||||
FO_UPDATERESULT,
|
||||
FO_REQUIREMENT,
|
||||
FO_OPTION,
|
||||
FO_PREAMBLE,
|
||||
FO_TRANSFORMCOMMAND,
|
||||
FO_TRANSFORMOPTION,
|
||||
FO_END
|
||||
};
|
||||
|
||||
keyword_item formattags[] = {
|
||||
{ "formatend", FO_END },
|
||||
{ "option", FO_OPTION },
|
||||
{ "preamble", FO_PREAMBLE },
|
||||
{ "product", FO_PRODUCT },
|
||||
{ "requirement", FO_REQUIREMENT },
|
||||
{ "transformcommand", FO_TRANSFORMCOMMAND },
|
||||
{ "transformoption", FO_TRANSFORMOPTION },
|
||||
{ "updateformat", FO_UPDATEFORMAT },
|
||||
{ "updateresult", FO_UPDATERESULT }
|
||||
};
|
||||
@ -368,11 +509,57 @@ void Template::Format::readFormat(LyXLex & lex)
|
||||
preambleNames.push_back(lex.getString());
|
||||
break;
|
||||
|
||||
case FO_TRANSFORMCOMMAND: {
|
||||
lex.next(true);
|
||||
string const name = lex.getString();
|
||||
lex.next(true);
|
||||
setCommandFactory(*this, name, lex.getString());
|
||||
break;
|
||||
}
|
||||
|
||||
case FO_TRANSFORMOPTION: {
|
||||
lex.next(true);
|
||||
string const name = lex.getString();
|
||||
lex.next(true);
|
||||
setOptionFactory(*this, name, lex.getString());
|
||||
break;
|
||||
}
|
||||
|
||||
case FO_OPTION: {
|
||||
lex.next(true);
|
||||
string const name = lex.getString();
|
||||
lex.next(true);
|
||||
string const opt = lex.getString();
|
||||
options.push_back(Option(name, opt));
|
||||
break;
|
||||
}
|
||||
|
||||
case FO_END:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
TransformIDTranslator const initIDTranslator()
|
||||
{
|
||||
TransformIDTranslator translator(TransformID(-1), "");
|
||||
translator.addPair(Rotate, "Rotate");
|
||||
translator.addPair(Resize, "Resize");
|
||||
translator.addPair(Clip, "Clip");
|
||||
translator.addPair(Extra, "Extra");
|
||||
return translator;
|
||||
}
|
||||
|
||||
|
||||
TransformIDTranslator const & transformIDTranslator()
|
||||
{
|
||||
static TransformIDTranslator const translator = initIDTranslator();
|
||||
return translator;
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
} // namespace external
|
||||
} // namespace lyx
|
||||
|
@ -5,6 +5,7 @@
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Asger Alstrup Nielsen
|
||||
* \author Angus Leeming
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
@ -12,6 +13,8 @@
|
||||
#ifndef EXTERNALTEMPLATE_H
|
||||
#define EXTERNALTEMPLATE_H
|
||||
|
||||
#include "ExternalTransforms.h"
|
||||
|
||||
#include <boost/utility.hpp>
|
||||
|
||||
#include <iosfwd>
|
||||
@ -32,6 +35,13 @@ struct Template {
|
||||
///
|
||||
void dumpFormats(std::ostream &) const;
|
||||
|
||||
struct Option {
|
||||
Option(std::string const & name_, std::string const & opt_)
|
||||
: name(name_), option(opt_) {}
|
||||
std::string name;
|
||||
std::string option;
|
||||
};
|
||||
|
||||
/// What is the name of this template in the LyX format?
|
||||
std::string lyxName;
|
||||
/// What will the button in the GUI say?
|
||||
@ -48,6 +58,8 @@ struct Template {
|
||||
std::string editCommand;
|
||||
/// Should we do automatic production of the output?
|
||||
bool automaticProduction;
|
||||
/// A collection of transforms that we can use to transform the data.
|
||||
std::vector<TransformID> transformIds;
|
||||
|
||||
/// This is the information needed to support a specific output format
|
||||
struct Format {
|
||||
@ -65,6 +77,12 @@ struct Template {
|
||||
std::string requirement;
|
||||
/// A collection of preamble snippets identified by name.
|
||||
std::vector<std::string> preambleNames;
|
||||
/// A list of options to the basic command.
|
||||
std::vector<Option> options;
|
||||
|
||||
/// The factory functions for each supported transformation.
|
||||
std::map<TransformID, TransformStore> command_transformers;
|
||||
std::map<TransformID, TransformStore> option_transformers;
|
||||
};
|
||||
///
|
||||
typedef std::map<std::string, Format> Formats;
|
||||
@ -72,6 +90,7 @@ struct Template {
|
||||
Formats formats;
|
||||
};
|
||||
|
||||
#include "ExternalTransforms.h"
|
||||
|
||||
/**
|
||||
* A singleton class that manages the external inset templates
|
||||
|
416
src/insets/ExternalTransforms.C
Normal file
416
src/insets/ExternalTransforms.C
Normal file
@ -0,0 +1,416 @@
|
||||
/**
|
||||
* \file ExternalTransforms.C
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Angus Leeming
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "ExternalTransforms.h"
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
#include "support/lstrings.h"
|
||||
#include "support/lyxlib.h" // float_equal
|
||||
#include "support/translator.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
#include "support/std_sstream.h"
|
||||
#include <cmath> // std::abs
|
||||
|
||||
using lyx::support::float_equal;
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
namespace lyx {
|
||||
namespace external {
|
||||
|
||||
string const ExtraData::get(string const & id) const
|
||||
{
|
||||
std::map<string, string>::const_iterator it = data_.find(id);
|
||||
return it == data_.end() ? string() : it->second;
|
||||
}
|
||||
|
||||
|
||||
void ExtraData::set(string const & id, string const & data)
|
||||
{
|
||||
data_[id] = data;
|
||||
}
|
||||
|
||||
|
||||
bool ResizeData::no_resize() const
|
||||
{
|
||||
return float_equal(scale, 0.0, 0.05) &&
|
||||
width.zero() && height.zero();
|
||||
}
|
||||
|
||||
|
||||
bool RotationData::no_rotation() const
|
||||
{
|
||||
return (std::abs(angle()) < 0.1);
|
||||
}
|
||||
|
||||
|
||||
void RotationData::angle(double a)
|
||||
{
|
||||
// Ensure that angle_ lies in the range -360 < angle_ < 360.
|
||||
int const multiples = int(a) / 360;
|
||||
angle_ = a - (multiples * 360);
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
typedef Translator<RotationData::OriginType, string> OriginTranslator;
|
||||
OriginTranslator const & originTranslator();
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
void RotationData::origin(string const & o)
|
||||
{
|
||||
origin_ = originTranslator().find(o);
|
||||
}
|
||||
|
||||
|
||||
string const RotationData::originString() const
|
||||
{
|
||||
return originTranslator().find(origin_);
|
||||
}
|
||||
|
||||
|
||||
string const ResizeLatexCommand::front_impl() const
|
||||
{
|
||||
if (data.no_resize())
|
||||
return string();
|
||||
|
||||
std::ostringstream os;
|
||||
if (!float_equal(data.scale, 0.0, 0.05)) {
|
||||
double const scl = data.scale / 100.0;
|
||||
os << "\\scalebox{" << scl << "}{" << scl << "}{";
|
||||
} else {
|
||||
os << "\\resizebox{"
|
||||
<< (data.width.zero() ?
|
||||
"!" : data.width.asLatexString()) << "}{"
|
||||
<< (data.height.zero() ?
|
||||
"!" : data.height.asLatexString()) << "}{";
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
string const ResizeLatexCommand::back_impl() const
|
||||
{
|
||||
if (data.no_resize())
|
||||
return string();
|
||||
|
||||
return "}";
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
std::ostream & operator<<(std::ostream & os, RotationData::OriginType type)
|
||||
{
|
||||
switch (type) {
|
||||
case RotationData::DEFAULT:
|
||||
case RotationData::CENTER:
|
||||
break;
|
||||
case RotationData::TOPLEFT:
|
||||
case RotationData::TOPCENTER:
|
||||
case RotationData::TOPRIGHT:
|
||||
os << 't';
|
||||
break;
|
||||
case RotationData::BOTTOMLEFT:
|
||||
case RotationData::BOTTOMCENTER:
|
||||
case RotationData::BOTTOMRIGHT:
|
||||
os << 'b';
|
||||
break;
|
||||
case RotationData::BASELINELEFT:
|
||||
case RotationData::BASELINECENTER:
|
||||
case RotationData::BASELINERIGHT:
|
||||
os << 'B';
|
||||
break;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case RotationData::DEFAULT:
|
||||
break;
|
||||
case RotationData::TOPLEFT:
|
||||
case RotationData::BOTTOMLEFT:
|
||||
case RotationData::BASELINELEFT:
|
||||
os << 'l';
|
||||
break;
|
||||
case RotationData::CENTER:
|
||||
case RotationData::TOPCENTER:
|
||||
case RotationData::BOTTOMCENTER:
|
||||
case RotationData::BASELINECENTER:
|
||||
os << 'c';
|
||||
break;
|
||||
case RotationData::TOPRIGHT:
|
||||
case RotationData::BOTTOMRIGHT:
|
||||
case RotationData::BASELINERIGHT:
|
||||
os << 'r';
|
||||
break;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
string const RotationLatexCommand::front_impl() const
|
||||
{
|
||||
if (data.no_rotation())
|
||||
return string();
|
||||
|
||||
std::ostringstream os;
|
||||
os << "\\rotatebox";
|
||||
|
||||
if (data.origin() != RotationData::DEFAULT)
|
||||
os << "[origin=" << data.origin() << ']';
|
||||
|
||||
os << '{' << data.angle() << "}{";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
string const RotationLatexCommand::back_impl() const
|
||||
{
|
||||
if (data.no_rotation())
|
||||
return string();
|
||||
|
||||
return "}";
|
||||
}
|
||||
|
||||
|
||||
string const ClipLatexOption::option_impl() const
|
||||
{
|
||||
if (!data.clip || data.bbox.empty())
|
||||
return string();
|
||||
|
||||
std::ostringstream os;
|
||||
if (!data.bbox.empty())
|
||||
os << "bb=" << data.bbox << ',';
|
||||
if (data.clip)
|
||||
os << "clip,";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
string const ResizeLatexOption::option_impl() const
|
||||
{
|
||||
if (data.no_resize())
|
||||
return string();
|
||||
|
||||
std::ostringstream os;
|
||||
if (!float_equal(data.scale, 0.0, 0.05)) {
|
||||
if (!float_equal(data.scale, 100.0, 0.05))
|
||||
os << "scale=" << data.scale / 100.0 << ',';
|
||||
return os.str();
|
||||
}
|
||||
|
||||
if (!data.width.zero())
|
||||
os << "width=" << data.width.asLatexString() << ',';
|
||||
if (!data.height.zero())
|
||||
os << "height=" << data.height.asLatexString() << ',';
|
||||
if (data.keepAspectRatio)
|
||||
os << "keepaspectratio,";
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
string const RotationLatexOption ::option_impl() const
|
||||
{
|
||||
if (data.no_rotation())
|
||||
return string();
|
||||
|
||||
std::ostringstream os;
|
||||
os << "angle=" << data.angle() << ',';
|
||||
|
||||
if (data.origin() != RotationData::DEFAULT)
|
||||
os << "origin=" << data.origin() << ',';
|
||||
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
string const sanitizeDocBookOption(string const & input)
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
string const sanitizeLatexOption(string const & input)
|
||||
{
|
||||
string::const_iterator begin = input.begin();
|
||||
string::const_iterator end = input.end();
|
||||
string::const_iterator it = begin;
|
||||
|
||||
// Strip any leading commas
|
||||
// "[,,,,foo..." -> "foo..."
|
||||
string output;
|
||||
boost::smatch what;
|
||||
boost::regex const front("^( *[[],*)(.*)$");
|
||||
|
||||
regex_match(it, end, what, front, boost::match_partial);
|
||||
if (!what[0].matched) {
|
||||
lyxerr << "Unable to sanitize LaTeX \"Option\": "
|
||||
<< output << '\n';
|
||||
return string();
|
||||
}
|
||||
it = what[1].second;
|
||||
|
||||
// Replace any consecutive commas with a single one
|
||||
// "foo,,,,bar" -> "foo,bar"
|
||||
// with iterator now pointing to 'b'
|
||||
boost::regex const commas("([^,]*)(,,*)(.*)$");
|
||||
for (; it != end;) {
|
||||
regex_match(it, end, what, commas, boost::match_partial);
|
||||
if (!what[0].matched) {
|
||||
output += string(it, end);
|
||||
break;
|
||||
}
|
||||
output += what.str(1) + ",";
|
||||
it = what[3].first;
|
||||
}
|
||||
|
||||
// Strip any trailing commas
|
||||
// "...foo,,,]" -> "...foo"
|
||||
boost::regex const back("^(.*[^,])(,*[]] *)$");
|
||||
regex_match(output, what, back);
|
||||
if (!what[0].matched) {
|
||||
lyxerr << "Unable to sanitize LaTeX \"Option\": "
|
||||
<< output << '\n';
|
||||
return string();
|
||||
}
|
||||
output = what.str(1);
|
||||
|
||||
// Remove any surrounding whitespace
|
||||
output = lyx::support::trim(output);
|
||||
|
||||
// If the thing is empty, leave it so, else wrap it in square brackets.
|
||||
return output.empty() ? output : "[" + output + "]";
|
||||
}
|
||||
|
||||
|
||||
string const sanitizeLinuxDocOption(string const & input)
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename Factory, typename Data, typename Transformer>
|
||||
void extractIt(boost::any const & any_factory,
|
||||
Data const & data, Transformer & transformer)
|
||||
{
|
||||
if (any_factory.type() != typeid(Factory))
|
||||
return;
|
||||
|
||||
Factory factory = boost::any_cast<Factory>(any_factory);
|
||||
if (!factory.empty())
|
||||
transformer = factory(data);
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
TransformCommand::ptr_type
|
||||
TransformStore::getCommandTransformer(RotationData const & data) const
|
||||
{
|
||||
TransformCommand::ptr_type ptr;
|
||||
if (id == Rotate)
|
||||
extractIt<RotationCommandFactory>(any_factory, data, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
TransformCommand::ptr_type
|
||||
TransformStore::getCommandTransformer(ResizeData const & data) const
|
||||
{
|
||||
TransformCommand::ptr_type ptr;
|
||||
if (id == Resize)
|
||||
extractIt<ResizeCommandFactory>(any_factory, data, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
TransformOption::ptr_type
|
||||
TransformStore::getOptionTransformer(RotationData const & data) const
|
||||
{
|
||||
TransformOption::ptr_type ptr;
|
||||
if (id == Rotate)
|
||||
extractIt<RotationOptionFactory>(any_factory, data, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
TransformOption::ptr_type
|
||||
TransformStore::getOptionTransformer(ResizeData const & data) const
|
||||
{
|
||||
TransformOption::ptr_type ptr;
|
||||
if (id == Resize)
|
||||
extractIt<ResizeOptionFactory>(any_factory, data, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
TransformOption::ptr_type
|
||||
TransformStore::getOptionTransformer(ClipData const & data) const
|
||||
{
|
||||
TransformOption::ptr_type ptr;
|
||||
if (id == Clip)
|
||||
extractIt<ClipOptionFactory>(any_factory, data, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TransformOption::ptr_type
|
||||
TransformStore::getOptionTransformer(string const & data) const
|
||||
{
|
||||
TransformOption::ptr_type ptr;
|
||||
if (id == Extra)
|
||||
extractIt<ExtraOptionFactory>(any_factory, data, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
OriginTranslator const initOriginTranslator()
|
||||
{
|
||||
OriginTranslator translator(RotationData::DEFAULT, "default");
|
||||
translator.addPair(RotationData::TOPLEFT, "topleft");
|
||||
translator.addPair(RotationData::BOTTOMLEFT, "bottomleft");
|
||||
translator.addPair(RotationData::BASELINELEFT, "baselineleft");
|
||||
translator.addPair(RotationData::CENTER, "center");
|
||||
translator.addPair(RotationData::TOPCENTER, "topcenter");
|
||||
translator.addPair(RotationData::BOTTOMCENTER, "bottomcenter");
|
||||
translator.addPair(RotationData::BASELINECENTER, "baselinecenter");
|
||||
translator.addPair(RotationData::TOPRIGHT, "topright");
|
||||
translator.addPair(RotationData::BOTTOMRIGHT, "bottomright");
|
||||
translator.addPair(RotationData::BASELINERIGHT, "baselineright");
|
||||
return translator;
|
||||
}
|
||||
|
||||
|
||||
OriginTranslator const & originTranslator()
|
||||
{
|
||||
static OriginTranslator const translator = initOriginTranslator();
|
||||
return translator;
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
} // namespace external
|
||||
} // namespace lyx
|
346
src/insets/ExternalTransforms.h
Normal file
346
src/insets/ExternalTransforms.h
Normal file
@ -0,0 +1,346 @@
|
||||
// -*- C++ -*-
|
||||
/**
|
||||
* \file ExternalTransforms.h
|
||||
* This file is part of LyX, the document processor.
|
||||
* Licence details can be found in the file COPYING.
|
||||
*
|
||||
* \author Angus Leeming
|
||||
*
|
||||
* Full author contact details are available in file CREDITS.
|
||||
*/
|
||||
|
||||
#ifndef EXTERNALTRANSFORMS_H
|
||||
#define EXTERNALTRANSFORMS_H
|
||||
|
||||
#include "lyxlength.h"
|
||||
|
||||
#include "graphics/GraphicsParams.h"
|
||||
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
class LyXLex;
|
||||
|
||||
namespace lyx {
|
||||
namespace external {
|
||||
|
||||
/*
|
||||
* The data containers
|
||||
*/
|
||||
class ClipData {
|
||||
public:
|
||||
ClipData() : clip(false) {}
|
||||
|
||||
lyx::graphics::BoundingBox bbox;
|
||||
bool clip;
|
||||
};
|
||||
|
||||
|
||||
class ExtraData {
|
||||
public:
|
||||
std::string const get(std::string const & id) const;
|
||||
void set(std::string const & id, std::string const & contents);
|
||||
|
||||
typedef std::map<std::string, std::string>::const_iterator const_iterator;
|
||||
const_iterator begin() const { return data_.begin(); }
|
||||
const_iterator end() const { return data_.end(); }
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> data_;
|
||||
};
|
||||
|
||||
|
||||
class ResizeData {
|
||||
public:
|
||||
ResizeData() : scale(0), keepAspectRatio(false) {}
|
||||
bool no_resize() const;
|
||||
|
||||
float scale;
|
||||
LyXLength width;
|
||||
LyXLength height;
|
||||
bool keepAspectRatio;
|
||||
};
|
||||
|
||||
|
||||
class RotationData {
|
||||
public:
|
||||
enum OriginType {
|
||||
DEFAULT,
|
||||
TOPLEFT,
|
||||
BOTTOMLEFT,
|
||||
BASELINELEFT,
|
||||
CENTER,
|
||||
TOPCENTER,
|
||||
BOTTOMCENTER,
|
||||
BASELINECENTER,
|
||||
TOPRIGHT,
|
||||
BOTTOMRIGHT,
|
||||
BASELINERIGHT
|
||||
};
|
||||
|
||||
RotationData() : angle_(0), origin_(DEFAULT) {}
|
||||
bool no_rotation() const;
|
||||
|
||||
void angle(double a);
|
||||
double angle() const { return angle_; }
|
||||
|
||||
void origin(OriginType o) { origin_ = o; }
|
||||
OriginType origin() const { return origin_; }
|
||||
|
||||
void origin(std::string const &);
|
||||
std::string const originString() const;
|
||||
|
||||
private:
|
||||
double angle_;
|
||||
OriginType origin_;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Transformers generating commands
|
||||
*/
|
||||
class TransformCommand {
|
||||
public:
|
||||
typedef std::auto_ptr<TransformCommand const> ptr_type;
|
||||
virtual ~TransformCommand() {}
|
||||
|
||||
/// The string from the External Template that we seek to replace.
|
||||
std::string const front_placeholder() const
|
||||
{ return front_placeholder_impl(); }
|
||||
std::string const back_placeholder() const
|
||||
{ return back_placeholder_impl(); }
|
||||
|
||||
/// The appropriate replacements for the placeholder strings.
|
||||
std::string const front() const { return front_impl(); }
|
||||
std::string const back() const { return back_impl(); }
|
||||
|
||||
private:
|
||||
virtual std::string const front_placeholder_impl() const = 0;
|
||||
virtual std::string const back_placeholder_impl() const = 0;
|
||||
|
||||
virtual std::string const front_impl() const = 0;
|
||||
virtual std::string const back_impl() const = 0;
|
||||
};
|
||||
|
||||
|
||||
class ResizeCommand : public TransformCommand {
|
||||
protected:
|
||||
ResizeData data;
|
||||
ResizeCommand(ResizeData const & data_) : data(data_) {}
|
||||
|
||||
private:
|
||||
virtual std::string const front_placeholder_impl() const
|
||||
{ return "$$ResizeFront"; }
|
||||
virtual std::string const back_placeholder_impl() const
|
||||
{ return "$$ResizeBack"; }
|
||||
};
|
||||
|
||||
|
||||
class ResizeLatexCommand : public ResizeCommand {
|
||||
public:
|
||||
static ptr_type factory(ResizeData const & data)
|
||||
{ return ptr_type(new ResizeLatexCommand(data)); }
|
||||
|
||||
private:
|
||||
ResizeLatexCommand(ResizeData const & data_)
|
||||
: ResizeCommand(data_) {}
|
||||
virtual std::string const front_impl() const;
|
||||
virtual std::string const back_impl() const;
|
||||
};
|
||||
|
||||
|
||||
class RotationCommand : public TransformCommand {
|
||||
protected:
|
||||
RotationData data;
|
||||
RotationCommand(RotationData const & data_) : data(data_) {}
|
||||
|
||||
private:
|
||||
virtual std::string const front_placeholder_impl() const
|
||||
{ return "$$RotateFront"; }
|
||||
virtual std::string const back_placeholder_impl() const
|
||||
{ return "$$RotateBack"; }
|
||||
};
|
||||
|
||||
|
||||
class RotationLatexCommand : public RotationCommand {
|
||||
public:
|
||||
static ptr_type factory(RotationData const & data)
|
||||
{ return ptr_type(new RotationLatexCommand(data)); }
|
||||
|
||||
private:
|
||||
RotationLatexCommand(RotationData const & data_)
|
||||
: RotationCommand(data_) {}
|
||||
virtual std::string const front_impl() const;
|
||||
virtual std::string const back_impl() const;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Transformers generating options
|
||||
*/
|
||||
class TransformOption {
|
||||
public:
|
||||
typedef std::auto_ptr<TransformOption const> ptr_type;
|
||||
virtual ~TransformOption() {}
|
||||
|
||||
/// The string from the External Template that we seek to replace.
|
||||
std::string const placeholder() const { return placeholder_impl(); }
|
||||
|
||||
/// The appropriate replacement for the placeholder string.
|
||||
std::string const option() const { return option_impl(); }
|
||||
|
||||
private:
|
||||
virtual std::string const placeholder_impl() const = 0;
|
||||
virtual std::string const option_impl() const = 0;
|
||||
};
|
||||
|
||||
|
||||
class ClipOption : public TransformOption {
|
||||
protected:
|
||||
ClipData data;
|
||||
ClipOption(ClipData const & data_) : data(data_) {}
|
||||
|
||||
private:
|
||||
virtual std::string const placeholder_impl() const
|
||||
{ return "$$Clip"; }
|
||||
};
|
||||
|
||||
|
||||
class ClipLatexOption : public ClipOption {
|
||||
public:
|
||||
static ptr_type factory(ClipData const & data)
|
||||
{ return ptr_type(new ClipLatexOption(data)); }
|
||||
|
||||
private:
|
||||
ClipLatexOption(ClipData const & data_)
|
||||
: ClipOption(data_) {}
|
||||
virtual std::string const option_impl() const;
|
||||
};
|
||||
|
||||
|
||||
class ExtraOption : public TransformOption {
|
||||
public:
|
||||
static ptr_type factory(std::string const & data)
|
||||
{ return ptr_type(new ExtraOption(data)); }
|
||||
|
||||
private:
|
||||
ExtraOption(std::string const & data_) : data(data_) {}
|
||||
|
||||
virtual std::string const placeholder_impl() const
|
||||
{ return "$$Extra"; }
|
||||
virtual std::string const option_impl() const
|
||||
{ return data; }
|
||||
std::string data;
|
||||
};
|
||||
|
||||
|
||||
class ResizeOption : public TransformOption {
|
||||
protected:
|
||||
ResizeData data;
|
||||
ResizeOption(ResizeData const & data_) : data(data_) {}
|
||||
|
||||
private:
|
||||
virtual std::string const placeholder_impl() const
|
||||
{ return "$$Resize"; }
|
||||
};
|
||||
|
||||
|
||||
class ResizeLatexOption : public ResizeOption {
|
||||
public:
|
||||
static ptr_type factory(ResizeData const & data)
|
||||
{ return ptr_type(new ResizeLatexOption(data)); }
|
||||
|
||||
private:
|
||||
ResizeLatexOption(ResizeData const & data_)
|
||||
: ResizeOption(data_) {}
|
||||
virtual std::string const option_impl() const;
|
||||
};
|
||||
|
||||
|
||||
class RotationOption : public TransformOption {
|
||||
protected:
|
||||
RotationData data;
|
||||
RotationOption(RotationData const & data_) : data(data_) {}
|
||||
|
||||
private:
|
||||
virtual std::string const placeholder_impl() const
|
||||
{ return "$$Rotate"; }
|
||||
};
|
||||
|
||||
|
||||
class RotationLatexOption : public RotationOption {
|
||||
public:
|
||||
static ptr_type factory(RotationData const & data)
|
||||
{ return ptr_type(new RotationLatexOption(data)); }
|
||||
|
||||
private:
|
||||
RotationLatexOption(RotationData const & data_)
|
||||
: RotationOption(data_) {}
|
||||
virtual std::string const option_impl() const;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Option sanitizers
|
||||
*/
|
||||
std::string const sanitizeLatexOption(std::string const & input);
|
||||
std::string const sanitizeDocBookOption(std::string const & input);
|
||||
std::string const sanitizeLinuxDocOption(std::string const & input);
|
||||
|
||||
|
||||
enum TransformID {
|
||||
Rotate,
|
||||
Resize,
|
||||
Clip,
|
||||
Extra
|
||||
};
|
||||
|
||||
|
||||
typedef boost::function1<TransformOption::ptr_type, ClipData>
|
||||
ClipOptionFactory;
|
||||
typedef boost::function1<TransformOption::ptr_type, std::string>
|
||||
ExtraOptionFactory;
|
||||
typedef boost::function1<TransformOption::ptr_type, ResizeData>
|
||||
ResizeOptionFactory;
|
||||
typedef boost::function1<TransformOption::ptr_type, RotationData>
|
||||
RotationOptionFactory;
|
||||
typedef boost::function1<TransformCommand::ptr_type, ResizeData>
|
||||
ResizeCommandFactory;
|
||||
typedef boost::function1<TransformCommand::ptr_type, RotationData>
|
||||
RotationCommandFactory;
|
||||
|
||||
|
||||
struct TransformStore
|
||||
{
|
||||
TransformStore() {}
|
||||
|
||||
/** Stores \c factory and a reminder of what \c data this \c factory
|
||||
* operates on.
|
||||
*/
|
||||
template <typename Factory>
|
||||
TransformStore(TransformID id_, Factory const & factory)
|
||||
: id(id_), any_factory(boost::any(factory)) {}
|
||||
|
||||
typedef TransformCommand::ptr_type ComPtr;
|
||||
typedef TransformOption::ptr_type OptPtr;
|
||||
|
||||
ComPtr getCommandTransformer(RotationData const &) const;
|
||||
ComPtr getCommandTransformer(ResizeData const &) const;
|
||||
OptPtr getOptionTransformer(RotationData const &) const;
|
||||
OptPtr getOptionTransformer(ResizeData const &) const;
|
||||
OptPtr getOptionTransformer(ClipData const &) const;
|
||||
OptPtr getOptionTransformer(std::string const &) const;
|
||||
|
||||
private:
|
||||
TransformID id;
|
||||
boost::any any_factory;
|
||||
};
|
||||
|
||||
} // namespace external
|
||||
} // namespace lyx
|
||||
|
||||
#endif // NOT EXTERNALTRANSFORMS_H
|
@ -17,6 +17,8 @@ libinsets_la_SOURCES = \
|
||||
ExternalSupport.h \
|
||||
ExternalTemplate.C \
|
||||
ExternalTemplate.h \
|
||||
ExternalTransforms.C \
|
||||
ExternalTransforms.h \
|
||||
renderers.C \
|
||||
renderers.h \
|
||||
inset.C \
|
||||
|
@ -109,9 +109,43 @@ InsetExternalParams::InsetExternalParams()
|
||||
{}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename T>
|
||||
void clearIfNotFound(T & data, external::TransformID value,
|
||||
vector<external::TransformID> const & ids)
|
||||
{
|
||||
typedef vector<external::TransformID>::const_iterator
|
||||
const_iterator;
|
||||
|
||||
const_iterator it = ids.begin();
|
||||
const_iterator end = ids.end();
|
||||
it = std::find(it, end, value);
|
||||
if (it == end)
|
||||
data = T();
|
||||
}
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
||||
void InsetExternalParams::settemplate(string const & name)
|
||||
{
|
||||
templatename_ = name;
|
||||
|
||||
external::TemplateManager const & etm =
|
||||
external::TemplateManager::get();
|
||||
external::Template const * const et = etm.getTemplateByName(name);
|
||||
if (!et)
|
||||
// Be safe. Don't lose data.
|
||||
return;
|
||||
|
||||
// Ascertain which transforms the template supports.
|
||||
// Empty all those that it doesn't.
|
||||
vector<external::TransformID> const & ids = et->transformIds;
|
||||
clearIfNotFound(clipdata, external::Clip, ids);
|
||||
clearIfNotFound(extradata, external::Extra, ids);
|
||||
clearIfNotFound(resizedata, external::Resize, ids);
|
||||
clearIfNotFound(rotationdata, external::Rotate, ids);
|
||||
}
|
||||
|
||||
|
||||
@ -132,6 +166,45 @@ void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
|
||||
|
||||
if (lyxscale != defaultLyxScale)
|
||||
os << "\tlyxscale " << tostr(lyxscale) << '\n';
|
||||
|
||||
if (!clipdata.bbox.empty())
|
||||
os << "\tboundingBox " << clipdata.bbox << '\n';
|
||||
if (clipdata.clip)
|
||||
os << "\tclip\n";
|
||||
|
||||
external::ExtraData::const_iterator it = extradata.begin();
|
||||
external::ExtraData::const_iterator end = extradata.end();
|
||||
for (; it != end; ++it) {
|
||||
if (!it->second.empty())
|
||||
os << "\textra " << it->first << " \""
|
||||
<< it->second << "\"\n";
|
||||
}
|
||||
|
||||
if (!rotationdata.no_rotation()) {
|
||||
os << "\trotateAngle " << rotationdata.angle() << '\n';
|
||||
if (rotationdata.origin() != external::RotationData::DEFAULT)
|
||||
os << "\trotateOrigin "
|
||||
<< rotationdata.originString() << '\n';
|
||||
}
|
||||
|
||||
if (!resizedata.no_resize()) {
|
||||
using support::float_equal;
|
||||
|
||||
if (!float_equal(resizedata.scale, 0.0, 0.05)) {
|
||||
if (!float_equal(resizedata.scale, 100.0, 0.05))
|
||||
os << "\tscale "
|
||||
<< resizedata.scale << '\n';
|
||||
} else {
|
||||
if (!resizedata.width.zero())
|
||||
os << "\twidth "
|
||||
<< resizedata.width.asString() << '\n';
|
||||
if (!resizedata.height.zero())
|
||||
os << "\theight "
|
||||
<< resizedata.height.asString() << '\n';
|
||||
}
|
||||
if (resizedata.keepAspectRatio)
|
||||
os << "\tkeepAspectRatio\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -142,15 +215,33 @@ bool InsetExternalParams::read(Buffer const & buffer, LyXLex & lex)
|
||||
EX_FILENAME,
|
||||
EX_DISPLAY,
|
||||
EX_LYXSCALE,
|
||||
EX_BOUNDINGBOX,
|
||||
EX_CLIP,
|
||||
EX_EXTRA,
|
||||
EX_HEIGHT,
|
||||
EX_KEEPASPECTRATIO,
|
||||
EX_ROTATEANGLE,
|
||||
EX_ROTATEORIGIN,
|
||||
EX_SCALE,
|
||||
EX_WIDTH,
|
||||
EX_END
|
||||
};
|
||||
|
||||
keyword_item external_tags[] = {
|
||||
{ "\\end_inset", EX_END },
|
||||
{ "boundingBox", EX_BOUNDINGBOX },
|
||||
{ "clip", EX_CLIP },
|
||||
{ "display", EX_DISPLAY},
|
||||
{ "extra", EX_EXTRA },
|
||||
{ "filename", EX_FILENAME},
|
||||
{ "height", EX_HEIGHT },
|
||||
{ "keepAspectRatio", EX_KEEPASPECTRATIO },
|
||||
{ "lyxscale", EX_LYXSCALE},
|
||||
{ "template", EX_TEMPLATE }
|
||||
{ "rotateAngle", EX_ROTATEANGLE },
|
||||
{ "rotateOrigin", EX_ROTATEORIGIN },
|
||||
{ "scale", EX_SCALE },
|
||||
{ "template", EX_TEMPLATE },
|
||||
{ "width", EX_WIDTH }
|
||||
};
|
||||
|
||||
pushpophelper pph(lex, external_tags, EX_END);
|
||||
@ -184,6 +275,58 @@ bool InsetExternalParams::read(Buffer const & buffer, LyXLex & lex)
|
||||
lyxscale = lex.getInteger();
|
||||
break;
|
||||
|
||||
case EX_BOUNDINGBOX:
|
||||
lex.next();
|
||||
clipdata.bbox.xl = lex.getInteger();
|
||||
lex.next();
|
||||
clipdata.bbox.yb = lex.getInteger();
|
||||
lex.next();
|
||||
clipdata.bbox.xr = lex.getInteger();
|
||||
lex.next();
|
||||
clipdata.bbox.yt = lex.getInteger();
|
||||
break;
|
||||
|
||||
case EX_CLIP:
|
||||
clipdata.clip = true;
|
||||
break;
|
||||
|
||||
case EX_EXTRA: {
|
||||
lex.next();
|
||||
string const name = lex.getString();
|
||||
lex.next();
|
||||
extradata.set(name, lex.getString());
|
||||
break;
|
||||
}
|
||||
|
||||
case EX_HEIGHT:
|
||||
lex.next();
|
||||
resizedata.height = LyXLength(lex.getString());
|
||||
break;
|
||||
|
||||
case EX_KEEPASPECTRATIO:
|
||||
resizedata.keepAspectRatio = true;
|
||||
break;
|
||||
|
||||
case EX_ROTATEANGLE:
|
||||
lex.next();
|
||||
rotationdata.angle(lex.getFloat());
|
||||
break;
|
||||
|
||||
case EX_ROTATEORIGIN:
|
||||
lex.next();
|
||||
rotationdata.origin(lex.getString());
|
||||
break;
|
||||
|
||||
case EX_SCALE:
|
||||
lex.next();
|
||||
resizedata.scale = lex.getFloat();
|
||||
break;
|
||||
|
||||
case EX_WIDTH:
|
||||
lex.next();
|
||||
resizedata.width = LyXLength(lex.getString());
|
||||
break;
|
||||
|
||||
case EX_END:
|
||||
found_end = true;
|
||||
break;
|
||||
@ -313,6 +456,9 @@ lyx::graphics::Params get_grfx_params(InsetExternalParams const & eparams)
|
||||
|
||||
gparams.filename = eparams.filename.absFilename();
|
||||
gparams.scale = eparams.lyxscale;
|
||||
if (eparams.clipdata.clip)
|
||||
gparams.bb = eparams.clipdata.bbox;
|
||||
gparams.angle = eparams.rotationdata.angle();
|
||||
|
||||
gparams.display = eparams.display;
|
||||
if (gparams.display == lyx::graphics::DefaultDisplay)
|
||||
|
@ -13,6 +13,7 @@
|
||||
#define INSET_EXTERNAL_H
|
||||
|
||||
#include "inset.h"
|
||||
#include "ExternalTransforms.h"
|
||||
|
||||
#include "graphics/GraphicsTypes.h"
|
||||
|
||||
@ -67,6 +68,11 @@ struct InsetExternalParams {
|
||||
/// The scale of the displayed graphic (if shown).
|
||||
unsigned int lyxscale;
|
||||
|
||||
lyx::external::ClipData clipdata;
|
||||
lyx::external::ExtraData extradata;
|
||||
lyx::external::ResizeData resizedata;
|
||||
lyx::external::RotationData rotationdata;
|
||||
|
||||
private:
|
||||
lyx::external::TempName tempname_;
|
||||
std::string templatename_;
|
||||
|
Loading…
Reference in New Issue
Block a user