Font Metrics

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
lilo
Newbie
Newbie
Posts: 62
Joined: Wed Sep 07, 2011 12:00 am

Font Metrics

Post by lilo » Sat Sep 17, 2011 7:48 am

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

lilo
Newbie
Newbie
Posts: 29
Joined: Thu Sep 30, 2010 12:00 am

Re: Font Metrics

Post by lilo » Sun Sep 18, 2011 10:04 am

The g.textwidth worked for centering and positioning text.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Font Metrics

Post by Sandra » Mon Sep 19, 2011 10:09 am

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,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

lilo
Newbie
Newbie
Posts: 29
Joined: Thu Sep 30, 2010 12:00 am

Re: Font Metrics

Post by lilo » Tue Sep 20, 2011 10:01 am

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?

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Font Metrics

Post by Sandra » Wed Sep 21, 2011 10:01 am

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,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

lilo
Newbie
Newbie
Posts: 62
Joined: Wed Sep 07, 2011 12:00 am

Re: Font Metrics

Post by lilo » Mon Sep 26, 2011 11:26 am

This works

Post Reply