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:
Hermet Park 2025-07-24 18:16:31 +09:00 committed by Hermet Park
parent 0cb903c711
commit 7730f8ba8b
2 changed files with 11 additions and 5 deletions

View file

@ -256,10 +256,11 @@ struct UserExample : tvgexam::Example
shape->moveTo(0, 0);
shape->lineTo(150, 100);
shape->lineTo(0, 100);
shape->close();
shape->fill(255, 0, 255);
shape->strokeWidth(30);
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};
shape->transform(m);

View file

@ -125,10 +125,15 @@ struct ShapeImpl : Shape
//Stroke feathering
if (stroking && rs.stroke) {
x -= rs.stroke->width * 0.5f;
y -= rs.stroke->width * 0.5f;
w += rs.stroke->width;
h += rs.stroke->width;
//Use geometric mean for feathering.
//Join, Cap wouldn't be considered. Generate stroke outline and compute bbox for accurate size?
auto sx = sqrt(m.e11 * m.e11 + m.e21 * m.e21);
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};