Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #include "imagesexportconfiguration.h"
23 :
24 : #include "settings.h"
25 :
26 : #include "engraving/dom/mscore.h"
27 :
28 : using namespace muse;
29 : using namespace mu;
30 : using namespace mu::iex::imagesexport;
31 :
32 : static const Settings::Key EXPORT_PDF_DPI_RESOLUTION_KEY("iex_imagesexport", "export/pdf/dpi");
33 : static const Settings::Key EXPORT_PDF_USE_TRANSPARENCY_KEY("iex_imagesexport", "export/pdf/useTransparency");
34 : static const Settings::Key EXPORT_PDF_USE_GRAYSCALE_KEY("iex_imagesexport", "export/pdf/useGrayscale");
35 : static const Settings::Key EXPORT_PNG_DPI_RESOLUTION_KEY("iex_imagesexport", "export/png/resolution");
36 : static const Settings::Key EXPORT_PNG_USE_TRANSPARENCY_KEY("iex_imagesexport", "export/png/useTransparency");
37 : static const Settings::Key EXPORT_PNG_USE_GRAYSCALE_KEY("iex_imagesexport", "export/png/useGrayscale");
38 : static const Settings::Key EXPORT_SVG_USE_TRANSPARENCY_KEY("iex_imagesexport", "export/svg/useTransparency");
39 : static const Settings::Key EXPORT_SVG_ILLUSTRATOR_COMPAT("iex_imagesexport", "export/svg/illustratorCompat");
40 :
41 0 : void ImagesExportConfiguration::init()
42 : {
43 0 : settings()->setDefaultValue(EXPORT_PNG_DPI_RESOLUTION_KEY, Val(mu::engraving::DPI));
44 0 : settings()->setDefaultValue(EXPORT_PDF_DPI_RESOLUTION_KEY, Val(mu::engraving::DPI));
45 0 : settings()->setDefaultValue(EXPORT_PNG_USE_TRANSPARENCY_KEY, Val(false));
46 0 : settings()->setDefaultValue(EXPORT_SVG_ILLUSTRATOR_COMPAT, Val(false));
47 0 : }
48 :
49 0 : int ImagesExportConfiguration::exportPdfDpiResolution() const
50 : {
51 0 : return settings()->value(EXPORT_PDF_DPI_RESOLUTION_KEY).toInt();
52 : }
53 :
54 0 : void ImagesExportConfiguration::setExportPdfDpiResolution(int dpi)
55 : {
56 0 : settings()->setSharedValue(EXPORT_PDF_DPI_RESOLUTION_KEY, Val(dpi));
57 0 : }
58 :
59 0 : bool ImagesExportConfiguration::exportPdfWithTransparentBackground() const
60 : {
61 0 : return settings()->value(EXPORT_PDF_USE_TRANSPARENCY_KEY).toBool();
62 : }
63 :
64 0 : void ImagesExportConfiguration::setExportPdfWithTransparentBackground(bool transparent)
65 : {
66 0 : settings()->setSharedValue(EXPORT_PDF_USE_TRANSPARENCY_KEY, Val(transparent));
67 0 : }
68 :
69 0 : bool ImagesExportConfiguration::exportPdfWithGrayscale() const
70 : {
71 0 : return settings()->value(EXPORT_PDF_USE_GRAYSCALE_KEY).toBool();
72 : }
73 :
74 0 : void ImagesExportConfiguration::setExportPdfWithGrayscale(bool grayscale)
75 : {
76 0 : settings()->setSharedValue(EXPORT_PDF_USE_GRAYSCALE_KEY, Val(grayscale));
77 0 : }
78 :
79 0 : float ImagesExportConfiguration::exportPngDpiResolution() const
80 : {
81 0 : if (m_customExportPngDpiOverride) {
82 0 : return m_customExportPngDpiOverride.value();
83 : }
84 :
85 0 : return settings()->value(EXPORT_PNG_DPI_RESOLUTION_KEY).toFloat();
86 : }
87 :
88 0 : void ImagesExportConfiguration::setExportPngDpiResolution(float dpi)
89 : {
90 0 : settings()->setSharedValue(EXPORT_PNG_DPI_RESOLUTION_KEY, Val(dpi));
91 0 : }
92 :
93 0 : void ImagesExportConfiguration::setExportPngDpiResolutionOverride(std::optional<float> dpi)
94 : {
95 0 : m_customExportPngDpiOverride = dpi;
96 0 : }
97 :
98 0 : bool ImagesExportConfiguration::exportPngWithTransparentBackground() const
99 : {
100 0 : return settings()->value(EXPORT_PNG_USE_TRANSPARENCY_KEY).toBool();
101 : }
102 :
103 0 : void ImagesExportConfiguration::setExportPngWithTransparentBackground(bool transparent)
104 : {
105 0 : settings()->setSharedValue(EXPORT_PNG_USE_TRANSPARENCY_KEY, Val(transparent));
106 0 : }
107 :
108 0 : bool ImagesExportConfiguration::exportPngWithGrayscale() const
109 : {
110 0 : return settings()->value(EXPORT_PNG_USE_GRAYSCALE_KEY).toBool();
111 : }
112 :
113 0 : void ImagesExportConfiguration::setExportPngWithGrayscale(bool grayscale)
114 : {
115 0 : settings()->setSharedValue(EXPORT_PNG_USE_GRAYSCALE_KEY, Val(grayscale));
116 0 : }
117 :
118 0 : bool ImagesExportConfiguration::exportSvgWithTransparentBackground() const
119 : {
120 0 : return settings()->value(EXPORT_SVG_USE_TRANSPARENCY_KEY).toBool();
121 : }
122 :
123 0 : void ImagesExportConfiguration::setExportSvgWithTransparentBackground(bool transparent)
124 : {
125 0 : settings()->setSharedValue(EXPORT_SVG_USE_TRANSPARENCY_KEY, Val(transparent));
126 0 : }
127 :
128 0 : bool ImagesExportConfiguration::exportSvgWithIllustratorCompat() const
129 : {
130 0 : return settings()->value(EXPORT_SVG_ILLUSTRATOR_COMPAT).toBool();
131 : }
132 :
133 0 : void ImagesExportConfiguration::setExportSvgWithIllustratorCompat(bool compat)
134 : {
135 0 : settings()->setSharedValue(EXPORT_SVG_ILLUSTRATOR_COMPAT, Val(compat));
136 0 : }
137 :
138 0 : int ImagesExportConfiguration::trimMarginPixelSize() const
139 : {
140 0 : return m_trimMarginPixelSize ? m_trimMarginPixelSize.value() : -1;
141 : }
142 :
143 0 : void ImagesExportConfiguration::setTrimMarginPixelSize(std::optional<int> pixelSize)
144 : {
145 0 : m_trimMarginPixelSize = pixelSize;
146 0 : }
|