Bug 457378

Summary: [Contributions] Provide a way to add a custom fonts to a product
Product: [Eclipse Project] Platform Reporter: Timo Kinnunen <timo.kinnunen>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3    
Version: 4.5   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Timo Kinnunen CLA 2015-01-13 16:24:27 EST
SWT provides a loadFont-method in Display, but as far as I can see no code in Eclipse calls it. Platform should provide some extension point from which custom fonts could be added to be distributed with Eclipse based products. These fonts would then be available for use in editors, styling from CSS and so on.
Comment 1 Timo Kinnunen CLA 2015-01-21 06:40:09 EST
As a proof of concept, I added a property to product definition which looks like this:

<property
		name="fontList"
		value="SourceCodePro-Black.ttf,SourceCodePro-Bold.ttf,SourceCodePro-ExtraLight.ttf,SourceCodePro-Light.ttf,SourceCodePro-Medium.ttf,SourceCodePro-Regular.ttf,SourceCodePro-Semibold.ttf"/>

And then I added this code to o.e.ui.internal.Workbench before the code that runs the legacy workbench:

					// add custom fonts before running workbench
					String fontList = Platform.getProduct().getProperty("fontList");
					if(fontList != null) {
						String[] fonts = fontList.split(",");
						Bundle bundle = Platform.getProduct().getDefiningBundle();
						if(bundle != null) {
							String location = bundle.getLocation().replace("reference:file:", "");
							for(String font : fonts) {
								String file = Paths.get(location, font).toAbsolutePath().toString();
								display.loadFont(file);
							}
						}
					}

And this works for me on Windows 8. 

I figure the custom fonts need to be loaded pretty early in the startup process before the splash screen gets displayed so an extension point may not be suitable.