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

Restructure html label section and add word-spacing #9249

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
99 changes: 61 additions & 38 deletions docs/user_manual/style_library/label_settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,59 +130,82 @@ In the |text| :guilabel:`Text` tab, you can set:
* the :guilabel:`Size` in any :ref:`supported unit <unit_selector>`
* the :guilabel:`Color`
* the :guilabel:`Opacity`
* and :guilabel:`Allow HTML Formatting`:
The HTML formatting option enables the proper rendering of some HTML tags to customize the label.
The supported HTML tags are:
* and :guilabel:`Allow HTML Formatting` enables the use of a subset of HTML tags and CSS rules to customize the label.

At the bottom of the tab, a widget shows a filterable list of compatible items
stored in your :ref:`style manager database <vector_style_manager>`.
This allows you to easily configure the current text format or label setting
based on an existing one, and also save a new item to the style database:
Press the :guilabel:`Save format...` or :guilabel:`Save settings...` button
and provide a name and tag(s).

.. note:: When configuring a :guilabel:`Label Settings` item, text format items
are also available in this widget. Select one to quickly overwrite the current
:ref:`textual properties <text_format>` of the label.
Likewise, you can create/overwrite a text format from there.

* Color, applicable to text, underline, strikethrough, and overline
* Font properties (font family, font size, bold and italic)
* Superscript and subscript components in text,
where the text will be vertically :sup:`super` or :sub:`sub` aligned
and automatically sized to 2/3 of the parent font size.
You can also set a fixed font size for the superscript/subscript
by including css rules, e.g.:

.. code:: html
.. _labels_text_html:

<sup style="font-size:33pt">my superscript text</sup>

The CSS formatting rules ``vertical-align: super`` or ``vertical-align: sub``
are also available in any other HTML element (annotation, layout label or HTML items, ...).
Allow HTML Formatting
.....................

In order to use the HTML formatting, you need to provide the HTML code in the :guilabel:`Value` field.
The expression is parsed and any supported HTML tag overrides its corresponding setting in the labels properties.
They also combine well with other background, shadow, buffer... properties of labels.
With :guilabel:`Allow HTML Formatting` enabled, you need to provide the HTML code in the :guilabel:`Value` field.
Use whitespaces instead of tabs for any kind of indentation.
The expression is parsed and any supported HTML tag overrides its corresponding setting in the labels properties.
An exhaustive list of the supported subset of HTML tags and CSS properties can be found `here <https://doc.qt.io/qt-5/richtext-html-subset.html>`_.
Copy link
Collaborator

Choose a reason for hiding this comment

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

@folinimarc Maybe do I misunderstand or nitpick but we do not yet support all these tags/properties, do we? They are more like targets afaict, "to be supported".

Copy link
Contributor

@nyalldawson nyalldawson Sep 16, 2024

Choose a reason for hiding this comment

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

Correct, we only support a small subset of them:

  • font colour
  • font size
  • font family
  • bold
  • italic
  • strike through
  • underline/overline
  • super/subscript
  • br
  • div
  • p

Copy link
Contributor Author

@folinimarc folinimarc Sep 16, 2024

Choose a reason for hiding this comment

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

Thank you both for bringing this up and the clarification! I should have seen this myself in the source code (or just stick to the scope of the change >.<). Will update the PR next week as soon as I am back at my laptop.

Copy link
Contributor

Choose a reason for hiding this comment

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

@folinimarc it might worth waiting till qgis/QGIS#58716 is merged, since that also relates


Below an example of a HTML-based expression and rendering
(applies different colors and underline to the same label):
Examples of supported HTML tags:

* Text formatting, such as italic or bold, e.g.:

.. code:: html

format(
'<span style="color:blue">%1</span> ( <span style="color:red"><u>%2 ft</u></span> )',
title( lower( "Name" ) ),
round($length)
)
<i>QGIS</i> <b>rocks!</b>

.. _figure_label_html_formatting:
* Superscript and subscript, where the text will be vertically :sup:`super` or
:sub:`sub` aligned and automatically sized to 2/3 of the parent font size.
You can also set a fixed font size for the superscript/subscript
by including css rules, e.g.:

.. figure:: img/label_HTML_formatting.png
:align: center
.. code:: html

Labeling with HTML formatting enabled
<sup style="font-size:33pt">my superscript text</sup>

Examples of supported CSS properties:

At the bottom of the tab, a widget shows a filterable list of compatible items
stored in your :ref:`style manager database <vector_style_manager>`.
This allows you to easily configure the current text format or label setting
based on an existing one, and also save a new item to the style database:
Press the :guilabel:`Save format...` or :guilabel:`Save settings...` button
and provide a name and tag(s).
* Font properties (``color``, ``font-family``, ``font-size``, ``font-weight``, ``font-style``, ``word-spacing``).
Note that ``word-spacing`` will always use unit points.
* Text decorations such as underline, overline and line-through (``text-decoration``)
* Text alignment (``vertical-align``)

.. note:: When configuring a :guilabel:`Label Settings` item, text format items
are also available in this widget. Select one to quickly overwrite the current
:ref:`textual properties <text_format>` of the label.
Likewise, you can create/overwrite a text format from there.
CSS properties can be set on HTML tags with the style attribute.
The HTML tag span does not apply any formatting to text by itself and is ideal if you just want to apply CSS styling.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
The HTML tag span does not apply any formatting to text by itself and is ideal if you just want to apply CSS styling.
The HTML tag ``span`` does not apply any formatting to text by itself and is ideal if you just want to apply CSS styling.

A CSS property name and its value are separated by a colon (``:``).
Multiple CSS properties are separated by semicolon (``;``), e.g.:

.. code:: html

<span style="text-decoration:underline;color:blue;word-spacing:20">I will be displayed as blue underlined text with increased space between words</span>

Below an example of a HTML-based expression and rendering
(applies different colors and underline to the same label):

.. code:: html

format(
'<span style="color:blue">%1</span> ( <span style="color:red"><u>%2 ft</u></span> )',
title( lower( "Name" ) ),
round($length)
)

.. _figure_label_html_formatting:

.. figure:: img/label_HTML_formatting.png
:align: center

Labeling with HTML formatting enabled

.. _labels_formatting:

Expand Down
Loading