71 Commits

Author SHA1 Message Date
Nyall Dawson
a7c39ffdc7 Add support for super and subscript HTML formatting in text renderer
This allows for either:

- <sup>superscript</sup> / <sub>subscript</sub> components in text,
where the text will be vertically super or subscript aligned
and automatically sized to 2/3rd of the parent font size. Users
can also set a fixed font size for the super/sub script by
including css rules, e.g. <sup style="font-size:33pt">super</sup>

- "vertical-align: super" or "vertical-align: sub" CSS formatting
rules in any other HTML element

Sponsored by OSGEO UK
2022-11-14 20:46:15 +10:00
Nyall Dawson
79b809a585 Prepare framework for text renderer vertical alignment 2022-11-14 20:46:15 +10:00
Nyall Dawson
ed84780de6 Avoid unnecessary font scaling by precalculating if format has a null
font size
2022-11-10 18:30:06 +10:00
Nyall Dawson
e478a52d72 Use precalculated horizontal advance and fragment fonts from text metrics instead of
recalculating
2022-11-10 18:30:06 +10:00
Nyall Dawson
8dbb654a55 Address review 2022-09-07 22:09:52 +10:00
Nyall Dawson
254c43df5f Correctly render vertical oriented text using HTML formatting 2022-09-07 22:09:52 +10:00
Nyall Dawson
05bd566089 Modify text renderer to account for rendering text with HTML
content which varies in font metrics
2022-09-07 22:09:52 +10:00
Nyall Dawson
5f2aca49af Correctly account for scaling factor and render context scale
when creating fonts for document fragments
2022-09-07 22:09:52 +10:00
Nyall Dawson
ad5d9d89f5 Add font size, family, italic and bold to QgsTextCharacterFormat 2022-09-07 22:09:52 +10:00
Nyall Dawson
b4c9378625 Move text renderer enums to Qgis, promote to enum class, tighten includes 2022-09-06 15:30:00 +10:00
Nyall Dawson
ed9dfa9f5a Move TextOrientation enum from QgsTextFormat and promote to enum class 2022-09-05 17:17:18 +10:00
Nyall Dawson
775e333ec3 [feature][labeling] Add option to use absolute units for line height
Previously the line height was always set in multiples of the
text line spacing. This works fine for rendering text blocks
containing text of all the same sizes, but when we mix
text sizes in the one document then the relative line height
option doesn't cover all use cases. (e.g. when a constant
spacing between lines is desired even when the text on those
lines varies in height)
2022-09-05 13:17:33 +10:00
Nyall Dawson
864fee0172 Try to take stored font filename from response headers 2022-06-20 13:01:55 +10:00
Nyall Dawson
dae637a67c Defer font download handling until QgsApplication is fully initialized
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.
2022-06-20 13:01:55 +10:00
Nyall Dawson
b9ff03473b Download missing fonts when parsing vector tile styles wherever possible
This is an alternative approach to solving #46588, where we avoid the
issues which arise from trying to render vector tile PBF fonts.

Refs #46588
2022-06-20 13:01:55 +10:00
Nyall Dawson
3214235580 Add method to remove a user font 2022-06-20 13:01:55 +10:00
Nyall Dawson
e1dba0dbe0 Allow for multiple user font directories, and add method to return
all installed user fonts
2022-06-20 13:01:55 +10:00
Nyall Dawson
852480c7bc Wrap up font download in a nice method which just requires a family name
And populate hardcoded list with a bunch of known fonts available
from Google Fonts
2022-06-20 13:01:55 +10:00
Nyall Dawson
4772f6c27e Add method to download and install a font 2022-06-20 13:01:55 +10:00
Nyall Dawson
4f2705e435 Make any TTF/OTF fonts stored in the QGIS user profile/fonts directory
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.
2022-06-20 13:01:55 +10:00
Nyall Dawson
d4ef3e3c3d Make sure QgsFontManager methods are thread safe 2022-06-20 13:01:55 +10:00
Nyall Dawson
607b140c30 Add method to process a font family name and apply any matching
replacements
2022-06-20 13:01:55 +10:00
Nyall Dawson
3d7310b65c Persist font replacements across sessions 2022-06-20 13:01:55 +10:00
Nyall Dawson
0091696272 Start on QgsFontManager class 2022-06-20 13:01:55 +10:00
Nyall Dawson
9de1920302 Add option for "forced bold" and "force italic" to QgsTextFormat
Unlike setting a font's style via setNamedStyle(), these settings
will ensure that a font is always rendered in bold or italic regardless
of whether the font family actually has a bold or italic variant. A
"faux bold" or slanted text effect will be emulated by Qt, which may
result in poor quality font rendering.

(For this reason it is greatly preferred to call setNamedStyle() instead.)

This API is being added so that QgsTextFormat/QgsTextRenderer can
replicate the same font behaviour as the base QFont/QPainter classes
do, where faux bold/italic effects are possible.

