Whitebeam Object Definition

Site Map
 
Home
 
Application Guide
Reference
  Installation
  Configuration
  XML Markup
  JavaScript Classes
  ROM
  Templates
  Environment
  Dev Process
  Tools
  External Links
  Example libraries
Community
Contact Whitebeam
To-Do
Download
Credits
Licence
Whitebeam Users
 
 
 

Whitebeam Object Definition

Method Description

GraphicImage.drawText()

Draw text into an image

Syntax

GraphicImage.Bounds = GraphicImage.drawText(text, startPoint, fontName, fontSize, colour, options)

Parameters

The 'GraphicImage.drawText' method takes 6 parameters:

Name Type/Value Range/Length Description
textstring  Required. The text to write
startPointstruct GraphicImage.Pointsee definition Required. The pixel coordinates of the 'bottom-left' starting point for writing text
fontNamestring  Required. The path to the font-definition file to use for writing this text. See documentation below!
fontSizenumber  Required. The point size for the text
colournumber  Required. Colour to use for text
optionsMetaData  Optional. Object containing optional values that change how the text is written

Results

The 'GraphicImage.drawText' method returns structure:

Type/Value Range/Length Description
struct GraphicImage.Bounds see definition Returns an instance of GraphicObject.Bounds if successful, which marks the bounding rectangle for the drawn text

Remarks

'draw' a string of text into the image. This method has a number of options that allow text to be written at angles, selecting a specific font and font size etc.

Selecting a font

The third parameter to this method allows you to identify a font-file, for example a TTF (True Type) file. For security reasons the fonts you can use are restricted as follows:

  • Specify a path to the font
    If you specify a path (the font parameter contains at least one '/') then the parameter identifies a specific font file within your virtual servers document root.
  • Specify just the font file name - no path
    If you do not specify a path then the Whitebeam will look in configured 'system' font areas. These may be well know directories (known and compiled into the graphics library) or specified by the 'GDFONTPATH' environment variable

The last parameter to this call is an optional set of 'options' expressed as a JavaScript object. To specify a non-default value for one of these options, include the options object.

Currently defined flags are :

OptionDefaultDescription
antialiastrueIf set to 'true', for true-colour images, anti-aliasing of fonts takes place
angle0Angle the text by a number of degrees (0-360)
boundsCheckfalseSet this option to 'true' to prevent any changes to the image, but to allow Whitebeam to calculate the bounding rectangle that completely surrounds the text. Note because text may be angled, the rectangle will also be angled. Use this, for example, if you want to draw a background then overlay text.

Example

  // Create an empty 500x100 pixel image
  var img = (new GraphicImage).create(500,100);

  var red  = img.colourAlloc(255,0,0);
  var blue = img.colourAlloc(  0,0,255);

  img.drawText("Hello World", {x:0,y:img.height}, "courier.ttf", 14, blue, 
               {angle:20 /*degrees*/});
        
Whitebeam release 1.3.36
(loadtime : 16ms)