Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions tools/dci-icon-theme/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#define MAX_SCALE 10
#define INVALIDE_QUALITY -2
#define SCALABLE_SIZE 256
static int quality4Scaled[MAX_SCALE] = {};
static inline void initQuality() {
for (int i = 0; i < MAX_SCALE; ++i)
Expand All @@ -44,11 +45,11 @@
}

// TODO 应该使用xdg图标查找规范解析index.theme来查找尺寸
static uint foundSize(const QFileInfo &fileInfo) {
static int foundSize(const QFileInfo &fileInfo) {
QDir dir = fileInfo.absoluteDir();

// 解析尺寸
auto parseSize = [](const QString &dirName) -> uint {
auto parseSize = [](const QString &dirName) -> int {
bool ok;
if (int size = dirName.toUInt(&ok); ok) {
return size;
Expand All @@ -60,10 +61,14 @@
}
}

if (dirName == "scalable") {
return SCALABLE_SIZE;
}

return 0;
};

if (uint size = parseSize(dir.dirName())) {
if (int size = parseSize(dir.dirName()); size > 0) {
return size;
}

Expand All @@ -83,14 +88,8 @@
return data;
}

static bool writeScaledImage(DDciFile &dci, const QImage &image, const QString &targetDir, int scale/* = 2*/)
static bool writeScaledImage(DDciFile &dci, const QImage &image, const QString &targetDir, const int baseSize, int scale/* = 2*/)
{
QString sizeDir = targetDir.mid(1, targetDir.indexOf("/", 1) - 1);
bool ok = false;
int baseSize = sizeDir.toInt(&ok);
if (!ok)
baseSize = 256;

int size = scale * baseSize;
QImage img;
if (image.width() == size) {
Expand All @@ -109,20 +108,28 @@

static bool writeImage(DDciFile &dci, const QString &imageFile, const QString &targetDir)
{
QString sizeDir = targetDir.mid(1, targetDir.indexOf("/", 1) - 1);
bool ok = false;
int baseSize = sizeDir.toInt(&ok);
if (!ok)
baseSize = 256;

QImageReader reader(imageFile);
if (!reader.canRead()) {
qWarning() << "Ignore the null image file:" << imageFile;
return false;
}

auto image = reader.read();
for (int i = 0; i < MAX_SCALE; ++i) {
if (quality4Scaled[i] == INVALIDE_QUALITY)
continue;
int scale = i + 1;

if (!writeScaledImage(dci, image, targetDir, i + 1))
reader.setScaledSize(QSize(baseSize * scale, baseSize * scale));
auto image = reader.read();
if (!writeScaledImage(dci, image, targetDir, baseSize, scale))

Check warning on line 130 in tools/dci-icon-theme/main.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Condition '!writeScaledImage(dci,image,targetDir,baseSize,scale)' is always false

Check warning on line 130 in tools/dci-icon-theme/main.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Condition '!writeScaledImage(dci,image,targetDir,baseSize,scale)' is always false
return false;
}
}

return true;
}
Expand Down Expand Up @@ -504,8 +511,8 @@
});

if (hasError.load()) {
qWarning() << "Encountered errors during DCI file writing. Exiting with error code:" << errorCode;
return errorCode;
qWarning() << "Encountered errors during DCI file writing" << errorCode;
continue;
}
}

Expand Down
Loading