Skip to content

Commit

Permalink
Release v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Sep 18, 2020
1 parent 92a24de commit a7a021b
Show file tree
Hide file tree
Showing 55 changed files with 234 additions and 616 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.3)

project(lunasvg VERSION 1.1.0 LANGUAGES CXX)
project(lunasvg VERSION 1.2.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ int main()
- Clipping, Masking and Compositing : clipPath, mask, group opacity.
- Document Structures: defs, svg, g, use, symbol.
- Coordinate Systems, Transformations and Units.
- Markers.
- Texts (TODO) : text, tspan, tref, textPath.
- Animations (TODO) : animate, animateColor, animateMotion, animateTransform
- Markers (TODO)

## depends
* [cmake](https://cmake.org/download/)
Expand Down
2 changes: 1 addition & 1 deletion include/svgdocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,6 @@ inline SVGDocumentImpl* SVGDocument::impl() const
return m_impl;
}

} //namespace lunasvg
} // namespace lunasvg

#endif // SVGDOCUMENT_H
3 changes: 1 addition & 2 deletions include/svgelementiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

#include <string>

namespace lunasvg
{
namespace lunasvg {

class SVGElement;
class SVGElementImpl;
Expand Down
10 changes: 3 additions & 7 deletions source/cssproperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ CSSPropertyBase::~CSSPropertyBase()
{
}

CSSPropertyBase::CSSPropertyBase(CSSPropertyID propertyId, PropertyType propertyType)
: m_propertyId(propertyId),
m_propertyType(propertyType)
CSSPropertyBase::CSSPropertyBase(CSSPropertyID propertyId)
: m_propertyId(propertyId)
{
}

Expand Down Expand Up @@ -52,8 +51,6 @@ CSSPropertyBase* CSSPropertyBase::create(CSSPropertyID propertyId)
return new CSSProperty<SVGEnumeration<Display>>(propertyId);
case CSSPropertyIdVisibility:
return new CSSProperty<SVGEnumeration<Visibility>>(propertyId);
case CSSPropertyIdOverflow:
return new CSSProperty<SVGEnumeration<Overflow>>(propertyId);
case CSSPropertyIdClip_Path:
case CSSPropertyIdMask:
case CSSPropertyIdMarker_Start:
Expand All @@ -74,7 +71,6 @@ CSSPropertyList::~CSSPropertyList()
}

CSSPropertyList::CSSPropertyList()
: SVGProperty(PropertyTypeCSSPropertyList)
{
m_values.fill(nullptr);
}
Expand Down Expand Up @@ -158,7 +154,7 @@ std::string CSSPropertyList::valueAsString() const
return out;
}

SVGProperty* CSSPropertyList::clone() const
SVGPropertyBase* CSSPropertyList::clone() const
{
CSSPropertyList* property = new CSSPropertyList;
for(unsigned int i = 0;i < MAX_STYLE;i++)
Expand Down
21 changes: 9 additions & 12 deletions source/cssproperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,33 @@ class CSSPropertyBase
public:
static CSSPropertyBase* create(CSSPropertyID propertyId);
virtual ~CSSPropertyBase();
virtual SVGProperty* ensureProperty() = 0;
virtual SVGProperty* property() const = 0;
virtual SVGPropertyBase* ensureProperty() = 0;
virtual SVGPropertyBase* property() const = 0;
virtual void setInherited() = 0;
virtual bool isInherited() const = 0;
virtual void setPropertyAsString(const std::string& value) = 0;
virtual std::string propertyAsString() const = 0;
virtual CSSPropertyBase* clone() const = 0;
CSSPropertyID propertyId() const { return m_propertyId; }
PropertyType propertyType() const { return m_propertyType; }

protected:
CSSPropertyBase(CSSPropertyID propertyId, PropertyType propertyType);
CSSPropertyBase(CSSPropertyID propertyId);

protected:
const CSSPropertyID m_propertyId;
const PropertyType m_propertyType;
};

