We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › WinXP Fonts problem - standalone app
Page Index Toggle Pages: 1
WinXP Fonts problem - standalone app (Read 711 times)
WinXP Fonts problem - standalone app
Jun 11th, 2008, 2:23am
 
Hello,

I'm a Java programmer, and am using the Processing.org code outside of an applet. (We're generating PNG graphs based on dynamic data, and applets are really not an option.)

It all works fine, except for the fonts, which show up as blocks. The same code, run as an applet shows the same fonts correctly.

Here's the snippet
Code:


graphics = new PGraphics2D(273, 80, null);
graphics.beginDraw();
graphics.hint(PConstants.ENABLE_NATIVE_FONTS);
graphics.background(255);
graphics.noStroke();
graphics.smooth();
...
//I'm Inheriting from PApplet to use the loadFont method
PFont mon10 = loadFont("c:/Monaco-10.vlw");
graphics.textFont(mon10);
graphics.text("Home", xOffset, yOffset);



I'm also drawing a couple of rectangles, which turn out just fine.

Any hints/suggestions? I'd appreciate it greatly.

I'd hate to have to convert to pure java AWT just to get the fonts right.


Thanks

Re: WinXP Fonts problem - standalone app
Reply #1 - Jun 11th, 2008, 2:33am
 
Well, guess what. Found the solution minutes after posting.
Here's the code in case any one else wants to create in memory PNGs, especially on the server side for embedding inside web-pages.

Code:

graphics = new PGraphics2D(273, 80, null);
graphics.beginDraw();
graphics.hint(PConstants.ENABLE_NATIVE_FONTS);
graphics.background(255);
graphics.noStroke();
graphics.textMode(PConstants.SCREEN);
graphics.smooth();

//Then do all your display processing. Do not change the
//text mode again.


If you want to eliminate dependence on PApplet for the font loading, copy the loadFont() method into your class.

Cheers and thanks for a very sharp library - sharper than JFreechart!
Re: WinXP Fonts problem - standalone app
Reply #2 - Jun 11th, 2008, 3:29am
 
actually, PGraphics2D is not finished, so I'm surprised it's working at all for you.. use PGraphics3D or PGraphicsJava2D for better results (at least until later this summer when it's finished up).

also, you can avoid the ENABLE_NATIVE_FONTS by using the createFont() method to create the font dynamically.
Page Index Toggle Pages: 1