diff --git a/CMakeLists.txt b/CMakeLists.txt index ec9ba28..a8137f8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.3) -project(lunasvg VERSION 1.0.1 LANGUAGES CXX) +project(lunasvg VERSION 1.1.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 11) diff --git a/include/svgelement.h b/include/svgelement.h index 3b5df76..a2750a0 100755 --- a/include/svgelement.h +++ b/include/svgelement.h @@ -25,18 +25,7 @@ class Bitmap std::uint32_t stride() const; private: - struct Impl - { - Impl(std::uint8_t* data, std::uint32_t width, std::uint32_t height, std::uint32_t stride); - Impl(std::uint32_t width, std::uint32_t height); - - std::unique_ptr ownData; - std::uint8_t* data; - std::uint32_t width; - std::uint32_t height; - std::uint32_t stride; - }; - + struct Impl; std::shared_ptr m_impl; }; diff --git a/source/backends/cairo/canvasimpl.cpp b/source/backends/cairo/canvasimpl.cpp index 657904a..080b361 100755 --- a/source/backends/cairo/canvasimpl.cpp +++ b/source/backends/cairo/canvasimpl.cpp @@ -22,15 +22,15 @@ CanvasImpl::~CanvasImpl() cairo_surface_destroy(m_surface); } -CanvasImpl::CanvasImpl(unsigned char* data, unsigned int width, unsigned int height, unsigned int stride) : - m_surface(cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, int(width), int(height), int(stride))), - m_cr(cairo_create(m_surface)) +CanvasImpl::CanvasImpl(unsigned char* data, unsigned int width, unsigned int height, unsigned int stride) + : m_surface(cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, int(width), int(height), int(stride))), + m_cr(cairo_create(m_surface)) { } -CanvasImpl::CanvasImpl(unsigned int width, unsigned int height) : - m_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, int(width), int(height))), - m_cr(cairo_create(m_surface)) +CanvasImpl::CanvasImpl(unsigned int width, unsigned int height) + : m_surface(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, int(width), int(height))), + m_cr(cairo_create(m_surface)) { } @@ -221,7 +221,8 @@ cairo_pattern_t* to_cairo_pattern(const Paint& paint) const Rgb* c = paint.color(); return cairo_pattern_create_rgba(c->r/255.0, c->g/255.0, c->b/255.0, (c->a/255.0)*paint.opacity()); } - else if(paint.type() == PaintTypeGradient) + + if(paint.type() == PaintTypeGradient) { const Gradient* gradient = paint.gradient(); cairo_pattern_t* pattern; @@ -266,7 +267,8 @@ cairo_pattern_t* to_cairo_pattern(const Paint& paint) cairo_pattern_set_matrix(pattern, &matrix); return pattern; } - else if(paint.type() == PaintTypePattern) + + if(paint.type() == PaintTypePattern) { const Pattern* p = paint.pattern(); cairo_pattern_t* pattern = cairo_pattern_create_for_surface(p->tile().impl()->surface()); diff --git a/source/cssproperty.cpp b/source/cssproperty.cpp index cba837f..7421845 100755 --- a/source/cssproperty.cpp +++ b/source/cssproperty.cpp @@ -11,9 +11,9 @@ CSSPropertyBase::~CSSPropertyBase() { } -CSSPropertyBase::CSSPropertyBase(CSSPropertyID propertyId, PropertyType propertyType) : - m_propertyId(propertyId), - m_propertyType(propertyType) +CSSPropertyBase::CSSPropertyBase(CSSPropertyID propertyId, PropertyType propertyType) + : m_propertyId(propertyId), + m_propertyType(propertyType) { } @@ -73,8 +73,8 @@ CSSPropertyList::~CSSPropertyList() delete m_values[i]; } -CSSPropertyList::CSSPropertyList() : - SVGProperty(PropertyTypeCSSPropertyList) +CSSPropertyList::CSSPropertyList() + : SVGProperty(PropertyTypeCSSPropertyList) { m_values.fill(nullptr); } @@ -124,7 +124,7 @@ void CSSPropertyList::setValueAsString(const std::string& value) ++ptr; std::string name(start, ptr); Utils::skipWs(ptr); - if(!*ptr || *ptr!=':') + if(*ptr!=':') return; ++ptr; Utils::skipWs(ptr); @@ -160,7 +160,7 @@ std::string CSSPropertyList::valueAsString() const SVGProperty* CSSPropertyList::clone() const { - CSSPropertyList* property = new CSSPropertyList; + CSSPropertyList* property = new CSSPropertyList; for(unsigned int i = 0;i < MAX_STYLE;i++) { if(m_values[i]) @@ -170,8 +170,8 @@ SVGProperty* CSSPropertyList::clone() const return property; } -DOMSVGStyle::DOMSVGStyle(DOMPropertyID propertyId) : - DOMSVGProperty(propertyId) +DOMSVGStyle::DOMSVGStyle(DOMPropertyID propertyId) + : DOMSVGProperty(propertyId) { } diff --git a/source/cssproperty.h b/source/cssproperty.h index f068114..76d2b93 100755 --- a/source/cssproperty.h +++ b/source/cssproperty.h @@ -36,9 +36,9 @@ template class CSSProperty : public CSSPropertyBase { public: - CSSProperty(CSSPropertyID propertyId) : - CSSPropertyBase(propertyId, T::classType()), - m_property(nullptr) + CSSProperty(CSSPropertyID propertyId) + : CSSPropertyBase(propertyId, T::classType()), + m_property(nullptr) {} SVGProperty* ensureProperty(); diff --git a/source/geometry/CMakeLists.txt b/source/geometry/CMakeLists.txt index d365c51..244484b 100755 --- a/source/geometry/CMakeLists.txt +++ b/source/geometry/CMakeLists.txt @@ -1,9 +1,7 @@ target_sources(lunasvg PRIVATE "${CMAKE_CURRENT_LIST_DIR}/affinetransform.cpp" - "${CMAKE_CURRENT_LIST_DIR}/flatteningpathiterator.cpp" "${CMAKE_CURRENT_LIST_DIR}/path.cpp" - "${CMAKE_CURRENT_LIST_DIR}/pathutils.cpp" "${CMAKE_CURRENT_LIST_DIR}/pathiterator.cpp" ) diff --git a/source/geometry/flatteningpathiterator.cpp b/source/geometry/flatteningpathiterator.cpp deleted file mode 100755 index 4ca5ce9..0000000 --- a/source/geometry/flatteningpathiterator.cpp +++ /dev/null @@ -1,183 +0,0 @@ -#include "flatteningpathiterator.h" - -namespace lunasvg { - -FlatteningPathIterator::FlatteningPathIterator(const Path& path, unsigned int limit) : - m_pathIterator(path), - m_segType(SegTypeClose), - m_recursionLimit(limit), - m_coordIndex(0) -{ - next(); -} - -SegType FlatteningPathIterator::currentSegment(double* coords) const -{ - if(m_coordIndex < m_pointCoords.size()) - { - coords[0] = m_pointCoords[m_coordIndex]; - coords[1] = m_pointCoords[m_coordIndex + 1]; - } - - return m_segType; -} - -bool FlatteningPathIterator::isDone() const -{ - return (m_coordIndex >= m_pointCoords.size()) && m_pathIterator.isDone(); -} - -void FlatteningPathIterator::next() -{ - m_coordIndex += 2; - - if(m_coordIndex >= m_pointCoords.size()) - { - m_pointCoords.clear(); - m_coordIndex = 0; - - if(!m_pathIterator.isDone()) - { - double coords[6]; - m_segType = m_pathIterator.currentSegment(coords); - switch(m_segType) - { - case SegTypeMoveTo: - m_pointCoords.push_back(coords[0]); - m_pointCoords.push_back(coords[1]); - m_lastPoint.x = coords[0]; - m_lastPoint.y = coords[1]; - break; - case SegTypeLineTo: - m_pointCoords.push_back(coords[0]); - m_pointCoords.push_back(coords[1]); - m_lastPoint.x = coords[0]; - m_lastPoint.y = coords[1]; - break; - case SegTypeQuadTo: - m_pointCoords.push_back(m_lastPoint.x); - m_pointCoords.push_back(m_lastPoint.y); - m_pointCoords.push_back(coords[0]); - m_pointCoords.push_back(coords[1]); - m_pointCoords.push_back(coords[2]); - m_pointCoords.push_back(coords[3]); - - for(unsigned int i = 0; i < m_recursionLimit;i++) - flattenCurveQuadTo(m_pointCoords); - - m_coordIndex = 2; - m_lastPoint.x = coords[2]; - m_lastPoint.y = coords[3]; - m_segType = SegTypeLineTo; - break; - case SegTypeCubicTo: - m_pointCoords.push_back(m_lastPoint.x); - m_pointCoords.push_back(m_lastPoint.y); - m_pointCoords.push_back(coords[0]); - m_pointCoords.push_back(coords[1]); - m_pointCoords.push_back(coords[2]); - m_pointCoords.push_back(coords[3]); - m_pointCoords.push_back(coords[4]); - m_pointCoords.push_back(coords[5]); - - for(unsigned int i = 0; i < m_recursionLimit;i++) - flattenCurveCubicTo(m_pointCoords); - - m_coordIndex = 2; - m_lastPoint.x = coords[4]; - m_lastPoint.y = coords[5]; - m_segType = SegTypeLineTo; - break; - case SegTypeClose: - m_pointCoords.push_back(m_lastPoint.x); - m_pointCoords.push_back(m_lastPoint.y); - break; - } - m_pathIterator.next(); - } - } -} - -void FlatteningPathIterator::flattenCurveQuadTo(std::vector& coords) const -{ - unsigned count, i = 0; - double p[6]; - - while (i + 5 < coords.size()) - { - count = i; - p[0] = coords[count++]; - p[1] = coords[count++]; - p[2] = coords[count++]; - p[3] = coords[count++]; - p[4] = coords[count++]; - p[5] = coords[count++]; - - p[0] = (p[0] + p[2]) * 0.5; - p[1] = (p[1] + p[3]) * 0.5; - p[4] = (p[2] + p[4]) * 0.5; - p[5] = (p[3] + p[5]) * 0.5; - p[2] = (p[0] + p[4]) * 0.5; - p[3] = (p[1] + p[5]) * 0.5; - - coords[i + 2] = p[2]; - coords[i + 3] = p[3]; - - coords.insert(coords.begin() + (i + 2), p[0]); - coords.insert(coords.begin() + (i + 3), p[1]); - coords.insert(coords.begin() + (i + 6), p[5]); - coords.insert(coords.begin() + (i + 7), p[4]); - - i += 8; - } -} - -void FlatteningPathIterator::flattenCurveCubicTo(std::vector& coords) const -{ - unsigned count, i = 0; - double p[10]; - - while (i + 7 < coords.size()) - { - count = i; - p[0] = coords[count++]; - p[1] = coords[count++]; - p[2] = coords[count++]; - p[3] = coords[count++]; - p[4] = coords[count++]; - p[5] = coords[count++]; - p[6] = coords[count++]; - p[7] = coords[count++]; - - p[0] = (p[0] + p[2]) * 0.5; - p[1] = (p[1] + p[3]) * 0.5; - p[6] = (p[4] + p[6]) * 0.5; - p[7] = (p[5] + p[7]) * 0.5; - p[8] = (p[2] + p[4]) * 0.5; - p[9] = (p[3] + p[5]) * 0.5; - p[2] = (p[0] + p[8]) * 0.5; - p[3] = (p[1] + p[9]) * 0.5; - p[4] = (p[6] + p[8]) * 0.5; - p[5] = (p[7] + p[9]) * 0.5; - p[8] = (p[2] + p[4]) * 0.5; - p[9] = (p[3] + p[5]) * 0.5; - - count = i + 2; - - coords[count++] = p[0]; - coords[count++] = p[1]; - coords[count++] = p[2]; - coords[count++] = p[3]; - - coords.insert(coords.begin() + count, p[7]); - coords.insert(coords.begin() + count, p[6]); - coords.insert(coords.begin() + count, p[5]); - coords.insert(coords.begin() + count, p[4]); - coords.insert(coords.begin() + count, p[9]); - coords.insert(coords.begin() + count, p[8]); - - i += 12; - } -} - -} // namespace lunasvg diff --git a/source/geometry/flatteningpathiterator.h b/source/geometry/flatteningpathiterator.h deleted file mode 100755 index 0eaa1bd..0000000 --- a/source/geometry/flatteningpathiterator.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef FLATTENINGPATHITERATOR_H -#define FLATTENINGPATHITERATOR_H - -#include "pathiterator.h" - -namespace lunasvg { - -class FlatteningPathIterator -{ -public: - FlatteningPathIterator(const Path& path, unsigned int limit); - - SegType currentSegment(double* coords) const; - bool isDone() const; - void next(); - -private: - void flattenCurveQuadTo(std::vector& coords) const; - void flattenCurveCubicTo(std::vector& coords) const; - -private: - PathIterator m_pathIterator; - std::vector m_pointCoords; - SegType m_segType; - unsigned int m_recursionLimit; - unsigned int m_coordIndex; - Point m_lastPoint; -}; - -} // namespace lunasvg - -#endif // FLATTENINGPATHITERATOR_H diff --git a/source/geometry/path.cpp b/source/geometry/path.cpp index 4fd2efe..32f9b97 100755 --- a/source/geometry/path.cpp +++ b/source/geometry/path.cpp @@ -4,10 +4,13 @@ #include #include +#include +#include namespace lunasvg { #define BEZIER_ARC_FACTOR 0.5522847498 +#define PI 3.14159265358979323846 Path::Path() { @@ -76,6 +79,121 @@ void Path::cubicTo(double x1, double y1, double x2, double y2, double x3, double m_coordinates.emplace_back(x3, y3); } +void Path::arcTo(double rx, double ry, double xAxisRotation, bool largeArcFlag, bool sweepFlag, double x, double y, bool rel) +{ + Point cp = currentPoint(); + if(rel) + { + x += cp.x; + y += cp.y; + } + + if(x == cp.x && y == cp.y) + return; + + if(rx == 0.0 || ry == 0.0) + { + lineTo(x, y); + return; + } + + double sin_th = std::sin(xAxisRotation * PI / 180.0); + double cos_th = std::cos(xAxisRotation * PI / 180.0); + + double dx2 = (cp.x - x) / 2.0; + double dy2 = (cp.y - y) / 2.0; + + double x1 = (cos_th * dx2 + sin_th * dy2); + double y1 = (-sin_th * dx2 + cos_th * dy2); + + double rx_sq = rx * rx; + double ry_sq = ry * ry; + double x1_sq = x1 * x1; + double y1_sq = y1 * y1; + + double check = x1_sq / rx_sq + y1_sq / ry_sq; + if(check > 0.99999) + { + double scale = std::sqrt(check) * 1.00001; + rx = scale * rx; + ry = scale * ry; + rx_sq = rx * rx; + ry_sq = ry * ry; + } + + double sign = (largeArcFlag == sweepFlag) ? -1 : 1; + double sq = ((rx_sq * ry_sq) - (rx_sq * y1_sq) - (ry_sq * x1_sq)) / ((rx_sq * y1_sq) + (ry_sq * x1_sq)); + sq = (sq < 0) ? 0 : sq; + double coef = (sign * std::sqrt(sq)); + double cx1 = coef * ((rx * y1) / ry); + double cy1 = coef * -((ry * x1) / rx); + + double sx2 = (cp.x + x) / 2.0; + double sy2 = (cp.y + y) / 2.0; + double cx = sx2 + (cos_th * cx1 - sin_th * cy1); + double cy = sy2 + (sin_th * cx1 + cos_th * cy1); + + double ux = (x1 - cx1) / rx; + double uy = (y1 - cy1) / ry; + double vx = (-x1 - cx1) / rx; + double vy = (-y1 - cy1) / ry; + double p, n; + + n = std::sqrt((ux * ux) + (uy * uy)); + p = ux; + sign = (uy < 0) ? -1.0 : 1.0; + double angleStart = sign * std::acos(p / n); + + n = std::sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy)); + p = ux * vx + uy * vy; + sign = (ux * vy - uy * vx < 0) ? -1.0 : 1.0; + double angleExtent = sign * ((p / n < -1.0) ? PI : (p / n > 1.0) ? 0 : std::acos(p / n)); + if(!sweepFlag && angleExtent > 0.0) + { + angleExtent -= PI * 2.0; + } + else if(sweepFlag && angleExtent < 0.0) + { + angleExtent += PI * 2.0; + } + + int numSegments = int(std::ceil(std::abs(angleExtent) * 2.0 / PI)); + double angleIncrement = angleExtent / numSegments; + double controlLength = 4.0 / 3.0 * std::sin(angleIncrement / 2.0) / (1.0 + std::cos(angleIncrement / 2.0)); + std::unique_ptr coords(new double[numSegments * 6]); + std::size_t pos = 0; + for(int i = 0;i < numSegments;i++) + { + double angle = angleStart + i * angleIncrement; + double dx = std::cos(angle); + double dy = std::sin(angle); + + coords[pos++] = dx - controlLength * dy; + coords[pos++] = dy + controlLength * dx; + + angle += angleIncrement; + dx = std::cos(angle); + dy = std::sin(angle); + + coords[pos++] = dx + controlLength * dy; + coords[pos++] = dy - controlLength * dx; + coords[pos++] = dx; + coords[pos++] = dy; + } + + AffineTransform m; + m *= AffineTransform::fromScale(rx, ry); + m *= AffineTransform::fromRotate(xAxisRotation * PI / 180.0); + m *= AffineTransform::fromTranslate(cx, cy); + m.map(coords.get(), coords.get(), int(pos)); + + coords[pos - 2] = x; + coords[pos - 1] = y; + + for(std::size_t i = 0;i < pos;i+=6) + cubicTo(coords[i], coords[i+1], coords[i+2], coords[i+3], coords[i+4], coords[i+5]); +} + void Path::smoothQuadTo(double x2, double y2, bool rel) { if(rel) diff --git a/source/geometry/path.h b/source/geometry/path.h index b4fddeb..c878552 100755 --- a/source/geometry/path.h +++ b/source/geometry/path.h @@ -29,6 +29,7 @@ class Path void lineTo(double x1, double y1, bool rel = false); void quadTo(double x1, double y1, double x2, double y2, bool rel = false); void cubicTo(double x1, double y1, double x2, double y2, double x3, double y3, bool rel = false); + void arcTo(double rx, double ry, double xAxisRotation, bool largeArcFlag, bool sweepFlag, double x, double y, bool rel = false); void smoothQuadTo(double x2, double y2, bool rel = false); void smoothCubicTo(double x2, double y2, double x3, double y3, bool rel = false); void horizontalTo(double x, bool rel = false); diff --git a/source/geometry/pathiterator.cpp b/source/geometry/pathiterator.cpp index 5feb98f..f0511a1 100755 --- a/source/geometry/pathiterator.cpp +++ b/source/geometry/pathiterator.cpp @@ -3,10 +3,10 @@ namespace lunasvg { -PathIterator::PathIterator(const Path& path) : - m_segments(path.segments()), - m_coordinates(path.coordinates().data()), - m_index(0) +PathIterator::PathIterator(const Path& path) + : m_segments(path.segments()), + m_coordinates(path.coordinates().data()), + m_index(0) { } diff --git a/source/geometry/pathutils.cpp b/source/geometry/pathutils.cpp deleted file mode 100755 index 925fd49..0000000 --- a/source/geometry/pathutils.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "pathutils.h" -#include "path.h" - -#include - -namespace lunasvg { - -#define K_PI 3.14159265358979323846 - -namespace Utils { - -static void path_arc_segment(Path& path, double xc, double yc, double th0, double th1, double rx, double ry, double xAxisRotation) -{ - double sinTh, cosTh; - double a00, a01, a10, a11; - double x1, y1, x2, y2, x3, y3; - double t; - double thHalf; - - sinTh = sin(xAxisRotation * double(K_PI / 180.0)); - cosTh = cos(xAxisRotation * double(K_PI / 180.0)); - - a00 = cosTh * rx; - a01 = -sinTh * ry; - a10 = sinTh * rx; - a11 = cosTh * ry; - - thHalf = 0.5 * (th1 - th0); - t = (8.0 / 3.0) * sin(thHalf * 0.5) * sin(thHalf * 0.5) / sin(thHalf); - x1 = xc + cos(th0) - t * sin(th0); - y1 = yc + sin(th0) + t * cos(th0); - x3 = xc + cos(th1); - y3 = yc + sin(th1); - x2 = x3 + t * sin(th1); - y2 = y3 - t * cos(th1); - - path.cubicTo(a00 * x1 + a01 * y1, - a10 * x1 + a11 * y1, - a00 * x2 + a01 * y2, - a10 * x2 + a11 * y2, - a00 * x3 + a01 * y3, - a10 * x3 + a11 * y3); -} - -void pathArcTo(Path& path, double rx, double ry, double xAxisRotation, bool largeArcFlag, bool sweepFlag, double x, double y, bool rel) -{ - Point cp = path.currentPoint(); - if(rel) - { - x += cp.x; - y += cp.y; - } - - double sin_th, cos_th; - double a00, a01, a10, a11; - double x0, y0, x1, y1, xc, yc; - double d, sfactor, sfactor_sq; - double th0, th1, th_arc; - int i, n_segs; - double dx, dy, dx1, dy1, Pr1, Pr2, Px, Py, check; - - rx = fabs(rx); - ry = fabs(ry); - - sin_th = sin(xAxisRotation * double(K_PI / 180.0)); - cos_th = cos(xAxisRotation * double(K_PI / 180.0)); - - dx = (cp.x - x) / 2.0; - dy = (cp.y - y) / 2.0; - dx1 = cos_th * dx + sin_th * dy; - dy1 = -sin_th * dx + cos_th * dy; - Pr1 = rx * rx; - Pr2 = ry * ry; - Px = dx1 * dx1; - Py = dy1 * dy1; - check = Px / Pr1 + Py / Pr2; - if(check > 1) - { - rx = rx * sqrt(check); - ry = ry * sqrt(check); - } - - a00 = cos_th / rx; - a01 = sin_th / rx; - a10 = -sin_th / ry; - a11 = cos_th / ry; - x0 = a00 * cp.x + a01 * cp.y; - y0 = a10 * cp.x + a11 * cp.y; - x1 = a00 * x + a01 * y; - y1 = a10 * x + a11 * y; - d = (x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0); - sfactor_sq = 1.0 / d - 0.25; - if(sfactor_sq < 0) sfactor_sq = 0; - sfactor = sqrt(sfactor_sq); - if(sweepFlag == largeArcFlag) sfactor = -sfactor; - xc = 0.5 * (x0 + x1) - sfactor * (y1 - y0); - yc = 0.5 * (y0 + y1) + sfactor * (x1 - x0); - - th0 = atan2(y0 - yc, x0 - xc); - th1 = atan2(y1 - yc, x1 - xc); - - th_arc = th1 - th0; - if(th_arc < 0 && sweepFlag) - th_arc += double(2 * K_PI); - else if(th_arc > 0 && !sweepFlag) - th_arc -= double(2 * K_PI); - - n_segs = int(ceil(fabs(th_arc / double(K_PI * 0.5 + 0.001)))); - for(i = 0; i < n_segs; i++) - path_arc_segment(path, xc, yc, th0 + i * th_arc / n_segs, th0 + (i + 1) * th_arc / n_segs, rx, ry, xAxisRotation); -} - -} // namespace Utils - -} // namespace lunasvg diff --git a/source/geometry/pathutils.h b/source/geometry/pathutils.h deleted file mode 100755 index 8459c31..0000000 --- a/source/geometry/pathutils.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef PATHUTILS_H -#define PATHUTILS_H - -namespace lunasvg { - -class Path; - -namespace Utils { - -void pathArcTo(Path& path, double rx, double ry, double xAxisRotation, bool largeArcFlag, bool sweepFlag, double x, double y, bool rel); - -} // namespace Utils - -} // namespace lunasvg - -#endif // PATHUTILS_H diff --git a/source/graphics/canvas.cpp b/source/graphics/canvas.cpp index c176672..f67b35e 100755 --- a/source/graphics/canvas.cpp +++ b/source/graphics/canvas.cpp @@ -7,13 +7,13 @@ Canvas::Canvas() { } -Canvas::Canvas(unsigned char* data, unsigned int width, unsigned int height, unsigned int stride) : - m_impl(new CanvasImpl(data, width, height, stride)) +Canvas::Canvas(unsigned char* data, unsigned int width, unsigned int height, unsigned int stride) + : m_impl(new CanvasImpl(data, width, height, stride)) { } -Canvas::Canvas(unsigned int width, unsigned int height) : - m_impl(new CanvasImpl(width, height)) +Canvas::Canvas(unsigned int width, unsigned int height) + : m_impl(new CanvasImpl(width, height)) { } diff --git a/source/graphics/pattern.cpp b/source/graphics/pattern.cpp index 90ecc8f..6274f8b 100644 --- a/source/graphics/pattern.cpp +++ b/source/graphics/pattern.cpp @@ -6,9 +6,9 @@ Pattern::Pattern() { } -Pattern::Pattern(const Canvas& canvas) : - m_tile(canvas), - m_tileMode(TileModeRepeat) +Pattern::Pattern(const Canvas& canvas) + : m_tile(canvas), + m_tileMode(TileModeRepeat) { } diff --git a/source/graphics/rgb.cpp b/source/graphics/rgb.cpp index af7afc2..a34a3b8 100755 --- a/source/graphics/rgb.cpp +++ b/source/graphics/rgb.cpp @@ -2,27 +2,21 @@ namespace lunasvg { -Rgb::Rgb() : - r(0), - g(0), - b(0), - a(255) +Rgb::Rgb() + : r(0), g(0), b(0), a(255) { } -Rgb::Rgb(unsigned int value) : - r((value&0xff000000)>>24), - g((value&0x00ff0000)>>16), - b((value&0x0000ff00)>>8 ), - a((value&0x000000ff)>>0 ) +Rgb::Rgb(unsigned int value) + : r((value&0xff000000)>>24), + g((value&0x00ff0000)>>16), + b((value&0x0000ff00)>>8 ), + a((value&0x000000ff)>>0 ) { } -Rgb::Rgb(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha) : - r(red), - g(green), - b(blue), - a(alpha) +Rgb::Rgb(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha) + : r(red), g(green), b(blue), a(alpha) { } diff --git a/source/graphics/strokedata.cpp b/source/graphics/strokedata.cpp index a2dc8c8..a302608 100644 --- a/source/graphics/strokedata.cpp +++ b/source/graphics/strokedata.cpp @@ -3,12 +3,8 @@ namespace lunasvg { -StrokeData::StrokeData() : - m_width(1.0), - m_miterLimit(4.0), - m_cap(LineCapButt), - m_join(LineJoinMiter), - m_dashOffset(0.0) +StrokeData::StrokeData() + : m_width(1.0), m_miterLimit(4.0), m_cap(LineCapButt), m_join(LineJoinMiter), m_dashOffset(0.0) { } diff --git a/source/rendercontext.cpp b/source/rendercontext.cpp index 4f49c29..d42a1a1 100755 --- a/source/rendercontext.cpp +++ b/source/rendercontext.cpp @@ -49,7 +49,6 @@ void RenderStyle::inheritFrom(const RenderStyle& style) switch(i) { case CSSPropertyIdDisplay: - case CSSPropertyIdClip: case CSSPropertyIdClip_Path: case CSSPropertyIdOverflow: case CSSPropertyIdStop_Color: @@ -266,10 +265,10 @@ RenderContext::~RenderContext() delete m_state; } -RenderContext::RenderContext(const SVGElementImpl* element, RenderMode mode) : - m_mode(mode), - m_state(new RenderState()), - m_current(element) +RenderContext::RenderContext(const SVGElementImpl* element, RenderMode mode) + : m_mode(mode), + m_state(new RenderState()), + m_current(element) { } diff --git a/source/svgcircleelement.cpp b/source/svgcircleelement.cpp index 3af5040..099ddc3 100755 --- a/source/svgcircleelement.cpp +++ b/source/svgcircleelement.cpp @@ -2,11 +2,11 @@ namespace lunasvg { -SVGCircleElement::SVGCircleElement(SVGDocument* document) : - SVGGeometryElement(ElementIdCircle, document), - m_cx(DOMPropertyIdCx, LengthModeWidth, AllowNegativeLengths), - m_cy(DOMPropertyIdCy, LengthModeHeight, AllowNegativeLengths), - m_r(DOMPropertyIdR, LengthModeBoth, ForbidNegativeLengths) +SVGCircleElement::SVGCircleElement(SVGDocument* document) + : SVGGeometryElement(DOMElementIdCircle, document), + m_cx(DOMPropertyIdCx, LengthModeWidth, AllowNegativeLengths), + m_cy(DOMPropertyIdCy, LengthModeHeight, AllowNegativeLengths), + m_r(DOMPropertyIdR, LengthModeBoth, ForbidNegativeLengths) { addToPropertyMap(m_cx); addToPropertyMap(m_cy); diff --git a/source/svgclippathelement.cpp b/source/svgclippathelement.cpp index 88add89..3491bee 100644 --- a/source/svgclippathelement.cpp +++ b/source/svgclippathelement.cpp @@ -3,9 +3,9 @@ namespace lunasvg { -SVGClipPathElement::SVGClipPathElement(SVGDocument* document) : - SVGGraphicsElement(ElementIdClipPath, document), - m_clipPathUnits(DOMPropertyIdClipPathUnits) +SVGClipPathElement::SVGClipPathElement(SVGDocument* document) + : SVGGraphicsElement(DOMElementIdClipPath, document), + m_clipPathUnits(DOMPropertyIdClipPathUnits) { addToPropertyMap(m_clipPathUnits); } @@ -38,7 +38,7 @@ void SVGClipPathElement::applyClip(RenderState& state) const void SVGClipPathElement::render(RenderContext& context) const { - if(context.state().element->elementId() != ElementIdClipPath) + if(context.state().element->elementId() != DOMElementIdClipPath) { context.skipElement(); return; diff --git a/source/svgcolor.cpp b/source/svgcolor.cpp index 3aea465..6f7095f 100755 --- a/source/svgcolor.cpp +++ b/source/svgcolor.cpp @@ -157,9 +157,9 @@ static const std::map colormap = { {"yellowgreen", 0x9ACD32FF} }; -SVGColor::SVGColor() : - SVGProperty(PropertyTypeColor), - m_colorType(ColorTypeRgb) +SVGColor::SVGColor() + : SVGProperty(PropertyTypeColor), + m_colorType(ColorTypeRgb) { } @@ -186,8 +186,9 @@ bool SVGColor::parseColorComponent(const char*& ptr, double& value) return false; if(Utils::skipDesc(ptr, "%", 1)) - value *= 2.55; + value *= 2.56; + value = (value < 0.0) ? 0.0 : (value > 255.0) ? 255.0 : std::round(value); return true; } diff --git a/source/svgdefselement.cpp b/source/svgdefselement.cpp index 0844306..6cf3623 100755 --- a/source/svgdefselement.cpp +++ b/source/svgdefselement.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGDefsElement::SVGDefsElement(SVGDocument* document) : - SVGGraphicsElement(ElementIdDefs, document) +SVGDefsElement::SVGDefsElement(SVGDocument* document) + : SVGGraphicsElement(DOMElementIdDefs, document) { } diff --git a/source/svgdocument.cpp b/source/svgdocument.cpp index 01cf278..3882255 100755 --- a/source/svgdocument.cpp +++ b/source/svgdocument.cpp @@ -5,8 +5,8 @@ namespace lunasvg { SVGDocument::SVGDocument() + : m_impl(new SVGDocumentImpl(this)) { - m_impl = new SVGDocumentImpl(this); } SVGElement* SVGDocument::getElementById(const std::string& id, int index) const diff --git a/source/svgdocumentimpl.cpp b/source/svgdocumentimpl.cpp index b4d3d5e..82b65fb 100755 --- a/source/svgdocumentimpl.cpp +++ b/source/svgdocumentimpl.cpp @@ -7,8 +7,8 @@ namespace lunasvg { -SVGDocumentImpl::SVGDocumentImpl(SVGDocument* document) : - m_svgParser(new SVGParser(document)) +SVGDocumentImpl::SVGDocumentImpl(SVGDocument* document) + : m_svgParser(new SVGParser(document)) { m_rootElement = new SVGRootElement(document); m_rootElement->tail = new SVGElementTail(document); @@ -29,13 +29,14 @@ SVGDocumentImpl::~SVGDocumentImpl() bool SVGDocumentImpl::loadFromFile(const std::string& filename) { - std::fstream fs; + std::ifstream fs; fs.open(filename.c_str()); if(!fs.is_open()) return false; std::string content; std::getline(fs, content, '\0'); + fs.close(); return loadFromData(content); } @@ -332,54 +333,54 @@ void SVGDocumentImpl::insertElement(SVGElementImpl* head, SVGElementImpl* tail, switch(position) { - case BeforeBegin: - { - SVGElementImpl* targetPrev = target->prev; + case BeforeBegin: + { + SVGElementImpl* targetPrev = target->prev; - targetPrev->next = head; - head->prev = targetPrev; + targetPrev->next = head; + head->prev = targetPrev; - target->prev = tail; - tail->next = target; - break; - } - case AfterBegin: - { - SVGElementImpl* targetNext = target->next; + target->prev = tail; + tail->next = target; + break; + } + case AfterBegin: + { + SVGElementImpl* targetNext = target->next; - target->next = head; - head->prev = target; + target->next = head; + head->prev = target; - targetNext->prev = tail; - tail->next = targetNext; - break; - } - case BeforeEnd: - { - assert(target->isSVGElementHead()); - target = to(target)->tail; - SVGElementImpl* targetPrev = target->prev; + targetNext->prev = tail; + tail->next = targetNext; + break; + } + case BeforeEnd: + { + assert(target->isSVGElementHead()); + target = to(target)->tail; + SVGElementImpl* targetPrev = target->prev; - targetPrev->next = head; - head->prev = targetPrev; + targetPrev->next = head; + head->prev = targetPrev; - target->prev = tail; - tail->next = target; - break; - } - case AfterEnd: - { - assert(target->isSVGElementHead()); - target = to(target)->tail; - SVGElementImpl* targetNext = target->next; + target->prev = tail; + tail->next = target; + break; + } + case AfterEnd: + { + assert(target->isSVGElementHead()); + target = to(target)->tail; + SVGElementImpl* targetNext = target->next; - target->next = head; - head->prev = target; + target->next = head; + head->prev = target; - targetNext->prev = tail; - tail->next = targetNext; - break; - } + targetNext->prev = tail; + tail->next = targetNext; + break; + } } } diff --git a/source/svgelement.cpp b/source/svgelement.cpp index d5e6d4d..c8eab01 100755 --- a/source/svgelement.cpp +++ b/source/svgelement.cpp @@ -5,13 +5,25 @@ namespace lunasvg { -Bitmap::Impl::Impl(std::uint8_t* data, std::uint32_t width, std::uint32_t height, std::uint32_t stride) : - data(data), width(width), height(height), stride(stride) +struct Bitmap::Impl +{ + Impl(std::uint8_t* data, std::uint32_t width, std::uint32_t height, std::uint32_t stride); + Impl(std::uint32_t width, std::uint32_t height); + + std::unique_ptr ownData; + std::uint8_t* data; + std::uint32_t width; + std::uint32_t height; + std::uint32_t stride; +}; + +Bitmap::Impl::Impl(std::uint8_t* data, std::uint32_t width, std::uint32_t height, std::uint32_t stride) + : data(data), width(width), height(height), stride(stride) { } -Bitmap::Impl::Impl(std::uint32_t width, std::uint32_t height) : - ownData(new std::uint8_t[width*height*4]), data(nullptr), width(width), height(height), stride(width * 4) +Bitmap::Impl::Impl(std::uint32_t width, std::uint32_t height) + : ownData(new std::uint8_t[width*height*4]), data(nullptr), width(width), height(height), stride(width * 4) { } @@ -19,13 +31,13 @@ Bitmap::Bitmap() { } -Bitmap::Bitmap(std::uint8_t* data, std::uint32_t width, std::uint32_t height, std::uint32_t stride) : - m_impl(new Impl(data, width, height, stride)) +Bitmap::Bitmap(std::uint8_t* data, std::uint32_t width, std::uint32_t height, std::uint32_t stride) + : m_impl(new Impl(data, width, height, stride)) { } -Bitmap::Bitmap(std::uint32_t width, std::uint32_t height) : - m_impl(new Impl(width, height)) +Bitmap::Bitmap(std::uint32_t width, std::uint32_t height) + : m_impl(new Impl(width, height)) { } @@ -59,8 +71,8 @@ std::uint32_t Bitmap::stride() const return m_impl ? m_impl->stride : 0; } -SVGElement::SVGElement(SVGDocument* document) : - m_document(document) +SVGElement::SVGElement(SVGDocument* document) + : m_document(document) { } diff --git a/source/svgelementhead.cpp b/source/svgelementhead.cpp index fc156a2..35542a5 100755 --- a/source/svgelementhead.cpp +++ b/source/svgelementhead.cpp @@ -5,9 +5,9 @@ namespace lunasvg { -SVGElementHead::SVGElementHead(ElementID elementId, SVGDocument* document) : - SVGElementImpl(document), - m_elementId(elementId) +SVGElementHead::SVGElementHead(DOMElementID elementId, SVGDocument* document) + : SVGElementImpl(document), + m_elementId(elementId) { } @@ -18,7 +18,7 @@ SVGElementHead::~SVGElementHead() const std::string& SVGElementHead::tagName() const { - return Utils::elementName(m_elementId); + return Utils::domElementName(m_elementId); } void SVGElementHead::setAttribute(const std::string& name, const std::string& value) @@ -57,7 +57,7 @@ void SVGElementHead::externalise(std::string& out, std::uint32_t& indent) const { out.append(indent, '\t'); out += '<'; - out += Utils::elementName(m_elementId); + out += Utils::domElementName(m_elementId); if(isSVGRootElement()) { out += ' '; @@ -126,7 +126,7 @@ void SVGElementHead::externaliseTail(std::string& out, std::uint32_t& indent) co out.append(indent, '\t'); out += '<'; out += '/'; - out += Utils::elementName(m_elementId); + out += Utils::domElementName(m_elementId); out += '>'; out += '\n'; } diff --git a/source/svgelementhead.h b/source/svgelementhead.h index 6dfc79a..924b0be 100755 --- a/source/svgelementhead.h +++ b/source/svgelementhead.h @@ -27,7 +27,7 @@ class SVGElementHead : public SVGElementImpl void removeProperty(DOMPropertyID nameId); const std::string& tagName() const; const std::string& id() const { return m_id; } - ElementID elementId() const { return m_elementId; } + DOMElementID elementId() const { return m_elementId; } bool isSVGElementHead() const { return true; } SVGElementTail* tail; @@ -36,11 +36,11 @@ class SVGElementHead : public SVGElementImpl void updateId(const std::string& newValue); protected: - SVGElementHead(ElementID elementId, SVGDocument* document); + SVGElementHead(DOMElementID elementId, SVGDocument* document); void baseClone(SVGElementHead& e) const; private: - ElementID m_elementId; + DOMElementID m_elementId; std::string m_id; std::vector m_properties; }; diff --git a/source/svgelementimpl.cpp b/source/svgelementimpl.cpp index 99e45f2..1d7dfb0 100755 --- a/source/svgelementimpl.cpp +++ b/source/svgelementimpl.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGElementImpl::SVGElementImpl(SVGDocument* document) : - SVGElement(document) +SVGElementImpl::SVGElementImpl(SVGDocument* document) + : SVGElement(document) { } diff --git a/source/svgelementimpl.h b/source/svgelementimpl.h index 9fcf691..92abff2 100755 --- a/source/svgelementimpl.h +++ b/source/svgelementimpl.h @@ -32,7 +32,7 @@ class SVGElementImpl : public SVGElement virtual void removeAttribute(const std::string&) {} virtual const std::string& tagName() const { return KEmptyString; } virtual const std::string& id() const { return KEmptyString; } - virtual ElementID elementId() const { return ElementIdUnknown; } + virtual DOMElementID elementId() const { return DOMElementIdUnknown; } virtual void render(RenderContext& context) const = 0; virtual void externalise(std::string& out, unsigned int& indent) const = 0; virtual SVGElementImpl* clone(SVGDocument* document) const = 0; diff --git a/source/svgelementiter.cpp b/source/svgelementiter.cpp index 91f4eff..793b108 100755 --- a/source/svgelementiter.cpp +++ b/source/svgelementiter.cpp @@ -8,7 +8,7 @@ SVGElementIter::SVGElementIter(const SVGElement* element, const std::string& id, { m_element = to(element); m_id.assign(id); - m_elementId = tagName.empty() ? ElementLastId : Utils::elementId(tagName); + m_elementId = tagName.empty() ? DOMElementLastId : Utils::domElementId(tagName); m_currentElement = m_element->isSVGElementHead() ? const_cast(m_element) : nullptr; } @@ -22,7 +22,7 @@ bool SVGElementIter::next() { if(!m_currentElement->isSVGElementTail()) { - if((m_elementId==ElementLastId || m_elementId==m_currentElement->elementId()) && (m_id.length()==0 || m_id==m_currentElement->id())) + if((m_elementId==DOMElementLastId || m_elementId==m_currentElement->elementId()) && (m_id.length()==0 || m_id==m_currentElement->id())) return true; } diff --git a/source/svgelementtail.cpp b/source/svgelementtail.cpp index 12afe38..6e7213d 100755 --- a/source/svgelementtail.cpp +++ b/source/svgelementtail.cpp @@ -3,8 +3,8 @@ namespace lunasvg { -SVGElementTail::SVGElementTail(SVGDocument* document) : - SVGElementImpl(document) +SVGElementTail::SVGElementTail(SVGDocument* document) + : SVGElementImpl(document) { } diff --git a/source/svgelementtext.cpp b/source/svgelementtext.cpp index ee7bad2..b8c54c4 100644 --- a/source/svgelementtext.cpp +++ b/source/svgelementtext.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGElementText::SVGElementText(SVGDocument* document) : - SVGElementImpl(document) +SVGElementText::SVGElementText(SVGDocument* document) + : SVGElementImpl(document) { } diff --git a/source/svgelementutils.cpp b/source/svgelementutils.cpp index 5108169..22dc952 100755 --- a/source/svgelementutils.cpp +++ b/source/svgelementutils.cpp @@ -1,3 +1,4 @@ +#include "svgelementutils.h" #include "svgsvgelement.h" #include "svggelement.h" #include "svgrectelement.h" @@ -25,252 +26,252 @@ namespace lunasvg { namespace Utils { #define KElementIdsAnimation \ - ElementIdAnimate, \ - ElementIdAnimateMotion, \ - ElementIdAnimateTransform, \ - ElementIdAnimateColor, \ - ElementIdSet + DOMElementIdAnimate, \ + DOMElementIdAnimateMotion, \ + DOMElementIdAnimateTransform, \ + DOMElementIdAnimateColor, \ + DOMElementIdSet #define KElementIdsDescriptive \ - ElementIdDesc, \ - ElementIdTitle, \ - ElementIdMetadata + DOMElementIdDesc, \ + DOMElementIdTitle, \ + DOMElementIdMetadata #define KElementIdsGradient \ - ElementIdLinearGradient, \ - ElementIdRadialGradient + DOMElementIdLinearGradient, \ + DOMElementIdRadialGradient #define KElementIdsStructural \ - ElementIdDefs, \ - ElementIdG, \ - ElementIdSvg, \ - ElementIdSymbol, \ - ElementIdUse + DOMElementIdDefs, \ + DOMElementIdG, \ + DOMElementIdSvg, \ + DOMElementIdSymbol, \ + DOMElementIdUse #define KElementIdsShape \ - ElementIdCircle, \ - ElementIdEllipse, \ - ElementIdLine, \ - ElementIdPath, \ - ElementIdPolygon, \ - ElementIdPolyline, \ - ElementIdRect + DOMElementIdCircle, \ + DOMElementIdEllipse, \ + DOMElementIdLine, \ + DOMElementIdPath, \ + DOMElementIdPolygon, \ + DOMElementIdPolyline, \ + DOMElementIdRect #define KElementIdsTextContentChild \ - ElementIdTextPath, \ - ElementIdTref, \ - ElementIdTspan + DOMElementIdTextPath, \ + DOMElementIdTref, \ + DOMElementIdTspan -static const ElementID contentmodel_1[] = { +static const DOMElementID contentmodel_1[] = { KElementIdsAnimation, KElementIdsShape, KElementIdsDescriptive, KElementIdsStructural, KElementIdsGradient, - ElementIdA, - ElementIdClipPath, - ElementIdImage, - ElementIdMarker, - ElementIdMask, - ElementIdPattern, - ElementIdStyle, - ElementIdSwitch, - ElementIdText, - ElementIdView, - ElementIdUnknown + DOMElementIdA, + DOMElementIdClipPath, + DOMElementIdImage, + DOMElementIdMarker, + DOMElementIdMask, + DOMElementIdPattern, + DOMElementIdStyle, + DOMElementIdSwitch, + DOMElementIdText, + DOMElementIdView, + DOMElementIdUnknown }; -static const ElementID contentmodel_2[] = { +static const DOMElementID contentmodel_2[] = { KElementIdsAnimation, KElementIdsDescriptive, - ElementIdUnknown + DOMElementIdUnknown }; -static const ElementID contentmodel_3[] = { +static const DOMElementID contentmodel_3[] = { //KElementAllIds, - ElementIdUnknown + DOMElementIdUnknown }; -static const ElementID contentmodel_4[] = { +static const DOMElementID contentmodel_4[] = { KElementIdsDescriptive, - ElementIdUnknown + DOMElementIdUnknown }; -static const ElementID contentmodel_5[] = { +static const DOMElementID contentmodel_5[] = { KElementIdsAnimation, KElementIdsShape, KElementIdsDescriptive, - ElementIdA, - ElementIdG, - ElementIdImage, - ElementIdSvg, - ElementIdSwitch, - ElementIdText, - ElementIdUse, - ElementIdUnknown + DOMElementIdA, + DOMElementIdG, + DOMElementIdImage, + DOMElementIdSvg, + DOMElementIdSwitch, + DOMElementIdText, + DOMElementIdUse, + DOMElementIdUnknown }; -static const ElementID contentmodel_6[] = { +static const DOMElementID contentmodel_6[] = { KElementIdsAnimation, KElementIdsDescriptive, KElementIdsTextContentChild, - ElementIdA, - ElementIdUnknown + DOMElementIdA, + DOMElementIdUnknown }; -static const ElementID contentmodel_7[] = { +static const DOMElementID contentmodel_7[] = { KElementIdsDescriptive, - ElementIdA, - ElementIdAnimate, - ElementIdAnimateColor, - ElementIdSet, - ElementIdTref, - ElementIdTspan, - ElementIdUnknown + DOMElementIdA, + DOMElementIdAnimate, + DOMElementIdAnimateColor, + DOMElementIdSet, + DOMElementIdTref, + DOMElementIdTspan, + DOMElementIdUnknown }; -static const ElementID contentmodel_8[] = { +static const DOMElementID contentmodel_8[] = { KElementIdsDescriptive, - ElementIdAnimate, - ElementIdAnimateColor, - ElementIdSet, - ElementIdUnknown + DOMElementIdAnimate, + DOMElementIdAnimateColor, + DOMElementIdSet, + DOMElementIdUnknown }; -static const ElementID contentmodel_9[] = { +static const DOMElementID contentmodel_9[] = { KElementIdsGradient, - ElementIdSolidColor, - ElementIdPattern, - ElementIdAnimate, - ElementIdAnimateColor, - ElementIdSet, - ElementIdUnknown + DOMElementIdSolidColor, + DOMElementIdPattern, + DOMElementIdAnimate, + DOMElementIdAnimateColor, + DOMElementIdSet, + DOMElementIdUnknown }; -static const ElementID contentmodel_11[] = { +static const DOMElementID contentmodel_11[] = { KElementIdsAnimation, KElementIdsShape, KElementIdsDescriptive, - ElementIdUse, - ElementIdText, - ElementIdUnknown + DOMElementIdUse, + DOMElementIdText, + DOMElementIdUnknown }; -static const ElementID contentmodel_12[] = { +static const DOMElementID contentmodel_12[] = { KElementIdsDescriptive, - ElementIdAnimate, - ElementIdAnimateTransform, - ElementIdSet, - ElementIdStop, - ElementIdUnknown + DOMElementIdAnimate, + DOMElementIdAnimateTransform, + DOMElementIdSet, + DOMElementIdStop, + DOMElementIdUnknown }; -static const ElementID contentmodel_13[] = { - ElementIdAnimate, - ElementIdAnimateColor, - ElementIdSet, - ElementIdUnknown +static const DOMElementID contentmodel_13[] = { + DOMElementIdAnimate, + DOMElementIdAnimateColor, + DOMElementIdSet, + DOMElementIdUnknown }; -static const ElementID contentmodel_23[] = { +static const DOMElementID contentmodel_23[] = { KElementIdsDescriptive, - ElementIdMpath, - ElementIdUnknown + DOMElementIdMpath, + DOMElementIdUnknown }; static const struct { - ElementID id; - const ElementID* content; + DOMElementID id; + const DOMElementID* content; } contentmodelmap[] = { - {ElementIdUnknown, nullptr}, - {ElementIdA, contentmodel_1}, - {ElementIdAnimate, contentmodel_4}, - {ElementIdAnimateColor, contentmodel_4}, - {ElementIdAnimateMotion, contentmodel_23}, - {ElementIdAnimateTransform, contentmodel_4}, - {ElementIdCircle, contentmodel_2}, - {ElementIdClipPath, contentmodel_11}, - {ElementIdDefs, contentmodel_1}, - {ElementIdDesc, contentmodel_3}, - {ElementIdEllipse, contentmodel_2}, - {ElementIdG, contentmodel_1}, - {ElementIdImage, contentmodel_2}, - {ElementIdLine, contentmodel_2}, - {ElementIdLinearGradient, contentmodel_12}, - {ElementIdMarker, contentmodel_1}, - {ElementIdMask, contentmodel_1}, - {ElementIdMetadata, contentmodel_3}, - {ElementIdMpath, contentmodel_23}, - {ElementIdPath, contentmodel_2}, - {ElementIdPattern, contentmodel_1}, - {ElementIdPolygon, contentmodel_2}, - {ElementIdPolyline, contentmodel_2}, - {ElementIdRadialGradient, contentmodel_12}, - {ElementIdRect, contentmodel_2}, - {ElementIdSet, contentmodel_4}, - {ElementIdSolidColor, contentmodel_9}, - {ElementIdStop, contentmodel_13}, - {ElementIdStyle, contentmodel_3}, - {ElementIdSvg, contentmodel_1}, - {ElementIdSwitch, contentmodel_5}, - {ElementIdSymbol, contentmodel_1}, - {ElementIdText, contentmodel_6}, - {ElementIdTextPath, contentmodel_7}, - {ElementIdTitle, contentmodel_3}, - {ElementIdTref, contentmodel_8}, - {ElementIdTspan, contentmodel_7}, - {ElementIdUse, contentmodel_2}, - {ElementIdView, contentmodel_4}, - {ElementLastId, nullptr} + {DOMElementIdUnknown, nullptr}, + {DOMElementIdA, contentmodel_1}, + {DOMElementIdAnimate, contentmodel_4}, + {DOMElementIdAnimateColor, contentmodel_4}, + {DOMElementIdAnimateMotion, contentmodel_23}, + {DOMElementIdAnimateTransform, contentmodel_4}, + {DOMElementIdCircle, contentmodel_2}, + {DOMElementIdClipPath, contentmodel_11}, + {DOMElementIdDefs, contentmodel_1}, + {DOMElementIdDesc, contentmodel_3}, + {DOMElementIdEllipse, contentmodel_2}, + {DOMElementIdG, contentmodel_1}, + {DOMElementIdImage, contentmodel_2}, + {DOMElementIdLine, contentmodel_2}, + {DOMElementIdLinearGradient, contentmodel_12}, + {DOMElementIdMarker, contentmodel_1}, + {DOMElementIdMask, contentmodel_1}, + {DOMElementIdMetadata, contentmodel_3}, + {DOMElementIdMpath, contentmodel_23}, + {DOMElementIdPath, contentmodel_2}, + {DOMElementIdPattern, contentmodel_1}, + {DOMElementIdPolygon, contentmodel_2}, + {DOMElementIdPolyline, contentmodel_2}, + {DOMElementIdRadialGradient, contentmodel_12}, + {DOMElementIdRect, contentmodel_2}, + {DOMElementIdSet, contentmodel_4}, + {DOMElementIdSolidColor, contentmodel_9}, + {DOMElementIdStop, contentmodel_13}, + {DOMElementIdStyle, contentmodel_3}, + {DOMElementIdSvg, contentmodel_1}, + {DOMElementIdSwitch, contentmodel_5}, + {DOMElementIdSymbol, contentmodel_1}, + {DOMElementIdText, contentmodel_6}, + {DOMElementIdTextPath, contentmodel_7}, + {DOMElementIdTitle, contentmodel_3}, + {DOMElementIdTref, contentmodel_8}, + {DOMElementIdTspan, contentmodel_7}, + {DOMElementIdUse, contentmodel_2}, + {DOMElementIdView, contentmodel_4}, + {DOMElementLastId, nullptr} }; -static const std::map elementmap = { - {"a", ElementIdA}, - {"animate", ElementIdAnimate}, - {"animateColor", ElementIdAnimateColor}, - {"animateMotion", ElementIdAnimateMotion}, - {"animateTransform", ElementIdAnimateTransform}, - {"circle", ElementIdCircle}, - {"clipPath", ElementIdClipPath}, - {"defs", ElementIdDefs}, - {"desc", ElementIdDesc}, - {"ellipse", ElementIdEllipse}, - {"g", ElementIdG}, - {"image", ElementIdImage}, - {"line", ElementIdLine}, - {"linearGradient", ElementIdLinearGradient}, - {"marker", ElementIdMarker}, - {"mask", ElementIdMask}, - {"metadata", ElementIdMetadata}, - {"mpath", ElementIdMpath}, - {"path", ElementIdPath}, - {"pattern", ElementIdPattern}, - {"polygon", ElementIdPolygon}, - {"polyline", ElementIdPolyline}, - {"radialGradient", ElementIdRadialGradient}, - {"rect", ElementIdRect}, - {"set", ElementIdSet}, - {"stop", ElementIdStop}, - {"solidColor", ElementIdSolidColor}, - {"style", ElementIdStyle}, - {"svg", ElementIdSvg}, - {"switch", ElementIdSwitch}, - {"symbol", ElementIdSymbol}, - {"text", ElementIdText}, - {"textPath", ElementIdTextPath}, - {"title", ElementIdTitle}, - {"tref", ElementIdTref}, - {"tspan", ElementIdTspan}, - {"use", ElementIdUse}, - {"view", ElementIdView}, +static const std::map domelementmap = { + {"a", DOMElementIdA}, + {"animate", DOMElementIdAnimate}, + {"animateColor", DOMElementIdAnimateColor}, + {"animateMotion", DOMElementIdAnimateMotion}, + {"animateTransform", DOMElementIdAnimateTransform}, + {"circle", DOMElementIdCircle}, + {"clipPath", DOMElementIdClipPath}, + {"defs", DOMElementIdDefs}, + {"desc", DOMElementIdDesc}, + {"ellipse", DOMElementIdEllipse}, + {"g", DOMElementIdG}, + {"image", DOMElementIdImage}, + {"line", DOMElementIdLine}, + {"linearGradient", DOMElementIdLinearGradient}, + {"marker", DOMElementIdMarker}, + {"mask", DOMElementIdMask}, + {"metadata", DOMElementIdMetadata}, + {"mpath", DOMElementIdMpath}, + {"path", DOMElementIdPath}, + {"pattern", DOMElementIdPattern}, + {"polygon", DOMElementIdPolygon}, + {"polyline", DOMElementIdPolyline}, + {"radialGradient", DOMElementIdRadialGradient}, + {"rect", DOMElementIdRect}, + {"set", DOMElementIdSet}, + {"stop", DOMElementIdStop}, + {"solidColor", DOMElementIdSolidColor}, + {"style", DOMElementIdStyle}, + {"svg", DOMElementIdSvg}, + {"switch", DOMElementIdSwitch}, + {"symbol", DOMElementIdSymbol}, + {"text", DOMElementIdText}, + {"textPath", DOMElementIdTextPath}, + {"title", DOMElementIdTitle}, + {"tref", DOMElementIdTref}, + {"tspan", DOMElementIdTspan}, + {"use", DOMElementIdUse}, + {"view", DOMElementIdView}, }; -bool isElementPermitted(ElementID parentId, ElementID childId) +bool isElementPermitted(DOMElementID parentId, DOMElementID childId) { - if(const ElementID* content = contentmodelmap[parentId].content) + if(const DOMElementID* content = contentmodelmap[parentId].content) { - for(int i = 0;content[i] != ElementIdUnknown;i++) + for(int i = 0;content[i] != DOMElementIdUnknown;i++) if(content[i] == childId) return true; } @@ -278,47 +279,47 @@ bool isElementPermitted(ElementID parentId, ElementID childId) return false; } -SVGElementHead* createElement(ElementID elementId, SVGDocument* document) +SVGElementHead* createElement(DOMElementID elementId, SVGDocument* document) { switch(elementId) { - case ElementIdSvg: + case DOMElementIdSvg: return new SVGSVGElement(document); - case ElementIdPath: + case DOMElementIdPath: return new SVGPathElement(document); - case ElementIdG: + case DOMElementIdG: return new SVGGElement(document); - case ElementIdRect: + case DOMElementIdRect: return new SVGRectElement(document); - case ElementIdCircle: + case DOMElementIdCircle: return new SVGCircleElement(document); - case ElementIdEllipse: + case DOMElementIdEllipse: return new SVGEllipseElement(document); - case ElementIdLine: + case DOMElementIdLine: return new SVGLineElement(document); - case ElementIdDefs: + case DOMElementIdDefs: return new SVGDefsElement(document); - case ElementIdPolygon: + case DOMElementIdPolygon: return new SVGPolygonElement(document); - case ElementIdPolyline: + case DOMElementIdPolyline: return new SVGPolylineElement(document); - case ElementIdStop: + case DOMElementIdStop: return new SVGStopElement(document); - case ElementIdLinearGradient: + case DOMElementIdLinearGradient: return new SVGLinearGradientElement(document); - case ElementIdRadialGradient: + case DOMElementIdRadialGradient: return new SVGRadialGradientElement(document); - case ElementIdSymbol: + case DOMElementIdSymbol: return new SVGSymbolElement(document); - case ElementIdUse: + case DOMElementIdUse: return new SVGUseElement(document); - case ElementIdPattern: + case DOMElementIdPattern: return new SVGPatternElement(document); - case ElementIdMask: + case DOMElementIdMask: return new SVGMaskElement(document); - case ElementIdClipPath: + case DOMElementIdClipPath: return new SVGClipPathElement(document); - case ElementIdSolidColor: + case DOMElementIdSolidColor: return new SVGSolidColorElement(document); default: break; @@ -327,10 +328,10 @@ SVGElementHead* createElement(ElementID elementId, SVGDocument* document) return nullptr; } -const std::string& elementName(ElementID nameId) +const std::string& domElementName(DOMElementID nameId) { - std::map::const_iterator it = elementmap.begin(); - std::map::const_iterator end = elementmap.end(); + std::map::const_iterator it = domelementmap.begin(); + std::map::const_iterator end = domelementmap.end(); for(;it != end;++it) if(it->second == nameId) @@ -339,10 +340,10 @@ const std::string& elementName(ElementID nameId) return KEmptyString; } -ElementID elementId(const std::string& name) +DOMElementID domElementId(const std::string& name) { - std::map::const_iterator it = elementmap.find(name); - return it != elementmap.end() ? it->second : ElementIdUnknown; + std::map::const_iterator it = domelementmap.find(name); + return it != domelementmap.end() ? it->second : DOMElementIdUnknown; } } // namespace Utils diff --git a/source/svgelementutils.h b/source/svgelementutils.h index f44ac02..8f272c9 100755 --- a/source/svgelementutils.h +++ b/source/svgelementutils.h @@ -5,48 +5,48 @@ namespace lunasvg { -enum ElementID +enum DOMElementID { - ElementIdUnknown = 0, - ElementIdA, - ElementIdAnimate, - ElementIdAnimateColor, - ElementIdAnimateMotion, - ElementIdAnimateTransform, - ElementIdCircle, - ElementIdClipPath, - ElementIdDefs, - ElementIdDesc, - ElementIdEllipse, - ElementIdG, - ElementIdImage, - ElementIdLine, - ElementIdLinearGradient, - ElementIdMarker, - ElementIdMask, - ElementIdMetadata, - ElementIdMpath, - ElementIdPath, - ElementIdPattern, - ElementIdPolygon, - ElementIdPolyline, - ElementIdRadialGradient, - ElementIdRect, - ElementIdSet, - ElementIdSolidColor, - ElementIdStop, - ElementIdStyle, - ElementIdSvg, - ElementIdSwitch, - ElementIdSymbol, - ElementIdText, - ElementIdTextPath, - ElementIdTitle, - ElementIdTref, - ElementIdTspan, - ElementIdUse, - ElementIdView, - ElementLastId + DOMElementIdUnknown = 0, + DOMElementIdA, + DOMElementIdAnimate, + DOMElementIdAnimateColor, + DOMElementIdAnimateMotion, + DOMElementIdAnimateTransform, + DOMElementIdCircle, + DOMElementIdClipPath, + DOMElementIdDefs, + DOMElementIdDesc, + DOMElementIdEllipse, + DOMElementIdG, + DOMElementIdImage, + DOMElementIdLine, + DOMElementIdLinearGradient, + DOMElementIdMarker, + DOMElementIdMask, + DOMElementIdMetadata, + DOMElementIdMpath, + DOMElementIdPath, + DOMElementIdPattern, + DOMElementIdPolygon, + DOMElementIdPolyline, + DOMElementIdRadialGradient, + DOMElementIdRect, + DOMElementIdSet, + DOMElementIdSolidColor, + DOMElementIdStop, + DOMElementIdStyle, + DOMElementIdSvg, + DOMElementIdSwitch, + DOMElementIdSymbol, + DOMElementIdText, + DOMElementIdTextPath, + DOMElementIdTitle, + DOMElementIdTref, + DOMElementIdTspan, + DOMElementIdUse, + DOMElementIdView, + DOMElementLastId }; class SVGElementHead; @@ -54,10 +54,10 @@ class SVGDocument; namespace Utils { -const std::string& elementName(ElementID nameId); -ElementID elementId(const std::string& name); -bool isElementPermitted(ElementID parentId, ElementID childId); -SVGElementHead* createElement(ElementID elementId, SVGDocument* document); +const std::string& domElementName(DOMElementID nameId); +DOMElementID domElementId(const std::string& name); +bool isElementPermitted(DOMElementID parentId, DOMElementID childId); +SVGElementHead* createElement(DOMElementID elementId, SVGDocument* document); } // namespace Utils diff --git a/source/svgellipseelement.cpp b/source/svgellipseelement.cpp index ff022c3..efe63bf 100755 --- a/source/svgellipseelement.cpp +++ b/source/svgellipseelement.cpp @@ -2,12 +2,12 @@ namespace lunasvg { -SVGEllipseElement::SVGEllipseElement(SVGDocument* document) : - SVGGeometryElement(ElementIdEllipse, document), - m_cx(DOMPropertyIdCx, LengthModeWidth, AllowNegativeLengths), - m_cy(DOMPropertyIdCy, LengthModeHeight, AllowNegativeLengths), - m_rx(DOMPropertyIdRx, LengthModeWidth, ForbidNegativeLengths), - m_ry(DOMPropertyIdRy, LengthModeHeight, ForbidNegativeLengths) +SVGEllipseElement::SVGEllipseElement(SVGDocument* document) + : SVGGeometryElement(DOMElementIdEllipse, document), + m_cx(DOMPropertyIdCx, LengthModeWidth, AllowNegativeLengths), + m_cy(DOMPropertyIdCy, LengthModeHeight, AllowNegativeLengths), + m_rx(DOMPropertyIdRx, LengthModeWidth, ForbidNegativeLengths), + m_ry(DOMPropertyIdRy, LengthModeHeight, ForbidNegativeLengths) { addToPropertyMap(m_cx); addToPropertyMap(m_cy); diff --git a/source/svgenumeration.cpp b/source/svgenumeration.cpp index 5053959..19d7bdc 100755 --- a/source/svgenumeration.cpp +++ b/source/svgenumeration.cpp @@ -7,9 +7,9 @@ template<> const EnumEntryList& getEnumEntryList() static EnumEntryList entries; if(entries.empty()) { - entries.push_back(EnumEntry(DisplayInline, "inline")); - entries.push_back(EnumEntry(DisplayBlock, "block")); - entries.push_back(EnumEntry(DisplayNone, "none")); + entries.emplace_back(DisplayInline, "inline"); + entries.emplace_back(DisplayBlock, "block"); + entries.emplace_back(DisplayNone, "none"); } return entries; @@ -20,9 +20,9 @@ template<> const EnumEntryList& getEnumEntryList() static EnumEntryList entries; if(entries.empty()) { - entries.push_back(EnumEntry(VisibilityVisible, "visible")); - entries.push_back(EnumEntry(VisibilityHidden, "hidden")); - entries.push_back(EnumEntry(VisibilityCollaspe, "collaspe")); + entries.emplace_back(VisibilityVisible, "visible"); + entries.emplace_back(VisibilityHidden, "hidden"); + entries.emplace_back(VisibilityCollaspe, "collaspe"); } return entries; @@ -33,10 +33,10 @@ template<> const EnumEntryList& getEnumEntryList() static EnumEntryList entries; if(entries.empty()) { - entries.push_back(EnumEntry(OverflowVisible, "visible")); - entries.push_back(EnumEntry(OverflowHidden, "hidden")); - entries.push_back(EnumEntry(OverflowScroll, "scroll")); - entries.push_back(EnumEntry(OverflowAuto, "auto")); + entries.emplace_back(OverflowVisible, "visible"); + entries.emplace_back(OverflowHidden, "hidden"); + entries.emplace_back(OverflowScroll, "scroll"); + entries.emplace_back(OverflowAuto, "auto"); } return entries; @@ -47,9 +47,9 @@ template<> const EnumEntryList& getEnumEntryList() static EnumEntryList entries; if(entries.empty()) { - entries.push_back(EnumEntry(LineCapButt, "butt")); - entries.push_back(EnumEntry(LineCapRound, "round")); - entries.push_back(EnumEntry(LineCapSquare, "square")); + entries.emplace_back(LineCapButt, "butt"); + entries.emplace_back(LineCapRound, "round"); + entries.emplace_back(LineCapSquare, "square"); } return entries; @@ -60,9 +60,9 @@ template<> const EnumEntryList& getEnumEntryList() static EnumEntryList entries; if(entries.empty()) { - entries.push_back(EnumEntry(LineJoinMiter, "miter")); - entries.push_back(EnumEntry(LineJoinBevel, "bevel")); - entries.push_back(EnumEntry(LineJoinRound, "round")); + entries.emplace_back(LineJoinMiter, "miter"); + entries.emplace_back(LineJoinBevel, "bevel"); + entries.emplace_back(LineJoinRound, "round"); } return entries; @@ -73,8 +73,8 @@ template<> const EnumEntryList& getEnumEntryList() static EnumEntryList entries; if(entries.empty()) { - entries.push_back(EnumEntry(WindRuleNonZero, "nonzero")); - entries.push_back(EnumEntry(WindRuleEvenOdd, "evenodd")); + entries.emplace_back(WindRuleNonZero, "nonzero"); + entries.emplace_back(WindRuleEvenOdd, "evenodd"); } return entries; @@ -85,9 +85,9 @@ template<> const EnumEntryList& getEnumEntryList() static EnumEntryList entries; if(entries.empty()) { - entries.push_back(EnumEntry(SpreadMethodPad, "pad")); - entries.push_back(EnumEntry(SpreadMethodReflect, "reflect")); - entries.push_back(EnumEntry(SpreadMethodRepeat, "repeat")); + entries.emplace_back(SpreadMethodPad, "pad"); + entries.emplace_back(SpreadMethodReflect, "reflect"); + entries.emplace_back(SpreadMethodRepeat, "repeat"); } return entries; @@ -98,8 +98,8 @@ template<> const EnumEntryList& getEnumEntryList() static EnumEntryList entries; if(entries.empty()) { - entries.push_back(EnumEntry(UnitTypeObjectBoundingBox, "objectBoundingBox")); - entries.push_back(EnumEntry(UnitTypeUserSpaceOnUse, "userSpaceOnUse")); + entries.emplace_back(UnitTypeObjectBoundingBox, "objectBoundingBox"); + entries.emplace_back(UnitTypeUserSpaceOnUse, "userSpaceOnUse"); } return entries; @@ -130,4 +130,4 @@ std::string SVGEnumerationBase::valueAsString() const return KEmptyString; } -} //namespace lunasvg +} // namespace lunasvg diff --git a/source/svgenumeration.h b/source/svgenumeration.h index e45f4cb..d00de6c 100755 --- a/source/svgenumeration.h +++ b/source/svgenumeration.h @@ -86,10 +86,10 @@ class SVGEnumerationBase : public SVGProperty static PropertyType classType() { return PropertyTypeEnumeration; } protected: - SVGEnumerationBase(const EnumEntryList& entries) : - SVGProperty(PropertyTypeEnumeration), - m_value(0), - m_entries(entries) + SVGEnumerationBase(const EnumEntryList& entries) + : SVGProperty(PropertyTypeEnumeration), + m_value(0), + m_entries(entries) {} protected: @@ -101,8 +101,8 @@ template class SVGEnumeration : public SVGEnumerationBase { public: - SVGEnumeration() : - SVGEnumerationBase(getEnumEntryList()) + SVGEnumeration() + : SVGEnumerationBase(getEnumEntryList()) {} T enumValue() const @@ -128,8 +128,8 @@ template class DOMSVGEnumeration : public DOMSVGProperty> { public: - DOMSVGEnumeration(DOMPropertyID propertyId) : - DOMSVGProperty>(propertyId) + DOMSVGEnumeration(DOMPropertyID propertyId) + : DOMSVGProperty>(propertyId) {} }; diff --git a/source/svgfittoviewbox.cpp b/source/svgfittoviewbox.cpp index 33fd2aa..fd243f9 100755 --- a/source/svgfittoviewbox.cpp +++ b/source/svgfittoviewbox.cpp @@ -4,9 +4,9 @@ namespace lunasvg { -SVGFitToViewBox::SVGFitToViewBox(SVGElementHead* element) : - m_viewBox(DOMPropertyIdViewBox), - m_preserveAspectRatio(DOMPropertyIdPreserveAspectRatio) +SVGFitToViewBox::SVGFitToViewBox(SVGElementHead* element) + : m_viewBox(DOMPropertyIdViewBox), + m_preserveAspectRatio(DOMPropertyIdPreserveAspectRatio) { element->addToPropertyMap(m_viewBox); element->addToPropertyMap(m_preserveAspectRatio); diff --git a/source/svggelement.cpp b/source/svggelement.cpp index 2868240..df3cc47 100755 --- a/source/svggelement.cpp +++ b/source/svggelement.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGGElement::SVGGElement(SVGDocument* document) : - SVGGraphicsElement(ElementIdG, document) +SVGGElement::SVGGElement(SVGDocument* document) + : SVGGraphicsElement(DOMElementIdG, document) { } diff --git a/source/svggeometryelement.cpp b/source/svggeometryelement.cpp index 185c0e3..61d4a20 100755 --- a/source/svggeometryelement.cpp +++ b/source/svggeometryelement.cpp @@ -4,8 +4,8 @@ namespace lunasvg { -SVGGeometryElement::SVGGeometryElement(ElementID elementId, SVGDocument* document) : - SVGGraphicsElement(elementId, document) +SVGGeometryElement::SVGGeometryElement(DOMElementID elementId, SVGDocument* document) + : SVGGraphicsElement(elementId, document) { } diff --git a/source/svggeometryelement.h b/source/svggeometryelement.h index 69f9b2f..d157d2c 100755 --- a/source/svggeometryelement.h +++ b/source/svggeometryelement.h @@ -9,7 +9,7 @@ namespace lunasvg { class SVGGeometryElement : public SVGGraphicsElement { public: - SVGGeometryElement(ElementID elementId, SVGDocument* document); + SVGGeometryElement(DOMElementID elementId, SVGDocument* document); bool isSVGGeometryElement() const { return true; } virtual Path makePath(const RenderState& state) const = 0; virtual Rect makeBoundingBox(const RenderState& state) const = 0; diff --git a/source/svggradientelement.cpp b/source/svggradientelement.cpp index e2f1ae5..507e1b1 100755 --- a/source/svggradientelement.cpp +++ b/source/svggradientelement.cpp @@ -4,12 +4,12 @@ namespace lunasvg { -SVGGradientElement::SVGGradientElement(ElementID elementId, SVGDocument* document) : - SVGPaintElement(elementId, document), - SVGURIReference (this), - m_gradientTransform(DOMPropertyIdGradientTransform), - m_spreadMethod(DOMPropertyIdSpreadMethod), - m_gradientUnits(DOMPropertyIdGradientUnits) +SVGGradientElement::SVGGradientElement(DOMElementID elementId, SVGDocument* document) + : SVGPaintElement(elementId, document), + SVGURIReference (this), + m_gradientTransform(DOMPropertyIdGradientTransform), + m_spreadMethod(DOMPropertyIdSpreadMethod), + m_gradientUnits(DOMPropertyIdGradientUnits) { addToPropertyMap(m_gradientTransform); addToPropertyMap(m_spreadMethod); @@ -29,7 +29,7 @@ void SVGGradientElement::setGradientAttributes(GradientAttributes& attributes) c const SVGElementImpl* e = next; while(e != tail) { - if(e->elementId()==ElementIdStop) + if(e->elementId()==DOMElementIdStop) attributes.gradientStops.push_back(to(e)); e = e->next; } diff --git a/source/svggradientelement.h b/source/svggradientelement.h index 81bb309..b2f4d97 100755 --- a/source/svggradientelement.h +++ b/source/svggradientelement.h @@ -23,7 +23,7 @@ class SVGGradientElement : public SVGPaintElement, public SVGURIReference { public: - SVGGradientElement(ElementID elementId, SVGDocument* document); + SVGGradientElement(DOMElementID elementId, SVGDocument* document); bool isSVGGradientElement() const { return true; } const DOMSVGTransform& gradientTransform() const { return m_gradientTransform; } const DOMSVGEnumeration& spreadMethod() const { return m_spreadMethod; } diff --git a/source/svggraphicselement.cpp b/source/svggraphicselement.cpp index 857d8a8..924c757 100755 --- a/source/svggraphicselement.cpp +++ b/source/svggraphicselement.cpp @@ -2,9 +2,9 @@ namespace lunasvg { -SVGGraphicsElement::SVGGraphicsElement(ElementID elementId, SVGDocument* document) : - SVGStyledElement(elementId, document), - m_transform(DOMPropertyIdTransform) +SVGGraphicsElement::SVGGraphicsElement(DOMElementID elementId, SVGDocument* document) + : SVGStyledElement(elementId, document), + m_transform(DOMPropertyIdTransform) { addToPropertyMap(m_transform); } diff --git a/source/svggraphicselement.h b/source/svggraphicselement.h index 93166f6..fe6cb02 100755 --- a/source/svggraphicselement.h +++ b/source/svggraphicselement.h @@ -10,7 +10,7 @@ namespace lunasvg { class SVGGraphicsElement : public SVGStyledElement { public: - SVGGraphicsElement(ElementID elementId, SVGDocument* document); + SVGGraphicsElement(DOMElementID elementId, SVGDocument* document); bool isSVGGraphicsElement() const { return true; } const DOMSVGTransform& transform() const { return m_transform; } virtual void render(RenderContext& context) const; diff --git a/source/svglength.cpp b/source/svglength.cpp index d24f3f1..d6c5625 100755 --- a/source/svglength.cpp +++ b/source/svglength.cpp @@ -3,7 +3,7 @@ namespace lunasvg { -#define K_SQRT2 1.41421356237309504880 +#define SQRT2 1.41421356237309504880 const SVGLength* hundredPercent() { @@ -29,17 +29,17 @@ const SVGLength* oneTwentyPercent() return &value; } -SVGLength::SVGLength() : - SVGProperty(PropertyTypeLength), - m_value(0), - m_unit(LengthUnitNumber) +SVGLength::SVGLength() + : SVGProperty(PropertyTypeLength), + m_value(0), + m_unit(LengthUnitNumber) { } -SVGLength::SVGLength(double value, LengthUnit unit) : - SVGProperty(PropertyTypeLength), - m_value(value), - m_unit(unit) +SVGLength::SVGLength(double value, LengthUnit unit) + : SVGProperty(PropertyTypeLength), + m_value(value), + m_unit(unit) { } @@ -90,7 +90,7 @@ double SVGLength::value(const RenderState& state, LengthMode mode) const { double w = state.viewPort.width; double h = state.viewPort.height; - double max = (mode == LengthModeWidth) ? w : (mode == LengthModeHeight) ? h : std::sqrt(w*w+h*h) / K_SQRT2; + double max = (mode == LengthModeWidth) ? w : (mode == LengthModeHeight) ? h : std::sqrt(w*w+h*h) / SQRT2; return m_value * max / 100.0; } @@ -229,11 +229,11 @@ SVGProperty* SVGLength::clone() const return property; } -DOMSVGLength::DOMSVGLength(DOMPropertyID propertyId, LengthMode mode, LengthNegativeValuesMode negativeValuesMode) : - DOMSVGProperty(propertyId), - m_mode(mode), - m_negativeValuesMode(negativeValuesMode), - m_defaultValue(nullptr) +DOMSVGLength::DOMSVGLength(DOMPropertyID propertyId, LengthMode mode, LengthNegativeValuesMode negativeValuesMode) + : DOMSVGProperty(propertyId), + m_mode(mode), + m_negativeValuesMode(negativeValuesMode), + m_defaultValue(nullptr) { } @@ -241,7 +241,7 @@ void DOMSVGLength::setPropertyAsString(const std::string& value) { DOMSVGProperty::setPropertyAsString(value); - if(negativeValuesMode()==ForbidNegativeLengths && property()->value()<0) + if(m_negativeValuesMode==ForbidNegativeLengths && property()->value()<0) { property()->setValue(0); property()->setUnit(LengthUnitNumber); diff --git a/source/svglengthlist.cpp b/source/svglengthlist.cpp index 7f9ec33..715ba74 100755 --- a/source/svglengthlist.cpp +++ b/source/svglengthlist.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGLengthList::SVGLengthList() : - SVGListProperty(PropertyTypeLengthList) +SVGLengthList::SVGLengthList() + : SVGListProperty(PropertyTypeLengthList) { } diff --git a/source/svglineargradientelement.cpp b/source/svglineargradientelement.cpp index 75f2382..6751b06 100755 --- a/source/svglineargradientelement.cpp +++ b/source/svglineargradientelement.cpp @@ -3,12 +3,12 @@ namespace lunasvg { -SVGLinearGradientElement::SVGLinearGradientElement(SVGDocument* document) : - SVGGradientElement(ElementIdLinearGradient, document), - m_x1(DOMPropertyIdX1, LengthModeWidth, AllowNegativeLengths), - m_y1(DOMPropertyIdY1, LengthModeHeight, AllowNegativeLengths), - m_x2(DOMPropertyIdX2, LengthModeWidth, AllowNegativeLengths), - m_y2(DOMPropertyIdY2, LengthModeHeight, AllowNegativeLengths) +SVGLinearGradientElement::SVGLinearGradientElement(SVGDocument* document) + : SVGGradientElement(DOMElementIdLinearGradient, document), + m_x1(DOMPropertyIdX1, LengthModeWidth, AllowNegativeLengths), + m_y1(DOMPropertyIdY1, LengthModeHeight, AllowNegativeLengths), + m_x2(DOMPropertyIdX2, LengthModeWidth, AllowNegativeLengths), + m_y2(DOMPropertyIdY2, LengthModeHeight, AllowNegativeLengths) { m_x2.setDefaultValue(hundredPercent()); @@ -26,7 +26,7 @@ void SVGLinearGradientElement::collectGradientAttributes(LinearGradientAttribute while(true) { current->setGradientAttributes(attributes); - if(current->elementId() == ElementIdLinearGradient) + if(current->elementId() == DOMElementIdLinearGradient) { const SVGLinearGradientElement* linear = to(current); if(!attributes.x1 && linear->m_x1.isSpecified()) diff --git a/source/svglineelement.cpp b/source/svglineelement.cpp index 508672b..07044f8 100755 --- a/source/svglineelement.cpp +++ b/source/svglineelement.cpp @@ -2,12 +2,12 @@ namespace lunasvg { -SVGLineElement::SVGLineElement(SVGDocument* document) : - SVGGeometryElement(ElementIdLine, document), - m_x1(DOMPropertyIdX1, LengthModeWidth, AllowNegativeLengths), - m_y1(DOMPropertyIdY1, LengthModeHeight, AllowNegativeLengths), - m_x2(DOMPropertyIdX2, LengthModeWidth, AllowNegativeLengths), - m_y2(DOMPropertyIdY2, LengthModeHeight, AllowNegativeLengths) +SVGLineElement::SVGLineElement(SVGDocument* document) + : SVGGeometryElement(DOMElementIdLine, document), + m_x1(DOMPropertyIdX1, LengthModeWidth, AllowNegativeLengths), + m_y1(DOMPropertyIdY1, LengthModeHeight, AllowNegativeLengths), + m_x2(DOMPropertyIdX2, LengthModeWidth, AllowNegativeLengths), + m_y2(DOMPropertyIdY2, LengthModeHeight, AllowNegativeLengths) { addToPropertyMap(m_x1); addToPropertyMap(m_y1); diff --git a/source/svgmaskelement.cpp b/source/svgmaskelement.cpp index 55ccdf4..b80a6f3 100644 --- a/source/svgmaskelement.cpp +++ b/source/svgmaskelement.cpp @@ -4,14 +4,14 @@ namespace lunasvg { -SVGMaskElement::SVGMaskElement(SVGDocument* document) : - SVGStyledElement(ElementIdMask, document), - m_x(DOMPropertyIdX, LengthModeWidth, AllowNegativeLengths), - m_y(DOMPropertyIdY, LengthModeHeight, AllowNegativeLengths), - m_width(DOMPropertyIdWidth, LengthModeWidth, ForbidNegativeLengths), - m_height(DOMPropertyIdHeight, LengthModeHeight, ForbidNegativeLengths), - m_maskUnits(DOMPropertyIdMaskUnits), - m_maskContentUnits(DOMPropertyIdMaskContentUnits) +SVGMaskElement::SVGMaskElement(SVGDocument* document) + : SVGStyledElement(DOMElementIdMask, document), + m_x(DOMPropertyIdX, LengthModeWidth, AllowNegativeLengths), + m_y(DOMPropertyIdY, LengthModeHeight, AllowNegativeLengths), + m_width(DOMPropertyIdWidth, LengthModeWidth, ForbidNegativeLengths), + m_height(DOMPropertyIdHeight, LengthModeHeight, ForbidNegativeLengths), + m_maskUnits(DOMPropertyIdMaskUnits), + m_maskContentUnits(DOMPropertyIdMaskContentUnits) { m_x.setDefaultValue(minusTenPercent()); m_y.setDefaultValue(minusTenPercent()); @@ -56,7 +56,7 @@ void SVGMaskElement::applyMask(RenderState& state) const void SVGMaskElement::render(RenderContext& context) const { - if(context.state().element->elementId() != ElementIdMask) + if(context.state().element->elementId() != DOMElementIdMask) { context.skipElement(); return; diff --git a/source/svgnumber.cpp b/source/svgnumber.cpp index d565af3..b54b635 100755 --- a/source/svgnumber.cpp +++ b/source/svgnumber.cpp @@ -2,9 +2,9 @@ namespace lunasvg { -SVGNumber::SVGNumber() : - SVGProperty(PropertyTypeNumber), - m_value(0) +SVGNumber::SVGNumber() + : SVGProperty(PropertyTypeNumber), + m_value(0) { } diff --git a/source/svgnumberlist.cpp b/source/svgnumberlist.cpp index 9dc1d08..2200da2 100755 --- a/source/svgnumberlist.cpp +++ b/source/svgnumberlist.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGNumberList::SVGNumberList() : - SVGListProperty(PropertyTypeNumberList) +SVGNumberList::SVGNumberList() + : SVGListProperty(PropertyTypeNumberList) { } diff --git a/source/svgpaintelement.cpp b/source/svgpaintelement.cpp index ce0ca1c..060e929 100755 --- a/source/svgpaintelement.cpp +++ b/source/svgpaintelement.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGPaintElement::SVGPaintElement(ElementID elementId, SVGDocument* document) : - SVGStyledElement(elementId, document) +SVGPaintElement::SVGPaintElement(DOMElementID elementId, SVGDocument* document) + : SVGStyledElement(elementId, document) { } diff --git a/source/svgpaintelement.h b/source/svgpaintelement.h index 4e4d6ce..4d74e41 100755 --- a/source/svgpaintelement.h +++ b/source/svgpaintelement.h @@ -10,7 +10,7 @@ namespace lunasvg { class SVGPaintElement : public SVGStyledElement { public: - SVGPaintElement(ElementID elementId, SVGDocument* document); + SVGPaintElement(DOMElementID elementId, SVGDocument* document); bool isSVGPaintElement() const { return true; } virtual Paint getPaint(const RenderState& state) const = 0; virtual void render(RenderContext& context) const; diff --git a/source/svgparser.cpp b/source/svgparser.cpp index 8480d05..c026196 100755 --- a/source/svgparser.cpp +++ b/source/svgparser.cpp @@ -17,12 +17,12 @@ namespace lunasvg { -SVGParser::SVGParser(SVGDocument* document) : - m_document(document) +SVGParser::SVGParser(SVGDocument* document) + : m_document(document) { } -bool SVGParser::appendHead(ElementID elementId, const AttributeList& attributes) +bool SVGParser::appendHead(DOMElementID elementId, const AttributeList& attributes) { SVGElementHead* parent; if(m_blocks.empty()) @@ -43,7 +43,7 @@ bool SVGParser::appendHead(ElementID elementId, const AttributeList& attributes) return true; } -bool SVGParser::appendTail(ElementID elementId) +bool SVGParser::appendTail(DOMElementID elementId) { if(m_blocks.empty() || elementId!=m_blocks.top()->elementId()) return false; @@ -85,12 +85,12 @@ SVGElementImpl* SVGParser::parse(const std::string& source, SVGElementHead* pare AttributeList attributes; while(enumTag(ptr, tagType, tagName, content, attributes)) { - ElementID elementId = Utils::elementId(tagName); + DOMElementID elementId = Utils::domElementId(tagName); if(tagType==KTagOpen || tagType==KTagEmpty) { if(!parent && m_blocks.empty()) { - if(elementId != ElementIdSvg) + if(elementId != DOMElementIdSvg) break; SVGElementHead* rootElement = to(m_document->rootElement()); m_blocks.push(rootElement); @@ -110,7 +110,7 @@ SVGElementImpl* SVGParser::parse(const std::string& source, SVGElementHead* pare break; if(!parent && m_blocks.top() == m_document->rootElement()) { - if(elementId != ElementIdSvg) + if(elementId != DOMElementIdSvg) break; m_blocks.pop(); break; @@ -169,9 +169,9 @@ bool SVGParser::enumTag(const char*& ptr, int& tagType, std::string& tagName, st return true; } - if(!*ptr || *ptr!='<') + if(*ptr!='<') return false; - ++ptr; + ++ptr; if(*ptr=='/') { @@ -198,7 +198,8 @@ bool SVGParser::enumTag(const char*& ptr, int& tagType, std::string& tagName, st return true; } - else if(Utils::skipDesc(ptr, "[CDATA[", 7)) + + if(Utils::skipDesc(ptr, "[CDATA[", 7)) { const char* sub = strstr(ptr, "]]>"); if(!sub) @@ -210,7 +211,8 @@ bool SVGParser::enumTag(const char*& ptr, int& tagType, std::string& tagName, st return true; } - else if(Utils::skipDesc(ptr, "DOCTYPE", 7)) + + if(Utils::skipDesc(ptr, "DOCTYPE", 7)) { start = ptr; while(*ptr && *ptr!='>') @@ -232,7 +234,7 @@ bool SVGParser::enumTag(const char*& ptr, int& tagType, std::string& tagName, st } } - if(!*ptr || *ptr!='>') + if(*ptr!='>') return false; tagType = KTagDocType; @@ -287,7 +289,7 @@ bool SVGParser::enumTag(const char*& ptr, int& tagType, std::string& tagName, st start = ptr; while(*ptr && *ptr!=quote) ++ptr; - if(!*ptr || *ptr!=quote) + if(*ptr!=quote) return false; attribute.second.assign(start, Utils::rtrim(start, ptr)); attributes.push_back(attribute); @@ -295,13 +297,11 @@ bool SVGParser::enumTag(const char*& ptr, int& tagType, std::string& tagName, st Utils::skipWs(ptr); } - if(*ptr=='?') + if(*ptr=='>') { - if(tagType!=KTagInstruction) - return false; - ++ptr; - if(*ptr!='>') + if(tagType!=KTagUnknown) return false; + tagType = KTagOpen; ++ptr; return true; } @@ -318,11 +318,13 @@ bool SVGParser::enumTag(const char*& ptr, int& tagType, std::string& tagName, st return true; } - if(*ptr=='>') + if(*ptr=='?') { - if(tagType!=KTagUnknown) + if(tagType!=KTagInstruction) + return false; + ++ptr; + if(*ptr!='>') return false; - tagType = KTagOpen; ++ptr; return true; } diff --git a/source/svgparser.h b/source/svgparser.h index e4e9aea..d1fb5f9 100755 --- a/source/svgparser.h +++ b/source/svgparser.h @@ -25,8 +25,8 @@ class SVGParser typedef std::pair Attribute; typedef std::vector AttributeList; bool enumTag(const char*& ptr, int& tagType, std::string& tagName, std::string& content, AttributeList& attributes); - bool appendHead(ElementID elementId, const AttributeList& attributes); - bool appendTail(ElementID elementId); + bool appendHead(DOMElementID elementId, const AttributeList& attributes); + bool appendTail(DOMElementID elementId); bool appendText(const std::string&); void appendElement(SVGElementImpl* newElement); diff --git a/source/svgparserutils.h b/source/svgparserutils.h index 6476021..7d10b73 100755 --- a/source/svgparserutils.h +++ b/source/svgparserutils.h @@ -111,12 +111,12 @@ inline bool parseInteger(const char*& ptr, T& integer, int base = 10) using signed_t = typename std::make_signed::type; const T maxMultiplier = intMax / static_cast(base); - if(*ptr && isSigned && *ptr == '-') + if(isSigned && *ptr == '-') { ++ptr; isNegative = true; } - else if(*ptr && *ptr == '+') + else if(*ptr == '+') ++ptr; if(!*ptr || !isIntegralDigit(*ptr, base)) @@ -159,9 +159,9 @@ inline bool parseNumber(const char*& ptr, T& number) sign = 1; expsign = 1; - if(*ptr && *ptr == '+') + if(*ptr == '+') ++ptr; - else if(*ptr && *ptr == '-') + else if(*ptr == '-') { ++ptr; sign = -1; @@ -176,7 +176,7 @@ inline bool parseNumber(const char*& ptr, T& number) integer = static_cast(10) * integer + (*ptr++ - '0'); } - if(*ptr && *ptr == '.') + if(*ptr == '.') { ++ptr; if(!*ptr || !IS_NUM(*ptr)) diff --git a/source/svgpath.cpp b/source/svgpath.cpp index 9cf533c..b92fcaa 100755 --- a/source/svgpath.cpp +++ b/source/svgpath.cpp @@ -1,19 +1,18 @@ #include "svgpath.h" #include "pathiterator.h" -#include "pathutils.h" namespace lunasvg { -SVGPath::SVGPath() : - SVGProperty(PropertyTypePath) +SVGPath::SVGPath() + : SVGProperty(PropertyTypePath) { } bool SVGPath::parseArcFlag(const char*& ptr, bool& flag) { - if(*ptr && *ptr=='0') + if(*ptr == '0') flag = false; - else if(*ptr && *ptr=='1') + else if(*ptr == '1') flag = true; else return false; @@ -23,12 +22,15 @@ bool SVGPath::parseArcFlag(const char*& ptr, bool& flag) return true; } -bool SVGPath::parseCoord(const char*& ptr, double& value) +bool SVGPath::parseCoordinate(const char*& ptr, double* coords, int length) { - if(!Utils::parseNumber(ptr, value)) - return false; + for(int i = 0;i < length;i++) + { + if(!Utils::parseNumber(ptr, coords[i])) + return false; + Utils::skipWsComma(ptr); + } - Utils::skipWsComma(ptr); return true; } @@ -52,78 +54,61 @@ void SVGPath::setValueAsString(const std::string& value) { case 'M': case 'm': - if(!parseCoord(ptr, c[0]) - || !parseCoord(ptr, c[1])) + if(!parseCoordinate(ptr, c, 2)) return; m_value.moveTo(c[0], c[1], pathCommand == 'm'); pathCommand = pathCommand == 'm' ? 'l' : 'L'; break; case 'L': case 'l': - if(!parseCoord(ptr, c[0]) - || !parseCoord(ptr, c[1])) + if(!parseCoordinate(ptr, c, 2)) return; m_value.lineTo(c[0], c[1], pathCommand == 'l'); break; case 'Q': case 'q': - if(!parseCoord(ptr, c[0]) - || !parseCoord(ptr, c[1]) - || !parseCoord(ptr, c[2]) - || !parseCoord(ptr, c[3])) + if(!parseCoordinate(ptr, c, 4)) return; m_value.quadTo(c[0], c[1], c[2], c[3], pathCommand == 'q'); break; case 'C': case 'c': - if(!parseCoord(ptr, c[0]) - || !parseCoord(ptr, c[1]) - || !parseCoord(ptr, c[2]) - || !parseCoord(ptr, c[3]) - || !parseCoord(ptr, c[4]) - || !parseCoord(ptr, c[5])) + if(!parseCoordinate(ptr, c, 6)) return; m_value.cubicTo(c[0], c[1], c[2], c[3], c[4], c[5], pathCommand == 'c'); break; case 'T': case 't': - if(!parseCoord(ptr, c[0]) - || !parseCoord(ptr, c[1])) + if(!parseCoordinate(ptr, c, 2)) return; m_value.smoothQuadTo(c[0], c[1], pathCommand == 't'); break; case 'S': case 's': - if(!parseCoord(ptr, c[0]) - || !parseCoord(ptr, c[1]) - || !parseCoord(ptr, c[2]) - || !parseCoord(ptr, c[3])) + if(!parseCoordinate(ptr, c, 4)) return; m_value.smoothCubicTo(c[0], c[1], c[2], c[3], pathCommand == 's'); break; case 'H': case 'h': - if(!parseCoord(ptr, c[0])) + if(!parseCoordinate(ptr, c, 1)) return; m_value.horizontalTo(c[0], pathCommand == 'h'); break; case 'V': case 'v': - if(!parseCoord(ptr, c[0])) + if(!parseCoordinate(ptr, c, 1)) return; m_value.verticalTo(c[0], pathCommand == 'v'); break; case 'A': case 'a': - if(!parseCoord(ptr, c[0]) - || !parseCoord(ptr, c[1]) - || !parseCoord(ptr, c[2]) + if(!parseCoordinate(ptr, c, 3) || !parseArcFlag(ptr, f[0]) || !parseArcFlag(ptr, f[1]) - || !parseCoord(ptr, c[3]) - || !parseCoord(ptr, c[4])) + || !parseCoordinate(ptr, c + 3, 2)) return; - Utils::pathArcTo(m_value, c[0], c[1], c[2], f[0], f[1], c[3], c[4], pathCommand == 'a'); + m_value.arcTo(c[0], c[1], c[2], f[0], f[1], c[3], c[4], pathCommand == 'a'); break; case 'Z': case 'z': @@ -153,7 +138,8 @@ std::string SVGPath::valueAsString() const SegType seg = it.currentSegment(c); if(seg!=lastSeg) out += ' '; - switch(seg) { + switch(seg) + { case SegTypeMoveTo: out += 'M'; out += Utils::toString(c[0]); diff --git a/source/svgpath.h b/source/svgpath.h index c44f27b..558fd15 100755 --- a/source/svgpath.h +++ b/source/svgpath.h @@ -15,7 +15,7 @@ class SVGPath : public SVGProperty const Path& value() const { return m_value; } static bool parseArcFlag(const char*& ptr, bool& flag); - static bool parseCoord(const char*& ptr, double& value); + static bool parseCoordinate(const char*& ptr, double* coords, int length); void setValueAsString(const std::string& value); std::string valueAsString() const; SVGProperty* clone() const; diff --git a/source/svgpathelement.cpp b/source/svgpathelement.cpp index cedb11a..e74fd39 100755 --- a/source/svgpathelement.cpp +++ b/source/svgpathelement.cpp @@ -2,9 +2,9 @@ namespace lunasvg { -SVGPathElement::SVGPathElement(SVGDocument* document) : - SVGGeometryElement(ElementIdPath, document), - m_d(DOMPropertyIdD) +SVGPathElement::SVGPathElement(SVGDocument* document) + : SVGGeometryElement(DOMElementIdPath, document), + m_d(DOMPropertyIdD) { addToPropertyMap(m_d); } diff --git a/source/svgpatternelement.cpp b/source/svgpatternelement.cpp index 9bd51c2..d90c2a7 100644 --- a/source/svgpatternelement.cpp +++ b/source/svgpatternelement.cpp @@ -5,17 +5,17 @@ namespace lunasvg { -SVGPatternElement::SVGPatternElement(SVGDocument* document) : - SVGPaintElement(ElementIdPattern, document), - SVGURIReference(this), - SVGFitToViewBox(this), - m_x(DOMPropertyIdX, LengthModeWidth, AllowNegativeLengths), - m_y(DOMPropertyIdY, LengthModeHeight, AllowNegativeLengths), - m_width(DOMPropertyIdWidth, LengthModeWidth, ForbidNegativeLengths), - m_height(DOMPropertyIdHeight, LengthModeHeight, ForbidNegativeLengths), - m_patternTransform(DOMPropertyIdPatternTransform), - m_patternUnits(DOMPropertyIdPatternUnits), - m_patternContentUnits(DOMPropertyIdPatternContentUnits) +SVGPatternElement::SVGPatternElement(SVGDocument* document) + : SVGPaintElement(DOMElementIdPattern, document), + SVGURIReference(this), + SVGFitToViewBox(this), + m_x(DOMPropertyIdX, LengthModeWidth, AllowNegativeLengths), + m_y(DOMPropertyIdY, LengthModeHeight, AllowNegativeLengths), + m_width(DOMPropertyIdWidth, LengthModeWidth, ForbidNegativeLengths), + m_height(DOMPropertyIdHeight, LengthModeHeight, ForbidNegativeLengths), + m_patternTransform(DOMPropertyIdPatternTransform), + m_patternUnits(DOMPropertyIdPatternUnits), + m_patternContentUnits(DOMPropertyIdPatternContentUnits) { addToPropertyMap(m_x); addToPropertyMap(m_y); @@ -56,7 +56,7 @@ void SVGPatternElement::collectPatternAttributes(PatternAttributes& attributes) processedGradients.insert(current); SVGElementImpl* ref = document()->impl()->resolveIRI(current->hrefValue()); - if(!ref || ref->elementId() != ElementIdPattern) + if(!ref || ref->elementId() != DOMElementIdPattern) break; current = to(ref); @@ -98,12 +98,12 @@ Paint SVGPatternElement::getPaint(const RenderState& state) const double width = w * scalex; double height = h * scaley; - if(width == 0.0 || height == 0.0 || attributes.patternContentElement == nullptr || RenderBreaker::hasElement(attributes.patternContentElement)) + if(width == 0.0 || height == 0.0 || attributes.patternContentElement == nullptr || RenderBreaker::hasElement(this)) return Paint(); RenderContext newContext(this, RenderModeDisplay); RenderState& newState = newContext.state(); - newState.element = attributes.patternContentElement; + newState.element = this; newState.canvas.reset(std::uint32_t(std::ceil(width)), std::uint32_t(std::ceil(height))); newState.style.add(style()); newState.matrix.scale(scalex, scaley); @@ -123,9 +123,9 @@ Paint SVGPatternElement::getPaint(const RenderState& state) const newState.viewPort = Rect(0, 0, 1, 1); } - RenderBreaker::registerElement(attributes.patternContentElement); + RenderBreaker::registerElement(this); newContext.render(attributes.patternContentElement->next, attributes.patternContentElement->tail->prev); - RenderBreaker::unregisterElement(attributes.patternContentElement); + RenderBreaker::unregisterElement(this); AffineTransform matrix(1.0/scalex, 0, 0, 1.0/scaley, x, y); if(attributes.patternTransform) diff --git a/source/svgpoint.cpp b/source/svgpoint.cpp index 9972baa..cf46e88 100755 --- a/source/svgpoint.cpp +++ b/source/svgpoint.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGPoint::SVGPoint() : - SVGProperty(PropertyTypePoint) +SVGPoint::SVGPoint() + : SVGProperty(PropertyTypePoint) { } diff --git a/source/svgpointlist.cpp b/source/svgpointlist.cpp index b467f99..7b89c37 100755 --- a/source/svgpointlist.cpp +++ b/source/svgpointlist.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGPointList::SVGPointList() : - SVGListProperty(PropertyTypePointList) +SVGPointList::SVGPointList() + : SVGListProperty(PropertyTypePointList) { } diff --git a/source/svgpolyelement.cpp b/source/svgpolyelement.cpp index 8d73779..f2174ca 100755 --- a/source/svgpolyelement.cpp +++ b/source/svgpolyelement.cpp @@ -2,9 +2,9 @@ namespace lunasvg { -SVGPolyElement::SVGPolyElement(ElementID elementId, SVGDocument* document) : - SVGGeometryElement(elementId, document), - m_points(DOMPropertyIdPoints) +SVGPolyElement::SVGPolyElement(DOMElementID elementId, SVGDocument* document) + : SVGGeometryElement(elementId, document), + m_points(DOMPropertyIdPoints) { addToPropertyMap(m_points); } diff --git a/source/svgpolyelement.h b/source/svgpolyelement.h index 59d8b01..53bb1b1 100755 --- a/source/svgpolyelement.h +++ b/source/svgpolyelement.h @@ -9,7 +9,7 @@ namespace lunasvg { class SVGPolyElement : public SVGGeometryElement { public: - SVGPolyElement(ElementID elementId, SVGDocument* document); + SVGPolyElement(DOMElementID elementId, SVGDocument* document); bool isSVGPolyElement() const { return true; } const DOMSVGPointList& points() const { return m_points; } virtual Rect makeBoundingBox(const RenderState&) const; diff --git a/source/svgpolygonelement.cpp b/source/svgpolygonelement.cpp index 11d4fee..20f0e3e 100755 --- a/source/svgpolygonelement.cpp +++ b/source/svgpolygonelement.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGPolygonElement::SVGPolygonElement(SVGDocument* document) : - SVGPolyElement(ElementIdPolygon, document) +SVGPolygonElement::SVGPolygonElement(SVGDocument* document) + : SVGPolyElement(DOMElementIdPolygon, document) { } diff --git a/source/svgpolylineelement.cpp b/source/svgpolylineelement.cpp index 186cbba..13d8ee9 100755 --- a/source/svgpolylineelement.cpp +++ b/source/svgpolylineelement.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGPolylineElement::SVGPolylineElement(SVGDocument* document) : - SVGPolyElement(ElementIdPolyline, document) +SVGPolylineElement::SVGPolylineElement(SVGDocument* document) + : SVGPolyElement(DOMElementIdPolyline, document) { } diff --git a/source/svgpreserveaspectratio.cpp b/source/svgpreserveaspectratio.cpp index fedfab1..385578d 100755 --- a/source/svgpreserveaspectratio.cpp +++ b/source/svgpreserveaspectratio.cpp @@ -4,10 +4,10 @@ namespace lunasvg { -SVGPreserveAspectRatio::SVGPreserveAspectRatio() : - SVGProperty(PropertyTypePreserveAspectRatio), - m_align(xMidYMid), - m_scale(Meet) +SVGPreserveAspectRatio::SVGPreserveAspectRatio() + : SVGProperty(PropertyTypePreserveAspectRatio), + m_align(xMidYMid), + m_scale(Meet) { } @@ -173,7 +173,7 @@ std::string SVGPreserveAspectRatio::valueAsString() const out += "slice"; } - return out; + return out; } SVGProperty* SVGPreserveAspectRatio::clone() const diff --git a/source/svgpropertyutils.cpp b/source/svgpropertyutils.cpp index 2951e5c..fc5e478 100755 --- a/source/svgpropertyutils.cpp +++ b/source/svgpropertyutils.cpp @@ -1,5 +1,4 @@ #include "svgpropertyutils.h" -#include "svgparserutils.h" #include "svgstring.h" #include @@ -87,21 +86,16 @@ static const std::unordered_map smilpropertymap = { }; static const std::unordered_map csspropertymap = { - {"clip", CSSPropertyIdClip}, {"clip-path", CSSPropertyIdClip_Path}, {"clip-rule", CSSPropertyIdClip_Rule}, {"color", CSSPropertyIdColor}, - {"direction", CSSPropertyIdDirection}, {"display", CSSPropertyIdDisplay}, {"fill", CSSPropertyIdFill}, {"fill-opacity", CSSPropertyIdFill_Opacity}, {"fill-rule", CSSPropertyIdFill_Rule}, {"font-family", CSSPropertyIdFont_Family}, {"font-size", CSSPropertyIdFont_Size}, - {"font-size-adjust", CSSPropertyIdFont_Size_Adjust}, - {"font-stretch", CSSPropertyIdFont_Stretch}, {"font-style", CSSPropertyIdFont_Style}, - {"font-variant", CSSPropertyIdFont_Variant}, {"font-weight", CSSPropertyIdFont_Weight}, {"marker-end", CSSPropertyIdMarker_End}, {"marker-mid", CSSPropertyIdMarker_Mid}, diff --git a/source/svgpropertyutils.h b/source/svgpropertyutils.h index 9b72856..93e4b57 100755 --- a/source/svgpropertyutils.h +++ b/source/svgpropertyutils.h @@ -92,21 +92,16 @@ enum SMILPropertyID enum CSSPropertyID { CSSPropertyIdUnknown = 0, - CSSPropertyIdClip, CSSPropertyIdClip_Path, CSSPropertyIdClip_Rule, CSSPropertyIdColor, - CSSPropertyIdDirection, CSSPropertyIdDisplay, CSSPropertyIdFill, CSSPropertyIdFill_Opacity, CSSPropertyIdFill_Rule, CSSPropertyIdFont_Family, CSSPropertyIdFont_Size, - CSSPropertyIdFont_Size_Adjust, - CSSPropertyIdFont_Stretch, CSSPropertyIdFont_Style, - CSSPropertyIdFont_Variant, CSSPropertyIdFont_Weight, CSSPropertyIdMarker_End, CSSPropertyIdMarker_Mid, diff --git a/source/svgradialgradientelement.cpp b/source/svgradialgradientelement.cpp index 3b68d78..9f9907c 100755 --- a/source/svgradialgradientelement.cpp +++ b/source/svgradialgradientelement.cpp @@ -3,13 +3,13 @@ namespace lunasvg { -SVGRadialGradientElement::SVGRadialGradientElement(SVGDocument* document) : - SVGGradientElement(ElementIdRadialGradient, document), - m_cx(DOMPropertyIdCx, LengthModeWidth, AllowNegativeLengths), - m_cy(DOMPropertyIdCy, LengthModeHeight, AllowNegativeLengths), - m_r(DOMPropertyIdR, LengthModeBoth, ForbidNegativeLengths), - m_fx(DOMPropertyIdFx, LengthModeWidth, AllowNegativeLengths), - m_fy(DOMPropertyIdFy, LengthModeHeight, AllowNegativeLengths) +SVGRadialGradientElement::SVGRadialGradientElement(SVGDocument* document) + : SVGGradientElement(DOMElementIdRadialGradient, document), + m_cx(DOMPropertyIdCx, LengthModeWidth, AllowNegativeLengths), + m_cy(DOMPropertyIdCy, LengthModeHeight, AllowNegativeLengths), + m_r(DOMPropertyIdR, LengthModeBoth, ForbidNegativeLengths), + m_fx(DOMPropertyIdFx, LengthModeWidth, AllowNegativeLengths), + m_fy(DOMPropertyIdFy, LengthModeHeight, AllowNegativeLengths) { m_cx.setDefaultValue(fiftyPercent()); m_cy.setDefaultValue(fiftyPercent()); @@ -30,7 +30,7 @@ void SVGRadialGradientElement::collectGradientAttributes(RadialGradientAttribute while(true) { current->setGradientAttributes(attributes); - if(current->elementId() == ElementIdRadialGradient) + if(current->elementId() == DOMElementIdRadialGradient) { const SVGRadialGradientElement* radial = to(current); if(!attributes.cx && radial->m_cx.isSpecified()) diff --git a/source/svgrect.cpp b/source/svgrect.cpp index 905db92..c65380f 100755 --- a/source/svgrect.cpp +++ b/source/svgrect.cpp @@ -2,9 +2,9 @@ namespace lunasvg { -SVGRect::SVGRect() : - SVGProperty(PropertyTypeRect), - m_valid(true) +SVGRect::SVGRect() + : SVGProperty(PropertyTypeRect), + m_valid(true) { } @@ -59,8 +59,8 @@ SVGProperty* SVGRect::clone() const return property; } -DOMSVGViewBoxRect::DOMSVGViewBoxRect(DOMPropertyID propertyId) : - DOMSVGRect(propertyId) +DOMSVGViewBoxRect::DOMSVGViewBoxRect(DOMPropertyID propertyId) + : DOMSVGRect(propertyId) { } diff --git a/source/svgrectelement.cpp b/source/svgrectelement.cpp index 8a54631..4637add 100755 --- a/source/svgrectelement.cpp +++ b/source/svgrectelement.cpp @@ -2,14 +2,14 @@ namespace lunasvg { -SVGRectElement::SVGRectElement(SVGDocument* document) : - SVGGeometryElement(ElementIdRect, document), - m_x(DOMPropertyIdX, LengthModeWidth, AllowNegativeLengths), - m_y(DOMPropertyIdY, LengthModeHeight, AllowNegativeLengths), - m_rx(DOMPropertyIdRx, LengthModeWidth, ForbidNegativeLengths), - m_ry(DOMPropertyIdRy, LengthModeHeight, ForbidNegativeLengths), - m_width(DOMPropertyIdWidth, LengthModeWidth, ForbidNegativeLengths), - m_heigth(DOMPropertyIdHeight, LengthModeHeight, ForbidNegativeLengths) +SVGRectElement::SVGRectElement(SVGDocument* document) + : SVGGeometryElement(DOMElementIdRect, document), + m_x(DOMPropertyIdX, LengthModeWidth, AllowNegativeLengths), + m_y(DOMPropertyIdY, LengthModeHeight, AllowNegativeLengths), + m_rx(DOMPropertyIdRx, LengthModeWidth, ForbidNegativeLengths), + m_ry(DOMPropertyIdRy, LengthModeHeight, ForbidNegativeLengths), + m_width(DOMPropertyIdWidth, LengthModeWidth, ForbidNegativeLengths), + m_heigth(DOMPropertyIdHeight, LengthModeHeight, ForbidNegativeLengths) { addToPropertyMap(m_x); addToPropertyMap(m_y); diff --git a/source/svgrootelement.cpp b/source/svgrootelement.cpp index 45859cb..39af55e 100755 --- a/source/svgrootelement.cpp +++ b/source/svgrootelement.cpp @@ -4,8 +4,8 @@ namespace lunasvg { -SVGRootElement::SVGRootElement(SVGDocument* document) : - SVGSVGElement(document) +SVGRootElement::SVGRootElement(SVGDocument* document) + : SVGSVGElement(document) { } diff --git a/source/svgsolidcolorelement.cpp b/source/svgsolidcolorelement.cpp index b154e6a..883a7a7 100644 --- a/source/svgsolidcolorelement.cpp +++ b/source/svgsolidcolorelement.cpp @@ -4,8 +4,8 @@ namespace lunasvg { -SVGSolidColorElement::SVGSolidColorElement(SVGDocument* document) : - SVGPaintElement(ElementIdSolidColor, document) +SVGSolidColorElement::SVGSolidColorElement(SVGDocument* document) + : SVGPaintElement(DOMElementIdSolidColor, document) { } diff --git a/source/svgstopelement.cpp b/source/svgstopelement.cpp index 8247ede..0665dfe 100755 --- a/source/svgstopelement.cpp +++ b/source/svgstopelement.cpp @@ -4,9 +4,9 @@ namespace lunasvg { -SVGStopElement::SVGStopElement(SVGDocument* document) : - SVGStyledElement(ElementIdStop, document), - m_offset(DOMPropertyIdOffset) +SVGStopElement::SVGStopElement(SVGDocument* document) + : SVGStyledElement(DOMElementIdStop, document), + m_offset(DOMPropertyIdOffset) { addToPropertyMap(m_offset); } diff --git a/source/svgstring.cpp b/source/svgstring.cpp index 52381b0..b394068 100755 --- a/source/svgstring.cpp +++ b/source/svgstring.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGString::SVGString() : - SVGProperty(PropertyTypeString) +SVGString::SVGString() + : SVGProperty(PropertyTypeString) { } diff --git a/source/svgstringlist.cpp b/source/svgstringlist.cpp index 4be8a15..de99f25 100755 --- a/source/svgstringlist.cpp +++ b/source/svgstringlist.cpp @@ -2,8 +2,8 @@ namespace lunasvg { -SVGStringList::SVGStringList() : - SVGListProperty(PropertyTypeStringList) +SVGStringList::SVGStringList() + : SVGListProperty(PropertyTypeStringList) { } diff --git a/source/svgstyledelement.cpp b/source/svgstyledelement.cpp index 94a5776..8a49ca5 100755 --- a/source/svgstyledelement.cpp +++ b/source/svgstyledelement.cpp @@ -7,10 +7,10 @@ namespace lunasvg { -SVGStyledElement::SVGStyledElement(ElementID elementId, SVGDocument* document) : - SVGElementHead(elementId, document), - m_className(DOMPropertyIdClass), - m_style(DOMPropertyIdStyle) +SVGStyledElement::SVGStyledElement(DOMElementID elementId, SVGDocument* document) + : SVGElementHead(elementId, document), + m_className(DOMPropertyIdClass), + m_style(DOMPropertyIdStyle) { addToPropertyMap(m_className); addToPropertyMap(m_style); @@ -96,14 +96,14 @@ void SVGStyledElement::renderTail(RenderContext& context) const if(state.style.clipPath() != KEmptyString) { SVGElementImpl* ref = document()->impl()->resolveIRI(state.style.clipPath()); - if(ref && ref->elementId() == ElementIdClipPath) + if(ref && ref->elementId() == DOMElementIdClipPath) to(ref)->applyClip(state); } if(state.style.mask() != KEmptyString) { SVGElementImpl* ref = document()->impl()->resolveIRI(state.style.mask()); - if(ref && ref->elementId() == ElementIdMask) + if(ref && ref->elementId() == DOMElementIdMask) to(ref)->applyMask(state); } diff --git a/source/svgstyledelement.h b/source/svgstyledelement.h index 9883575..6b40736 100755 --- a/source/svgstyledelement.h +++ b/source/svgstyledelement.h @@ -11,7 +11,7 @@ class Rgb; class SVGStyledElement : public SVGElementHead { public: - SVGStyledElement(ElementID elementId, SVGDocument* document); + SVGStyledElement(DOMElementID elementId, SVGDocument* document); virtual void setAttribute(const std::string& name, const std::string& value); virtual std::string getAttribute(const std::string& name) const; virtual bool hasAttribute(const std::string& name) const; diff --git a/source/svgsvgelement.cpp b/source/svgsvgelement.cpp index 8ba7078..2b74db0 100755 --- a/source/svgsvgelement.cpp +++ b/source/svgsvgelement.cpp @@ -2,13 +2,13 @@ namespace lunasvg { -SVGSVGElement::SVGSVGElement(SVGDocument* document) : - SVGGraphicsElement(ElementIdSvg, document), - SVGFitToViewBox(this), - m_x(DOMPropertyIdX, LengthModeWidth, AllowNegativeLengths), - m_y(DOMPropertyIdY, LengthModeHeight, AllowNegativeLengths), - m_width(DOMPropertyIdWidth, LengthModeWidth, ForbidNegativeLengths), - m_height(DOMPropertyIdHeight, LengthModeHeight, ForbidNegativeLengths) +SVGSVGElement::SVGSVGElement(SVGDocument* document) + : SVGGraphicsElement(DOMElementIdSvg, document), + SVGFitToViewBox(this), + m_x(DOMPropertyIdX, LengthModeWidth, AllowNegativeLengths), + m_y(DOMPropertyIdY, LengthModeHeight, AllowNegativeLengths), + m_width(DOMPropertyIdWidth, LengthModeWidth, ForbidNegativeLengths), + m_height(DOMPropertyIdHeight, LengthModeHeight, ForbidNegativeLengths) { m_height.setDefaultValue(hundredPercent()); m_width.setDefaultValue(hundredPercent()); @@ -29,7 +29,7 @@ void SVGSVGElement::render(RenderContext& context) const const RenderState& state = context.state(); Rect viewPort; - if(state.element->elementId() == ElementIdUse) + if(state.element->elementId() == DOMElementIdUse) { viewPort = state.viewPort; } diff --git a/source/svgsymbolelement.cpp b/source/svgsymbolelement.cpp index 366fd7d..a3d81d3 100755 --- a/source/svgsymbolelement.cpp +++ b/source/svgsymbolelement.cpp @@ -3,15 +3,15 @@ namespace lunasvg { -SVGSymbolElement::SVGSymbolElement(SVGDocument* document) : - SVGStyledElement(ElementIdSymbol, document), - SVGFitToViewBox(this) +SVGSymbolElement::SVGSymbolElement(SVGDocument* document) + : SVGStyledElement(DOMElementIdSymbol, document), + SVGFitToViewBox(this) { } void SVGSymbolElement::render(RenderContext& context) const { - if(context.state().element->elementId() != ElementIdUse || style().isDisplayNone()) + if(context.state().element->elementId() != DOMElementIdUse || style().isDisplayNone()) { context.skipElement(); return; diff --git a/source/svgtransform.cpp b/source/svgtransform.cpp index 1782d11..40f33df 100755 --- a/source/svgtransform.cpp +++ b/source/svgtransform.cpp @@ -2,10 +2,10 @@ namespace lunasvg { -#define K_PI 3.14159265358979323846 +#define PI 3.14159265358979323846 -SVGTransform::SVGTransform() : - SVGProperty(PropertyTypeTransform) +SVGTransform::SVGTransform() + : SVGProperty(PropertyTypeTransform) { } @@ -54,7 +54,8 @@ bool SVGTransform::parseTransform(const char*& ptr, TransformType& type, double* return false; } - if(!Utils::skipWs(ptr) || *ptr!='(') + Utils::skipWs(ptr); + if(*ptr!='(') return false; ++ptr; @@ -69,7 +70,7 @@ bool SVGTransform::parseTransform(const char*& ptr, TransformType& type, double* Utils::skipWsComma(ptr); } - if(!*ptr || *ptr!=')' || !(count==required || count==maxCount)) + if(*ptr!=')' || !(count==required || count==maxCount)) return false; ++ptr; @@ -99,9 +100,9 @@ void SVGTransform::setValueAsString(const std::string& value) break; case TransformTypeRotate: if(count == 1) - m_value.rotate(values[0]*K_PI/180.0, 0, 0); + m_value.rotate(values[0]*PI/180.0, 0, 0); else - m_value.rotate(values[0]*K_PI/180.0, values[1], values[2]); + m_value.rotate(values[0]*PI/180.0, values[1], values[2]); break; case TransformTypeScale: if(count == 1) @@ -110,10 +111,10 @@ void SVGTransform::setValueAsString(const std::string& value) m_value.scale(values[0], values[1]); break; case TransformTypeSkewX: - m_value.shear(values[0]*K_PI/180.0, 0); + m_value.shear(values[0]*PI/180.0, 0); break; case TransformTypeSkewY: - m_value.shear(0, values[0]*K_PI/180.0); + m_value.shear(0, values[0]*PI/180.0); break; case TransformTypeTranslate: if(count == 1) @@ -146,7 +147,7 @@ std::string SVGTransform::valueAsString() const out += Utils::toString(m[5]); out += ')'; - return out; + return out; } SVGProperty* SVGTransform::clone() const diff --git a/source/svgurireference.cpp b/source/svgurireference.cpp index e6f718c..93cfb58 100755 --- a/source/svgurireference.cpp +++ b/source/svgurireference.cpp @@ -3,8 +3,8 @@ namespace lunasvg { -SVGURIReference::SVGURIReference(SVGElementHead* element) : - m_href(DOMPropertyIdHref) +SVGURIReference::SVGURIReference(SVGElementHead* element) + : m_href(DOMPropertyIdHref) { element->addToPropertyMap(m_href); } diff --git a/source/svguseelement.cpp b/source/svguseelement.cpp index 767aec5..9ac225d 100755 --- a/source/svguseelement.cpp +++ b/source/svguseelement.cpp @@ -4,13 +4,13 @@ namespace lunasvg { -SVGUseElement::SVGUseElement(SVGDocument* document) : - SVGGraphicsElement(ElementIdUse, document), - SVGURIReference(this), - m_x(DOMPropertyIdX, LengthModeWidth, AllowNegativeLengths), - m_y(DOMPropertyIdY, LengthModeHeight, AllowNegativeLengths), - m_width(DOMPropertyIdWidth, LengthModeWidth, ForbidNegativeLengths), - m_height(DOMPropertyIdHeight, LengthModeHeight, ForbidNegativeLengths) +SVGUseElement::SVGUseElement(SVGDocument* document) + : SVGGraphicsElement(DOMElementIdUse, document), + SVGURIReference(this), + m_x(DOMPropertyIdX, LengthModeWidth, AllowNegativeLengths), + m_y(DOMPropertyIdY, LengthModeHeight, AllowNegativeLengths), + m_width(DOMPropertyIdWidth, LengthModeWidth, ForbidNegativeLengths), + m_height(DOMPropertyIdHeight, LengthModeHeight, ForbidNegativeLengths) { m_height.setDefaultValue(hundredPercent()); m_width.setDefaultValue(hundredPercent()); @@ -53,7 +53,7 @@ void SVGUseElement::render(RenderContext& context) const newState.color = state.color; newState.dpi = state.dpi; - if(ref->elementId()==ElementIdSvg || ref->elementId()==ElementIdSymbol) + if(ref->elementId()==DOMElementIdSvg || ref->elementId()==DOMElementIdSymbol) { double _w = m_width.value(state); double _h = m_height.value(state);