Allows you to draw text onto the Canvas.

 

   
Syntax
 
     

[VBScript]
outRect = Canvas.DrawText(inText, inParams)

 

   
Params
 
     
Name   Type   Description
inText String The text to be drawn.
inParams String A parameter string containing Override parameters, Positioning parameters and Transform parameters.
outRect See Desc.

The Rect (before transformation) of the area drawn to.

Under ASP the return value is a comma delimited string.

 

   
Notes
 
     

Allows you to draw text onto the Canvas.

The text is drawn within a rectangle specified in the Parameter String. The font, size, style and color are determined by the current TextFont, TextSize, TextStyle and TextColor properties. The horizontal and vertical alignment of the text within the rectangle is determined by the HAlign and VAlign properties.

Note that if you only specify a position for your text (see example below) the width and height will default to the width and height of the canvas.

To draw curved text or text aligned to a path you should specify a set of points using the Points parameter. As you move left to right the text sits on top of the line and as you move from right to left the text drops down under the line.

There are a variety of ways you can further modify curved text. You can use HAlign to determine whether the text is left, middle or right aligned on the line. Similarly you can use VAlign to control where the text appears relative to the line - top is above, bottom is below, middle means that the base of each character sits on the line. You can further vary this using the Offset parameter which is a percentage of the character height - positive or negative. The Kerning parameter allows you to add or subtract space between characters and is measured in 1000ths of an m-space.

Note that if you use characters outside the normal ASCII range (e.g. for Japanese or other Unicode) you must specify the correct CODEPAGE in your Active Server Pages (e.g. for Japanese CODEPAGE=932) and you may need to specify a TextCharset depending on the type of font you are using.

 

   
See Also
 
     

Canvas TextArea function.
Canvas TextLength function.

 

   
Example
 
     

[VBScript]
Set mycanvas = Server.CreateObject("ImageGlue7.Canvas")
mycanvas.Color = "cyan"
mycanvas.Width = 300
mycanvas.Height = 300
mycanvas.TextFont = "Times"
mycanvas.TextSize = 18
mycanvas.TextColor = "darkgray"
mycanvas.DrawText "18 Point Times New Roman", ""
mycanvas.TextSize = 9
mycanvas.TextStyle = "italic"
mycanvas.DrawText "9 Point Italic Times New Roman", "Pos=30,50 TextColor=green"
mycanvas.TextSize = 5
mycanvas.TextStyle = "bold,italic"
mycanvas.DrawText "5 Point Bold Italic Times New Roman", "Pos=60,100 TextColor=gray"
mycanvas.TextSize = 16
mycanvas.DrawText "16 Point Left Aligned Times New Roman", "Pos=10,130 Size=200,200"
mycanvas.DrawText "16 Point Right Aligned Times New Roman", "Pos=10,200 Size=200,200 HAlign=right"
mycanvas.DrawText "16 Point Rotated Text", "Rotate=270 Translate=250,270"
mycanvas.SaveAs Server.MapPath("drawtext.jpg"), "Quality=high"

The code draws text in a number of sizes, shapes, styles and positions. It then saves the resulting Canvas out as a jpeg. The final image is shown below.

drawtext.jpg

 

   
Example
 
     

[VBScript]
theText1 = "Once upon a time there was a hobbit who lived in a hole."
theText2 = "Not a dry sandy hole..."
thePoints = ""
For i = 0 To 126
  If thePoints <> "" Then thePoints = thePoints & ","
  x = (120 * Cos(i / 20)) + 150
  y = (120 * Sin(i / 20)) + 150
  thePoints = thePoints & Round(x, 1) & "," & Round(y, 1)
Next

Set thePic = Server.CreateObject("ImageGlue7.Canvas")
thePic.Color = "yellow"
thePic.TextSize = 18
thePic.Width = 300
thePic.Height = 300
thePic.DrawShape "poly", "Operation=draw Points=" & thePoints
thePic.DrawText theText1, "Valign=middle Points=" & thePoints
thePic.DrawText theText2, "Offset=-100 Kerning=100 TextColor=red Points=" & thePoints
thePic.SaveAs Server.MapPath("shapetext.gif"), ""

The code draws text aligned along a circular path. The final image is shown below.

shapetext.gif