Using system fonts on Windows (fontconfig equivalent?)

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Using system fonts on Windows (fontconfig equivalent?)

Elvis Stansvik
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using system fonts on Windows (fontconfig equivalent?)

David Lonie-2
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!

Dave

On Tue, Apr 11, 2017 at 4:45 AM, Elvis Stansvik
<[hidden email]> 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
>
_______________________________________________
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using system fonts on Windows (fontconfig equivalent?)

Elvis Stansvik
2017-04-11 18:43 GMT+02:00 David Lonie <[hidden email]>:
> 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.

Hm, alright.

QFont (as returned by QFontDatabase::system(...) etc.) unfortunately
can't give me a specific font file (it's not part of its API, QFont
should actually be thought of as query to the underlying font backend,
not a specific font file), so I don't have a file path to pass to
SetFontFile :/

Would it make sense as future improvement to add a VTK module similar
to vtkRenderingFreeTypeFontConfig, but which interfaces with the
Windows font backend?

How are people dealing with this in VTK applications today? Do they
just accept that fonts in VTK will look out of place compared to
surrounding UI elements and other programs (and not respecting the
user's font settings)? What's the situation on macOS? We're planning a
port to macOS as well, and would of course like to respect the user's
font choice there as well.

Elvis

>
> Good luck!
>
> Dave
>
> On Tue, Apr 11, 2017 at 4:45 AM, Elvis Stansvik
> <[hidden email]> 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
>>
_______________________________________________
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using system fonts on Windows (fontconfig equivalent?)

David Lonie-2
On Tue, Apr 11, 2017 at 3:54 PM, Elvis Stansvik
<[hidden email]> wrote:
> Would it make sense as future improvement to add a VTK module similar
> to vtkRenderingFreeTypeFontConfig, but which interfaces with the
> Windows font backend?

Sure, that would be useful.

> How are people dealing with this in VTK applications today? Do they
> just accept that fonts in VTK will look out of place compared to
> surrounding UI elements and other programs (and not respecting the
> user's font settings)? What's the situation on macOS? We're planning a
> port to macOS as well, and would of course like to respect the user's
> font choice there as well.

Most of the applications I'm aware of that use a consistent font
across components with VTK do so by specifying a font file explicitly
as part of their distribution, or just settle for matching
serif/sans-serif/monospace properties.

HTH,
Dave
_______________________________________________
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using system fonts on Windows (fontconfig equivalent?)

Elvis Stansvik
2017-04-11 22:00 GMT+02:00 David Lonie <[hidden email]>:

> On Tue, Apr 11, 2017 at 3:54 PM, Elvis Stansvik
> <[hidden email]> wrote:
>> Would it make sense as future improvement to add a VTK module similar
>> to vtkRenderingFreeTypeFontConfig, but which interfaces with the
>> Windows font backend?
>
> Sure, that would be useful.
>
>> How are people dealing with this in VTK applications today? Do they
>> just accept that fonts in VTK will look out of place compared to
>> surrounding UI elements and other programs (and not respecting the
>> user's font settings)? What's the situation on macOS? We're planning a
>> port to macOS as well, and would of course like to respect the user's
>> font choice there as well.
>
> Most of the applications I'm aware of that use a consistent font
> across components with VTK do so by specifying a font file explicitly
> as part of their distribution, or just settle for matching
> serif/sans-serif/monospace properties.

Alright, I guess that's what we'll do for Windows/macOS for now then,
even if the goal was to obey the user's settings and not impose a
specific shipped font. The problem is that the font we choose to ship
may not fit in well with the user's chosen font (which the surrounding
Qt GUI will respect).

Elvis

>
> HTH,
> Dave
_______________________________________________
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using system fonts on Windows (fontconfig equivalent?)

Sean McBride
In reply to this post by Elvis Stansvik
On Tue, 11 Apr 2017 21:54:20 +0200, Elvis Stansvik said:

>How are people dealing with this in VTK applications today? Do they
>just accept that fonts in VTK will look out of place compared to
>surrounding UI elements and other programs (and not respecting the
>user's font settings)? What's the situation on macOS? We're planning a
>port to macOS as well, and would of course like to respect the user's
>font choice there as well.

Elvis,

I finally recently updated our app to use the macOS system font.  I really feel it should be VTK's default behaviour, because otherwise most non-English characters are not going to render, and in this day and age, Unicode should "just work".

I guess such a change would complicate VTK's test suite, at least the tests that compare images, because the system font is often tweaked from OS release to release.

Perhaps VTK should at the very least provide an API that does the platform-specific work to return the path to the system font (for a given string at a given size).

Here's our Mac code if you want to copy it:

        vtkTextProperty* property = textActor->GetTextProperty();
        const char* fontPath = [[self fontPathForString:inString size:14] fileSystemRepresentation];
        property->SetFontFile(fontPath);

and

- (nullable NSURL*)fontPathForString:(nullable NSString*)inString
                                size:(CGFloat)inSize
{
        NSURL* fontUrl = nil;
       
        if (inString)
        {
                NSFont* startFont = [NSFont systemFontOfSize:inSize];
                CTFontRef font = CTFontCreateForString((__bridge CTFontRef)startFont,
                                                                                           (__bridge CFStringRef)inString,
                                                                                           CFRangeMake(0, [inString length]));
                if (font)
                {
                        NSFontDescriptor* fontDesc = [(__bridge NSFont*)font fontDescriptor];
                        fontUrl = [fontDesc objectForKey:(__bridge NSString*)kCTFontURLAttribute];
                       
                        CFRelease(font);
                }
        }
       
        return fontUrl;
}

Sean


_______________________________________________
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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using system fonts on Windows (fontconfig equivalent?)

Elvis Stansvik
2017-04-14 4:08 GMT+02:00 Sean McBride <[hidden email]>:

> On Tue, 11 Apr 2017 21:54:20 +0200, Elvis Stansvik said:
>
>>How are people dealing with this in VTK applications today? Do they
>>just accept that fonts in VTK will look out of place compared to
>>surrounding UI elements and other programs (and not respecting the
>>user's font settings)? What's the situation on macOS? We're planning a
>>port to macOS as well, and would of course like to respect the user's
>>font choice there as well.
>
> Elvis,
>
> I finally recently updated our app to use the macOS system font.  I really feel it should be VTK's default behaviour, because otherwise most non-English characters are not going to render, and in this day and age, Unicode should "just work".
>
> I guess such a change would complicate VTK's test suite, at least the tests that compare images, because the system font is often tweaked from OS release to release.
>
> Perhaps VTK should at the very least provide an API that does the platform-specific work to return the path to the system font (for a given string at a given size).
>
> Here's our Mac code if you want to copy it:
>
>         vtkTextProperty* property = textActor->GetTextProperty();
>         const char* fontPath = [[self fontPathForString:inString size:14] fileSystemRepresentation];
>         property->SetFontFile(fontPath);
>
> and
>
> - (nullable NSURL*)fontPathForString:(nullable NSString*)inString
>                                 size:(CGFloat)inSize
> {
>         NSURL* fontUrl = nil;
>
>         if (inString)
>         {
>                 NSFont* startFont = [NSFont systemFontOfSize:inSize];
>                 CTFontRef font = CTFontCreateForString((__bridge CTFontRef)startFont,
>                                                                                            (__bridge CFStringRef)inString,
>                                                                                            CFRangeMake(0, [inString length]));
>                 if (font)
>                 {
>                         NSFontDescriptor* fontDesc = [(__bridge NSFont*)font fontDescriptor];
>                         fontUrl = [fontDesc objectForKey:(__bridge NSString*)kCTFontURLAttribute];
>
>                         CFRelease(font);
>                 }
>         }
>
>         return fontUrl;
> }

Thanks a lot for this snippet Sean, it'll come handy when I turn my
attention to macOS.

A cross-platform helper like you mention would sure be a useful addition.

Elvis

>
> Sean
>
>
_______________________________________________
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

Loading...