Torvald Torvald - 1 year ago 247
C++ Question

Formated outline text on QImage

How to draw outline text on

QImage
with word wrap, alignment etc.?

I tried
QPainterPath::addText()
method, but it does not support word wrap and alignment.

This is how I draw text now:

path.addText(rect.bottomLeft(), font, text);
p.strokePath(path, pen);
p.drawText(rect, flag, text);


where


  • p
    -
    QPainter

  • rect
    - rectangle that contains the text

  • flag
    -
    Qt::AlignRight
    ,
    Qt::TextWordWrap



but it looks like this


Answer Source

I found this solution: I draw the text in the buffer (using QPainter.drawText), calculate the SDF, and make outline.

https://en.wikipedia.org/wiki/Signed_distance_function

https://blog.mapbox.com/drawing-text-with-signed-distance-fields-in-mapbox-gl-b0933af6f817

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download