OBS-URL: https://build.opensuse.org/package/show/KDE:Frameworks/kf6-breeze-icons?expand=0&rev=34
114 lines
5.0 KiB
Diff
114 lines
5.0 KiB
Diff
From 0ba3967bf1cb94e6b6b610f7d01e7474db5aeaeb Mon Sep 17 00:00:00 2001
|
|
From: Mykola Krachkovsky <w01dnick@gmail.com>
|
|
Date: Fri, 14 Jun 2024 20:11:00 +0000
|
|
Subject: [PATCH] skip unneeded icons while generation dark theme icons for
|
|
decrease size of package
|
|
|
|
References: boo#1226207
|
|
---
|
|
src/tools/generate-symbolic-dark.cpp | 45 ++++++++++++++++++++++++++++
|
|
1 file changed, 45 insertions(+)
|
|
|
|
diff --git a/src/tools/generate-symbolic-dark.cpp b/src/tools/generate-symbolic-dark.cpp
|
|
index 365c5ea0..62fb8400 100644
|
|
--- a/src/tools/generate-symbolic-dark.cpp
|
|
+++ b/src/tools/generate-symbolic-dark.cpp
|
|
@@ -109,6 +109,7 @@ int main(int argc, char **argv)
|
|
QStringList unwrittenFiles;
|
|
QStringList xmlReadErrorFiles;
|
|
QStringList xmlWriteErrorFiles;
|
|
+ QRE recolorUsage(u"class=\"(?:[^\"]+\\s)?ColorScheme-(?:Text|Background)[\\s\"]"_s);
|
|
for (auto &inputDir : std::as_const(inputDirs)) {
|
|
QDirIterator dirIt(inputDir, QDirIterator::Subdirectories);
|
|
while (dirIt.hasNext()) {
|
|
@@ -121,6 +122,11 @@ int main(int argc, char **argv)
|
|
continue;
|
|
}
|
|
|
|
+ // Skip applets (used by Plasma and recolored at run-time)
|
|
+ if (inputFilePath.contains("/applets/256/"_L1)) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
// create dir, might be needed for symlink
|
|
QDir outputDir = outputDirInfo.absoluteFilePath();
|
|
const auto outputFilePath = outputDir.absoluteFilePath(QString{inputFilePath}.remove(QRE(u".*/icons/"_s)));
|
|
@@ -149,11 +155,18 @@ int main(int argc, char **argv)
|
|
continue;
|
|
}
|
|
|
|
+ // Skip any icons that don't have class `ColorScheme-Text|Background` usage
|
|
+ if (!recolorUsage.match(QString::fromUtf8(inputData)).hasMatch()) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
QFile outputFile(outputFilePath);
|
|
+ /*
|
|
if (!outputFile.open(QIODevice::WriteOnly)) {
|
|
unwrittenFiles.append("\""_L1 + outputFile.fileName() + "\": "_L1 + outputFile.errorString());
|
|
continue;
|
|
}
|
|
+ */
|
|
|
|
QXmlStreamReader reader(inputData);
|
|
reader.setNamespaceProcessing(false);
|
|
@@ -161,9 +174,32 @@ int main(int argc, char **argv)
|
|
QXmlStreamWriter writer(&outputData);
|
|
writer.setAutoFormatting(true);
|
|
|
|
+ bool currentColorUsed = false;
|
|
while (!reader.atEnd() && !reader.hasError() && !writer.hasError()) {
|
|
reader.readNext();
|
|
writer.writeCurrentToken(reader);
|
|
+ if (!currentColorUsed && reader.isStartElement()) {
|
|
+ const auto classAttr = reader.attributes().value("class"_L1);
|
|
+ if (classAttr == "ColorScheme-Text"_L1 || classAttr == "ColorScheme-Background"_L1) {
|
|
+ const auto styleAttr = reader.attributes().value("style"_L1);
|
|
+ if (!styleAttr.isEmpty()) {
|
|
+ bool fillCurrentColor = false;
|
|
+ bool directColor = false;
|
|
+ for (const auto style : styleAttr.split(';'_L1)) {
|
|
+ const auto prop = style.split(':'_L1);
|
|
+ const auto propName = prop[0].trimmed();
|
|
+ const auto propValue = prop[1].trimmed();
|
|
+ if ((propName == "fill"_L1 || propName == "stroke"_L1) && propValue == "currentColor"_L1) {
|
|
+ fillCurrentColor = true;
|
|
+ }
|
|
+ if (propName == "color"_L1 && propValue != "currentColor"_L1) {
|
|
+ directColor = true;
|
|
+ }
|
|
+ }
|
|
+ currentColorUsed = fillCurrentColor && !directColor;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
if (!reader.isStartElement() || reader.qualifiedName() != "style"_L1 || reader.attributes().value("id"_L1) != "current-color-scheme"_L1) {
|
|
continue;
|
|
}
|
|
@@ -175,6 +211,10 @@ int main(int argc, char **argv)
|
|
writer.writeCharacters(convertStylesheet(reader.text().toString()));
|
|
}
|
|
|
|
+ if (!currentColorUsed) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
if (reader.hasError()) {
|
|
xmlReadErrorFiles.append("\""_L1 + inputFile.fileName() + "\": "_L1 + reader.errorString());
|
|
}
|
|
@@ -182,6 +222,11 @@ int main(int argc, char **argv)
|
|
xmlWriteErrorFiles.append("\""_L1 + outputFile.fileName() + "\""_L1);
|
|
}
|
|
|
|
+ if (!outputFile.open(QIODevice::WriteOnly)) {
|
|
+ unwrittenFiles.append("\""_L1 + outputFile.fileName() + "\": "_L1 + outputFile.errorString());
|
|
+ continue;
|
|
+ }
|
|
+
|
|
auto bytesWritten = outputFile.write(outputData);
|
|
outputFile.close();
|
|
wasAnyFileWritten |= bytesWritten > 0;
|
|
--
|
|
2.49.0
|
|
|