Skip to content

Commit

Permalink
Release v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Aug 14, 2020
1 parent e902221 commit e4f1917
Show file tree
Hide file tree
Showing 239 changed files with 273 additions and 321 deletions.
15 changes: 15 additions & 0 deletions 3rdparty/agg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
target_sources(lunasvg
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/src/agg_vcgen_stroke.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/agg_vcgen_dash.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/agg_vcgen_contour.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/agg_trans_affine.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/agg_curves.cpp"
"${CMAKE_CURRENT_LIST_DIR}/src/agg_sqrt_tables.cpp"
)

target_include_directories(lunasvg
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/include"
)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 5 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
cmake_minimum_required(VERSION 3.3)

set(LUNASVG_MAJOR_VERSION 0)
set(LUNASVG_MINOR_VERSION 1)
set(LUNASVG_PATCH_VERSION 0)
set(LUNASVG_VERSION ${LUNASVG_MAJOR_VERSION}.${LUNASVG_MINOR_VERSION}.${LUNASVG_PATCH_VERSION})

project(lunasvg VERSION ${LUNASVG_VERSION} LANGUAGES CXX)
project(lunasvg VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)

Expand All @@ -27,6 +22,10 @@ if(LUNASVG_ENABLE_CAIRO)
pkg_check_modules(CAIRO REQUIRED cairo)
target_include_directories(lunasvg PRIVATE ${CAIRO_INCLUDE_DIRS})
target_link_libraries(lunasvg ${CAIRO_LIBRARIES})
add_subdirectory(source/backends/cairo)
else()
add_subdirectory(3rdparty/agg)
add_subdirectory(source/backends/agg)
endif()

set(LUNASVG_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib)
Expand All @@ -44,4 +43,3 @@ install(TARGETS lunasvg
ARCHIVE DESTINATION ${LUNASVG_LIBDIR}
INCLUDES DESTINATION ${LUNASVG_INCDIR}
)

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main()
- Basic Shapes : rect, circle, ellipse, line, polyline, polygon, path.
- Paint Servers : solidColor, linearGradient, radialGradient, pattern.
- Clipping, Masking and Compositing : clipPath, mask, group opacity.
- Document Structure: defs, svg, g, use, symbol.
- Document Structures: defs, svg, g, use, symbol.
- Coordinate Systems, Transformations and Units.
- Texts (TODO) : text, tspan, tref, textPath.
- Animations (TODO) : animate, animateColor, animateMotion, animateTransform
Expand Down
18 changes: 17 additions & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
add_subdirectory(geometry)
add_subdirectory(graphics)
add_subdirectory(properties)

target_sources(lunasvg
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/cssproperty.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgcolor.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgenumeration.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svglength.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svglengthlist.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgnumber.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgnumberlist.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgpath.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgpoint.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgpointlist.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgpreserveaspectratio.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgproperty.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgpropertyutils.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgrect.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgstring.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgstringlist.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgtransform.cpp"
"${CMAKE_CURRENT_LIST_DIR}/rendercontext.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgdefselement.cpp"
"${CMAKE_CURRENT_LIST_DIR}/svgdocument.cpp"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ template<typename source_t, typename span_generator_t>
void CanvasImpl::render_pattern(const Pattern* pattern, const agg::trans_affine& matrix)
{
typedef agg::span_interpolator_linear<> span_interpolator_t;
typedef agg::span_allocator<typename pixel_format_t::color_type> span_allocator_t;
typedef agg::span_allocator<agg::rgba8> span_allocator_t;
typedef agg::renderer_scanline_aa<renderer_base_t, span_allocator_t, span_generator_t> pattern_renderer_t;

agg::trans_affine transform(to_agg_transform(pattern->matrix()));
Expand Down Expand Up @@ -353,7 +353,7 @@ void CanvasImpl::render_scanlines(const Paint& paint, const agg::trans_affine& m
{
const RadialGradient* radial = static_cast<const RadialGradient*>(g);
agg::gradient_radial_focus gradient_function(KGradientScale, KGradientScale*(radial->fx() - radial->cx())/ radial->r(), KGradientScale*(radial->fy() - radial->cy())/ radial->r());
render_gradient(gradient_function, radial, paint.opacity(), matrix);
render_gradient(gradient_function, g, paint.opacity(), matrix);
}
}
else if(paint.type() == PaintTypePattern)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
add_subdirectory(include)
add_subdirectory(src)

target_sources(lunasvg
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/canvasimpl.cpp"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions source/properties/cssproperty.h → source/cssproperty.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef DOMSVGSTYLE_H
#define DOMSVGSTYLE_H
#ifndef CSSPROPERTY_H
#define CSSPROPERTY_H

#include "svgproperty.h"

Expand Down Expand Up @@ -138,4 +138,4 @@ class DOMSVGStyle : public DOMSVGProperty<CSSPropertyList>

} // namespace lunasvg

#endif // DOMSVGSTYLE_H
#endif // CSSPROPERTY_H
119 changes: 62 additions & 57 deletions source/geometry/affinetransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,11 @@ void AffineTransform::setMatrix(double m00, double m10, double m01, double m11,
m_matrix[4] = m02; m_matrix[5] = m12;
}

void AffineTransform::multiply(const double* a, const double* b)
void AffineTransform::makeIdentity()
{
double m00 = a[0] * b[0] + a[1] * b[2];
double m10 = a[0] * b[1] + a[1] * b[3];
double m01 = a[2] * b[0] + a[3] * b[2];
double m11 = a[2] * b[1] + a[3] * b[3];
double m02 = a[4] * b[0] + a[5] * b[2] + b[4];
double m12 = a[4] * b[1] + a[5] * b[3] + b[5];

m_matrix[0] = m00; m_matrix[1] = m10;
m_matrix[2] = m01; m_matrix[3] = m11;
m_matrix[4] = m02; m_matrix[5] = m12;
}

AffineTransform& AffineTransform::multiply(const AffineTransform& transform)
{
const double* a = m_matrix;
const double* b = transform.m_matrix;
multiply(b, a);

return *this;
}

AffineTransform& AffineTransform::postmultiply(const AffineTransform& transform)
{
const double* a = m_matrix;
const double* b = transform.m_matrix;
multiply(a, b);

return *this;
m_matrix[0] = 1.0; m_matrix[1] = 0.0;
m_matrix[2] = 0.0; m_matrix[3] = 1.0;
m_matrix[4] = 0.0; m_matrix[5] = 0.0;
}

AffineTransform AffineTransform::inverted() const
Expand All @@ -94,21 +69,42 @@ AffineTransform AffineTransform::inverted() const
m02, m12);
}

