getsolus / packages

Solus Package Monorepo & Issue Tracker
65 stars 78 forks source link

appstream: Add metainfo xml to all font packages #449

Open joebonrichie opened 1 year ago

joebonrichie commented 1 year ago

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 <copyright@getsol.us -->
  <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.

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

malfisya commented 12 months ago

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 <copyright@getsol.us>, while in commit https://github.com/getsolus/packages/commit/8b48034963aa8dfb329a96ef5ebfe1b1c089252d it says Copyright 2014 Richard Hughes <richard@hughsie.com>. 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 ?
joebonrichie commented 12 months ago
1. I see in the example given it just says `Copyright 2023 Solus Developers <copyright@getsol.us>`, while in commit [8b48034](https://github.com/getsolus/packages/commit/8b48034963aa8dfb329a96ef5ebfe1b1c089252d) it says `Copyright 2014 Richard Hughes <richard@hughsie.com>`. 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.

TraceyC77 commented 10 months ago

@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.

malfisya commented 10 months ago

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).

TraceyC77 commented 10 months ago

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.

joebonrichie commented 10 months ago

font-noto-cjk |metainfo failed

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

TraceyC77 commented 10 months ago

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.

joebonrichie commented 8 months ago

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

TraceyC77 commented 7 months ago

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

malfisya commented 5 months ago

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 commented 5 months ago

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: