Drawing the text
To display texts on a canvas in Opa, we can use the Canvas.fill_text
or Canvas.stroke_text
method. We can change the fill style or stroke style by invoking Canvas.set_fill_style
or Canvas.set_stroke_style
respectively.
To set the font of the text, use the Canvas.set_font
function. We should pass the font information to the method; the font information is a string matching the following pattern:
[font-style] [font-weight] [font-size] [font-family]
The following code draws the word "start" twice, one is filled and the other is stroked, both with font information italic bold 40px verdana
:
Canvas.set_fill_style(ctx,{color:Color.red}) Canvas.set_font(ctx,"italic bold 40px verdana") Canvas.fill_text(ctx,"Start",5,50) Canvas.set_stroke_style(ctx,{color:Color.red}) Canvas.set_line_width(ctx,2.0) Canvas.stroke_text(ctx,"Start",200,50)
The result of the preceding code fragment is as follows: