Jump to content

canvas and font size..


Mark-

Recommended Posts

Hi,

 

We have a Windows program that lets the user create graphics, rectangles, circles, text etc.. The user sets the text size for the font. For example, a 12pt Tahoma font is the same size in all other programs run on Windows.

 

We take the drawing and convert to Javascript so it can be viewed in a browser, a new feature for us. All the shapes are the correct size. The text is not.

 

I have searched and searched for a solution to the text size on Windows and the text size in the browser, how to make them match.

 

I cannot be the first to run into this issue and I assume it is something simple I am missing. I am using jCanvas to draw the shapes and it wants the font size in pixels which is not the same as a Windows font size.

 

Ideas?

 

Thanks,

 

Mark

 

Link to comment
Share on other sites

pt is an absolute unit, while pixels are relative to the size of the screen. To transform from pt to px you need to know exactly how large a pixel on the user's monitor in real life. The information isn't available or if it is it's usually wrong.

 

I tested using CSS's centimeter unit on a box and measured the screen with a ruler, the result turned out to be 9 millimeters, or 0.9 centimeters. So there's no real way to know for sure how many pt is a px.

 

Using 1.33 might work on your screen, but on somebody else's screen it might not. If you can get the desktop program to use pixels instead that would work better. Either that, or use a different framework than jCanvas. As far as I know, the <canvas> element allows other units for its fonts including pt.

Link to comment
Share on other sites

Hmm, maybe Windows has its own idea of how many points are to a pixel. I'd have to research and see why people suggest that number.

Link to comment
Share on other sites

Hi,

 

Thanks for the response.

 

>Why not just...

 

I tried that and the fonts were the same size regardless of points or pixels. The author of jCanvas posted today that was a bug and it would be corrected very soon.

 

Mark

Edited by Mark-
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...