bully
bully

Reputation: 5994

JavaFX: how to use matrix transformations of SVG

it's me again :)

My question today focusses SVG. Within SVG, you can group different <path> elements within a <g> tag for being able to call transformations for all paths at once. Additionally, there are some transformations / operations which only can be called on groups, not on paths directly.

I have an SVG source I need to display in my UI, containing different elements like described above. So I have something like:

<g id="myId" transform="matrix(-1,2.4336e-008,-2.4336e-008,-1,2163.78,1161.93)">
  <path .../>
</g>

Currently I'm using SVGPath and a Stackpane, which works quite well. I'm just wondering how I could deal with the matrix transformation? As there is no according SVGGroup class, I guess I have to implement this myself, rules are described here.

Am I on the right way or do I miss something again? Would you maybe recommend using Images instead of dealing with the SVG stuff (though I don't know exactly how this would help in this special case concerning the matrix transformations).

As everytime, any recommendation is appreciated :)

Cheers.

Upvotes: 1

Views: 751

Answers (1)

Sergey Grinev
Sergey Grinev

Reputation: 34518

You can use FX transforms:

    SVGPath path = new SVGPath();
    path.setContent("M50,50 L100,50 L100,100 L50,50 Z");
    path.getTransforms().add(
         Transform.affine(-1,2.4336e-008,-2.4336e-008,-1,2163.78,1161.93));

Your numbers are a bit extreme, but for simple transforms I've tried matrix parameters are the same as Transform#affine ones.

Upvotes: 2

Related Questions