Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Fonts  (Read 1223 times)
0 Members and 1 Guest are viewing this topic.
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Posted 2003-12-07 21:06:59 »

Is it possible to use the methods that are in the rather important FontMetrics class without having a Graphics available? Is the nearest possible way of achieving this to create a headless-device and get a dummy Graphics from it?

Mostly, I'm interested in fixing the "feature" of various swing classes (like JTree) that practically ignore things like "setRowHeight". However, there are so very very very many occasions when I need to fit text to an area that I'd like to make a generic class for it (I wish it were in the java.awt.* - if I'm missing something, please let me know! I've looked and looked and never found Sad ).

Dynamic font-resizing can be extremely slow (especially on linux - big one-time penalty to get some font-cache somewhere filled) but you can get decent performance with standard tricks, like exponential "homing-in" on an approximately correct answer, erring on the side of being too small.

malloc will be first against the wall when the revolution comes...
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #1 - Posted 2003-12-07 22:21:22 »

...and I have the age-old stupid stupid stupid problem with Swing that it's impossible to setSize() etc my components until they have a Graphics, but by the time I'm allowed access to a Graphics its too late to setSize() my components (unless I put in apparently nonsensical code (think of the poor guy who has to try and maintain my code!) just to relayout the Swing hierarchy on the first time a call is made to the paintComponent method with a non-null Graphics which ALSO has a width and height greater than 0 because Sun's JDK likes to pass in a fake Graphics every now and then with 0 dimensions but otherwise apparently valid).

Phew! Just like the "good ole days" of AWT, where almost everything is broken and you have to override every method you can just to get the darned windowing system to work how it should have done in the first place if they'd thought about what they were doing more!

(apologies for ranting; anyone else trying to work with Fonts in a similar way is bound to have these problems too and I'd like to spare them the weeks of frustration that it takes to discover all this through trial and error Sad ).

malloc will be first against the wall when the revolution comes...
Online princec

JGO Kernel


Medals: 343
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2003-12-07 23:50:41 »

I just created myself a BufferedImage of 1x1 pixel and got its Graphics2D and then keep it hanging around as long as I like. I create the FontRenderContext on it too and set antialiasing on. Didn't seem to hurt. (Of course, all I do with it is blit the whole font out and steal all the glyph metrics ahead of time)

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #3 - Posted 2003-12-08 00:46:49 »

....which AFAICS is just about the same as using a headless's Graphics, but less hassle but less elegant Smiley ?

FWIW, FontRenderContext doesn't work on Linux without a Graphics to come from (although this may be my fault). The docs imply that it SHOULD work, but that it will be "inaccurate" because e.g. fractional font metrics calcs will be slightly inaccurate.

In practice, it seems to just arbitrarily returns "1" for the width of all text, and other brain-dead stuff.

I've not tried very hard to get it to work, since it's giving me deja-vu of trying to create Image's without any GUI code in 1.1.x - when I finally achieved success, I just crashed the VM every time, because without a GUI there's no native callback for preparing valid mem etc, IIRC. Had to wait rather a lot of years for the headless displays instead Smiley.

malloc will be first against the wall when the revolution comes...
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #4 - Posted 2003-12-08 00:51:34 »

Quote
....which AFAICS is just about the same as using a headless's Graphics, but less hassle but less elegant Smiley ?


...but works, so thanks anyway Smiley.

malloc will be first against the wall when the revolution comes...
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (12 views)
2014-07-29 18:09:19

Riven (8 views)
2014-07-29 18:08:52

Dwinin (9 views)
2014-07-29 10:59:34

E.R. Fleming (25 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!