-
-
Notifications
You must be signed in to change notification settings - Fork 693
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
folinimarc
wants to merge
8
commits into
qgis:master
Choose a base branch
from
folinimarc:support_word_spacing_in_html
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
181f8c3
Restructure html label section and add word-spacing
folinimarc 0f86743
Harmonize css properties
folinimarc d3568b6
Remove trailing dot in list
folinimarc 86a2e7e
Fix typo
folinimarc 9f04418
Include review feedback
folinimarc a2368de
Merge branch 'master' of https://github.com/qgis/QGIS-Documentation i…
folinimarc af661c8
Qt docs reference to supported subset of html and css
folinimarc 99e7106
Streamline structure of html and css section and add little more exam…
folinimarc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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>`_. | ||||||
|
||||||
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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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: | ||||||
|
||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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