Results 1 to 7 of 7

Thread: [RESOLVED] Font Size in MM

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Resolved [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:
    1. Using G As Graphics = PictureBox1.CreateGraphics
    2.  
    3.             G.PageUnit = GraphicsUnit.Millimeter
    4.             G.InterpolationMode = InterpolationMode.HighQualityBicubic
    5.  
    6.             DPI = G.DpiY
    7.             Dim emSize As Single = txtHeight.Text.Replace("mm", "")
    8.  
    9.  
    10.             Using myPath2 As New GraphicsPath
    11.                 Dim DrawPoint As PointF = New PointF(4, 5)
    12.                 Dim myStringFormat As StringFormat = New StringFormat()
    13.  
    14.                 myPath2.AddString(txtText.Text, fntFont.Font.FontFamily, fntFont.Font.Style, emSize, DrawPoint, myStringFormat)
    15.  
    16.                 'Get all points
    17.                 PointsArr.AddRange(myPath2.PathData.Points)
    18.                 'Draw the text using coords
    19.  
    20.                 If loadXY5 = True Then
    21.                     myPath2.AddLines(XY5Points.ToArray)
    22.                 Else
    23.                     myPath2.AddLines(PointsArr.ToArray)
    24.                 End If
    25.  
    26.                 boundRect = myPath2.GetBounds()
    27.  
    28.                 PictureBox1.Invalidate()
    29.  
    30.             End Using
    31.  
    32.         End Using
    33.  
    34. lblBlankSize.Text = "Blank Size:- " & Math.Round(boundRect.Width) & " X " & Math.Round(boundRect.Height)
    Last edited by DanDanDan1; May 26th, 2010 at 11:12 AM.

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Font Size in MM

    0.3514 mm per point I think.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Re: Font Size in MM

    but if pageunit is set to mm surely i can just enter the size as mm??

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    Re: Font Size in MM

    Anyone got any ideas?

  5. #5
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Font Size in MM

    Quote Originally Posted by DanDanDan1 View Post
    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

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Font Size in MM

    Here's the correct way to do it:

    vb.net Code:
    1. Using pn As New Pen(Color.Black, 1) With {.MiterLimit = 1}
    2.             boundRectF = myPath2.GetBounds(New Drawing2D.Matrix, pn)
    3.         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

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2002
    Posts
    129

    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
  •  



Click Here to Expand Forum to Full Width