Bug 457378 - [Contributions] Provide a way to add a custom fonts to a product
Summary: [Contributions] Provide a way to add a custom fonts to a product
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-13 16:24 EST by Timo Kinnunen CLA
Modified: 2015-01-21 06:40 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.