Skip to content

Commit

Permalink
Download Google fonts from github, not broken Google fonts download url
Browse files Browse the repository at this point in the history
Note that not all fonts available from Google fonts are present on
the github repo for some reason, eg Open Sans Condensed is not.

Fixes qgis#57070
  • Loading branch information
nyalldawson authored and agiudiceandrea committed Aug 29, 2024
1 parent 5efe6a7 commit d52518c
Show file tree
Hide file tree
Showing 5 changed files with 2,134 additions and 1,679 deletions.
111 changes: 108 additions & 3 deletions python/PyQt6/core/auto_generated/textrenderer/qgsfontmanager.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,69 @@



class QgsFontDownloadDetails
{
%Docstring(signature="appended")

Encapsulates details required for downloading a font.

.. versionadded:: 3.38
%End

%TypeHeaderCode
#include "qgsfontmanager.h"
%End
public:

QgsFontDownloadDetails();
%Docstring
Constructor for an invalid QgsFontDownloadDetails.
%End

QgsFontDownloadDetails( const QString &family, const QStringList &fontUrls, const QString &licenseUrl = QString() );
%Docstring
Constructor for QgsFontDownloadDetails.

:param family: Font family name
:param fontUrls: List of URLS to download for complete set of the font family resources
:param licenseUrl: optional URL to download the font license
%End

static QString standardizeFamily( const QString &family );
%Docstring
Returns a cleaned, standardized version of a font ``family`` name.
%End

bool isValid() const;
%Docstring
Returns ``True`` if the details represent a valid downloadable font.
%End

QString family() const;
%Docstring
Returns the font family.

.. seealso:: :py:func:`standardizedFamily`
%End

QString standardizedFamily() const;
%Docstring
Returns the cleaned, standardized font family name.
%End

QStringList fontUrls() const;
%Docstring
Returns a list of download URLs for all files associated with the font family.
%End

QString licenseUrl() const;
%Docstring
Returns the optional URL for downloading the font license details.
%End

};


