我对通过 EasySVG 在 svg 文件中定位文本有误解。 我有一张 svg 格式的图像 1200x1400px。
我需要通过设置坐标来放置文本。
require '../../lib/easysvg/src/easySVG.php';
$svg = new EasySVG($pattern);
$svg->setFont($fontPath, 32, '#000000');
$ppo = 3.779527559;
$left=1200/$ppo;
$top=1400/$ppo;
//there i convert values for pxs to mms
$svg->addText("Text", $left, $top);
file_put_contents('result.svg',$svg->asXML());
结果是下一张图片,但我真的不明白为什么文本包含在(1536;-404)中。 “矩形”的位置与第一张照片相同。 我从来没有使用过矢量 imgs 或 inkscape,我承认这些坐标可以根据一些相对论或类似的东西“转换”。
解决方案!
最后我的问题通过重新计算添加文本的 x 和 y 得到解决。这是帮助我的代码。
$sizeCoef = 2.7069767442;
$newSize = $size/$sizeCoef;
//if i put 43(for example) as font size to ->setFont() method it drawed me 116.4 px height text
$ppo = 3.779527559;
//1 mm = 3.779... pxs
$shift = 1.133786;
// i do not know why, but i calculeted that if i try to shift text position,
//for example, to 100 pxs righter and 100 lower, i get text, moved by 88,2
//in both directions instead of 100 (i think it`s the solution of my problem)
$x = $left/$ppo*$shift;
$y = $top/$ppo*$shift;
// here i recalculate coordinates to mms
$svg->addText($text,$x,$y);
我在题体末尾写了一个解决方案