This is a migrated thread and some comments may be shown as answers.

Calculate Rendered Html Font Size

4 Answers 329 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Steven
Top achievements
Rank 1
Steven asked on 29 Mar 2013, 03:12 AM
I need to calculate the rendered html font size in order to auto clean some content designed for full page width to fit nicely into a Multi-Column report.

I would love to invoke the private "MeasureContent" if I can instantiate my own context object.

Or some sort of HtmlTextBox.ToImage() to pull width/height from.


The problem is that there are an infinite number of possibilities generated from the horrific FREERICHTEXTBOX WYSIWYG control.  I'm using the HtmlAgilityPack to delete and merge redundant FONT tags so my end HTML is pretty tight.
I've also flattened the HtmlTextNodes into a List of Lists split by block level elements so that I can individual calculate the different rendered elements within each line to determine its width in order to shrink user defined padding "&nbps;" and input lines "______".

I was going to use the System.Drawing.Graphics.MeasureString, but I'm uncertain on how the FONT SIZE 1-7 becomes relative.
If the textbox fontsize is 11pt, or 1.2in, is the relative measurement type always in POINTS?

Thanks
Steve

4 Answers, 1 is accepted

Sort by
0
IvanY
Telerik team
answered on 02 Apr 2013, 02:52 PM
Hi Steven,

You can safely use the System.Drawing.Graphics.MeasureString method since the Font can be created with the GraphicsUnit enumeration, which supports inches, millimeters, pixels and other units as well. Since MeasureString accepts Font as parameter it internally takes into consideration the unit of the Font.

All the best,
IvanY
the Telerik team

Have you tried the new visualization options in Telerik Reporting Q1 2013? You can get them from your account.

0
Steven
Top achievements
Rank 1
answered on 03 Apr 2013, 02:58 AM
OK, but with the HtmlTextBox and the relative FontSize determined from <font size=4><font size=1>Test</font> This will be bigger</font>

I need to determine what that end Font will be since it is relative to the HtmlTextBox.Style.Font.Size measurement.
FontSize 1, 2, 3=100%, 4, 5, 6, 7

If I break out the line segment elements with the HtmlAgilityPack, how do I calculate what the final Font Size will be as far as GraphicUnits from the HtmlTextBox.Style.Font.Size measurement.

Unfortunately the html mess we get is normally wrapped in <font size=1> so we are setting the HtmlTextBox Size to 11.5pt so that the relational size equates to a font size of 9px.   But since our textbox could accept any form of HTML I also need to account for valid inline style <div style="font-size:8pt">.

This is the math I need to determine. 

It would be nice to run the calculation from the populated control "thisTextbox.GeneratedSize()" which accounts for its own content.
But in my current project, I need to break out line segments to determine the length of those individual lines to apply cleanup.  So it is a subset of full HTML and I determine the targeted FontSize based on the html tags hierarchy, but if its not FontSize=3, then I need to scale it.

The full reason is that our signature lines are designed for a full page width and I need to shrink the long underlines or non-breaking spaces to ensure they fit the width of a multi column report.


Thanks
Steve
0
Elian
Telerik team
answered on 05 Apr 2013, 12:53 PM
Hello Steven,

We do not provide public API which you can use to make measurements. You can however explore the source code of the product and see details of the implementation that are of interest to you. The relative font size, for example is mapped to the base font (which is coming from the Style of the HtmlTextBox item) or to the parent element.
The mapping is the following:

parentSize = style.Font.Size, the style of the HtmlTextBox item
baseSize = baseStyle.Font.Size, the style of the parent element

"xx-small", "1", "h6" = baseSize * 0.6; // (3 / 5)
"x-small" = baseSize * 0.75; // (3 / 4)
"small", "2", "h5" = baseSize * 0.89; // (8 / 9)
"medium", "3", "h4" = baseSize; // (1)
"large", "4", "h3" = baseSize * 1.2; // (6 / 5)
"x-large", "5", "h2" = baseSize * 1.5; // (3 / 2)
"xx-large", "6", "h1" = baseSize * 2; // (2)
"7" = baseSize * 3; // (3)
"smaller" = parentSize * 0.86; // (5 / 6)
"larger" = parentSize * 1.2; // (6 / 5)

I hope this helps. 
 

Greetings,
Elian
the Telerik team

Have you tried the new visualization options in Telerik Reporting Q1 2013? You can get them from your account.

0
Steven
Top achievements
Rank 1
answered on 06 Apr 2013, 05:12 AM
Thanks,

I will try your numbers to see if I can get them more accurate.




Thanks for the help.
Steve
Tags
General Discussions
Asked by
Steven
Top achievements
Rank 1
Answers by
IvanY
Telerik team
Steven
Top achievements
Rank 1
Elian
Telerik team
Share this question
or