void AffineTransform::reset()
AffineTransform AffineTransform::operator*(const AffineTransform& transform) const
{
m_matrix[0] = 1.0; m_matrix[1] = 0.0;
m_matrix[2] = 0.0; m_matrix[3] = 1.0;
m_matrix[4] = 0.0; m_matrix[5] = 0.0;
const double* a = m_matrix;
const double* b = transform.m_matrix;

double m00 = a[0] * b[0] + a[1] * b[2];
double m10 = a[0] * b[1] + a[1] * b[3];
double m01 = a[2] * b[0] + a[3] * b[2];
double m11 = a[2] * b[1] + a[3] * b[3];
double m02 = a[4] * b[0] + a[5] * b[2] + b[4];
double m12 = a[4] * b[1] + a[5] * b[3] + b[5];

return AffineTransform(m00, m10,
m01, m11,
m02, m12);
}

AffineTransform AffineTransform::makeIdentity()
AffineTransform& AffineTransform::operator*=(const AffineTransform& transform)
{
return AffineTransform(1, 0,
0, 1,
0, 0);
*this = *this * transform;
return *this;
}

AffineTransform AffineTransform::makeRotate(double radians)
AffineTransform& AffineTransform::multiply(const AffineTransform& transform)
{
*this = transform * *this;
return *this;
}

AffineTransform& AffineTransform::postmultiply(const AffineTransform& transform)
{
*this = *this * transform;
return *this;
}

AffineTransform AffineTransform::fromRotate(double radians)
{
double c = std::cos(radians);
double s = std::sin(radians);
Expand All @@ -118,7 +114,7 @@ AffineTransform AffineTransform::makeRotate(double radians)
0, 0);
}

AffineTransform AffineTransform::makeRotate(double radians, double cx, double cy)
AffineTransform AffineTransform::fromRotate(double radians, double cx, double cy)
{
double c = std::cos(radians);
double s = std::sin(radians);
Expand All @@ -131,14 +127,14 @@ AffineTransform AffineTransform::makeRotate(double radians, double cx, double cy
x, y);
}

AffineTransform AffineTransform::makeScale(double sx, double sy)
AffineTransform AffineTransform::fromScale(double sx, double sy)
{
return AffineTransform(sx, 0,
0, sy,
0, 0);
}

AffineTransform AffineTransform::makeShear(double shx, double shy)
AffineTransform AffineTransform::fromShear(double shx, double shy)
{
double x = std::tan(shx);
double y = std::tan(shy);
Expand All @@ -148,36 +144,36 @@ AffineTransform AffineTransform::makeShear(double shx, double shy)
0, 0);
}

