mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-27 08:36:59 +00:00
renderer: properly support stroke bounding box after scaling.
The stroke bounding box in ThorVG was previously only approximated, as the stroke transformation was mistakenly omitted. This has now been enhanced. The stroke join/corner is still not taken into account in the bounding box computation...
This commit is contained in:
parent
0cb903c711
commit
7730f8ba8b
2 changed files with 11 additions and 5 deletions
|
@ -256,10 +256,11 @@ struct UserExample : tvgexam::Example
|
||||||
shape->moveTo(0, 0);
|
shape->moveTo(0, 0);
|
||||||
shape->lineTo(150, 100);
|
shape->lineTo(150, 100);
|
||||||
shape->lineTo(0, 100);
|
shape->lineTo(0, 100);
|
||||||
|
shape->close();
|
||||||
shape->fill(255, 0, 255);
|
shape->fill(255, 0, 255);
|
||||||
shape->strokeWidth(30);
|
shape->strokeWidth(30);
|
||||||
shape->strokeFill(0, 255, 255);
|
shape->strokeFill(0, 255, 255);
|
||||||
shape->close();
|
shape->strokeJoin(tvg::StrokeJoin::Round);
|
||||||
|
|
||||||
tvg::Matrix m = {1.8794f, -0.6840f, 0.0f, 0.6840f, 1.8794f, 0.0f, 0.0f, 0.0f, 1.0f};
|
tvg::Matrix m = {1.8794f, -0.6840f, 0.0f, 0.6840f, 1.8794f, 0.0f, 0.0f, 0.0f, 1.0f};
|
||||||
shape->transform(m);
|
shape->transform(m);
|
||||||
|
|
|
@ -125,10 +125,15 @@ struct ShapeImpl : Shape
|
||||||
|
|
||||||
//Stroke feathering
|
//Stroke feathering
|
||||||
if (stroking && rs.stroke) {
|
if (stroking && rs.stroke) {
|
||||||
x -= rs.stroke->width * 0.5f;
|
//Use geometric mean for feathering.
|
||||||
y -= rs.stroke->width * 0.5f;
|
//Join, Cap wouldn't be considered. Generate stroke outline and compute bbox for accurate size?
|
||||||
w += rs.stroke->width;
|
auto sx = sqrt(m.e11 * m.e11 + m.e21 * m.e21);
|
||||||
h += rs.stroke->width;
|
auto sy = sqrt(m.e12 * m.e12 + m.e22 * m.e22);
|
||||||
|
auto feather = rs.stroke->width * sqrt(sx * sy);
|
||||||
|
x -= feather * 0.5f;
|
||||||
|
y -= feather * 0.5f;
|
||||||
|
w += feather;
|
||||||
|
h += feather;
|
||||||
}
|
}
|
||||||
|
|
||||||
pt4[0] = {x, y};
|
pt4[0] = {x, y};
|
||||||
|
|
Loading…
Add table
Reference in a new issue