[DEV] add dimention and linear gradient parsing

This commit is contained in:
Edouard DUPIN 2015-12-04 23:06:38 +01:00
parent aa6e69c7e7
commit d3162ad4c3
15 changed files with 816 additions and 15 deletions

View File

@ -186,7 +186,7 @@ float esvg::Base::parseLength(const std::string& _dataInput) {
}
// return the next char position ... (after ';' or NULL)
int32_t extractPartOfStyle(const std::string& _data, std::string& _outputType, std::string& _outputData, int32_t _pos) {
int32_t esvg::extractPartOfStyle(const std::string& _data, std::string& _outputType, std::string& _outputData, int32_t _pos) {
_outputType = "";
_outputData = "";
if (_pos == -1) {

View File

@ -50,6 +50,8 @@ namespace esvg {
float opacity;
};
int32_t extractPartOfStyle(const std::string& _data, std::string& _outputType, std::string& _outputData, int32_t _pos);
class Base {
protected:
PaintState m_paint;

316
esvg/Dimension.cpp Normal file
View File

@ -0,0 +1,316 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <gale/Dimension.h>
#include <gale/debug.h>
#undef __class__
#define __class__ "Dimension"
// TODO : set this in a super class acced in a statin fuction...
// ratio in milimeter :
static bool isInit = false;
static vec2 ratio(9999999,888888);
static vec2 invRatio(1,1);
static gale::Dimension windowsSize(vec2(9999999,888888), gale::Dimension::Pixel);
static const float inchToMillimeter = 1.0f/25.4f;
static const float footToMillimeter = 1.0f/304.8f;
static const float meterToMillimeter = 1.0f/1000.0f;
static const float centimeterToMillimeter = 1.0f/10.0f;
static const float kilometerToMillimeter = 1.0f/1000000.0f;
static const float millimeterToInch = 25.4f;
static const float millimeterToFoot = 304.8f;
static const float millimeterToMeter =1000.0f;
static const float millimeterToCentimeter = 10.0f;
static const float millimeterToKilometer = 1000000.0f;
void gale::Dimension::init() {
if (true == isInit) {
return;
}
gale::Dimension conversion(vec2(72,72), gale::Dimension::Inch);
ratio = conversion.getMillimeter();
invRatio.setValue(1.0f/ratio.x(),1.0f/ratio.y());
windowsSize.set(vec2(200,200), gale::Dimension::Pixel);
isInit = true;
}
void gale::Dimension::unInit() {
isInit = false;
ratio.setValue(9999999,888888);
invRatio.setValue(1.0f/ratio.x(),1.0f/ratio.y());
windowsSize.set(vec2(9999999,88888), gale::Dimension::Pixel);
}
void gale::Dimension::setPixelRatio(const vec2& _ratio, enum gale::Dimension::distance _type) {
gale::Dimension::init();
GALE_INFO("Set a new screen ratio for the screen : ratio=" << _ratio << " type=" << _type);
gale::Dimension conversion(_ratio, _type);
GALE_INFO(" == > " << conversion);
ratio = conversion.getMillimeter();
invRatio.setValue(1.0f/ratio.x(),1.0f/ratio.y());
GALE_INFO("Set a new screen ratio for the screen : ratioMm=" << ratio);
}
void gale::Dimension::setPixelWindowsSize(const vec2& _size) {
windowsSize = _size;
GALE_VERBOSE("Set a new Windows property size " << windowsSize << "px");
}
vec2 gale::Dimension::getWindowsSize(enum gale::Dimension::distance _type) {
return windowsSize.get(_type);
}
float gale::Dimension::getWindowsDiag(enum gale::Dimension::distance _type) {
vec2 size = gale::Dimension::getWindowsSize(_type);
return size.length();
}
gale::Dimension::Dimension() :
m_data(0,0),
m_type(gale::Dimension::Pixel) {
// notinh to do ...
}
gale::Dimension::Dimension(const vec2& _size, enum gale::Dimension::distance _type) :
m_data(0,0),
m_type(gale::Dimension::Pixel) {
set(_size, _type);
}
void gale::Dimension::set(std::string _config) {
m_data.setValue(0,0);
m_type = gale::Dimension::Pixel;
enum distance type = gale::Dimension::Pixel;
if (etk::end_with(_config, "%", false) == true) {
type = gale::Dimension::Pourcent;
_config.erase(_config.size()-1, 1);
} else if (etk::end_with(_config, "px",false) == true) {
type = gale::Dimension::Pixel;
_config.erase(_config.size()-2, 2);
} else if (etk::end_with(_config, "ft",false) == true) {
type = gale::Dimension::foot;
_config.erase(_config.size()-2, 2);
} else if (etk::end_with(_config, "in",false) == true) {
type = gale::Dimension::Inch;
_config.erase(_config.size()-2, 2);
} else if (etk::end_with(_config, "km",false) == true) {
type = gale::Dimension::Kilometer;
_config.erase(_config.size()-2, 2);
} else if (etk::end_with(_config, "mm",false) == true) {
type = gale::Dimension::Millimeter;
_config.erase(_config.size()-2, 2);
} else if (etk::end_with(_config, "cm",false) == true) {
type = gale::Dimension::Centimeter;
_config.erase(_config.size()-2, 2);
} else if (etk::end_with(_config, "m",false) == true) {
type = gale::Dimension::Meter;
_config.erase(_config.size()-1, 1);
} else {
GALE_CRITICAL("Can not parse dimention : \"" << _config << "\"");
return;
}
vec2 tmp = _config;
set(tmp, type);
GALE_VERBOSE(" config dimention : \"" << _config << "\" == > " << *this );
}
gale::Dimension::~Dimension() {
// nothing to do ...
}
gale::Dimension::operator std::string() const {
std::string str;
str = get(getType());
switch(getType()) {
case gale::Dimension::Pourcent:
str += "%";
break;
case gale::Dimension::Pixel:
str += "px";
break;
case gale::Dimension::Meter:
str += "m";
break;
case gale::Dimension::Centimeter:
str += "cm";
break;
case gale::Dimension::Millimeter:
str += "mm";
break;
case gale::Dimension::Kilometer:
str += "km";
break;
case gale::Dimension::Inch:
str += "in";
break;
case gale::Dimension::foot:
str += "ft";
break;
}
return str;
}
vec2 gale::Dimension::get(enum gale::Dimension::distance _type) const {
switch(_type) {
case gale::Dimension::Pourcent:
return getPourcent();
case gale::Dimension::Pixel:
return getPixel();
case gale::Dimension::Meter:
return getMeter();
case gale::Dimension::Centimeter:
return getCentimeter();
case gale::Dimension::Millimeter:
return getMillimeter();
case gale::Dimension::Kilometer:
return getKilometer();
case gale::Dimension::Inch:
return getInch();
case gale::Dimension::foot:
return getFoot();
}
return vec2(0,0);
}
void gale::Dimension::set(const vec2& _size, enum gale::Dimension::distance _type) {
// set min max on input to limit error :
vec2 size(std::avg(0.0f,_size.x(),9999999.0f),
std::avg(0.0f,_size.y(),9999999.0f));
switch(_type) {
case gale::Dimension::Pourcent: {
vec2 size2(std::avg(0.0f,_size.x(),100.0f),
std::avg(0.0f,_size.y(),100.0f));
m_data = vec2(size2.x()*0.01f, size2.y()*0.01f);
//GALE_VERBOSE("Set % : " << size2 << " == > " << m_data);
break;
}
case gale::Dimension::Pixel:
m_data = size;
break;
case gale::Dimension::Meter:
m_data = vec2(size.x()*meterToMillimeter*ratio.x(), size.y()*meterToMillimeter*ratio.y());
break;
case gale::Dimension::Centimeter:
m_data = vec2(size.x()*centimeterToMillimeter*ratio.x(), size.y()*centimeterToMillimeter*ratio.y());
break;
case gale::Dimension::Millimeter:
m_data = vec2(size.x()*ratio.x(), size.y()*ratio.y());
break;
case gale::Dimension::Kilometer:
m_data = vec2(size.x()*kilometerToMillimeter*ratio.x(), size.y()*kilometerToMillimeter*ratio.y());
break;
case gale::Dimension::Inch:
m_data = vec2(size.x()*inchToMillimeter*ratio.x(), size.y()*inchToMillimeter*ratio.y());
break;
case gale::Dimension::foot:
m_data = vec2(size.x()*footToMillimeter*ratio.x(), size.y()*footToMillimeter*ratio.y());
break;
}
m_type = _type;
}
vec2 gale::Dimension::getPixel() const {
if (m_type!=gale::Dimension::Pourcent) {
return m_data;
} else {
vec2 windDim = windowsSize.getPixel();
vec2 res = vec2(windDim.x()*m_data.x(), windDim.y()*m_data.y());
//GALE_DEBUG("Get % : " << m_data << " / " << windDim << " == > " << res);
return res;
}
}
vec2 gale::Dimension::getPourcent() const {
if (m_type!=gale::Dimension::Pourcent) {
vec2 windDim = windowsSize.getPixel();
//GALE_DEBUG(" windows dimention : " /*<< windowsSize*/ << " == > " << windDim << "px"); // ==> infinite loop ...
//printf(" windows dimention : %f,%f", windDim.x(),windDim.y());
//printf(" data : %f,%f", m_data.x(),m_data.y());
return vec2((m_data.x()/windDim.x())*100.0f, (m_data.y()/windDim.y())*100.0f);
}
return vec2(m_data.x()*100.0f, m_data.y()*100.0f);;
}
vec2 gale::Dimension::getMeter() const {
return gale::Dimension::getMillimeter()*millimeterToMeter;
}
vec2 gale::Dimension::getCentimeter() const {
return gale::Dimension::getMillimeter()*millimeterToCentimeter;
}
vec2 gale::Dimension::getMillimeter() const {
return gale::Dimension::getPixel()*invRatio;
}
vec2 gale::Dimension::getKilometer() const {
return gale::Dimension::getMillimeter()*millimeterToKilometer;
}
vec2 gale::Dimension::getInch() const {
return gale::Dimension::getMillimeter()*millimeterToInch;
}
vec2 gale::Dimension::getFoot() const {
return gale::Dimension::getMillimeter()*millimeterToFoot;
}
std::ostream& gale::operator <<(std::ostream& _os, enum gale::Dimension::distance _obj) {
switch(_obj) {
case gale::Dimension::Pourcent:
_os << "%";
break;
case gale::Dimension::Pixel:
_os << "px";
break;
case gale::Dimension::Meter:
_os << "m";
break;
case gale::Dimension::Centimeter:
_os << "cm";
break;
case gale::Dimension::Millimeter:
_os << "mm";
break;
case gale::Dimension::Kilometer:
_os << "km";
break;
case gale::Dimension::Inch:
_os << "in";
break;
case gale::Dimension::foot:
_os << "ft";
break;
}
return _os;
}
std::ostream& gale::operator <<(std::ostream& _os, const gale::Dimension& _obj) {
_os << _obj.get(_obj.getType()) << _obj.getType();
return _os;
}
namespace etk {
template<> std::string to_string<gale::Dimension>(const gale::Dimension& _obj) {
return _obj;
}
template<> std::u32string to_u32string<gale::Dimension>(const gale::Dimension& _obj) {
return etk::to_u32string(etk::to_string(_obj));
}
template<> bool from_string<gale::Dimension>(gale::Dimension& _variableRet, const std::string& _value) {
_variableRet = gale::Dimension(_value);
return true;
}
template<> bool from_string<gale::Dimension>(gale::Dimension& _variableRet, const std::u32string& _value) {
return from_string(_variableRet, etk::to_string(_value));
}
};

203
esvg/Dimension.h Normal file
View File

@ -0,0 +1,203 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifndef __ESVG_DIMENSION_H__
#define __ESVG_DIMENSION_H__
#include <etk/types.h>
#include <etk/types.h>
#include <etk/math/Vector2D.h>
namespace esvg {
/**
* @brief in the dimention class we store the data as the more usefull unit (pixel)
* but one case need to be dynamic the %, then when requested in % the register the % value
*/
class Dimension {
public:
enum distance {
Pourcent=0,
Pixel,
Meter,
Centimeter,
Millimeter,
Kilometer,
Inch,
foot,
};
private:
vec2 m_data;
enum distance m_type;
public:
/**
* @brief Constructor (default :0,0 mode pixel)
*/
Dimension();
/**
* @brief Constructor
* @param[in] _size Requested dimention
* @param[in] _type Unit of the Dimention
*/
Dimension(const vec2& _size, enum gale::Dimension::distance _type=gale::Dimension::Pixel);
/**
* @brief Constructor
* @param[in] _config dimension configuration.
*/
Dimension(const std::string& _config) :
m_data(0,0),
m_type(gale::Dimension::Pixel) {
set(_config);
};
/**
* @brief Destructor
*/
~Dimension();
/**
* @brief string cast :
*/
operator std::string() const;
/**
* @brief get the current dimention in requested type
* @param[in] _type Type of unit requested.
* @return dimention requested.
*/
vec2 get(enum distance _type) const;
/**
* @brief set the current dimention in requested type
* @param[in] _size Dimention to set
* @param[in] _type Type of unit requested.
*/
void set(const vec2& _size, enum distance _type);
private:
/**
* @brief set the current dimention in requested type
* @param[in] _config dimension configuration.
*/
void set(std::string _config);
public:
/**
* @brief get the current dimention in pixel
* @return dimention in Pixel
*/
vec2 getPixel() const;
/**
* @brief get the current dimention in Pourcent
* @return dimention in Pourcent
*/
vec2 getPourcent() const;
/**
* @brief get the current dimention in Meter
* @return dimention in Meter
*/
vec2 getMeter() const;
/**
* @brief get the current dimention in Centimeter
* @return dimention in Centimeter
*/
vec2 getCentimeter() const;
/**
* @brief get the current dimention in Millimeter
* @return dimention in Millimeter
*/
vec2 getMillimeter() const;
/**
* @brief get the current dimention in Kilometer
* @return dimention in Kilometer
*/
vec2 getKilometer() const;
/**
* @brief get the current dimention in Inch
* @return dimention in Inch
*/
vec2 getInch() const;
/**
* @brief get the current dimention in Foot
* @return dimention in Foot
*/
vec2 getFoot() const;
/*****************************************************
* = assigment
*****************************************************/
const Dimension& operator= (const Dimension& _obj ) {
if (this!=&_obj) {
m_data = _obj.m_data;
m_type = _obj.m_type;
}
return *this;
}
/*****************************************************
* == operator
*****************************************************/
bool operator == (const Dimension& _obj) const {
if( m_data == _obj.m_data
&& m_type == _obj.m_type) {
return true;
}
return false;
}
/*****************************************************
* != operator
*****************************************************/
bool operator!= (const Dimension& _obj) const {
if( m_data != _obj.m_data
|| m_type != _obj.m_type) {
return true;
}
return false;
}
/**
* @breif get the dimension type
* @return the type
*/
enum distance getType() const {
return m_type;
};
public : // Global static access :
/**
* @brief basic init
*/
static void init();
/**
* @brief basic un-init
*/
static void unInit();
/**
* @brief set the Milimeter ratio for calculation
* @param[in] Ratio Milimeter ration for the screen calculation interpolation
* @param[in] type Unit type requested.
* @note: same as @ref setPixelPerInch (internal manage convertion)
*/
static void setPixelRatio(const vec2& _ratio, enum gale::Dimension::distance _type);
/**
* @brief set the current Windows size
* @param[in] size size of the current windows in pixel.
*/
static void setPixelWindowsSize(const vec2& _size);
/**
* @brief get the Windows size in the request unit
* @param[in] type Unit type requested.
* @return the requested size
*/
static vec2 getWindowsSize(enum gale::Dimension::distance _type);
/**
* @brief get the Windows diagonal size in the request unit
* @param[in] type Unit type requested.
* @return the requested size
*/
static float getWindowsDiag(enum gale::Dimension::distance _type);
};
std::ostream& operator <<(std::ostream& _os, enum esvg::Dimension::distance _obj);
std::ostream& operator <<(std::ostream& _os, const esvg::Dimension& _obj);
};
#endif

116
esvg/LinearGradient.cpp Normal file
View File

@ -0,0 +1,116 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <esvg/debug.h>
#include <esvg/LinearGradient.h>
#include <esvg/render/Path.h>
#include <esvg/render/Weight.h>
#undef __class__
#define __class__ "LinearGradient"
esvg::LinearGradient::LinearGradient(PaintState _parentPaintState) : esvg::Base(_parentPaintState) {
m_pos1.setValue(0,0);
m_pos2.setValue(0,0);
}
esvg::LinearGradient::~LinearGradient() {
}
bool esvg::LinearGradient::parseXML(const std::shared_ptr<exml::Element>& _element, mat2& _parentTrans, vec2& _sizeMax) {
// line must have a minimum size...
//m_paint.strokeWidth = 1;
if (_element == nullptr) {
return false;
}
// ---------------- get unique ID ----------------
m_id = _element->getAttribute("id");
//parseTransform(_element);
//parsePaintAttr(_element);
// add the property of the parrent modifications ...
m_transformMatrix *= _parentTrans;
std::string content = _element->getAttribute("x1");
if (content.size()!=0) {
m_pos1.setX(parseLength(content));
}
content = _element->getAttribute("y1");
if (content.size()!=0) {
m_pos1.setY(parseLength(content));
}
content = _element->getAttribute("x2");
if (content.size()!=0) {
m_pos2.setX(parseLength(content));
}
content = _element->getAttribute("y2");
if (content.size()!=0) {
m_pos2.setY(parseLength(content));
}
// parse all sub node :
for(int32_t iii=0; iii<_element->size() ; iii++) {
std::shared_ptr<exml::Element> child = _element->getElement(iii);
if (child == nullptr) {
// can be a comment ...
continue;
}
if (child->getValue() == "stop") {
float offset = 0;
etk::Color<float,4> stopColor = etk::color::none;
// ---------------- offset ----------------
content = child->getAttribute("offset");
if (content.size()!=0) {
offset = parseLength(content);
offset = std::avg(0.0f, offset, 100.0f);
}
// ---------------- STYLE ----------------
content = _element->getAttribute("style");
if (content.size()!=0) {
std::string outputType;
std::string outputValue;
for( int32_t sss=extractPartOfStyle(content, outputType, outputValue, 0);
-2 != sss;
sss=extractPartOfStyle(content, outputType, outputValue, sss) ) {
SVG_VERBOSE(" style parse : \"" << outputType << "\" with value : \"" << outputValue << "\"");
if (outputType == "stop-color") {
stopColor = parseColor(outputValue);
SVG_VERBOSE(" input : \"" << outputValue << "\" == > " << stopColor);
} else if (outputType == "stop-opacity") {
float opacity = parseLength(outputValue);
opacity = std::avg(0.0f, opacity, 1.0f);
stopColor.setA(opacity);
SVG_VERBOSE(" input : \"" << outputValue << "\" == > " << stopColor);
} else {
SVG_ERROR("not know painting element in style balise : \"" << outputType << "\" with value : \"" << outputValue << "\"");
}
}
}
m_data.push_back(std::pair<float, etk::Color<float,4>>(offset, stopColor));
} else {
SVG_ERROR("(l " << child->getPos() << ") node not suported : \"" << child->getValue() << "\" must be [stop]");
}
}
return true;
}
void esvg::LinearGradient::display(int32_t _spacing) {
SVG_DEBUG(spacingDist(_spacing) << "LinearGradient " << m_pos1 << " to " << m_pos2);
for (auto &it : m_data) {
SVG_DEBUG(spacingDist(_spacing+1) << "STOP: offset=" << it.first << " color=" << it.second);
}
}
void esvg::LinearGradient::draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level) {
SVG_VERBOSE(spacingDist(_level) << "DRAW esvg::LinearGradient");
}

30
esvg/LinearGradient.h Normal file
View File

@ -0,0 +1,30 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#ifndef __ESVG_LINEAR_GRANDIENT_H__
#define __ESVG_LINEAR_GRANDIENT_H__
#include <esvg/Base.h>
namespace esvg {
class LinearGradient : public esvg::Base {
private:
vec2 m_pos1; //!< gradient position x1 y1
vec2 m_pos2; //!< gradient position x2 y2
std::vector<std::pair<float, etk::Color<float,4>>> m_data;
public:
LinearGradient(PaintState _parentPaintState);
~LinearGradient();
virtual bool parseXML(const std::shared_ptr<exml::Element>& _element, mat2& _parentTrans, vec2& _sizeMax);
virtual void display(int32_t _spacing);
virtual void draw(esvg::Renderer& _myRenderer, mat2& _basicTrans, int32_t _level);
};
};
#endif

0
esvg/RadialGradient.cpp Normal file
View File

0
esvg/RadialGradient.h Normal file
View File

View File

@ -18,6 +18,8 @@
#include <esvg/Rectangle.h>
#include <esvg/Text.h>
#include <esvg/Group.h>
#include <esvg/LinearGradient.h>
#include <esvg/RadialGradient.h>
#undef __class__
#define __class__ "Document"
@ -199,22 +201,26 @@ bool esvg::Document::store(const std::string& _file) {
bool esvg::Document::parseXMLData(const std::shared_ptr<exml::Element>& _root) {
bool esvg::Document::parseXMLData(const std::shared_ptr<exml::Element>& _root, bool _isReference) {
// get the svg version :
m_version = _root->getAttribute("version");
// parse ...
vec2 pos(0,0);
parseTransform(_root);
parsePosition(_root, pos, m_size);
parsePaintAttr(_root);
SVG_VERBOSE("parsed .ROOT trans: " << m_transformMatrix);
if (_isReference == false) {
parseTransform(_root);
parsePosition(_root, pos, m_size);
parsePaintAttr(_root);
SVG_VERBOSE("parsed .ROOT trans: " << m_transformMatrix);
} else {
SVG_VERBOSE("Parse Reference section ... (no attibute)");
}
vec2 maxSize(0,0);
vec2 size(0,0);
// parse all sub node :
for(int32_t iii=0; iii< _root->size(); iii++) {
std::shared_ptr<exml::Element> child = _root->getElement(iii);
if (child == nullptr) {
// comment trsh here...
// comment can be here...
continue;
}
std::shared_ptr<esvg::Base> elementParser;
@ -242,9 +248,29 @@ bool esvg::Document::parseXMLData(const std::shared_ptr<exml::Element>& _root) {
elementParser = std::make_shared<esvg::Polygon>(m_paint);
} else if (child->getValue() == "text") {
elementParser = std::make_shared<esvg::Text>(m_paint);
} else if (child->getValue() == "radialGradient") {
if (_isReference == false) {
SVG_ERROR("'" << child->getValue() << "' node must not be defined outside a defs Section");
continue;
} else {
//elementParser = std::make_shared<esvg::RadialGradient>(m_paint);
}
} else if (child->getValue() == "linearGradient") {
if (_isReference == false) {
SVG_ERROR("'" << child->getValue() << "' node must not be defined outside a defs Section");
continue;
} else {
elementParser = std::make_shared<esvg::LinearGradient>(m_paint);
}
} else if (child->getValue() == "defs") {
SVG_ERROR("'defs' node must not be defined in a group");
continue;
if (_isReference == true) {
SVG_ERROR("'" << child->getValue() << "' node must not be defined in a defs Section");
continue;
} else {
bool retRefs = parseXMLData(child, true);
// TODO : Use retRefs ...
continue;
}
} else if (child->getValue() == "sodipodi:namedview") {
// Node ignore : generaly inkscape data
continue;
@ -270,7 +296,11 @@ bool esvg::Document::parseXMLData(const std::shared_ptr<exml::Element>& _root) {
maxSize.setY(size.y());
}
// add element in the system
m_subElementList.push_back(elementParser);
if (_isReference == false) {
m_subElementList.push_back(elementParser);
} else {
m_refList.push_back(elementParser);
}
}
if (m_size.x() == 0 || m_size.y()==0) {
m_size.setValue((int32_t)maxSize.x(), (int32_t)maxSize.y());

View File

@ -59,7 +59,7 @@ namespace esvg {
*/
bool store(const std::string& _file);
protected:
virtual bool parseXMLData(const std::shared_ptr<exml::Element>& _root);
virtual bool parseXMLData(const std::shared_ptr<exml::Element>& _root, bool _isReference = false);
public:
bool isLoadOk() {
return m_loadOK;

View File

@ -40,7 +40,9 @@ def create(target, module_name):
'test/testJoin.cpp',
'test/testCap.cpp',
'test/testColor.cpp',
'test/testStyle.cpp'
'test/testStyle.cpp',
'test/testGradientLinear.cpp',
'test/testGradientRadial.cpp'
])
my_module.add_module_depend(['esvg', 'gtest', 'test-debug'])
return my_module

View File

@ -60,7 +60,9 @@ def create(target, module_name):
'esvg/render/Scanline.cpp',
'esvg/render/Segment.cpp',
'esvg/render/SegmentList.cpp',
'esvg/render/Weight.cpp'
'esvg/render/Weight.cpp',
'esvg/LinearGradient.cpp',
'esvg/RadialGradient.cpp'
])
my_module.add_header_file([
@ -97,7 +99,9 @@ def create(target, module_name):
'esvg/render/PointList.h',
'esvg/render/Segment.h',
'esvg/render/SegmentList.h',
'esvg/render/Weight.h'
'esvg/render/Weight.h',
'esvg/LinearGradient.h',
'esvg/RadialGradient.h'
])
my_module.add_path(tools.get_current_path(__file__))

View File

@ -0,0 +1,49 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <gtest/gtest.h>
#include <esvg/esvg.h>
#include "main.h"
#undef __class__
#define __class__ "TestGradientLinear"
TEST(TestGradientLinear, horizontal) {
std::string data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
"<svg height='100' width='100'>\n"
" <defs>\n"
" <linearGradient id='grad1' x1='0%' y1='0%' x2='100%' y2='0%'>\n"
" <stop offset='0%' style='stop-color:rgb(255,255,0);stop-opacity:1' />\n"
" <stop offset='100%' style='stop-color:rgb(255,0,0);stop-opacity:1' />\n"
" </linearGradient>\n"
" </defs>\n"
" <ellipse cx='200' cy='70' rx='85' ry='55' fill='url(#grad1)' />\n"
"</svg>\n");
esvg::Document doc;
doc.parse(data);
etk::FSNodeWriteAllData("TestGradientLinear_horizontal.svg", data);
//doc.generateAnImage(ivec2(100, 100), "TestGradientLinear_horizontal.bmp", g_visualDebug);
}
TEST(TestGradientLinear, vertical) {
std::string data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
"<svg height='100' width='100'>\n"
" <defs>\n"
" <linearGradient id='grad2' x1='0%' y1='0%' x2='0%' y2='100%'>\n"
" <stop offset='0%' style='stop-color:rgb(255,255,0);stop-opacity:1' />\n"
" <stop offset='100%' style='stop-color:rgb(255,0,0);stop-opacity:1' />\n"
" </linearGradient>\n"
" </defs>\n"
" <ellipse cx='200' cy='70' rx='85' ry='55' fill='url(#grad2)' />\n"
"</svg>\n");
esvg::Document doc;
doc.parse(data);
etk::FSNodeWriteAllData("TestGradientLinear_vertical.svg", data);
doc.generateAnImage(ivec2(100, 100), "TestGradientLinear_vertical.bmp", g_visualDebug);
}

View File

@ -0,0 +1,49 @@
/**
* @author Edouard DUPIN
*
* @copyright 2014, Edouard DUPIN, all right reserved
*
* @license APACHE v2.0 (see license file)
*/
#include <gtest/gtest.h>
#include <esvg/esvg.h>
#include "main.h"
#undef __class__
#define __class__ "TestGradientRadial"
TEST(TestGradientRadial, full) {
std::string data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
"<svg height='100' width='100'>\n"
" <defs>\n"
" <radialGradient id='grad1' cx='50%' cy='50%' r='50%' fx='50%' fy='50%'>\n"
" <stop offset='0%' style='stop-color:rgb(255,255,255);stop-opacity:0' />\n"
" <stop offset='100%' style='stop-color:rgb(0,0,255);stop-opacity:1' />\n"
" </radialGradient>\n"
" </defs>\n"
" <ellipse cx='200' cy='70' rx='85' ry='55' fill='url(#grad1)' />\n"
"</svg>\n");
esvg::Document doc;
doc.parse(data);
etk::FSNodeWriteAllData("TestGradientRadial_full.svg", data);
doc.generateAnImage(ivec2(100, 100), "TestGradientRadial_full.bmp", g_visualDebug);
}
TEST(TestGradientRadial, partial) {
std::string data("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
"<svg height='100' width='100'>\n"
" <defs>\n"
" <radialGradient id='grad2' cx='20%' cy='30%' r='30%' fx='50%' fy='50%'>\n"
" <stop offset='0%' style='stop-color:rgb(255,255,255);stop-opacity:0' />\n"
" <stop offset='100%' style='stop-color:rgb(0,0,255);stop-opacity:1' />\n"
" </radialGradient>\n"
" </defs>\n"
" <ellipse cx='200' cy='70' rx='85' ry='55' fill='url(#grad2)' />\n"
"</svg>\n");
esvg::Document doc;
doc.parse(data);
etk::FSNodeWriteAllData("TestGradientRadial_partial.svg", data);
doc.generateAnImage(ivec2(100, 100), "TestGradientRadial_partial.bmp", g_visualDebug);
}

View File

@ -11,7 +11,7 @@
#include "main.h"
#undef __class__
#define __class__ "TestLine"
#define __class__ "TestJoin"
// ------------------------------------------------------ Miter test -----------------------------------------------------
TEST(TestJoin, miterRight1) {