(It's not exposed anywhere for user control!)
2022-04-26 10:56:28 +10:00
Nyall Dawson
fadfb477d9 [api] Move text wrapping handling logic from layout table code to QgsTextRenderer
Allows other users of QgsTextRenderer to take advantage of the
automatic line wrapping behaviour
2021-11-29 13:03:13 +10:00
Nyall Dawson
730cd7e23a [feature] Add "stretch" setting for labels and text formats
Allows text to be horizontally stretched or condensed by a %
factor. Handy for tweaking the widths of fonts to fit a bit
of extra text into labels (when used sparingly, that is...
you can certainly abuse font stretching with some horrendous
results!)

Requires Qt 6.3+ or KDE's 5.15 fork

Thanks for KDAB for fixing the upstream issues blocking this!
2021-11-09 14:58:14 +11:00
Nyall Dawson
dae69acc76 [feature] Support Small Caps style in labels/text renderer
Adds two new capitalization styles for labels and text symbols:

- Small Caps: Renders lowercase characters as small caps
- All Small Caps: Renders all characters as small caps (regardless
of their original case)

Requires Qt 6.3+, or Qt 5.15 using KDE's fork and the cmake
HAS_KDE_QT5_SMALL_CAPS_FIX switch defined during build.
2021-11-08 14:36:44 +11:00
Nyall Dawson
7c75c4cd7f Never try to create/render 0 pixel sized fonts
This throws Qt warnings, and results in large fonts being created
when they actually should be invisible
2021-08-19 05:58:08 +10:00
Nyall Dawson
711a615be3 Fix raises sphinx format 2021-06-25 10:50:04 +10:00
Nyall Dawson
bb0dfb6ba3 Doxygen says no 2021-06-10 11:03:43 +10:00
Nyall Dawson
49e48f9383 Better approach to avoid duplicate docs 2021-06-10 11:03:43 +10:00
Nyall Dawson
4ff3f447dc Don't try to insert links in raises blocks in PyQGIS docs
These aren't formatted correctly if we do
2021-06-10 11:03:43 +10:00
Nyall Dawson
8359281012 Fix formatting of exception blocks in PyQGIS docs 2021-06-10 11:03:43 +10:00
Nyall Dawson
22c2d7213b Remove unnecessary includes of qgssymbollayerreference.h 2021-05-24 12:16:21 +10:00
Mathieu Pellerin
65ba35921a Address review 2021-05-04 13:12:45 +07:00
Mathieu Pellerin
672d53e5fe Handle data defined properties upgrade when reading pre-3.20 project files 2021-05-04 11:57:28 +07:00
Mathieu Pellerin
4fad4bac0f [feature][labeling] Use fill symbols to render rectangle,square,circle,ellipse background shields 2021-05-04 11:57:28 +07:00
Nyall Dawson
e5c709ccd6 [api] Provide a mechanism to specify a list of fallback font families for
QgsTextFormat

Just like in CSS, these families will be used as an ordered list
of fonts to fallback on if the actual text format font isn't available
on a particular QGIS install.

This is API only, and isn't designed to be shown anywhere in QGIS.
Instead the intended use is for creators of QGIS styles to either use
the raw api to specify the list of fallback fonts OR hand edit the
style xml to add the fallback fonts, e.g by adding a block like:

    <families>
      <family name="Arial"/>
      <family name="Helvetica"/>
      <family name="Sans"/>
    </families>

To the "text-style" parent element.
2021-04-22 16:39:24 +10:00
Nyall Dawson
832d5e95ee Cleanup and refactor calculationg of label text metrics for curved
labels, and move methods for calculating curved text placement
out of PAL so that they can be reused elsewhere
2021-04-08 14:26:05 +10:00
Denis Rouzaud
ba8a445850 run sipify 2021-03-22 21:13:52 +01:00
Nyall Dawson
50b9beaad6 [sipify] Catch more class references and insert :py:class: annotations 2021-01-31 05:41:22 +10:00
Nyall Dawson
620948f809 Add method to change capitalization of QgsTextDocument 2020-09-21 12:05:54 +10:00
Nyall Dawson
484ba6f979 [labeling] Add a new capitalization option for "Title Case", and
rename the confusing "Capitalize First Letter" option to
"Force First Letter to Capital"

This change is intended to clarify the role of the "capitalize
first letter" option, and to provide an option which actually
does what users expect the "capitalize first letter" option
to do.

Fixes #16539
2020-09-17 09:33:51 +10:00
Nyall Dawson
51d8ad75c5 Don't modify text format paint effects in place
Avoids race conditions when multiple threads are rendering the same
text format which contains paint effects

Fixes #37938
2020-07-27 07:36:50 +10:00
Nyall Dawson
ac5a7226ee Add equality operator for QgsTextFormat 2020-07-14 11:23:33 +10:00
Nyall Dawson
9bad5578cf Equality operator for QgsTextShadowSettings 2020-07-14 11:23:33 +10:00
Nyall Dawson
52d7d1886a Add an equality operator for QgsTextMaskSettings 2020-07-14 11:23:33 +10:00
Nyall Dawson
305fa330bd Add equality operator for QgsTextBufferSettings 2020-07-14 11:23:33 +10:00
Nyall Dawson
7547dbd464 Equality operator for QgsTextBackgroundSettings 2020-07-14 11:23:33 +10:00