The component reference guide has a usage example in Section 5.3. The idea is that the fontMetrics size() method returns the target rect size for a passed in string rendered in the specified font.
--Kevin
Here's the sample code:
helloString = "Hello ImageCanvas"
fontReg = CreateObject("roFontRegistry")
fontReg.Register("pkg:/fonts/LCDMono.ttf")
font = fontReg.Get("LCDMono",36,50,false) ' 36pt, 50 is normal
' weight, no italics
fontMetrics = CreateObject("roFontMetrics", font)
stringSize = fontMetrics.size(helloString)
canvasItem = { Text:helloString
TextAttrs:{Color:"#FFCCCCCC", Font:font,
HAlign:"HCenter",
VAlign:"VCenter", Direction:"LeftToRight"}
TargetRect:{x:390,y:357,
w:stringSize.w,h:stringSize.h}
}
canvas = CreateObject("roImageCanvas")
port = CreateObject("roMessagePort")
canvas.SetMessagePort(m.port)
'Set opaque background
canvas.SetLayer(0, {Color:"#FF000000", CompositionMode:"Source"})
canvas.SetRequireAllImagesToDraw(true)
canvas.SetLayer(1, canvasItem)
canvas.Show()