[vtkusers] Using fontconfig with vtkTextMapper/vtkTextProperty?

Elvis Stansvik elvis.stansvik at orexplore.com
Thu Oct 20 11:27:17 EDT 2016


2016-10-20 16:55 GMT+02:00 David Lonie <david.lonie at kitware.com>:
> On Thu, Oct 20, 2016 at 10:48 AM, Elvis Stansvik
> <elvis.stansvik at orexplore.com> wrote:
>>
>> 2016-10-20 16:41 GMT+02:00 David Lonie <david.lonie at kitware.com>:
>> > Correct -- Set ForceCompiledFonts off on vtkFreeTypeTools, and set the
>> > name
>> > of the font using vtkTextProperty::SetFontFamilyAsString.
>> >
>> > As you discovered, this requires the RenderingFreeTypeFontConfig module
>> > to
>> > be enabled and linked to the final application. There is an example
>> > usage in
>> > Rendering/FreeTypeFontConfig/Testing/Cxx/TestSystemFontRendering.cxx if
>> > you
>> > get stuck.
>> >
>> > Let us know if you have further issues, AFAIK this functionality is not
>> > widely used.
>>
>> Yep, it now seems to work. E.g. I can now do:
>>
>>     textProperty->SetFontSize(10);
>>     textProperty->SetFontFamilyAsString("Noto Sans");
>>
>> However, one thing puzzles me: The font is much smaller than what I
>> would have expected. I set it to 10 points here, but the result is
>> much smaller (see attached screenshot).
>>
>> My goal is to use
>> QFontDatabase::systemFont(QFontDatabase::GeneralFont) to get the
>> system font through Qt, and use its values for .fontSize() and
>> .family() when constructing my vtkTextProperty, to make the font in
>> VTK match my system font.
>>
>> Any idea why the text is rendered so small? The vtkTextProperty is set
>> on a vtkTextMapper which in turn is set on a vtkActor2D.
>
>
> It's hard to say. How does it compare to a VTK built-in font of the same
> size? The glyph sizes are set by the freetype library, VTK doesn't have much
> control over this. It just asks the library for glyphs of a certain
> size/family and draws them into a texture. You may need to set a scaling
> factor during the conversion if something seems iffy.

Using built-in fonts I also get text rendered smaller than expected.

However, I think it's a matter of DPI. I guess VTK assumes a DPI of 72
somewhere?

With the following, the text is rendered in the expected size:

    auto logicalDpiY = QApplication::screens().at(0)->logicalDotsPerInchY();
    ...
    textProperty->SetFontSize(qRound(10 * (logicalDpiY / 72.0)));
    textProperty->SetFontFamilyAsString("Noto Sans");

So I'm compensating for VTK's assumption about 72 DPI by increasing
the font size (on my system Qt's logicalDotsPerInchY() reports
96.2526).

I guess I should also figure out how to be notified when the widget is
moved to another screen and update the size, since the DPI of the
other screen might be different.

Elvis

>
> Dave


More information about the vtkusers mailing list