QSvgGenerator how to display medium weight font via SVG file?



  • Hi there,

    does anyone know a workaround of this QSvgGenerator Qt Bug?
    https://bugreports.qt.io/browse/QTBUG-55780 (Please vote this up)

    I simply want to display a medium weight font (for example 'Roboto Medium' font) via SVG file. SVG font-weight=500 is the value for medium fonts.

    Todays Browser recognize SVG font-weight values that are full hundreds: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900.
    (For example 400=Normal, 500=Medium, 700=Bold etc.)

    Unfortunately QSvgGenerator converts QFont::Weight (0-99) values just by multiplying them by ten to get the resulting SVG font-weight values (100-900).

    Only the QFont::Weight constants: QFont::Light, QFont::Normal and QFont::Bold are not done this way. They are converted to valid values of full hundreds. For example QFont::Normal (QFont::Weight=50) is converted to SVG font-weight=400 (Normal).

    The problem is:
    QSvgGenerator converts QFont::Medium constant (Font::Weight=57) to SVG font-weight=570, which is a non valid SVG font-weight value.
    QSvgGeberator converts QFont::Weight=50 set by number to SVG font-weight=400 (Normal).

    The latter happens because QSvgGenerator converts the QFont::Normal constant (QFont::Weight=50) to SVG font-weight=400 (see example above).

    Is there any working solution to force QSvgGenerator to set the SVG property font-weight=500 for a medium font?


  • Lifetime Qt Champion

    Hi,

    Did you saw the "inline" patch proposed by the original poster ? Apply it to the QtSvg module and build it. You don't need to build the whole of Qt, just that module.



  • @SGaist
    Yes I saw the patch.

    Today I tried to build just the svg module. Never build any Qt module from source before. But although the svg module is a small package I wasn't able to build the Qt5Svg.dll which is needed for Windows. I did not setup any extra things like paths or so for the build process. Could this be the problem?

    There are more than one *.pro file in the package.

    Building qtsvg.pro in the 'qtsvg' base directory I got error messages just by opening the project file: 'Project MESSAGE: cmake executable not found. Not running CMake unit tests'.

    Building svg.pro in 'qtsvg/src' went fine. All *.obj files were sucessfully build but no Qt5Svg.dll which is needed for Windows.

    Do you know what the problem might be?


  • Lifetime Qt Champion

    qtsvg.pro is the right to open. That just a warning that you can safely ignore.



  • @SGaist
    It worked, thank you very much!!

    Build option: Shadow-Build was the problem. By default it is turned on. After deactivation of Shadow-Build the Qt5Svg.dll build just fine.


  • Lifetime Qt Champion

    Great !

    Happy coding :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.