mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Preview: fill background
This commit is contained in:
parent
0508e8f34d
commit
b9da920bb4
@ -1656,7 +1656,9 @@ int VUtils::elapsedTime(bool p_reset)
|
||||
return tm.restart();
|
||||
}
|
||||
|
||||
QPixmap VUtils::svgToPixmap(const QByteArray &p_content, qreal p_factor)
|
||||
QPixmap VUtils::svgToPixmap(const QByteArray &p_content,
|
||||
const QString &p_background,
|
||||
qreal p_factor)
|
||||
{
|
||||
QSvgRenderer renderer(p_content);
|
||||
QSize deSz = renderer.defaultSize();
|
||||
@ -1665,6 +1667,10 @@ QPixmap VUtils::svgToPixmap(const QByteArray &p_content, qreal p_factor)
|
||||
}
|
||||
|
||||
QPixmap pm(deSz);
|
||||
if (!p_background.isEmpty()) {
|
||||
pm.fill(p_background);
|
||||
}
|
||||
|
||||
QPainter painter(&pm);
|
||||
renderer.render(&painter);
|
||||
return pm;
|
||||
|
@ -361,7 +361,9 @@ public:
|
||||
|
||||
// Render SVG to Pixmap.
|
||||
// @p_factor: < 0 indicates no scaling.
|
||||
static QPixmap svgToPixmap(const QByteArray &p_content, qreal p_factor);
|
||||
static QPixmap svgToPixmap(const QByteArray &p_content,
|
||||
const QString &p_background,
|
||||
qreal p_factor);
|
||||
|
||||
// Regular expression for image link.
|
||||
// 
|
||||
|
@ -175,17 +175,11 @@ void VLivePreviewHelper::updateCodeBlocks(TimeStamp p_timeStamp, const QVector<V
|
||||
entry->m_ts = m_timeStamp;
|
||||
cached = true;
|
||||
m_codeBlocks[idx].setImageData(entry->m_imgFormat, entry->m_imgData);
|
||||
|
||||
QString background;
|
||||
if (vcb.m_lang == "puml") {
|
||||
background = g_config->getEditorPreviewImageBg();
|
||||
}
|
||||
|
||||
m_codeBlocks[idx].updateInplacePreview(m_editor,
|
||||
m_doc,
|
||||
entry->m_image,
|
||||
entry->m_imageName,
|
||||
background);
|
||||
entry->m_imageBackground);
|
||||
}
|
||||
|
||||
if (m_inplacePreviewEnabled
|
||||
@ -386,6 +380,7 @@ void VLivePreviewHelper::localAsyncResultReady(int p_id,
|
||||
QSharedPointer<CodeBlockImageCacheEntry> entry(new CodeBlockImageCacheEntry(p_timeStamp,
|
||||
p_format,
|
||||
p_result,
|
||||
background,
|
||||
getScaleFactor(cb)));
|
||||
m_cache.insert(text, entry);
|
||||
|
||||
@ -501,6 +496,7 @@ void VLivePreviewHelper::mathjaxPreviewResultReady(int p_identitifer,
|
||||
QSharedPointer<CodeBlockImageCacheEntry> entry(new CodeBlockImageCacheEntry(p_timeStamp,
|
||||
p_format,
|
||||
p_data,
|
||||
"",
|
||||
getScaleFactor(cb)));
|
||||
m_cache.insert(text, entry);
|
||||
|
||||
|
@ -141,16 +141,21 @@ private:
|
||||
CodeBlockImageCacheEntry(TimeStamp p_ts,
|
||||
const QString &p_format,
|
||||
const QByteArray &p_data,
|
||||
const QString &p_background,
|
||||
qreal p_scaleFactor)
|
||||
: m_ts(p_ts)
|
||||
{
|
||||
if (!p_data.isEmpty()) {
|
||||
m_imageBackground = p_background;
|
||||
|
||||
if (p_scaleFactor < SCALE_FACTOR_THRESHOLD) {
|
||||
m_image.loadFromData(p_data,
|
||||
p_format.toLocal8Bit().data());
|
||||
} else {
|
||||
if (p_format == "svg") {
|
||||
m_image = VUtils::svgToPixmap(p_data, p_scaleFactor);
|
||||
m_image = VUtils::svgToPixmap(p_data,
|
||||
m_imageBackground,
|
||||
p_scaleFactor);
|
||||
} else {
|
||||
QPixmap tmpImg;
|
||||
tmpImg.loadFromData(p_data,
|
||||
@ -165,18 +170,23 @@ private:
|
||||
CodeBlockImageCacheEntry(TimeStamp p_ts,
|
||||
const QString &p_format,
|
||||
const QString &p_data,
|
||||
const QString &p_background,
|
||||
qreal p_scaleFactor)
|
||||
: m_ts(p_ts),
|
||||
m_imgData(p_data),
|
||||
m_imgFormat(p_format)
|
||||
{
|
||||
if (!p_data.isEmpty()) {
|
||||
m_imageBackground = p_background;
|
||||
|
||||
if (p_scaleFactor < SCALE_FACTOR_THRESHOLD) {
|
||||
m_image.loadFromData(p_data.toUtf8(),
|
||||
p_format.toLocal8Bit().data());
|
||||
} else {
|
||||
if (p_format == "svg") {
|
||||
m_image = VUtils::svgToPixmap(p_data.toUtf8(), p_scaleFactor);
|
||||
m_image = VUtils::svgToPixmap(p_data.toUtf8(),
|
||||
m_imageBackground,
|
||||
p_scaleFactor);
|
||||
} else {
|
||||
QPixmap tmpImg;
|
||||
tmpImg.loadFromData(p_data.toUtf8(),
|
||||
@ -207,6 +217,7 @@ private:
|
||||
// For in-place preview.
|
||||
QPixmap m_image;
|
||||
QString m_imageName;
|
||||
QString m_imageBackground;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user