CLASS Text
(Defined in: jpgraph.php : 3180)
 Text 
 Align() 
 Center() 
 GetFontHeight() 
 GetTextHeight() 
 GetWidth() 
 Hide() 
 ParagraphAlign() 
 Pos() 
 Set() 
 SetAlign() 
 SetAngle() 
 SetBox() 
 SetColor() 
 SetCSIMTarget() 
 SetFont() 
 SetMargin() 
 SetOrientation() 
 SetParagraphAlign() 
 SetPos() 
 SetScalePos() 
 SetShadow() 
 SetWordWrap() 
 Show() 
 Text() 
 

Class usage and Overview
All text that is to be draw onto any graph is handled by this class. You create each text you want printed as an instance of this class. It is possible to adjust both font, color, alignment and paragraph alignment. If the text contains multiple lines (separated by "\n") the paragraph alignment determines how each line is formatted (i.e. left,center or right)

 


Class Methods

 

 

function Align($aHAlign,$aVAlign,$aParagraphAlign)
Specify alignment for the text in relation to the x,y position for text

ArgumentDefaultDescription
$aHAlign  Horizontal alignment
$aVAlign "top" Vertical alignment
$aParagraphAlign "" Paragraph alignment

Description
This determines how the text's x,y position is to be interpretated. Valid horizontal alignments are Valid vertical position are Valid paragraph alignment  
 
See also
Text::ParagraphAlign

Example

$text = new Text();

 

 

function Center($aLeft,$aRight,$aYAbsPos)
Center the text between left and right coordinates

ArgumentDefaultDescription
$aLeft  Left corner X-coordinate
$aRight  Right corner X-coordinate
$aYAbsPos false The common Y-coodinate

Description
Center the text between left and right coordinates on the same Y-coordinate 
 
See also
Text::Pos

Example

$txt->Center(50,150,75);

 

 

function GetFontHeight(&$aImg)
Height of font

ArgumentDefaultDescription
&$aImg  No description available

Description
Return the height of the font used in the text. The difference between this method and the GetTextHeight() is that this method uses a predefined character to determine the height while GetTextHeight() uses the actual text in the string.  
 
See also
Text::GetTextHeight and Text::GetWidth

Example

$height $txt->GetFontHeight($graph->img)

 

 

function GetTextHeight(&$aImg)
Return the height of the actual text in the text object

ArgumentDefaultDescription
&$aImg  No description available

Description
Return the height of the text in this object. The difference between this method and the GetFontHeight() is that that method uses a predefined character to determine the height while GetTextHeight() uses the actual text in the string. 
 
See also
Text::GetFontHeight and Text::GetWidth

Example

$height $txt->GetTextHeight($graph->img);

 

 

function GetWidth(&$aImg)
Get total width of text

ArgumentDefaultDescription
&$aImg  No description available

Description
Get total width of text 
 
See also
Text::GetTextHeight and Text::GetFontHeight

Example

$width $txt->GetWidth($graph->img);

 

 

function Hide($aHide)
Hide the text

ArgumentDefaultDescription
$aHide true True=Hide text

Description
The opposite of Show() 
 
See also
Text::Show

Example

$txt->Hide();

 

 

function ParagraphAlign($aAlign)
Specifies the alignment for a multi line text

ArgumentDefaultDescription
$aAlign  Alignment for a multiline text

Description
Specify the paragraph alignment for a multi line text. Each text line is separated by a "\n" character. Valid alignments are:  
 
See also
Text::Align

Example

$txt->Set("The first line\nSec line\nThird line");
$txt->ParagraphAlign('center');

// Will give the result:
//
//  The first line
//     Sec line
//    Third line

 

 

function Pos($aXAbsPos,$aYAbsPos,$aHAlign,$aVAlign)
Specify the position and alignment for the text object

ArgumentDefaultDescription
$aXAbsPos 0 X-position absolute position
$aYAbsPos 0 Y-position absolute position
$aHAlign "left" Horizontal alignment
$aVAlign "top" Vertical alignment

