Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic HiDPI support #48

Merged
merged 3 commits into from Sep 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -320,10 +320,13 @@ public:

// prepare icon-tarball array
immutable iconTarSizes = ["64", "128"];
immutable iconTarScales = ["1", "2"];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we should iterate over wantedIconSizes here, instead of defining another array (minor thing though).

Appender!(immutable(string)[])[string] iconTarFiles;
if (withIconTar) {
foreach (size; iconTarSizes) {
iconTarFiles[size] = appender!(immutable(string)[]);
foreach (scale; iconTarScales) {
iconTarFiles["%s%s".format (size, scale)] = appender!(immutable(string)[]);
}
}
}

@@ -367,11 +370,14 @@ public:
// compile list of icon-tarball files
if (withIconTar) {
foreach (ref size; iconTarSizes) {
immutable iconDir = buildPath (mediaExportDir, gcid, "icons", "%sx%s".format (size, size));
if (!std.file.exists (iconDir))
continue;
foreach (ref path; std.file.dirEntries (iconDir, std.file.SpanMode.shallow, false)) {
iconTarFiles[size] ~= path.idup;
foreach (ref scale; iconTarScales) {
string size_dir = scale == "1" ? "%sx%s".format (size, size) : "%sx%s@%s".format (size, size, scale);
immutable iconDir = buildPath (mediaExportDir, gcid, "icons", size_dir);
if (!std.file.exists (iconDir))
continue;
foreach (ref path; std.file.dirEntries (iconDir, std.file.SpanMode.shallow, false)) {
iconTarFiles["%s%s".format (size, scale)] ~= path.idup;
}
}
}
}
@@ -396,14 +402,17 @@ public:
if (withIconTar) {
logInfo ("Creating icon tarball.");
foreach (size; iconTarSizes) {
import std.conv : to;

auto iconTar = scoped!ArchiveCompressor (ArchiveType.GZIP);
iconTar.open (buildPath (dataExportDir, format ("icons-%sx%s.tar.gz", size, size)));
auto iconFiles = iconTarFiles[size].data;
sort!("a < b", SwapStrategy.stable) (to!(string[]) (iconFiles));
foreach (fname; iconFiles) {
iconTar.addFile (fname);
foreach (scale; iconTarScales) {
import std.conv : to;

auto iconTar = scoped!ArchiveCompressor (ArchiveType.GZIP);
string size_dir = scale == "1" ? "%sx%s".format (size, size) : "%sx%s@%s".format (size, size, scale);
iconTar.open (buildPath (dataExportDir, "icons-%s.tar.gz".format (size_dir)));
auto iconFiles = iconTarFiles["%s%s".format (size, scale)].data;
sort!("a < b", SwapStrategy.stable) (to!(string[]) (iconFiles));
foreach (fname; iconFiles) {
iconTar.addFile (fname);
}
}
}
logInfo ("Icon tarball(s) built.");
@@ -51,7 +51,7 @@ private immutable possibleIconExts = [".png", ".jpg", ".svgz", ".svg", ".gif", "
// the image extensions that we will actually allow software to have.
private immutable allowedIconExts = [".png", ".jpg", ".svgz", ".svg", ".xpm"];

public immutable wantedIconSizes = [ImageSize (64), ImageSize (128)];
public immutable wantedIconSizes = [ImageSize (64), ImageSize (128), ImageSize (64, 64, 2), ImageSize (128, 128, 2)];

/**
* Describes an icon theme as specified in the XDG theme spec.
@@ -77,6 +77,7 @@ public:
foreach (section; index.getGroups (dummy)) {
string type;
string context;
int scale;
int threshold;
int size;
int minSize;
@@ -106,6 +107,11 @@ public:
} catch {
maxSize = size;
}
try {
scale = index.getInteger (section, "Scale");
} catch {
scale = 1;
}

if (size == 0)
continue;
@@ -115,7 +121,8 @@ public:
"size": Algebraic!(int, string) (size),
"minsize": Algebraic!(int, string) (minSize),
"maxsize": Algebraic!(int, string) (maxSize),
"threshold": Algebraic!(int, string) (threshold)
"threshold": Algebraic!(int, string) (threshold),
"scale": Algebraic!(int, string) (scale)
];
directories ~= themedir;
}
@@ -129,6 +136,9 @@ public:

private bool directoryMatchesSize (Algebraic!(int, string)[string] themedir, ImageSize size)
{
int scale = themedir["scale"].get!(int);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make this just themedir["scale"].get!int;, D doesn't need the brackets here (that particular code is rather old from when I didn't know that much about D yet ^^)
But that's just a style-thing, no need to change it.

if (scale != size.scale)
return false;
string type = themedir["type"].get!(string);
if (type == "Fixed")
return size.toInt () == themedir["size"].get!(int);
@@ -450,6 +460,7 @@ public:
icon.setKind (IconKind.CACHED);
icon.setWidth (size.width);
icon.setHeight (size.height);
icon.setScale (size.scale);
icon.setName (iconName);
cpt.addIcon (icon);
return true;
@@ -470,12 +481,14 @@ public:
return false;
}

auto scaled_width = size.width * size.scale;
auto scaled_height = size.height * size.scale;
if ((iformat == ImageFormat.SVG) || (iformat == ImageFormat.SVGZ)) {
// create target directory
mkdirRecurse (path);

try {
auto cv = new Canvas (size.width, size.height);
auto cv = new Canvas (scaled_width, scaled_height);
cv.renderSvg (iconData);
cv.savePng (iconStoreLocation);
delete cv;
@@ -494,15 +507,15 @@ public:

if (iformat == ImageFormat.XPM) {
// we use XPM images only if they are large enough
if ((img.width < size.width) || (img.height < size.height))
if ((img.width < scaled_width) || (img.height < scaled_height))
return false;
}

// create target directory
mkdirRecurse (path);

try {
img.scale (size.width, size.height);
img.scale (scaled_width, scaled_height);
img.savePng (iconStoreLocation);
} catch (Exception e) {
gres.addHint(cpt.getId (), "image-write-error", ["fname": baseName (iconPath), "pkg_fname": baseName (sourcePkg.filename), "error": e.msg]);
@@ -516,6 +529,7 @@ public:
icon.setKind (IconKind.CACHED);
icon.setWidth (size.width);
icon.setHeight (size.height);
icon.setScale (size.scale);
icon.setName (iconName);
cpt.addIcon (icon);

@@ -47,39 +47,58 @@ struct ImageSize
{
uint width;
uint height;
uint scale;

this (uint w, uint h, uint s)
{
width = w;
height = h;
scale = s;
}

this (uint w, uint h)
{
width = w;
height = h;
scale = 1;
}

this (uint s)
{
width = s;
height = s;
scale = 1;
}

string toString () const
{
return format ("%sx%s", width, height);
if (scale == 1)
return format ("%ux%u", width, height);
else
return format ("%ux%u@%u", width, height, scale);
}

uint toInt () const
{
if (width > height)
return width;
return height;
return width * scale;
return height * scale;
}

int opCmp (const ImageSize s) const
{
// only compares width, should be enough for now
if (this.width > s.width)
return 1;
if (this.width == s.width)
return 0;
return -1;
else if (this.width < s.width)
return -1;

if (this.scale > s.scale)
return 1;
else if (this.scale < s.scale)
return -1;

return 0;
}
}