Using custom fonts in Swing application - configuration

I have two specific fonts installed on my computer and would like to configure the JRE to make them
available to my application, specifically Calibri and Cambria Math. However, I understand the basics of how default fonts work in Java; how the JRE reads a properties file that sets the default fonts for any Java application running on top of it.
However, these two fonts are not available in any of the properties files that I can find. So:
(1) Is it possible to "add" these two new fonts to the JRE's config, so that in my program I can call myJButton.setFont(myCambriaMathFont) on a component and make use of these added fonts? If so, how? If not, then:
(2) Are there any libraries/JARs out there for matching font names/font families to the fonts available via the JRE, and matching them as close as possible, algorithmically?
C'mon, I know you'd all love to see what a JList looks like....on Wingdings!!!
Thanks and sorry for this quirky question.

Would you like to load the font at runtime?
See Font.createFont(...)

Related

Building font-awesome icons

I would build my own font-awesome icons set. In particular I would build something which is a copy of font-awesome with all its features, but using just a subset of icons.
Furthermore, I'm really interested how they build files within the fonts folders.
On github I found this repo, which contains all svg icons. On ubuntu, using Font Custom, I was able to generate giving svg files as input, the fonts file, even if I'm not really satisfied. But besides that, I do not understand how to merge those files with font-awesome.
So summarizing, how can I create my own font-awesome set, using my own svg files?
Please, do not say to use fontello, icoMoon or similars, because I would like to do on my local machine, without any third-parties services.
I actually did something similar but have to admit it was never perfect, most likely due to bad font conversion, just never had time to make it perfect. Basically i used the following link (to the most part)
http://www.webdesignerdepot.com/2012/01/how-to-make-your-own-icon-webfont/
An overview of the process
Step 1 - Create the individual gylphs (you should use the special characters to avoid someone "typing" using your font.
Step 2 - Save gylphs selection as an SVG font.
Step 3 - Convert SVG font to web-font (there are plenty of free online converters)
step 4 - generate the CSS classes to use (create all of the possible classes for all individual glyphs) - outcome should be something like: "icon icon-lg icon-blue icon-hand" - (better using LESS / SCSS for this part - you'll get why later)
where one contains the general settings for all icons, the other controls size-overrides, one controls the color, and most important one that using the :after -> outputs the icon.
step 5 - now that you have a working web-font controlled by CSS, make a UI for selecting individual glyphs to be available. most likely you should use LESS, this way you are "exposing" only the classes that are selected by the user (EG. - icon-1, 2, 5, 8 etc) all other icons are still included in the font but their corresponding CSS classes are not outputted in the final CSS.
There might be more advanced ways of doing it but this overview and tutorial should help you get the basics.
I believe you can use FontLab Studio for that: http://store.fontlab.com/
However, you will probably have to write your own css, personally I think generating it with icomoon or similiar web based generator is much easier and faster, because it is made particularly for generating web fonts, in before FontLab Studio or similiar desktop applications were made to design desktop fonts and do not come with prebuilt css compiler/generator.
I would like to see a generator for desktop aswell.
I haven't dug deeply with own font-icon sets, but I assume there's some svg data in use.
Just as an idea of a different way to go- you could even use background-img on set classes :before / :after
useful resource: http://iconizr.com/ I find their data-url generation is useful (better svg conversion than fontello, icoMoon )

netbeans on ubuntu font look and feel

is there any chance to make the font in Netbeans 7.3 under ubuntu 12 to look better???
take a look on how the same code looks in eclipse and netbeans
while both IDEs configured with the same editor fonts settings (monospaced), i tried with other fonts also. it seams like netbeans rendering the fonts completely in a different way, the font is much more thinner ? why is it happening ?
i read a lot about that issue and already added the following to the netbeans.conf file
-J-Dapple.awt.graphics.UseQuartz=false
-J-Dswing.aatext=true
-J-Dawt.useSystemAAFontSettings=lcd
it fixed a little, but still it is a big difference between the both,
did anyone found a proper solution for that problem or maybe one can state here that there is no solution at all ??? i am a new Netbeans user and love this IDE but this thing is driving me crazy ;((
will thank a lot !
The fonts will look different regardless of the changes you make, as Eclipse is based upon SWT, and NetBeans on Swing; the two UI tool kits use different font rendering engines.
Some fonts look better than others in Swing. My preference in Swing (and nearly everywhere I use mono-spaced fonts, really) is Ubuntu Mono, but both Deja Vu Sans Mono and Source Code Pro render well in Swing, as well.
You almost certainly have the first two on your system already, and the third is easy enough to install, should you wish. I will say that the line pitch of Source Code Pro is way to large for my taste, though it is otherwise a nice font.
After enabling the JRE flags you mention, and choosing an appropriate font, the next vital item is to choose the best font size. A given font in a given rendering engine may look better or worse at a given size than in a different environment.
I find that, in Swing, Deja Vu Sans Mono looks better in even point sizes, so I typically use it at either 10pt or 12pt in NetBeans. Ubuntu Mono, on the other hand, renders much nicer at odd sizes, so I typically use it at either 11pt or 13pt in NetBeans.
Font rendering is different because they use different UI libraries.
Netbeans uses swing.
Eclipse uses swt.
You can patch the jdk to get swing to respect your font rendering settings:
https://gist.github.com/aleksandara/2963640
PPA for ubuntu with patch applied:
https://launchpad.net/~no1wantdthisname/+archive/openjdk-fontfix

Loading and unloading fonts for multilingual Flex app

My Flex app allows people to enter text. There's a broad selection of fonts to choose from. Because it is a multi-lingual app, some of those fonts (e.g. Chinese) are very large indeed - too big to embed all fonts.
I know that I can load fonts at runtime via stylesheets - I plan to do this as people select a font (a small wait while the font loads is not a problem). What I want to be able to do is to unload those fonts again, so that the app doesn't consume huge amount of memory if people select one font and then another.
I can't see a way to do it, though. I can load fonts at runtime, but not unload them. Any ideas?
I did see this question on SO that mentions loading fonts as part of a module - with one font per module, I guess. The advantage being that modules can be unloaded. But then, the font isn't accessible outside the module, as the questioner points out. So that seems like a dead end.
If it's not possible, I will - sadly - accept an answer that shows me that it's impossible, but much more useful would be an alternative strategy! This must be a pretty common scenario that people have run into before...
As your intuition suggests, this is a relatively common scenario for flex developers - there's got to be a solution!
As you have suggested, I would compile the stylesheets as modules with the fonts embedded in each (for Chinese, I suggest you look at specifying unicode ranges if possible to save on font size: http://renaun.com/blog/2011/10/flash-embed-font-unicode-range-generator/).
There are 3 application domains you can load modules into a parent app. Take a look at this: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e07.html. I believe 2 out of the 3 ways allows you to use resources from the module. The easiest is to load it with the same application domain - meaning you assume the classes in the module are the same as the parent's.
Make sure your build system is compiling the modules with the same version of the sdk as the parent application. Otherwise, you will run into actionscript runtime errors with marshalling classes.
Finally, how are you profiling your application for garbage collection? Are you using the flash builder's built-in profiler? Forcing garbage collection on a flex app is annoying (from what I remember, you must call System.gc() twice or some weird voodoo magic like that).
Here are some useful links:
http://livedocs.adobe.com/flex/3/html/help.html?content=fonts_04.html (esp. see the section beginning "Embedding fonts in ActionScript")
http://divillysausages.com/blog/as3_font_embedding_masterclass
http://bryanlangdon.com/blog/2007/03/22/loading-fonts-dynamically-in-actionscript-2-and-3/
You can embed the fonts externally in SWF files (one per font), load them up as needed, and use the same value as SWF Embed's "fontName" for CSS's "fontFamily".
When the user is done, and you've cleared all references to the font, you can unload the SWF (Loader.unloadAndStop()) and set it to null. I would think this would prompt it for garbage collection and free up the memory.
I think this is your best bet, because for a font to be used it must be registered, no matter how you got it to that point. And there is no Font.unregisterFont() method. This solution at least lets you free up everything up to that point.
Though I'm curious if Font.enumerateFonts() would still list the font and if it is really freed for garbage collection...
I haven't got too deep into it, but I too think it's not possible to unload a registered font.
I can only think of two probably unfeasible workarounds:
Come up with an elaborate and reliable way to use device fonts. I
guess it would imply quite an extensive investigation about fonts
available/required in different systems and countries, but if you're
not using the font for very graphical things, I think it could be
pulled off.
Reload the whole movie when you change the font. This
obviously depends heavily in what's your application like, but maybe
you could save the app state and reload it through javascript, or
maybe even have a separate overlaid swf that you load on demand
(maybe the latter could work loading the swf in a separate
application/security domain, but I'm not sure the registered fonts
would be sandboxed correctly).
Anyway, I guess it being a Flex app would complicate things quite a bit and render anything outside the box useless...

How do I make a custom Flash component work with any font?

So we have a component we have written ourselves that deals with text display and translation between languages, reading translations from a file. Ideally what we would like to do is have this component be compatible with any font we can embed in the main .swf's library. What's the best way to do that?
Currently we are going down the route of having our component have an attribute for the font name, lets say 'Font1'. We drag the component into the .FLA file we want and then add a new font to the library called 'Font1' and set it to the typeface we want. This is proving to be inconsistent and problematic which implies it's not really an ideal way of doing it.
Is there anyway to achieve the feature we want? The key is flexibility, we want to easily support languages (hence the component) but we don't want design to be limited in their font selection. Its not practical to embed a range of fonts in the component for example, as it adds to file size and is restrictive.
Any ideas or solutions to this much appreciated. The component is written in AS3 and we are using Flash CS4.
Look into Runtime font loading or runtime font embedding.
There are many ways to deal with this depending on your development environment. In that regard, FlashBuilder may offer you more flexibility than Flash CS4 actually.
A general approach could be to have a set of SWFs file, each embedded with a particular font. Of course, these SWFs shouldn't be loaded at start up.
When calling a font in your component, you would practically call a function that would load the corresponding SWF, adding the font to your Application Domain, therefore making it available to your component.
Here's an article that may help in clarifying the process
http://nochump.com/blog/archives/20
but a Google search such as Runtime font loading or embedding should bring out a lot more resources.
Hope this helps!

Phpstorm Editor fonts on linux systems

So tired to search solution..
I use PHPStorm IDE for my php projects and one trouble just makes me crazy.
Editor fonts (editor, don't care about interface) looks horrible. I've tried on different distributions and different DE but result is always the same :(
There are screenshots to compare Kate and PHPStorm fonts. I know that PHPStorm is an JAVA application and it uses different font hitting engine, but.. Eclipse is an JAVA app too, but has pretty nice fonts.
PHPStorm fonts on both Windows and OSX looks like other system fonts. Smooth and readable.
Is there way to fix this font issue before my eyes will explode..?
Thanks.
Following the PhpStorm issue, here is what I added to phpstorm64.vmoptions (that I have installed in /usr/local/bin/PhpStorm/bin/):
-Dswing.aatext=true
-Dawt.useSystemAAFontSettings=gasp
-Dsun.java2d.xrender=true
I also did the trick of opening the font in FontForge:
Ctrl+A (select all chars)
Hints -> Clear Hints
Hints -> Clear Instructions
File -> Generate Font
I put it in ~/fonts/
I am running Ubuntu 12.10 and after all that, everything looks quite great (I did it for Ubuntu Mono).
The only problem I noticed is that -Dawt.useSystemAAFontSettings=gasp leads to great editor font rendering, but poor rendering for menus and other stuffs. Whereas -Dawt.useSystemAAFontSettings=lcd gives awesome font rendering for menus, but less good font rendering in the editor. So try both and pick the one you prefer.
Update: on Ubuntu 13.10, I have no problem anymore.
This is Linux specific issue, you can find a lot of information on this problem here. Check the comments for various suggestions and workarounds.
Here is what you can get with just a different font:
You can install infinality patches and patch OpenJDK to make it use freetype for fonts rendering.
Here are links about installing infinality and patched OpenJDK for Ubuntu-based distributions:
http://www.webupd8.org/2013/06/better-font-rendering-in-linux-with.html
http://www.webupd8.org/2013/06/install-openjdk-patched-with-font-fixes.html
And here is my screenshot of PHPStorm running on Fedora 20 with infinality and patched OpenJDK:
Try adding -Dawt.useSystemAAFontSettings=lcd to bin/phpstorm.vmoptions
Try Settings -> Editor -> Appearance -> Use anti-aliased font
The best solution I've found is to use FontForge.
FontForge it's a linux application which allows you to edit some font preferences.
Just open ttf font within app.
Press ctrl+a to select all chars. Then choose from menu Hints -> Clear Hints. Then Hints -> Clear Instructions. And last File -> Generate Fonts. Just save the new font as new or replace existing and try to use this font with PhpStorm. Looks not ideal but much better than before.
Also I've noticed that fonts on a dark background looks pretty good in Linux
Comparing NetBeans and PhpStorm side by side on my Debian-Squeeze box and I found NetBeans looked much better even when the same font and font-size was selected. The difference was that PhpStorm had bolded most of the code. After going through the editor configuration and getting rid of all the bolding the editor looks much better now.
Monospaced with anti-aliasing looks good to me for WebStorm.