[vtk-developers] Using system fonts on Windows (fontconfig equivalent?)

Elvis Stansvik elvis.stansvik at orexplore.com
Thu Aug 23 11:36:46 EDT 2018


2017-04-11 18:43 GMT+02:00 David Lonie <david.lonie at kitware.com>:
> AFAIK, the only option on windows would be to load the font file
> directly using vtkTextProperty::SetFontFamily(VTK_FONT_FILE) and
> vtkTextProperty::SetFontFile(...). I've never heard of FontConfig
> being used on Windows, but I haven't really looked into it, either.
>
> Good luck!

Just to report back on this old post of mine. I've just built VTK with
the vtkRendereringFreeTypeFontConfig module activated on Windows.

I used the pre-built fontconfig binaries available at
https://github.com/ShiftMediaProject/fontconfig

There was one gotcha regarding updating a vtkTextProperty to match
that of a QFont (such as returned by e.g.
QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)).

The gotcha is that QFont::family() may return a "logical" font family
name such as "MS Shell Dlg 2", which needs to be mapped through the
font substitution mapping in the Windows registry in order to get a
"physical" font family name (such as "Tahoma") that can be passed to
vtkTextProperty::SetFontFamilyAsString(..).

Example shown below.

Hope this might help someone else.

Elvis

namespace FontUtils {

const static QString WindowsFontSubstitutesKey
    = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows
NT\\CurrentVersion\\FontSubstitutes";

void updateFromQFont(vtkTextProperty *property, const QFont &font)
{
    auto family = font.family();

#if defined(Q_OS_WIN)
    // On Windows, since the QFont::family() may be a "logical font"
    // like "MS Shell Dlg 2", we can't use it directly as parameter to
    // vtkTextProperty::SetFontFamilyAsString(..), but must map it
    // through the font substitutions in the Windows registry to
    // get the real font family (e.g. "Tahoma").
    QSettings map(WindowsFontSubstitutesKey, QSettings::NativeFormat);
    family = map.value(family, family).toString();
#endif

    property->SetFontFamilyAsString(family.toLocal8Bit());
    property->SetFontSize(font.pointSize());
    property->SetBold(font.bold());
    property->SetItalic(font.italic());
}


>
> Dave
>
> On Tue, Apr 11, 2017 at 4:45 AM, Elvis Stansvik
> <elvis.stansvik at orexplore.com> wrote:
>> Hi all,
>>
>> Cross-posting since I'm not sure if vtkusers@ or vtk-developers@ is
>> most appropriate for this.
>>
>> On Linux, I'm using the vtkRendereringFreeTypeFontConfig module, so
>> that I can use system fonts (e.g. for charts labels et.c). The goal is
>> to make VTK fonts match those used by Qt, so I'm using
>> QFontDatabase::system(...) to query for the user's preferred font, and
>> then use that in my VTK code. This is all working quite well.
>>
>> I'm now porting the application to Windows. Does VTK have any support
>> for loading system fonts on Windows? Something similar to the
>> vtkRendereringFreeTypeFontConfig, but for whatever font backend
>> Windows uses?
>>
>> If not, has anyone had luck in building fontconfig for Windows, and
>> using the vtkRendereringFreeTypeFontConfig module there? (I'm not even
>> sure if fontconfig has support for hooking into Windows' font backend,
>> so this may not be a solution at all).
>>
>> Many thanks in advance,
>> Elvis
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Search the list archives at: http://markmail.org/search/?q=vtk-developers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtk-developers
>>


More information about the vtk-developers mailing list