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 HTML bold/italic/font size and font family to labelling #50103

Merged
merged 17 commits into from
Sep 7, 2022

Conversation

nyalldawson
Copy link
Collaborator

@nyalldawson nyalldawson commented Sep 6, 2022

This PR adds support for additional HTML formatting tags within labeling (and everywhere text renderer is used). Specifically:

  • font family
  • font size
  • bold
  • italic

Sponsored by the Swiss QGIS user group

Fixes #40532
Fixes #32098
Fixes #18727
Fixes #31501

(should have no impact on existing releases, as the text fragements
previously did not support properties which altered font metrics)
when creating fonts for document fragments
@nyalldawson nyalldawson added Requires Tests! Waiting on the submitter to add unit tests before eligible for merging Feature Changelog Items that are queued to appear in the visual changelog - remove after harvesting labels Sep 6, 2022
@github-actions github-actions bot added this to the 3.28.0 milestone Sep 6, 2022
@nirvn
Copy link
Contributor

nirvn commented Sep 6, 2022

@nyalldawson , did some testing, it's really nice, good job.

I did run into a crash (having to do with curved labels I think):

#6  0x000055555556567b in myMessageOutput(QtMsgType, QMessageLogContext const&, QString const&)
    (type=QtFatalMsg, msg=...) at /home/webmaster/dev/cpp/QGIS/src/app/main.cpp:455
#7  0x00007ffff3a2e530 in  () at /lib/x86_64-linux-gnu/libQt5Core.so.5
#8  0x00007ffff3a2e649 in  () at /lib/x86_64-linux-gnu/libQt5Core.so.5
#9  0x00007ffff39fab8a in QMessageLogger::fatal(char const*, ...) const ()
#10 0x00007ffff39f9ff0 in qt_assert_x(char const*, char const*, char const*, int) () at /lib/x86_64-linux-gnu/libQt5Core.so.5
#11 0x00007ffff142a73d in QList<double>::last() const (this=0x7fffcbffb378) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:365
#12 0x00007ffff142a134 in QList<double>::constLast() const (this=0x7fffcbffb378) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qlist.h:366
#13 0x00007ffff1429a41 in QgsTextDocumentMetrics::calculateMetrics(QgsTextDocument const&, QgsTextFormat const&, QgsRenderContext const&, double)
    (document=..., format=..., context=..., scaleFactor=1) at /home/webmaster/dev/cpp/QGIS/src/core/textrenderer/qgstextdocumentmetrics.cpp:153
#14 0x00007ffff1e0150b in QgsPalLayerSettings::calculateLabelSize(QFontMetricsF const*, QString const&, double&, double&, QgsFeature const*, QgsRenderContext*, double*, double*, QgsTextDocument*, QgsTextDocumentMetrics*)
     (this=0x55556062e520, fm=0x7fffc07238c0, text=..., labelX=@0x7fffcbffb4e8: 2.5599981057214506e-172, labelY=@0x7fffcbffb4f0: 9.8813129168249309e-324, f=0x7fffcbffbaa0, context=0x55556062b5d0, rotatedLabelX=0x7fffcbffb4f8, rotatedLabelY=0x7fffcbffb500, document=0x7fffcbffb508, documentMetrics=0x7fffcbffb890) at /home/webmaster/dev/cpp/QGIS/src/core/labeling/qgspallabeling.cpp:1630
#15 0x00007ffff1e03f30 in QgsPalLayerSettings::registerFeatureWithDetails(QgsFeature const&, QgsRenderContext&, QgsGeometry, QgsSymbol const*)
    (this=0x55556062e520, f=..., context=..., obstacleGeometry=..., symbol=0x55556062c2d0)
    at /home/webmaster/dev/cpp/QGIS/src/core/labeling/qgspallabeling.cpp:2025
#16 0x00007ffff1e2e9f4 in QgsVectorLayerLabelProvider::registerFeature(QgsFeature const&, QgsRenderContext&, QgsGeometry const&, QgsSymbol const*)
    (this=0x55556062e4c0, feature=..., context=..., obstacleGeometry=..., symbol=0x55556062c2d0)
    at /home/webmaster/dev/cpp/QGIS/src/core/labeling/qgsvectorlayerlabelprovider.cpp:199
#17 0x00007ffff1fe3db2 in QgsVectorLayerRenderer::drawRenderer(QgsFeatureRenderer*, QgsFeatureIterator&)
     (this=0x55556062bf10, renderer=0x55556062d7a0, fit=...) at /home/webmaster/dev/cpp/QGIS/src/core/vector/qgsvectorlayerrenderer.cpp:511
#18 0x00007ffff1fe3039 in QgsVectorLayerRenderer::renderInternal(QgsFeatureRenderer*) (this=0x55556062bf10, renderer=0x55556062d7a0)
    at /home/webmaster/dev/cpp/QGIS/src/core/vector/qgsvectorlayerrenderer.cpp:409
#19 0x00007ffff1fe1a6c in QgsVectorLayerRenderer::render() (this=0x55556062bf10)
    at /home/webmaster/dev/cpp/QGIS/src/core/vector/qgsvectorlayerrenderer.cpp:225

I haven't worked out a reduced test project to replicate crash, but on a large project, I can replicate crash as soon as curved labels are on the canvas. Let me know if you need something or the above stacktrace is enough.

One thing I've noticed is the absence of support for font-size in %. Is that a Qt limitation or is there a way to support that? I'd be nice to have it as you could still control the text size via UI and have parts be e.g. font-size:80% of the text size that's set via UI.

In any case, super cool stuff.

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.

The code change is, well, dense! :) I couldn't find anything wrong but it's not the easiest part of the src tree to navigate. I however did a fair amount of testing locally, and couldn't spot any further regressions. Good job. Just a few Qs.

src/core/labeling/qgstextlabelfeature.h Show resolved Hide resolved
src/core/textrenderer/qgstextdocumentmetrics.cpp Outdated Show resolved Hide resolved
src/core/textrenderer/qgstextmetrics.h Show resolved Hide resolved
@nyalldawson nyalldawson removed the Requires Tests! Waiting on the submitter to add unit tests before eligible for merging label Sep 7, 2022
@nyalldawson nyalldawson changed the title Add support for HTML bold/italic/font size and font family to labelling (WIP) Add support for HTML bold/italic/font size and font family to labelling Sep 7, 2022
@nyalldawson nyalldawson merged commit 8dbb654 into qgis:master Sep 7, 2022
@nyalldawson nyalldawson deleted the html_font_metrics branch September 7, 2022 12:09
@Gustry Gustry added the Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. label Sep 7, 2022
@github-actions
Copy link

github-actions bot commented Sep 7, 2022

@nyalldawson
This pull request has been tagged as requiring documentation.

A documentation ticket will be opened at https://github.com/qgis/QGIS-Documentation when this PR is merged.

Please update the description (not the comments) with helpful description and screenshot to help the work from documentors.
Also, any commit having [needs-doc] or [Needs Documentation] in will see its message pushed to the issue, so please be as verbose as you can.

Thank you!

@github-actions
Copy link

github-actions bot commented Sep 7, 2022

@nyalldawson
A documentation ticket has been opened at qgis/QGIS-Documentation#7762
It is your responsibility to visit this ticket and add as much detail as possible for the documentation team to correctly document this change.
Thank you!

@zacharlie zacharlie added 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
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 Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo.
Projects
None yet
4 participants