Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Font Size vs HTML Font Size

Tags:

java

graphics

I am writing text on an image . I am using DrawString(x,y,string) method and I set font size as below

Font font = new Font(fontName, fontWeight, fontSize);

enter image description here

As you can see left side text written on image with 12pt size. Right side you can see 12pt size in HTML . Is there any way to map this so that I get same size in output as user sees in HTML ?

like image 274
Pit Digger Avatar asked Jun 06 '11 20:06

Pit Digger


People also ask

What is the difference between font size and text size in HTML?

"The 'text-' properties are working rendered text without modifying of the characters geometry. The 'font-' properties are working with raw characters and imparts the specific form to them".

What is font size in HTML?

The default text size in browsers is 16px. So, the default size of 1em is 16px.

How do I resize font size in HTML?

To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property font-size. HTML5 do not support the <font> tag, so the CSS style is used to add font size.

Which is the highest size of font in HTML?

Explanation. The Maximum font size in font drop down is 96 and minimum is 6 . 12 is default size for font size drop-down.


2 Answers

I found this link. Maybe useful. Try it out.

Basically it says that

Java assumes 72 dpi screen resolution Windows uses 96 dpi or 120 dpi depending 
on your font size setting in the display properties.

The site suggests

instead of using getNormalizingTransform() you have to use getScreenResolution()


From the website again.

int screenRes = Toolkit.getDefaultToolkit().getScreenResolution();
int fontSize = (int)Math.round(12.0 * screenRes / 72.0);
like image 181
kensen john Avatar answered Oct 31 '22 12:10

kensen john


I believe this is because java assumes 72 dpi display, where most everything else uses 96dpi now?

see: http://download.oracle.com/javase/tutorial/2d/text/fonts.html

like image 32
John Gardner Avatar answered Oct 31 '22 11:10

John Gardner