CLASS CanvasRectangleText
(Defined in: jpgraph_canvtools.php : 375) Class usage and Overview
YOu can use this class to convieniently draw a text on canvas. The text may have multiple lines wher each line is separated by a "\n" (newline) character.
The text may also be enclosed in a rounded (possibly filled) rectangle.
See also related classes:
CanvasGraph and CanvasScale
Class Methods
function CanvasRectangleText($aTxt,$xl,$yt,$w,$h)
Draws a text paragraph inside a rounded, possibly filled, rectangle
Argument | Default | Description |
$aTxt
|
''
| Text |
$xl
|
0
| Top left X |
$yt
|
0
| Top left Y |
$w
|
0
| Width |
$h
|
0
| Height |
Description
Draws a text paragraph inside a rounded, possible filled, rectangle.
$t = new CanvasRectangleText();
$t->SetFillColor('lightgreen');
$t->SetFontColor('navy');
$t->SetFont(FF_ARIAL,FS_NORMAL,16);
$t->Set("\n\n\n\n\n\n\n\n\n\n\nTTF Fonts",0.5,19,26,32);
$t->Stroke($g->img,$scale);
function ParagraphAlign($aParaAlign)
Specify paragraph alignment for the text
Argument | Default | Description |
$aParaAlign
| | Alignment |
Description
Specify paragraph alignment for the text. Alignments can be:
$g = new CanvasGraph(550,450);
$scale = new CanvasScale($g);
$scale->Set(0,27,0,53);
//
$t = new CanvasRectangleText();
$t->SetFillColor('lightgreen');
$t->SetFontColor('navy');
$t->SetFont(FF_ARIAL,FS_NORMAL,16);
$t->ParagraphAlign('center');
$t->Set("First line\nSecond line",0.5,19,26,32);
$t->Stroke($g->img,$scale);
function Pos($xl,$yt,$w,$h)
Specify position for text
Argument | Default | Description |
$xl
|
0
| Top left X |
$yt
|
0
| Top left Y |
$w
|
0
| Width |
$h
|
0
| Height |
Description
Set position for text. All coordinates will be translaed according to the current scale used.
function Set($aTxt,$xl,$yt,$w,$h)
Specify the text and position
Argument | Default | Description |
$aTxt
| | Text |
$xl
| | Top left X |
$yt
| | Top left Y |
$w
|
0
| Width |
$h
|
0
| Height |
Description
Specify the text and position. All coordinates will be translated using the specified scale when stroked.
$t->SetShadow('');
$t->SetFont(FF_ARIAL,FS_BOLD,18);
$t->Set('Family',1,1,8);
$t->Stroke($g->img,$scale);
function SetAutoMargin($aMargin)
Specify auto margin when no specific size is specified
Argument | Default | Description |
$aMargin
| | Margin in pixels |
Description
Specify auto margin when no specific size is specified. This margin is used to add extra space around the text and the border around the text.
function SetColor($aColor)
Set border color for rectangle
Argument | Default | Description |
$aColor
| | Border color |
Description
Set border color for rectangle
See also
CanvasRectangleText::SetFontColor and CanvasRectangleText::SetFillColor
$t->SetColor('navy');
function SetCornerRadius($aRad)
Set radius for corners
Argument | Default | Description |
$aRad
|
5
| Radius in pixels |
Description
Specify the radius for the rounded corners. Specifying the value as 0 will give normal square corners.
$t->SetCornerRadius(15);
function SetFillColor($aFillColor)
Specify fill color for rectangle
Argument | Default | Description |
$aFillColor
| | Color |
Description
Specify fill color for rectangle
$t->SetFillColor('#12A73C');
function SetFont($FontFam,$aFontStyle,$aFontSize)
Specify font
Argument | Default | Description |
$FontFam
| | Font family |
$aFontStyle
| | Font style |
$aFontSize
|
12
| Font size |
Description
Specify font
$t->SetFont(FF_ARIAL,FS_BOLD,24);
function SetFontColor($aColor)
Specify text (font) color
Argument | Default | Description |
$aColor
| | Color specification |
Description
Set color for text. Use SetColor() to specify border colro and SetFillColor() to set fill color.
See also
CanvasRectangleText::SetColor and CanvasRectangleText::SetFillColor
$t->SetFontCOlor('black')
function SetPos($xl,$yt,$w,$h)
Specify position
Argument | Default | Description |
$xl
|
0
| Top left X |
$yt
|
0
| Top left Y |
$w
|
0
| Width |
$h
|
0
| Height |
Description
Specify position. All coordinates will be transalted with the specified scale when stroked.
function SetShadow($aColor,$aWidth)
Add a drop shadow
Argument | Default | Description |
$aColor
|
'gray'
| Color of shadow |
$aWidth
|
3
| Width of shadow |
Description
Add a drop shadow to the rounded reactangle surranding the text
$t->SetShadow(); // Use default values
function SetTxt($aTxt)
Specify text string
Argument | Default | Description |
$aTxt
| | Textt |
Description
Set text string to be displayed. The text string may have multiple lines separated by a newline character "\n"
$t->Set("This is a text!");
function Stroke($aImg,$scale)
Stroke text to canvas
Argument | Default | Description |
$aImg
| | Image context |
$scale
| | Scale |
Description
Stroke text to canvas
See also
CanvasScale::CanvasScale
$t->Stroke($graph->img,$scale);