1

I am using HTML code to buffer a label in QGIS Print Composer, as described in Question 84324.

Sadly, this code also changes the font and I can´t change it back using the font size dialog. I´m not sure what it does, it might just add serifs that I can´t remove, since the font DOES change when I use the font size dialog, but still the output font in the label looks very different from the original "MS Shell Dlg 2" font (compare labels "1 Germany" and "2 and 3 Germany"). I have tried playing around with the code to change the font but couldn´t get the effect I want.

Example of the labels

What I actually want: Label "1 Germany", but with a white buffer and in this exact font (MS Shell Dlg 2, size 24)

Code for Label "2 Germany": <p style="-webkit-text-stroke: 8px white">2 - Germany</p>

Code for Label "3 Germany": <span style="color:black;text-shadow: 0px 0px 2px #4d2d4d, 0px 5px 10px #aefe00;">3 - Germany</span>

How do I set the specific font "MS Shell Dlg 2" with a white halo?

EDIT: Final code as suggested by Thomas:

<style>body {color: 'black';font-size: 50px;}.label1 {font-family: Tahoma;-webkit-text-stroke: 8px white}</style><span class="label1">Germany</span>
4
  • I did find a good source of information on the general topic of HTML and fonts here: html.com/fonts/#Getting_Started_with_Fonts_and_Typography ... will look through that Commented Jun 18, 2020 at 22:00
  • As per the Tour there should be only one question asked per question.
    – PolyGeo
    Commented Jun 18, 2020 at 22:49
  • Does the native QGIS label halo not work in print composer? The question you linked to is years old, and I'd hope QGIS halos now work the way you need without that HTML/CSS technique. Commented Jun 19, 2020 at 8:18
  • Tom, sadly I still can´t find a halo in the print composer. That would of course be the easiest way. Commented Jun 19, 2020 at 9:02

1 Answer 1

2

You may try to add a HTML <style> block. Normally, it's only HTML with some limitations due to QtWebKit html rendering (QGIS relies on it as confirmed with this discussion http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-qgis2web-and-qtwebkit-td5378226.html#a5378445).

You can set the following in an HTML frame

<style>
body {
  color: 'black';
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}
.otherfont {
  font-family: Tahoma, Times New Roman; /*Tahoma is an alias to find font. The real name is Tahoma. See https://docs.microsoft.com/en-us/windows/win32/intl/using-ms-shell-dlg-and-ms-shell-dlg-2*/
  font-size: 18px;
  -webkit-text-shadow: 0px 0px 2px #4d2d4d, 0px 5px 10px #aefe00;
  text-shadow: 0px 0px 2px #4d2d4d, 0px 5px 10px #aefe00;
}
</style>
<h1>My other title</h1>
<h1 class="otherfont">Alternative</h1>
<br>
my latest text

The above answer was generic. More specific now. So, if you have three styles you set below code

<style>
body {
  color: 'black';
  font-size: 14px;
}
.label1 {
  font-family: Tahoma;
  /*Add the style for the white halo here*/
}
.label2 {
  color: black;text-shadow: 0px 0px 2px #4d2d4d, 0px 5px 10px #aefe00;
}

.label3 {
 -webkit-text-stroke: 8px white;
}
</style>
<span class="label1">1 - Germany</span>
<p class="label2">2 - Germany</p>
<span class="label3">3 - Germany</span>
3
  • Thanks ThomasG77, but how can I still have a white halo and set the specific font: MS Shell Dlg 2? I am unsure how to specify that. Commented Jun 19, 2020 at 9:07
  • Updated the code
    – ThomasG77
    Commented Jun 19, 2020 at 9:26
  • Thank you! That did the trick! Commented Jun 19, 2020 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.