home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Font Fun / WrapText / WrapText.cs next >
Encoding:
Text File  |  2001-01-15  |  1.9 KB  |  60 lines

  1. //---------------------------------------
  2. // WrapText.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class WrapText: FontMenuForm
  10. {
  11.      float fRadius = 100;
  12.  
  13.      public new static void Main()
  14.      {
  15.           Application.Run(new WrapText());
  16.      }
  17.      public WrapText()
  18.      {
  19.           Text = "Wrap Text";
  20.  
  21.           strText = "e snake ate the tail of th";
  22.           font = new Font("Times New Roman", 48);
  23.      }
  24.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  25.      {
  26.           GraphicsPath path = new GraphicsPath();
  27.           float fFontSize = PointsToPageUnits(grfx, font);
  28.  
  29.                // Add text to the path.
  30.  
  31.           path.AddString(strText, font.FontFamily, (int) font.Style,
  32.                          fFontSize, new PointF(0, 0), new StringFormat());
  33.  
  34.                // Shift the origin to left baseline, y increasing up.
  35.  
  36.           RectangleF rectf = path.GetBounds();
  37.           path.Transform(new Matrix(1, 0, 0, -1, -rectf.Left, 
  38.                                                  GetAscent(grfx, font)));
  39.                // Scale so width equals 2*PI.
  40.  
  41.           float fScale = 2 * (float) Math.PI / rectf.Width;
  42.           path.Transform(new Matrix(fScale, 0, 0, fScale, 0, 0));
  43.  
  44.                // Modify the path.
  45.  
  46.           PointF[] aptf  = path.PathPoints;
  47.  
  48.           for (int i = 0; i < aptf.Length; i++)
  49.                aptf[i] = new PointF(
  50.                     fRadius * (1 + aptf[i].Y) * (float) Math.Cos(aptf[i].X),
  51.                     fRadius * (1 + aptf[i].Y) * (float) Math.Sin(aptf[i].X));
  52.  
  53.           path = new GraphicsPath(aptf, path.PathTypes);
  54.  
  55.                // Fill the path.
  56.  
  57.           grfx.TranslateTransform(cx / 2, cy / 2);
  58.           grfx.FillPath(new SolidBrush(clr), path);
  59.      }
  60. }