mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-10 14:41:50 +00:00
svg_loader: code refactoring
removed duplicate matrix multiply function.
This commit is contained in:
parent
d23e0fd22c
commit
9972fa9831
2 changed files with 27 additions and 36 deletions
17
src/examples/resources/skew.svg
Normal file
17
src/examples/resources/skew.svg
Normal file
|
@ -0,0 +1,17 @@
|
|||
<svg
|
||||
viewBox="-40 0 150 100"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g
|
||||
fill="grey"
|
||||
transform="rotate(-10 50 100)
|
||||
translate(-36 45.5)
|
||||
skewX(40)
|
||||
scale(1 0.5)">
|
||||
<path
|
||||
id="heart"
|
||||
d="M 10,30 A 20,20 0,0,1 50,30 A 20,20 0,0,1 90,30 Q 90,60 50,90 Q 10,60 10,30 z" />
|
||||
</g>
|
||||
|
||||
<use href="#heart" fill="none" stroke="red" />
|
||||
</svg>
|
After Width: | Height: | Size: 440 B |
|
@ -683,32 +683,6 @@ static constexpr struct
|
|||
};
|
||||
|
||||
|
||||
static void _matrixCompose(const Matrix* m1, const Matrix* m2, Matrix* dst)
|
||||
{
|
||||
auto a11 = (m1->e11 * m2->e11) + (m1->e12 * m2->e21) + (m1->e13 * m2->e31);
|
||||
auto a12 = (m1->e11 * m2->e12) + (m1->e12 * m2->e22) + (m1->e13 * m2->e32);
|
||||
auto a13 = (m1->e11 * m2->e13) + (m1->e12 * m2->e23) + (m1->e13 * m2->e33);
|
||||
|
||||
auto a21 = (m1->e21 * m2->e11) + (m1->e22 * m2->e21) + (m1->e23 * m2->e31);
|
||||
auto a22 = (m1->e21 * m2->e12) + (m1->e22 * m2->e22) + (m1->e23 * m2->e32);
|
||||
auto a23 = (m1->e21 * m2->e13) + (m1->e22 * m2->e23) + (m1->e23 * m2->e33);
|
||||
|
||||
auto a31 = (m1->e31 * m2->e11) + (m1->e32 * m2->e21) + (m1->e33 * m2->e31);
|
||||
auto a32 = (m1->e31 * m2->e12) + (m1->e32 * m2->e22) + (m1->e33 * m2->e32);
|
||||
auto a33 = (m1->e31 * m2->e13) + (m1->e32 * m2->e23) + (m1->e33 * m2->e33);
|
||||
|
||||
dst->e11 = a11;
|
||||
dst->e12 = a12;
|
||||
dst->e13 = a13;
|
||||
dst->e21 = a21;
|
||||
dst->e22 = a22;
|
||||
dst->e23 = a23;
|
||||
dst->e31 = a31;
|
||||
dst->e32 = a32;
|
||||
dst->e33 = a33;
|
||||
}
|
||||
|
||||
|
||||
/* parse transform attribute
|
||||
* https://www.w3.org/TR/SVG/coords.html#TransformAttribute
|
||||
*/
|
||||
|
@ -751,14 +725,14 @@ static Matrix* _parseTransformationMatrix(const char* value)
|
|||
if (state == MatrixState::Matrix) {
|
||||
if (ptCount != 6) goto error;
|
||||
Matrix tmp = {points[0], points[2], points[4], points[1], points[3], points[5], 0, 0, 1};
|
||||
_matrixCompose(matrix, &tmp, matrix);
|
||||
*matrix = mathMultiply(matrix, &tmp);
|
||||
} else if (state == MatrixState::Translate) {
|
||||
if (ptCount == 1) {
|
||||
Matrix tmp = {1, 0, points[0], 0, 1, 0, 0, 0, 1};
|
||||
_matrixCompose(matrix, &tmp, matrix);
|
||||
*matrix = mathMultiply(matrix, &tmp);
|
||||
} else if (ptCount == 2) {
|
||||
Matrix tmp = {1, 0, points[0], 0, 1, points[1], 0, 0, 1};
|
||||
_matrixCompose(matrix, &tmp, matrix);
|
||||
*matrix = mathMultiply(matrix, &tmp);
|
||||
} else goto error;
|
||||
} else if (state == MatrixState::Rotate) {
|
||||
//Transform to signed.
|
||||
|
@ -768,14 +742,14 @@ static Matrix* _parseTransformationMatrix(const char* value)
|
|||
auto s = sinf(points[0] * (M_PI / 180.0));
|
||||
if (ptCount == 1) {
|
||||
Matrix tmp = { c, -s, 0, s, c, 0, 0, 0, 1 };
|
||||
_matrixCompose(matrix, &tmp, matrix);
|
||||
*matrix = mathMultiply(matrix, &tmp);
|
||||
} else if (ptCount == 3) {
|
||||
Matrix tmp = { 1, 0, points[1], 0, 1, points[2], 0, 0, 1 };
|
||||
_matrixCompose(matrix, &tmp, matrix);
|
||||
*matrix = mathMultiply(matrix, &tmp);
|
||||
tmp = { c, -s, 0, s, c, 0, 0, 0, 1 };
|
||||
_matrixCompose(matrix, &tmp, matrix);
|
||||
*matrix = mathMultiply(matrix, &tmp);
|
||||
tmp = { 1, 0, -points[1], 0, 1, -points[2], 0, 0, 1 };
|
||||
_matrixCompose(matrix, &tmp, matrix);
|
||||
*matrix = mathMultiply(matrix, &tmp);
|
||||
} else {
|
||||
goto error;
|
||||
}
|
||||
|
@ -785,17 +759,17 @@ static Matrix* _parseTransformationMatrix(const char* value)
|
|||
auto sy = sx;
|
||||
if (ptCount == 2) sy = points[1];
|
||||
Matrix tmp = { sx, 0, 0, 0, sy, 0, 0, 0, 1 };
|
||||
_matrixCompose(matrix, &tmp, matrix);
|
||||
*matrix = mathMultiply(matrix, &tmp);
|
||||
} else if (state == MatrixState::SkewX) {
|
||||
if (ptCount != 1) goto error;
|
||||
auto deg = tanf(points[0] * (M_PI / 180.0));
|
||||
Matrix tmp = { 1, deg, 0, 0, 1, 0, 0, 0, 1 };
|
||||
_matrixCompose(matrix, &tmp, matrix);
|
||||
*matrix = mathMultiply(matrix, &tmp);
|
||||
} else if (state == MatrixState::SkewY) {
|
||||
if (ptCount != 1) goto error;
|
||||
auto deg = tanf(points[0] * (M_PI / 180.0));
|
||||
Matrix tmp = { 1, 0, 0, deg, 1, 0, 0, 0, 1 };
|
||||
_matrixCompose(matrix, &tmp, matrix);
|
||||
*matrix = mathMultiply(matrix, &tmp);
|
||||
}
|
||||
}
|
||||
return matrix;
|
||||
|
|
Loading…
Add table
Reference in a new issue