Next: Chapter 5  Managing Visual Styles Up: Part I  User's Guide Previous: Chapter 3  Equation Editor


Chapter 4
Drawings

The BookEditor includes embedded editor for creating figures containing 2D graphics. With the editor, you may create figure containing curved shapes, boxes with or without text text, links, arrows, or raster images.

4.1 Creating New Drawing

To insert new empty drawing into the document, use Insert Drawing ([inline]) or Insert Titled Drawing ([inline]) toolbar command. An empty drawing area is added to the document, see Figure 4.1. If you click the drawing area, a Drawing toolbar appears in the toolbar window. Using the toolbar, you can add drawing elements to the drawing.

[picture]
[end of picture]

Figure 4.1 Empty Drawing Area and Drawing Toolbar

4.2 Adding Graphical Elements

To add new elements to the drawing area, you must first select one of the drawing tools using the Drawing Toolbar. This can be done using one of the drawing tool buttons of the toolbar, see Figure 4.1. The tools are described in detail in subsequent sections.

When you select a particular tool, the New Element Toolbar is added to the toolbar window, see Figure 4.2. You may use the toolbar to specify properties of drawing element before it is added to your drawing. This is useful if you want to add several objects with certain properties. The properties include background color ([inline]), foreground color ([inline]), and more element-specific properties accessible using the [inline] button. You may, of course, also change the properties of elements that have been added to the drawing already.

[picture]
[end of picture]

Figure 4.2 The New Element Toolbar

The first icon on the toolbar indicates the kind of object to be added to the drawing. The yellow star suggests that the properties apply to the new, prototype element, that has not been added to the drawing yet. When you move the mouse cursor over the drawing area, the cursor changes to indicate the kind of tool that is currently active. When you are finished with the tool, you may press the ESC key or the right mouse button to return to the normal mode.

4.2.1 Curved Shapes

To add line, quadratic curve, Bézier curve or arc, use one of the drawing tools [inline], [inline], [inline] or [inline], respectively. Then click the left mouse button to designate the segment start, and drag to specify its end. With this tool, you may create shapes containing only one segment.

To modify existing shape, make sure that no tool is active, and click a shape to select it. The Shape Toolbar shows up in the toolbar window. A number of boxes appears along the selected shape, see Figure 4.3. These boxes represent manipulation points that can be dragged to change the selected shape.

[picture]
[end of picture]

Figure 4.3 Manipulation Points of Shape Segments

To add more segments to the selected shape, use any of buttons of the Shape toolbar: [inline], [inline], [inline], or [inline]. Then use mouse clicks to add segments to the selected shape. Please note the difference between the [inline] and [inline] tools: the former creates new shape, while the latter adds new segment to the selected shape. To delete a segment, right-click it with the mouse, and select Delete Segment from the popup menu.

By default, shapes are open, meaning that they have the beginning and the end. You may close a shape using the [inline] button, i.e. permanently connect the beginning and the end. Press the button again to open a closed shape. Closed shapes may be filled with a color. To toggle filled/transparent state, press the [inline] toolbar button.

4.2.2 Boxes

You can add boxes of various shapes to the drawing. The boxes may optionally contain text. To add new box to the drawing, use any of tools according to Table 4.1. Then click mouse to define upper-left corner of the box, and drag to the right and bottom to define the box size. You may toggle the plain / text state later using the [inline] button.

Table 4.1 Add Box Tools

  Plain With Text
Rectangular [inline] [inline]
Rounded [inline] [inline]
Elliptic [inline] [inline]

The block with text may contain any block content, e.g. a paragraph, series of paragraphs, list, etc. You can set the preferred size of a block by dragging its yellow control point, see Figure 4.4. The text is automatically wrapped to the preferred width. If the preferred height is too small to accommodate the text, the box is automatically widened so that the text fits into the box.

[picture]
Some text to be wrapped
Some text to be wrapped
Some text to be wrapped
[end of picture]

Figure 4.4 Wrapping Text in a Box

To create a box containing a table, use the [inline] tool. The tool creates an invisible box containing a table. Again, you may drag the yellow point to set the preferred width of the table.

4.2.3 Bitmaps

To add a raster image (also known as bitmap) to your drawing, just select the drawing, and paste the image previously copied to the clipboard, by pressing Shift + Insert. You may also insert an image from file, using the [inline] toolbar button. The supported image formats are GIF, JPEG and PNG. You can use the popup menu to change the properties of the bitmap. Use the Set Scale command to enlarge or reduce the natural size of the bitmap. The Crop command cuts away margins having the same color, see Figure 4.5. To mark some color as transparent, use the Set Transparent Color, and click the image to select a color that you want to make transparent.

[picture]

[end of picture]

Figure 4.5 Cropping a Bitmap

4.2.4 Links

Solid elements, i.e. boxes, bitmaps and closed shapes, may be connected with links. A link is a straight, angular or curved connector line connecting two points. The endpoints may be associated with host elements, which causes the link to change automatically when the host element moves. Link endpoints may also have decorations such as arrows or bullets.

