From 61ecf988f7458009c9e3a13bc31dcdeecd99f878 Mon Sep 17 00:00:00 2001 From: alexl Date: Tue, 7 Feb 2006 11:33:57 +0000 Subject: Add list lookup and clarify lookup code --- spec/icon-theme-spec.xml | 149 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 105 insertions(+), 44 deletions(-) diff --git a/spec/icon-theme-spec.xml b/spec/icon-theme-spec.xml index 063d861..af619cb 100644 --- a/spec/icon-theme-spec.xml +++ b/spec/icon-theme-spec.xml @@ -5,8 +5,8 @@
Icon Theme Specification - Version 0.7 - September 22 2003 + Version 0.10 + February 7 2006 Alexander @@ -470,72 +470,115 @@ fallback, as the correct choice depends on the context. - The exact algorithm (in pseudocode) for looking up an icon in an - implementation that supports SVG is: - LookupIcon (iconname, size): -for each subdir in $(theme subdir list) { - for each directory in $(basename list) { - for extension in ("png", "svg", "xpm") { - if DirectoryMatchesSize(subdir, size) { - filename = directory/$(themename)/subdir/iconname.extension - if exist filename - return filename - } - } - } + The exact algorithm (in pseudocode) for looking up an icon in a theme + (if the implementation supports SVG) is: + +FindIcon(icon, size) { + theme = user selected theme + do { + filename = LookupIcon (icon, size, theme) + if filename != none + return filename + theme = theme.parentTheme() + } while (theme) + return LookupFallbackIcon (iconname) } - -minimal_size = MAXINT -for each subdir in $(theme subdir list) { + + With the following helper functions: + +LookupIcon (iconname, size, theme) { + for each subdir in $(theme subdir list) { for each directory in $(basename list) { - for extension in ("png", "svg", "xpm") { - filename = directory/$(themename)/subdir/iconname.extension - if exist filename and DirectorySizeDistance(subdir, size) < minimal_size - closest_filename = filename - minimal_size = DirectorySizeDistance(subdir, size) - } - } + for extension in ("png", "svg", "xpm") { + if DirectoryMatchesSize(subdir, size) { + filename = directory/$(themename)/subdir/iconname.extension + if exist filename + return filename + } + } + } + } + minimal_size = MAXINT + for each subdir in $(theme subdir list) { + for each directory in $(basename list) { + for extension in ("png", "svg", "xpm") { + filename = directory/$(themename)/subdir/iconname.extension + if exist filename and DirectorySizeDistance(subdir, size) < minimal_size { + closest_filename = filename + minimal_size = DirectorySizeDistance(subdir, size) + } + } + } + } + if closest_filename set + return closest_filename + return none } -if closest_filename set - return closest_filename - -for each directory in $(basename list) { + +LookupFallbackIcon (iconname) { + for each directory in $(basename list) { for extension in ("png", "svg", "xpm") { - if exists directory/iconname.extension - return directory/iconname.extension + if exists directory/iconname.extension + return directory/iconname.extension } + } + return none } -return failed icon lookup - - With the following helper functions: - DirectoryMatchesSize(subdir, iconsize): -read Type and size data from subdir -if Type is Fixed +DirectoryMatchesSize(subdir, iconsize) { + read Type and size data from subdir + if Type is Fixed return Size == iconsize -if Type is Scaled + if Type is Scaled return MinSize <= iconsize <= MaxSize -if Type is Threshold + if Type is Threshold return Size - Threshold <= iconsize <= Size + Threshold +} -DirectorySizeDistance(subdir, size): -read Type and size data from subdir -if Type is Fixed +DirectorySizeDistance(subdir, size) { + read Type and size data from subdir + if Type is Fixed return abs(Size - iconsize) -if Type is Scaled + if Type is Scaled if iconsize < MinSize return MinSize - iconsize if iconsize > MaxSize return iconsize - MaxSize return 0 -if Type is Threshold + if Type is Threshold if iconsize < Size - Threshold return MinSize - iconsize if iconsize > Size + Threshold return iconsize - MaxSize return 0 +} + + In some cases you don't always want to fall back to an icon in an + inherited theme. For instance, sometimes you look for a set of + icons, prefering any of them before using an icon from an inherited + theme. To support such operations implementations can contain a + function that finds the first of a list of icon names in the inheritance + hierarchy. I.E. It would look something like this: +FindBestIcon(iconList, size) { + theme = user selected theme + do { + for icon in iconList { + filename = LookupIcon (icon, size, theme) + if filename != none + return filename + } + + theme = theme.parentTheme() + } while (theme) + + return LookupFallbackIcon (iconname) +} + + This can be very useful for example when handling mimetype icons, where there + are more and less "specific" versions of icons. + @@ -661,6 +704,24 @@ AttachPoints=20,20|40,40|50,10|10,50 Change history + + Version 0.10, 7 February 2006, Alexander Larsson + + + + + Clarify that icon lookup looks in all parent themes before + falling back to nonthemed icons. + + + + + Added lookup function that takes a list of icon names (FindBestIcon) + + + + + Version 0.9, 4 April 2005, Alexander Larsson -- cgit