バティックライブラリを使用してjavaのポリライン要素のみでsvgファイルを解析しています。具体的に解析されたポリラインの点のバウンディングボックスにビューボックスを変更して500pxなどにwidth
とheight
パラメータを変更する、Iは、DOM要素に対して何らかの操作を実行その後バティックを使ってsvgポリラインの変換点を取得
<svg fill-rule="evenodd" height="0.38in" preserveAspectRatio="none"
stroke-linecap="round" viewBox="0 0 150 225" width="0.25in">
<style type="text/css">
.pen1 { stroke: rgb(0,0,0); stroke-width: 19; stroke-linejoin: round;}
</style>
<g>
<polyline class="pen1" fill="none" points="10.0,-95 132.0,2.5 10,105 "/>
</g>
<g/>
</svg>
:これは、例えば、SVGファイルです。
私はポリラインの操作された(拡大縮小された)点を抽出する方法を探しています。
どのようにこれを行うことができますか?私はロバート・Longsonによって提案されたアプローチを試みたが、どうやらgetTransformToElement
EDIT 1
は常に単位行列を返すので、ポイントは同じまま。多分私のコードに何か問題がありますか?
if ((baseElement instanceof SVGLocatable) && (e instanceof SVGElement)) {
SVGSVGElement docSVGElement = (SVGSVGElement) baseElement;
SVGLocatable locatable = (SVGLocatable) baseElement;
SVGElement svgPolyline = (SVGElement) e;
SVGMatrix transformationMatrix = docSVGElement.createSVGMatrix();
transformationMatrix = locatable.getTransformToElement(svgPolyline);
for (Point2D p : points) {
SVGPoint svgPoint = docSVGElement.createSVGPoint();
svgPoint.setX((float) p.getX());
svgPoint.setY((float) p.getY());
SVGPoint svgPoint1 = svgPoint.matrixTransform(transformationMatrix);
normalizedPoints.add(new Point2D.Float(svgPoint1.getX(),svgPoint1.getY()));
}
}
e
はdom構造のPolyLine要素の1つです。
多分、ポイント値をルートからポリライン要素に[getTransformToElement](https://www.w3.org/TR/SVG/single-page.html#types-__svg__SVGLocatable__getTransformToElement)の結果で掛けてください。 –
ありがとう、これは良いアプローチと思われる。 svgにtransform = ...属性が必要ですか?私はまだそれを動作させることができなかった、私の編集された質問を見てください。それはあなたが提案したものですか? –