mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
Preview: scale SVG via QSvgRenderer
This commit is contained in:
parent
33f4631f91
commit
35f66ba88e
@ -29,6 +29,8 @@
|
||||
#include <QFormLayout>
|
||||
#include <QInputDialog>
|
||||
#include <QFontDatabase>
|
||||
#include <QSvgRenderer>
|
||||
#include <QPainter>
|
||||
|
||||
#include "vorphanfile.h"
|
||||
#include "vnote.h"
|
||||
@ -1653,3 +1655,17 @@ int VUtils::elapsedTime(bool p_reset)
|
||||
|
||||
return tm.restart();
|
||||
}
|
||||
|
||||
QPixmap VUtils::svgToPixmap(const QByteArray &p_content, qreal p_factor)
|
||||
{
|
||||
QSvgRenderer renderer(p_content);
|
||||
QSize deSz = renderer.defaultSize();
|
||||
if (p_factor > 0) {
|
||||
deSz *= p_factor;
|
||||
}
|
||||
|
||||
QPixmap pm(deSz);
|
||||
QPainter painter(&pm);
|
||||
renderer.render(&painter);
|
||||
return pm;
|
||||
}
|
||||
|
@ -359,6 +359,10 @@ public:
|
||||
|
||||
static int elapsedTime(bool p_reset = false);
|
||||
|
||||
// Render SVG to Pixmap.
|
||||
// @p_factor: < 0 indicates no scaling.
|
||||
static QPixmap svgToPixmap(const QByteArray &p_content, qreal p_factor);
|
||||
|
||||
// Regular expression for image link.
|
||||
// 
|
||||
// Captured texts (need to be trimmed):
|
||||
|
@ -149,11 +149,15 @@ private:
|
||||
m_image.loadFromData(p_data,
|
||||
p_format.toLocal8Bit().data());
|
||||
} else {
|
||||
QPixmap tmpImg;
|
||||
tmpImg.loadFromData(p_data,
|
||||
p_format.toLocal8Bit().data());
|
||||
m_image = tmpImg.scaledToWidth(tmpImg.width() * p_scaleFactor,
|
||||
Qt::SmoothTransformation);
|
||||
if (p_format == "svg") {
|
||||
m_image = VUtils::svgToPixmap(p_data, p_scaleFactor);
|
||||
} else {
|
||||
QPixmap tmpImg;
|
||||
tmpImg.loadFromData(p_data,
|
||||
p_format.toLocal8Bit().data());
|
||||
m_image = tmpImg.scaledToWidth(tmpImg.width() * p_scaleFactor,
|
||||
Qt::SmoothTransformation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -171,11 +175,15 @@ private:
|
||||
m_image.loadFromData(p_data.toUtf8(),
|
||||
p_format.toLocal8Bit().data());
|
||||
} else {
|
||||
QPixmap tmpImg;
|
||||
tmpImg.loadFromData(p_data.toUtf8(),
|
||||
p_format.toLocal8Bit().data());
|
||||
m_image = tmpImg.scaledToWidth(tmpImg.width() * p_scaleFactor,
|
||||
Qt::SmoothTransformation);
|
||||
if (p_format == "svg") {
|
||||
m_image = VUtils::svgToPixmap(p_data.toUtf8(), p_scaleFactor);
|
||||
} else {
|
||||
QPixmap tmpImg;
|
||||
tmpImg.loadFromData(p_data.toUtf8(),
|
||||
p_format.toLocal8Bit().data());
|
||||
m_image = tmpImg.scaledToWidth(tmpImg.width() * p_scaleFactor,
|
||||
Qt::SmoothTransformation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user