template<typename T>
class CSSProperty : public CSSPropertyBase
{
public:
CSSProperty(CSSPropertyID propertyId)
: CSSPropertyBase(propertyId, T::classType()),
: CSSPropertyBase(propertyId),
m_property(nullptr)
{}

SVGProperty* ensureProperty();
SVGProperty* property() const { return m_property; }
SVGPropertyBase* ensureProperty();
SVGPropertyBase* property() const { return m_property; }
bool isInherited() const { return !m_property; }
void setInherited();
void setPropertyAsString(const std::string& value);
Expand All @@ -55,7 +53,7 @@ class CSSProperty : public CSSPropertyBase
};

template<typename T>
SVGProperty* CSSProperty<T>::ensureProperty()
SVGPropertyBase* CSSProperty<T>::ensureProperty()
{
if(!m_property)
m_property = new T();
Expand Down Expand Up @@ -102,7 +100,7 @@ CSSProperty<T>::~CSSProperty()
delete m_property;
}

class CSSPropertyList : public SVGProperty
class CSSPropertyList : public SVGPropertyBase
{
public:
~CSSPropertyList();
Expand All @@ -115,8 +113,7 @@ class CSSPropertyList : public SVGProperty

void setValueAsString(const std::string& value);
std::string valueAsString() const;
SVGProperty* clone() const;
static PropertyType classType() { return PropertyTypeCSSPropertyList; }
SVGPropertyBase* clone() const;

private:
std::array<CSSPropertyBase*, MAX_STYLE> m_values;
Expand Down
47 changes: 23 additions & 24 deletions source/rendercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ void RenderStyle::inheritFrom(const RenderStyle& style)
{
case CSSPropertyIdDisplay:
case CSSPropertyIdClip_Path:
case CSSPropertyIdOverflow:
case CSSPropertyIdStop_Color:
case CSSPropertyIdStop_Opacity:
case CSSPropertyIdSolid_Color:
Expand Down Expand Up @@ -85,7 +84,7 @@ void RenderStyle::clearAll()

bool RenderStyle::isDisplayNone() const
{
if(const SVGProperty* property = get(CSSPropertyIdDisplay))
if(const SVGPropertyBase* property = get(CSSPropertyIdDisplay))
{
const SVGEnumeration<Display>* display = to<SVGEnumeration<Display>>(property);
return display->enumValue() == DisplayNone;
Expand All @@ -96,7 +95,7 @@ bool RenderStyle::isDisplayNone() const

bool RenderStyle::isHidden() const
{
if(const SVGProperty* property = get(CSSPropertyIdVisibility))
if(const SVGPropertyBase* property = get(CSSPropertyIdVisibility))
{
const SVGEnumeration<Visibility>* visibility = to<SVGEnumeration<Visibility>>(property);
return visibility->enumValue() == VisibilityHidden;
Expand All @@ -107,15 +106,15 @@ bool RenderStyle::isHidden() const

bool RenderStyle::hasStroke() const
{
if(const SVGProperty* property = get(CSSPropertyIdStroke))
if(const SVGPropertyBase* property = get(CSSPropertyIdStroke))
return to<SVGPaint>(property)->colorType() != ColorTypeNone;

return false;
}

bool RenderStyle::hasFill() const
{
if(const SVGProperty* property = get(CSSPropertyIdFill))
if(const SVGPropertyBase* property = get(CSSPropertyIdFill))
return to<SVGPaint>(property)->colorType() != ColorTypeNone;

return false;
Expand All @@ -124,105 +123,105 @@ bool RenderStyle::hasFill() const
StrokeData RenderStyle::strokeData(const RenderState& state) const
{
StrokeData strokeData;
if(const SVGProperty* property = get(CSSPropertyIdStroke_Width))
if(const SVGPropertyBase* property = get(CSSPropertyIdStroke_Width))
strokeData.setWidth(to<SVGLength>(property)->value(state));
if(const SVGProperty* property = get(CSSPropertyIdStroke_Miterlimit))
if(const SVGPropertyBase* property = get(CSSPropertyIdStroke_Miterlimit))
strokeData.setMiterLimit(to<SVGNumber>(property)->value());
if(const SVGProperty* property = get(CSSPropertyIdStroke_Linecap))
if(const SVGPropertyBase* property = get(CSSPropertyIdStroke_Linecap))
strokeData.setCap(to<SVGEnumeration<LineCap>>(property)->enumValue());
if(const SVGProperty* property = get(CSSPropertyIdStroke_Linejoin))
if(const SVGPropertyBase* property = get(CSSPropertyIdStroke_Linejoin))
strokeData.setJoin(to<SVGEnumeration<LineJoin>>(property)->enumValue());
if(const SVGProperty* property = get(CSSPropertyIdStroke_Dasharray))
if(const SVGPropertyBase* property = get(CSSPropertyIdStroke_Dasharray))
strokeData.setDash(to<SVGLengthList>(property)->values(state));
if(const SVGProperty* property = get(CSSPropertyIdStroke_Dashoffset))
if(const SVGPropertyBase* property = get(CSSPropertyIdStroke_Dashoffset))
strokeData.setDashOffset(to<SVGLength>(property)->value(state));

return strokeData;
}

Paint RenderStyle::fillPaint(const RenderState& state) const
{
if(const SVGProperty* property = get(CSSPropertyIdFill))
if(const SVGPropertyBase* property = get(CSSPropertyIdFill))
return to<SVGPaint>(property)->getPaint(state);

return KRgbBlack;
}

Paint RenderStyle::strokePaint(const RenderState& state) const
{
if(const SVGProperty* property = get(CSSPropertyIdStroke))
if(const SVGPropertyBase* property = get(CSSPropertyIdStroke))
return to<SVGPaint>(property)->getPaint(state);

return Paint();
}

double RenderStyle::strokeWidth(const RenderState& state) const
{
if(const SVGProperty* property = get(CSSPropertyIdStroke_Width))
if(const SVGPropertyBase* property = get(CSSPropertyIdStroke_Width))
return to<SVGLength>(property)->value(state);

return 1.0;
}

double RenderStyle::fillOpacity() const
{
if(const SVGProperty* property = get(CSSPropertyIdFill_Opacity))
if(const SVGPropertyBase* property = get(CSSPropertyIdFill_Opacity))
return to<SVGNumber>(property)->value();

return 1.0;
}

double RenderStyle::strokeOpacity() const
{
if(const SVGProperty* property = get(CSSPropertyIdStroke_Opacity))
if(const SVGPropertyBase* property = get(CSSPropertyIdStroke_Opacity))
return to<SVGNumber>(property)->value();

return 1.0;
}

double RenderStyle::opacity() const
{
if(const SVGProperty* property = get(CSSPropertyIdOpacity))
if(const SVGPropertyBase* property = get(CSSPropertyIdOpacity))
return to<SVGNumber>(property)->value();

return 1.0;
}

const std::string& RenderStyle::mask() const
{
if(const SVGProperty* property = get(CSSPropertyIdMask))
if(const SVGPropertyBase* property = get(CSSPropertyIdMask))
return to<SVGString>(property)->value();

return KEmptyString;
}

const std::string& RenderStyle::clipPath() const
{
if(const SVGProperty* property = get(CSSPropertyIdClip_Path))
if(const SVGPropertyBase* property = get(CSSPropertyIdClip_Path))
return to<SVGString>(property)->value();

return KEmptyString;
}

WindRule RenderStyle::fillRule() const
{
if(const SVGProperty* property = get(CSSPropertyIdFill_Rule))
if(const SVGPropertyBase* property = get(CSSPropertyIdFill_Rule))
return to<SVGEnumeration<WindRule>>(property)->enumValue();

return WindRuleNonZero;
}

WindRule RenderStyle::clipRule() const
{
if(const SVGProperty* property = get(CSSPropertyIdClip_Rule))
if(const SVGPropertyBase* property = get(CSSPropertyIdClip_Rule))
return to<SVGEnumeration<WindRule>>(property)->enumValue();

return WindRuleNonZero;
}

const SVGMarkerElement* RenderStyle::markerStart(const SVGDocument* document) const
{
if(const SVGProperty* property = get(CSSPropertyIdMarker_Start))
if(const SVGPropertyBase* property = get(CSSPropertyIdMarker_Start))
{
const std::string& value = to<SVGString>(property)->value();
SVGElementImpl* ref = document->impl()->resolveIRI(value);
Expand All @@ -235,7 +234,7 @@ const SVGMarkerElement* RenderStyle::markerStart(const SVGDocument* document) co

const SVGMarkerElement* RenderStyle::markerMid(const SVGDocument* document) const
{
if(const SVGProperty* property = get(CSSPropertyIdMarker_Mid))
if(const SVGPropertyBase* property = get(CSSPropertyIdMarker_Mid))
{
const std::string& value = to<SVGString>(property)->value();
SVGElementImpl* ref = document->impl()->resolveIRI(value);
Expand All @@ -248,7 +247,7 @@ const SVGMarkerElement* RenderStyle::markerMid(const SVGDocument* document) cons

const SVGMarkerElement* RenderStyle::markerEnd(const SVGDocument* document) const
{
if(const SVGProperty* property = get(CSSPropertyIdMarker_End))
if(const SVGPropertyBase* property = get(CSSPropertyIdMarker_End))
{
const std::string& value = to<SVGString>(property)->value();
SVGElementImpl* ref = document->impl()->resolveIRI(value);
Expand Down
4 changes: 2 additions & 2 deletions source/rendercontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class RenderStyle
bool isDisplayNone() const;
bool isHidden() const;

const SVGProperty* get(CSSPropertyID nameId) const { return m_properties[nameId]; }
const SVGPropertyBase* get(CSSPropertyID nameId) const { return m_properties[nameId]; }
bool isSet(CSSPropertyID nameId) const { return m_properties[nameId]; }
bool isEmpty() const { return m_properties.empty(); }

Expand All @@ -57,7 +57,7 @@ class RenderStyle
const SVGMarkerElement* markerEnd(const SVGDocument* document) const;

private:
std::array<const SVGProperty*, MAX_STYLE> m_properties;
std::array<const SVGPropertyBase*, MAX_STYLE> m_properties;
};

class RenderState
Expand Down
9 changes: 4 additions & 5 deletions source/svgangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ namespace lunasvg {
#define PI 3.14159265358979323846

SVGAngle::SVGAngle()
: SVGProperty(PropertyTypeAngle),
m_value(0),
: m_value(0),
m_orientType(MarkerOrientTypeAngle)
{
}
Expand All @@ -30,8 +29,8 @@ void SVGAngle::setValueAsString(const std::string& value)
return;

if(Utils::skipDesc(ptr, "rad", 3))
m_value *= 180 * PI;
else if(Utils::skipDesc(ptr, "grad", 4))
m_value *= 180.0 / PI;
else if(Utils::skipDesc(ptr, "grad", 3))
m_value *= 360.0 / 400.0;
}

Expand All @@ -40,7 +39,7 @@ std::string SVGAngle::valueAsString() const
return m_orientType == MarkerOrientTypeAuto ? std::string("auto") : Utils::toString(m_value);
}

SVGProperty* SVGAngle::clone() const
SVGPropertyBase* SVGAngle::clone() const
{
SVGAngle* property = new SVGAngle();
property->m_value = m_value;
Expand Down
5 changes: 2 additions & 3 deletions source/svgangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum MarkerOrientType
MarkerOrientTypeAngle
};

class SVGAngle : public SVGProperty
class SVGAngle : public SVGPropertyBase
{
public:
SVGAngle();
Expand All @@ -24,8 +24,7 @@ class SVGAngle : public SVGProperty

void setValueAsString(const std::string& value);
std::string valueAsString() const;
SVGProperty* clone() const;
static PropertyType classType() { return PropertyTypeAngle; }
SVGPropertyBase* clone() const;

private:
double m_value;
Expand Down
Loading

0 comments on commit a7a021b

Please sign in to comment.