![]() ![]() (That means you can't use the same path on both the screen and the printer.) Suppose you already have a Font object named font, and you want to add text to a path based on that font. But you need to calculate an fSize argument to AddString based on the desired point size of the font and the resolution of the device. Before rendering the path, you simply set page units to points:Īnother approach (one that I'll be using in the sample programs in the remainder of this chapter) lets you use the default page units when rendering the font. Perhaps the simplest approach is to call AddString with the desired point size of the font. It's likely that you want text in a path to be compatible with text displayed normally. (That's 72/120 inch times 72 points to the inch.) If the video resolution is 120 dpi, for example, the 72-unit size of the font will be interpreted as 72/120 inch and will appear about the size of a 43-point font. (That's 0.72 inch times 72 points to an inch.) If you render the path on the screen using the default GraphicsUnit.Pixel page units, the size of the font will depend on the video resolution. But if you render the path on the printer using the default GraphicsUnit.Display page units, the 72 units will be interpreted as 0.72 inch, and the text will be rendered in the same size as a 52-point font. If the page unit is GraphicsUnit.Point, the text will be rendered in the same size as a 72-point font drawn using DrawString. What does that number mean? How large will the font be? It all depends on the page transform in effect when you eventually render that path by calling DrawPath or FillPath. ![]() Let's assume you add a text string to a path by calling AddString with a fourth argument of 72. (And if there were an AddString method that did include a Font argument, it would undoubtedly be restricted to a Font object created with GraphicsUnit.Pixel or GraphicsUnit.World.) For that reason, the AddString method can't be defined in terms of a Font. The path is only a collection of coordinates. When you render text using that font, the size is interpreted at that time in terms of the current page coordinates of the output device.Ī path doesn't retain metrical information. The size of such a font is just a number. As I showed in Chapter 9, it's also possible to create a font that is not a specific metrical size by using the GraphicsUnit.Pixel or GraphicsUnit.World value in the Font constructor. Very often, you specify the font size in points, but you can also use inches or millimeters. When you create a font for drawing, you generally base the font on a specific metrical size. Notice that the third argument is defined as an int, but it's really a member of the FontStyle enumeration cast to an int. Instead of specifying a font (as in DrawString), you specify the three basic components that go into making a font (a font family, a style, and a size) plus a destination (either a point or a rectangle) and a StringFormat object:ĪddString(string str, FontFamily ff, int iStyle, float fSize, Point pt, StringFormat sf)ĪddString(string str, FontFamily ff, int iStyle, float fSize, PointF ptf,ĪddString(string str, FontFamily ff, int iStyle, float fSize, In contrast, the AddString methods of GraphicsPath are considerably different from the DrawString methods of the Graphics class. The AddLine method doesn't require a Pen argument because the path retains only the coordinates of the lines. You can add a line to a path by calling path.AddLine(x1, y1, x2, y2) For example, using the Graphics class, you can draw a line by calling grfx.DrawLine(pen, x1, y1, x2, y2) As you'll recall from Chapter 15, most of the Add methods in GraphicsPath are very similar to the corresponding Draw methods in the Graphics class. The first problem involves the AddString method itself. As usual, however, text is a little different from other graphics objects, and adding text to a path requires some special considerations. The straight lines and curves that make up the character outlines become part of the path. The GraphicsPath class includes a method named AddString that lets you add a text string to a path.
0 Comments
Leave a Reply. |