Java Reference
In-Depth Information
The XML Element for a Text Element in a Sketch
You 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 also has a bounding rectangle that is required
to construct it. You have some options as to how you define this element. You could use mixed element con-
tent in a <text> element, combining the text string with <font> and <position> elements, for example.
The disadvantage of this is that you cannot limit the number of occurrences of the child elements and
how they are intermixed with the text. You can make the definition more precisely controlled by enclosing
the text in its own element. Then you can define the <text> element as having element content — like this:
<!ELEMENT text (color, position, bounds, font, string)>
<!ATTLIST text
angle CDATA #REQUIRED
maxascent CDATA #REQUIRED
>
<!ELEMENT font EMPTY>
<!ATTLIST font
fontname CDATA #REQUIRED
fontstyle (plain|bold|italic) #REQUIRED
pointsize CDATA #REQUIRED
>
<!ELEMENT string (#PCDATA)>
The text element has a maxascent attribute in addition to the angle attribute to specify the value of the
maximum ascent for the font. The <font> and <string> elements are new. The <font> element provides
the name, style, and size of the font as attribute values, and because nothing is required beyond that, it is
an empty element. You could specify the style as CDATA because its value is just an integer, but that would
make the XML for a sketch rather less readable because the font style would not be obvious from the integer
value. The <string> element content is just the text to be displayed. Other children of the <text> element
specify the color and position of the text.
The Complete Sketcher DTD
That's all you need. The complete DTD for Sketcher documents is the following:
<?xml version="1.0" encoding="UTF-8"?>
<!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">
<!ENTITY % dimensions "width CDATA #REQUIRED height CDATA #REQUIRED">
<!ELEMENT position EMPTY>
Search WWH ::




Custom Search