openSUSE:打包字体
目的
本页面旨在定义一套通用的软件包名称、内容及其他相关信息的规则。
如何选择新字体
市面上有许多“免费”字体,理论上都可以打包。但是,我们应该追求质量而非数量。因此,在您打包任何新字体之前,请先回答以下一些指导性问题
- 该字体是开源的吗?
您应该专注于在 OFL、GPL 或任何其他开放或自由源代码许可下发布的免费字体。尽管这应该很清楚,但绝不能打包商业字体! - 该字体已被打包了吗?
在您打包新字体之前,请务必首先查看 M17N:fonts 仓库。搜索类似的软件包名称。 - 该字体有多少种字体样式?
尝试打包至少包含常规和斜体样式的字体。最好字体还包含粗体和粗斜体(这将是四种样式)。有时,字体会附带小写字母,其他则带来紧凑或更宽的变体,但这并非常见情况。 - 该字体可用于不同语言吗?
尽管您很少会找到包含所有可能语言的字体,但请寻找至少支持欧洲语言的字体。有些还包含希腊语或西里尔字母。其他可能支持亚洲字符。字体支持的语言越多,对大多数用户来说就越好。 - 该字体有多少个字形?
这个问题与上一个问题相关。但是,还有更多有用的字形,如箭头、装饰字体、数学符号等。额外的字形使其更容易用于其他目的,如编程或特定文本。
命名和中央字体仓库
想一个好的字体名称。一般语法是这样的(全部小写)
[foundryname-]projectname[-fontfamilyname][-fonttype]-fonts
这里有更详细的解释
- foundryname:通常是设计师或字体铸造厂的名称
- projectname:字体项目的名称
- fontfamilyname:如果项目包含不同的字体家族,在此处指定
- fonttype:如果您打包的是位图字体,则替换为“bitmap”
在大多数情况下,软件包名称非常短。例如,如果您有一个字体项目“foo”,软件包名称将是“foo-fonts”。
几乎所有字体包现在都位于M17N:fonts仓库中。
请参阅 opensuse-packaging 邮件列表上的讨论 RFC: 字体仓库和重命名问题。它也源于 FATE #313035 (发明一致的字体命名方案/中央字体仓库)。
请参阅 M17N:fonts 以了解软件包和子软件包的名称,或在 openSUSE:Packaging Fonts:Fontlist 中查看已重命名的软件包列表。
软件包内容
字体各不相同,项目页面和它们的档案也如此。有些项目只发布一个档案,别无他物;其他则带来样本或附加信息。
如果可能,尝试将这些附加信息打包到%{_docdir}/PACKAGENAME.
字体包布局
考虑如何将您的软件包拆分为子软件包。最佳实践是
- 一个字体家族占用一个 (noarch) rpm,并且
- 不要将一个字体家族的字体文件分散到多个 rpm 中。
不过,这些规则并非强制性的,您肯定会在 M17N:fonts 中遇到一些反例。
如何创建新字体包
以下步骤展示了如何创建一个新的字体包。
- 在您的主项目中创建新软件包(在我们的例子中是 "foo-fonts")
osc mkpac foo-fonts
如果您还没有主项目的本地副本,可以通过以下方式创建一个
osc co home:yourname
- 从项目主页下载字体包存档并将其保存到新创建的 foo-fonts 目录中。
- 创建 spec 文件(在我们的例子中是 foo-fonts.spec)并填补空白。通常,这样的文件看起来像这样
# # spec file # # Copyright (c) 2022 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owner, unless otherwise agreed # upon. The license for this file, and modifications and additions to the # file, is the same license as for the pristine package itself (unless the # license for the pristine package is not an Open Source License, in which # case the license is the MIT License). An "Open Source License" is a # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. # # Please submit bugfixes or comments via https://bugs.opensuse.org/ # Definitions %define fontname foo Name: foo-fonts Summary: ... License: OFL-1.1 Group: System/X11/Fonts BuildArch: noarch Version: 1.0 Release: 0 Source: %{fontname}-%{version}.tar.bz2 # Provides: scalable-font-X # Provides: scalable-font-Y # The following provides line is an instruction to libzypp declaring this package # is essential when the openSUSE default install is set to language X. # It should not be used lightly! # Provides: locale(X) # You can do it conveniently with # %{lua: # l = "X;Y;" # print (string .gsub (l, "(%a+);", "Provides: scalable-font-%1\n"), "\n") # print (string .sub (l, 1, string .len (l) - 1)) } BuildRequires: fontpackages-devel BuildRequires: unzip # only if zipped %reconfigure_fonts_prereq URL: http://www.example.org/foo-font %description Foo fonts is... Designer: Add the name of the font designer %prep %autosetup -p1 -n %{fontname}-%{version} # Usually empty, but insert fixes here, if necessary # Zipped fonts require unzip and prepare like this: # %setup -cT # %{uncompress:%{S:0}} %build # Usually nothing to do %install install -d '%{buildroot}%{_ttfontsdir}' install '-t%{buildroot}%{_ttfontsdir}' -m 644 *.ttf # call fonts-config after installation or deinstallation of this package %reconfigure_fonts_scriptlets %files # Include additional content for the font package, if available # %doc METADATA FONTLOG.txt OFL.txt %{_ttfontsdir} %changelog - 创建变更日志并写入您的评论
osc vc
- 在本地构建软件包
osc build --local-package 15.4 foo-fonts.spec
- 如果没有错误,则提交字体包
osc ci
- 检查一切是否正确构建
osc r
- 将您的软件包提交到我们的 M17N:fonts 仓库
osc sr YOUR_REPO foo-fonts M17N:fonts
RPM 宏
强烈建议在字体包中使用 rpm 宏。每个字体包都应 buildrequire fontpackages-devel 并使用 /etc/rpm/macros-fontconfig 中定义的宏。这是因为
- 更改通用字体包行为以这种方式集中在一处,并且
- 使用它们的 spec 文件可以更清晰。
示例
这里有一些带有简单 spec 文件的示例软件包
如何更新现有字体包
如果您想将字体更新到新版本或发现了错误,以下过程展示了如何操作
- 打开 shell 并分支现有字体包M17N:fonts:
osc bco M17N:fonts FONTPACKAGE
该osc脚本检出字体包并将其保存到home/USER/branches/M17N/fonts/FONTPACKAGE(如果您已设置checkout_no_colon=1在您的~/.oscrc配置文件中)。这将是您的当前工作目录。
- 下载新软件包并将其保存到您的工作目录中。通常您可以在项目主页上找到该软件包。
- 更改 spec 文件中的版本号。
- 如果需要,在 spec 文件中添加补丁或其他要求(通常大多数情况下不需要)。
- 写入有意义的变更日志条目
osc vc
(您可能会在变更日志文件(如果包含在存档中)或项目主页上找到有关更改的信息)。
- 删除旧存档并添加新存档
osc rm OLD_ARCHIVE osc add NEW_ARCHIVE
- 构建您的软件包并修复任何错误(您可以替换openSUSE_Factory为您首选的发行版)
osc build openSUSE_Factory *.spec
- 提交您的所有更改
osc ci
- 将您的更改提交回M17N:fonts仓库
osc sr -m"Updated to version x.y"
您的提交将接受审核,如果符合我们的打包规则,则将被接受。如果被拒绝,您将被告知原因。修复错误或问题并再次提交(您可能希望将-s选项(此请求取代另一个请求)与您的sr命令结合使用)。
包含多个字体的字体包
即使包含多个字体家族,许多软件包也不会拆分为子软件包。然而,当您想让用户选择从您的软件包中安装哪个字体家族时,您将不得不将您的字体包拆分为子软件包。
一般经验法则:如果字体“很大”,则将其拆分为多个软件包。对于“大”没有确切的定义,但如果字体包含多个字体家族或包含大量导致文件大小巨大的文件,则可以认为它是“大”的。
spec 文件可能如下所示
#
# spec file
#
# Copyright (c) 2022 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%define projname bar
Name: bar-fonts
Version: 2.0
Release: 0
Summary: ...
License: OFL.1.1
Group: System/X11/Fonts
Url: ...
Source0: %{projname}-%{version}.tar.bz2
BuildRequires: fontpackages-devel
%reconfigure_fonts_prereq
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildArch: noarch
%description
...
%package -n %{projname}-family1-fonts
Summary: ...
Group: System/X11/Fonts
%description -n %{projname}-family1-fonts
...
%package -n %{projname}-family2-fonts
Summary: ...
Group: System/X11/Fonts
%description -n %{projname}-family2-fonts
...
%package -n %{projname}-family3-fonts
Summary: ...
Group: System/X11/Fonts
%description -n %{projname}-family3-fonts
...
%prep
%setup -q -n %{projname}-%{version}
%build
%install
mkdir -p %{buildroot}%{_ttfontsdir}
for i in *.ttf
do
install -m 644 $i %{buildroot}%{_ttfontsdir}
done
%reconfigure_fonts_scriptlets -c -n %{projname}-family1-fonts
%reconfigure_fonts_scriptlets -c -n %{projname}-family2-fonts
%reconfigure_fonts_scriptlets -c -n %{projname}-family3-fonts
# main package can be also empty, then don't inclue %files section
# at all
%files
# Include common content for the font package, if available
# %doc METADATA FONTLOG.txt
%files -n %{projname}-family1-fonts
%license OTF.txt
%dir %{_ttfontsdir}/
%{_ttfontsdir}/family1.*
%files -n %{projname}-family2-fonts
%license OTF.txt
%dir %{_ttfontsdir}/
%{_ttfontsdir}/family2.*
%files -n %{projname}-family3-fonts
%license OTF.txt
%dir %{_ttfontsdir}/
%{_ttfontsdir}/family3.*
%changelog
示例
与字体包一同打包 Fontconfig 文件
您可能希望将 fontconfig 文件与您的字体文件一起打包。没有规定 fontconfig 文件必须是 fontconfig 包本身的一部分,因此鼓励您将其包含在您的字体包中。但有一个例外:映射到通用名称 serif、sans-serif、monospace、cursive 和 fantasy。特别是 <default> 别名:它旨在帮助 fontconfig 在您的字体未安装时找到与您的字体相似的字体,因此将其与您的软件包一起打包显然无法工作。
fontconfig 文件可以随上游 tarball 一起提供,或者您可以将其添加为包源。
fontconfig 文件的名称没有严格的规则,除了 fontconfig 文件的通用规则(参见/etc/fonts/conf.d/README)。如果您想使用 RPM 宏%install_fontsconf,您必须确保 fontconfig 文件的名称与您想要的名称在/etc/fonts/conf.d.
中完全相同。在下面的 spec 文件示例中,我们想安装/etc/fonts/conf.d/31-foo-fonts.conf,因此包源中的文件名为31-foo-fonts.conf。如果 fontconfig 文件是上游 tarball 的一部分,您必须手动重命名它,或者不使用%install_fontsconfRPM 宏(即手动安装)。
以下是示例 spec 文件;它打包了一个 fontconfig 文件。
#
# spec file
#
# Copyright (c) 2022 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%define fontname foo
Name: foo-fonts
Version: 3.0
Release: 0
Summary: ...
License: GPL-2.0-with-font-exception
Group: System/X11/Fonts
Url: ...
Source0: %{fontname}-%{version}.tar.bz2
Source1: 31-%{fontname}-fonts.conf
BuildRequires: fontconfig
BuildRequires: fontpackages-devel
%reconfigure_fonts_prereq
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildArch: noarch
%description
...
%prep
%setup -q -n %{fontname}
%build
%install
mkdir -p %{buildroot}%{_ttfontsdir}/
install -m 0644 *.otf %{buildroot}%{_ttfontsdir}
%install_fontsconf %{SOURCE1}
%reconfigure_fonts_scriptlets
%files
%doc COPYING README
%{_ttfontsdir}
%files_fontsconf_availdir
%files_fontsconf_file -l 31-linux-libertine.conf
%changelog
请注意,与简单字体包相比,有一些必要的补充
- 将配置文件添加到包源中
Source1: 31-%{fontname}-fonts.conf - 添加 fontconfig 的构建依赖
BuildRequires: fontconfig
- 将 fontconfig 文件安装到 availdir(当前为/usr/share/%{name}/conf.avail定义在%{_fontsconfavaildir}RPM 宏中)并将其链接到 confdir(当前为/etc/fonts/conf.d定义在%{_fontsconfddir}RPM 宏)使用
%install_fontsconf %{SOURCE1} - 将 availdir 添加到包文件列表中
%files_fontsconf_availdir
- 将配置文件本身添加到文件列表中;-l开关告诉宏包含 confdir 链接
%files_fontsconf_file -l 31-linux-libertine.conf
尽管如此,在字体包中包含 fontconfig 文件并不常见。截至撰写本文时,M17N:fonts 中的 141 个软件包中只有 9 个这样做。
示例
- linux-libertine-fonts -- 包含一个 fontconfig 文件作为包源
- wqy-bitmap-fonts -- 安装一个随上游 tarball 提供的 fontconfig 文件
- wqy-zenhei-fonts -- 安装三个 fontconfig 文件(手动),但只将其中一个链接到系统配置
- stix-fonts -- 包含多个 fontconfig 文件作为包源,每个子包安装一个
- thai-fonts -- 包含两个 fontconfig 文件但未在 confddir 中链接它们
- cantarell-fonts -- 通过原生构建过程安装一个 fontconfig 文件并将其链接到系统配置
说明
如何重命名字体
以下过程展示了如何重命名字体包。
准备
- 检出M17N:fonts仓库
osc co M17N:fonts
- 在您的浏览器中打开 Fedora 字体包列表
- 使用以下命令获取 M17N 仓库的列表
osc ls M17N
- 从此列表中获取一个字体,例如LinuxLibertine.
- 在上面的链接中搜索名称以查看新名称是什么。在这种情况下,它是linux-libertine-fonts.
如果找不到等效的软件包名称,请使用以下命名方案[foundryname-]projectname[-fontfamilyname][-fonttype]-fonts
复制和重命名
- 将 LinuxLibertine 字体复制到新的字体仓库 M17N:fonts 并使用新名称
osc copypac M17N LinuxLibertine M17N:fonts linux-libertine-fonts
- 更新您的M17N:fonts仓库。您将获得新的重命名字体包
osc update cd linux-libertine-fonts
- 重命名.spec和.changes文件到它们的新名称
mv LinuxLibertine.spec linux-libertine-fonts.spec mv LinuxLibertine.changes linux-libertine-fonts.changes
- 打开文件linux-libertine-fonts.spec。重要的行.spec文件看起来像这样
Name: LinuxLibertine ... Version: 5.1.3
- 更改名称关键字的内容为linux-libertine-fonts.
- 从版本关键字复制版本号并将其插入到废弃 (Obsoletes)关键字中。添加以下行
# FIXME: This causes a rpmlint warning; change <= to < once there's a new upstream version Obsoletes: LinuxLibertine <= 5.1.3 Provides: LinuxLibertine = %{version} - 保存.spec文件中提供相同的供应商和标识信息。
您还可以在 M17N:fonts 仓库中看到很多示例。
完成
- 构建软件包,警告是正常的,并且预期会
$ osc build openSUSE_12.1 *.spec [...] RPMLINT report: =============== linux-libertine-fonts.noarch: W: self-obsoletion LinuxLibertine <= 5.1.3 obsoletes LinuxLibertine = 5.1.3 The package obsoletes itself. This is known to cause errors in various tools and should thus be avoided, usually by using appropriately versioned Obsoletes and/or Provides and avoiding unversioned ones. 2 packages and 0 specfiles checked; 0 errors, 1 warnings.
- 运行osc vc打开编辑器。
- 写入一些变更日志行并保存。我们使用了以下措辞
Renamed LinuxLibertine -> linux-libertine-fonts according to Fedora packaging guidelines and FATE#313035 Adjusted Obsoletes and Provides accordingly
- 提交您的更改
osc ci
- 将您的更改提交到 factory
osc submitreq -m"... some meaningful message ..." openSUSE:Factory
- 等待您的提交请求被接受。如果您的提交请求被拒绝,请修复问题。:-)
- 将旧字体的 devel 仓库更改为新仓库
osc changedevelreq openSUSE:Factory LinuxLibertine M17N:fonts linux-libertine-fonts
自 12.2 版本以来的 BuildRequires 变更 (bdftopcf,xmkmf,imake, mkfontdir)
自 openSUSE 12.2 以来,X11:XOrg 项目拆分并更改了一些软件包。bdftopcf、imake(包括 xmkmf)和 mkfontdir 软件包现在拆分为单独的子软件包。这对于终端用户的最小系统来说是好事,但这些更改现在打破了旧的自动构建依赖链,并使 BuildRequires 变得更加复杂。
如果您的构建在 openSUSE 12.2 或 Factory 中失败,并显示类似以下错误消息
bdftopcf/xmkmf/mkfontdir: Command not found.
或
Imakefile.c:34:0: fatal error: Imake.tmpl: No such file or directory.
您需要本节中的调整。
以前用于打包字体的通用 BuildRequires
BuildRequires: xorg-x11 BuildRequires: xorg-x11-devel
需要进行一些更改。
旧 BuildRequires 的解释
xorg-x11 提供了/usr/bin/bdftopcf,而 xorg-x11-devel 实际上用于调用 xorg-x11-utils-devel,其中包括 xmkmf、imake 和 mkfontdir。所以 xorg-x11 不能被忽略。
- 如果错误消息是关于 bdftopcf 的,您需要
%if 0%{?suse_version} >= 1220
BuildRequires: bdftopcf
%else
BuildRequires: xorg-x11
BuildRequires: xorg-x11-devel
%endif
- 如果错误消息是关于 xmkmf/imake 的,您需要
%if 0%{?suse_version} >= 1220
BuildRequires: imake //includes xmkmf
BuildRequires: xorg-cf-files //includes Imake.tmpl
%else
BuildRequires: xorg-x11
BuildRequires: xorg-x11-devel
%endif
- 如果错误消息是关于 mkfontdir 的,您需要
%if 0%{?suse_version} >= 1220
BuildRequires: mkfontdir //this is a "fake" package points to mkfontscale
%else
BuildRequires: xorg-x11
BuildRequires: xorg-x11-devel
%endif
- 如果错误消息是关于 fc-cache 的,您需要
%if 0%{?suse_version} >= 1220
BuildRequires: fontconfig
%else
BuildRequires: xorg-x11
BuildRequires: xorg-x11-devel
%endif
- 如果错误消息是关于 libfreetype6.so 的,您需要
%if 0%{?suse_version} >= 1220
BuildRequires: freetype2-devel
%else
BuildRequires: xorg-x11
BuildRequires: xorg-x11-devel
%endif
在 Fedora 中,bdftopcf 和 mkfontdir 在 xorg-x11-font-utils 中,因此需要更多的更改
%if 0%{?suse_version} >= 1220
BuildRequires: bdftopcf
BuildRequires: mkfontdir
%else
%if 0%{?fedora_version}
BuildRequires: xorg-x11-font-utils
%else
BuildRequires: xorg-x11
BuildRequires: xorg-x11-devel
%endif
%endif