2003-10-07 22:59:58 +00:00
|
|
|
// -*- 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 "graphics/GraphicsParams.h"
|
|
|
|
|
2020-11-21 14:27:13 +00:00
|
|
|
#include "support/any.h"
|
2020-08-03 12:15:09 +00:00
|
|
|
#include "support/Length.h"
|
2016-06-02 20:58:52 +00:00
|
|
|
#include "support/unique_ptr.h"
|
|
|
|
|
2016-06-29 09:22:13 +00:00
|
|
|
#include <functional>
|
2003-10-07 22:59:58 +00:00
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
2016-06-29 09:22:13 +00:00
|
|
|
#include <string>
|
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
namespace external {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The data containers
|
|
|
|
*/
|
|
|
|
class ClipData {
|
|
|
|
public:
|
|
|
|
ClipData() : clip(false) {}
|
|
|
|
|
2015-07-16 20:04:08 +00:00
|
|
|
/// The bounding box
|
2006-10-21 00:16:43 +00:00
|
|
|
graphics::BoundingBox bbox;
|
2015-07-16 20:04:08 +00:00
|
|
|
/// clip image
|
2003-10-07 22:59:58 +00:00
|
|
|
bool clip;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ExtraData {
|
|
|
|
public:
|
|
|
|
std::string const get(std::string const & id) const;
|
2020-10-31 17:18:51 +00:00
|
|
|
void set(std::string const & id, std::string const & data);
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
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:
|
2005-01-04 10:59:49 +00:00
|
|
|
ResizeData() : scale(), keepAspectRatio(false) {}
|
2003-10-07 22:59:58 +00:00
|
|
|
bool no_resize() const;
|
|
|
|
|
2003-12-04 16:53:53 +00:00
|
|
|
bool usingScale() const;
|
|
|
|
|
2005-01-04 10:59:49 +00:00
|
|
|
std::string scale;
|
2007-04-28 12:58:49 +00:00
|
|
|
Length width;
|
|
|
|
Length height;
|
2003-10-07 22:59:58 +00:00
|
|
|
bool keepAspectRatio;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RotationData {
|
|
|
|
public:
|
|
|
|
enum OriginType {
|
|
|
|
DEFAULT,
|
|
|
|
TOPLEFT,
|
|
|
|
BOTTOMLEFT,
|
|
|
|
BASELINELEFT,
|
|
|
|
CENTER,
|
|
|
|
TOPCENTER,
|
|
|
|
BOTTOMCENTER,
|
|
|
|
BASELINECENTER,
|
|
|
|
TOPRIGHT,
|
|
|
|
BOTTOMRIGHT,
|
|
|
|
BASELINERIGHT
|
|
|
|
};
|
|
|
|
|
2005-01-04 10:59:49 +00:00
|
|
|
RotationData() : angle("0"), origin_(DEFAULT) {}
|
2003-10-07 22:59:58 +00:00
|
|
|
bool no_rotation() const;
|
|
|
|
|
2005-01-04 10:59:49 +00:00
|
|
|
std::string const adjAngle() const;
|
|
|
|
std::string angle;
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
void origin(OriginType o) { origin_ = o; }
|
|
|
|
OriginType origin() const { return origin_; }
|
|
|
|
|
|
|
|
void origin(std::string const &);
|
|
|
|
std::string const originString() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
OriginType origin_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-12-04 16:53:53 +00:00
|
|
|
/** \c RotationDataType is a wrapper for RotationData::OriginType
|
|
|
|
* It can be forward-declared and passed as a function argument without
|
|
|
|
* having to expose this header file.
|
|
|
|
*/
|
|
|
|
class RotationDataType {
|
|
|
|
RotationData::OriginType val_;
|
|
|
|
public:
|
|
|
|
RotationDataType(RotationData::OriginType val) : val_(val) {}
|
|
|
|
operator RotationData::OriginType() const { return val_; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-10-07 22:59:58 +00:00
|
|
|
/*
|
|
|
|
* Transformers generating commands
|
|
|
|
*/
|
|
|
|
class TransformCommand {
|
|
|
|
public:
|
2016-06-02 20:58:52 +00:00
|
|
|
typedef unique_ptr<TransformCommand const> ptr_type;
|
2003-10-07 22:59:58 +00:00
|
|
|
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;
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit ResizeCommand(ResizeData const & data_) : data(data_) {}
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const front_placeholder_impl() const override
|
2003-10-07 22:59:58 +00:00
|
|
|
{ return "$$ResizeFront"; }
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const back_placeholder_impl() const override
|
2003-10-07 22:59:58 +00:00
|
|
|
{ return "$$ResizeBack"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ResizeLatexCommand : public ResizeCommand {
|
|
|
|
public:
|
|
|
|
static ptr_type factory(ResizeData const & data)
|
|
|
|
{ return ptr_type(new ResizeLatexCommand(data)); }
|
|
|
|
|
|
|
|
private:
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit ResizeLatexCommand(ResizeData const & data_)
|
2003-10-07 22:59:58 +00:00
|
|
|
: ResizeCommand(data_) {}
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const front_impl() const override;
|
|
|
|
std::string const back_impl() const override;
|
2003-10-07 22:59:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RotationCommand : public TransformCommand {
|
|
|
|
protected:
|
|
|
|
RotationData data;
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit RotationCommand(RotationData const & data_) : data(data_) {}
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const front_placeholder_impl() const override
|
2003-10-07 22:59:58 +00:00
|
|
|
{ return "$$RotateFront"; }
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const back_placeholder_impl() const override
|
2003-10-07 22:59:58 +00:00
|
|
|
{ return "$$RotateBack"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RotationLatexCommand : public RotationCommand {
|
|
|
|
public:
|
|
|
|
static ptr_type factory(RotationData const & data)
|
|
|
|
{ return ptr_type(new RotationLatexCommand(data)); }
|
|
|
|
|
|
|
|
private:
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit RotationLatexCommand(RotationData const & data_)
|
2003-10-07 22:59:58 +00:00
|
|
|
: RotationCommand(data_) {}
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const front_impl() const override;
|
|
|
|
std::string const back_impl() const override;
|
2003-10-07 22:59:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Transformers generating options
|
|
|
|
*/
|
|
|
|
class TransformOption {
|
|
|
|
public:
|
2016-06-02 20:58:52 +00:00
|
|
|
typedef unique_ptr<TransformOption const> ptr_type;
|
2003-10-07 22:59:58 +00:00
|
|
|
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;
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit ClipOption(ClipData const & data_) : data(data_) {}
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const placeholder_impl() const override
|
2003-10-07 22:59:58 +00:00
|
|
|
{ return "$$Clip"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ClipLatexOption : public ClipOption {
|
|
|
|
public:
|
|
|
|
static ptr_type factory(ClipData const & data)
|
|
|
|
{ return ptr_type(new ClipLatexOption(data)); }
|
|
|
|
|
|
|
|
private:
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit ClipLatexOption(ClipData const & data_)
|
2003-10-07 22:59:58 +00:00
|
|
|
: ClipOption(data_) {}
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const option_impl() const override;
|
2003-10-07 22:59:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ExtraOption : public TransformOption {
|
|
|
|
public:
|
|
|
|
static ptr_type factory(std::string const & data)
|
|
|
|
{ return ptr_type(new ExtraOption(data)); }
|
|
|
|
|
|
|
|
private:
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit ExtraOption(std::string const & data_) : data(data_) {}
|
2003-10-07 22:59:58 +00:00
|
|
|
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const placeholder_impl() const override
|
2003-10-07 22:59:58 +00:00
|
|
|
{ return "$$Extra"; }
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const option_impl() const override
|
2003-10-07 22:59:58 +00:00
|
|
|
{ return data; }
|
|
|
|
std::string data;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ResizeOption : public TransformOption {
|
|
|
|
protected:
|
|
|
|
ResizeData data;
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit ResizeOption(ResizeData const & data_) : data(data_) {}
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const placeholder_impl() const override
|
2003-10-07 22:59:58 +00:00
|
|
|
{ return "$$Resize"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ResizeLatexOption : public ResizeOption {
|
|
|
|
public:
|
|
|
|
static ptr_type factory(ResizeData const & data)
|
|
|
|
{ return ptr_type(new ResizeLatexOption(data)); }
|
|
|
|
|
|
|
|
private:
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit ResizeLatexOption(ResizeData const & data_)
|
2003-10-07 22:59:58 +00:00
|
|
|
: ResizeOption(data_) {}
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const option_impl() const override;
|
2003-10-07 22:59:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RotationOption : public TransformOption {
|
|
|
|
protected:
|
|
|
|
RotationData data;
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit RotationOption(RotationData const & data_) : data(data_) {}
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const placeholder_impl() const override
|
2003-10-07 22:59:58 +00:00
|
|
|
{ return "$$Rotate"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RotationLatexOption : public RotationOption {
|
|
|
|
public:
|
|
|
|
static ptr_type factory(RotationData const & data)
|
|
|
|
{ return ptr_type(new RotationLatexOption(data)); }
|
|
|
|
|
|
|
|
private:
|
2019-09-17 21:06:18 +00:00
|
|
|
explicit RotationLatexOption(RotationData const & data_)
|
2003-10-07 22:59:58 +00:00
|
|
|
: RotationOption(data_) {}
|
2020-10-01 07:42:11 +00:00
|
|
|
std::string const option_impl() const override;
|
2003-10-07 22:59:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Option sanitizers
|
|
|
|
*/
|
|
|
|
std::string const sanitizeLatexOption(std::string const & input);
|
|
|
|
std::string const sanitizeDocBookOption(std::string const & input);
|
|
|
|
|
|
|
|
|
|
|
|
enum TransformID {
|
2020-11-24 18:46:49 +00:00
|
|
|
None = -1,
|
2003-10-07 22:59:58 +00:00
|
|
|
Rotate,
|
|
|
|
Resize,
|
|
|
|
Clip,
|
|
|
|
Extra
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-06-29 09:22:13 +00:00
|
|
|
typedef std::function<TransformOption::ptr_type(ClipData)>
|
2003-10-07 22:59:58 +00:00
|
|
|
ClipOptionFactory;
|
2016-06-29 09:22:13 +00:00
|
|
|
typedef std::function<TransformOption::ptr_type(std::string)>
|
2003-10-07 22:59:58 +00:00
|
|
|
ExtraOptionFactory;
|
2016-06-29 09:22:13 +00:00
|
|
|
typedef std::function<TransformOption::ptr_type(ResizeData)>
|
2003-10-07 22:59:58 +00:00
|
|
|
ResizeOptionFactory;
|
2016-06-29 09:22:13 +00:00
|
|
|
typedef std::function<TransformOption::ptr_type(RotationData)>
|
2003-10-07 22:59:58 +00:00
|
|
|
RotationOptionFactory;
|
2016-06-29 09:22:13 +00:00
|
|
|
typedef std::function<TransformCommand::ptr_type(ResizeData)>
|
2003-10-07 22:59:58 +00:00
|
|
|
ResizeCommandFactory;
|
2016-06-29 09:22:13 +00:00
|
|
|
typedef std::function<TransformCommand::ptr_type(RotationData)>
|
2003-10-07 22:59:58 +00:00
|
|
|
RotationCommandFactory;
|
|
|
|
|
|
|
|
|
2005-01-19 15:03:31 +00:00
|
|
|
class TransformStore
|
2003-10-07 22:59:58 +00:00
|
|
|
{
|
2005-01-19 15:03:31 +00:00
|
|
|
public:
|
2016-06-12 03:39:45 +00:00
|
|
|
TransformStore() : id(Rotate) {}
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
/** Stores \c factory and a reminder of what \c data this \c factory
|
|
|
|
* operates on.
|
|
|
|
*/
|
|
|
|
template <typename Factory>
|
|
|
|
TransformStore(TransformID id_, Factory const & factory)
|
2020-11-21 14:27:13 +00:00
|
|
|
: id(id_), any_factory(any(factory)) {}
|
2003-10-07 22:59:58 +00:00
|
|
|
|
|
|
|
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;
|
2020-11-21 14:27:13 +00:00
|
|
|
any any_factory;
|
2003-10-07 22:59:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace external
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // NOT EXTERNALTRANSFORMS_H
|