Description
Set the position text to be displayed. As a convinience the horizontal alignment may also be set in this call. If you need to specify vertical position you have to use the Align() method. 
 
See also
Text::Align, Text::Set and Text::ParagraphAlign

Example

$txt->Pos(100,150,'center');

 

 

function Set($aTxt)
Set text to be displayed

ArgumentDefaultDescription
$aTxt  Text string

Description
Set text to be displayed 

Example

$txt->Set('Hello world');

 

 

function SetAlign($aHAlign,$aVAlign,$aParagraphAlign)
Alias for Align()

ArgumentDefaultDescription
$aHAlign  Horizontal anchor point
$aVAlign "top" Vertical anchor point
$aParagraphAlign "" Paragraph alignment

Description
See Align 
 
See also
Text::Align

 

 

function SetAngle($aAngle)
Specify text angle

ArgumentDefaultDescription
$aAngle  Angle in degrees

Description
Specify Orientation of text. If TTF fonts are used then the orientation can be a arbitrary angle. If the builtin fonts are used then only horizontal and vertical position can be used, i.e 0 or 90 degrees, 

Example

$txt->SetAngle(45);

 

 

function SetBox($aFrameColor,$aBorderColor,$aShadowColor,$aCornerRadius,$aShadowWidth)
Set parameters for poossible frame around text

ArgumentDefaultDescription
$aFrameColor array(255,255,255) Color for text background
$aBorderColor array(0,0,0) Color for border around text
$aShadowColor false Color for shadow
$aCornerRadius 4 Corner radius for rectangle
$aShadowWidth 3 Drop shadow width

Description
Specify parameters for background color, border and possible text drop shadow.
If no shadow color is specified then no shadow will appear.

To use the old style of stright corners specify a corner radius of 0.  
 

See also
Text::SetShadow

Example

$txt = new Text("Note: Simple textnote.\nWIth two lines");
$txt->SetFont(FF_FONT1,FS_BOLD);
$txt->Pos(0.5,0.97,'center','bottom');
$txt->SetBox('yellow','black');
$graph->AddText($txt);


 

 

function SetColor($aColor)
Set text color

ArgumentDefaultDescription
$aColor  Color

Description
Specify color for text 

Example

$txt->SetColor('darkblue');

 

 

function SetCSIMTarget($aTarget,$aAlt)
Specify CSIM Target for text

ArgumentDefaultDescription
$aTarget  Target URL
$aAlt null Alt-tag text

Description
Specify Client Side Image Target for text 

Example

$graph->title->SetCSIMTarget('mainpage.html','Go to main page');

 

 

function SetFont($aFamily,$aStyle,$aSize)
Specify font

ArgumentDefaultDescription
$aFamily  Font family
$aStyle FS_NORMAL Font style
$aSize 10 Font size

Description
Specify font family, size and style. Two major types of font families can be used, builtin bitmnapped fonts or TTF fonts. The builtin fonts have a fixed size which can't be altered. Valid styles are Valid values for the internal font families are Note: FF_FONT0 only suppor font style FS_NORMAL The available TTF are by default  
 
See also
Image::StrokeText

Example

$txt->SetFont(FF_ARIALFS_BOLD14);

 

 

function SetMargin($aMarg)
Set the contect sensiive margin

ArgumentDefaultDescription
$aMarg  Margin in pixels

Description
Specify a context sensitive margin for the text. Depending on in which context the text is used the margin will be interpretated accordingly. 

Example

// Start further away from the top of graph
$graph->title->SetMargin(15);

 

 

function SetOrientation($aDirection)
Deprecated. Use SetAngle instead. Specify text angle

ArgumentDefaultDescription
$aDirection 0 Orientation of text in degrees

Description
Deprecated. Use SetAngle() instead. Specify Orientation of text. If TTF fonts are used then the orientation can be a arbitrary angle. If the builtin fonts are used then only horizontal and vertical position can be used, i.e 0 or 90 degrees, 

Example

$txt->SetOrientation(90); // Vertical text

 

 

function SetParagraphAlign($aAlign)
Specifies the alignment for a multi line text

