packages icon indicating copy to clipboard operation
packages copied to clipboard

appstream: Add metainfo xml to all font packages

Open joebonrichie opened this issue 2 years ago • 11 comments
trafficstars

Add appstream metainfo to all font packages so font previews show up in Software Centers.

Please see font-clear-sans-ttf in the Solus Software Center as an example.

Screenshot from 2023-10-06 12-18-13

Please see this commit for liberation-fonts-ttf on how to add appstream metainfo to a package

https://github.com/getsolus/packages/commit/8b48034963aa8dfb329a96ef5ebfe1b1c089252d

Finding fonts to update

Originally, all of our fonts except font-clear-sans-ttf and liberation-fonts-ttf were missing appstream data. To search for fonts that have no metainfo.xml file:

Method 1: Run this (substitute solus-builds for the directory you have on your system):

cd solus-builds/packages/packages

find . -maxdepth 2 -type d -iname "font-*" -a ! -iname "*-manager" ! -exec sh -c 'test -e "$1"/files/*metainfo.xml' sh {} \; -print

Also check t/texlive/files for the texlive fonts

Note: Make sure the package is actually a font. The above commands are provided for convenience.

Method 2: Run this to find all desktop font packages:

eopkg info -c desktop.font

Then pick a font and check its info in the repo. Pick one that has no metadata file to add appstream data to.

Create the metainfo file

Create a file fontname.metainfo.xml in the files subdirectory (for the liberation-fonts-ttf font this file is named files/liberation.metainfo.xml because the font name is liberation) It should contain

<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2023 Solus Developers <[email protected] -->
  <component type="font">
  <id>packagename</id>
  <metadata_license>CC0-1.0</metadata_license>
  <name>fontname</name>
  <url type="homepage">https://fontwebpage.com/</url>
  <summary>Some summary of the fonts provided</summary>
</component>

You will need a few pieces of data for the file for the placeholders.

  • The font package name from eopkg info fontname | grep Name for id
  • The font name. You can get this by looking at the install section of its package.yml file. The font name is the last part of the directory in the install directive.
  • The homepage (if one exists). This is usually in package.yml, if not please add it as part of your commit.
  • The summary should be brief, one short one sentence. It can be gotten from the font's website or you can create it yourself. It may be different than the eopkg description if that is longer.
  • The metadata_license needs to be CC0-1.0

If the font provides translations for the name, add them like this:

<summary>This is SARASA GOTHIC, a CJK programming font based on Iosevka and Source Han Sans.</summary>
<summary xml:lang="ja">更紗ゴシック</summary>
<summary xml:lang="kr">사라사 고딕</summary>
<summary xml:lang="zh">更纱黑体</summary>

See this PR for reference.

Then install it via package.yml

install    : |
    install -Dm00644 $pkgfiles/somefont.metainfo.xml $installdir/usr/share/metainfo/somefont.metainfo.xml

Build and test

To test the appstream metainfo is valid; after building the package with the appstream data included

Install appstream-glib then run appstream-builder --packages-dir=. --include-failed -v

Finally, check that the package doesn't show up in the example-failed.xml.gz file. The font preview will then show up in the software center when appstream-data is next refreshed.

To cleanup after running appstream-builder, run: rm -fr example* tmp/ cache/.

If a font package provides more than one font

appstream-builder requires a 1:1 mapping between appstream data and packages. If a package provides several different families of fonts, it must also be sub-packaged if providing more than one appstream metainfo xml file.

If a font is sub-packaged you can use the extends field in its metadata file so that one font extends another e.g.

<component type="font">
  <id>some-font-subpackage</id>
  <metadata_license>CC0-1.0</metadata_license>
  <extends>some-font</extends>
</component>

In the package.yml file only use one install directive for the metainfo file for the parent. Use patterns to put the sub-package metainfo.xml files in the right place. Example from noto-sans, which has noto-serif as a sub-package:

    install -Dm00644 $pkgfiles/noto-sans-ttf.metainfo.xml $installdir/usr/share/metainfo/noto-sans-ttf.metainfo.xml
patterns   :
    - ^noto-serif-ttf :
      - /usr/share/fonts/truetype/noto-sans-ttf/NotoSerif*
      - /usr/share/metainfo/noto-serif-ttf.metainfo.xml

Further information

Reference: The Freedesktop font metadata spec

joebonrichie avatar Oct 06 '23 11:10 joebonrichie

Hello, i want to try to help with this one. A few question:

  1. I see in the example given it just says Copyright 2023 Solus Developers <[email protected]>, while in commit https://github.com/getsolus/packages/commit/8b48034963aa8dfb329a96ef5ebfe1b1c089252d it says Copyright 2014 Richard Hughes <[email protected]>. Where does the copyright info should come from?
  2. info provided inside metainfo.xml on font-clear-sans-ttf doesn't really match with the specs given in the example. Also the filename should be clear-sans.metainfo.xml. Should i also add pull request for this?
  3. Is homepage should also be included in somefont.metainfo.xml ?

