Tutorial - Other Text Routines

There are two other text drawing routines. One for writing a line of text at an angle and one for writing text as a column.

TextRotate()

This will draw a line of text and rotate it. The angle will be measured in degrees clockwise relative to a normal horizontal line of text. The call also has parameters for alignment. These parameter control the alignment before the text is rotated.

Here is the format of the call :-

Shape TextRotate(Text text, Number angle = 0, EHorizAlign halign = Left, EVertAlign valign = Top )

Here is a simple example :-

Program()
    Begin
	TextRotate("Text rotated by 30 degrees", 30);	
    End;
text_rotate_1.grs Output of text_rotate_1.grs text_rotate_1.png

TextColumn()

This will draw a line of text as a column and possibly rotate it. The angle will be measured in degrees clockwise relative to a normal horizontal line of text. The call also has parameters for alignment. These parameter control the alignment before the text is rotated. The default for alignment is centred ( for reasons that have escaped me ).

Here is the format of the call :-

Shape TextColumn(Text text, Number angle = 0, EHorizAlign halign = Centre, EVertAlign valign = Centre)

Here is a simple example :-

Program()
    Begin
	TextColumn("Text Column", 30);	
    End;
text_column_1.grs Output of text_column_1.grs text_column_1.png

TextSize()

There is also a function that returns the size of the rectangle require to contain a block of text. The result is stored in a Point structure as the bottom right of the rectangle relative to the top left. In other words the x field has the width and the y field the height. These values are only applicable for a standard orientation of a text block. These value may have odd rounding error ( when text wraps it seems to allow for a space character at the end of the line ), but nothing critical - best to allow for a margin all around anyway.

Here is the format of the call :-

Point TextSize(Text text, Const Ref TFont font, Number width)

The font parameter will be explained in the following tutorial. Here is a simple example :-

Program()
	Text txt = "This is the sample text for the example";
	Number width = 100;
	Point blocksize;
    Begin
	With {120, 100} Do
		blocksize := TextSize(txt, Font, width);
		Rectangle(blocksize.x, blocksize.y);
		TextBlock(txt, width);
	EndWith;
    End;
text_size_1.grs Output of text_size_1.grs text_size_1.png