svg-flatten: Fix pattern clipping for rotated/skewed transforms

main
jaseg 2023-04-16 20:12:59 +02:00
rodzic 384c917307
commit 4aa448a5a3
1 zmienionych plików z 9 dodań i 9 usunięć

Wyświetl plik

@ -60,8 +60,8 @@ void gerbolyze::Pattern::tile (gerbolyze::RenderContext &ctx) {
* patternTransform. This is necessary so we iterate over the correct bounds when tiling below */
d2p pos_xf = ctx.mat().doc2phys(d2p{x, y});
double inst_x = pos_xf[0], inst_y = pos_xf[1];
double inst_w = ctx.mat().doc2phys_dist(w);
double inst_h = ctx.mat().doc2phys_dist(h);
double inst_w = w;
double inst_h = h;
ClipperLib::IntRect clip_bounds = get_paths_bounds(ctx.clip());
double bx = clip_bounds.left / clipper_scale;
@ -70,12 +70,14 @@ void gerbolyze::Pattern::tile (gerbolyze::RenderContext &ctx) {
double bh = (clip_bounds.bottom - clip_bounds.top) / clipper_scale;
d2p clip_p0 = patternTransform_inv.doc2phys(d2p{bx, by});
d2p clip_p1 = patternTransform_inv.doc2phys(d2p{bx+bw, by+bh});
d2p clip_p1 = patternTransform_inv.doc2phys(d2p{bx+bw, by});
d2p clip_p2 = patternTransform_inv.doc2phys(d2p{bx+bw, by+bh});
d2p clip_p3 = patternTransform_inv.doc2phys(d2p{bx, by+bh});
bx = fmin(clip_p0[0], clip_p1[0]);
by = fmin(clip_p0[1], clip_p1[1]);
bw = fmax(clip_p0[0], clip_p1[0]) - bx;
bh = fmax(clip_p0[1], clip_p1[1]) - by;
bx = fmin(fmin(clip_p0[0], clip_p1[0]), fmin(clip_p2[0], clip_p3[0]));
by = fmin(fmin(clip_p0[1], clip_p1[1]), fmin(clip_p2[1], clip_p3[1]));
bw = fmax(fmax(clip_p0[0], clip_p1[0]), fmax(clip_p2[0], clip_p3[0])) - bx;
bh = fmax(fmax(clip_p0[1], clip_p1[1]), fmax(clip_p2[1], clip_p3[1])) - by;
if (patternUnits == SVG_ObjectBoundingBox) {
inst_x *= bw;
@ -102,11 +104,9 @@ void gerbolyze::Pattern::tile (gerbolyze::RenderContext &ctx) {
for (double inst_off_x = fmod(inst_x, inst_w) - 2*inst_w;
inst_off_x < bx + bw + 2*inst_w;
inst_off_x += inst_w) {
for (double inst_off_y = fmod(inst_y, inst_h) - 2*inst_h;
inst_off_y < by + bh + 2*inst_h;
inst_off_y += inst_h) {
xform2d elem_xf;
/* Change into this individual tile's coordinate system */
elem_xf.translate(inst_off_x, inst_off_y);