Java Reference
In-Depth Information
Lastly we have the element that defines a text element in Sketcher terms. We need to allow for the font
name and its style and point size, a rotation angle for the text, and a color - plus the text itself, of
course, and its position. A Text element is also a little different from the other elements, as its
bounding rectangle is required to construct it, so we must also include that. We have some choices as to
how we define this element. We could use mixed element content in a <text> element, combining the
text string with <font> and <position> elements, for instance.
The disadvantage of this is that we cannot limit the number of occurrences of the child elements and
how they are intermixed with the text. We can make the definition more precisely controlled by
enclosing the text in its own element. Then we can define the <text> element as having element
content - like this:
<!ELEMENT text (color, position, font, string)>
<!ATTLIST text angle CDATA #REQUIRED>
<!ELEMENT font EMPTY>
<!ATTLIST font
fontname CDATA #REQUIRED
fontstyle (plain|bold|italic) #REQUIRED
pointsize CDATA #REQUIRED
>
<!ELEMENT string (#PCDATA|bounds)*>
<!ELEMENT bounds EMPTY>
<!ATTLIST point
width CDATA #REQUIRED
height CDATA #REQUIRED
>
The <string> element content will be a <bounds> element defining the height and width of the
bounding rectangle plus the text to be displayed. The <font> element provides the name, style, and
size of the font as attribute values and since nothing is required beyond that it is an empty element.
Children of the <text> element that we have already defined specify the color and position of the text.
That's all we need. The complete DTD for Sketcher documents will be:
<!ELEMENT sketch (line|circle|rectangle|curve|text)*>
<!ELEMENT color EMPTY>
<!ATTLIST color
R CDATA #REQUIRED
G CDATA #REQUIRED
B CDATA #REQUIRED
>
<!ENTITY % coordinates "x CDATA #REQUIRED y CDATA #REQUIRED">
<!ELEMENT position EMPTY>
<!ATTLIST position %coordinates;>
<!ELEMENT endpoint EMPTY>
Search WWH ::




Custom Search