我需要在 SVG 中找到路径的确切中心点。我使用了路径对象,有什么方法可以处理正确的点,将文本放在 SVG 路径的中心吗? pathMetrics 没有得到中心点。我使用这个路径类 = 类路径扩展 NativeFieldWrapperClass1
transform = transform.replaceAll('matrix(', '').replaceAll(')', '');
List<String> array = transform.split(',').toList();
final double xScale = double.parse(array[0]) * 1.6;
final double yScale = double.parse(array[3]) * 1.6;
Matrix4 matrix4 = Matrix4.identity();
matrix4.scale(xScale, yScale);
double scaledSvgWidth = width * xScale;
//double scaledSvgHeight = height * yScale;
// calculate offset to center the svg image
double offsetX = (size.width - scaledSvgWidth) / 3;
Offset offset = Offset(offsetX, 0.0);
final text = '30';
final ParagraphBuilder paragraphBuilder = ParagraphBuilder(
ParagraphStyle(
fontSize: 10,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.w800,
textAlign: TextAlign.justify,
maxLines: null),
)
..pushStyle(
getTextStyle(),
)
..addText(text);
final Paragraph paragraph = paragraphBuilder.build()
..layout(ParagraphConstraints(width: size.width));
final pathMetrics = paths[index].transform(matrix4.storage).shift(offset).computeMetrics();
final pathMetricsList = pathMetrics.toList();
final tangent = pathMetricsList[0].getTangentForOffset(3)!;
final currLetterPos = tangent.position;
canvas.drawParagraph(paragraph, currLetterPos);[![enter image description here][1]][1]