了解 *nix 图标'路径
有人可以解释一下,为什么许多程序的图标路径是这样的: /usr/share/program/icons/hicolor/16x16/...
我不明白的是为什么 hicolor 以及为什么 16x16、32x32 等。
有什么功能吗(例如在 GTK 中)自动从此类路径中获取正确的图标?
谢谢你!
Could someone please explain, why many programs have their icons' paths this way:
/usr/share/program/icons/hicolor/16x16/...
What I don't understand is why hicolor and why 16x16, 32x32 etc.
Are there any functions (e.g. in GTK) that automatically get the proper icon from such kind of paths?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这些图标路径由图标主题规范。原因是所有应用程序都可以将其默认图标安装到
hicolor
主题中(这是默认主题,这意味着如果另一个主题中缺少图标,则使用hicolor
中的版本> 将被使用。)此外,程序可以请求与提供的图标大小不同的图标大小,例如 37x37,系统将选择最合适的可用大小(例如
32x32
)并缩放它到要求的尺寸。如果有人想要覆盖应用程序的图标,例如为视力不好的用户制作一个高对比度的黑白版本,那么他们所要做的就是制作一个同名的图标并将其放在高位-对比黑白主题,它将覆盖
hicolor
图标。你问的功能也是存在的。在 GTK 中,有些函数采用 const gchar *icon_name 参数,例如
gtk_image_new_from_icon_name()
。这些将使用您从当前主题提供的名称加载图标,如果当前主题中不存在该图标,则从hicolor
主题加载图标。Those icon paths are standardized by the Icon Theme Specification. The reasoning is that all applications can install their default icons into the
hicolor
theme (which is the default theme, meaning that if an icon is missing from another theme, the version fromhicolor
will be used.)Also, a program can request an icon size that is different from the ones provided, say 37x37, and the system will select the most appropriate available size (like
32x32
) and scale it to the requested size.If someone wants to override the application's icon, for example to make a high-contrast black-and-white version for users with poor eyesight, then all they have to do is to make an icon with the same name and put it in the high-contrast black-and-white theme, and it will override the
hicolor
icon.The functions you ask about also exist. In GTK there are functions that take a
const gchar *icon_name
parameter, such asgtk_image_new_from_icon_name()
. These will load the icon with the name you supply from the current theme, and if it doesn't exist in the current theme, then from thehicolor
theme.术语“hicolor”是标准图标集的名称,它是所有其他图标集的后备,这意味着,如果在当前图标集中找不到应用程序的图标(例如
/usr/share/icons /oxygen
) 接下来搜索 hicolor 目录。16x16、32x32 意味着存储在该目录中的图像的大小,因为图标存储为简单的 PNG 文件,其中恰好包含一个图像(与 Mac 上的 .icns 等不同)。
The term "hicolor" is the name of the standard icon set which is the fallback for all other icon sets, which means, that if an application's icon is not found in the current icon set (e.g.
/usr/share/icons/oxygen
) the hicolor directory is searched next.16x16, 32x32 is imply the size of the images, stored in that directory, as the icons are stored as simple PNG files, which contain exactly one image (unlike, e.g. .icns on mac).
如果问题不是像其他人回答的那样“为什么'hicolor'?”而是“为什么使用文件系统作为树状数据库?”答案是大多数unix当目录中的条目超过 1000 个时,文件系统(所有旧的文件系统)就会陷入困境。
因为必须线性搜索这些文件系统中的目录。
一些更现代的文件系统支持 O(log N) 搜索,并且可以有效地处理更高的计数。
If the question is not "Why 'hicolor'?" as others have answered but "Why use the filesystem as a tree-like database?" the answer is that most unix filesystems (all the old ones) bog down when walking paths where there are more than ~1000 entries in a directory.
Because directories in those filesystems have to be searched linearly.
Some more modern filesystems support O(log N) searches and can deal with higher counts efficiently.