编写路径数据的c++ SVG库

C++ SVG library to write path data

本文关键字:c++ SVG 数据 路径      更新时间:2023-10-16

有人知道一个好的c++库,可以为我生成SVG路径数据吗?这个想法是,我应该使用简单的MoveTo, LineTo, CurveTo命令等,应该得到一个最终的路径字符串。虽然这并不难,我也可以自己写,但为了节省时间,最好有这样的东西存在。

可能太晚了,不过Cairo是用C写的,libboard是c++写的。和简单的svg在c++。

我和这些机构都没有关系。

Qt提供了一个很好的SVG导出器和一个很好的简单的绘图界面:

QSvgGenerator generator;
generator.setFileName(path);
generator.setSize(QSize(200, 200));
generator.setViewBox(QRect(0, 0, 200, 200));
generator.setTitle(tr("SVG Generator Example Drawing"));
generator.setDescription(tr("An SVG drawing created by the SVG Generator "
                            "Example provided with Qt."));
QPainter painter;
painter.begin(&generator);

painter.fillRect(QRect(0, 0, 200, 200), Qt::darkGreen);
painter.setBrush(Qt::green);
painter.setPen(Qt::black);
    for (int y = -55, row = 0; y < 200; y += 50, ++row) {
        int xs;
        if (row == 2 || row == 3)
            xs = 150;
        else
            xs = 50;
        for (int x = 0; x < 200; x += xs) {
            painter.save();
            painter.translate(x, y);
            painter.drawPath(tree);
            painter.restore();
        }
    }

painter.fillRect(QRect(0, 0, 200, 200), Qt::gray);
painter.setPen(QPen(Qt::white, 4, Qt::DashLine));
painter.drawLine(QLine(0, 35, 200, 35));
painter.drawLine(QLine(0, 165, 200, 165));
painter.end();