mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 14:29:54 +08:00
Preview: scale SVG via QSvgRenderer
This commit is contained in:
parent
33f4631f91
commit
35f66ba88e
@ -29,6 +29,8 @@
|
|||||||
#include <QFormLayout>
|
#include <QFormLayout>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QFontDatabase>
|
#include <QFontDatabase>
|
||||||
|
#include <QSvgRenderer>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
#include "vorphanfile.h"
|
#include "vorphanfile.h"
|
||||||
#include "vnote.h"
|
#include "vnote.h"
|
||||||
@ -1653,3 +1655,17 @@ int VUtils::elapsedTime(bool p_reset)
|
|||||||
|
|
||||||
return tm.restart();
|
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);
|
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.
|
// Regular expression for image link.
|
||||||
// 
|
// 
|
||||||
// Captured texts (need to be trimmed):
|
// Captured texts (need to be trimmed):
|
||||||
|
@ -149,11 +149,15 @@ private:
|
|||||||
m_image.loadFromData(p_data,
|
m_image.loadFromData(p_data,
|
||||||
p_format.toLocal8Bit().data());
|
p_format.toLocal8Bit().data());
|
||||||
} else {
|
} else {
|
||||||
QPixmap tmpImg;
|
if (p_format == "svg") {
|
||||||
tmpImg.loadFromData(p_data,
|
m_image = VUtils::svgToPixmap(p_data, p_scaleFactor);
|
||||||
p_format.toLocal8Bit().data());
|
} else {
|
||||||
m_image = tmpImg.scaledToWidth(tmpImg.width() * p_scaleFactor,
|
QPixmap tmpImg;
|
||||||
Qt::SmoothTransformation);
|
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(),
|
m_image.loadFromData(p_data.toUtf8(),
|
||||||
p_format.toLocal8Bit().data());
|
p_format.toLocal8Bit().data());
|
||||||
} else {
|
} else {
|
||||||
QPixmap tmpImg;
|
if (p_format == "svg") {
|
||||||
tmpImg.loadFromData(p_data.toUtf8(),
|
m_image = VUtils::svgToPixmap(p_data.toUtf8(), p_scaleFactor);
|
||||||
p_format.toLocal8Bit().data());
|
} else {
|
||||||
m_image = tmpImg.scaledToWidth(tmpImg.width() * p_scaleFactor,
|
QPixmap tmpImg;
|
||||||
Qt::SmoothTransformation);
|
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