To add new link to the drawing, use one of the following toolbar buttons: [inline] for straight link, [inline] for curved link, [inline] for corner link, or [inline] for rectangular link. You may drag the endpoints of a link to designate the link start and end. If you drag a connector over another element, the link endpoint snaps to the geometrical center of the selected element. If you drop the endpoint like this, the link endpoint is permanently associated with the element. If you want to prevent snapping of the endpoint while dragging over an element, hold the Ctrl key during dragging.

Note that when link endpoint is associated with some element, the link virtually ends in the center of the host element, is automatically trimmed by the boundary of the host element, see Figure 4.6. Also note that the curved link may have the start point identical to the end point, see Figure 4.6e. In this case, the link has, besides a control point controlling its shape, a control point for rotating the link around its collapsed endpoints.

[picture]
(a)
(b)
(c)
(d)
(e)
[end of picture]

Figure 4.6 A Variety of Links. (a) Straight Link, (b) Curved Link, (c) Corner Link, (d) Rectangular Link, (e) Loop Link

If you create a complex diagram containing many boxes and links, you may tell the drawing to automatically layout the diagram. To do this, select the root element of the diagram, and invoke the Auto Layout command from the popup menu, see Figure 4.7. From now on, the position of all boxes except the root box is controlled automatically. You may disable the auto-layout state by invoking the command again, and then manually refine the structure of the diagram.

[picture]
[end of picture]

Figure 4.7 Automatically Laid-out Diagram.

4.2.5 Linear Dimensions

You may add add linear dimensions to your drawings using the [inline] toolbar button, see Figure 4.8a. Four control points affect the shape of the linear dimension, see Figure 4.8b. Two points control the position of the arrow, other two points control endpoints of the perpendicular extension lines, and the green point control the relative position of the text. Note that as with text, you may snap the endpoints of the extension lines to some objects, to permanently associate the dimension with the object being measured. When the position or size of the measured object changes, the dimension is updated accordingly.

[picture]
width
height
depth
(a)
(b)
[end of picture]

Figure 4.8 Linear Dimensions Example. (a) Variety of Linear Dimensions, (b) Control Points of a Linear Dimension

4.2.6 Custom Boxes

At times you might need to add material to your drawing that is better described using an algorithm, or script, rather than by interactively drawing it. In this case, you may want to use the Custom Box tool. To add the Custom Box to your drawing, use the [inline] tool, and drag mouse to define position and size of the box. Then use the [inline] to open the script editor, and enter the script that draws the content of the box. For an example of using Custom Box, see Figure 4.9. The detailed description of the script language is beyond the scope of this document. Also note that this feature is still under construction.

[picture]
[end of picture]  
List sin = list(); List cos = list();
translate(0,height/2); double scale=3;
width = width/scale-0.2; scale(scale);
translate(0.2,0);
for (double i=-0.2; i<width; i+=0.2) {
  sin.add(p(i, sin(i)));
  cos.add(p(i, cos(i))); }
setColor(red);   draw(poly(sin));
setColor(blue);  draw(poly(cos));
setColor(black); setStroke(0.02);
draw(line(0,-1.2,0,1.2));
draw(line(-0.2,0,width,0));

Figure 4.9 Custom Box Example

4.3 Manipulating Elements

When you have drawing containing a number of elements, its easy to move, copy or delete them. To move an element, just drag it with mouse. If the element has manipulating points, be sure to click point outside the manipulating point to initiate move gesture instead of manipulation. If you want to drag more elements at once, select them by clicking outside of any element, and extending the selection using mouse dragging. Then drag any of the selected objects to move the whole selection. You may also toggle object selection by clicking it while holding the Ctrl key. To delete selected objects, just press the Delete key.

Note that you cannot change the size of the drawing area; the area resize automatically to accommodate all objects in it. You may drag an object outside the area; the object temporarily disappears, but when you drop it, the area resizes so that the distant object fits to it. Also note that the relative position of objects in the drawing coordinate system has no effect on final visual appearance of the drawing. That is, if you move all objects to any new position, there is no visible change in the drawing.

To copy selected objects, you have two options. Either drag one of selected objects with the mouse, or use the clipboard, i.e. use Ctrl + Insert to copy selection to the clipboard, and Shift + Insert to paste it. The clipboard way of copying objects can be used also to copy elements between different drawings. Note that you can also copy entire drawing using the Local Document Pane, as described in Section 2.2.

All elements in the drawing have its Z-order, i.e. position on the imaginary axis perpendicular to the screen. The later the element is added to the drawing, the closer it is to you. The Z-order is particularly important when the elements overlap; the elements that are closer obscure the elements that are behind them. The Z-order of object can be additionally changed. To move object one position up or down, use the buttons [inline] or [inline], respectively. Button [inline] brings object above all objects, while button [inline] sends object beneath all object.

4.4 Setting Visual Properties

