Returns the length of text that could be drawn.

 

   
Syntax
 
     

[VBScript]
outC1 = Canvas.TextLength(inText, inParams, outC2)

 

   
Params
 
     
Name   Type   Description
inText String The text to be measured.
inParams String A parameter string containing Override parameters, Positioning parameters and Transform parameters.
outC2 Variant On return set to the number of characters that could be drawn.
outC1 Integer On return set to the number of characters that could be drawn. This value is needed when coding in JScript as values are not passed back by reference in JScript.

 

   
Notes
 
     

This method takes the same arguments as the DrawText method. However it measures the number of characters that could be drawn into the specified rectangle rather than actually drawing any text.

 

   
See Also
 
     

Canvas DrawText function.
Canvas TextArea function.

 

   
Example
 
     

[VBScript]
Set ca = Server.CreateObject("ImageGlue7.Canvas")
txt = "In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with..."
pars = "Rect=10,10,190,190"
ca.Color = "yellow"
ca.Width = 200
ca.Height = 200
ca.TextFont = "Times"
ca.TextSize = 18
ca.TextLength txt, pars, mylen
ca.DrawText txt, pars
ca.SaveAs Server.MapPath("textlen.jpg"), "Quality=high"
Response.Write("Only able to fit " & mylen & " characters onto the canvas<br>")
Response.Write("<b>Original Text</b><br> " & txt & "<br>")
Response.Write("<b>Drawn Text</b><br> " & Left(txt, mylen) & "<br>")

The code draws out a piece of text onto a rather small canvas. It also works out how much text was drawn onto the canvas and writes it out as HTML. The image saved and the page output is shown below.

textlen.jpg

Only able to fit 106 characters onto the canvas
Original Text
In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends of worms and an oozy smell, nor yet a dry, bare, sandy hole with...
Drawn Text
In a hole in the ground there lived a hobbit. Not a nasty, dirty, wet hole, filled with the ends of worms