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

Sean McBride sean at rogue-research.com
Thu Apr 13 22:08:38 EDT 2017


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




More information about the vtk-developers mailing list