KDE/kdelibs/kdeui/icons

Rafael Fernández López ereslibre at kde.org
Tue Oct 16 18:59:59 BST 2007


SVN commit 725955 by ereslibre:

KIconLoader now returns more quality icons if the requested size is not a standard one. This means that if the size requested is not standard it will try to load the icon 
from the SVG format before than trying to load the PNG image and then resizing it (what leads to a worse image quality). In the case that not SVG was found and PNG was, 
the change on KIconTheme assures that it will stop on the closest size bigger than the selected (for example, it will stop on 22x22 if you requested a 19x19 pixels icon 
size) and then resize it. This will only happen if the SVG wasn't found. If the size is a standard one, go on with the normal procedure: load the PNG that is faster than 
drawing a SVG and since no resizes are needed no quality is lost.

CCMAIL: aseigo at kde.org
CCMAIL: kde-core-devel at kde.org


 M  +53 -6     kiconloader.cpp  
 M  +7 -8      kicontheme.cpp  


--- trunk/KDE/kdelibs/kdeui/icons/kiconloader.cpp #725954:725955
@@ -615,9 +615,35 @@
     const_cast<KIconLoaderPrivate*>(this)->initIconThemes();
 
     K3Icon icon;
-    const char * const ext[4] = { ".png", ".svgz", ".svg", ".xpm" };
 
-    /* To follow the XDG icon theme and icon naming specifications,
+    const char * ext1[4] = { ".png", ".svgz", ".svg", ".xpm" };
+    const char * ext2[4] = { ".svgz", ".svg", ".png", ".xpm" };
+    const char ** ext;
+
+    if (size == KIconLoader::SizeSmall ||
+        size == KIconLoader::SizeSmallMedium ||
+        size == KIconLoader::SizeMedium ||
+        size == KIconLoader::SizeLarge ||
+        size == KIconLoader::SizeHuge ||
+        size == KIconLoader::SizeEnormous)
+    {
+        ext = ext1; // size is standard, give preference to PNG over SVG when searching
+    }
+    else
+    {
+        ext = ext2; // size is non-standard, give preference to SVG over PNG when searching
+    }
+
+    /* If size parameter is a standard one, that means:
+
+           - KIconLoader::SizeSmall
+           - KIconLoader::SizeSmallMedium
+           - KIconLoader::SizeMedium
+           - KIconLoader::SizeLarge
+           - KIconLoader::SizeHuge
+           - KIconLoader::SizeEnormous
+
+       To follow the XDG icon theme and icon naming specifications,
        the order in which we look for an icon is:
 
        png, svgz, svg, xpm exact match
@@ -638,7 +664,32 @@
        (...)
 
        and so on.
+
+       If size parameter is a non-standard one, then we give more preference to
+       SVG format since drawing SVG's gives better quality and despite being
+       slower than resizing a PNG image, the cases where non-standard sizes are
+       asked are very rare. For non-standard sizes what we have is:
+
+       svgz, svg, png, xpm exact match
+       svgz, svg, png, xpm best match
+       less specific fallback in this theme: svgz, svg, png, xpm exact match
+                                             svgz, svg, png, xpm best match
+       even less specific fallback in this theme: [same order]
+       (...)
+
+       next theme in inheritance tree: svgz, svg, png, xpm exact match
+                                       svgz, svg, png, xpm best match
+       less specific fallbacks in this next theme
+       (...)
+
+       next theme in inheritance tree: svgz, svg, png, xpm exact match
+                                       svgz, svg, png, xpm best match
+       less specific fallbacks in this next theme
+       (...)
+
+       and so on.
        */
+
     foreach(KIconThemeNode *themeNode, links)
     {
         QStringList nameParts = name.split("-");
@@ -981,10 +1032,6 @@
     }
 
     // Scale the icon and apply effects if necessary
-    if (iconType == KIconLoader::Scalable && size != img->width())
-    {
-        *img = img->scaled(size, size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
-    }
     if (iconType == KIconLoader::Threshold && size != img->width())
     {
         if ( abs(size-img->width())>iconThreshold )
--- trunk/KDE/kdelibs/kdeui/icons/kicontheme.cpp #725954:725955
@@ -442,7 +442,7 @@
                 ((size < dir->minSize()) || (size > dir->maxSize())))
               continue;
             if ((dir->type() == KIconLoader::Threshold) &&
-		(abs(dir->size()-size) > dir->threshold()))
+                (abs(dir->size()-size) > dir->threshold()))
                 continue;
         } else
         {
@@ -471,8 +471,7 @@
              it's a downscale, and we only had upscales befores.
              This is to avoid scaling up unless we have to,
              since that looks very ugly */
-          if ((abs(dw) >= abs(delta)) ||
-              (delta > 0 && dw < 0))
+          if ((abs(dw) >= abs(delta)) || dw < 0)
             continue;
         }
 
@@ -480,18 +479,18 @@
         if (path.isEmpty())
             continue;
         icon.path = path;
-        icon.size = dir->size();
+        icon.size = size;
         icon.type = dir->type();
-	icon.threshold = dir->threshold();
+        icon.threshold = dir->threshold();
         icon.context = dir->context();
 
         // if we got in MatchExact that far, we find no better
         if (match == KIconLoader::MatchExact)
             return icon;
-	else
+        else
         {
-	    delta = dw;
-	    if (delta==0) return icon; // We won't find a better match anyway
+            delta = dw;
+            if (delta==0) return icon; // We won't find a better match anyway
         }
     }
     return icon;




More information about the kde-core-devel mailing list