4.5 Text Measurement

Since the BookEditor is not strictly WYSIWYG as described in Section 1.1, the text style used in drawings can be changed by applying different visual style to the drawing. This may break the structure of the drawing. It is thus not recommended to change fonts used in drawings from the setting used to create the drawing.

Moreover, the BookEditor paints text in a way optimized for good appearance on low-resolution displays. This means that each letter has integer width and height, causing that the text does not scale uniformly. For example, if you scale a letter 11 pixels wide to 50% size, its width will be either 5 or 6 pixels, a value quite different from the correct width of 5.5 pixels. The measurement of text may be thus inaccurate with errors of order up to tens of percent, which may easily break your drawing. If your drawing requires accurate measurement of text, you may set its Fractional Metrics attribute. With this attribute, the texts scale uniformly, but the spacing of letters may be uneven.

4.6 Transformations

Existing objects in the drawing may be transformed by applying transforming operations to the drawing. This feature is particularly useful in connection with animations, described in Section 4.7. The four basic transforming operations are demonstrated in Figure 4.10.

[picture]
translate
rotate
scale
shear
[end of picture]

Figure 4.10 Transforming Operations

To create new transform in a drawing, select the drawing, and use its [inline] toolbar button. The Transform Properties dialog shows up, see Figure 4.10. Initially, the list of operations is empty. Press the New button, and select one of the four transformation types. The list of operations is populated with parameters corresponding to the created operation. Each transforming operation has different parameters, as specified in Table 4.2.

[picture]
[end of picture]

Figure 4.11 Transform Properties Dialog

Each transformation may have an identifier, which can be set in the Transform Properties dialog. This identifier may be later used e.g. to programmatically change the parameters of the transform, to achieve an effect of animation, see Section 4.7.

Table 4.2 Parameters of Transforming Operations

Operation Description Parameters
[inline] Translation Moves objects by a vector x , y... translation vector
[inline] Rotation Rotates objects by an angle around a point x , y... center point, theta... rotation angle in degrees (counterclockwise)
[inline] Scale Scales objects x , y... center point, sx... horizontal scale, sy... vertical scale; negative scale values may be used to flip the object
[inline] Shear Shears objects x , y... center point, sx... horizontal shear, sy... vertical shear

Note that it is possible to add more operations to single transformation object. The operations are then applied to objects subsequently. For operations having center point, i.e. all operations except translation, it is useful to specify the center point by selecting it directly in the drawing. This can be done by pressing the Pick Point button in the Transform Properties dialog, and then clicking with mouse any point in the drawing underneath the dialog. The x , y variables of the currently selected operation are then selected appropriately.

[picture]

[end of picture]

Figure 4.12 Moving Objects into Transformation

When transformation object is prepared, we need to associate it with drawing objects to be transformed. This can be done by dragging the objects into the transformation in the Document Structure Pane, see Figure 4.12. When we drop objects into transformation, the transformation's operations begin to apply to its child objects. It is also possible to compose transformations, i.e. a child of transformation may be another transformation.

4.7 Animations

You may turn a still-image prepared with the drawing editor into an animated image, by introducing animation rules. To add animation rules to the drawing, select the drawing, and use the Animation command from the popup menu. The Animation Rules dialog pops up, see Figure 4.13.

[picture]
[end of picture]

Figure 4.13 Animation Rules Dialog

Every rule has the form object = value, where object is an expression that evaluates to object that can receive a value, and value is an expression that evaluates to object that can provide a value. During animation, the rule is executed periodically to evaluate the expression on the right side and update the state of the object at the left side. The objects that can appear on the left side of an animation rule are summarized in Table 4.3. The right side of a rule may be an arithmetic expression, involving mathematical operators, functions, and the animation parameter time. The parameter represents the animation real time in seconds, starting from zero at the time animation started, i.e. the first frame of the animation has been displayed.

Table 4.3 Scriptable Properties

Property Description
transform[n].parameter Parameter of n-th operation of transform. The parameters depend on the type of transforming operation, see Section 4.6.
object.color.component Sets specific color of given object. The color may be one of foreColor, backColor, backColor2 or borderColor. The component may be one of r, g, b for specifying color components in the RGB color model, or c, m, y for specifying components of the CMY color model. The color components should have value in the interval [inline math].

For an example, see Figure 4.14. Figure 4.14a shows the transforms that have been defined in the picture. Figure 4.14b shows the animation script. Figure 4.14c shows the final animated picture.

[picture]
R
F1
F2
S
[end of picture]
R[0].radTheta=time
F1[0].radTheta=sin(time*2)/10
F2[0].radTheta=sin(time*2)/10
S[0].sx=sin(time*2)/(0-8)
(a) (b)
(c)

Figure 4.14 Sample Animated Figure: (a) Parametrized Picture, (b) Animation Rules, (c) Animated Picture


Next: Chapter 5  Managing Visual Styles Up: Part I  User's Guide Previous: Chapter 3  Equation Editor