AffineTransform AffineTransform::makeTranslate(double tx, double ty)
AffineTransform AffineTransform::fromTranslate(double tx, double ty)
{
return AffineTransform(1, 0,
0, 1,
tx, ty);
}

void AffineTransform::rotate(double radians)
AffineTransform& AffineTransform::rotate(double radians)
{
multiply(makeRotate(radians));
return multiply(fromRotate(radians));
}

void AffineTransform::rotate(double radians, double cx, double cy)
AffineTransform& AffineTransform::rotate(double radians, double cx, double cy)
{
multiply(makeRotate(radians, cx, cy));
return multiply(fromRotate(radians, cx, cy));
}

void AffineTransform::scale(double sx, double sy)
AffineTransform& AffineTransform::scale(double sx, double sy)
{
multiply(makeScale(sx, sy));
return multiply(fromScale(sx, sy));
}

void AffineTransform::shear(double shx, double shy)
AffineTransform& AffineTransform::shear(double shx, double shy)
{
multiply(makeShear(shx, shy));
return multiply(fromShear(shx, shy));
}

void AffineTransform::translate(double cx, double cy)
AffineTransform& AffineTransform::translate(double cx, double cy)
{
multiply(makeTranslate(cx, cy));
return multiply(fromTranslate(cx, cy));
}

void AffineTransform::map(double x, double y, double& _x, double& _y) const
Expand All @@ -186,10 +182,22 @@ void AffineTransform::map(double x, double y, double& _x, double& _y) const
_y = x * m_matrix[1] + y * m_matrix[3] + m_matrix[5];
}

void AffineTransform::map(const double* src, double* dst, int size) const
{
for(int i = 0;i < size;i+=2)
map(src[i], src[i+1], dst[i], dst[i+1]);
}

void AffineTransform::map(const Point* src, Point* dst, int size) const
{
for(int i = 0;i < size;i++)
map(src[i].x, src[i].y, dst[i].x, dst[i].y);
}

Point AffineTransform::mapPoint(const Point& point) const
{
Point p;
map(point.x, point.y, p.x, p.y);
map(&point, &p, 1);
return p;
}

Expand All @@ -205,10 +213,7 @@ Rect AffineTransform::mapRect(const Rect& rect) const
p[3].x = rect.x;
p[3].y = rect.y + rect.height;

map(p[0].x, p[0].y, p[0].x, p[0].y);
map(p[1].x, p[1].y, p[1].x, p[1].y);
map(p[2].x, p[2].y, p[2].x, p[2].y);
map(p[3].x, p[3].y, p[3].x, p[3].y);
map(p, p, 4);

double l = p[0].x;
double t = p[0].y;
Expand Down
36 changes: 20 additions & 16 deletions source/geometry/affinetransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,31 @@ class AffineTransform
AffineTransform(double m00, double m10, double m01, double m11, double m02, double m12);

void setMatrix(double m00, double m10, double m01, double m11, double m02, double m12);
void multiply(const double* a, const double* b);
void makeIdentity();
AffineTransform inverted() const;

AffineTransform operator*(const AffineTransform& transform) const;
AffineTransform& operator*=(const AffineTransform& transform);

AffineTransform& multiply(const AffineTransform& transform);
AffineTransform& postmultiply(const AffineTransform& transform);
void reset();
AffineTransform& rotate(double radians);
AffineTransform& rotate(double radians, double cx, double cy);
AffineTransform& scale(double sx, double sy);
AffineTransform& shear(double shx, double shy);
AffineTransform& translate(double cx, double cy);

static AffineTransform fromRotate(double radians);
static AffineTransform fromRotate(double radians, double cx, double cy);
static AffineTransform fromScale(double sx, double sy);
static AffineTransform fromShear(double shx, double shy);
static AffineTransform fromTranslate(double tx, double ty);

void map(double x, double y, double& _x, double& _y) const;
void map(const double* src, double* dst, int size) const;
void map(const Point* src, Point* dst, int size) const;
Point mapPoint(const Point& point) const;
Rect mapRect(const Rect& rect) const;
AffineTransform inverted() const;

void rotate(double radians);
void rotate(double radians, double cx, double cy);
void scale(double sx, double sy);
void shear(double angleX, double angleY);
void translate(double cx, double cy);

static AffineTransform makeIdentity();
static AffineTransform makeRotate(double radians);
static AffineTransform makeRotate(double radians, double cx, double cy);
static AffineTransform makeScale(double sx, double sy);
static AffineTransform makeShear(double shx, double shy);
static AffineTransform makeTranslate(double tx, double ty);

bool isIdentity() const;
double determinant() const;
Expand Down
Loading

0 comments on commit e4f1917

Please sign in to comment.