Results 1 to 6 of 6

Thread: [RESOLVED] GDI warp path question

Threaded View

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

    Re: GDI warp path question

    Sorry, after all that, "calculating the array using a sine function" IS the right way to go. I tried transforming the PathPoints array of a text path with trig functions and after much tinkering got the following results:

    Name:  CurvedTextForm.png
Views: 2225
Size:  50.7 KB

    It's the result of lots of scribbling diagrams on paper, half-remembered geometry and blind guesswork. So don't take the details too seriously, especially the trig code, as it may not work for text paths of different sizes. But it shows it can be done and it shouldn't take too much code. It's all on this form:
    vb.net Code:
    1. Imports System.Drawing.Drawing2D
    2. Public Class OldCurvedTextForm
    3.  
    4.     Private textPath As New GraphicsPath
    5.     Private newPath As GraphicsPath
    6.     Private textFont As Font = New Font("Georgia", 100, FontStyle.Regular, GraphicsUnit.Pixel)
    7.     Private textString As String = "THIS IS MY STRING"
    8.  
    9.     Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    10.         e.Graphics.SmoothingMode = SmoothingMode.HighQuality
    11.  
    12.         e.Graphics.DrawPath(Pens.Gray, textPath)
    13.         e.Graphics.FillPath(Brushes.Yellow, newPath)
    14.         e.Graphics.DrawPath(Pens.Black, newPath)
    15.     End Sub
    16.  
    17.     Private Sub OldCurvedTextForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    18.         textPath.AddString(textString, textFont.FontFamily, 0, 80, Point.Empty, Nothing)
    19.         newPath = CurvePath(textPath)
    20.     End Sub
    21.  
    22.     Private Function CurvePath(ByVal inputPath As GraphicsPath) As GraphicsPath
    23.         Dim newPath As GraphicsPath
    24.         Dim w = inputPath.GetBounds.Width / 2
    25.         Dim h = inputPath.GetBounds.Height / 2
    26.         Using mtx As New Matrix
    27.             mtx.Translate(-w, -h)
    28.             inputPath.Transform(mtx)
    29.         End Using
    30.         Dim newPathPoints(inputPath.PathPoints.Count - 1) As PointF
    31.         For i As Integer = 0 To inputPath.PathPoints.Count - 1
    32.  
    33.             Dim pf As PointF = inputPath.PathPoints(i)
    34.             Dim newX = pf.X * Math.Cos(pf.X / w / 2)
    35.             Dim newY = 2 * pf.Y / Math.Cos(pf.X / w)
    36.             newPathPoints(i) = New PointF(newX, newY)
    37.         Next
    38.         newPath = New GraphicsPath(newPathPoints, inputPath.PathTypes)
    39.         Using mtx As New Matrix
    40.             mtx.Translate(w, h)
    41.             inputPath.Transform(mtx)
    42.             mtx.Translate(0, 5 * h)
    43.             newPath.Transform(mtx)
    44.         End Using
    45.         Return newPath
    46.     End Function
    47. End Class

    BB

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