CLASS Text (Defined in: jpgraph.php : 2966)

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

Argument | Default | Description
--- | --- | ---
$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

- 'left'
- 'center'
- 'right'

Valid vertical position are

- 'top'
- 'middle' or 'center'
- 'bottom'

Valid paragraph alignment

- 'left'
- 'center'
- 'right'

See also
Text::ParagraphAlign

Example

$text = new Text();

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

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$aImg |  | Image context

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

Argument | Default | Description
--- | --- | ---
$aImg |  | Image context

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

Argument | Default | Description
--- | --- | ---
$aImg |  | Image context

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

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$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:

- 'left'
- 'center'
- 'right'

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

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$aTxt |  | Text string

Description
Set text to be displayed

Example

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

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

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$aColor |  | Color

Description
Specify color for text

Example

$txt->SetColor('darkblue');

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

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$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

- FS_NORMAL
- FS_BOLD
- FS_ITALIC
- FS_BOLDITALIC

Valid values for the internal font families are

- FF_FONT0, Internal font 1 (small font)
- FF_FONT1, Internal font 2, (Medium size)
- FF_FONT2, Internal font 3, (large size)

Note: FF_FONT0 only suppor font style FS_NORMAL The available TTF are by default

- FF_ARIAL
- FF_TIMES, (Times Roman)
- FF_COURIER, (Courier new)
- FF_VERDANA, (Verdana)
- FF_BOOK, (Bookman)
- FF_HANDWRT, (Handwriting)
- FF_COMIC, (Sans Comic)

See also
Image::StrokeText

Example

$txt->SetFont(FF_ARIAL, FS_BOLD, 14);

function SetMargin($aMarg)
Set the contect sensiive margin

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$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()

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$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.3, 278.9);

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

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$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

Argument | Default | Description
--- | --- | ---
$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);