malfisya avatar Oct 12 '23 05:10 malfisya

1. I see in the example given it just says `Copyright 2023 Solus Developers <[email protected]>`, while in commit [8b48034](https://github.com/getsolus/packages/commit/8b48034963aa8dfb329a96ef5ebfe1b1c089252d) it says `Copyright 2014 Richard Hughes <[email protected]>`. Where does the copyright info should come from?

I stole the XML file from the fedora repos for that package.

2. info provided inside `metainfo.xml` on `font-clear-sans-ttf` doesn't really match with the specs given in the example. Also the filename should be `clear-sans.metainfo.xml`. Should i also add pull request for this?

Feel free to do so thanks

3. Is `homepage` should also be included in `somefont.metainfo.xml` ?

Feel free to do so. I will look at ensuring appstream-builder includes it.

joebonrichie avatar Oct 12 '23 10:10 joebonrichie

@joebonrichie , @EbonJaeger , @HarveyDevel I can no longer find any fonts that are missing appdata metainfo using the find commands. Please take a second look. We may be able to close this one out.

TraceyC77 avatar Nov 16 '23 02:11 TraceyC77

This is the list of font that i haven't done the last time I added metainfo.xml. I haven't seen a few of these fonts in this thread (maybe merged without mentioning this issue).

  • font-firacode-ttf |metainfo failed
  • font-firago-otf |metainfo failed subpackage
  • font-firago-ttf |metainfo failed subpackage
  • noto-sans-ttf |subpackage
  • noto-serif-ttf |subpackage
  • font-ibm-plex-otf
  • font-ibm-plex-ttf
  • font-weather-icons-otf
  • font-weather-icons-ttf
  • font-noto-cjk |metainfo failed
  • font-symbola-ttf |source unavailable https://aur.archlinux.org/packages/ttf-symbola https://dn-works.com/wp-content/uploads/2023/UFAS010223/Symbola.pdf
  • texlive-fonts-extra |have to touch texlive
  • texlive-fonts-opentype
  • texlive-fonts-truetype

malfisya avatar Nov 16 '23 04:11 malfisya

The noto fonts have had their metainfo file merged, and reference this issue (I see the mentions above). The others are indeed still missing it. Thanks for the update.

TraceyC77 avatar Nov 16 '23 22:11 TraceyC77

font-noto-cjk |metainfo failed

This one should be fixed now. I added a patch to appstream-builder to not fail on .ttc files.

joebonrichie avatar Nov 16 '23 23:11 joebonrichie

This gets every font that still needs metainfo, except the texlive ones that are provided by texlive.

find . -maxdepth 2 -type d -iname "font-*" -a ! -iname "*-manager" ! -exec sh -c 'test -e "$1"/files/*metainfo.xml' sh {} \; -print

I'm updating the main comment with it.

TraceyC77 avatar Nov 20 '23 21:11 TraceyC77

How are we looking on it issue now, is there any outstanding fonts?

joebonrichie avatar Jan 21 '24 13:01 joebonrichie

I found a few stragglers, using the same command as above (just added *-util to the exclusions)

~/p/p/packages ❯❯❯ find . -maxdepth 2 -type d -iname "font-*" -a ! -iname "*-manager" -a ! -iname "*-util" ! -exec sh -c 'test -e "$1"/files/*metainfo.xml' sh {} \; -print
./f/font-firago
./f/font-noto-cjk
./f/font-adobe-100dpi
./f/font-terminus-console
./f/font-firacode
./f/font-symbola-ttf
./f/font-weather-icons
./f/font-adobe-75dpi

t/texlive also has no metainfo file

TraceyC77 avatar Feb 16 '24 20:02 TraceyC77

font-adobe-100dpi and font-adobe-75dpi can be ignored/scratch off the list as they contain .bdf font. Bitmap font cannot be handled by appstream-builder.

malfisya avatar May 03 '24 13:05 malfisya

It seems appstream-builder can't handle .otf and .ttf file of the same font at the same time. This behaviour can also be replicated on nautilus thumbnail. If you preview .otf file first then the .ttf, The .ttf file thumbnail won't generate. You can try download this https://github.com/bBoxType/FiraGO/archive/1.000.tar.gz. Extract it. Then open FiraGO_TTF folder first, then FiraGO_OTF. See, if the thumbnail successfully generated.

This was tested on font-firago and font-weather-icons

Document related issue:

  • https://github.com/hughsie/appstream-glib/blob/appstream_glib_0_8_2/libappstream-builder/plugins/asb-plugin-font.c#L366
  • https://gitlab.freedesktop.org/cairo/cairo/-/issues/840
  • Appstream-builder log paste-7c2e8c62f4e0ce56.txt

malfisya avatar May 04 '24 01:05 malfisya