<< Chapter < Page Chapter >> Page >

Usage

Begin by setting the name of the Java object ( textA in Listing 20 ) to the name that you prefer.

Then set the x and y coordinate values for the location in the drawing where the text will be drawn.This specifies the location of the lower-left corner of the first character in the text string.

Then set the name of the font family (" arial " in Listing 20 ) or optionally leave that name blank. If no name is set ("") or an invalid name is set, a default font family will be used.

Then set the font size to the desired font size in points ( 32 in Listing 20 ).

Finally, set the last parameter to the string of text that is to be drawn.

Make sure that you include the quotation marks in both cases where they are used in Listing 20 .

Don't make any other changes to the code shown in Listing 20 .

Setting the font style and font weight

By default the text is normal (not bold, not italic, etc.) . My SVG graphics library provides methods by which you can change the weight and style of thetext, such as making it bold and italic. (See usage instructions for those methods in Listing 27 .)

SVG code to draw text

Listing 21 shows the SVG code produced by the Java code in Listing 20 .

Listing 21 . SVG code to draw text.
<text fill="black" stroke="black" x="225" y="468" font-size="32" font-family="arial">Friction free table.</text>

You should be able to recognize all of the attributes and their values shown in Listing 21 .

The content of an element

There is something in Listing 21 that was not previously discussed in any detail -- content.The actual text, Friction free table , is not an attribute. Instead, it is what is called content in XML/SVG.

In addition, many of the earlier SVG code fragments had elements whose content consisted of a title element, which in turn had text content with words like line , polygon , etc.

This isn't particularly important to you as a user of my SVG graphics library. However, if you elect to create drawings by writingraw SVG code, this is something that you will need to study a little more deeply.

Write the output file

If you elect to create your drawings by writing raw SVG code in a text editor, all you need to do to write the output file is to save the text filefrom inside the editor.

However, if you elect to use my SVG graphics library and create your drawings by writing Java code, you need to include the code shown in Listing 22 to cause the final output SVG file to be written.

(Don't include the .svg extension in the file name that you specify. It is added automatically.)

Listing 22 . Write the output file.
//WRITE OUTPUT FILE SvgLib21.writePrettyFile("Svg21a",doc);

This must be the last statement that you write in your program. Otherwise, you will get an incomplete file.

Set the value inside the quotation marks to the desired path and filename for the file.

(Don't include the .svg extension in the file name that you specify. It is added automatically.)

Don't make any other changes to the code in Listing 22 .

The Java code in Listing 22 writes the output file with the name Svg21.svg in the folder from which the program is being executed (the current folder) . Because it is being written into the current folder, it isn't necessary to provide a path.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Accessible physics concepts for blind students. OpenStax CNX. Oct 02, 2015 Download for free at https://legacy.cnx.org/content/col11294/1.36
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Accessible physics concepts for blind students' conversation and receive update notifications?

Ask