Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for "user" fonts, and automatically downloading freely licensed fonts #49020

Merged
merged 29 commits into from
Jun 20, 2022

Conversation

nyalldawson
Copy link
Collaborator

@nyalldawson nyalldawson commented Jun 16, 2022

This PR works towards an alternative solution to #46588 (adding support for vector tile font glyphs). (This approach was selected because supporting vector font glyphs is an extremely difficult task, which ultimately would result only in poor-quality rasterised text rendering.)

In full, this adds a new "Fonts" panel to the settings dialog, with support for:

  • The ability for users to populate a list of automatic font replacements to apply when loading projects or styles. So e.g. they can setup an automatic replacement of "Arial" to "Helvetica", allowing easier use of projects and styles created on different operating systems.
  • Users can now place TTF or OTF fonts in the "fonts" subfolder off their user profile. These fonts will automatically be loaded at QGIS startup time. This provides a way for users to use fonts without requiring them to be installed on an operating system level, which is often blocked in enterprise environments. The Fonts setting panel lists all installed user fonts and allows users to manage (i.e. remove) previously installed user fonts
  • There's an api for plugins/other clients to specify additional user font folders which should be scanned during QGIS startup too, at the request of QField
  • There's now support for automatic downloading of missing fonts in certain circumstances. If a user opens a project or style, OR tries to load a vector tile layer which references fonts which aren't currently available, then a hard-coded list of freely licensed fonts to download URL is consulted to determine whether it's possible to automatically download the font. If so, a background task will launch to download and install the font into the user font folder and notify the user of the font license. (There's also a setting to opt-out of this in the Fonts panel if so desired). This provides a solution to Vector tile glyph support #46588, in that the vector tile styles referenced in that ticket can now be loaded by any user and the required fonts will be automatically installed without any manual user effort!

Funded by Toitū Te Whenua Land Information New Zealand

Peek 2022-06-16 14-48

@nyalldawson nyalldawson added Feature Frozen Feature freeze - Do not merge! labels Jun 16, 2022
@github-actions github-actions bot added this to the 3.26.0 milestone Jun 16, 2022
@nyalldawson nyalldawson modified the milestones: 3.26.0, 3.28 (feature) Jun 16, 2022
Copy link
Contributor

@nirvn nirvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic!

src/app/options/qgsfontoptions.cpp Outdated Show resolved Hide resolved
src/app/qgisapp.cpp Outdated Show resolved Hide resolved
src/app/qgisapp.cpp Show resolved Hide resolved
src/core/textrenderer/qgsfontmanager.cpp Outdated Show resolved Hide resolved
src/core/textrenderer/qgstextformat.cpp Show resolved Hide resolved
src/core/textrenderer/qgstextformat.cpp Show resolved Hide resolved
src/ui/qgsfontoptionswidgetbase.ui Outdated Show resolved Hide resolved
src/core/textrenderer/qgsfontmanager.cpp Outdated Show resolved Hide resolved
to configure a set of automatic font name replacements to use
when loading projects or styles

Allows users/administrators to configure a list of alternative fonts
to automatically match when a font referenced by a project/style is
not available on the current system.
available for use in QGIS

Allows for use of fonts which aren't installed system-wide in QGIS, e.g.
when the user does not have permission to install fonts on a system.
And populate hardcoded list with a bunch of known fonts available
from Google Fonts
This is an alternative approach to solving qgis#46588, where we avoid the
issues which arise from trying to render vector tile PBF fonts.

Refs qgis#46588
and make opt-in for non-app clients

There's a tricky initialization balancing act happening here -- but
if we try to load the default style on a system missing the fonts
referenced in that style, then we risk trying to download those
fonts before the QgsNetworkAccessManager is ready.

So play it safe and defer all font download handling until the
QGIS app is fully launched.
@nyalldawson nyalldawson merged commit 864fee0 into qgis:master Jun 20, 2022
@nyalldawson nyalldawson deleted the font_manager branch June 20, 2022 03:02
@zacharlie zacharlie added Changelog Items that are queued to appear in the visual changelog - remove after harvesting ChangelogHarvested This PR description has been harvested in the Changelog already. and removed Changelog Items that are queued to appear in the visual changelog - remove after harvesting labels Oct 16, 2022
@phidrho
Copy link
Contributor

phidrho commented Jan 30, 2023

Hi,

I really like this feature, thank you for this @nyalldawson.
Just wanted to check to be sure, is it possible to add fonts from other sources than Google fonts? If I understood correctly from qgsfontmanager.cpp, it's currently not possible.
I had in mind to add some popular free fonts which are designed to replace Microsoft's fonts, but are not available from Google fonts, for example:
Liberation fonts from Red Hat - LiberationSerif, LiberationSans, LiberationSans Narrow,
GNU FreeFonts from GNU project

@nyalldawson
Copy link
Collaborator Author

@phidrho

Just wanted to check to be sure, is it possible to add fonts from other sources than Google fonts?

Yes, they just need to have:

  1. A stable download uri
  2. Be either directly downloaded as a ttf or a zip of a ttf without a complex structure
  3. Be openly licensed

You basically just need to add logic to QgsFontManager::urlForFontDownload to return the correct download url for the desired font names.

@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Apr 4, 2024

Hi @nyalldawson, it seems something changed in https://fonts.google.com/download. Please see https://trac.osgeo.org/osgeo4w/ticket/824 and google/fonts#7481.

@nyalldawson
Copy link
Collaborator Author

@agiudiceandrea not an easy fix. I'll look into it later this month.

@kannes
Copy link
Contributor

kannes commented Apr 8, 2024

It looks like the fonts are available via GitHub too without any need for API keys (until Microsoft decides otherwise): https://github.com/google/fonts/tree/main/ofl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ChangelogHarvested This PR description has been harvested in the Changelog already. Feature Frozen Feature freeze - Do not merge!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants