|
-
May 26th, 2010, 08:16 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Font Size in MM
Hello,
I have a strange problem which I am really struggling with, im making a type of CAD program which the user needs to specify a font size in mm.
Everything seems to work ok but when I get the bounding box of the font it reports it as being less than the font height specified. I have pasted the code below. I hope someone here could help me.
vb.net Code:
Using G As Graphics = PictureBox1.CreateGraphics G.PageUnit = GraphicsUnit.Millimeter G.InterpolationMode = InterpolationMode.HighQualityBicubic DPI = G.DpiY Dim emSize As Single = txtHeight.Text.Replace("mm", "") Using myPath2 As New GraphicsPath Dim DrawPoint As PointF = New PointF(4, 5) Dim myStringFormat As StringFormat = New StringFormat() myPath2.AddString(txtText.Text, fntFont.Font.FontFamily, fntFont.Font.Style, emSize, DrawPoint, myStringFormat) 'Get all points PointsArr.AddRange(myPath2.PathData.Points) 'Draw the text using coords If loadXY5 = True Then myPath2.AddLines(XY5Points.ToArray) Else myPath2.AddLines(PointsArr.ToArray) End If boundRect = myPath2.GetBounds() PictureBox1.Invalidate() End Using End Using lblBlankSize.Text = "Blank Size:- " & Math.Round(boundRect.Width) & " X " & Math.Round(boundRect.Height)
Last edited by DanDanDan1; May 26th, 2010 at 11:12 AM.
-
May 26th, 2010, 08:20 AM
#2
Re: Font Size in MM
0.3514 mm per point I think.
-
May 26th, 2010, 08:24 AM
#3
Thread Starter
Addicted Member
Re: Font Size in MM
but if pageunit is set to mm surely i can just enter the size as mm??
-
May 27th, 2010, 02:07 AM
#4
Thread Starter
Addicted Member
-
May 27th, 2010, 04:28 AM
#5
Re: Font Size in MM
 Originally Posted by DanDanDan1
Anyone got any ideas?
Yes. It's due to the miter setting. GraphicsPath.GetBounds returns a "loose fit" because the corners of the path could conceivably stick out a long way at sharp bends. I think you can fix it either by specifying the Pen parameter to a value of 1 (or less?); or by setting Path.Flatten to a low value, something like 0.01.
BB
-
May 27th, 2010, 09:12 AM
#6
Re: Font Size in MM
Here's the correct way to do it:
vb.net Code:
Using pn As New Pen(Color.Black, 1) With {.MiterLimit = 1}
boundRectF = myPath2.GetBounds(New Drawing2D.Matrix, pn)
End Using
The default value for MiterLimit is 10, which results in the actual bounds being inflated by 10 x the (default) Pen width all round.
BB
-
May 27th, 2010, 10:32 AM
#7
Thread Starter
Addicted Member
Re: Font Size in MM
Thanks alot but have now sorted this using a different method.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|