mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 06:04:03 +00:00
sw_engine: revise stroke scaling logic.
previous fast track logic is useless, it actually doesn't helpful for performance, just increase the code complexity. Change-Id: Ib6ad204edfb241d74c41413dfec7ab42fb02af81
This commit is contained in:
parent
f1aab52958
commit
5fdc1f7fc8
2 changed files with 7 additions and 24 deletions
|
@ -153,13 +153,11 @@ struct SwStroke
|
||||||
|
|
||||||
SwStrokeBorder borders[2];
|
SwStrokeBorder borders[2];
|
||||||
|
|
||||||
float sx;
|
float sx, sy;
|
||||||
float sy;
|
|
||||||
|
|
||||||
bool firstPt;
|
bool firstPt;
|
||||||
bool openSubPath;
|
bool openSubPath;
|
||||||
bool handleWideStrokes;
|
bool handleWideStrokes;
|
||||||
bool postScale;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SwDashStroke
|
struct SwDashStroke
|
||||||
|
|
|
@ -36,10 +36,8 @@ static inline SwFixed SIDE_TO_ROTATE(const int32_t s)
|
||||||
|
|
||||||
static inline void SCALE(SwStroke& stroke, SwPoint& pt)
|
static inline void SCALE(SwStroke& stroke, SwPoint& pt)
|
||||||
{
|
{
|
||||||
if (stroke.postScale) {
|
pt.x *= stroke.sx;
|
||||||
pt.x = pt.x * stroke.sx;
|
pt.y *= stroke.sy;
|
||||||
pt.y = pt.y * stroke.sy;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -548,7 +546,6 @@ static void _cubicTo(SwStroke& stroke, const SwPoint& ctrl1, const SwPoint& ctrl
|
||||||
|
|
||||||
SwPoint delta = {alen, 0};
|
SwPoint delta = {alen, 0};
|
||||||
mathRotate(delta, beta);
|
mathRotate(delta, beta);
|
||||||
SCALE(stroke, delta);
|
|
||||||
delta += _start;
|
delta += _start;
|
||||||
|
|
||||||
//circumnavigate the negative sector backwards
|
//circumnavigate the negative sector backwards
|
||||||
|
@ -848,26 +845,14 @@ void strokeReset(SwStroke& stroke, const Shape* sdata, const Matrix* transform)
|
||||||
{
|
{
|
||||||
assert(sdata);
|
assert(sdata);
|
||||||
|
|
||||||
auto scale = 1.0f;
|
|
||||||
|
|
||||||
if (transform) {
|
if (transform) {
|
||||||
//Fast Track: if x/y scale factor is identical, we can scale width size simply.
|
stroke.sx = sqrt(pow(transform->e11, 2) + pow(transform->e21, 2));
|
||||||
auto sx = sqrt(pow(transform->e11, 2) + pow(transform->e21, 2));
|
stroke.sy = sqrt(pow(transform->e12, 2) + pow(transform->e22, 2));
|
||||||
auto sy = sqrt(pow(transform->e12, 2) + pow(transform->e22, 2));
|
|
||||||
if (fabsf(sx - sy) < FLT_EPSILON) {
|
|
||||||
scale = sx;
|
|
||||||
stroke.postScale = false;
|
|
||||||
//Try scaling stroke with normal approach.
|
|
||||||
} else {
|
} else {
|
||||||
stroke.postScale = true;
|
stroke.sx = stroke.sy = 1.0f;
|
||||||
stroke.sx = sx;
|
|
||||||
stroke.sy = sy;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
stroke.postScale = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stroke.width = TO_SWCOORD(sdata->strokeWidth() * 0.5 * scale);
|
stroke.width = TO_SWCOORD(sdata->strokeWidth() * 0.5);
|
||||||
stroke.cap = sdata->strokeCap();
|
stroke.cap = sdata->strokeCap();
|
||||||
|
|
||||||
//Save line join: it can be temporarily changed when stroking curves...
|
//Save line join: it can be temporarily changed when stroking curves...
|
||||||
|
|
Loading…
Add table
Reference in a new issue