ArgumentDefaultDescription
$aAlign  Horizontal alignment

Description
Determines how a multi-line text paragraph will be formatted. Each line in the paragraph will be treated individually. Allowed values are
  1. "center"
  2. "left"
  3. "right"
Note: Paragraph alignment is only applicable to horizontal text, i.e. angle = 0 . For paragraphs at an angle the alignbment will always be "left".  

Example

$graph->title->Set("Multi line\ntext !");
$graph->title->SetParagraphAlign('right');

// Default for title is "center"

 

 

function SetPos($aXAbsPos,$aYAbsPos,$aHAlign,$aVAlign)
Alias for Pos()

ArgumentDefaultDescription
$aXAbsPos 0 X position
$aYAbsPos 0 Y position
$aHAlign "left" Horizontal align
$aVAlign "top" Vertical align

Description
Alias for Pos() 
 
See also
Text::Pos

Example

$txt->Pos(100,150,'center');

 

 

function SetScalePos($aX,$aY)
Specify the position of the text using the plot scale positions

ArgumentDefaultDescription
$aX  X-position
$aY  Y-position

Description
Specify the position of the text using the plot scale positions. The Y position is taken to be the Y axis. It is not possible to use Y2 scale to specify the position. 

Example

$txt = new Text();
$txt->SetScalePos(27.3278.9);

 

 

function SetShadow($aShadowColor,$aShadowWidth)
Add a drop shadow to boxed text

ArgumentDefaultDescription
$aShadowColor 'gray' Shadow color
$aShadowWidth 3 Shadow width (in pixels)

Description
If the text has been boxed (by call to SetBox()) then you can easily add a drop shadow by just calling this method.

Note: You can also specify the shadow directly in the SetBox() call. This method was added to make Text more like other graph objects which have a SetShadow() method. 
 

See also
Text::SetBox

Example

$txt = new Text("Note: Simple textnote.\nWIth two lines");
$txt->SetFont(FF_FONT1,FS_BOLD);
$txt->Pos(0.5,0.97,'center','bottom');
$txt->SetBox('yellow','black');
$txt->SetShadow();
$graph->AddText($txt);

 

 

function SetWordWrap($aCol)
Specify a maximum line length

ArgumentDefaultDescription
$aCol  Number of chars in column

Description
Specify a maximum line length. This method will insert suitable line breaks to ensure thateach line never exeeds the specified number of characters. The method will not break words. 

Example

$txt = new Text('A suitable long text which will be broken');
$txt->SetWordWrap(15);

 

 

function Show($aShow)
Show or hide the text string

ArgumentDefaultDescription
$aShow true True=Display text

Description
Show or hide the text string. By default the text string is turned off. So a call to Show() is becessary for the text string to be displayed in the graph.  

Example

$txt->Show();

 

 

function Text($aTxt,$aXAbsPos,$aYAbsPos)
Constructor. Create new text at absolute pixel coordinates

ArgumentDefaultDescription
$aTxt "" Text string
$aXAbsPos 0 X-coordinate
$aYAbsPos 0 Y-coordinate

Description
Create a new object to repesent a text string that is to be displayed on the graph. If the position is not specified when the object is created it can later be specified with a call to the Pos() method. The default alignment is to interpret the x,y coordinate as being the lower left corner of the bounding box for the text string. Note. The texts are hidden by default and you must remember toi call Show() to make the text appear in the image. 
 
See also
Text::Pos, Text::Set, Text::ParagraphAlign and Text::Show

Example

// Possible creations of text objects

// Case 1. Text and position is specified later
$txt = new Text();

// Case 2. Position is specified later
$txt = new Text('Hello world');

// Case 3. Full specification
$txt = new Text('Hello world',100,150);

// A more real life example
$txt = new Text("Note: Simple textnote.\nWIth two lines");
$txt->SetFont(FF_FONT1,FS_BOLD);
$txt->Pos(0.5,0.97,'center','bottom');
$txt->SetBox('yellow','black');
$graph->AddText($txt);