Non-applet Pixel to cm/inch conversion

Hi,

I'm stuck with my java web application where I need to determine the number of character and line of text which can be fitted into a specific size of text area. For example, in a text area of 2inch * 8 inch, how many character of Arial font 12 can be fitted per row? And how many row can the text area fit? To make the situation more complicated, the requirement also allow each line to have different font type and also different font size.

I know Java AWT can convert pixel to cm/inch, but I don't want an applet in my web application as applet will take times to load. Any Java developer out there can help me out?

[643 byte] By [iNSTiNCTza] at [2007-11-27 11:26:57]
# 1

there are just so many things wrong with that question.

"linguo is dead."

TuringPesta at 2007-7-29 16:13:29 > top of Java-index,Java Essentials,Java Programming...
# 2

Can you throw in some light? thanks in advance

iNSTiNCTza at 2007-7-29 16:13:29 > top of Java-index,Java Essentials,Java Programming...
# 3

> I'm stuck with my java web application where I need

> to determine the number of character and line of text

> which can be fitted into a specific size of text

> area. For example, in a text area of 2inch * 8 inch,

> how many character of Arial font 12 can be fitted per

> row?

It's not "12 pixels" but "12 (DTP) points". 1 DTP point is 0,3527 mm. You also need to consider spacing (A and C spaces?) and margins.

> And how many row can the text area fit?

Depends on the row height.

> To make

> the situation more complicated, the requirement also

> allow each line to have different font type and also

> different font size.

Well, you'll have to add then. But how are you going to calculate a number of characters if you don't even know which font size they have?

CeciNEstPasUnProgrammeura at 2007-7-29 16:13:29 > top of Java-index,Java Essentials,Java Programming...
# 4

> Can you throw in some light? thanks in advance

throw new Light();

cotton.ma at 2007-7-29 16:13:29 > top of Java-index,Java Essentials,Java Programming...
# 5

Although the sizes of text areas are measured in pixels. So you have to convert from pixels to centimetres, wich won't be easy without knowing the user's monitor size and resolution - maybe some website scripting can provide that info as an argument to your service.

> I know Java AWT can convert pixel to cm/inch, but I don't want an

> applet in my web application

I think you shouldn't even be writing a web app, if you don't know wthat you can call AWT classes without actually having a GUI, and aren't are that your server won't be doing anything on the client side anyway - even if the server used an applet, why should it have any relevance to the user and have long loading times?

CeciNEstPasUnProgrammeura at 2007-7-29 16:13:29 > top of Java-index,Java Essentials,Java Programming...
# 6

Oh, and FontMetrics can even tell you the length of a given String for a given font in pixels, if that's of any interest to you.

CeciNEstPasUnProgrammeura at 2007-7-29 16:13:29 > top of Java-index,Java Essentials,Java Programming...
# 7

> Oh, and FontMetrics can even tell you the length of a

> given String for a given font in pixels, if that's of

> any interest to you.

I suspect by text area the OP means

<textarea rows="10" cols="30">

To which if true I say, good luck.

Whatever the solution might be, and I am not sure there is one, it involves an ungodly amount of JavaScript and CSS. Which also means that you should be asking on another forum (not this site).

cotton.ma at 2007-7-29 16:13:29 > top of Java-index,Java Essentials,Java Programming...