Page 1 of 1

Font Metrics

Posted: Sat Sep 17, 2011 7:48 am
by 15660116
I determined font metrics with my old code:

GetTextMetrics pic.hdc, text_metrics
internal_leading = text_metrics.tmInternalLeading
total_hgt = text_metrics.tmHeight
text_hgt = total_hgt - internal_leading
text_wid = pic.ScaleX(pic.TextWidth("Text")), pic.ScaleMode, vbPixels)

I cant figure out the font metrics correctly with teechart. My results seem to be wrong:

Private Sub TChart1_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.AfterDraw
text_hgt = g.TextHeight("Text") ' without leading
text_wid = g.TextWidth("Text")
total_hgt = ? 'with leading
End Sub

Re: Font Metrics

Posted: Sun Sep 18, 2011 10:04 am
by 15657351
The g.textwidth worked for centering and positioning text.

Re: Font Metrics

Posted: Mon Sep 19, 2011 10:09 am
by 10050769
Hello lilo,

I am glad that you can find a solution :). And also, can help you, take a look in this thread, where are working with alignment of Text.

Thanks,

Re: Font Metrics

Posted: Tue Sep 20, 2011 10:01 am
by 15657351
I also need to determine textheight in pixels. I am getting inconsistent results using this code:

Private Sub TChart1_AfterDraw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D) Handles TChart1.AfterDraw
text_hgt = g.TextHeight("Text")
End Sub

The result is given in some other units, usually something like thousands of units for 34 font.size text. How can I get the textheight in pixels?

Re: Font Metrics

Posted: Wed Sep 21, 2011 10:01 am
by 10050769
Hello lilo,
I think you have two ways to get Height of Text :
First , using g.TextHeight,as you do, so it returns values in pixels Text Height or Width:

Code: Select all

      
        void tChart1_AfterDraw(object sender, Graphics3D g)
        {
            g.Font.Size = 10;
            this.Text = g.TextHeight("Text").ToString() + "," + g.TextWidth("Text").ToString();
        }
Second, using MeasureString method that returns Text Size in pixels, too:

Code: Select all

        void tChart1_AfterDraw(object sender, Graphics3D g)
        {
            g.Font.Size = 10;
            SizeF fontSize = g.MeasureString(g.Font, "Text");
             this.Text= fontSize.ToString();
        }
For us this methods returns a correctly values (height and width) that text have, but if you can find a inconsistency with results, please explain exactly what is it? And why can not you consider correct, the values do you get?

Thanks,

Re: Font Metrics

Posted: Mon Sep 26, 2011 11:26 am
by 15660116
This works