Merge pull request #19996 from MaxiSchwindler/19555_transparent_svg
Add option to export SVGs with transparent background
This commit is contained in:
commit
ace7a60986
|
@ -49,6 +49,10 @@ public:
|
|||
virtual bool exportPngWithTransparentBackground() const = 0;
|
||||
virtual void setExportPngWithTransparentBackground(bool transparent) = 0;
|
||||
|
||||
// Svg
|
||||
virtual bool exportSvgWithTransparentBackground() const = 0;
|
||||
virtual void setExportSvgWithTransparentBackground(bool transparent) = 0;
|
||||
|
||||
virtual int trimMarginPixelSize() const = 0;
|
||||
virtual void setTrimMarginPixelSize(std::optional<int> pixelSize) = 0;
|
||||
};
|
||||
|
|
|
@ -31,6 +31,7 @@ using namespace mu::iex::imagesexport;
|
|||
static const Settings::Key EXPORT_PDF_DPI_RESOLUTION_KEY("iex_imagesexport", "export/pdf/dpi");
|
||||
static const Settings::Key EXPORT_PNG_DPI_RESOLUTION_KEY("iex_imagesexport", "export/png/resolution");
|
||||
static const Settings::Key EXPORT_PNG_USE_TRANSPARENCY_KEY("iex_imagesexport", "export/png/useTransparency");
|
||||
static const Settings::Key EXPORT_SVG_USE_TRANSPARENCY_KEY("iex_imagesexport", "export/svg/useTransparency");
|
||||
|
||||
void ImagesExportConfiguration::init()
|
||||
{
|
||||
|
@ -78,6 +79,16 @@ void ImagesExportConfiguration::setExportPngWithTransparentBackground(bool trans
|
|||
settings()->setSharedValue(EXPORT_PNG_USE_TRANSPARENCY_KEY, Val(transparent));
|
||||
}
|
||||
|
||||
bool ImagesExportConfiguration::exportSvgWithTransparentBackground() const
|
||||
{
|
||||
return settings()->value(EXPORT_SVG_USE_TRANSPARENCY_KEY).toBool();
|
||||
}
|
||||
|
||||
void ImagesExportConfiguration::setExportSvgWithTransparentBackground(bool transparent)
|
||||
{
|
||||
settings()->setSharedValue(EXPORT_SVG_USE_TRANSPARENCY_KEY, Val(transparent));
|
||||
}
|
||||
|
||||
int ImagesExportConfiguration::trimMarginPixelSize() const
|
||||
{
|
||||
return m_trimMarginPixelSize ? m_trimMarginPixelSize.value() : -1;
|
||||
|
|
|
@ -40,6 +40,9 @@ public:
|
|||
bool exportPngWithTransparentBackground() const override;
|
||||
void setExportPngWithTransparentBackground(bool transparent) override;
|
||||
|
||||
bool exportSvgWithTransparentBackground() const override;
|
||||
void setExportSvgWithTransparentBackground(bool transparent) override;
|
||||
|
||||
int trimMarginPixelSize() const override;
|
||||
void setTrimMarginPixelSize(std::optional<int> pixelSize) override;
|
||||
|
||||
|
|
|
@ -61,7 +61,8 @@ mu::Ret PngWriter::write(INotationPtr notation, QIODevice& destinationDevice, co
|
|||
image.setDotsPerMeterX(std::lrint((CANVAS_DPI * 1000) / mu::engraving::INCH));
|
||||
image.setDotsPerMeterY(std::lrint((CANVAS_DPI * 1000) / mu::engraving::INCH));
|
||||
|
||||
const bool TRANSPARENT_BACKGROUND = options.value(OptionKey::TRANSPARENT_BACKGROUND, Val(false)).toBool();
|
||||
const bool TRANSPARENT_BACKGROUND = options.value(OptionKey::TRANSPARENT_BACKGROUND,
|
||||
Val(configuration()->exportPngWithTransparentBackground())).toBool();
|
||||
image.fill(TRANSPARENT_BACKGROUND ? Qt::transparent : Qt::white);
|
||||
|
||||
mu::draw::Painter painter(&image, "pngwriter");
|
||||
|
|
|
@ -99,7 +99,9 @@ mu::Ret SvgWriter::write(INotationPtr notation, QIODevice& destinationDevice, co
|
|||
|
||||
mu::engraving::MScore::pixelRatio = mu::engraving::DPI / printer.logicalDpiX();
|
||||
|
||||
if (!options[OptionKey::TRANSPARENT_BACKGROUND].toBool()) {
|
||||
const bool TRANSPARENT_BACKGROUND = options.value(OptionKey::TRANSPARENT_BACKGROUND,
|
||||
Val(configuration()->exportSvgWithTransparentBackground())).toBool();
|
||||
if (!TRANSPARENT_BACKGROUND) {
|
||||
painter.fillRect(pageRect, mu::draw::Color::WHITE);
|
||||
}
|
||||
|
||||
|
|
|
@ -176,7 +176,6 @@ bool ExportProjectScenario::exportScores(const notation::INotationPtrList& notat
|
|||
|
||||
INotationWriter::Options options {
|
||||
{ INotationWriter::OptionKey::UNIT_TYPE, Val(unitType) },
|
||||
{ INotationWriter::OptionKey::TRANSPARENT_BACKGROUND, Val(imagesExportConfiguration()->exportPngWithTransparentBackground()) }
|
||||
};
|
||||
|
||||
switch (unitType) {
|
||||
|
|
|
@ -24,6 +24,22 @@ import QtQuick 2.15
|
|||
import MuseScore.UiComponents 1.0
|
||||
|
||||
ExportSettingsPage {
|
||||
id: root
|
||||
|
||||
CheckBox {
|
||||
width: parent.width
|
||||
text: qsTrc("project/export", "Transparent background")
|
||||
|
||||
navigation.name: "TransparentBackgroundCheckbox"
|
||||
navigation.panel: root.navigationPanel
|
||||
navigation.row: root.navigationOrder + 2
|
||||
|
||||
checked: root.model.svgTransparentBackground
|
||||
onClicked: {
|
||||
root.model.svgTransparentBackground = !checked
|
||||
}
|
||||
}
|
||||
|
||||
StyledTextLabel {
|
||||
width: parent.width
|
||||
text: qsTrc("project/export", "Each page of the selected parts will be exported as a separate %1 file.").arg("SVG")
|
||||
|
|
|
@ -433,6 +433,21 @@ void ExportDialogModel::setPngTransparentBackground(const bool& transparent)
|
|||
emit pngTransparentBackgroundChanged(transparent);
|
||||
}
|
||||
|
||||
bool ExportDialogModel::svgTransparentBackground() const
|
||||
{
|
||||
return imageExportConfiguration()->exportSvgWithTransparentBackground();
|
||||
}
|
||||
|
||||
void ExportDialogModel::setSvgTransparentBackground(const bool& transparent)
|
||||
{
|
||||
if (transparent == svgTransparentBackground()) {
|
||||
return;
|
||||
}
|
||||
|
||||
imageExportConfiguration()->setExportSvgWithTransparentBackground(transparent);
|
||||
emit svgTransparentBackgroundChanged(transparent);
|
||||
}
|
||||
|
||||
QList<int> ExportDialogModel::availableSampleRates() const
|
||||
{
|
||||
const std::vector<int>& rates = audioExportConfiguration()->availableSampleRates();
|
||||
|
|
|
@ -71,6 +71,9 @@ class ExportDialogModel : public QAbstractListModel, public async::Asyncable
|
|||
Q_PROPERTY(
|
||||
bool pngTransparentBackground READ pngTransparentBackground WRITE setPngTransparentBackground NOTIFY pngTransparentBackgroundChanged)
|
||||
|
||||
Q_PROPERTY(
|
||||
bool svgTransparentBackground READ svgTransparentBackground WRITE setSvgTransparentBackground NOTIFY svgTransparentBackgroundChanged)
|
||||
|
||||
Q_PROPERTY(int sampleRate READ sampleRate WRITE setSampleRate NOTIFY sampleRateChanged)
|
||||
Q_PROPERTY(int bitRate READ bitRate WRITE setBitRate NOTIFY bitRateChanged)
|
||||
|
||||
|
@ -120,6 +123,9 @@ public:
|
|||
bool pngTransparentBackground() const;
|
||||
void setPngTransparentBackground(const bool& transparent);
|
||||
|
||||
bool svgTransparentBackground() const;
|
||||
void setSvgTransparentBackground(const bool& transparent);
|
||||
|
||||
Q_INVOKABLE QList<int> availableSampleRates() const;
|
||||
int sampleRate() const;
|
||||
void setSampleRate(int sampleRate);
|
||||
|
@ -164,6 +170,8 @@ signals:
|
|||
void pngResolutionChanged(int resolution);
|
||||
void pngTransparentBackgroundChanged(bool transparent);
|
||||
|
||||
void svgTransparentBackgroundChanged(bool transparent);
|
||||
|
||||
void availableSampleRatesChanged();
|
||||
void sampleRateChanged(int sampleRate);
|
||||
void availableBitRatesChanged();
|
||||
|
|
Loading…
Reference in New Issue