[vtkusers] Using fontconfig with vtkTextMapper/vtkTextProperty?

Elvis Stansvik elvis.stansvik at orexplore.com
Thu Oct 20 10:52:10 EDT 2016


2016-10-20 16:48 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:
> 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.

I'm attaching another screenshot where some Qt window is visible, for
comparison.

I would have expected the VTK text size (in the background) to match the Qt one.

Elvis

>
> Thanks in advance,
> Elvis
>
>>
>> HTH,
>> Dave
>>
>> On Thu, Oct 20, 2016 at 9:34 AM, Elvis Stansvik
>> <elvis.stansvik at orexplore.com> wrote:
>>>
>>> 2016-10-20 14:49 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:
>>> > 2016-10-20 14:48 GMT+02:00 Elvis Stansvik
>>> > <elvis.stansvik at orexplore.com>:
>>> >> 2016-10-20 14:06 GMT+02:00 Elvis Stansvik
>>> >> <elvis.stansvik at orexplore.com>:
>>> >>> Hi,
>>> >>>
>>> >>> How can I load a system font through fontconfig and use it with
>>> >>> vtkTextMapper/vtkTextProperty?
>>> >>>
>>> >>> I've called vtkFreeTypeTools::GetInstance()->ForceCompiledFontsOff(),
>>> >>> but I can't find any API on vtkTextProperty to set a font family to
>>> >>> use for a fontconfig-based search.
>>> >>
>>> >> Am I supposed to pass the fontconfig family name (e.g. "Noto Sans") to
>>> >> vtkTextProperty::SetFontFamilyAsString(..) ? I tried it but it didn't
>>> >> seem to have any effect.
>>> >>
>>> >> In fact, I just had a look at the build log for the Debian package I
>>> >> built of 7.1.0.rc1, and it's not mentioning "FontConfig" at all (see
>>> >> attached log). Does that mean my build doesn't have fontconfig
>>> >
>>> > Sorry, forgot the attachment, here it is in case it's too big to be
>>> > attached:
>>> >
>>> >
>>> > https://dl.dropboxusercontent.com/u/22350696/vtk7_7.1.0~rc1-0ubuntu1_amd64.build.bz2
>>> >
>>> > Elvis
>>>
>>> Sorry for the noise. Just adding
>>> -DModule_vtkRenderingFreeTypeFontConfig=ON to my build and
>>> libfontconfig1-dev to the build dependencies, and I get
>>>
>>>     --  * vtkRenderingFreeTypeFontConfig, requested by
>>> Module_vtkRenderingFreeTypeFontConfig.
>>>
>>> in the VTK CMake output. Building now and will report back how it went.
>>>
>>> Still interested in if vtkTextProperty::SetFontFamilyAsString(..) is
>>> the right API to set the fontconfig family name.
>>>
>>> Elvis
>>>
>>> >
>>> >> support? Must I enable the FreeTypeFontConfig module explicitly? (not
>>> >> enough that fontconfig is found on the system?).
>>> >>
>>> >> Elvis
>>> >>
>>> >>>
>>> >>> Elvis
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the VTK FAQ at:
>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>
>>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: comparison_to_qt_font.png
Type: image/png
Size: 53630 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20161020/3d977268/attachment.png>


More information about the vtkusers mailing list