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

[Backport release-3_34] Download Google fonts from github, not broken Google fonts download url - Fix automatic font download on Windows #58524

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 110 additions & 4 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,9 +274,11 @@ 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() );
bool installFontsFromData( const QByteArray &data, QString &errorMessage /Out/, QStringList &families /Out/, QString &licenseDetails /Out/, const QString &filename = QString(), const QString &extension = QString() );
%Docstring
Installs local user fonts from the specified raw ``data``.

Expand All @@ -182,6 +287,7 @@ or a zipped archive of font files.

:param data: raw font data or zipped font data
:param filename: filename hint for destination file. Will be ignored for archived content (e.g. zip file data)
:param extension: known file extension (eg "ttf", "otf") for font. Should be specified to avoid issues with font installation on Windows if filename is not specified (since QGIS 3.38)

:return: - ``True`` if installation was successful.
- errorMessage: will be set to a descriptive error message if the installation fails
Expand Down
114 changes: 110 additions & 4 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,9 +274,11 @@ 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() );
bool installFontsFromData( const QByteArray &data, QString &errorMessage /Out/, QStringList &families /Out/, QString &licenseDetails /Out/, const QString &filename = QString(), const QString &extension = QString() );
%Docstring
Installs local user fonts from the specified raw ``data``.

Expand All @@ -182,6 +287,7 @@ or a zipped archive of font files.

:param data: raw font data or zipped font data
:param filename: filename hint for destination file. Will be ignored for archived content (e.g. zip file data)
:param extension: known file extension (eg "ttf", "otf") for font. Should be specified to avoid issues with font installation on Windows if filename is not specified (since QGIS 3.38)

:return: - ``True`` if installation was successful.
- errorMessage: will be set to a descriptive error message if the installation fails
Expand Down
Loading
Loading