!DrawGen - Part 2.

Text and Paths.

At the end of the first article on !DrawGen I left you to try a 'C' program which contained some commands which I hadn't explained. You may well have been able to puzzle them out already, but if not, here are the keys to the riddles... Firstly, lets look at producing text.

I have already introduced the command:

where the first parameter is a text string, and the other two are integers which determine where the bottom-left corner of the displayed text will appear in the drawfile. To accompany this command there is another:

where 'font' is an integer which selects the font to be used, font_width and font_height are also integer values which set the size of the font to print (in 'points'), and font_colour is a string - e.g. "red" - which sets the colour of the font.

To see which fonts !DrawGen is using, open a task-window (press Control-F12), then type "DrawGen Help", and press return. (Note: that *is* the right way around!). If the module is active this will cause it to print some information. For the version which you can get on the Archive disc (or from the Archive WebSite) this information should read something like:

N.B. I have left the above as it appeared in the original Archive article.
However, the help text is different for the 2019 version!

In this case font '5' is Trinity.Medium.Italic, so if we want to write something in this font using characters 20 points wide and 24 points high, in blue, we'd use the command:

and then follow this with the appropriate DG_text commands. To see how this works, try the program:

This produces fig 2.1

You can now use the DG_font/DG_text commands to produce text as and how you wish in your drawfile. What's more, you aren't limited to the fonts shown above. You can add some fonts of your choice to the list that DrawGen knows about. To do this you have to alter the contents of the !Run file which is inside the !DrawGen application.

Open up !DrawGen by holding down <shift> and double-clicking on its icon with select. Now draw the !Run file and drop it onto your favourite plain text editor. (!Edit if you haven't anything better!). This will now show:

The interesting lines here are the first two which 'set' a pair of system variables. The second of these - DrawGen$ExFonts - is a list of the fonts you want to add to the basic ones (the Homerton and Trinity families) which !DrawGen knows about. By default the extra fonts are just the Corpus family as that's the only one I can feel confident will be on most machines. You can change these if you wish to other fonts which you wish to use. For example, on my machine these lines are normally set to:

So I'd normally get the Bodoni font when I ask !DrawGen for font 7, and LondonA.Italic when I ask for font 13. To set up your own choices, change the DrawGen$ExFonts string to include the fonts you want, but keep to the following rules:

This final item is because the -F tells !DrawGen how many extra fonts to expect over and above those it always assumes are present. When you get !DrawGen this will be set to '-F3'. But if you were to make the change to my own font choices their would now be 8 extra fonts, so this item would have to be changed to '-F8'.

While looking at the !Run file, this is perhaps a good time to explain the other options. These are:

By altering these settings you can tailor the !DrawGen defaults to suite your needs.


Having dealt with text in detail we can now have a close look at how you can draw complex patterns. In the previous article I showed an easy way to draw simple shapes like rectangles and circles. However !DrawGen also provides a way to draw almost any shape, using a wide variety of lines. This more powerful level of drawing is based upon a small set of commands which set out to provide access to the DrawFile concept of a *path*. The easiest way to understand this is by looking at an example:

This produces the pattern shown in figure 2.2.

Although not exactly worthy of Rembrant, this drawing shows how the path drawing system works. To draw a path you start with the command:
This tells drawgen to start drawing the object or path at the location, x_start, y_start. Both these values are integers in 'OS units'. The remaining three integer values provided define the line thickness (in tenths of a point), its line colour, and the filling colour (if any). To draw out the actual shape you then use the appropriate mixture of
commands. These work very much like the DRAW and MOVE commands used by BASIC to draw on the screen. We essentially draw a line from place to place using the DG_draw command, or use DG_move to move without drawing anything.

To tell !DrawGen we've finished the path, we use the command:
Unlike the simple commands we've used up until now, the DG_path command gives us detailed control over the colours. To do this we must use numbers define the red, green, and blue content. For example, try the program:

This produces the shape shown in figure 2.3 - a peculiar shape which shows a red line filled in green.
The colours are defined by the two values, "0x0000ff00", and "0x00ff0000" in the DG_path command. These values follow the internal Acorn standard approach, they are integers in hexadecimal form, "0xbbggrr00", where the "rr" sets the amount of red, the "gg" sets the amount of green, and the "bb" the amount of blue. On this basis we can now look back at the previous example which created fig2.2 and see that this had a line colour of "0", i.e. of "0x00000000" or "no blue, no green, no red", hence a black line. To get a 'transparent' colour we use the special value "-1". Using this as the fill colour in the earlier example ensured that the no attempt was made to fill the shape. In this newer red/green example we have specified a green fill. In principle, we can use any colours we like.

When filling in a shape it is a good idea to use the command
just before DG_end(). This ensures that the shape is fully closed and the chosen line runs all around the edge.

That's probably enough about drawing complex lines for now, but in part 3 we can see how it is possible to draw curved lines, and lines which have dotted/dashed patterns. Before that, however, I'll spend time in the next part explaining how to use !DrawGen from BASIC programs. (And about time, too! I hear some of you say!)

Content and pages maintained by: Jim Lesurf
using HTMLEdit3 on a StrongARM powered RISCOS machine.