Summary: | Request a SWT style for monospace and proportional fonts | ||||||
---|---|---|---|---|---|---|---|
Product: | [Eclipse Project] Platform | Reporter: | shmuel siegel <hard2> | ||||
Component: | SWT | Assignee: | Platform-SWT-Inbox <platform-swt-inbox> | ||||
Status: | NEW --- | QA Contact: | |||||
Severity: | enhancement | ||||||
Priority: | P3 | CC: | billy.biggs, christoph.zauner, daniel.kruegler, dh_tue, francisu, geonik, guido.schnepp, jvb, kirill.balod, klaus.ziegler, lieven.lemiengre, meetmathi, piero.campa, rfuhrer, robin, rsternberg, ruediger.herrmann, spambox, steveneo, steve_northover | ||||
Version: | 3.0 | ||||||
Target Milestone: | --- | ||||||
Hardware: | All | ||||||
OS: | All | ||||||
See Also: | https://bugs.eclipse.org/bugs/show_bug.cgi?id=568520 | ||||||
Whiteboard: | |||||||
Attachments: |
|
Description
shmuel siegel
2003-12-04 05:43:27 EST
I suggest adding methods to complement 'systemFont', shadowing the work done by the w3c to solve this problem for XML/CSS with font-families: e.g. methods getMonoFont(), getCursiveFont(), etc. see http://www.w3.org/TR/CSS1#font-family I have since discovered that awt supports this concept, as 'logical fonts'. These are the meta-names Serif, SansSerif, Monospaced, Dialog, and DialogInput which are mapped to system-dependent values. If anyone knows how to extract a physical font name from a java.awt.Font and build a org.eclipse.swt.graphics.Font from this, I'd be very grateful. A useful intermediate step. Perhaps the time has come to add Font aliases? At any rate, having a fixed width font that is available on all platforms is a useful concept (ie. Display.getSystemFixedFont() or Display.getSystemFont(SWT.FONT_FIXED)) has there been any activity for this enhancement request Font aliases are a very interesting feature to have in future releases of SWT. The monospace issue shows why they are important in cross-platform development. Sorry about that, I hit the wrong key in adding myself as a cc to the bug. Any update here? A platform-independent "monospace font" would definitely be very useful to the IMP project. Created attachment 238603 [details]
Cross platform, thread-safe, monospaced font utility class.
SWTFontUtils.java
Utility class (thread safe) that implements 'getMonospacedFont' and 'getMonospacedFont(Display)', to get a monospaced font for the current/given display.
Is platform independent. Has various hard coded fonts for operating system and windowing system combinations, as well as a default fallback. Hard coded values based on class 'org.eclipse.jface.resource.FontRegistry' and resources 'org.eclipse.jface.resource/jfacefonts*.properties' from 'org.eclipse.jface' plug-in (version 3.9.1).
Some notes:
- Caches the fonts, per display, for performance.
- Is thread safe.
- Hooks into the display dispose callback to dispose the font once the display is disposed, to avoid resource leaks.
- Coded for Java 7, but could easily be adapted to work on older versions.
- Uses org.apache.commons.lang3 (version 3.1), but it's not really essential.
- Tested with org.eclipse.swt.win32.win32.x86_64_3.102.1.v20130827-2048.jar
- Currently the hard coded fonts are hard coded in code. It might be better to use resource files as 'org.eclipse.jface' does, to allow users to override the properties, but I didn't need that.
- If included in SWT, the functionality may be better added to the Display class instead of a utility class.
Comment on attachment 238603 [details]
Cross platform, thread-safe, monospaced font utility class.
Setting mime-type to text/plain.
What about adding methods to retrieve default OS-dependent fonts, but for each family? I mean: serif, sans-serif, monospace, cursive and fantasy. (In reply to Piero Campalani from comment #10) > What about adding methods to retrieve default OS-dependent fonts, but for > each family? > > I mean: serif, sans-serif, monospace, cursive and fantasy. Can we do that? Is that sort of functionality available as a system call? If so, that would be the obvious solution. I am no longer working on SWT. Moving to INBOX so that the team can see the comments. Just for information for people who will decide to reuse "SWTFontUtils" snippet (https://bugs.eclipse.org/bugs/attachment.cgi?id=238603) Black Duck now recognize it as part of code was published in CCW project (https://github.com/ccw-ide/ccw/blob/master/ccw.core/src/java/ccw/util/SWTFontUtils.java) under EPL 1.0 |