The intermediary document : Boxes structure (box tbox)

1. Description

The box called tbox is used to handle a piece of text. We used a simple tbox in our first example with the following line of XML :

    <tbox fontSize="30" fontStyle="italic">Hello world !</tbox>

The box tbox is a final box. That means that it cannot contain any other box. It must be placed in a non-final box (so far, the only non-final box we used was hbox). The text is the value of the tag tbox :

    <tbox>Place your text here</tbox>

You can specify attributes for a tag tbox. Here are the different attributes you can specify for a tbox :

Attribute name Description Allowed values Default value Mandatory
background Specifies the background to apply to that tbox. Background defined in the definitions document. - No
fontColor Specifies the color of the text. Colors allowed by SVG specification. black No
fontFamily Specifies the font of the text. Any font. Arial No
fontSize Specifies the size of the text. Real values greater than 0 10 No
fontStyle Specifies the style of the text. normal or italic normal No
fontWeight Specifies the weight of the text. normal or bold normal No
id Identifier of that tbox. Any value (must be unique inside the whole document). - No
preferredWidth Used to specify the preferred width of the box tbox. Specifying a value for this attribute is particulary usefull to display the text on several lines (see the example below for further explanations). Real values greater than 0 infinite No

Note : background and id attributes are common to every box and will be discussed later.

2. Example

The following example shows the use of all the tbox's attributes. Save the following code under editor/XML/Examples/tbox.grp :

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE grp SYSTEM "../grp.dtd">
        <tbox fontColor="rgb(100,200,30)" fontFamily="Helvetica" fontSize="20" fontStyle="italic" fontWeight="bold" preferredWidth="80">A tbox using all the possible attributes.</tbox>

We will use the same definitions document than previously. In a console, change to directory editor/XML/Examples (if not already done), and then type :

    java -cp ../../lib/taxi.jar -grp_in tbox.grp -defs examples.def -svg_dtd ../svg.dtd

You should see the following output :

    Parsing file examples.def
    Parsing file tbox.grp
    Creating SVG document
    Generating SVG file tbox.svg

The document tbox.svg in the directory editor/XML/Examples has been generated. It looks like that with the Adobe plugin :

The attribute that need to be explained a little further is preferredWidth. When specifying a value for this attribute, you ask the tbox to be that width, if possible. Depending on the possibilities for cutting down the text, the width of the tbox may be different. In our example, the width of the tbox is 143 in spite of the specification of 80 because the string attributes. is 143 wide with the specified font and font attributes.

You can try to modify the value of some parameters and look into the outcome.