MeasureString and HTML
-
I'm trying to determine the dimensions of a string as it will appear in HTML. The closest way I've been able to do this is to use a graphics object and use MeasureString. However, there seems to be a slight difference between GDI and HTML with the dimension of strings. Does anybody know how I can reliably measure the string? Thanks in advance.
-
I'm trying to determine the dimensions of a string as it will appear in HTML. The closest way I've been able to do this is to use a graphics object and use MeasureString. However, there seems to be a slight difference between GDI and HTML with the dimension of strings. Does anybody know how I can reliably measure the string? Thanks in advance.
You can't. The browser will display the string in whatever font was assigned to it client-side. There is no way for the server to know in what font, pitch, and browser Text Size the string will be rendered in. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
You can't. The browser will display the string in whatever font was assigned to it client-side. There is no way for the server to know in what font, pitch, and browser Text Size the string will be rendered in. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Maybe I should clarify a bit more then. I want to be able to predict the flow of text that I'm placing into HTML. I'm applying styles to the text using CSS. For example, I know that it's going to be Arial 12 px. So why shouldn't I be able to determine the way that say IE or Firefox are going to render it?
-
Maybe I should clarify a bit more then. I want to be able to predict the flow of text that I'm placing into HTML. I'm applying styles to the text using CSS. For example, I know that it's going to be Arial 12 px. So why shouldn't I be able to determine the way that say IE or Firefox are going to render it?
Because there is no way to garantee that the workstation has Arial 12 pt on it. Also, the users can just click the View menu and change the Text Size, regardless of the size you think they're going to see. Also, last I checked (admittedly, a long time ago), Mac's don't have an Arial font, but they do have web browsers. Also, the size of the browser window will change the rendered flow of the document. Not everybody runs their browsers maximized at 1280x1024. At 1920x1440, you can fit a lot of text on a single line using Arial 12pt. You cannot determine this information server-side. If your rendering is that picky, you'll have to handle rendering in Java client-side. At least there, you've got more information about the environment you're working in. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Maybe I should clarify a bit more then. I want to be able to predict the flow of text that I'm placing into HTML. I'm applying styles to the text using CSS. For example, I know that it's going to be Arial 12 px. So why shouldn't I be able to determine the way that say IE or Firefox are going to render it?
You might get slightly better results if you specify your font size in points; when you use pixels, you don't know how the browser is going to interpret that. Also, you have the problem of how the ie box model differs from every other browser, so the actual size of the area where text is rendered might be different in each browser depending on your settings for margin, padding, and borders.
-
Because there is no way to garantee that the workstation has Arial 12 pt on it. Also, the users can just click the View menu and change the Text Size, regardless of the size you think they're going to see. Also, last I checked (admittedly, a long time ago), Mac's don't have an Arial font, but they do have web browsers. Also, the size of the browser window will change the rendered flow of the document. Not everybody runs their browsers maximized at 1280x1024. At 1920x1440, you can fit a lot of text on a single line using Arial 12pt. You cannot determine this information server-side. If your rendering is that picky, you'll have to handle rendering in Java client-side. At least there, you've got more information about the environment you're working in. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
If I specify the font size using css the user is unable to change the font size and I'm not so sure about Macs not having Arial but that's besides the point. Also, I don't care how big the user has their browser because I just want to know the dimentions of a given set of text. I will be the one locking in the size of the text area using HTML. I simply can't believe that there is no way of determining that out without using the HTML DOM. Still, thanks for your input.
-
You might get slightly better results if you specify your font size in points; when you use pixels, you don't know how the browser is going to interpret that. Also, you have the problem of how the ie box model differs from every other browser, so the actual size of the area where text is rendered might be different in each browser depending on your settings for margin, padding, and borders.