[webkit-gtk] rendering a webpage to SVG

Konstantin Tokarev annulen at yandex.ru
Fri Aug 21 02:56:16 PDT 2020



21.08.2020, 11:49, "Ivan Klimek" <ivan at xclbr.com>:
> Hi Carlos,
>
> thanks for your fast reply
>
> not sure if this helps or if your question was addressed to me - from my *very* limited understanding - how its done its done in Qt - they have the qt_svg module that implements methods that directly write vectorized SVG elements:
>
> void drawEllipse(const QRectF &r) override;
>
> void drawPath(const QPainterPath &path) override;
>
> void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) override;
>
> void drawPolygon(const QPointF *points, int pointCount, PolygonDrawMode mode) override;
>
> void drawRects(const QRectF *rects, int rectCount) override;
>
> void drawTextItem(const QPointF &pt, const QTextItem &item) override;
>
> void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr,
>
> Qt::ImageConversionFlags flags = Qt::AutoColor) override;
>
> see here: https://github.com/qt/qtsvg/blob/dev/src/svg/qsvggenerator.cpp
>
> from code its used like this:
>
>     QWebFrame *frame = m_page.mainFrame();
>     QPainter painter;
>     QSvgGenerator svg;
>
>     svg.setFileName(fileName);
>     svg.setSize(resolution);
>
>     painter.begin(&svg);
>
>     frame->render(&painter);
>
> and that's all - output is vector SVG - every text / formatting etc all vector
>
> cairo is able to draw to SVG vectorized too, but the surface types need to be set correctly when drawing, I took a very light look at webkit-gtk cairo usage and cairo surface types are image types / aka bitmap so it draws stuff already to bitmap, and once in bitmap there is no way back :( but maybe I am reading this wrong, not sure
>
> *I do not know why this is done the way it is done in webkit-gtk, maybe it would be possible to just internally use svg surfaces?*
>
> would be epic if webkit-gtk could do something like that as Qt Webkit is dead and there are so many projects using this ...

QtWebKit is not dead, I'm working on it.
-- 
Regards,
Konstantin


More information about the webkit-gtk mailing list