class QgsFontManager : QObject
{
%Docstring(signature="appended")
Expand Down Expand Up @@ -146,7 +209,7 @@ Enables font downloads the the current QGIS session.
Ensure that the :py:class:`QgsApplication` is fully initialized before calling this method.
%End

QString urlForFontDownload( const QString &family, QString &matchedFamily /Out/ ) const;
QString urlForFontDownload( const QString &family, QString &matchedFamily /Out/ ) const /Deprecated/;
%Docstring
Returns the URL at which the font ``family`` can be downloaded.

Expand All @@ -157,11 +220,51 @@ return an empty string for any font families not present in this list.

:return: - URL to download font, or an empty string if no URL is available
- matchedFamily: will be set to found font family if a match was successful

.. deprecated:: QGIS 3.38
use :py:func:`~QgsFontManager.detailsForFontDownload` instead
%End

void downloadAndInstallFont( const QUrl &url, const QString &identifier = QString() );
QgsFontDownloadDetails detailsForFontDownload( const QString &family, QString &matchedFamily /Out/ ) const;
%Docstring
Downloads a font and installs in the user's profile/fonts directory as an application font.
Returns a the details for downloading the specified font ``family``.

The returned object will contain all URLs which must be fetched to retrieve the
entire font family (eg it may contain one URL per font style).

This method relies on a hardcoded list of available freely licensed fonts, and will
return an invalid :py:class:`QgsFontDownloadDetails` for any font families not present in this list.

:param family: input font family name to try to match to known fonts

:return: - details required for downloading font, or an invalid :py:class:`QgsFontDownloadDetails` if no URL is available
- matchedFamily: will be set to found font family if a match was successful

.. versionadded:: 3.38
%End

void downloadAndInstallFont( const QUrl &url, const QString &identifier = QString() ) /Deprecated/;
%Docstring
Downloads a font and installs in the user's profile/fonts directory as an application font,
where the font family can be downloaded via a single ``url``.

The download will proceed in a background task.

The optional ``identifier`` string can be used to specify a user-friendly name for the download
tasks, e.g. the font family name if known.

.. seealso:: :py:func:`fontDownloaded`

.. seealso:: :py:func:`fontDownloadErrorOccurred`

.. deprecated:: QGIS 3.38
use the version which takes a :py:class:`QgsFontDownloadDetails` argument instead
%End

void downloadAndInstallFont( const QgsFontDownloadDetails &details, const QString &identifier = QString() );
%Docstring
Downloads a font and installs in the user's profile/fonts directory as an application font, where the
font family is split over multiple download URLs.

The download will proceed in a background task.

Expand All @@ -171,6 +274,8 @@ tasks, e.g. the font family name if known.
.. seealso:: :py:func:`fontDownloaded`

.. seealso:: :py:func:`fontDownloadErrorOccurred`

.. versionadded:: 3.38
%End

bool installFontsFromData( const QByteArray &data, QString &errorMessage /Out/, QStringList &families /Out/, QString &licenseDetails /Out/, const QString &filename = QString() );
Expand Down
111 changes: 108 additions & 3 deletions python/core/auto_generated/textrenderer/qgsfontmanager.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,69 @@



class QgsFontDownloadDetails
{
%Docstring(signature="appended")

Encapsulates details required for downloading a font.

.. versionadded:: 3.38
%End

%TypeHeaderCode
#include "qgsfontmanager.h"
%End
public:

QgsFontDownloadDetails();
%Docstring
Constructor for an invalid QgsFontDownloadDetails.
%End

QgsFontDownloadDetails( const QString &family, const QStringList &fontUrls, const QString &licenseUrl = QString() );
%Docstring
Constructor for QgsFontDownloadDetails.

:param family: Font family name
:param fontUrls: List of URLS to download for complete set of the font family resources
:param licenseUrl: optional URL to download the font license
%End

static QString standardizeFamily( const QString &family );
%Docstring
Returns a cleaned, standardized version of a font ``family`` name.
%End

bool isValid() const;
%Docstring
Returns ``True`` if the details represent a valid downloadable font.
%End

QString family() const;
%Docstring
Returns the font family.

.. seealso:: :py:func:`standardizedFamily`
%End

QString standardizedFamily() const;
%Docstring
Returns the cleaned, standardized font family name.
%End

QStringList fontUrls() const;
%Docstring
Returns a list of download URLs for all files associated with the font family.
%End

QString licenseUrl() const;
%Docstring
Returns the optional URL for downloading the font license details.
%End

};


class QgsFontManager : QObject
{
%Docstring(signature="appended")
Expand Down Expand Up @@ -146,7 +209,7 @@ Enables font downloads the the current QGIS session.
Ensure that the :py:class:`QgsApplication` is fully initialized before calling this method.
%End

QString urlForFontDownload( const QString &family, QString &matchedFamily /Out/ ) const;
QString urlForFontDownload( const QString &family, QString &matchedFamily /Out/ ) const /Deprecated/;
%Docstring
Returns the URL at which the font ``family`` can be downloaded.

Expand All @@ -157,11 +220,51 @@ return an empty string for any font families not present in this list.

:return: - URL to download font, or an empty string if no URL is available
- matchedFamily: will be set to found font family if a match was successful

.. deprecated:: QGIS 3.38
use :py:func:`~QgsFontManager.detailsForFontDownload` instead
%End

void downloadAndInstallFont( const QUrl &url, const QString &identifier = QString() );
QgsFontDownloadDetails detailsForFontDownload( const QString &family, QString &matchedFamily /Out/ ) const;
%Docstring
Downloads a font and installs in the user's profile/fonts directory as an application font.
Returns a the details for downloading the specified font ``family``.

The returned object will contain all URLs which must be fetched to retrieve the
entire font family (eg it may contain one URL per font style).

This method relies on a hardcoded list of available freely licensed fonts, and will
return an invalid :py:class:`QgsFontDownloadDetails` for any font families not present in this list.

:param family: input font family name to try to match to known fonts

:return: - details required for downloading font, or an invalid :py:class:`QgsFontDownloadDetails` if no URL is available
- matchedFamily: will be set to found font family if a match was successful

.. versionadded:: 3.38
%End

void downloadAndInstallFont( const QUrl &url, const QString &identifier = QString() ) /Deprecated/;
%Docstring
Downloads a font and installs in the user's profile/fonts directory as an application font,
where the font family can be downloaded via a single ``url``.

The download will proceed in a background task.

The optional ``identifier`` string can be used to specify a user-friendly name for the download
tasks, e.g. the font family name if known.

.. seealso:: :py:func:`fontDownloaded`

.. seealso:: :py:func:`fontDownloadErrorOccurred`

.. deprecated:: QGIS 3.38
use the version which takes a :py:class:`QgsFontDownloadDetails` argument instead
%End

void downloadAndInstallFont( const QgsFontDownloadDetails &details, const QString &identifier = QString() );
%Docstring
Downloads a font and installs in the user's profile/fonts directory as an application font, where the
font family is split over multiple download URLs.

The download will proceed in a background task.

Expand All @@ -171,6 +274,8 @@ tasks, e.g. the font family name if known.
.. seealso:: :py:func:`fontDownloaded`

.. seealso:: :py:func:`fontDownloadErrorOccurred`

.. versionadded:: 3.38
%End

bool installFontsFromData( const QByteArray &data, QString &errorMessage /Out/, QStringList &families /Out/, QString &licenseDetails /Out/, const QString &filename = QString() );
Expand Down
Loading

0 comments on commit d52518c

Please sign in to comment.