[Qgis-developer] Adding blending modes for labels, to have 'transparenting' labels?

Richard Duivenvoorde rdmailings at duif.net
Sat Oct 1 02:48:21 PDT 2016


Hi All,

I've been contacted by a cartophil (no offence Jan ;-)), which sent me
the two attached images, and asked me if the labelbuffers you see there
could be done with QGIS...

To precize:

If you look in lblbuf1.png [0] (Dutch kadastral 1:10000 map) it looks
like the label 'Arnhemse Broek' is normally buffered on first side. But
better looking into it, it looks like it is ONLY ('transparently')
buffered the complement(?) color of the buffer.
So: text = black, so there is only a complement(?) of black == white
buffer, IF the buffer(!) is covering a pixel which has the same color as
the text (black in this case).
For example: looking at the top of the A in 'Arnhemse Broek' you see
that red is actually NOT having a buffer, but the little black casing of
the red, DOES have a buffer..

In lblbuf2.png (swiss topo map) if you look at the height-line/contour
labels, you see exactly the same: there is a buffer, but only if it is
over a line with the same color...

Tried some label settings in QGIS with lblbuf3.png as nearest result...
Taking blue as labeltext, yellow (complement) as buffer color, and
Addition as blending.

But as you see there the blending takes ALL colors into account, so you
have a slight buffering everywhere, and yellow artifacts in the red
pixels....

So diving into the code:

Blending mode is here:

https://github.com/qgis/QGIS/blob/master/src/core/qgspallabeling.cpp#L1009

Going to renderer:

https://github.com/qgis/QGIS/blob/master/src/core/qgspainting.cpp#L6

Going to pretty low level qpainter behaviour:

http://doc.qt.io/qt-5/qpainter.html#setCompositionMode

http://doc.qt.io/qt-5/qpainter.html#CompositionMode-enum

It looks like there are even more modes then are available in the
Blending dropdown in QGIS.

I'm not so much into color theories, but is it possible that the use
case above is one of the composition modes which just is not in QGIS
blending mode dropdown yet?

And if so: which one do you think? I can try to add it myself.

OR is the usecase a custom blending mode (we are wondering then how the
dutch cadastre and the swiss topo are doing this... because it is NOT
part of esri apparently too....).

Thanks for any pointers.

Regards,

Richard Duivenvoorde

[0]
http://storage3.static.itmages.com/i/16/1001/h_1475315030_8477266_8bd662bb47.png
[1]
http://storage7.static.itmages.com/i/16/1001/h_1475315072_4576698_eaebba1bb0.png
[2]
http://storage1.static.itmages.com/i/16/1001/h_1475315103_2918295_e2b5874a36.png



More information about the Qgis-developer mailing list